HLSL: add readonly qualifier to tbuffer, so they end up as SRV

This commit is contained in:
steve-lunarg 2017-04-20 13:16:23 -06:00
parent be28355019
commit 7b1dcd6693
7 changed files with 101 additions and 29 deletions

View File

@ -15,6 +15,7 @@ u4: offset -1, type 9051, size 1, index -1, binding 44
u5.@data: offset 0, type 1405, size 0, index 2, binding -1
u6.@data: offset 0, type 1406, size 1, index 3, binding -1
cb1: offset 0, type 1404, size 1, index 4, binding -1
tb1: offset 0, type 1404, size 1, index 5, binding -1
Uniform block reflection:
t4: offset -1, type ffffffff, size 0, index -1, binding 14
@ -22,6 +23,7 @@ t5: offset -1, type ffffffff, size 0, index -1, binding 15
u5: offset -1, type ffffffff, size 0, index -1, binding 45
u6: offset -1, type ffffffff, size 0, index -1, binding 46
cb: offset -1, type ffffffff, size 4, index -1, binding 51
tb: offset -1, type ffffffff, size 4, index -1, binding 17
Vertex attribute reflection:

View File

@ -17,7 +17,7 @@ gl_FragCoord origin is upper left
0:31 Constant:
0:31 0 (const uint)
0:31 v2: direct index for structure (layout( row_major std430) buffer 4-component vector of float)
0:31 'anon@1' (layout( row_major std430) buffer block{layout( row_major std430) buffer 4-component vector of float v2})
0:31 'anon@1' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer 4-component vector of float v2})
0:31 Constant:
0:31 0 (const uint)
0:31 v3: direct index for structure (layout( row_major std140) uniform 4-component vector of float)
@ -25,7 +25,7 @@ gl_FragCoord origin is upper left
0:31 Constant:
0:31 0 (const uint)
0:31 v4: direct index for structure (layout( row_major std430 offset=16) buffer 4-component vector of float)
0:31 'anon@3' (layout( binding=8 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v4, layout( row_major std430 offset=48) buffer int i4, layout( row_major std430 offset=60) buffer float f1, layout( row_major std430 offset=64) buffer float f3, layout( row_major std430 offset=68) buffer float f4, layout( row_major std430 offset=72) buffer float f5, layout( row_major std430) buffer float f6, layout( row_major std430) buffer float f7, layout( row_major std430) buffer 3X4 matrix of float m1, layout( column_major std430) buffer 3X4 matrix of float m2, layout( row_major std430) buffer 3X4 matrix of float m3, layout( row_major std430) buffer 3X4 matrix of float m4})
0:31 'anon@3' (layout( binding=8 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v4, layout( row_major std430 offset=48) buffer int i4, layout( row_major std430 offset=60) buffer float f1, layout( row_major std430 offset=64) buffer float f3, layout( row_major std430 offset=68) buffer float f4, layout( row_major std430 offset=72) buffer float f5, layout( row_major std430) buffer float f6, layout( row_major std430) buffer float f7, layout( row_major std430) buffer 3X4 matrix of float m1, layout( column_major std430) buffer 3X4 matrix of float m2, layout( row_major std430) buffer 3X4 matrix of float m3, layout( row_major std430) buffer 3X4 matrix of float m4})
0:31 Constant:
0:31 0 (const uint)
0:30 Function Definition: PixelShaderFunction( ( temp void)
@ -40,9 +40,9 @@ gl_FragCoord origin is upper left
0:? 'input' ( temp 4-component vector of float)
0:? Linker Objects
0:? 'anon@0' (layout( row_major std140) uniform block{layout( row_major std140) uniform 4-component vector of float v1})
0:? 'anon@1' (layout( row_major std430) buffer block{layout( row_major std430) buffer 4-component vector of float v2})
0:? 'anon@1' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer 4-component vector of float v2})
0:? 'anon@2' (layout( set=10 binding=2 row_major std140) uniform block{layout( row_major std140) uniform 4-component vector of float v3, layout( row_major std140 offset=20) uniform int i3})
0:? 'anon@3' (layout( binding=8 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v4, layout( row_major std430 offset=48) buffer int i4, layout( row_major std430 offset=60) buffer float f1, layout( row_major std430 offset=64) buffer float f3, layout( row_major std430 offset=68) buffer float f4, layout( row_major std430 offset=72) buffer float f5, layout( row_major std430) buffer float f6, layout( row_major std430) buffer float f7, layout( row_major std430) buffer 3X4 matrix of float m1, layout( column_major std430) buffer 3X4 matrix of float m2, layout( row_major std430) buffer 3X4 matrix of float m3, layout( row_major std430) buffer 3X4 matrix of float m4})
0:? 'anon@3' (layout( binding=8 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v4, layout( row_major std430 offset=48) buffer int i4, layout( row_major std430 offset=60) buffer float f1, layout( row_major std430 offset=64) buffer float f3, layout( row_major std430 offset=68) buffer float f4, layout( row_major std430 offset=72) buffer float f5, layout( row_major std430) buffer float f6, layout( row_major std430) buffer float f7, layout( row_major std430) buffer 3X4 matrix of float m1, layout( column_major std430) buffer 3X4 matrix of float m2, layout( row_major std430) buffer 3X4 matrix of float m3, layout( row_major std430) buffer 3X4 matrix of float m4})
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float)
@ -68,7 +68,7 @@ gl_FragCoord origin is upper left
0:31 Constant:
0:31 0 (const uint)
0:31 v2: direct index for structure (layout( row_major std430) buffer 4-component vector of float)
0:31 'anon@1' (layout( row_major std430) buffer block{layout( row_major std430) buffer 4-component vector of float v2})
0:31 'anon@1' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer 4-component vector of float v2})
0:31 Constant:
0:31 0 (const uint)
0:31 v3: direct index for structure (layout( row_major std140) uniform 4-component vector of float)
@ -76,7 +76,7 @@ gl_FragCoord origin is upper left
0:31 Constant:
0:31 0 (const uint)
0:31 v4: direct index for structure (layout( row_major std430 offset=16) buffer 4-component vector of float)
0:31 'anon@3' (layout( binding=8 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v4, layout( row_major std430 offset=48) buffer int i4, layout( row_major std430 offset=60) buffer float f1, layout( row_major std430 offset=64) buffer float f3, layout( row_major std430 offset=68) buffer float f4, layout( row_major std430 offset=72) buffer float f5, layout( row_major std430) buffer float f6, layout( row_major std430) buffer float f7, layout( row_major std430) buffer 3X4 matrix of float m1, layout( column_major std430) buffer 3X4 matrix of float m2, layout( row_major std430) buffer 3X4 matrix of float m3, layout( row_major std430) buffer 3X4 matrix of float m4})
0:31 'anon@3' (layout( binding=8 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v4, layout( row_major std430 offset=48) buffer int i4, layout( row_major std430 offset=60) buffer float f1, layout( row_major std430 offset=64) buffer float f3, layout( row_major std430 offset=68) buffer float f4, layout( row_major std430 offset=72) buffer float f5, layout( row_major std430) buffer float f6, layout( row_major std430) buffer float f7, layout( row_major std430) buffer 3X4 matrix of float m1, layout( column_major std430) buffer 3X4 matrix of float m2, layout( row_major std430) buffer 3X4 matrix of float m3, layout( row_major std430) buffer 3X4 matrix of float m4})
0:31 Constant:
0:31 0 (const uint)
0:30 Function Definition: PixelShaderFunction( ( temp void)
@ -91,9 +91,9 @@ gl_FragCoord origin is upper left
0:? 'input' ( temp 4-component vector of float)
0:? Linker Objects
0:? 'anon@0' (layout( row_major std140) uniform block{layout( row_major std140) uniform 4-component vector of float v1})
0:? 'anon@1' (layout( row_major std430) buffer block{layout( row_major std430) buffer 4-component vector of float v2})
0:? 'anon@1' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer 4-component vector of float v2})
0:? 'anon@2' (layout( set=10 binding=2 row_major std140) uniform block{layout( row_major std140) uniform 4-component vector of float v3, layout( row_major std140 offset=20) uniform int i3})
0:? 'anon@3' (layout( binding=8 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v4, layout( row_major std430 offset=48) buffer int i4, layout( row_major std430 offset=60) buffer float f1, layout( row_major std430 offset=64) buffer float f3, layout( row_major std430 offset=68) buffer float f4, layout( row_major std430 offset=72) buffer float f5, layout( row_major std430) buffer float f6, layout( row_major std430) buffer float f7, layout( row_major std430) buffer 3X4 matrix of float m1, layout( column_major std430) buffer 3X4 matrix of float m2, layout( row_major std430) buffer 3X4 matrix of float m3, layout( row_major std430) buffer 3X4 matrix of float m4})
0:? 'anon@3' (layout( binding=8 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v4, layout( row_major std430 offset=48) buffer int i4, layout( row_major std430 offset=60) buffer float f1, layout( row_major std430 offset=64) buffer float f3, layout( row_major std430 offset=68) buffer float f4, layout( row_major std430 offset=72) buffer float f5, layout( row_major std430) buffer float f6, layout( row_major std430) buffer float f7, layout( row_major std430) buffer 3X4 matrix of float m1, layout( column_major std430) buffer 3X4 matrix of float m2, layout( row_major std430) buffer 3X4 matrix of float m3, layout( row_major std430) buffer 3X4 matrix of float m4})
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float)
@ -141,6 +141,7 @@ gl_FragCoord origin is upper left
MemberDecorate 14 0 Offset 0
Decorate 14 Block
Decorate 16 DescriptorSet 0
MemberDecorate 23 0 NonWritable
MemberDecorate 23 0 Offset 0
Decorate 23 BufferBlock
Decorate 25 DescriptorSet 0
@ -149,24 +150,36 @@ gl_FragCoord origin is upper left
Decorate 29(cbufName) Block
Decorate 31 DescriptorSet 10
Decorate 31 Binding 2
MemberDecorate 36(tbufName) 0 NonWritable
MemberDecorate 36(tbufName) 0 Offset 16
MemberDecorate 36(tbufName) 1 NonWritable
MemberDecorate 36(tbufName) 1 Offset 48
MemberDecorate 36(tbufName) 2 NonWritable
MemberDecorate 36(tbufName) 2 Offset 60
MemberDecorate 36(tbufName) 3 NonWritable
MemberDecorate 36(tbufName) 3 Offset 64
MemberDecorate 36(tbufName) 4 NonWritable
MemberDecorate 36(tbufName) 4 Offset 68
MemberDecorate 36(tbufName) 5 NonWritable
MemberDecorate 36(tbufName) 5 Offset 72
MemberDecorate 36(tbufName) 6 NonWritable
MemberDecorate 36(tbufName) 6 Offset 76
MemberDecorate 36(tbufName) 7 NonWritable
MemberDecorate 36(tbufName) 7 Offset 80
MemberDecorate 36(tbufName) 8 RowMajor
MemberDecorate 36(tbufName) 8 NonWritable
MemberDecorate 36(tbufName) 8 Offset 96
MemberDecorate 36(tbufName) 8 MatrixStride 16
MemberDecorate 36(tbufName) 9 ColMajor
MemberDecorate 36(tbufName) 9 NonWritable
MemberDecorate 36(tbufName) 9 Offset 160
MemberDecorate 36(tbufName) 9 MatrixStride 16
MemberDecorate 36(tbufName) 10 RowMajor
MemberDecorate 36(tbufName) 10 NonWritable
MemberDecorate 36(tbufName) 10 Offset 208
MemberDecorate 36(tbufName) 10 MatrixStride 16
MemberDecorate 36(tbufName) 11 RowMajor
MemberDecorate 36(tbufName) 11 NonWritable
MemberDecorate 36(tbufName) 11 Offset 272
MemberDecorate 36(tbufName) 11 MatrixStride 16
Decorate 36(tbufName) BufferBlock

