mirror of
https://github.com/godotengine/godot-angle-static.git
synced 2026-01-03 14:09:33 +03:00
Translator: Unconditionally limit variable sizes
... instead of just for WebGL. This is to avoid hitting driver bugs that were prevented with this check for WebGL on a compromised renderer that can create non-WebGL contexts. Bug: chromium:1464682 Change-Id: I47a9d9690bd1ca9d701391fb7d70932f2dbe7334 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4685307 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
This commit is contained in:
committed by
Angle LUCI CQ
parent
35c077b110
commit
5032f08b35
@@ -397,9 +397,10 @@ bool TCompiler::shouldRunLoopAndIndexingValidation(const ShCompileOptions &compi
|
||||
|
||||
bool TCompiler::shouldLimitTypeSizes() const
|
||||
{
|
||||
// WebGL shaders limit the size of variables' types in shaders,
|
||||
// including arrays, structs and interface blocks.
|
||||
return IsWebGLBasedSpec(mShaderSpec);
|
||||
// Prevent unrealistically large variable sizes in shaders. This works around driver bugs
|
||||
// around int-size limits (such as 2GB). The limits are generously large enough that no real
|
||||
// shader should ever hit it.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TCompiler::Init(const ShBuiltInResources &resources)
|
||||
|
||||
@@ -23,10 +23,10 @@ namespace
|
||||
// Arbitrarily enforce that all types declared with a size in bytes of over 2 GB will cause
|
||||
// compilation failure.
|
||||
//
|
||||
// For local and global variables, the limit is much lower (1MB) as that much memory won't fit in
|
||||
// For local and global variables, the limit is much lower (16MB) as that much memory won't fit in
|
||||
// the GPU registers anyway.
|
||||
constexpr size_t kMaxVariableSizeInBytes = static_cast<size_t>(2) * 1024 * 1024 * 1024;
|
||||
constexpr size_t kMaxPrivateVariableSizeInBytes = static_cast<size_t>(1) * 1024 * 1024;
|
||||
constexpr size_t kMaxPrivateVariableSizeInBytes = static_cast<size_t>(16) * 1024 * 1024;
|
||||
|
||||
// Traverses intermediate tree to ensure that the shader does not
|
||||
// exceed certain implementation-defined limits on the sizes of types.
|
||||
|
||||
@@ -282,6 +282,9 @@ GLenum GLVariableType(const TType &type)
|
||||
|
||||
return kBoolGLType[type.getNominalSize() - 1];
|
||||
|
||||
case EbtYuvCscStandardEXT:
|
||||
return GL_UNSIGNED_INT;
|
||||
|
||||
case EbtSampler2D:
|
||||
return GL_SAMPLER_2D;
|
||||
case EbtSampler3D:
|
||||
|
||||
@@ -5302,8 +5302,8 @@ void main()
|
||||
|
||||
constexpr char kVSArrayTooLarge[] =
|
||||
R"(varying vec4 color;
|
||||
// 1 MB / 32 aligned bytes per mat2 = 32768
|
||||
const int array_size = 32769;
|
||||
// 16 MB / 32 aligned bytes per mat2 = 524288
|
||||
const int array_size = 524289;
|
||||
void main()
|
||||
{
|
||||
mat2 array[array_size];
|
||||
@@ -5315,7 +5315,7 @@ void main()
|
||||
|
||||
constexpr char kVSArrayMuchTooLarge[] =
|
||||
R"(varying vec4 color;
|
||||
const int array_size = 55600;
|
||||
const int array_size = 757000;
|
||||
void main()
|
||||
{
|
||||
mat2 array[array_size];
|
||||
@@ -5379,9 +5379,9 @@ TEST_P(WebGLCompatibilityTest, ValidateTotalPrivateSize)
|
||||
constexpr char kTooLargeGlobalMemory1[] =
|
||||
R"(precision mediump float;
|
||||
|
||||
// 1 MB / 16 bytes per vec4 = 65536
|
||||
vec4 array[32768];
|
||||
vec4 array2[32769];
|
||||
// 16 MB / 16 bytes per vec4 = 1048576
|
||||
vec4 array[524288];
|
||||
vec4 array2[524289];
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -5394,9 +5394,9 @@ void main()
|
||||
constexpr char kTooLargeGlobalMemory2[] =
|
||||
R"(precision mediump float;
|
||||
|
||||
// 1 MB / 16 bytes per vec4 = 65536
|
||||
vec4 array[32767];
|
||||
vec4 array2[32767];
|
||||
// 16 MB / 16 bytes per vec4 = 1048576
|
||||
vec4 array[524287];
|
||||
vec4 array2[524287];
|
||||
vec4 x, y, z;
|
||||
|
||||
void main()
|
||||
@@ -5410,12 +5410,12 @@ void main()
|
||||
constexpr char kTooLargeGlobalAndLocalMemory1[] =
|
||||
R"(precision mediump float;
|
||||
|
||||
// 1 MB / 16 bytes per vec4 = 65536
|
||||
vec4 array[32768];
|
||||
// 16 MB / 16 bytes per vec4 = 1048576
|
||||
vec4 array[524288];
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 array2[32769];
|
||||
vec4 array2[524289];
|
||||
if (array[0].x + array[1].x == 2.0)
|
||||
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
|
||||
else
|
||||
@@ -5426,18 +5426,18 @@ void main()
|
||||
constexpr char kTooLargeGlobalAndLocalMemory2[] =
|
||||
R"(precision mediump float;
|
||||
|
||||
// 1 MB / 16 bytes per vec4 = 65536
|
||||
vec4 array[32768];
|
||||
// 16 MB / 16 bytes per vec4 = 1048576
|
||||
vec4 array[524288];
|
||||
|
||||
float f()
|
||||
{
|
||||
vec4 array2[16384];
|
||||
vec4 array2[524288];
|
||||
return array2[0].x;
|
||||
}
|
||||
|
||||
float g()
|
||||
{
|
||||
vec4 array3[16383];
|
||||
vec4 array3[524287];
|
||||
return array3[0].x;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user