diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2024-04-25 09:18:32 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-25 09:18:32 -0400 |
| commit | 366a947cdf2e3c6958b7a9e17d561ce76ab0f594 (patch) | |
| tree | ca305c7315806b51c3922d334b10b5f203a0b219 /source/slang/slang-lower-to-ir.cpp | |
| parent | 52dcb5bd44aa15f07826062c53fae344d55959e9 (diff) | |
Support derivative functions in compute & capabilities adjustments (#4014)
* Support derivative functions in compute & capabilities adjustments
fixes #4000
PR implements derivative functions in compute shaders properly so we have the functionality for SPIR-V & GLSL. Tests reflect fragment and compute paths.
PR also adjusts capabilities to correct wrong SPRI-V target capabilities for when using textures.
Remarks:
1. __requireComputeDerivative(); is a intrinsic_op and not modifier since inlining will destroy the modifier.
2. Derivative mode is tied to an entry point decoration `[DerivativeGroupQuad]`/`[DerivativeGroupLinear]` or GLSL syntax ``derivative_group_linearNV`. Default is to set the mode to `[DerivativeGroupQuad]`
* remove -emit-spirv-directly
* fixes
1. fix minor issue fwidth change where I returned the wrong type
2. fix issue where glslang{glsl->spirv} is wrong, so we don't run that test and just run the glsl test & direct spir-v test for intrinsic-texture.slang
* adjust as per review and refine code
1. add test to ensure multi-diverging-in-logic entry points work -- 2 functions which may cause computeDerivatives + 1 that uses, 1 that does not.
2. naming
3. use entry point ref graph for c-like-targets
4. reordered some code to util's and removed `static linline` since that was just for ease of coding on my end (should not have been pushed).
* Grammer
* split up source file + issolate GLSL emit path change.
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 83 |
1 files changed, 69 insertions, 14 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index a600963a7..e4fc33e33 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -12,6 +12,7 @@ #include "slang-ir-bit-field-accessors.h" #include "slang-ir-loop-inversion.h" #include "slang-ir.h" +#include "slang-ir-util.h" #include "slang-ir-constexpr.h" #include "slang-ir-dce.h" #include "slang-ir-diff-call.h" @@ -7264,26 +7265,61 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> #undef IGNORED_CASE + void getAllEntryPointsNoOverride(List<IRInst*>& entryPoints) + { + if(entryPoints.getCount() != 0 ) + return; + for(const auto d : context->irBuilder->getModule()->getModuleInst()->getGlobalInsts()) + if(d->findDecoration<IREntryPointDecoration>()) + entryPoints.add(d); + } + LoweredValInfo visitEmptyDecl(EmptyDecl* decl) { + bool verifyComputeDerivativeGroupModifier = false; + List<IRInst*> entryPoints {}; for(const auto modifier : decl->modifiers) { if(const auto layoutLocalSizeAttr = as<GLSLLayoutLocalSizeAttribute>(modifier)) { - for(const auto d : context->irBuilder->getModule()->getModuleInst()->getGlobalInsts()) - { - if(d->findDecoration<IREntryPointDecoration>()) - { - getBuilder()->addNumThreadsDecoration( + verifyComputeDerivativeGroupModifier = true; + getAllEntryPointsNoOverride(entryPoints); + for(auto d : entryPoints) + as<IRNumThreadsDecoration>(getBuilder()->addNumThreadsDecoration( d, getSimpleVal(context, lowerVal(context, layoutLocalSizeAttr->x)), getSimpleVal(context, lowerVal(context, layoutLocalSizeAttr->y)), getSimpleVal(context, lowerVal(context, layoutLocalSizeAttr->z)) - ); - } - } + )); + } + else if(as<GLSLLayoutDerivativeGroupQuadAttribute>(modifier)) + { + verifyComputeDerivativeGroupModifier = true; + getAllEntryPointsNoOverride(entryPoints); + for(auto d : entryPoints) + getBuilder()->addSimpleDecoration<IRDerivativeGroupQuadDecoration>(d); + } + else if(as<GLSLLayoutDerivativeGroupLinearAttribute>(modifier)) + { + verifyComputeDerivativeGroupModifier = true; + getAllEntryPointsNoOverride(entryPoints); + for(auto d : entryPoints) + getBuilder()->addSimpleDecoration<IRDerivativeGroupLinearDecoration>(d); } } + + if(!verifyComputeDerivativeGroupModifier) + return LoweredValInfo(); + for(auto d : entryPoints) + { + verifyComputeDerivativeGroupModifiers( + getSink(), + decl->loc, + d->findDecoration<IRDerivativeGroupQuadDecoration>(), + d->findDecoration<IRDerivativeGroupLinearDecoration>(), + d->findDecoration<IRNumThreadsDecoration>()); + } + return LoweredValInfo(); } @@ -9677,6 +9713,9 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> addBitFieldAccessorDecorations(irFunc, decl); + IRNumThreadsDecoration* numThreadsDecor = nullptr; + IRDecoration* derivativeGroupQuadDecor = nullptr; + IRDecoration* derivativeGroupLinearDecor = nullptr; for (auto modifier : decl->modifiers) { if (as<RequiresNVAPIAttribute>(modifier)) @@ -9691,6 +9730,14 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> { getBuilder()->addSimpleDecoration<IRNoInlineDecoration>(irFunc); } + else if (auto derivativeGroupQuadMod = as<DerivativeGroupQuadAttribute>(modifier)) + { + derivativeGroupQuadDecor = getBuilder()->addSimpleDecoration<IRDerivativeGroupQuadDecoration>(irFunc); + } + else if (auto derivativeGroupLinearMod = as<DerivativeGroupLinearAttribute>(modifier)) + { + derivativeGroupLinearDecor = getBuilder()->addSimpleDecoration<IRDerivativeGroupLinearDecoration>(irFunc); + } else if (auto instanceAttr = as<InstanceAttribute>(modifier)) { IRIntLit* intLit = _getIntLitFromAttribute(getBuilder(), instanceAttr); @@ -9703,12 +9750,13 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> } else if (auto numThreadsAttr = as<NumThreadsAttribute>(modifier)) { - getBuilder()->addNumThreadsDecoration( - irFunc, - getSimpleVal(context, lowerVal(context, numThreadsAttr->x)), - getSimpleVal(context, lowerVal(context, numThreadsAttr->y)), - getSimpleVal(context, lowerVal(context, numThreadsAttr->z)) - ); + numThreadsDecor = as<IRNumThreadsDecoration>( + getBuilder()->addNumThreadsDecoration( + irFunc, + getSimpleVal(context, lowerVal(context, numThreadsAttr->x)), + getSimpleVal(context, lowerVal(context, numThreadsAttr->y)), + getSimpleVal(context, lowerVal(context, numThreadsAttr->z)) + )); } else if (auto waveSizeAttr = as<WaveSizeAttribute>(modifier)) { @@ -9862,6 +9910,13 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> getBuilder()->addDecoration(irFunc, kIROp_NonDynamicUniformReturnDecoration); } + verifyComputeDerivativeGroupModifiers( + getSink(), + decl->loc, + derivativeGroupQuadDecor, + derivativeGroupLinearDecor, + numThreadsDecor); + if (!isInline) { // If there are any constant expr rate parameters, we should inline this function. |