View File

@ -12,23 +12,23 @@ gl_FragCoord origin is upper left
0:17 add ( temp 4-component vector of float)
0:17 'input' ( in 4-component vector of float)
0:17 v1: direct index for structure (layout( row_major std430 offset=16) buffer 4-component vector of float)
0:17 'anon@0' (layout( set=3 binding=5 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1})
0:17 'anon@0' (layout( set=3 binding=5 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1})
0:17 Constant:
0:17 0 (const uint)
0:17 v5: direct index for structure (layout( row_major std430 offset=0) buffer 4-component vector of float)
0:17 'anon@1' (layout( row_major std430 push_constant) buffer block{layout( row_major std430 offset=0) buffer 4-component vector of float v5})
0:17 'anon@1' (layout( row_major std430 push_constant) readonly buffer block{layout( row_major std430 offset=0) buffer 4-component vector of float v5})
0:17 Constant:
0:17 0 (const uint)
0:17 v1PostLayout: direct index for structure (layout( row_major std430 offset=16) buffer 4-component vector of float)
0:17 'anon@2' (layout( set=4 binding=7 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1PostLayout})
0:17 'anon@2' (layout( set=4 binding=7 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1PostLayout})
0:17 Constant:
0:17 0 (const uint)
0:? Linker Objects
0:? 'anon@0' (layout( set=3 binding=5 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1})
0:? 'anon@1' (layout( row_major std430 push_constant) buffer block{layout( row_major std430 offset=0) buffer 4-component vector of float v5})
0:? 'anon@0' (layout( set=3 binding=5 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1})
0:? 'anon@1' (layout( row_major std430 push_constant) readonly buffer block{layout( row_major std430 offset=0) buffer 4-component vector of float v5})
0:? 'specConst' ( specialization-constant const int)
0:? 10 (const int)
0:? 'anon@2' (layout( set=4 binding=7 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1PostLayout})
0:? 'anon@2' (layout( set=4 binding=7 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1PostLayout})
Linked fragment stage:
@ -48,23 +48,23 @@ gl_FragCoord origin is upper left
0:17 add ( temp 4-component vector of float)
0:17 'input' ( in 4-component vector of float)
0:17 v1: direct index for structure (layout( row_major std430 offset=16) buffer 4-component vector of float)
0:17 'anon@0' (layout( set=3 binding=5 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1})
0:17 'anon@0' (layout( set=3 binding=5 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1})
0:17 Constant:
0:17 0 (const uint)
0:17 v5: direct index for structure (layout( row_major std430 offset=0) buffer 4-component vector of float)
0:17 'anon@1' (layout( row_major std430 push_constant) buffer block{layout( row_major std430 offset=0) buffer 4-component vector of float v5})
0:17 'anon@1' (layout( row_major std430 push_constant) readonly buffer block{layout( row_major std430 offset=0) buffer 4-component vector of float v5})
0:17 Constant:
0:17 0 (const uint)
0:17 v1PostLayout: direct index for structure (layout( row_major std430 offset=16) buffer 4-component vector of float)
0:17 'anon@2' (layout( set=4 binding=7 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1PostLayout})
0:17 'anon@2' (layout( set=4 binding=7 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1PostLayout})
0:17 Constant:
0:17 0 (const uint)
0:? Linker Objects
0:? 'anon@0' (layout( set=3 binding=5 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1})
0:? 'anon@1' (layout( row_major std430 push_constant) buffer block{layout( row_major std430 offset=0) buffer 4-component vector of float v5})
0:? 'anon@0' (layout( set=3 binding=5 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1})
0:? 'anon@1' (layout( row_major std430 push_constant) readonly buffer block{layout( row_major std430 offset=0) buffer 4-component vector of float v5})
0:? 'specConst' ( specialization-constant const int)
0:? 10 (const int)
0:? 'anon@2' (layout( set=4 binding=7 row_major std430) buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1PostLayout})
0:? 'anon@2' (layout( set=4 binding=7 row_major std430) readonly buffer block{layout( row_major std430 offset=16) buffer 4-component vector of float v1PostLayout})
// Module Version 10000
// Generated by (magic number): 80001
@ -89,12 +89,15 @@ gl_FragCoord origin is upper left
MemberName 30(tbufName2) 0 "v1PostLayout"
Name 32 ""
Name 38 "specConst"
MemberDecorate 14(tbufName) 0 NonWritable
MemberDecorate 14(tbufName) 0 Offset 16
Decorate 14(tbufName) BufferBlock
Decorate 16 DescriptorSet 3
Decorate 16 Binding 5
MemberDecorate 23(tbufName2) 0 NonWritable
MemberDecorate 23(tbufName2) 0 Offset 0
Decorate 23(tbufName2) BufferBlock
MemberDecorate 30(tbufName2) 0 NonWritable
MemberDecorate 30(tbufName2) 0 Offset 16
Decorate 30(tbufName2) BufferBlock
Decorate 32 DescriptorSet 4

