Commit 51c4768b by Jamie Madill Committed by Commit Bot

Fix a couple global variable warnings.

The DynamicHLSL code was using global strings to find stubs. The math code was also using pow in a global, which can be replaced with a simple bit shift. BUG=angleproject:1459 Change-Id: Idb0602ab7640c221843385b0a0a4cfecd5fd3a26 Reviewed-on: https://chromium-review.googlesource.com/403289Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent c5fa0ad5
......@@ -14,6 +14,9 @@
namespace gl
{
namespace
{
struct RGB9E5Data
{
unsigned int R : 9;
......@@ -23,17 +26,20 @@ struct RGB9E5Data
};
// B is the exponent bias (15)
static const int g_sharedexp_bias = 15;
constexpr int g_sharedexp_bias = 15;
// N is the number of mantissa bits per component (9)
static const int g_sharedexp_mantissabits = 9;
constexpr int g_sharedexp_mantissabits = 9;
// Emax is the maximum allowed biased exponent value (31)
static const int g_sharedexp_maxexponent = 31;
constexpr int g_sharedexp_maxexponent = 31;
constexpr float g_sharedexp_max =
((static_cast<float>(1 << g_sharedexp_mantissabits) - 1) /
static_cast<float>(1 << g_sharedexp_mantissabits)) *
static_cast<float>(1 << (g_sharedexp_maxexponent - g_sharedexp_bias));
static const float g_sharedexp_max = ((pow(2.0f, g_sharedexp_mantissabits) - 1) /
pow(2.0f, g_sharedexp_mantissabits)) *
pow(2.0f, g_sharedexp_maxexponent - g_sharedexp_bias);
} // anonymous namespace
unsigned int convertRGBFloatsTo999E5(float red, float green, float blue)
{
......
......@@ -117,8 +117,8 @@ void WriteArrayString(std::stringstream &strstr, unsigned int i)
strstr << "]";
}
const std::string VERTEX_ATTRIBUTE_STUB_STRING = "@@ VERTEX ATTRIBUTES @@";
const std::string PIXEL_OUTPUT_STUB_STRING = "@@ PIXEL OUTPUT @@";
constexpr const char *VERTEX_ATTRIBUTE_STUB_STRING = "@@ VERTEX ATTRIBUTES @@";
constexpr const char *PIXEL_OUTPUT_STUB_STRING = "@@ PIXEL OUTPUT @@";
} // anonymous namespace
std::string GetVaryingSemantic(int majorShaderModel, bool programUsesPointSize)
......@@ -295,7 +295,7 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(
std::string vertexHLSL(sourceShader);
size_t copyInsertionPos = vertexHLSL.find(VERTEX_ATTRIBUTE_STUB_STRING);
vertexHLSL.replace(copyInsertionPos, VERTEX_ATTRIBUTE_STUB_STRING.length(), structStream.str());
vertexHLSL.replace(copyInsertionPos, strlen(VERTEX_ATTRIBUTE_STUB_STRING), structStream.str());
return vertexHLSL;
}
......@@ -360,7 +360,7 @@ std::string DynamicHLSL::generatePixelShaderForOutputSignature(
std::string pixelHLSL(sourceShader);
size_t outputInsertionPos = pixelHLSL.find(PIXEL_OUTPUT_STUB_STRING);
pixelHLSL.replace(outputInsertionPos, PIXEL_OUTPUT_STUB_STRING.length(),
pixelHLSL.replace(outputInsertionPos, strlen(PIXEL_OUTPUT_STUB_STRING),
declarationStream.str());
return pixelHLSL;
......@@ -440,7 +440,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::ContextState &data,
}
// Add stub string to be replaced when shader is dynamically defined by its layout
vertexStream << "\n" << VERTEX_ATTRIBUTE_STUB_STRING + "\n";
vertexStream << "\n" << std::string(VERTEX_ATTRIBUTE_STUB_STRING) << "\n";
// Write the HLSL input/output declarations
vertexStream << "struct VS_OUTPUT\n";
......@@ -597,7 +597,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::ContextState &data,
generateVaryingLinkHLSL(SHADER_PIXEL, varyingPacking, pixelStream);
pixelStream << "\n";
pixelStream << PIXEL_OUTPUT_STUB_STRING + "\n";
pixelStream << std::string(PIXEL_OUTPUT_STUB_STRING) << "\n";
if (fragmentShader->usesFrontFacing())
{
......
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