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/emit.cpp | 21 +++++++++++++++++++-- source/slang/slang-stdlib.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index effa9aa97..c6efa88dc 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -1041,7 +1041,7 @@ struct EmitVisitor default: switch (samplerStateType->flavor) { - case SamplerStateType::Flavor::SamplerState: Emit("SamplerState"); break; + case SamplerStateType::Flavor::SamplerState: Emit("SamplerState"); break; case SamplerStateType::Flavor::SamplerComparisonState: Emit("SamplerComparisonState"); break; default: assert(!"unreachable"); @@ -1050,7 +1050,15 @@ struct EmitVisitor break; case CodeGenTarget::GLSL: - Emit("sampler"); + switch (samplerStateType->flavor) + { + case SamplerStateType::Flavor::SamplerState: Emit("sampler"); break; + case SamplerStateType::Flavor::SamplerComparisonState: Emit("samplerShadow"); break; + default: + assert(!"unreachable"); + break; + } + break; break; } @@ -1847,6 +1855,15 @@ struct EmitVisitor if (auto baseTextureType = base->Type->As()) { emitGLSLTextureOrTextureSamplerType(baseTextureType, "sampler"); + + if (auto samplerType = callExpr->Arguments[0]->Type.type->As()) + { + if (samplerType->flavor == SamplerStateType::Flavor::SamplerComparisonState) + { + Emit("Shadow"); + } + } + Emit("("); EmitExpr(memberExpr->BaseExpression); Emit(","); 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