From 6aca3813c4ccc496c0f9b2db293acb546aa11d2d Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 1 Nov 2023 21:42:12 -0700 Subject: Parameter binding and gfx fixes. (#3302) * Parameter binding and gfx fixes. * Add diagnostics on entry point parameters. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-check-shader.cpp | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'source/slang/slang-check-shader.cpp') 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(type)) + return true; + if (as(type)) + return true; + if (as(type)) + return true; + if (as(type)) + return true; + if (as(type)) + return true; + return false; + } + + bool isBuiltinParameterType(Type* type) + { + return as(type) != nullptr; + } + + bool doStructFieldsHaveSemanticImpl(Type* type, HashSet& seenTypes) + { + auto declRefType = as(type); + if (!declRefType) + return false; + auto structDecl = as(declRefType->getDeclRef().getDecl()); + if (!structDecl) + return false; + seenTypes.add(type); + for (auto field : structDecl->getFields()) + { + if (!field->findModifier()) + { + if (!seenTypes.contains(type)) + { + if (!doStructFieldsHaveSemanticImpl(field->getType(), seenTypes)) + return false; + } + } + } + return true; + } + + bool doStructFieldsHaveSemantic(Type* type) + { + HashSet 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()) + addModifier(param, getCurrentASTBuilder()->create()); + } + 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()) + { + if (!param->findModifier()) + { + if (!doStructFieldsHaveSemantic(param->getType())) + sink->diagnose(param, Diagnostics::nonUniformEntryPointParameterMustHaveSemantic, param->getName()); + } + } + } + } } // Given an entry point specified via API or command line options, -- cgit v1.2.3