View File

@ -24,9 +24,9 @@ cbuffer cb : register(b1) {
int cb1;
};
// tbuffer tb : register(t7) {
// int tb1;
// };
tbuffer tb : register(t7) {
int tb1;
};
float4 main() : SV_Target0
{
@ -47,11 +47,11 @@ float4 main() : SV_Target0
u4[0];
u5.Load(0);
u6[0];
u7[0];
u8[0];
u7;
u8;
cb1;
// tb1; TODO: wrong type?
tb1;
return 0;
}

View File

@ -1555,14 +1555,23 @@ void TShader::setSourceEntryPoint(const char* name)
sourceEntryPointName = name;
}
// Set binding base for sampler types
void TShader::setShiftSamplerBinding(unsigned int base) { intermediate->setShiftSamplerBinding(base); }
// Set binding base for texture types (SRV)
void TShader::setShiftTextureBinding(unsigned int base) { intermediate->setShiftTextureBinding(base); }
// Set binding base for image types
void TShader::setShiftImageBinding(unsigned int base) { intermediate->setShiftImageBinding(base); }
// Set binding base for uniform buffer objects (CBV)
void TShader::setShiftUboBinding(unsigned int base) { intermediate->setShiftUboBinding(base); }
// Synonym for setShiftUboBinding, to match HLSL language.
void TShader::setShiftCbufferBinding(unsigned int base) { intermediate->setShiftUboBinding(base); }
// Set binding base for UAV (unordered access view)
void TShader::setShiftUavBinding(unsigned int base) { intermediate->setShiftUavBinding(base); }
// Set binding base for SSBOs
void TShader::setShiftSsboBinding(unsigned int base) { intermediate->setShiftSsboBinding(base); }
// Enables binding automapping using TIoMapper
void TShader::setAutoMapBindings(bool map) { intermediate->setAutoMapBindings(map); }
// See comment above TDefaultHlslIoMapper in iomapper.cpp:
void TShader::setHlslIoMapping(bool hlslIoMap) { intermediate->setHlslIoMapping(hlslIoMap); }
void TShader::setFlattenUniformArrays(bool flatten) { intermediate->setFlattenUniformArrays(flatten); }
void TShader::setNoStorageFormat(bool useUnknownFormat) { intermediate->setNoStorageFormat(useUnknownFormat); }

