summaryrefslogtreecommitdiffstats
path: root/source/slang/parameter-binding.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-09-21 11:12:23 -0700
committerGitHub <noreply@github.com>2018-09-21 11:12:23 -0700
commit7250ed1e73351b6f3f72d6a42a90f2878f78b0f8 (patch)
tree8d7663dacadc454fab448a0ddcb717eee4419b2f /source/slang/parameter-binding.cpp
parent738bcb82d0327c463625ee6fcdf14b52e766cedc (diff)
Remove the "hack sampler" workaround (#648)
* Update glslang version * Fix build for new glslang The latest glslang required a few changes to our manual build for their code (because we are *not* taking a dependency on CMake). * Rebuild project files using premake, which picks up a few files added to glslang, but also a few diffs in Slang's own project files in cases where they were edited manually instead of using premake. * Fix up the declaration our our device limits (which are inentionally set to *not* limit what code passes through our glslang), because the underlying structure definition in glslang has changed. This is a kludgy bit of glslang's design, but it doesn't make sense for us to invest in a more serious workaround. * Remove the "hack sampler" workaround When the `GL_KHR_vulkan_glsl` spec was introduced to allow GLSL to be compiled for Vulkan SPIR-V, it made an annoying mistake by leaving a few builtins as taking `sampler2D`, etc. when the equivalent SPIR-V operations only require a `texture2D`, etc. The relevant builtins are: * `textureSize` * `textureQueryLevels` * `textureSamples` * `texelFetch` * `texelFetchOffset` This means that shader code that wanted to use those operations needed to conspire to have a `sampler` handy so they could write, e.g.: ```glsl vec4 val = texelFetch(sampler2D(myTexture, someRandomSampler), p, lod); ``` when what they really wanted was this: ```glsl vec4 val = texelFetch(myTexture, p, lod); ``` That is annoying but probably something each to work around for a GLSL programmer, but when cross-compiling from HLSL, you might have an operation like: ```hlsl float4 val = myTexure.Load(p); ``` in which case a cross-compiler needs to manufacture a sampler out of thin air. If the shader happened to use a sampler for something else you could snag that, but in the worse case you had to cross-compile to GLSL that declared a new sampler. Slang did this by declaring a sampler called `SLANG_hack_samplerForTexelFetch` (because `texelFetch` is the operation that first surfaced the issue). For complex reasons we *always* define this sampler, even if we turn out not to need it in a particular output kernel. This choice has a bunch of annoying consequences: * There is *always* a sampler defined in descriptor set zero, because that's where we put the hack sampler, so a user-defined parameter block always has a set number of 1 or greater (see #646). * The hack sampler shows up in reflection output because users need to size their descriptor sets appropriately to pass along this sampler that won't actually be used if they don't want to get debug spew from the validation layers. We filed an issue on glslang about this problem, and eventually some kind folks from the gamedev community (who also saw the same problem) defined an extension spec (`GL_EXT_samplerless_texture_functions`) to fix the underlying issue and contributed a patch to glslang to make it support that extension. This change just backs the hack out of Slang now that we have a glslang version that supports the extension to get past the defect in the original GLSL-for-Vulkan definition. Besides yanking out the code for the hack, we also change the relevant builtins to declare that they require this new GLSL extension (so that we properly request it from glslang when the builtins are used), and fix some reflection test cases that exposed the existence of the "hack sampler." * Fixup: syntax error in stdlib generator files * Remove more code for hack sampler There was logic to ensure we always have a "default" register space/set when cross-compiling, because the hack sampler would need it. This is no longer necessary once we remove the hack sampler. * Fix expected test output. Fixing the root cause of issue #646 means that one of our test cases that tickles that issue now produces different output (luckily it can now be used as a regression test for the issue).
Diffstat (limited to 'source/slang/parameter-binding.cpp')
-rw-r--r--source/slang/parameter-binding.cpp79
1 files changed, 0 insertions, 79 deletions
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp
index 40491c4df..34b490c71 100644
--- a/source/slang/parameter-binding.cpp
+++ b/source/slang/parameter-binding.cpp
@@ -2231,44 +2231,6 @@ static void collectParameters(
}
}
-static bool isGLSLCrossCompilerNeeded(
- TargetRequest* targetReq)
-{
- auto compileReq = targetReq->compileRequest;
-
- // We only need cross-compilation if we
- // are targetting something GLSL-based.
- switch (targetReq->target)
- {
- default:
- return false;
-
- case CodeGenTarget::GLSL:
- case CodeGenTarget::SPIRV:
- case CodeGenTarget::SPIRVAssembly:
- break;
- }
-
- // If we `import`ed any Slang code, then the
- // cross compiler is definitely needed, to
- // translate that Slang over to GLSL.
- if (compileReq->loadedModulesList.Count() != 0)
- return true;
-
- // If there are any non-GLSL translation units,
- // then we need to cross compile those...
- for (auto tu : compileReq->translationUnits)
- {
- if (tu->sourceLanguage != SourceLanguage::GLSL)
- return true;
- }
-
- // If we get to this point, then we have plain vanilla
- // GLSL input, with no `import` declarations, so we
- // are able to output GLSL without cross compilation.
- return false;
-}
-
void generateParameterBindings(
TargetRequest* targetReq)
{
@@ -2356,12 +2318,6 @@ void generateParameterBindings(
}
}
}
- // If we are having to insert our "hack" default sampler, then
- // we need to put it in the default space.
- if (isGLSLCrossCompilerNeeded(targetReq))
- {
- needDefaultSpace = true;
- }
// If we need a space for default bindings, then allocate it here.
if (needDefaultSpace)
@@ -2504,39 +2460,6 @@ void generateParameterBindings(
globalScopeLayout = globalConstantBufferLayout;
}
- // Final final step: pick a binding for the "hack sampler", if needed...
- //
- // We only want to do this if the GLSL cross-compilation support is
- // being invoked, so that we don't gum up other shaders.
- if(isGLSLCrossCompilerNeeded(targetReq))
- {
- UInt space = sharedContext.defaultSpace;
- auto hackSamplerUsedRanges = findUsedRangeSetForSpace(&context, space);
-
- UInt binding = hackSamplerUsedRanges->usedResourceRanges[(int)LayoutResourceKind::DescriptorTableSlot].Allocate(nullptr, 1);
-
- programLayout->bindingForHackSampler = (int)binding;
-
- RefPtr<Variable> var = new Variable();
- var->nameAndLoc.name = compileReq->getNamePool()->getName("SLANG_hack_samplerForTexelFetch");
- var->type.type = getSamplerStateType(compileReq->mSession);
-
- auto typeLayout = new TypeLayout();
- typeLayout->type = var->type.type;
- typeLayout->addResourceUsage(LayoutResourceKind::DescriptorTableSlot, 1);
-
- auto varLayout = new VarLayout();
- varLayout->varDecl = makeDeclRef(var.Ptr());
- varLayout->typeLayout = typeLayout;
- auto resInfo = varLayout->AddResourceInfo(LayoutResourceKind::DescriptorTableSlot);
- resInfo->index = binding;
- resInfo->space = space;
-
- programLayout->hackSamplerVar = var;
-
- globalScopeStructLayout->fields.Add(varLayout);
- }
-
// We now have a bunch of layout information, which we should
// record into a suitable object that represents the program
RefPtr<VarLayout> globalVarLayout = new VarLayout();
@@ -2561,8 +2484,6 @@ RefPtr<ProgramLayout> specializeProgramLayout(
RefPtr<ProgramLayout> newProgramLayout;
newProgramLayout = new ProgramLayout();
newProgramLayout->targetRequest = targetReq;
- newProgramLayout->bindingForHackSampler = programLayout->bindingForHackSampler;
- newProgramLayout->hackSamplerVar = programLayout->hackSamplerVar;
newProgramLayout->globalGenericParams = programLayout->globalGenericParams;
List<RefPtr<TypeLayout>> paramTypeLayouts;