forked from llvm/offload-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.cpp
More file actions
103 lines (81 loc) · 2.98 KB
/
Device.cpp
File metadata and controls
103 lines (81 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//===- DX/Device.cpp - DirectX Device API ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
#include "API/Device.h"
#include "API/FormatConversion.h"
#include "Config.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
using namespace offloadtest;
Buffer::~Buffer() {}
CommandBuffer::~CommandBuffer() {}
Fence::~Fence() {}
Queue::~Queue() {}
Texture::~Texture() {}
Device::~Device() {}
llvm::Expected<llvm::SmallVector<std::unique_ptr<Device>>>
offloadtest::initializeDevices(const DeviceConfig Config) {
llvm::SmallVector<std::unique_ptr<Device>> Devices;
llvm::Error Err = llvm::Error::success();
#ifdef OFFLOADTEST_ENABLE_D3D12
if (auto E = initializeDX12Devices(Config, Devices))
Err = llvm::joinErrors(std::move(Err), std::move(E));
#endif
#ifdef OFFLOADTEST_ENABLE_VULKAN
if (auto E = initializeVulkanDevices(Config, Devices))
Err = llvm::joinErrors(std::move(Err), std::move(E));
#endif
#ifdef OFFLOADTEST_ENABLE_METAL
if (auto E = initializeMetalDevices(Config, Devices))
Err = llvm::joinErrors(std::move(Err), std::move(E));
#endif
if (Devices.empty()) {
if (Err)
return std::move(Err);
return llvm::createStringError(std::errc::no_such_device,
"No GPU devices found.");
}
// Log errors from backends that failed while others succeeded.
if (Err)
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs());
return Devices;
}
llvm::Expected<std::unique_ptr<Texture>>
offloadtest::createRenderTargetFromCPUBuffer(Device &Dev,
const CPUBuffer &Buf) {
auto TexFmtOrErr = toFormat(Buf.Format, Buf.Channels);
if (!TexFmtOrErr)
return TexFmtOrErr.takeError();
TextureCreateDesc Desc = {};
Desc.Location = MemoryLocation::GpuOnly;
Desc.Usage = TextureUsage::RenderTarget;
Desc.Fmt = *TexFmtOrErr;
Desc.Width = Buf.OutputProps.Width;
Desc.Height = Buf.OutputProps.Height;
Desc.MipLevels = 1;
Desc.OptimizedClearValue = ClearColor{};
if (auto Err = validateTextureDescMatchesCPUBuffer(Desc, Buf))
return Err;
return Dev.createTexture("RenderTarget", Desc);
}
llvm::Expected<std::unique_ptr<Texture>>
offloadtest::createDefaultDepthStencilTarget(Device &Dev, uint32_t Width,
uint32_t Height) {
TextureCreateDesc Desc = {};
Desc.Location = MemoryLocation::GpuOnly;
Desc.Usage = TextureUsage::DepthStencil;
Desc.Fmt = Format::D32FloatS8Uint;
Desc.Width = Width;
Desc.Height = Height;
Desc.MipLevels = 1;
Desc.OptimizedClearValue = ClearDepthStencil{1.0f, 0};
return Dev.createTexture("DepthStencil", Desc);
}