Skip to content

Commit

Permalink
Fix the type error in kIROp_RWStructuredBufferLoad (#4523)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kaizhangNV authored Jul 2, 2024
1 parent fff79c3 commit bd01bd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions source/slang/slang-emit-glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,10 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu

emitOperand(inst->getOperand(0), leftSide(outerPrec, prec));
m_writer->emit("._data[");
// glsl only support int/uint as array index
m_writer->emit("uint(");
emitOperand(inst->getOperand(1), getInfo(EmitOp::General));
m_writer->emit(")");
m_writer->emit("]");

maybeCloseParens(needClose);
Expand Down
6 changes: 3 additions & 3 deletions tests/compute/byte-address-buffer-array.slang
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void computeMain(uint3 threadId : SV_DispatchThreadID)
// CHECK1: {{.*}}[0] = {{.*}}.data_0[0];
// CHECK1: {{.*}}[1] = {{.*}}.data_0[1];
// CHECK1: vec4 {{.*}}[2];
// CHECK1: unpackStorage_0(buffer_0._data[0], {{.*}});
// CHECK1: unpackStorage_0(buffer_0._data[uint(0)], {{.*}});
// CHECK1: vec4 {{.*}}[2] = buffer_0._data[0] = packStorage_0({{.*}});
// CHECK1: vec4 {{.*}} = buffer_2._data[1];
// CHECK1: vec4 {{.*}} = buffer_2._data[1] = vec4(buffer_1._data[1], buffer_1._data[2], buffer_1._data[3], buffer_1._data[4]);
// CHECK1: vec4 {{.*}} = buffer_2._data[uint(1)];
// 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)]);

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

0 comments on commit bd01bd3

Please sign in to comment.