Skip to content

Commit 4583e39

Browse files
author
Tim Foley
authored
Implement type splitting for raw buffers (shader-slang#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.
1 parent b6bc083 commit 4583e39

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

source/slang/legalize-types.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ static bool isResourceType(Type* type)
9191
{
9292
return true;
9393
}
94+
else if(auto untypedBufferType = type->As<UntypedBufferResourceType>())
95+
{
96+
return true;
97+
}
9498

9599
// TODO: need more comprehensive coverage here
96100

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//TEST(compute):COMPARE_COMPUTE:
2+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
3+
//TEST_INPUT:ubuffer(data=[0 2 3 3]):dxbinding(1),glbinding(1)
4+
//TEST_INPUT:ubuffer(data=[4 5 6 7]):dxbinding(2),glbinding(2)
5+
//TEST_INPUT:ubuffer(data=[8 9 10 11]):dxbinding(3),glbinding(3)
6+
//TEST_INPUT:ubuffer(data=[12 13 14 15]):dxbinding(4),glbinding(4)
7+
8+
RWStructuredBuffer<int> outputBuffer;
9+
10+
struct S
11+
{
12+
RWByteAddressBuffer a;
13+
RWByteAddressBuffer b;
14+
};
15+
S s[2];
16+
17+
[numthreads(4, 1, 1)]
18+
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
19+
{
20+
uint i = dispatchThreadID.x;
21+
22+
int val =
23+
s[0].a.Load(i * 4)
24+
+ s[1].a.Load(i * 4)*16
25+
+ s[0].b.Load(i * 4)*256
26+
+ s[1].b.Load(i * 4)*4096;
27+
28+
outputBuffer[i] = val;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
C840
2+
D952
3+
EA63
4+
FB73

tools/render-test/render-d3d11.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,16 @@ class D3D11Renderer : public Renderer, public ShaderCompiler
815815
viewDesc.Buffer.Flags = 0;
816816
viewDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
817817
viewDesc.Format = DXGI_FORMAT_UNKNOWN;
818+
819+
if( bufferDesc.stride == 0 )
820+
{
821+
// TODO: are there UAV cases we need to handle that are neither
822+
// raw nor structured? RWBuffer<T> would be one...
823+
824+
viewDesc.Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
825+
viewDesc.Format = DXGI_FORMAT_R32_TYPELESS;
826+
}
827+
818828
dxDevice->CreateUnorderedAccessView(bufferOut, &viewDesc, &viewOut);
819829
}
820830
if (bufferDesc.type != InputBufferType::ConstantBuffer)

0 commit comments

Comments
 (0)