diff options
| -rw-r--r-- | source/slang/slang-emit-wgsl.cpp | 12 | ||||
| -rw-r--r-- | tests/wgsl/buffer-array.slang | 24 |
2 files changed, 36 insertions, 0 deletions
diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp index 227c6cf75..8a3a3cc01 100644 --- a/source/slang/slang-emit-wgsl.cpp +++ b/source/slang/slang-emit-wgsl.cpp @@ -656,6 +656,11 @@ void WGSLSourceEmitter::emitSimpleTypeImpl(IRType* type) m_writer->emit(">"); return; } + case kIROp_ConstantBufferType: + { + emitType((IRType*)type->getOperand(0)); + return; + } default: break; } @@ -772,6 +777,13 @@ void WGSLSourceEmitter::emitVarKeywordImpl(IRType* type, IRInst* varDecl) m_writer->emit("<workgroup>"); } else if ( + type->getOp() == kIROp_ArrayType && + type->getOperand(0)->getOp() == kIROp_ConstantBufferType) + { + // Arrays of constant buffers should use the uniform keyword. + m_writer->emit("<uniform>"); + } + else if ( type->getOp() == kIROp_HLSLRWStructuredBufferType || type->getOp() == kIROp_HLSLRasterizerOrderedStructuredBufferType || type->getOp() == kIROp_HLSLRWByteAddressBufferType) diff --git a/tests/wgsl/buffer-array.slang b/tests/wgsl/buffer-array.slang new file mode 100644 index 000000000..3ab27eaac --- /dev/null +++ b/tests/wgsl/buffer-array.slang @@ -0,0 +1,24 @@ +//TEST:SIMPLE(filecheck=WGSL): -stage vertex -entry main -target wgsl
+
+static const int cubeCount = 3;
+
+struct PerInstanceUniforms
+{
+ float4x4 model;
+ float4x4 normalModel;
+};
+
+// WGSL: @binding(0) @group(0) var<uniform> perInstance_0 : array<PerInstanceUniforms_std140_0, i32(3)>;
+[[vk::binding(0, 0)]] ConstantBuffer<PerInstanceUniforms> perInstance[cubeCount] : register(b0, space0);
+
+struct VertexInput
+{
+ float4 position : POSITION0;
+};
+
+float4 main(VertexInput input)
+{
+ // Only here to ensure that perInstance is not ignored.
+ float4 pos = mul(input.position, perInstance[0].model);
+ return pos;
+}
|