View File

@ -491,6 +491,48 @@ protected:
}
};
/********************************************************************************
The following IO resolver maps types in HLSL register space, as follows:
t for shader resource views (SRV)
TEXTURE1D
TEXTURE1DARRAY
TEXTURE2D
TEXTURE2DARRAY
TEXTURE3D
TEXTURECUBE
TEXTURECUBEARRAY
TEXTURE2DMS
TEXTURE2DMSARRAY
STRUCTUREDBUFFER
BYTEADDRESSBUFFER
BUFFER
TBUFFER
s for samplers
SAMPLER
SAMPLER1D
SAMPLER2D
SAMPLER3D
SAMPLERCUBE
SAMPLERSTATE
SAMPLERCOMPARISONSTATE
u for unordered access views (UAV)
RWBYTEADDRESSBUFFER
RWSTRUCTUREDBUFFER
APPENDSTRUCTUREDBUFFER
CONSUMESTRUCTUREDBUFFER
RWBUFFER
RWTEXTURE1D
RWTEXTURE1DARRAY
RWTEXTURE2D
RWTEXTURE2DARRAY
RWTEXTURE3D
b for constant buffer views (CBV)
CBUFFER
********************************************************************************/
struct TDefaultHlslIoResolver : public TDefaultIoResolverBase
{
bool validateBinding(EShLanguage /*stage*/, const char* /*name*/, const glslang::TType& type, bool /*is_live*/) override
@ -498,7 +540,6 @@ struct TDefaultHlslIoResolver : public TDefaultIoResolverBase
if (type.getQualifier().hasBinding()) {
const int set = getLayoutSet(type);
// Use Uav binding if requested: else will pass through to old behavior
if (isUavType(type))
return checkEmpty(set, baseUavBinding + type.getQualifier().layoutBinding);

View File

@ -1846,13 +1846,16 @@ bool HlslGrammar::acceptStruct(TType& type, TIntermNode*& nodeList)
// This storage qualifier will tell us whether it's an AST
// block type or just a generic structure type.
TStorageQualifier storageQualifier = EvqTemporary;
bool readonly = false;
// CBUFFER
if (acceptTokenClass(EHTokCBuffer))
if (acceptTokenClass(EHTokCBuffer)) {
storageQualifier = EvqUniform;
// TBUFFER
else if (acceptTokenClass(EHTokTBuffer))
} else if (acceptTokenClass(EHTokTBuffer)) {
storageQualifier = EvqBuffer;
readonly = true;
}
// CLASS
// STRUCT
else if (! acceptTokenClass(EHTokClass) && ! acceptTokenClass(EHTokStruct))
@ -1908,6 +1911,7 @@ bool HlslGrammar::acceptStruct(TType& type, TIntermNode*& nodeList)
new(&type) TType(typeList, structName);
else {
postDeclQualifier.storage = storageQualifier;
postDeclQualifier.readonly = readonly;
new(&type) TType(typeList, structName, postDeclQualifier); // sets EbtBlock
}