diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-01 10:55:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-01 10:55:48 -0700 |
| commit | 32b843215b2e80c23c1fbcf02150c52a6304a447 (patch) | |
| tree | 5892ef28f2e603781af4c6dde5b2a1dc1112c125 /source | |
| parent | 4c6b0a2831a7edd1419bd0b2e6edd089080e07be (diff) | |
Allow implicit 'uniform' entrypoint parameters. (#4765)
* Allow impliocit 'uniform' entrypoint parameters.
* Fix.
* Fix.
* Fix.
* Fix.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-shader.cpp | 76 | ||||
| -rw-r--r-- | source/slang/slang-diagnostic-defs.h | 3 |
2 files changed, 60 insertions, 19 deletions
diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp index a802906a7..99205e522 100644 --- a/source/slang/slang-check-shader.cpp +++ b/source/slang/slang-check-shader.cpp @@ -333,7 +333,17 @@ namespace Slang bool isBuiltinParameterType(Type* type) { - return as<BuiltinType>(type) != nullptr; + if (!as<BuiltinType>(type)) + return false; + if (as<BasicExpressionType>(type)) + return false; + if (as<VectorExpressionType>(type)) + return false; + if (as<MatrixExpressionType>(type)) + return false; + if (auto arrayType = as<ArrayExpressionType>(type)) + return isBuiltinParameterType(arrayType->getElementType()); + return true; } bool doStructFieldsHaveSemanticImpl(Type* type, HashSet<Type*>& seenTypes) @@ -345,18 +355,20 @@ namespace Slang if (!structDecl) return false; seenTypes.add(type); + bool hasFields = false; for (auto field : structDecl->getFields()) { + hasFields = true; if (!field->findModifier<HLSLSemantic>()) { - if (!seenTypes.contains(type)) + if (!seenTypes.contains(field->getType())) { if (!doStructFieldsHaveSemanticImpl(field->getType(), seenTypes)) return false; } } } - return true; + return hasFields; } bool doStructFieldsHaveSemantic(Type* type) @@ -488,30 +500,58 @@ namespace Slang } } + bool canHaveVaryingInput = false; + switch (stage) + { + case Stage::Vertex: + case Stage::Fragment: + case Stage::Miss: + case Stage::AnyHit: + case Stage::ClosestHit: + case Stage::Callable: + case Stage::Geometry: + case Stage::Mesh: + case Stage::Hull: + case Stage::Domain: + canHaveVaryingInput = true; + break; + default: + break; + } + 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()); - } + addModifier(param, getCurrentASTBuilder()->create<HLSLUniformModifier>()); + continue; } } + + if (canHaveVaryingInput) + continue; + + // If the stage doesn't allow varying input/output, + // we require the parameter to be associated with a system value semantic. + if (param->hasModifier<HLSLUniformModifier>()) + continue; + if (param->findModifier<HLSLSemantic>()) + continue; + + bool isBuiltinType = isBuiltinParameterType(param->getType()); + if (isBuiltinType) + continue; + + if (doStructFieldsHaveSemantic(param->getType())) + continue; + + // The user is defining a parameter with no 'uniform' modifier for a stage that doesn't support + // varying input/output. We will automatically convert it to a 'uniform' parameter, and diagnose a warning. + addModifier(param, getCurrentASTBuilder()->create<HLSLUniformModifier>()); + sink->diagnose(param, Diagnostics::nonUniformEntryPointParameterTreatedAsUniform, param->getName()); } for (auto target : linkage->targets) diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index cb3e39dd4..487f264d5 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -649,7 +649,8 @@ DIAGNOSTIC(38033, Error, cannotUseNoDiffInNonDifferentiableFunc, "cannot use 'no DIAGNOSTIC(38034, Error, cannotUseConstRefOnDifferentiableParameter, "cannot use '__constref' on a differentiable parameter.") DIAGNOSTIC(38034, Error, cannotUseConstRefOnDifferentiableMemberMethod, "cannot use '[constref]' on a differentiable member method of a differentiable type.") -DIAGNOSTIC(38040, Error, nonUniformEntryPointParameterMustHaveSemantic, "non-uniform parameter '$0' must have a system-value semantic.") +DIAGNOSTIC(38040, Warning, nonUniformEntryPointParameterTreatedAsUniform, "parameter '$0' is treated as 'uniform' because it does not have a system-value semantic.") + DIAGNOSTIC(38200, Error, recursiveModuleImport, "module `$0` recursively imports itself") DIAGNOSTIC(39999, Error, errorInImportedModule, "import of module '$0' failed because of a compilation error") |
