Commit 329747ca by Alexis Hetu Committed by Alexis Hétu

Added check for temporary register overflow

Currently, when overflowing the number of temporary registers allowed, SwiftShader will crash somewhere in the generated code. This cl adds an early check to prevent the crash and instead output an error message to the user. Bug chromium:814987 Change-Id: Idadda21ee14298662763d986ee1283a5114c1c01 Reviewed-on: https://swiftshader-review.googlesource.com/18388Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 10bcdb46
...@@ -96,6 +96,7 @@ namespace sw ...@@ -96,6 +96,7 @@ namespace sw
MAX_PROGRAM_TEXEL_OFFSET = 7, MAX_PROGRAM_TEXEL_OFFSET = 7,
MAX_TEXTURE_LOD = MIPMAP_LEVELS - 2, // Trilinear accesses lod+1 MAX_TEXTURE_LOD = MIPMAP_LEVELS - 2, // Trilinear accesses lod+1
RENDERTARGETS = 8, RENDERTARGETS = 8,
NUM_TEMPORARY_REGISTERS = 4096,
}; };
} }
......
...@@ -3031,7 +3031,14 @@ namespace glsl ...@@ -3031,7 +3031,14 @@ namespace glsl
int OutputASM::temporaryRegister(TIntermTyped *temporary) int OutputASM::temporaryRegister(TIntermTyped *temporary)
{ {
return allocate(temporaries, temporary); int index = allocate(temporaries, temporary);
if(index >= sw::NUM_TEMPORARY_REGISTERS)
{
mContext.error(temporary->getLine(),
"Too many temporary registers required to compile shader",
pixelShader ? "pixel shader" : "vertex shader");
}
return index;
} }
void OutputASM::setPixelShaderInputs(const TType& type, int var, bool flat) void OutputASM::setPixelShaderInputs(const TType& type, int var, bool flat)
......
...@@ -55,7 +55,7 @@ namespace sw ...@@ -55,7 +55,7 @@ namespace sw
private: private:
// Temporary registers // Temporary registers
RegisterArray<4096> r; RegisterArray<NUM_TEMPORARY_REGISTERS> r;
// Color outputs // Color outputs
Vector4f c[RENDERTARGETS]; Vector4f c[RENDERTARGETS];
......
...@@ -37,7 +37,7 @@ namespace sw ...@@ -37,7 +37,7 @@ namespace sw
private: private:
const VertexShader *const shader; const VertexShader *const shader;
RegisterArray<4096> r; // Temporary registers RegisterArray<NUM_TEMPORARY_REGISTERS> r; // Temporary registers
Vector4f a0; Vector4f a0;
Array<Int, 4> aL; Array<Int, 4> aL;
Vector4f p0; Vector4f p0;
......
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