From e1940e53c0f76e91a2616693b261beb9190015be Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:46:24 -0400 Subject: For C-like targets, emit resource declarations before other globals (#2843) * For C-like targets, emit resource declarations before other globals * Remove unused tests --- source/slang/slang-emit-c-like.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source') diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index c122c13f2..34467d25d 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -3769,6 +3769,18 @@ void CLikeSourceEmitter::computeEmitActions(IRModule* module, List& ctx.moduleInst = module->getModuleInst(); ctx.actions = &ioActions; + for(auto inst : module->getGlobalInsts()) + { + // Emit all resource-typed objects first. This is to avoid an odd scenario in HLSL + // where not using a resource type in a resource definition before the same type + // is used for a function parameter causes HLSL to complain about an 'incomplete type' + // + if ( isResourceType(inst->getDataType()) ) + { + ensureGlobalInst(&ctx, inst, EmitAction::Level::Definition); + } + } + for(auto inst : module->getGlobalInsts()) { if( as(inst) ) @@ -3778,6 +3790,10 @@ void CLikeSourceEmitter::computeEmitActions(IRModule* module, List& continue; } + // Skip resource types in this pass. + if ( isResourceType(inst->getDataType()) ) + continue; + ensureGlobalInst(&ctx, inst, EmitAction::Level::Definition); } } -- cgit v1.2.3