Commit 6d232bb6 by Nicolas Capens Committed by Shannon Woods

Generate HLSL code for integer sampling.

TRAC #23472 Signed-off-by: Geoff Lang Signed-off-by: Shannon Woods Author: Nicolas Capens
parent e6050884
...@@ -34,24 +34,15 @@ TString OutputHLSL::TextureFunction::name() const ...@@ -34,24 +34,15 @@ TString OutputHLSL::TextureFunction::name() const
{ {
TString name = "gl_texture"; TString name = "gl_texture";
if (sampler == EbtSampler2D || if (IsSampler2D(sampler))
sampler == EbtISampler2D ||
sampler == EbtUSampler2D ||
sampler == EbtSampler2DArray ||
sampler == EbtISampler2DArray ||
sampler == EbtUSampler2DArray)
{ {
name += "2D"; name += "2D";
} }
else if (sampler == EbtSampler3D || else if (IsSampler3D(sampler))
sampler == EbtISampler3D ||
sampler == EbtUSampler3D)
{ {
name += "3D"; name += "3D";
} }
else if (sampler == EbtSamplerCube || else if (IsSamplerCube(sampler))
sampler == EbtISamplerCube ||
sampler == EbtUSamplerCube)
{ {
name += "Cube"; name += "Cube";
} }
...@@ -972,27 +963,51 @@ void OutputHLSL::header() ...@@ -972,27 +963,51 @@ void OutputHLSL::header()
} }
out << ")\n" out << ")\n"
"{\n" "{\n";
" return ";
// HLSL intrinsic if (IsIntegerSampler(textureFunction->sampler) && IsSamplerCube(textureFunction->sampler))
if (mOutputType == SH_HLSL9_OUTPUT)
{ {
switch(textureFunction->sampler) // Currently unsupported because TextureCube does not support Load
// This will require emulation using a Texture2DArray with 6 faces
if (textureFunction->sampler == EbtISamplerCube)
{ {
case EbtSampler2D: out << "tex2D"; break; out << " return int4(0, 0, 0, 0);";
case EbtSamplerCube: out << "texCUBE"; break;
default: UNREACHABLE();
} }
else if (textureFunction->sampler == EbtUSamplerCube)
{
out << " return uint4(0, 0, 0, 0);";
} }
else if (mOutputType == SH_HLSL11_OUTPUT) else UNREACHABLE();
}
else
{
if (IsIntegerSampler(textureFunction->sampler))
{ {
out << "x.Sample"; if (IsSampler2D(textureFunction->sampler))
{
out << " uint width; uint height; uint numberOfLevels;\n"
" x.GetDimensions(0, width, height, numberOfLevels);\n";
}
else if (IsSampler3D(textureFunction->sampler))
{
out << " uint width; uint height; uint depth; uint numberOfLevels;\n"
" x.GetDimensions(0, width, height, depth, numberOfLevels);\n";
} }
else UNREACHABLE(); else UNREACHABLE();
}
out << " return ";
// HLSL intrinsic
if (mOutputType == SH_HLSL9_OUTPUT) if (mOutputType == SH_HLSL9_OUTPUT)
{ {
switch(textureFunction->sampler)
{
case EbtSampler2D: out << "tex2D"; break;
case EbtSamplerCube: out << "texCUBE"; break;
default: UNREACHABLE();
}
switch(textureFunction->mipmap) switch(textureFunction->mipmap)
{ {
case TextureFunction::IMPLICIT: out << "(s, "; break; case TextureFunction::IMPLICIT: out << "(s, "; break;
...@@ -1004,17 +1019,46 @@ void OutputHLSL::header() ...@@ -1004,17 +1019,46 @@ void OutputHLSL::header()
} }
else if (mOutputType == SH_HLSL11_OUTPUT) else if (mOutputType == SH_HLSL11_OUTPUT)
{ {
if (IsIntegerSampler(textureFunction->sampler))
{
out << "x.Load(";
}
else
{
switch(textureFunction->mipmap) switch(textureFunction->mipmap)
{ {
case TextureFunction::IMPLICIT: out << "(s, "; break; case TextureFunction::IMPLICIT: out << "x.Sample(s, "; break;
case TextureFunction::BIAS: out << "Bias(s, "; break; case TextureFunction::BIAS: out << "x.SampleBias(s, "; break;
case TextureFunction::LOD: out << "Level(s, "; break; case TextureFunction::LOD: out << "x.SampleLevel(s, "; break;
case TextureFunction::LOD0: out << "Level(s, "; break; case TextureFunction::LOD0: out << "x.SampleLevel(s, "; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
}
else UNREACHABLE(); else UNREACHABLE();
// Integer sampling requires integer addresses
TString addressx = "";
TString addressy = "";
TString addressz = "";
TString close = "";
if (IsIntegerSampler(textureFunction->sampler))
{
switch(hlslCoords)
{
case 2: out << "int3("; break;
case 3: out << "int4("; break;
default: UNREACHABLE();
}
addressx = "int(floor(float(width) * frac(";
addressy = "int(floor(float(height) * frac(";
addressz = "int(floor(float(depth) * frac(";
close = ")))";
}
else
{
switch(hlslCoords) switch(hlslCoords)
{ {
case 2: out << "float2("; break; case 2: out << "float2("; break;
...@@ -1022,8 +1066,9 @@ void OutputHLSL::header() ...@@ -1022,8 +1066,9 @@ void OutputHLSL::header()
case 4: out << "float4("; break; case 4: out << "float4("; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
}
TString proj = ""; TString proj = ""; // Only used for projected textures
if (textureFunction->proj) if (textureFunction->proj)
{ {
...@@ -1035,7 +1080,7 @@ void OutputHLSL::header() ...@@ -1035,7 +1080,7 @@ void OutputHLSL::header()
} }
} }
out << "t.x" + proj + ", t.y" + proj; out << addressx + ("t.x" + proj) + close + ", " + addressy + ("t.y" + proj) + close;
if (mOutputType == SH_HLSL9_OUTPUT) if (mOutputType == SH_HLSL9_OUTPUT)
{ {
...@@ -1068,9 +1113,11 @@ void OutputHLSL::header() ...@@ -1068,9 +1113,11 @@ void OutputHLSL::header()
{ {
if (hlslCoords >= 3) if (hlslCoords >= 3)
{ {
out << ", t.z" + proj; out << ", " + addressz + ("t.z" + proj) + close;
} }
if (!IsIntegerSampler(textureFunction->sampler))
{
switch(textureFunction->mipmap) switch(textureFunction->mipmap)
{ {
case TextureFunction::IMPLICIT: out << "));"; break; case TextureFunction::IMPLICIT: out << "));"; break;
...@@ -1080,9 +1127,16 @@ void OutputHLSL::header() ...@@ -1080,9 +1127,16 @@ void OutputHLSL::header()
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
else
{
out << ", 0));"; // Sample from the top level
}
}
else UNREACHABLE(); else UNREACHABLE();
}
out << "}\n" out << "\n"
"}\n"
"\n"; "\n";
} }
...@@ -3014,9 +3068,11 @@ TString OutputHLSL::textureString(const TType &type) ...@@ -3014,9 +3068,11 @@ TString OutputHLSL::textureString(const TType &type)
case EbtSampler2DArray: return "Texture2DArray"; case EbtSampler2DArray: return "Texture2DArray";
case EbtSampler3D: return "Texture3D"; case EbtSampler3D: return "Texture3D";
case EbtISampler2D: return "Texture2D<int4>"; case EbtISampler2D: return "Texture2D<int4>";
case EbtISampler3D: return "Texture3D<int4>";
case EbtISamplerCube: return "TextureCube<int4>"; case EbtISamplerCube: return "TextureCube<int4>";
case EbtISampler2DArray: return "Texture2DArray<int4>"; case EbtISampler2DArray: return "Texture2DArray<int4>";
case EbtUSampler2D: return "Texture2D<uint4>"; case EbtUSampler2D: return "Texture2D<uint4>";
case EbtUSampler3D: return "Texture3D<uint4>";
case EbtUSamplerCube: return "TextureCube<uint4>"; case EbtUSamplerCube: return "TextureCube<uint4>";
case EbtUSampler2DArray: return "Texture2DArray<uint4>"; case EbtUSampler2DArray: return "Texture2DArray<uint4>";
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment