Use the DX11 syntax for GLSL samplers and textures.

TRAC #22330 Signed-off-by: Geoff Lang Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1739 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b73964e3
...@@ -162,9 +162,22 @@ void OutputHLSL::header() ...@@ -162,9 +162,22 @@ void OutputHLSL::header()
const TType &type = uniform->second->getType(); const TType &type = uniform->second->getType();
const TString &name = uniform->second->getSymbol(); const TString &name = uniform->second->getSymbol();
if (mOutputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType())) // Also declare the texture
{
int index = samplerRegister(mReferencedUniforms[name]);
uniforms += "uniform SamplerState sampler_" + decorateUniform(name, type) + arrayString(type) +
" : register(s" + str(index) + ");\n";
uniforms += "uniform " + textureString(type) + " texture_" + decorateUniform(name, type) + arrayString(type) +
" : register(t" + str(index) + ");\n";
}
else
{
uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type) + arrayString(type) + uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type) + arrayString(type) +
" : register(" + registerString(mReferencedUniforms[name]) + ");\n"; " : register(" + registerString(mReferencedUniforms[name]) + ");\n";
} }
}
for (ReferencedSymbols::const_iterator varying = mReferencedVaryings.begin(); varying != mReferencedVaryings.end(); varying++) for (ReferencedSymbols::const_iterator varying = mReferencedVaryings.begin(); varying != mReferencedVaryings.end(); varying++)
{ {
...@@ -223,24 +236,50 @@ void OutputHLSL::header() ...@@ -223,24 +236,50 @@ void OutputHLSL::header()
if (mUsesTexture2D) if (mUsesTexture2D)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2D(sampler2D s, float2 t)\n" out << "float4 gl_texture2D(sampler2D s, float2 t)\n"
"{\n" "{\n"
" return tex2D(s, t);\n" " return tex2D(s, t);\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv)\n"
"{\n"
" return t.Sample(s, uv);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2D_bias) if (mUsesTexture2D_bias)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2D(sampler2D s, float2 t, float bias)\n" out << "float4 gl_texture2D(sampler2D s, float2 t, float bias)\n"
"{\n" "{\n"
" return tex2Dbias(s, float4(t.x, t.y, 0, bias));\n" " return tex2Dbias(s, float4(t.x, t.y, 0, bias));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv, float bias)\n"
"{\n"
" return t.SampleBias(s, uv, bias);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2DProj) if (mUsesTexture2DProj)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DProj(sampler2D s, float3 t)\n" out << "float4 gl_texture2DProj(sampler2D s, float3 t)\n"
"{\n" "{\n"
" return tex2Dproj(s, float4(t.x, t.y, 0, t.z));\n" " return tex2Dproj(s, float4(t.x, t.y, 0, t.z));\n"
...@@ -252,9 +291,26 @@ void OutputHLSL::header() ...@@ -252,9 +291,26 @@ void OutputHLSL::header()
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw)\n"
"{\n"
" return t.Sample(s, float2(uvw.x / uvw.z, uvw.y / uvw.z));\n"
"}\n"
"\n"
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw)\n"
"{\n"
" return t.Sample(s, float2(uvw.x / uvw.w, uvw.y / uvw.w));\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2DProj_bias) if (mUsesTexture2DProj_bias)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DProj(sampler2D s, float3 t, float bias)\n" out << "float4 gl_texture2DProj(sampler2D s, float3 t, float bias)\n"
"{\n" "{\n"
" return tex2Dbias(s, float4(t.x / t.z, t.y / t.z, 0, bias));\n" " return tex2Dbias(s, float4(t.x / t.z, t.y / t.z, 0, bias));\n"
...@@ -266,47 +322,112 @@ void OutputHLSL::header() ...@@ -266,47 +322,112 @@ void OutputHLSL::header()
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw, float bias)\n"
"{\n"
" return t.SampleBias(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), bias);\n"
"}\n"
"\n"
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw, float bias)\n"
"{\n"
" return t.SampleBias(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), bias);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTextureCube) if (mUsesTextureCube)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_textureCube(samplerCUBE s, float3 t)\n" out << "float4 gl_textureCube(samplerCUBE s, float3 t)\n"
"{\n" "{\n"
" return texCUBE(s, t);\n" " return texCUBE(s, t);\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw)\n"
"{\n"
" return t.Sample(s, uvw);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTextureCube_bias) if (mUsesTextureCube_bias)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_textureCube(samplerCUBE s, float3 t, float bias)\n" out << "float4 gl_textureCube(samplerCUBE s, float3 t, float bias)\n"
"{\n" "{\n"
" return texCUBEbias(s, float4(t.x, t.y, t.z, bias));\n" " return texCUBEbias(s, float4(t.x, t.y, t.z, bias));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw, float bias)\n"
"{\n"
" return t.SampleBias(s, uvw, bias);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
// These *Lod0 intrinsics are not available in GL fragment shaders. // These *Lod0 intrinsics are not available in GL fragment shaders.
// They are used to sample using discontinuous texture coordinates. // They are used to sample using discontinuous texture coordinates.
if (mUsesTexture2DLod0) if (mUsesTexture2DLod0)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DLod0(sampler2D s, float2 t)\n" out << "float4 gl_texture2DLod0(sampler2D s, float2 t)\n"
"{\n" "{\n"
" return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n" " return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DLod0(Texture2D t, SamplerState s, float2 uv)\n"
"{\n"
" return t.SampleLevel(s, uv, 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2DLod0_bias) if (mUsesTexture2DLod0_bias)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DLod0(sampler2D s, float2 t, float bias)\n" out << "float4 gl_texture2DLod0(sampler2D s, float2 t, float bias)\n"
"{\n" "{\n"
" return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n" " return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DLod0(Texture2D t, SamplerState s, float2 uv, float bias)\n"
"{\n"
" return t.SampleLevel(s, uv, 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2DProjLod0) if (mUsesTexture2DProjLod0)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DProjLod0(sampler2D s, float3 t)\n" out << "float4 gl_texture2DProjLod0(sampler2D s, float3 t)\n"
"{\n" "{\n"
" return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n" " return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n"
...@@ -318,9 +439,26 @@ void OutputHLSL::header() ...@@ -318,9 +439,26 @@ void OutputHLSL::header()
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DProjLod0(Texture2D t, SamplerState s, float3 uvw)\n"
"{\n"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);\n"
"}\n"
"\n"
"float4 gl_texture2DProjLod0(Texture2D t, SamplerState s, float4 uvw)\n"
"{\n"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2DProjLod0_bias) if (mUsesTexture2DProjLod0_bias)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DProjLod0_bias(sampler2D s, float3 t, float bias)\n" out << "float4 gl_texture2DProjLod0_bias(sampler2D s, float3 t, float bias)\n"
"{\n" "{\n"
" return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n" " return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n"
...@@ -332,24 +470,63 @@ void OutputHLSL::header() ...@@ -332,24 +470,63 @@ void OutputHLSL::header()
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DProjLod_bias(Texture2D t, SamplerState s, float3 uvw, float bias)\n"
"{\n"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);\n"
"}\n"
"\n"
"float4 gl_texture2DProjLod_bias(Texture2D t, SamplerState s, float4 uvw, float bias)\n"
"{\n"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTextureCubeLod0) if (mUsesTextureCubeLod0)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_textureCubeLod0(samplerCUBE s, float3 t)\n" out << "float4 gl_textureCubeLod0(samplerCUBE s, float3 t)\n"
"{\n" "{\n"
" return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n" " return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_textureCubeLod0(TextureCube t, SamplerState s, float3 uvw)\n"
"{\n"
" return t.SampleLevel(s, uvw, 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTextureCubeLod0_bias) if (mUsesTextureCubeLod0_bias)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_textureCubeLod0(samplerCUBE s, float3 t, float bias)\n" out << "float4 gl_textureCubeLod0(samplerCUBE s, float3 t, float bias)\n"
"{\n" "{\n"
" return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n" " return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_textureCubeLod0(TextureCube t, SamplerState s, float3 uvw, float bias)\n"
"{\n"
" return t.SampleLevel(s, uvw, 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
} }
else // Vertex shader else // Vertex shader
{ {
...@@ -374,24 +551,50 @@ void OutputHLSL::header() ...@@ -374,24 +551,50 @@ void OutputHLSL::header()
if (mUsesTexture2D) if (mUsesTexture2D)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2D(sampler2D s, float2 t)\n" out << "float4 gl_texture2D(sampler2D s, float2 t)\n"
"{\n" "{\n"
" return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n" " return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv)\n"
"{\n"
" return t.SampleLevel(s, uv, 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2DLod) if (mUsesTexture2DLod)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DLod(sampler2D s, float2 t, float lod)\n" out << "float4 gl_texture2DLod(sampler2D s, float2 t, float lod)\n"
"{\n" "{\n"
" return tex2Dlod(s, float4(t.x, t.y, 0, lod));\n" " return tex2Dlod(s, float4(t.x, t.y, 0, lod));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DLod(Texture2D t, SamplerState s, float2 uv, float lod)\n"
"{\n"
" return t.SampleLevel(s, uv, lod);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2DProj) if (mUsesTexture2DProj)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DProj(sampler2D s, float3 t)\n" out << "float4 gl_texture2DProj(sampler2D s, float3 t)\n"
"{\n" "{\n"
" return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n" " return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n"
...@@ -403,9 +606,26 @@ void OutputHLSL::header() ...@@ -403,9 +606,26 @@ void OutputHLSL::header()
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw)\n"
"{\n"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);\n"
"}\n"
"\n"
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw)\n"
"{\n"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTexture2DProjLod) if (mUsesTexture2DProjLod)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_texture2DProjLod(sampler2D s, float3 t, float lod)\n" out << "float4 gl_texture2DProjLod(sampler2D s, float3 t, float lod)\n"
"{\n" "{\n"
" return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, lod));\n" " return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, lod));\n"
...@@ -417,24 +637,63 @@ void OutputHLSL::header() ...@@ -417,24 +637,63 @@ void OutputHLSL::header()
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw, float lod)\n"
"{\n"
" return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), lod);\n"
"}\n"
"\n"
"float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw)\n"
"{\n"
" return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), lod);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTextureCube) if (mUsesTextureCube)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_textureCube(samplerCUBE s, float3 t)\n" out << "float4 gl_textureCube(samplerCUBE s, float3 t)\n"
"{\n" "{\n"
" return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n" " return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw)\n"
"{\n"
" return t.SampleLevel(s, uvw, 0);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
if (mUsesTextureCubeLod) if (mUsesTextureCubeLod)
{ {
if (mOutputType == SH_HLSL9_OUTPUT)
{
out << "float4 gl_textureCubeLod(samplerCUBE s, float3 t, float lod)\n" out << "float4 gl_textureCubeLod(samplerCUBE s, float3 t, float lod)\n"
"{\n" "{\n"
" return texCUBElod(s, float4(t.x, t.y, t.z, lod));\n" " return texCUBElod(s, float4(t.x, t.y, t.z, lod));\n"
"}\n" "}\n"
"\n"; "\n";
} }
else if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "float4 gl_textureCubeLod(TextureCube t, SamplerState s, float3 uvw, float lod)\n"
"{\n"
" return t.SampleLevel(s, uvw, lod);\n"
"}\n"
"\n";
}
else UNREACHABLE();
}
} }
if (mUsesFragCoord) if (mUsesFragCoord)
...@@ -1524,6 +1783,13 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1524,6 +1783,13 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
out << "gl_textureCubeLod("; out << "gl_textureCubeLod(";
} }
else UNREACHABLE(); else UNREACHABLE();
if (mOutputType == SH_HLSL11_OUTPUT)
{
out << "texture_";
node->getSequence()[0]->traverse(this);
out << ", sampler_";
}
} }
} }
else if (visit == InVisit) else if (visit == InVisit)
...@@ -2234,10 +2500,28 @@ TString OutputHLSL::typeString(const TType &type) ...@@ -2234,10 +2500,28 @@ TString OutputHLSL::typeString(const TType &type)
} }
} }
UNIMPLEMENTED(); // FIXME UNREACHABLE();
return "<unknown type>"; return "<unknown type>";
} }
TString OutputHLSL::textureString(const TType &type)
{
switch (type.getBasicType())
{
case EbtSampler2D:
return "Texture2D";
case EbtSamplerCube:
return "TextureCube";
case EbtSamplerExternalOES:
return "Texture2D";
default:
break;
}
UNREACHABLE();
return "<unknown texture type>";
}
TString OutputHLSL::arrayString(const TType &type) TString OutputHLSL::arrayString(const TType &type)
{ {
if (!type.isArray()) if (!type.isArray())
......
...@@ -34,6 +34,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -34,6 +34,7 @@ class OutputHLSL : public TIntermTraverser
const ActiveUniforms &getUniforms(); const ActiveUniforms &getUniforms();
TString typeString(const TType &type); TString typeString(const TType &type);
TString textureString(const TType &type);
static TString qualifierString(TQualifier qualifier); static TString qualifierString(TQualifier qualifier);
static TString arrayString(const TType &type); static TString arrayString(const TType &type);
static TString initializer(const TType &type); static TString initializer(const TType &type);
......
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