Skip to content

Commit bd01bd3

Browse files
authored
Fix the type error in kIROp_RWStructuredBufferLoad (shader-slang#4523)
* Fix the type error in kIROp_RWStructuredBufferLoad In StructuredBuffer::Load(), we allow any type of integer as the input. However, when emitting glsl code, StructuredBuffer::Load(index) will be translated to the subscript index of the buffer, e.g. buffer[index], however, glsl doesn't allow 64bit integer as the subscript. So the easiest fix is to convert the index to uint when emitting glsl. * Add commit
1 parent fff79c3 commit bd01bd3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

source/slang/slang-emit-glsl.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,10 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
20682068

20692069
emitOperand(inst->getOperand(0), leftSide(outerPrec, prec));
20702070
m_writer->emit("._data[");
2071+
// glsl only support int/uint as array index
2072+
m_writer->emit("uint(");
20712073
emitOperand(inst->getOperand(1), getInfo(EmitOp::General));
2074+
m_writer->emit(")");
20722075
m_writer->emit("]");
20732076

20742077
maybeCloseParens(needClose);

tests/compute/byte-address-buffer-array.slang

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ void computeMain(uint3 threadId : SV_DispatchThreadID)
2626
// CHECK1: {{.*}}[0] = {{.*}}.data_0[0];
2727
// CHECK1: {{.*}}[1] = {{.*}}.data_0[1];
2828
// CHECK1: vec4 {{.*}}[2];
29-
// CHECK1: unpackStorage_0(buffer_0._data[0], {{.*}});
29+
// CHECK1: unpackStorage_0(buffer_0._data[uint(0)], {{.*}});
3030
// CHECK1: vec4 {{.*}}[2] = buffer_0._data[0] = packStorage_0({{.*}});
31-
// CHECK1: vec4 {{.*}} = buffer_2._data[1];
32-
// CHECK1: vec4 {{.*}} = buffer_2._data[1] = vec4(buffer_1._data[1], buffer_1._data[2], buffer_1._data[3], buffer_1._data[4]);
31+
// CHECK1: vec4 {{.*}} = buffer_2._data[uint(1)];
32+
// CHECK1: vec4 {{.*}} = buffer_2._data[1] = vec4(buffer_1._data[uint(1)], buffer_1._data[uint(2)], buffer_1._data[uint(3)], buffer_1._data[uint(4)]);
3333

3434
// CHECK2: float4 {{.*}}[int(2)] = (buffer_0).Load<float4 [int(2)] >(int(0));
3535
// CHECK2: buffer_0.Store(int(0),{{.*}});

0 commit comments

Comments
 (0)