Commit b1f45b70 by Nicolas Capens

Create HLSL texture offset functions.

BUG=angle:541 Change-Id: I63dd47c40d693724aa6bed93e9967e3b1f8535bd Reviewed-on: https://chromium-review.googlesource.com/181521Tested-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent f831e3dd
// //
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -57,6 +57,11 @@ TString OutputHLSL::TextureFunction::name() const ...@@ -57,6 +57,11 @@ TString OutputHLSL::TextureFunction::name() const
name += "Proj"; name += "Proj";
} }
if (offset)
{
name += "Offset";
}
switch(method) switch(method)
{ {
case IMPLICIT: break; case IMPLICIT: break;
...@@ -1009,13 +1014,36 @@ void OutputHLSL::header() ...@@ -1009,13 +1014,36 @@ void OutputHLSL::header()
switch(textureFunction->method) switch(textureFunction->method)
{ {
case TextureFunction::IMPLICIT: break; case TextureFunction::IMPLICIT: break;
case TextureFunction::BIAS: out << ", float bias"; break; case TextureFunction::BIAS: break;
case TextureFunction::LOD: out << ", float lod"; break; case TextureFunction::LOD: out << ", float lod"; break;
case TextureFunction::LOD0: break; case TextureFunction::LOD0: break;
case TextureFunction::SIZE: break; case TextureFunction::SIZE: break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
if (textureFunction->offset)
{
switch(textureFunction->sampler)
{
case EbtSampler2D: out << ", int2 offset"; break;
case EbtSampler3D: out << ", int3 offset"; break;
case EbtSampler2DArray: out << ", int2 offset"; break;
case EbtISampler2D: out << ", int2 offset"; break;
case EbtISampler3D: out << ", int3 offset"; break;
case EbtISampler2DArray: out << ", int2 offset"; break;
case EbtUSampler2D: out << ", int2 offset"; break;
case EbtUSampler3D: out << ", int3 offset"; break;
case EbtUSampler2DArray: out << ", int2 offset"; break;
case EbtSampler2DShadow: out << ", int2 offset"; break;
default: UNREACHABLE();
}
}
if (textureFunction->method == TextureFunction::BIAS)
{
out << ", float bias";
}
out << ")\n" out << ")\n"
"{\n"; "{\n";
...@@ -1310,15 +1338,15 @@ void OutputHLSL::header() ...@@ -1310,15 +1338,15 @@ void OutputHLSL::header()
if (IsIntegerSampler(textureFunction->sampler)) if (IsIntegerSampler(textureFunction->sampler))
{ {
out << ", mip));"; out << ", mip)";
} }
else if (IsShadowSampler(textureFunction->sampler)) else if (IsShadowSampler(textureFunction->sampler))
{ {
// Compare value // Compare value
switch(textureFunction->coords) switch(textureFunction->coords)
{ {
case 3: out << "), t.z);"; break; case 3: out << "), t.z"; break;
case 4: out << "), t.w);"; break; case 4: out << "), t.w"; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
...@@ -1326,13 +1354,20 @@ void OutputHLSL::header() ...@@ -1326,13 +1354,20 @@ void OutputHLSL::header()
{ {
switch(textureFunction->method) switch(textureFunction->method)
{ {
case TextureFunction::IMPLICIT: out << "));"; break; case TextureFunction::IMPLICIT: out << ")"; break;
case TextureFunction::BIAS: out << "), bias);"; break; case TextureFunction::BIAS: out << "), bias"; break;
case TextureFunction::LOD: out << "), lod);"; break; case TextureFunction::LOD: out << "), lod"; break;
case TextureFunction::LOD0: out << "), 0);"; break; case TextureFunction::LOD0: out << "), 0"; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
if (textureFunction->offset)
{
out << ", offset";
}
out << ");";
} }
else UNREACHABLE(); else UNREACHABLE();
} }
...@@ -2277,6 +2312,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2277,6 +2312,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
textureFunction.coords = arguments[1]->getAsTyped()->getNominalSize(); textureFunction.coords = arguments[1]->getAsTyped()->getNominalSize();
textureFunction.method = TextureFunction::IMPLICIT; textureFunction.method = TextureFunction::IMPLICIT;
textureFunction.proj = false; textureFunction.proj = false;
textureFunction.offset = false;
if (name == "texture2D" || name == "textureCube" || name == "texture") if (name == "texture2D" || name == "textureCube" || name == "texture")
{ {
...@@ -2300,18 +2336,32 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2300,18 +2336,32 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
textureFunction.method = TextureFunction::SIZE; textureFunction.method = TextureFunction::SIZE;
} }
else if (name == "textureOffset")
{
textureFunction.method = TextureFunction::IMPLICIT;
textureFunction.offset = true;
}
else UNREACHABLE(); else UNREACHABLE();
if (textureFunction.method != TextureFunction::LOD && if (textureFunction.method == TextureFunction::IMPLICIT) // Could require lod 0 or have a bias argument
textureFunction.method != TextureFunction::SIZE)
{ {
if (lod0 || mContext.shaderType == SH_VERTEX_SHADER) if (lod0 || mContext.shaderType == SH_VERTEX_SHADER)
{ {
textureFunction.method = TextureFunction::LOD0; textureFunction.method = TextureFunction::LOD0;
} }
else if (arguments.size() == 3) else
{ {
textureFunction.method = TextureFunction::BIAS; unsigned int mandatoryArgumentCount = 2; // All functions have sampler and coordinate arguments
if (textureFunction.offset)
{
mandatoryArgumentCount++;
}
if (arguments.size() > mandatoryArgumentCount) // Bias argument is optional
{
textureFunction.method = TextureFunction::BIAS;
}
} }
} }
......
// //
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -110,6 +110,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -110,6 +110,7 @@ class OutputHLSL : public TIntermTraverser
TBasicType sampler; TBasicType sampler;
int coords; int coords;
bool proj; bool proj;
bool offset;
Method method; Method method;
TString name() const; TString name() const;
......
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