From 08d61df04069280fb2595adca7e796df39611f6f Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Fri, 19 Apr 2019 04:47:03 -0600 Subject: [PATCH] Fix #1720: Give an error for parameter mismatched image format. --- Test/310.comp | 6 +- Test/420.vert | 6 +- Test/baseResults/310.comp.out | 5 +- Test/baseResults/420.vert.out | 5 +- Test/baseResults/specExamples.vert.out | 4 +- Test/baseResults/specExamplesConf.vert.out | 4 +- Test/baseResults/spv.paramMemory.frag.out | 116 +++++++++------------ Test/specExamples.vert | 4 +- Test/spv.paramMemory.frag | 8 +- glslang/MachineIndependent/ParseHelper.cpp | 7 ++ 10 files changed, 82 insertions(+), 83 deletions(-) diff --git a/Test/310.comp b/Test/310.comp index 9ca8eaaa..33ecbf01 100644 --- a/Test/310.comp +++ b/Test/310.comp @@ -106,9 +106,9 @@ layout(r32i) coherent restrict readonly uniform iimage2D qualim2; void passrc() { - passr(qualim1); - passr(qualim2); // ERROR, drops restrict - passr(iimg2D); + passr(qualim1); // ERROR, changing formats + passr(qualim2); // ERROR, drops restrict, ERROR, changing formats + passr(iimg2D); // ERROR, changing formats } highp layout(rg8i) uniform readonly uimage2D i1bad; // ERROR, type mismatch diff --git a/Test/420.vert b/Test/420.vert index ab28140e..c7ffa902 100644 --- a/Test/420.vert +++ b/Test/420.vert @@ -131,9 +131,9 @@ layout(r32i) coherent volatile readonly uniform iimage2D qualim2; void passrc() { - passr(qualim1); - passr(qualim2); // ERROR, drops volatile - passr(iimg2D); + passr(qualim1); // ERROR, changing formats + passr(qualim2); // ERROR, drops volatile, ERROR, changing formats + passr(iimg2D); // ERROR, changing formats } layout(rg8i) uniform uimage2D i1bad; // ERROR, type mismatch diff --git a/Test/baseResults/310.comp.out b/Test/baseResults/310.comp.out index 5a926f67..b4136b0a 100644 --- a/Test/baseResults/310.comp.out +++ b/Test/baseResults/310.comp.out @@ -28,6 +28,9 @@ ERROR: 0:90: 'imageAtomicMax' : no matching overloaded function found ERROR: 0:94: 'writeonly' : argument cannot drop memory qualifier when passed to formal parameter ERROR: 0:97: '' : memory qualifiers cannot be used on this type ERROR: 0:98: '' : memory qualifiers cannot be used on this type +ERROR: 0:109: 'format' : image formats must match +ERROR: 0:110: 'format' : image formats must match +ERROR: 0:111: 'format' : image formats must match ERROR: 0:114: 'image load-store format' : not supported with this profile: es ERROR: 0:114: 'rg8i' : does not apply to unsigned integer images ERROR: 0:115: 'rgba32i' : does not apply to floating point images @@ -83,7 +86,7 @@ WARNING: 0:238: '#define' : names containing consecutive underscores are reserve ERROR: 0:244: 'gl_DeviceIndex' : required extension not requested: GL_EXT_device_group ERROR: 0:245: 'gl_ViewIndex' : undeclared identifier ERROR: 0:255: 'gl_ViewIndex' : undeclared identifier -ERROR: 82 compilation errors. No code generated. +ERROR: 85 compilation errors. No code generated. Shader version: 310 diff --git a/Test/baseResults/420.vert.out b/Test/baseResults/420.vert.out index 740c8fe7..c572d97b 100644 --- a/Test/baseResults/420.vert.out +++ b/Test/baseResults/420.vert.out @@ -38,7 +38,10 @@ ERROR: 0:115: 'imageAtomicMax' : no matching overloaded function found ERROR: 0:119: 'writeonly' : argument cannot drop memory qualifier when passed to formal parameter ERROR: 0:122: '' : memory qualifiers cannot be used on this type ERROR: 0:123: '' : memory qualifiers cannot be used on this type +ERROR: 0:134: 'format' : image formats must match ERROR: 0:135: 'volatile' : argument cannot drop memory qualifier when passed to formal parameter +ERROR: 0:135: 'format' : image formats must match +ERROR: 0:136: 'format' : image formats must match ERROR: 0:139: 'rg8i' : does not apply to unsigned integer images ERROR: 0:140: 'rgba32i' : does not apply to floating point images ERROR: 0:141: 'rgba32f' : does not apply to unsigned integer images @@ -52,7 +55,7 @@ ERROR: 0:157: 'assign' : cannot convert from ' const float' to ' temp int' ERROR: 0:158: 'textureQueryLevels' : no matching overloaded function found ERROR: 0:158: 'assign' : cannot convert from ' const float' to ' temp int' WARNING: 0:161: '[]' : assuming binding count of one for compile-time checking of binding numbers for unsized array -ERROR: 51 compilation errors. No code generated. +ERROR: 54 compilation errors. No code generated. Shader version: 420 diff --git a/Test/baseResults/specExamples.vert.out b/Test/baseResults/specExamples.vert.out index 5c8ca391..3a83f3b7 100644 --- a/Test/baseResults/specExamples.vert.out +++ b/Test/baseResults/specExamples.vert.out @@ -30,8 +30,10 @@ ERROR: 0:132: 'shared' : not supported in this stage: vertex ERROR: 0:134: '' : function does not return a value: funcA ERROR: 0:136: '' : function does not return a value: funcB ERROR: 0:153: '' : function does not return a value: func3 +ERROR: 0:169: 'format' : image formats must match ERROR: 0:170: 'coherent' : argument cannot drop memory qualifier when passed to formal parameter -ERROR: 32 compilation errors. No code generated. +ERROR: 0:170: 'format' : image formats must match +ERROR: 34 compilation errors. No code generated. Shader version: 430 diff --git a/Test/baseResults/specExamplesConf.vert.out b/Test/baseResults/specExamplesConf.vert.out index e7217817..6487de22 100644 --- a/Test/baseResults/specExamplesConf.vert.out +++ b/Test/baseResults/specExamplesConf.vert.out @@ -31,8 +31,10 @@ ERROR: 0:132: 'shared' : not supported in this stage: vertex ERROR: 0:134: '' : function does not return a value: funcA ERROR: 0:136: '' : function does not return a value: funcB ERROR: 0:153: '' : function does not return a value: func3 +ERROR: 0:169: 'format' : image formats must match ERROR: 0:170: 'coherent' : argument cannot drop memory qualifier when passed to formal parameter -ERROR: 33 compilation errors. No code generated. +ERROR: 0:170: 'format' : image formats must match +ERROR: 35 compilation errors. No code generated. Shader version: 430 diff --git a/Test/baseResults/spv.paramMemory.frag.out b/Test/baseResults/spv.paramMemory.frag.out index 02a48520..cba2fbd0 100644 --- a/Test/baseResults/spv.paramMemory.frag.out +++ b/Test/baseResults/spv.paramMemory.frag.out @@ -2,14 +2,14 @@ spv.paramMemory.frag Validation failed // Module Version 10000 // Generated by (magic number): 80007 -// Id's are bound by 69 +// Id's are bound by 64 Capability Shader Capability StorageImageReadWithoutFormat Capability StorageImageWriteWithoutFormat 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 27 66 + EntryPoint Fragment 4 "main" 27 61 ExecutionMode 4 OriginUpperLeft Source ESSL 310 Name 4 "main" @@ -22,39 +22,28 @@ Validation failed Name 22 "data" Name 27 "in_coords" Name 35 "read1" - Name 38 "image1" - Name 39 "param" - Name 42 "read2" - Name 45 "image2" + Name 38 "read2" + Name 43 "image3" Name 46 "param" - Name 49 "image3" - Name 53 "param" - Name 55 "param" - Name 57 "image4" - Name 61 "param" - Name 63 "param" - Name 66 "out_color" + Name 48 "param" + Name 52 "image4" + Name 56 "param" + Name 58 "param" + Name 61 "out_color" Decorate 14(image) Coherent Decorate 14(image) NonWritable Decorate 20(image) Coherent Decorate 20(image) NonReadable Decorate 27(in_coords) Flat Decorate 27(in_coords) Location 0 - Decorate 38(image1) DescriptorSet 0 - Decorate 38(image1) Binding 0 - Decorate 38(image1) Coherent - Decorate 38(image1) NonWritable - Decorate 45(image2) DescriptorSet 0 - Decorate 45(image2) Binding 2 - Decorate 45(image2) NonWritable - Decorate 49(image3) DescriptorSet 0 - Decorate 49(image3) Binding 1 - Decorate 49(image3) Coherent - Decorate 49(image3) NonReadable - Decorate 57(image4) DescriptorSet 0 - Decorate 57(image4) Binding 3 - Decorate 57(image4) NonReadable - Decorate 66(out_color) Location 0 + Decorate 43(image3) DescriptorSet 0 + Decorate 43(image3) Binding 1 + Decorate 43(image3) Coherent + Decorate 43(image3) NonReadable + Decorate 52(image4) DescriptorSet 0 + Decorate 52(image4) Binding 3 + Decorate 52(image4) NonReadable + Decorate 61(out_color) Location 0 2: TypeVoid 3: TypeFunction 2 6: TypeFloat 32 @@ -69,51 +58,44 @@ Validation failed 19: TypeFunction 2 8(ptr) 11(ptr) 18(ptr) 26: TypePointer Input 10(ivec2) 27(in_coords): 26(ptr) Variable Input - 36: TypeImage 6(float) 2D nonsampled format:Rgba32f - 37: TypePointer UniformConstant 36 - 38(image1): 37(ptr) Variable UniformConstant - 43: TypeImage 6(float) 2D nonsampled format:Rgba16f - 44: TypePointer UniformConstant 43 - 45(image2): 44(ptr) Variable UniformConstant - 49(image3): 37(ptr) Variable UniformConstant - 51: 6(float) Constant 1056964608 - 57(image4): 44(ptr) Variable UniformConstant - 59: 6(float) Constant 1073741824 - 65: TypePointer Output 12(fvec4) - 66(out_color): 65(ptr) Variable Output - 67: 6(float) Constant 0 - 68: 12(fvec4) ConstantComposite 67 67 67 67 + 36: 6(float) Constant 1053609165 + 37: 12(fvec4) ConstantComposite 36 36 36 36 + 39: 6(float) Constant 1056964608 + 40: 12(fvec4) ConstantComposite 39 39 39 39 + 41: TypeImage 6(float) 2D nonsampled format:Rgba32f + 42: TypePointer UniformConstant 41 + 43(image3): 42(ptr) Variable UniformConstant + 50: TypeImage 6(float) 2D nonsampled format:Rgba16f + 51: TypePointer UniformConstant 50 + 52(image4): 51(ptr) Variable UniformConstant + 54: 6(float) Constant 1073741824 + 60: TypePointer Output 12(fvec4) + 61(out_color): 60(ptr) Variable Output + 62: 6(float) Constant 0 + 63: 12(fvec4) ConstantComposite 62 62 62 62 4(main): 2 Function None 3 5: Label 35(read1): 18(ptr) Variable Function - 39(param): 11(ptr) Variable Function - 42(read2): 18(ptr) Variable Function + 38(read2): 18(ptr) Variable Function 46(param): 11(ptr) Variable Function - 53(param): 11(ptr) Variable Function - 55(param): 18(ptr) Variable Function - 61(param): 11(ptr) Variable Function - 63(param): 18(ptr) Variable Function - 40: 10(ivec2) Load 27(in_coords) - Store 39(param) 40 - 41: 12(fvec4) FunctionCall 16(image_load(I21;vi2;) 38(image1) 39(param) - Store 35(read1) 41 + 48(param): 18(ptr) Variable Function + 56(param): 11(ptr) Variable Function + 58(param): 18(ptr) Variable Function + Store 35(read1) 37 + Store 38(read2) 40 + 44: 12(fvec4) Load 35(read1) + 45: 12(fvec4) VectorTimesScalar 44 39 47: 10(ivec2) Load 27(in_coords) Store 46(param) 47 - 48: 12(fvec4) FunctionCall 16(image_load(I21;vi2;) 45(image2) 46(param) - Store 42(read2) 48 - 50: 12(fvec4) Load 35(read1) - 52: 12(fvec4) VectorTimesScalar 50 51 - 54: 10(ivec2) Load 27(in_coords) - Store 53(param) 54 - Store 55(param) 52 - 56: 2 FunctionCall 23(image_store(I21;vi2;vf4;) 49(image3) 53(param) 55(param) - 58: 12(fvec4) Load 42(read2) - 60: 12(fvec4) VectorTimesScalar 58 59 - 62: 10(ivec2) Load 27(in_coords) - Store 61(param) 62 - Store 63(param) 60 - 64: 2 FunctionCall 23(image_store(I21;vi2;vf4;) 57(image4) 61(param) 63(param) - Store 66(out_color) 68 + Store 48(param) 45 + 49: 2 FunctionCall 23(image_store(I21;vi2;vf4;) 43(image3) 46(param) 48(param) + 53: 12(fvec4) Load 38(read2) + 55: 12(fvec4) VectorTimesScalar 53 54 + 57: 10(ivec2) Load 27(in_coords) + Store 56(param) 57 + Store 58(param) 55 + 59: 2 FunctionCall 23(image_store(I21;vi2;vf4;) 52(image4) 56(param) 58(param) + Store 61(out_color) 63 Return FunctionEnd 16(image_load(I21;vi2;): 12(fvec4) Function None 13 diff --git a/Test/specExamples.vert b/Test/specExamples.vert index 9df1561f..64ec7104 100644 --- a/Test/specExamples.vert +++ b/Test/specExamples.vert @@ -166,8 +166,8 @@ void main() v.x = func2(a.x, b.x, c.x, d.x); // precise! func3(a.x * b.x, c.x * d.x, v.x); // precise! - funcA(img1); // OK, adding "restrict" is allowed - funcB(img2); // illegal, stripping "coherent" is not + funcA(img1); // OK, adding "restrict" is allowed, ERROR, changing formats + funcB(img2); // illegal, stripping "coherent" is not, ERROR, changing formats { struct light { diff --git a/Test/spv.paramMemory.frag b/Test/spv.paramMemory.frag index 79d2fe57..1d080814 100644 --- a/Test/spv.paramMemory.frag +++ b/Test/spv.paramMemory.frag @@ -1,7 +1,7 @@ #version 310 es -readonly coherent uniform layout(set = 0, binding = 0, rgba32f) highp image2D image1; -readonly uniform layout(set = 0, binding = 2, rgba16f) highp image2D image2; +// readonly coherent uniform layout(set = 0, binding = 0) highp image2D image1; +// readonly uniform layout(set = 0, binding = 2) highp image2D image2; writeonly coherent uniform layout(set = 0, binding = 1, rgba32f) highp image2D image3; writeonly uniform layout(set = 0, binding = 3, rgba16f) highp image2D image4; @@ -20,8 +20,8 @@ void image_store(writeonly coherent highp image2D image, highp ivec2 coords, hig void main() { - highp vec4 read1 = image_load(image1, in_coords); - highp vec4 read2 = image_load(image2, in_coords); + highp vec4 read1 = vec4(0.4); // = image_load(image1, in_coords); + highp vec4 read2 = vec4(0.5); // = image_load(image2, in_coords); image_store(image3, in_coords, read1*0.5); image_store(image4, in_coords, read2*2.0); diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index e1e2ee91..593089c9 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1157,6 +1157,13 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction if (argQualifier.writeonly && ! formalQualifier.writeonly) error(arguments->getLoc(), message, "writeonly", ""); } + if (!builtIn && argQualifier.layoutFormat != formalQualifier.layoutFormat) { + // we have mismatched formats, which should only be allowed if writeonly + // and at least one format is unknown + if (!formalQualifier.writeonly || (formalQualifier.layoutFormat != ElfNone && + argQualifier.layoutFormat != ElfNone)) + error(arguments->getLoc(), "image formats must match", "format", ""); + } if (builtIn && arg->getAsTyped()->getType().containsBasicType(EbtFloat16)) requireFloat16Arithmetic(arguments->getLoc(), "built-in function", "float16 types can only be in uniform block or buffer storage");