From 8f6c6e333c06ae1c3b9f00396563c14a2ae09b4d Mon Sep 17 00:00:00 2001 From: Darren Wihandi <65404740+fairywreath@users.noreply.github.com> Date: Sun, 27 Apr 2025 14:31:34 -0600 Subject: Emit SPIRV NonReadable decoration for WTexture* (#6922) --- source/slang/slang-emit-glsl.cpp | 10 ++++++++-- source/slang/slang-emit-spirv.cpp | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 848d9c08d..5e9fa7f70 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -1837,8 +1837,9 @@ bool GLSLSourceEmitter::tryEmitGlobalParamImpl(IRGlobalParam* varDecl, IRType* v void GLSLSourceEmitter::emitImageFormatModifierImpl(IRInst* varDecl, IRType* varType) { - // As a special case, if we are emitting a GLSL declaration - // for an HLSL `RWTexture*` then we need to emit a `format` layout qualifier. + // Special cases when emitting a GLSL declaration for HLSL/Slang `RWTexture* and `WTexture*`: + // - Emit a `format` layout qualifier. + // - Emit `writeonly` memory qualifier for `WTexture*`. if (auto resourceType = as(unwrapArray(varType))) { @@ -1855,6 +1856,11 @@ void GLSLSourceEmitter::emitImageFormatModifierImpl(IRInst* varDecl, IRType* var default: break; } + + if (resourceType->getAccess() == SLANG_RESOURCE_ACCESS_WRITE) + { + m_writer->emit("writeonly\n"); + } } } diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index d07d587e5..e4b5c2f4d 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -2767,6 +2767,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex param->getDataType(), storageClass); maybeEmitPointerDecoration(varInst, param); + maybeEmitWriteOnlyImageDecoration(varInst, param); if (layout) emitVarLayout(param, varInst, layout); emitDecorations(param, getID(varInst)); @@ -5686,6 +5687,25 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex maybeEmitPointerDecoration(varInst, inst->getDataType(), as(inst), inst->getOp()); } + void maybeEmitWriteOnlyImageDecoration(SpvInst* varInst, IRInst* inst) + { + auto ptrType = as(inst->getDataType()); + if (!ptrType) + return; + auto textureType = as(ptrType->getValueType()); + if (!textureType) + return; + + if (textureType->getAccess() == SLANG_RESOURCE_ACCESS_WRITE) + { + emitOpDecorate( + getSection(SpvLogicalSectionID::Annotations), + nullptr, + getID(varInst), + SpvDecorationNonReadable); + } + } + SpvInst* emitParam(SpvInstParent* parent, IRInst* inst) { auto paramSpvInst = emitOpFunctionParameter(parent, inst, inst->getFullType()); -- cgit v1.2.3