diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-07-17 11:37:29 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-07-17 13:35:22 -0700 |
| commit | 5d5aca4206c77677d9c64c47417302cb2eb2b6c4 (patch) | |
| tree | 0a3e9c34b958032b98ab3e20e4627d4730dac9e8 /source | |
| parent | 6f239b0489602d0c333282a3751d454a166d33f1 (diff) | |
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`)
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/emit.cpp | 21 | ||||
| -rw-r--r-- | source/slang/slang-stdlib.cpp | 42 |
2 files changed, 61 insertions, 2 deletions
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<TextureType>()) { emitGLSLTextureOrTextureSamplerType(baseTextureType, "sampler"); + + if (auto samplerType = callExpr->Arguments[0]->Type.type->As<SamplerStateType>()) + { + 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"; |
