diff options
| author | Yong He <yonghe@outlook.com> | 2023-11-01 21:42:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-01 21:42:12 -0700 |
| commit | 6aca3813c4ccc496c0f9b2db293acb546aa11d2d (patch) | |
| tree | 5281f0ac62946787db90409c1ab3da5ed3f0fc5c /source/slang/slang-check-shader.cpp | |
| parent | 532c4322c9d9ab2c95a5bb573c89062456b59236 (diff) | |
Parameter binding and gfx fixes. (#3302)
* Parameter binding and gfx fixes.
* Add diagnostics on entry point parameters.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-shader.cpp')
| -rw-r--r-- | source/slang/slang-check-shader.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp index d2ac0d12f..00c924982 100644 --- a/source/slang/slang-check-shader.cpp +++ b/source/slang/slang-check-shader.cpp @@ -301,6 +301,56 @@ namespace Slang return entryPointFuncDecl; } + // Is a entry pointer parmaeter of `type` always a uniform parameter? + bool isUniformParameterType(Type* type) + { + if (as<ResourceType>(type)) + return true; + if (as<HLSLStructuredBufferTypeBase>(type)) + return true; + if (as<UntypedBufferResourceType>(type)) + return true; + if (as<UniformParameterGroupType>(type)) + return true; + if (as<SamplerStateType>(type)) + return true; + return false; + } + + bool isBuiltinParameterType(Type* type) + { + return as<BuiltinType>(type) != nullptr; + } + + bool doStructFieldsHaveSemanticImpl(Type* type, HashSet<Type*>& seenTypes) + { + auto declRefType = as<DeclRefType>(type); + if (!declRefType) + return false; + auto structDecl = as<StructDecl>(declRefType->getDeclRef().getDecl()); + if (!structDecl) + return false; + seenTypes.add(type); + for (auto field : structDecl->getFields()) + { + if (!field->findModifier<HLSLSemantic>()) + { + if (!seenTypes.contains(type)) + { + if (!doStructFieldsHaveSemanticImpl(field->getType(), seenTypes)) + return false; + } + } + } + return true; + } + + bool doStructFieldsHaveSemantic(Type* type) + { + HashSet<Type*> seenTypes; + return doStructFieldsHaveSemanticImpl(type, seenTypes); + } + // Validate that an entry point function conforms to any additional // constraints based on the stage (and profile?) it specifies. void validateEntryPoint( @@ -424,6 +474,32 @@ namespace Slang } } } + + for (const auto& param : entryPointFuncDecl->getParameters()) + { + if (isUniformParameterType(param->getType())) + { + // Automatically add `uniform` modifier to entry point parameters. + if (!param->hasModifier<HLSLUniformModifier>()) + addModifier(param, getCurrentASTBuilder()->create<HLSLUniformModifier>()); + } + else if (isBuiltinParameterType(param->getType())) + { + } + else + { + // For all non-uniform parameters of a general type, we require the parameter be associated with + // a system value semantic. + if (!param->hasModifier<HLSLUniformModifier>()) + { + if (!param->findModifier<HLSLSemantic>()) + { + if (!doStructFieldsHaveSemantic(param->getType())) + sink->diagnose(param, Diagnostics::nonUniformEntryPointParameterMustHaveSemantic, param->getName()); + } + } + } + } } // Given an entry point specified via API or command line options, |
