Commit b4cc49fb by Olli Etuaho Committed by Commit Bot

Use only ImmutableString in TextureFunctionHLSL

BUG=angleproject:2267 TEST=angle_unittests, angle_end2end_tests Change-Id: I344ca0098762fcf665365c79d1f8fb04cb1b03f6 Reviewed-on: https://chromium-review.googlesource.com/887067Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 29bda815
...@@ -1967,8 +1967,9 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1967,8 +1967,9 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
coords = (*arguments)[1]->getAsTyped()->getNominalSize(); coords = (*arguments)[1]->getAsTyped()->getNominalSize();
} }
TString textureFunctionName = mTextureFunctionHLSL->useTextureFunction( const ImmutableString &textureFunctionName =
name, samplerType, coords, arguments->size(), lod0, mShaderType); mTextureFunctionHLSL->useTextureFunction(name, samplerType, coords,
arguments->size(), lod0, mShaderType);
out << textureFunctionName << "("; out << textureFunctionName << "(";
} }
......
...@@ -23,8 +23,8 @@ namespace ...@@ -23,8 +23,8 @@ namespace
void OutputIntTexCoordWrap(TInfoSinkBase &out, void OutputIntTexCoordWrap(TInfoSinkBase &out,
const char *wrapMode, const char *wrapMode,
const char *size, const char *size,
const TString &texCoord, const ImmutableString &texCoord,
const TString &texCoordOffset, const char *texCoordOffset,
const char *texCoordOutName) const char *texCoordOutName)
{ {
// GLES 3.0.4 table 3.22 specifies how the wrap modes work. We don't use the formulas verbatim // GLES 3.0.4 table 3.22 specifies how the wrap modes work. We don't use the formulas verbatim
...@@ -58,9 +58,9 @@ void OutputIntTexCoordWrap(TInfoSinkBase &out, ...@@ -58,9 +58,9 @@ void OutputIntTexCoordWrap(TInfoSinkBase &out,
void OutputIntTexCoordWraps(TInfoSinkBase &out, void OutputIntTexCoordWraps(TInfoSinkBase &out,
const TextureFunctionHLSL::TextureFunction &textureFunction, const TextureFunctionHLSL::TextureFunction &textureFunction,
TString *texCoordX, ImmutableString *texCoordX,
TString *texCoordY, ImmutableString *texCoordY,
TString *texCoordZ) ImmutableString *texCoordZ)
{ {
// Convert from normalized floating-point to integer // Convert from normalized floating-point to integer
out << "int wrapS = samplerMetadata[samplerIndex].wrapModes & 0x3;\n"; out << "int wrapS = samplerMetadata[samplerIndex].wrapModes & 0x3;\n";
...@@ -72,7 +72,7 @@ void OutputIntTexCoordWraps(TInfoSinkBase &out, ...@@ -72,7 +72,7 @@ void OutputIntTexCoordWraps(TInfoSinkBase &out,
{ {
OutputIntTexCoordWrap(out, "wrapS", "width", *texCoordX, "0", "tix"); OutputIntTexCoordWrap(out, "wrapS", "width", *texCoordX, "0", "tix");
} }
*texCoordX = "tix"; *texCoordX = ImmutableString("tix");
out << "int wrapT = (samplerMetadata[samplerIndex].wrapModes >> 2) & 0x3;\n"; out << "int wrapT = (samplerMetadata[samplerIndex].wrapModes >> 2) & 0x3;\n";
if (textureFunction.offset) if (textureFunction.offset)
{ {
...@@ -82,11 +82,11 @@ void OutputIntTexCoordWraps(TInfoSinkBase &out, ...@@ -82,11 +82,11 @@ void OutputIntTexCoordWraps(TInfoSinkBase &out,
{ {
OutputIntTexCoordWrap(out, "wrapT", "height", *texCoordY, "0", "tiy"); OutputIntTexCoordWrap(out, "wrapT", "height", *texCoordY, "0", "tiy");
} }
*texCoordY = "tiy"; *texCoordY = ImmutableString("tiy");
if (IsSamplerArray(textureFunction.sampler)) if (IsSamplerArray(textureFunction.sampler))
{ {
*texCoordZ = "int(max(0, min(layers - 1, floor(0.5 + t.z))))"; *texCoordZ = ImmutableString("int(max(0, min(layers - 1, floor(0.5 + t.z))))");
} }
else if (!IsSamplerCube(textureFunction.sampler) && !IsSampler2D(textureFunction.sampler)) else if (!IsSamplerCube(textureFunction.sampler) && !IsSampler2D(textureFunction.sampler))
{ {
...@@ -99,7 +99,7 @@ void OutputIntTexCoordWraps(TInfoSinkBase &out, ...@@ -99,7 +99,7 @@ void OutputIntTexCoordWraps(TInfoSinkBase &out,
{ {
OutputIntTexCoordWrap(out, "wrapR", "depth", *texCoordZ, "0", "tiz"); OutputIntTexCoordWrap(out, "wrapR", "depth", *texCoordZ, "0", "tiz");
} }
*texCoordZ = "tiz"; *texCoordZ = ImmutableString("tiz");
} }
} }
...@@ -557,27 +557,33 @@ void OutputTextureSizeFunctionBody(TInfoSinkBase &out, ...@@ -557,27 +557,33 @@ void OutputTextureSizeFunctionBody(TInfoSinkBase &out,
} }
void ProjectTextureCoordinates(const TextureFunctionHLSL::TextureFunction &textureFunction, void ProjectTextureCoordinates(const TextureFunctionHLSL::TextureFunction &textureFunction,
TString *texCoordX, ImmutableString *texCoordX,
TString *texCoordY, ImmutableString *texCoordY,
TString *texCoordZ) ImmutableString *texCoordZ)
{ {
if (textureFunction.proj) if (textureFunction.proj)
{ {
TString proj(""); ImmutableString proj("");
switch (textureFunction.coords) switch (textureFunction.coords)
{ {
case 3: case 3:
proj = " / t.z"; proj = ImmutableString(" / t.z");
break; break;
case 4: case 4:
proj = " / t.w"; proj = ImmutableString(" / t.w");
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
*texCoordX = "(" + *texCoordX + proj + ")"; ImmutableStringBuilder texCoordXBuilder(texCoordX->length() + proj.length() + 2u);
*texCoordY = "(" + *texCoordY + proj + ")"; texCoordXBuilder << '(' << *texCoordX << proj << ')';
*texCoordZ = "(" + *texCoordZ + proj + ")"; *texCoordX = texCoordXBuilder;
ImmutableStringBuilder texCoordYBuilder(texCoordY->length() + proj.length() + 2u);
texCoordYBuilder << '(' << *texCoordY << proj << ')';
*texCoordY = texCoordYBuilder;
ImmutableStringBuilder texCoordZBuilder(texCoordZ->length() + proj.length() + 2u);
texCoordZBuilder << '(' << *texCoordZ << proj << ')';
*texCoordZ = texCoordZBuilder;
} }
} }
...@@ -586,9 +592,9 @@ void OutputIntegerTextureSampleFunctionComputations( ...@@ -586,9 +592,9 @@ void OutputIntegerTextureSampleFunctionComputations(
const TextureFunctionHLSL::TextureFunction &textureFunction, const TextureFunctionHLSL::TextureFunction &textureFunction,
const ShShaderOutput outputType, const ShShaderOutput outputType,
const ImmutableString &textureReference, const ImmutableString &textureReference,
TString *texCoordX, ImmutableString *texCoordX,
TString *texCoordY, ImmutableString *texCoordY,
TString *texCoordZ) ImmutableString *texCoordZ)
{ {
if (!IsIntegerSampler(textureFunction.sampler)) if (!IsIntegerSampler(textureFunction.sampler))
{ {
...@@ -676,9 +682,18 @@ void OutputIntegerTextureSampleFunctionComputations( ...@@ -676,9 +682,18 @@ void OutputIntegerTextureSampleFunctionComputations(
} }
// Convert from normalized floating-point to integer // Convert from normalized floating-point to integer
*texCoordX = "int(floor(width * frac(" + *texCoordX + ")))"; static const ImmutableString kXPrefix("int(floor(width * frac(");
*texCoordY = "int(floor(height * frac(" + *texCoordY + ")))"; static const ImmutableString kYPrefix("int(floor(height * frac(");
*texCoordZ = "face"; static const ImmutableString kSuffix(")))");
ImmutableStringBuilder texCoordXBuilder(kXPrefix.length() + texCoordX->length() +
kSuffix.length());
texCoordXBuilder << kXPrefix << *texCoordX << kSuffix;
*texCoordX = texCoordXBuilder;
ImmutableStringBuilder texCoordYBuilder(kYPrefix.length() + texCoordX->length() +
kSuffix.length());
texCoordYBuilder << kYPrefix << *texCoordY << kSuffix;
*texCoordY = texCoordYBuilder;
*texCoordZ = ImmutableString("face");
} }
else if (textureFunction.method != TextureFunctionHLSL::TextureFunction::FETCH) else if (textureFunction.method != TextureFunctionHLSL::TextureFunction::FETCH)
{ {
...@@ -833,9 +848,9 @@ void OutputTextureSampleFunctionReturnStatement( ...@@ -833,9 +848,9 @@ void OutputTextureSampleFunctionReturnStatement(
const ShShaderOutput outputType, const ShShaderOutput outputType,
const ImmutableString &textureReference, const ImmutableString &textureReference,
const ImmutableString &samplerReference, const ImmutableString &samplerReference,
const TString &texCoordX, const ImmutableString &texCoordX,
const TString &texCoordY, const ImmutableString &texCoordY,
const TString &texCoordZ) const ImmutableString &texCoordZ)
{ {
out << " return "; out << " return ";
...@@ -1046,22 +1061,28 @@ void OutputTextureSampleFunctionReturnStatement( ...@@ -1046,22 +1061,28 @@ void OutputTextureSampleFunctionReturnStatement(
} // Anonymous namespace } // Anonymous namespace
TString TextureFunctionHLSL::TextureFunction::name() const ImmutableString TextureFunctionHLSL::TextureFunction::name() const
{ {
TString name = "gl_texture"; static const ImmutableString kGlTextureName("gl_texture");
ImmutableString suffix(TextureTypeSuffix(this->sampler));
ImmutableStringBuilder name(kGlTextureName.length() + suffix.length() + 4u + 6u + 5u);
name << kGlTextureName;
// We need to include full the sampler type in the function name to make the signature unique // We need to include full the sampler type in the function name to make the signature unique
// on D3D11, where samplers are passed to texture functions as indices. // on D3D11, where samplers are passed to texture functions as indices.
name += TextureTypeSuffix(this->sampler); name << suffix;
if (proj) if (proj)
{ {
name += "Proj"; name << "Proj";
} }
if (offset) if (offset)
{ {
name += "Offset"; name << "Offset";
} }
switch (method) switch (method)
...@@ -1071,22 +1092,22 @@ TString TextureFunctionHLSL::TextureFunction::name() const ...@@ -1071,22 +1092,22 @@ TString TextureFunctionHLSL::TextureFunction::name() const
case BIAS: case BIAS:
break; // Extra parameter makes the signature unique break; // Extra parameter makes the signature unique
case LOD: case LOD:
name += "Lod"; name << "Lod";
break; break;
case LOD0: case LOD0:
name += "Lod0"; name << "Lod0";
break; break;
case LOD0BIAS: case LOD0BIAS:
name += "Lod0"; name << "Lod0";
break; // Extra parameter makes the signature unique break; // Extra parameter makes the signature unique
case SIZE: case SIZE:
name += "Size"; name << "Size";
break; break;
case FETCH: case FETCH:
name += "Fetch"; name << "Fetch";
break; break;
case GRAD: case GRAD:
name += "Grad"; name << "Grad";
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -1166,12 +1187,12 @@ bool TextureFunctionHLSL::TextureFunction::operator<(const TextureFunction &rhs) ...@@ -1166,12 +1187,12 @@ bool TextureFunctionHLSL::TextureFunction::operator<(const TextureFunction &rhs)
std::tie(rhs.sampler, rhs.coords, rhs.proj, rhs.offset, rhs.method); std::tie(rhs.sampler, rhs.coords, rhs.proj, rhs.offset, rhs.method);
} }
TString TextureFunctionHLSL::useTextureFunction(const ImmutableString &name, ImmutableString TextureFunctionHLSL::useTextureFunction(const ImmutableString &name,
TBasicType samplerType, TBasicType samplerType,
int coords, int coords,
size_t argumentCount, size_t argumentCount,
bool lod0, bool lod0,
sh::GLenum shaderType) sh::GLenum shaderType)
{ {
TextureFunction textureFunction; TextureFunction textureFunction;
textureFunction.sampler = samplerType; textureFunction.sampler = samplerType;
...@@ -1322,9 +1343,9 @@ void TextureFunctionHLSL::textureFunctionHeader(TInfoSinkBase &out, ...@@ -1322,9 +1343,9 @@ void TextureFunctionHLSL::textureFunctionHeader(TInfoSinkBase &out,
} }
else else
{ {
TString texCoordX("t.x"); ImmutableString texCoordX("t.x");
TString texCoordY("t.y"); ImmutableString texCoordY("t.y");
TString texCoordZ("t.z"); ImmutableString texCoordZ("t.z");
ProjectTextureCoordinates(textureFunction, &texCoordX, &texCoordY, &texCoordZ); ProjectTextureCoordinates(textureFunction, &texCoordX, &texCoordY, &texCoordZ);
OutputIntegerTextureSampleFunctionComputations(out, textureFunction, outputType, OutputIntegerTextureSampleFunctionComputations(out, textureFunction, outputType,
textureReference, &texCoordX, &texCoordY, textureReference, &texCoordX, &texCoordY,
......
...@@ -40,7 +40,7 @@ class TextureFunctionHLSL final : angle::NonCopyable ...@@ -40,7 +40,7 @@ class TextureFunctionHLSL final : angle::NonCopyable
GRAD GRAD
}; };
TString name() const; ImmutableString name() const;
bool operator<(const TextureFunction &rhs) const; bool operator<(const TextureFunction &rhs) const;
...@@ -55,12 +55,12 @@ class TextureFunctionHLSL final : angle::NonCopyable ...@@ -55,12 +55,12 @@ class TextureFunctionHLSL final : angle::NonCopyable
// Returns the name of the texture function implementation to call. // Returns the name of the texture function implementation to call.
// The name that's passed in is the name of the GLSL texture function that it should implement. // The name that's passed in is the name of the GLSL texture function that it should implement.
TString useTextureFunction(const ImmutableString &name, ImmutableString useTextureFunction(const ImmutableString &name,
TBasicType samplerType, TBasicType samplerType,
int coords, int coords,
size_t argumentCount, size_t argumentCount,
bool lod0, bool lod0,
sh::GLenum shaderType); sh::GLenum shaderType);
void textureFunctionHeader(TInfoSinkBase &out, void textureFunctionHeader(TInfoSinkBase &out,
const ShShaderOutput outputType, const ShShaderOutput outputType,
......
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