diff options
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/core.meta.slang | 22 | ||||
| -rw-r--r-- | source/slang/core.meta.slang.h | 22 | ||||
| -rw-r--r-- | source/slang/emit.cpp | 40 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 6 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang.h | 6 | ||||
| -rw-r--r-- | source/slang/parameter-binding.cpp | 79 | ||||
| -rw-r--r-- | source/slang/slang.vcxproj | 2 | ||||
| -rw-r--r-- | source/slang/slang.vcxproj.filters | 2 | ||||
| -rw-r--r-- | source/slang/type-layout.h | 5 |
9 files changed, 38 insertions, 146 deletions
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; }; |
