Skip to content

Commit d1e1277

Browse files
authored
Merge branch 'llvm:main' into remove-pWaitDstStageMask
2 parents cb36f12 + ef3571c commit d1e1277

163 files changed

Lines changed: 56576 additions & 17643 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,28 @@ pip3 install pyyaml
3434

3535
On Windows, the [Graphics Tools](https://learn.microsoft.com/en-us/windows/win32/direct3d12/directx-12-programming-environment-set-up#debug-layer) optional feature is additionally required to run the test suite.
3636

37-
# Adding to LLVM Build
37+
# Building
3838

39-
Add the following to the CMake options:
39+
The LLVM project provides a CMake cache file,
40+
[`clang/cmake/caches/HLSL.cmake`](https://github.com/llvm/llvm-project/blob/main/clang/cmake/caches/HLSL.cmake),
41+
that configures the required projects and targets for HLSL development. You can
42+
use it with `-C` to set up a build that includes the offload test suite:
4043

4144
```shell
42-
-DLLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR=${workspaceRoot}\..\OffloadTest -DLLVM_EXTERNAL_PROJECTS="OffloadTest"
45+
cmake -G Ninja -Bbuild \
46+
-C <path to llvm-project>/clang/cmake/caches/HLSL.cmake \
47+
-C <path to OffloadTest>/cmake/caches/OffloadTest.cmake \
48+
<path to llvm-project>/llvm
49+
```
50+
51+
The `OffloadTest.cmake` cache file automatically sets
52+
`LLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR` and `LLVM_EXTERNAL_PROJECTS` based on its
53+
location in the source tree. If you already have an LLVM build configured, you
54+
can add the offload test suite to it by passing the same `-C` flag or by adding
55+
the following to your CMake options:
56+
57+
```shell
58+
-DLLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR=<path to OffloadTest> -DLLVM_EXTERNAL_PROJECTS="OffloadTest"
4359
```
4460

4561
If you do not have a build of dxc on your path you'll need to specify the shader
@@ -49,6 +65,20 @@ compiler to use by passing:
4965
-DDXC_DIR=<path to folder containing dxc & dxv>
5066
```
5167

68+
## Running Tests
69+
70+
```shell
71+
cmake --build build --target check-hlsl
72+
```
73+
74+
The `check-hlsl` target builds all required tools and runs the full test suite.
75+
You can also run tests for a specific platform with `check-hlsl-<platform>`
76+
(e.g. `check-hlsl-vk`, `check-hlsl-d3d12`). To only run `clang`-based tests
77+
(without requiring DXC), use `check-hlsl-clang-<platform>` (e.g.
78+
`check-hlsl-clang-mtl`). Subdirectories of the test suite are also available as
79+
targets with `check-hlsl-<platform>-<path>` where the path is lowercased with
80+
directory separators replaced by `-` (e.g. `check-hlsl-d3d12-feature-hlsllib`).
81+
5282
## Enabling clang-tidy
5383

5484
The offload test suite's code is clang-tidy clean for a limited ruleset.

cmake/caches/OffloadTest.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(LLVM_EXTERNAL_OFFLOADTEST_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../ CACHE STRING "")
2+
set(LLVM_EXTERNAL_PROJECTS "${LLVM_EXTERNAL_PROJECTS};OffloadTest" CACHE STRING "")

include/API/Device.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ struct DeviceConfig {
3535
bool EnableValidationLayer = false;
3636
};
3737

38+
enum class MemoryLocation {
39+
GpuOnly,
40+
CpuToGpu,
41+
GpuToCpu,
42+
};
43+
44+
struct BufferCreateDesc {
45+
MemoryLocation Location;
46+
};
47+
48+
class Buffer {
49+
public:
50+
virtual ~Buffer() = default;
51+
52+
Buffer(const Buffer &) = delete;
53+
Buffer &operator=(const Buffer &) = delete;
54+
55+
protected:
56+
Buffer() = default;
57+
};
58+
3859
class Queue {
3960
public:
4061
virtual ~Queue() = 0;
@@ -56,6 +77,9 @@ class Device {
5677

5778
virtual Queue &getGraphicsQueue() = 0;
5879

80+
virtual llvm::Expected<std::shared_ptr<Buffer>>
81+
createBuffer(std::string Name, BufferCreateDesc &Desc,
82+
size_t SizeInBytes) = 0;
5983
virtual void printExtra(llvm::raw_ostream &OS) {}
6084

6185
virtual ~Device() = 0;

include/Image/Image.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ImageRef {
8585
assert(Data.size() == size() && "Data size does not match properties");
8686
}
8787

88-
ImageRef(const Buffer &B)
88+
ImageRef(const CPUBuffer &B)
8989
: ImageRef(B.OutputProps.Height, B.OutputProps.Width,
9090
B.getSingleElementSize(), B.Channels,
9191
B.Format == DataFormat::Float32 ||

include/Support/Pipeline.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static inline uint32_t getFormatSize(DataFormat Format) {
130130
llvm_unreachable("All cases covered.");
131131
}
132132

133-
struct Buffer {
133+
struct CPUBuffer {
134134
std::string Name;
135135
DataFormat Format;
136136
int Channels;
@@ -161,8 +161,8 @@ struct Result {
161161
Rule ComparisonRule;
162162
std::string Actual;
163163
std::string Expected;
164-
Buffer *ActualPtr = nullptr;
165-
Buffer *ExpectedPtr = nullptr;
164+
CPUBuffer *ActualPtr = nullptr;
165+
CPUBuffer *ExpectedPtr = nullptr;
166166
DenormMode DM = DenormMode::Any;
167167
unsigned ULPT; // ULP Tolerance
168168
double Epsilon;
@@ -173,7 +173,7 @@ struct Resource {
173173
std::string Name;
174174
DirectXBinding DXBinding;
175175
std::optional<VulkanBinding> VKBinding;
176-
Buffer *BufferPtr = nullptr;
176+
CPUBuffer *BufferPtr = nullptr;
177177
Sampler *SamplerPtr = nullptr;
178178
bool HasCounter;
179179
std::optional<uint32_t> TilesMapped;
@@ -306,7 +306,7 @@ enum class RootParamKind {
306306
struct RootResource : public Resource {};
307307

308308
struct RootConstant {
309-
Buffer *BufferPtr;
309+
CPUBuffer *BufferPtr;
310310
std::string Name;
311311
};
312312

@@ -335,11 +335,11 @@ struct VertexAttribute {
335335

336336
struct IOBindings {
337337
std::string VertexBuffer;
338-
Buffer *VertexBufferPtr;
338+
CPUBuffer *VertexBufferPtr;
339339
llvm::SmallVector<VertexAttribute> VertexAttributes;
340340

341341
std::string RenderTarget;
342-
Buffer *RTargetBufferPtr;
342+
CPUBuffer *RTargetBufferPtr;
343343

344344
uint32_t getVertexStride() const {
345345
uint32_t Stride = 0;
@@ -402,7 +402,7 @@ struct Pipeline {
402402

403403
IOBindings Bindings;
404404
llvm::SmallVector<PushConstantBlock> PushConstants;
405-
llvm::SmallVector<Buffer> Buffers;
405+
llvm::SmallVector<CPUBuffer> Buffers;
406406
llvm::SmallVector<Sampler> Samplers;
407407
llvm::SmallVector<Result> Results;
408408
llvm::SmallVector<DescriptorSet> Sets;
@@ -422,7 +422,7 @@ struct Pipeline {
422422
return DescriptorCount;
423423
}
424424

425-
Buffer *getBuffer(llvm::StringRef Name) {
425+
CPUBuffer *getBuffer(llvm::StringRef Name) {
426426
for (auto &B : Buffers)
427427
if (Name == B.Name)
428428
return &B;
@@ -446,7 +446,7 @@ struct Pipeline {
446446

447447
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::DescriptorSet)
448448
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Resource)
449-
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Buffer)
449+
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::CPUBuffer)
450450
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Sampler)
451451
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Shader)
452452
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::dx::RootParameter)
@@ -467,8 +467,8 @@ template <> struct MappingTraits<offloadtest::DescriptorSet> {
467467
static void mapping(IO &I, offloadtest::DescriptorSet &D);
468468
};
469469

470-
template <> struct MappingTraits<offloadtest::Buffer> {
471-
static void mapping(IO &I, offloadtest::Buffer &R);
470+
template <> struct MappingTraits<offloadtest::CPUBuffer> {
471+
static void mapping(IO &I, offloadtest::CPUBuffer &R);
472472
};
473473

474474
template <> struct MappingTraits<offloadtest::Sampler> {

lib/API/DX/Device.cpp

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ static DXGI_FORMAT getDXFormat(DataFormat Format, int Channels) {
6767
DXFormats(SINT) break;
6868
case DataFormat::Float32:
6969
DXFormats(FLOAT) break;
70+
case DataFormat::UInt64:
71+
case DataFormat::Int64:
72+
if (Channels == 1)
73+
return DXGI_FORMAT_R32G32_UINT;
74+
if (Channels == 2)
75+
return DXGI_FORMAT_R32G32B32A32_UINT;
76+
llvm_unreachable("Unsupported channel count for 64-bit format");
7077
case DataFormat::Depth32:
7178
llvm_unreachable(
7279
"Depth32 format is not yet supported in the DirectX backend.");
@@ -162,7 +169,7 @@ static DXResourceKind getDXKind(offloadtest::ResourceKind RK) {
162169
static llvm::Expected<D3D12_RESOURCE_DESC>
163170
getResourceDescription(const Resource &R) {
164171
const D3D12_RESOURCE_DIMENSION Dimension = getDXDimension(R.Kind);
165-
const offloadtest::Buffer &B = *R.BufferPtr;
172+
const offloadtest::CPUBuffer &B = *R.BufferPtr;
166173

167174
if (B.OutputProps.MipLevels != 1)
168175
return llvm::createStringError(std::errc::not_supported,
@@ -270,6 +277,18 @@ static D3D12_UNORDERED_ACCESS_VIEW_DESC getUAVDescription(const Resource &R) {
270277

271278
namespace {
272279

280+
class DXBuffer : public offloadtest::Buffer {
281+
public:
282+
ComPtr<ID3D12Resource> Buffer;
283+
std::string Name;
284+
BufferCreateDesc Desc;
285+
size_t SizeInBytes;
286+
287+
DXBuffer(ComPtr<ID3D12Resource> Buffer, llvm::StringRef Name,
288+
BufferCreateDesc Desc, size_t SizeInBytes)
289+
: Buffer(Buffer), Name(Name), Desc(Desc), SizeInBytes(SizeInBytes) {}
290+
};
291+
273292
class DXQueue : public offloadtest::Queue {
274293
public:
275294
ComPtr<ID3D12CommandQueue> Queue;
@@ -355,6 +374,41 @@ class DXDevice : public offloadtest::Device {
355374

356375
Queue &getGraphicsQueue() override { return GraphicsQueue; }
357376

377+
llvm::Expected<std::shared_ptr<offloadtest::Buffer>>
378+
createBuffer(std::string Name, BufferCreateDesc &Desc,
379+
size_t SizeInBytes) override {
380+
381+
D3D12_HEAP_TYPE HeapType = D3D12_HEAP_TYPE_DEFAULT;
382+
switch (Desc.Location) {
383+
case MemoryLocation::GpuOnly:
384+
HeapType = D3D12_HEAP_TYPE_DEFAULT;
385+
break;
386+
case MemoryLocation::CpuToGpu:
387+
HeapType = D3D12_HEAP_TYPE_UPLOAD;
388+
break;
389+
case MemoryLocation::GpuToCpu:
390+
HeapType = D3D12_HEAP_TYPE_READBACK;
391+
break;
392+
}
393+
394+
const D3D12_RESOURCE_FLAGS Flags =
395+
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
396+
397+
const D3D12_HEAP_PROPERTIES HeapProps = CD3DX12_HEAP_PROPERTIES(HeapType);
398+
const D3D12_RESOURCE_DESC BufferDesc =
399+
CD3DX12_RESOURCE_DESC::Buffer(SizeInBytes, Flags);
400+
401+
ComPtr<ID3D12Resource> DeviceBuffer;
402+
if (auto Err = HR::toError(Device->CreateCommittedResource(
403+
&HeapProps, D3D12_HEAP_FLAG_NONE,
404+
&BufferDesc, D3D12_RESOURCE_STATE_COMMON,
405+
nullptr, IID_PPV_ARGS(&DeviceBuffer)),
406+
"Failed to create buffer."))
407+
return Err;
408+
409+
return std::make_shared<DXBuffer>(DeviceBuffer, Name, Desc, SizeInBytes);
410+
}
411+
358412
static llvm::Expected<DXDevice> create(ComPtr<IDXCoreAdapter> Adapter,
359413
const DeviceConfig &Config) {
360414
ComPtr<ID3D12Device> Device;
@@ -569,7 +623,7 @@ class DXDevice : public offloadtest::Device {
569623
ComPtr<ID3D12Resource> Source) {
570624
addUploadBeginBarrier(IS, Destination);
571625
if (R.isTexture()) {
572-
const offloadtest::Buffer &B = *R.BufferPtr;
626+
const offloadtest::CPUBuffer &B = *R.BufferPtr;
573627
const D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint{
574628
0, CD3DX12_SUBRESOURCE_FOOTPRINT(
575629
getDXFormat(B.Format, B.Channels), B.OutputProps.Width,
@@ -1227,7 +1281,7 @@ class DXDevice : public offloadtest::Device {
12271281

12281282
auto CopyBackResource = [&IS, this](ResourcePair &R) {
12291283
if (R.first->isTexture()) {
1230-
const offloadtest::Buffer &B = *R.first->BufferPtr;
1284+
const offloadtest::CPUBuffer &B = *R.first->BufferPtr;
12311285
const D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint{
12321286
0, CD3DX12_SUBRESOURCE_FOOTPRINT(
12331287
getDXFormat(B.Format, B.Channels), B.OutputProps.Width,
@@ -1309,7 +1363,7 @@ class DXDevice : public offloadtest::Device {
13091363
// Map readback and copy into host buffer, accounting for row pitch and
13101364
// flipping vertical orientation. DirectX render target origin is top-left,
13111365
// while our image writer expects bottom-left.
1312-
const Buffer &B = *P.Bindings.RTargetBufferPtr;
1366+
const CPUBuffer &B = *P.Bindings.RTargetBufferPtr;
13131367
void *Mapped = nullptr;
13141368
if (auto Err = HR::toError(IS.RTReadback->Map(0, nullptr, &Mapped),
13151369
"Failed to map render target readback"))
@@ -1351,7 +1405,7 @@ class DXDevice : public offloadtest::Device {
13511405
return llvm::createStringError(
13521406
std::errc::invalid_argument,
13531407
"No render target bound for graphics pipeline.");
1354-
const Buffer &OutBuf = *P.Bindings.RTargetBufferPtr;
1408+
const CPUBuffer &OutBuf = *P.Bindings.RTargetBufferPtr;
13551409
if (OutBuf.OutputProps.MipLevels != 1)
13561410
return llvm::createStringError(
13571411
std::errc::not_supported,
@@ -1405,7 +1459,7 @@ class DXDevice : public offloadtest::Device {
14051459
return llvm::createStringError(
14061460
std::errc::invalid_argument,
14071461
"No vertex buffer bound for graphics pipeline.");
1408-
const Buffer &VB = *P.Bindings.VertexBufferPtr;
1462+
const CPUBuffer &VB = *P.Bindings.VertexBufferPtr;
14091463
const uint64_t VBSize = VB.size();
14101464
D3D12_RESOURCE_DESC const Desc = CD3DX12_RESOURCE_DESC::Buffer(VBSize);
14111465
CD3DX12_HEAP_PROPERTIES HeapProps =
@@ -1542,7 +1596,7 @@ class DXDevice : public offloadtest::Device {
15421596
D3D12_RESOURCE_STATE_COPY_SOURCE);
15431597
IS.CmdList->ResourceBarrier(1, &Barrier);
15441598

1545-
const Buffer &B = *P.Bindings.RTargetBufferPtr;
1599+
const CPUBuffer &B = *P.Bindings.RTargetBufferPtr;
15461600
const D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint{
15471601
0,
15481602
CD3DX12_SUBRESOURCE_FOOTPRINT(
@@ -1555,7 +1609,7 @@ class DXDevice : public offloadtest::Device {
15551609

15561610
auto CopyBackResource = [&IS, this](ResourcePair &R) {
15571611
if (R.first->isTexture()) {
1558-
const offloadtest::Buffer &B = *R.first->BufferPtr;
1612+
const offloadtest::CPUBuffer &B = *R.first->BufferPtr;
15591613
const D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint{
15601614
0, CD3DX12_SUBRESOURCE_FOOTPRINT(
15611615
getDXFormat(B.Format, B.Channels), B.OutputProps.Width,

0 commit comments

Comments
 (0)