diff options
| author | Anders Leino <aleino@nvidia.com> | 2024-11-06 13:14:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-06 13:14:35 +0200 |
| commit | f8294202ce8d5658f6308eeaed634058db9bbb4b (patch) | |
| tree | 400d8379f8bd49749d0985e21eaf9e3deb5a356d /source/slang | |
| parent | 79056cd7e0ba261a007e21a98a6f49cb0b032e25 (diff) | |
Make various parameters and return types require specialization when targeting WGSL (#5483)
Structured buffer types translate to array types in the WGSL emitter.
WGSL doesn't allow passing runtime-sized arrays to functions.
Similarly for pointers to texture handles.
Also, structured buffers (runtime-sized arrays) cannot be returned in WGSL.
This closes issue #5228, issue #5278 and issue #5288 by enabling specialized functions
to be generated in these cases, in order to work around these constraints.
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-compiler.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir-specialize-resources.cpp | 13 | ||||
| -rw-r--r-- | source/slang/slang-ir-specialize-resources.h | 1 | ||||
| -rw-r--r-- | source/slang/slang-type-layout.cpp | 14 |
4 files changed, 29 insertions, 2 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 624e6ec3b..9fea93b7c 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1958,6 +1958,9 @@ bool isCUDATarget(TargetRequest* targetReq); // Are we generating code for a CPU target bool isCPUTarget(TargetRequest* targetReq); +/// Are we generating code for the WebGPU API? +bool isWGPUTarget(TargetRequest* targetReq); + /// A request to generate output in some target format. class TargetRequest : public RefObject { diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp index 6aca4bbc7..56f468ac7 100644 --- a/source/slang/slang-ir-specialize-resources.cpp +++ b/source/slang/slang-ir-specialize-resources.cpp @@ -67,7 +67,10 @@ struct ResourceParameterSpecializationCondition : FunctionCallSpecializeConditio else return isIllegalGLSLParameterType(type); } - + else if (isWGPUTarget(targetRequest)) + { + return isIllegalWGSLParameterType(type); + } // For now, we will not treat any other parameters as // needing specialization, even if they use resource @@ -1220,7 +1223,7 @@ bool specializeResourceOutputs( HashSet<IRFunc*>& unspecializableFuncs) { auto targetRequest = codeGenContext->getTargetReq(); - if (isD3DTarget(targetRequest) || isKhronosTarget(targetRequest)) + if (isD3DTarget(targetRequest) || isKhronosTarget(targetRequest) || isWGPUTarget(targetRequest)) { } else @@ -1354,4 +1357,10 @@ bool isIllegalSPIRVParameterType(IRType* type, bool isArray) } return false; } + +bool isIllegalWGSLParameterType(IRType* type) +{ + return isIllegalGLSLParameterType(type); +} + } // namespace Slang diff --git a/source/slang/slang-ir-specialize-resources.h b/source/slang/slang-ir-specialize-resources.h index 911fa3bb9..feb61c026 100644 --- a/source/slang/slang-ir-specialize-resources.h +++ b/source/slang/slang-ir-specialize-resources.h @@ -26,5 +26,6 @@ bool specializeResourceUsage(CodeGenContext* codeGenContext, IRModule* irModule) bool isIllegalGLSLParameterType(IRType* type); bool isIllegalSPIRVParameterType(IRType* type, bool isArray); +bool isIllegalWGSLParameterType(IRType* type); } // namespace Slang diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index a63d6401e..e36e54531 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -2397,6 +2397,20 @@ bool isCUDATarget(TargetRequest* targetReq) } } +bool isWGPUTarget(TargetRequest* targetReq) +{ + switch (targetReq->getTarget()) + { + default: + return false; + + case CodeGenTarget::WGSL: + case CodeGenTarget::WGSLSPIRV: + case CodeGenTarget::WGSLSPIRVAssembly: + return true; + } +} + SourceLanguage getIntermediateSourceLanguageForTarget(TargetProgram* targetProgram) { // If we are emitting directly, there is no intermediate source language |
