From 8cd85272adb6f966faee08b8b52e8997120b87ec Mon Sep 17 00:00:00 2001 From: ZhiqianXia Date: Mon, 19 Jul 2021 17:24:28 +0800 Subject: [PATCH] Support Uint to Int implicit conversions at #extension GL_ARB_gpu_shader5. Signed-off-by: ZhiqianXia --- Test/GL_ARB_gpu_shader5.u2i.vert | 11 ++++ .../GL_ARB_gpu_shader5.u2i.vert.out | 57 +++++++++++++++++++ glslang/MachineIndependent/Intermediate.cpp | 2 +- .../MachineIndependent/localintermediate.h | 5 ++ gtests/AST.FromFile.cpp | 1 + 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 Test/GL_ARB_gpu_shader5.u2i.vert create mode 100644 Test/baseResults/GL_ARB_gpu_shader5.u2i.vert.out diff --git a/Test/GL_ARB_gpu_shader5.u2i.vert b/Test/GL_ARB_gpu_shader5.u2i.vert new file mode 100644 index 000000000..0caa9bcfa --- /dev/null +++ b/Test/GL_ARB_gpu_shader5.u2i.vert @@ -0,0 +1,11 @@ +#version 150 +#extension GL_ARB_gpu_shader5 : require + +uniform int u1; +uniform int u2; +out vec4 result; +void main() +{ + uint v = 0; + v = uint(u2) - u1; // implicit conversions +} diff --git a/Test/baseResults/GL_ARB_gpu_shader5.u2i.vert.out b/Test/baseResults/GL_ARB_gpu_shader5.u2i.vert.out new file mode 100644 index 000000000..c7b34556f --- /dev/null +++ b/Test/baseResults/GL_ARB_gpu_shader5.u2i.vert.out @@ -0,0 +1,57 @@ +GL_ARB_gpu_shader5.u2i.vert +WARNING: 0:2: '#extension' : extension is only partially supported: GL_ARB_gpu_shader5 + +Shader version: 150 +Requested GL_ARB_gpu_shader5 +0:? Sequence +0:7 Function Definition: main( ( global void) +0:7 Function Parameters: +0:9 Sequence +0:9 Sequence +0:9 move second child to first child ( temp uint) +0:9 'v' ( temp uint) +0:9 Constant: +0:9 0 (const uint) +0:10 move second child to first child ( temp uint) +0:10 'v' ( temp uint) +0:10 subtract ( temp uint) +0:10 Convert int to uint ( temp uint) +0:10 'u2' ( uniform int) +0:10 Convert int to uint ( temp uint) +0:10 'u1' ( uniform int) +0:? Linker Objects +0:? 'u1' ( uniform int) +0:? 'u2' ( uniform int) +0:? 'result' ( smooth out 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + + +Linked vertex stage: + + +Shader version: 150 +Requested GL_ARB_gpu_shader5 +0:? Sequence +0:7 Function Definition: main( ( global void) +0:7 Function Parameters: +0:9 Sequence +0:9 Sequence +0:9 move second child to first child ( temp uint) +0:9 'v' ( temp uint) +0:9 Constant: +0:9 0 (const uint) +0:10 move second child to first child ( temp uint) +0:10 'v' ( temp uint) +0:10 subtract ( temp uint) +0:10 Convert int to uint ( temp uint) +0:10 'u2' ( uniform int) +0:10 Convert int to uint ( temp uint) +0:10 'u1' ( uniform int) +0:? Linker Objects +0:? 'u1' ( uniform int) +0:? 'u2' ( uniform int) +0:? 'result' ( smooth out 4-component vector of float) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index d1123d4a9..a2c57326c 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -1739,7 +1739,7 @@ bool TIntermediate::canImplicitlyPromote(TBasicType from, TBasicType to, TOperat case EbtUint: switch (from) { case EbtInt: - return version >= 400 || getSource() == EShSourceHlsl; + return version >= 400 || getSource() == EShSourceHlsl || IsRequestedExtension(E_GL_ARB_gpu_shader5); case EbtBool: return getSource() == EShSourceHlsl; case EbtInt16: diff --git a/glslang/MachineIndependent/localintermediate.h b/glslang/MachineIndependent/localintermediate.h index 5cc9930ac..b8353f985 100644 --- a/glslang/MachineIndependent/localintermediate.h +++ b/glslang/MachineIndependent/localintermediate.h @@ -926,6 +926,11 @@ public: return false; } + bool IsRequestedExtension(const char* extension) const + { + return (requestedExtensions.find(extension) != requestedExtensions.end()); + } + void addToCallGraph(TInfoSink&, const TString& caller, const TString& callee); void merge(TInfoSink&, TIntermediate&); void finalCheck(TInfoSink&, bool keepUncalled); diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index 77f0aafbf..16cda6b79 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -282,6 +282,7 @@ INSTANTIATE_TEST_SUITE_P( "terminate.vert", "negativeWorkGroupSize.comp", "textureoffset_sampler2darrayshadow.vert", + "GL_ARB_gpu_shader5.u2i.vert", })), FileNameAsCustomTestSuffix );