diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-09-21 11:12:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-21 11:12:23 -0700 |
| commit | 7250ed1e73351b6f3f72d6a42a90f2878f78b0f8 (patch) | |
| tree | 8d7663dacadc454fab448a0ddcb717eee4419b2f | |
| parent | 738bcb82d0327c463625ee6fcdf14b52e766cedc (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).
22 files changed, 71 insertions, 194 deletions
diff --git a/external/glslang b/external/glslang -Subproject 5a867acad5da07cfb59a1eaadf8e366fb58bbed +Subproject 088da33263b320c3713b39d5f1928e503f07e67 diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj index 2944ee9dd..8ec4b7031 100644 --- a/source/core/core.vcxproj +++ b/source/core/core.vcxproj @@ -213,4 +213,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project>
\ No newline at end of file +</Project>
\ No newline at end of file diff --git a/source/core/core.vcxproj.filters b/source/core/core.vcxproj.filters index 9e90aaa77..f30cad939 100644 --- a/source/core/core.vcxproj.filters +++ b/source/core/core.vcxproj.filters @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Filter Include="Header Files"> @@ -54,6 +54,12 @@ <ClInclude Include="slang-math.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="slang-memory-arena.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-random-generator.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="slang-string-util.h"> <Filter>Header Files</Filter> </ClInclude> @@ -75,12 +81,6 @@ <ClInclude Include="type-traits.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="slang-memory-arena.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="slang-random-generator.h"> - <Filter>Header Files</Filter> - </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="platform.cpp"> @@ -92,6 +92,12 @@ <ClCompile Include="slang-io.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="slang-memory-arena.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="slang-random-generator.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="slang-string-util.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -107,12 +113,6 @@ <ClCompile Include="token-reader.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="slang-memory-arena.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="slang-random-generator.cpp"> - <Filter>Source Files</Filter> - </ClCompile> </ItemGroup> <ItemGroup> <None Include="core.natvis"> diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp index ae61823d1..2f5f17e42 100644 --- a/source/slang-glslang/slang-glslang.cpp +++ b/source/slang-glslang/slang-glslang.cpp @@ -46,7 +46,8 @@ static TBuiltInResource gResources = UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, - UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, { true, true, true, true, true, true, true, true, true, } }; diff --git a/source/slang-glslang/slang-glslang.vcxproj b/source/slang-glslang/slang-glslang.vcxproj index d1975cba5..28e64e8de 100644 --- a/source/slang-glslang/slang-glslang.vcxproj +++ b/source/slang-glslang/slang-glslang.vcxproj @@ -176,6 +176,7 @@ <ClInclude Include="..\..\external\glslang\SPIRV\Logger.h" /> <ClInclude Include="..\..\external\glslang\SPIRV\SPVRemapper.h" /> <ClInclude Include="..\..\external\glslang\SPIRV\SpvBuilder.h" /> + <ClInclude Include="..\..\external\glslang\SPIRV\SpvTools.h" /> <ClInclude Include="..\..\external\glslang\SPIRV\bitutils.h" /> <ClInclude Include="..\..\external\glslang\SPIRV\disassemble.h" /> <ClInclude Include="..\..\external\glslang\SPIRV\doc.h" /> @@ -213,6 +214,8 @@ <ClCompile Include="..\..\external\glslang\SPIRV\Logger.cpp" /> <ClCompile Include="..\..\external\glslang\SPIRV\SPVRemapper.cpp" /> <ClCompile Include="..\..\external\glslang\SPIRV\SpvBuilder.cpp" /> + <ClCompile Include="..\..\external\glslang\SPIRV\SpvPostProcess.cpp" /> + <ClCompile Include="..\..\external\glslang\SPIRV\SpvTools.cpp" /> <ClCompile Include="..\..\external\glslang\SPIRV\disassemble.cpp" /> <ClCompile Include="..\..\external\glslang\SPIRV\doc.cpp" /> <ClCompile Include="..\..\external\glslang\StandAlone\ResourceLimits.cpp" /> diff --git a/source/slang-glslang/slang-glslang.vcxproj.filters b/source/slang-glslang/slang-glslang.vcxproj.filters index 0d3841020..2e15ff5bd 100644 --- a/source/slang-glslang/slang-glslang.vcxproj.filters +++ b/source/slang-glslang/slang-glslang.vcxproj.filters @@ -39,6 +39,9 @@ <ClInclude Include="..\..\external\glslang\SPIRV\SpvBuilder.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\..\external\glslang\SPIRV\SpvTools.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="..\..\external\glslang\SPIRV\bitutils.h"> <Filter>Header Files</Filter> </ClInclude> @@ -146,6 +149,12 @@ <ClCompile Include="..\..\external\glslang\SPIRV\SpvBuilder.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\..\external\glslang\SPIRV\SpvPostProcess.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\..\external\glslang\SPIRV\SpvTools.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="..\..\external\glslang\SPIRV\disassemble.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index b5b78c2e5..fd8826de3 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -544,6 +544,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { { sb << "__glsl_version(450)\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; sb << "__target_intrinsic(glsl, \"("; int aa = 1; @@ -556,7 +557,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) lodStr.append(")"); } - String opStr = " = textureSize($P" + lodStr; + String opStr = " = textureSize($0" + lodStr; switch( access ) { case SLANG_RESOURCE_ACCESS_READ_WRITE: @@ -603,12 +604,12 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if(isMultisample) { - sb << ", ($" << aa++ << " = textureSamples($P))"; + sb << ", ($" << aa++ << " = textureSamples($0))"; } if (includeMipInfo) { - sb << ", ($" << aa++ << " = textureQueryLevels($P))"; + sb << ", ($" << aa++ << " = textureQueryLevels($0))"; } @@ -680,11 +681,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { - sb << "__target_intrinsic(glsl, \"texelFetch($P, $1, $3)\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, $1, $3)\")\n"; } else { - sb << "__target_intrinsic(glsl, \"texelFetch($P, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ")\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ")\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -696,11 +699,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { - sb << "__target_intrinsic(glsl, \"texelFetchOffset($P, $0, $1, $2)\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetchOffset($0, $0, $1, $2)\")\n"; } else { - sb << "__target_intrinsic(glsl, \"texelFetch($P, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ", $2)\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ", $2)\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -741,7 +746,8 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { case SLANG_RESOURCE_ACCESS_NONE: case SLANG_RESOURCE_ACCESS_READ: - sb << "__target_intrinsic(glsl, \"texelFetch($P, " << ivecN << "($1)"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, " << ivecN << "($1)"; if( !isMultisample ) { sb << ", 0"; diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index c69878112..d5b513d2f 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -559,6 +559,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { { sb << "__glsl_version(450)\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; sb << "__target_intrinsic(glsl, \"("; int aa = 1; @@ -571,7 +572,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) lodStr.append(")"); } - String opStr = " = textureSize($P" + lodStr; + String opStr = " = textureSize($0" + lodStr; switch( access ) { case SLANG_RESOURCE_ACCESS_READ_WRITE: @@ -618,12 +619,12 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if(isMultisample) { - sb << ", ($" << aa++ << " = textureSamples($P))"; + sb << ", ($" << aa++ << " = textureSamples($0))"; } if (includeMipInfo) { - sb << ", ($" << aa++ << " = textureQueryLevels($P))"; + sb << ", ($" << aa++ << " = textureQueryLevels($0))"; } @@ -695,11 +696,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { - sb << "__target_intrinsic(glsl, \"texelFetch($P, $1, $3)\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, $1, $3)\")\n"; } else { - sb << "__target_intrinsic(glsl, \"texelFetch($P, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ")\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ")\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -711,11 +714,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { - sb << "__target_intrinsic(glsl, \"texelFetchOffset($P, $0, $1, $2)\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetchOffset($0, $0, $1, $2)\")\n"; } else { - sb << "__target_intrinsic(glsl, \"texelFetch($P, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ", $2)\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ", $2)\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -756,7 +761,8 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { case SLANG_RESOURCE_ACCESS_NONE: case SLANG_RESOURCE_ACCESS_READ: - sb << "__target_intrinsic(glsl, \"texelFetch($P, " << ivecN << "($1)"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, " << ivecN << "($1)"; if( !isMultisample ) { sb << ", 0"; diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 1e833838c..381b3c7c8 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -115,8 +115,6 @@ struct SharedEmitContext ModuleDecl* program; - bool needHackSamplerForTexelFetch = false; - ExtensionUsageTracker extensionUsageTracker; UInt uniqueIDCounter = 1; @@ -3052,36 +3050,6 @@ struct EmitVisitor } break; - case 'P': - { - // Okay, we need a collosal hack to deal with the fact that GLSL `texelFetch()` - // for Vulkan seems to be completely broken by design. It's signature wants - // a `sampler2D` for consistency with its peers, but the actual SPIR-V operation - // ignores the sampler paart of it, and just used the `texture2D` part. - // - // The HLSL equivalent (e.g., `Texture2D.Load()`) doesn't provide a sampler - // argument, so we seemingly need to conjure one out of thin air. :( - // - // We are going to hack this *hard* for now. - - auto textureArg = args[0].get(); - if (auto baseTextureType = as<IRTextureType>(textureArg->getDataType())) - { - emitGLSLTextureOrTextureSamplerType(baseTextureType, "sampler"); - Emit("("); - emitIROperand(ctx, textureArg, mode); - Emit(","); - Emit("SLANG_hack_samplerForTexelFetch"); - context->shared->needHackSamplerForTexelFetch = true; - Emit(")"); - } - else - { - SLANG_UNEXPECTED("bad format in intrinsic definition"); - } - } - break; - case 'z': { // If we are calling a D3D texturing operation in the form t.Foo(s, ...), @@ -6204,14 +6172,6 @@ String emitEntryPoint( finalResultBuilder << sharedContext.extensionUsageTracker.glslExtensionRequireLines.ProduceString(); - if (sharedContext.needHackSamplerForTexelFetch) - { - finalResultBuilder - << "layout(set = 0, binding = " - << programLayout->bindingForHackSampler - << ") uniform sampler SLANG_hack_samplerForTexelFetch;\n"; - } - finalResultBuilder << code; String finalResult = finalResultBuilder.ProduceString(); diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index bf6c12788..b8cd7a4ad 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -1187,14 +1187,16 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa) sb << "void GetDimensions(out uint dim);\n"; - sb << "__target_intrinsic(glsl, \"texelFetch($P, $1)$z\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, $1)$z\")\n"; sb << "T Load(int location);\n"; sb << "T Load(int location, out uint status);\n"; sb << "__subscript(uint index) -> T {\n"; - sb << "__target_intrinsic(glsl, \"texelFetch($P, int($1))$z\") get;\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, int($1))$z\") get;\n"; if (kBaseBufferAccessLevels[aa].access != SLANG_RESOURCE_ACCESS_READ) { diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h index 8a7add3aa..7a2bcc759 100644 --- a/source/slang/hlsl.meta.slang.h +++ b/source/slang/hlsl.meta.slang.h @@ -1232,14 +1232,16 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa) sb << "void GetDimensions(out uint dim);\n"; - sb << "__target_intrinsic(glsl, \"texelFetch($P, $1)$z\")\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, $1)$z\")\n"; sb << "T Load(int location);\n"; sb << "T Load(int location, out uint status);\n"; sb << "__subscript(uint index) -> T {\n"; - sb << "__target_intrinsic(glsl, \"texelFetch($P, int($1))$z\") get;\n"; + sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, int($1))$z\") get;\n"; if (kBaseBufferAccessLevels[aa].access != SLANG_RESOURCE_ACCESS_READ) { 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; diff --git a/source/slang/slang.vcxproj b/source/slang/slang.vcxproj index eeaf7410a..3be83b4f5 100644 --- a/source/slang/slang.vcxproj +++ b/source/slang/slang.vcxproj @@ -295,4 +295,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project>
\ No newline at end of file +</Project>
\ No newline at end of file diff --git a/source/slang/slang.vcxproj.filters b/source/slang/slang.vcxproj.filters index e2b17530e..d2efaf191 100644 --- a/source/slang/slang.vcxproj.filters +++ b/source/slang/slang.vcxproj.filters @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Filter Include="Header Files"> diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h index f151a498a..35466a42c 100644 --- a/source/slang/type-layout.h +++ b/source/slang/type-layout.h @@ -458,11 +458,6 @@ public: List<RefPtr<GenericParamLayout>> globalGenericParams; Dictionary<String, GenericParamLayout*> globalGenericParamsMap; - // HACK: binding to use when we have to create - // a dummy sampler just to appease glslang - int bindingForHackSampler = 0; - RefPtr<VarDeclBase> hackSamplerVar; - TargetRequest* targetRequest = nullptr; }; diff --git a/tests/bindings/glsl-parameter-blocks.slang.glsl b/tests/bindings/glsl-parameter-blocks.slang.glsl index 01f49279a..3ade8bb6b 100644 --- a/tests/bindings/glsl-parameter-blocks.slang.glsl +++ b/tests/bindings/glsl-parameter-blocks.slang.glsl @@ -22,16 +22,16 @@ struct Test vec4 a; }; -layout(binding = 0, set = 1) +layout(binding = 0) uniform ParameterBlock_gTest { Test gTest; }; -layout(binding = 1, set = 1) +layout(binding = 1) uniform texture2D gTest_t; -layout(binding = 2, set = 1) +layout(binding = 2) uniform sampler gTest_s; layout(location = 0) diff --git a/tests/reflection/binding-gl.hlsl.expected b/tests/reflection/binding-gl.hlsl.expected index 5ace782cc..1b5e7354f 100644 --- a/tests/reflection/binding-gl.hlsl.expected +++ b/tests/reflection/binding-gl.hlsl.expected @@ -93,13 +93,6 @@ standard output = { "type": { "kind": "samplerState" } - }, - { - "name": "SLANG_hack_samplerForTexelFetch", - "binding": {"kind": "descriptorTableSlot", "index": 4}, - "type": { - "kind": "samplerState" - } } ], "entryPoints": [ diff --git a/tests/reflection/binding-push-constant-gl.hlsl.expected b/tests/reflection/binding-push-constant-gl.hlsl.expected index 6dd9d0fdd..ed6983364 100644 --- a/tests/reflection/binding-push-constant-gl.hlsl.expected +++ b/tests/reflection/binding-push-constant-gl.hlsl.expected @@ -122,13 +122,6 @@ standard output = { "type": { "kind": "samplerState" } - }, - { - "name": "SLANG_hack_samplerForTexelFetch", - "binding": {"kind": "descriptorTableSlot", "index": 4}, - "type": { - "kind": "samplerState" - } } ], "entryPoints": [ diff --git a/tests/reflection/cross-compile.slang.expected b/tests/reflection/cross-compile.slang.expected index 3a8bea41e..3bb730f66 100644 --- a/tests/reflection/cross-compile.slang.expected +++ b/tests/reflection/cross-compile.slang.expected @@ -42,13 +42,6 @@ standard output = { ] } } - }, - { - "name": "SLANG_hack_samplerForTexelFetch", - "binding": {"kind": "descriptorTableSlot", "index": 3}, - "type": { - "kind": "samplerState" - } } ] } diff --git a/tests/reflection/parameter-block.slang.expected b/tests/reflection/parameter-block.slang.expected index bc04d79ed..6821c46ca 100644 --- a/tests/reflection/parameter-block.slang.expected +++ b/tests/reflection/parameter-block.slang.expected @@ -39,13 +39,6 @@ standard output = { "kind": "resource", "baseShape": "texture2D" } - }, - { - "name": "SLANG_hack_samplerForTexelFetch", - "binding": {"kind": "descriptorTableSlot", "index": 1}, - "type": { - "kind": "samplerState" - } } ] } diff --git a/tools/slang-test/slang-test.vcxproj b/tools/slang-test/slang-test.vcxproj index b94f2f627..4987e1ce3 100644 --- a/tools/slang-test/slang-test.vcxproj +++ b/tools/slang-test/slang-test.vcxproj @@ -182,4 +182,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project>
\ No newline at end of file +</Project>
\ No newline at end of file diff --git a/tools/slang-test/slang-test.vcxproj.filters b/tools/slang-test/slang-test.vcxproj.filters index 3d80416f8..4c000ba58 100644 --- a/tools/slang-test/slang-test.vcxproj.filters +++ b/tools/slang-test/slang-test.vcxproj.filters @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Filter Include="Header Files"> |
