diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-02-01 12:06:06 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-01 12:06:06 -0800 |
| commit | 4583e395ad503b63343a14adaeb621dee8a8da71 (patch) | |
| tree | 8dc7ea0861ee11c5742925785ecb7b312c242599 | |
| parent | b6bc0837ba6e7fb42280bf6289f4dab633c88392 (diff) | |
Implement type splitting for raw buffers (#393)
* Fix render-test to handle raw buffers
I don't know if this fix will work for UAVs that are neither structured nor raw, but it fixes the code that currently only really works if every UAV is structured (since it doesn't set a format).
* Make type legalization consider raw buffer types
The type layout logic was already handling these, but the type splitting logic in legalization was failing to split structure types that contain, e.g., `RWByteAddressBuffer`.
A compute test case has been added to confirm the fix.
| -rw-r--r-- | source/slang/legalize-types.cpp | 4 | ||||
| -rw-r--r-- | tests/compute/buffer-type-splitting.slang | 29 | ||||
| -rw-r--r-- | tests/compute/buffer-type-splitting.slang.expected.txt | 4 | ||||
| -rw-r--r-- | tools/render-test/render-d3d11.cpp | 10 |
4 files changed, 47 insertions, 0 deletions
diff --git a/source/slang/legalize-types.cpp b/source/slang/legalize-types.cpp index 76fda18e3..d0cf2ab69 100644 --- a/source/slang/legalize-types.cpp +++ b/source/slang/legalize-types.cpp @@ -91,6 +91,10 @@ static bool isResourceType(Type* type) { return true; } + else if(auto untypedBufferType = type->As<UntypedBufferResourceType>()) + { + return true; + } // TODO: need more comprehensive coverage here diff --git a/tests/compute/buffer-type-splitting.slang b/tests/compute/buffer-type-splitting.slang new file mode 100644 index 000000000..c7577a0b2 --- /dev/null +++ b/tests/compute/buffer-type-splitting.slang @@ -0,0 +1,29 @@ +//TEST(compute):COMPARE_COMPUTE: +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +//TEST_INPUT:ubuffer(data=[0 2 3 3]):dxbinding(1),glbinding(1) +//TEST_INPUT:ubuffer(data=[4 5 6 7]):dxbinding(2),glbinding(2) +//TEST_INPUT:ubuffer(data=[8 9 10 11]):dxbinding(3),glbinding(3) +//TEST_INPUT:ubuffer(data=[12 13 14 15]):dxbinding(4),glbinding(4) + +RWStructuredBuffer<int> outputBuffer; + +struct S +{ + RWByteAddressBuffer a; + RWByteAddressBuffer b; +}; +S s[2]; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint i = dispatchThreadID.x; + + int val = + s[0].a.Load(i * 4) + + s[1].a.Load(i * 4)*16 + + s[0].b.Load(i * 4)*256 + + s[1].b.Load(i * 4)*4096; + + outputBuffer[i] = val; +}
\ No newline at end of file diff --git a/tests/compute/buffer-type-splitting.slang.expected.txt b/tests/compute/buffer-type-splitting.slang.expected.txt new file mode 100644 index 000000000..4bc5fcbf9 --- /dev/null +++ b/tests/compute/buffer-type-splitting.slang.expected.txt @@ -0,0 +1,4 @@ +C840 +D952 +EA63 +FB73 diff --git a/tools/render-test/render-d3d11.cpp b/tools/render-test/render-d3d11.cpp index d0280a770..7d5c79b19 100644 --- a/tools/render-test/render-d3d11.cpp +++ b/tools/render-test/render-d3d11.cpp @@ -815,6 +815,16 @@ public: viewDesc.Buffer.Flags = 0; viewDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; viewDesc.Format = DXGI_FORMAT_UNKNOWN; + + if( bufferDesc.stride == 0 ) + { + // TODO: are there UAV cases we need to handle that are neither + // raw nor structured? RWBuffer<T> would be one... + + viewDesc.Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW; + viewDesc.Format = DXGI_FORMAT_R32_TYPELESS; + } + dxDevice->CreateUnorderedAccessView(bufferOut, &viewDesc, &viewOut); } if (bufferDesc.type != InputBufferType::ConstantBuffer) |
