From 5d5aca4206c77677d9c64c47417302cb2eb2b6c4 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 17 Jul 2017 11:37:29 -0700 Subject: Improve handling of `SampleCmpLevelZero` - We map `SampleCmpLevelZero` to either `textureLod` or `textureGrad` based on what the GLSL spec seems to allow - We map `SamplerComparisonState` to `samplerShadow` (instead of just `sampler`) --- source/slang/slang-stdlib.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'source/slang/slang-stdlib.cpp') diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 1c1bcceaf..169eac4fb 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -1612,6 +1612,48 @@ namespace Slang sb << "float compareValue"; sb << ");\n"; + int baseCoordCount = kBaseTextureTypes[tt].coordCount; + int arrCoordCount = baseCoordCount + isArray; + if (arrCoordCount < 3) + { + int extCoordCount = arrCoordCount + 1; + + if (extCoordCount < 3) + extCoordCount = 3; + + sb << "__intrinsic(glsl, \"textureLod($p, "; + + sb << "vec" << extCoordCount << "($1,"; + for (int ii = arrCoordCount; ii < extCoordCount - 1; ++ii) + { + sb << " 0.0,"; + } + sb << "$2)"; + + sb << ", 0.0)\")\n"; + } + else if(arrCoordCount <= 3) + { + int extCoordCount = arrCoordCount + 1; + + if (extCoordCount < 3) + extCoordCount = 3; + + sb << "__intrinsic(glsl, \"textureGrad($p, "; + + sb << "vec" << extCoordCount << "($1,"; + for (int ii = arrCoordCount; ii < extCoordCount - 1; ++ii) + { + sb << " 0.0,"; + } + sb << "$2)"; + + // Construct gradients + sb << ", vec" << baseCoordCount << "(0.0)"; + sb << ", vec" << baseCoordCount << "(0.0)"; + sb << ")\")\n"; + } + sb << "__intrinsic\n"; sb << "T SampleCmpLevelZero(SamplerComparisonState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float compareValue"; -- cgit v1.2.3 From fcf007268b077ee0d46553a62ae1b09528345be6 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 17 Jul 2017 11:54:58 -0700 Subject: Add hacky GLSL lowering for `GetDimensions` This is hacky for two big reasons: 1. It uses "operator comma" in the output to deal with calling multiple functions in an expression context 2. The way I'm lowering things to GLSL ends up using certain function arguments more than once, which means they get emitted as GLSL more than once, which means their *side effects* get evaluated more than once. Please don't put an expression with side effects in as an argument to `GetDimensions` when cross-compiling. Solving these issues requires the translation of builtins to be more directly handled as part of lowering, rather than a purely textual operation done during emission. I don't have time to fix that right now. --- source/slang/slang-stdlib.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'source/slang/slang-stdlib.cpp') diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 169eac4fb..4fcef6639 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -1440,6 +1440,66 @@ namespace Slang for(int isFloat = 0; isFloat < 2; ++isFloat) for(int includeMipInfo = 0; includeMipInfo < 2; ++includeMipInfo) { + { + sb << "__intrinsic(glsl, \"("; + + int aa = 0; + String lodStr = "0"; + if (includeMipInfo) + { + int mipLevelArg = aa++; + lodStr.append("$"); + lodStr.append(mipLevelArg); + } + + int cc = 0; + switch(baseShape) + { + case TextureType::Shape1D: + sb << "($" << aa++ << " = textureSize($P, " << lodStr << "))"; + cc = 1; + break; + + case TextureType::Shape2D: + case TextureType::ShapeCube: + sb << "($" << aa++ << " = textureSize($P, " << lodStr << ").x)"; + sb << ", ($" << aa++ << " = textureSize($P, " << lodStr << ").y)"; + cc = 2; + break; + + case TextureType::Shape3D: + sb << "($" << aa++ << " = textureSize($P, " << lodStr << ").x)"; + sb << ", ($" << aa++ << " = textureSize($P, " << lodStr << ").y)"; + sb << ", ($" << aa++ << " = textureSize($P, " << lodStr << ").z)"; + cc = 3; + break; + + default: + assert(!"unexpected"); + break; + } + + if(isArray) + { + sb << ", ($" << aa++ << " = textureSize($P, " << lodStr << ")." << kComponentNames[cc] << ")"; + } + + if(isMultisample) + { + sb << ", ($" << aa++ << " = textureSamples($P))"; + } + + if (includeMipInfo) + { + sb << ", ($" << aa++ << " = textureQueryLevels($P))"; + } + + + sb << ")\")\n"; + sb << "__intrinsic\n"; + + } + char const* t = isFloat ? "out float " : "out uint "; sb << "void GetDimensions("; -- cgit v1.2.3 From 77e3c3bfb1f77ec04cd8e63a676bfa3e2ae2f998 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 17 Jul 2017 12:03:05 -0700 Subject: Map HLSL `SampleGrad` to GLSL `textureGrad[Offset]` - This was an easy case, as far as these things go. --- source/slang/slang-stdlib.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/slang/slang-stdlib.cpp') diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 4fcef6639..3de33f554 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -1739,6 +1739,9 @@ namespace Slang sb << "int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; } + + sb << "__intrinsic(glsl, \"textureGrad($p, $1, $2, $3)\")\n"; + sb << "__intrinsic\n"; sb << "T SampleGrad(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " gradX, "; @@ -1747,6 +1750,8 @@ namespace Slang if( baseShape != TextureType::ShapeCube ) { + sb << "__intrinsic(glsl, \"textureGradOffset($p, $1, $2, $3, $4)\")\n"; + sb << "__intrinsic\n"; sb << "T SampleGrad(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " gradX, "; -- cgit v1.2.3