summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-21 09:31:31 -0700
committerGitHub <noreply@github.com>2025-07-21 16:31:31 +0000
commita77d22bf3bfc3098b01e4886c3a63fb751edc704 (patch)
treef85a6c952bb68eb746b3a90de05dceb687fafeca
parent368ddbb7b99dfb939d20f53c35d05b2b4758bd64 (diff)
Fix C-style casts in GLSL pointer cast operations (#7841)
* Initial plan * Fix C-style casts in GLSL pointer cast operations Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
-rw-r--r--source/slang/slang-emit-glsl.cpp17
-rw-r--r--tests/language-feature/pointer-cast-glsl.slang14
2 files changed, 31 insertions, 0 deletions
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp
index 9d4f72b07..eb71286a2 100644
--- a/source/slang/slang-emit-glsl.cpp
+++ b/source/slang/slang-emit-glsl.cpp
@@ -2727,6 +2727,23 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
}
break;
}
+ case kIROp_CastPtrToInt:
+ case kIROp_CastIntToPtr:
+ case kIROp_PtrCast:
+ {
+ // For GLSL, emit constructor-style casts instead of C-style casts
+ auto prec = getInfo(EmitOp::Postfix);
+ EmitOpInfo outerPrec = inOuterPrec; // Make a mutable copy
+ bool needClose = maybeEmitParens(outerPrec, prec);
+
+ emitType(inst->getDataType());
+ m_writer->emit("(");
+ emitOperand(inst->getOperand(0), getInfo(EmitOp::General));
+ m_writer->emit(")");
+
+ maybeCloseParens(needClose);
+ return true;
+ }
default:
break;
}
diff --git a/tests/language-feature/pointer-cast-glsl.slang b/tests/language-feature/pointer-cast-glsl.slang
new file mode 100644
index 000000000..9e51c4328
--- /dev/null
+++ b/tests/language-feature/pointer-cast-glsl.slang
@@ -0,0 +1,14 @@
+//TEST:SIMPLE(filecheck=GLSL):-target glsl -entry main
+
+// Test that pointer casts in GLSL generate constructor-style casts instead of C-style casts
+// This addresses issue https://github.com/shader-slang/slang/issues/7838
+
+//GLSL: BufferPointer__S1_2(address_0)
+
+[shader("vertex")]
+float4 main(uint vertexID : SV_VertexID, uint64_t address) : SV_Position
+{
+ // This should generate BufferPointer(address) instead of (BufferPointer)address in GLSL
+ let buffer = ConstBufferPointer<float4>(address);
+ return buffer[vertexID];
+} \ No newline at end of file