From 5c61d8e0f95981359db3353383677773040509ca Mon Sep 17 00:00:00 2001 From: qining Date: Thu, 31 Mar 2016 13:57:28 -0400 Subject: [PATCH] fix format; remove unnecessary parameters; rename some spec op mode guard class; remove support of float point comparison and composite type comparison; update the tests. --- SPIRV/GlslangToSpv.cpp | 21 ++- SPIRV/SpvBuilder.cpp | 86 +-------- .../spv.specConstantOperations.vert.out | 169 +++++------------- Test/spv.specConstantOperations.vert | 45 +---- 4 files changed, 63 insertions(+), 258 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index ee48b3c1..9622a775 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -3855,21 +3855,19 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstUnionArray(const glsla } namespace { -class SpecConstOpCodeGenerationSettingGuard{ - public: - SpecConstOpCodeGenerationSettingGuard(spv::Builder* builder, - bool shouldGeneratingForSpecConst) +class SpecConstantOpModeGuard { +public: + SpecConstantOpModeGuard(spv::Builder* builder) : builder_(builder) { previous_flag_ = builder->isInSpecConstCodeGenMode(); - shouldGeneratingForSpecConst ? builder->setToSpecConstCodeGenMode() - : builder->setToNormalCodeGenMode(); + builder->setToSpecConstCodeGenMode(); } - ~SpecConstOpCodeGenerationSettingGuard() { + ~SpecConstantOpModeGuard() { previous_flag_ ? builder_->setToSpecConstCodeGenMode() : builder_->setToNormalCodeGenMode(); } - private: +private: spv::Builder* builder_; bool previous_flag_; }; @@ -3877,7 +3875,8 @@ class SpecConstOpCodeGenerationSettingGuard{ // Create constant ID from const initializer sub tree. spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstSubTree( - glslang::TIntermTyped* subTree) { + glslang::TIntermTyped* subTree) +{ const glslang::TType& glslangType = subTree->getType(); spv::Id typeId = convertGlslangToSpvType(glslangType); bool is_spec_const = subTree->getType().getQualifier().isSpecConstant(); @@ -3909,7 +3908,7 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstSubTree( // Spec constants defined with binary operations and other constants requires // OpSpecConstantOp instruction. - SpecConstOpCodeGenerationSettingGuard set_to_spec_const_mode(&builder, true); + SpecConstantOpModeGuard set_to_spec_const_mode(&builder); bn->traverse(this); return accessChainLoad(bn->getType()); @@ -3920,7 +3919,7 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstSubTree( // Spec constants defined with unary operations and other constants requires // OpSpecConstantOp instruction. - SpecConstOpCodeGenerationSettingGuard set_to_spec_const_mode(&builder, true); + SpecConstantOpModeGuard set_to_spec_const_mode(&builder); un->traverse(this); return accessChainLoad(un->getType()); diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp index 3c0e2f63..4235f273 100644 --- a/SPIRV/SpvBuilder.cpp +++ b/SPIRV/SpvBuilder.cpp @@ -1229,90 +1229,8 @@ Id Builder::createOp(Op opCode, Id typeId, const std::vector& operands) return op->getResultId(); } -Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector& operands, const std::vector& literals) { - switch(opCode) { - // OpCodes that do not need any capababilities. - case OpSConvert: - case OpFConvert: - case OpSNegate: - case OpNot: - case OpIAdd: - case OpISub: - case OpIMul: - case OpUDiv: - case OpSDiv: - case OpUMod: - case OpSRem: - case OpSMod: - case OpShiftRightLogical: - case OpShiftRightArithmetic: - case OpShiftLeftLogical: - case OpBitwiseOr: - case OpBitwiseXor: - case OpBitwiseAnd: - case OpVectorShuffle: - case OpCompositeExtract: - case OpCompositeInsert: - case OpLogicalOr: - case OpLogicalAnd: - case OpLogicalNot: - case OpLogicalEqual: - case OpLogicalNotEqual: - case OpSelect: - case OpIEqual: - case OpULessThan: - case OpSLessThan: - case OpUGreaterThan: - case OpSGreaterThan: - case OpULessThanEqual: - case OpSLessThanEqual: - case OpUGreaterThanEqual: - case OpSGreaterThanEqual: - // Added temporarily to enable compsite type spec constants comparison. - // Remove this comment after Spec being updated. - case OpAll: - case OpAny: - case OpFOrdEqual: - case OpFUnordEqual: - case OpFOrdNotEqual: - case OpFUnordNotEqual: - break; - - // OpCodes that need Shader capability. - case OpQuantizeToF16: - addCapability(CapabilityShader); - break; - - // OpCodes that need Kernel capability. - case OpConvertFToS: - case OpConvertSToF: - case OpConvertFToU: - case OpConvertUToF: - case OpUConvert: - case OpConvertPtrToU: - case OpConvertUToPtr: - case OpGenericCastToPtr: - case OpPtrCastToGeneric: - case OpBitcast: - case OpFNegate: - case OpFAdd: - case OpFSub: - case OpFMul: - case OpFDiv: - case OpFRem: - case OpFMod: - case OpAccessChain: - case OpInBoundsAccessChain: - case OpPtrAccessChain: - case OpInBoundsPtrAccessChain: - addCapability(CapabilityKernel); - break; - - default: - // Invalid OpCode for Spec Constant operations. - return NoResult; - } - +Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector& operands, const std::vector& literals) +{ Instruction* op = new Instruction(getUniqueId(), typeId, OpSpecConstantOp); op->addImmediateOperand((unsigned) opCode); for (auto it = operands.cbegin(); it != operands.cend(); ++it) diff --git a/Test/baseResults/spv.specConstantOperations.vert.out b/Test/baseResults/spv.specConstantOperations.vert.out index c3eaedd5..476efc90 100644 --- a/Test/baseResults/spv.specConstantOperations.vert.out +++ b/Test/baseResults/spv.specConstantOperations.vert.out @@ -7,21 +7,15 @@ Linked vertex stage: // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 163 +// Id's are bound by 94 Capability Shader - Capability Kernel Capability Float64 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 EntryPoint Vertex 4 "main" Source GLSL 450 Name 4 "main" - Name 108 "int_float_double_vec2" - MemberName 108(int_float_double_vec2) 0 "i" - MemberName 108(int_float_double_vec2) 1 "f" - MemberName 108(int_float_double_vec2) 2 "d" - MemberName 108(int_float_double_vec2) 3 "v" Decorate 7 SpecId 200 Decorate 9 SpecId 201 Decorate 11 SpecId 202 @@ -70,121 +64,52 @@ Linked vertex stage: 45: 8(int) SpecConstantOp 197 12 44 46: 10(int) Constant 512 47: 10(int) SpecConstantOp 198 11 46 - 48: 8(int) SpecConstantOp 124 11 - 49: 8(int) SpecConstantOp 199 12 48 - 50: TypeBool - 51: 50(bool) SpecConstantOp 177 9 12 - 52: 10(int) SpecConstantOp 124 12 - 53: 50(bool) SpecConstantOp 176 11 52 - 54: 10(int) SpecConstantOp 124 12 - 55: 50(bool) SpecConstantOp 176 54 11 - 56: TypeVector 8(int) 4 - 57: 8(int) Constant 30 - 58: 56(ivec4) SpecConstantComposite 39 57 9 9 - 59: TypeVector 10(int) 4 - 60: 10(int) Constant 4294967295 - 61: 10(int) Constant 4294967294 - 62: 59(ivec4) SpecConstantComposite 11 11 60 61 - 63: TypeVector 6(float) 4 - 64: 6(float) Constant 1067450368 - 65: 63(fvec4) SpecConstantComposite 7 64 7 64 - 66: TypeVector 13(float) 4 - 67: 66(fvec4) SpecConstantOp 115 65 - 68: 63(fvec4) SpecConstantOp 115 67 - 69: 56(ivec4) SpecConstantOp 200 58 - 70: 63(fvec4) SpecConstantOp 111 69 - 71: 56(ivec4) SpecConstantOp 126 58 - 72: 56(ivec4) ConstantComposite 18 18 18 18 - 73: 56(ivec4) SpecConstantOp 128 58 72 - 74: 56(ivec4) SpecConstantOp 128 58 72 - 75: 56(ivec4) ConstantComposite 21 21 21 21 - 76: 56(ivec4) SpecConstantOp 130 74 75 - 77: 56(ivec4) ConstantComposite 23 23 23 23 - 78: 56(ivec4) SpecConstantOp 130 76 77 - 79: 56(ivec4) SpecConstantOp 132 58 72 - 80: 56(ivec4) ConstantComposite 28 28 28 28 - 81: 56(ivec4) SpecConstantOp 135 79 80 - 82: 56(ivec4) SpecConstantOp 139 58 77 - 83: 56(ivec4) ConstantComposite 37 37 37 37 - 84: 56(ivec4) SpecConstantOp 195 58 83 - 85: 56(ivec4) SpecConstantOp 196 58 72 - 86: 8(int) Constant 1024 - 87: 56(ivec4) ConstantComposite 86 86 86 86 - 88: 56(ivec4) SpecConstantOp 197 58 87 - 89: 10(int) Constant 2048 - 90: 59(ivec4) ConstantComposite 89 89 89 89 - 91: 59(ivec4) SpecConstantOp 198 62 90 - 92: 56(ivec4) SpecConstantOp 124 62 - 93: 56(ivec4) SpecConstantOp 199 58 92 - 94: 10(int) Constant 0 - 95: 8(int) SpecConstantOp 81 58 0 - 96: TypeVector 8(int) 2 - 97: 96(ivec2) SpecConstantOp 79 58 58 1(GLSL.std.450) 0 - 98: TypeVector 8(int) 3 - 99: 98(ivec3) SpecConstantOp 79 58 58 2 1(GLSL.std.450) 0 - 100: 56(ivec4) SpecConstantOp 79 58 58 1(GLSL.std.450) 2 0 3 - 101: 59(ivec4) SpecConstantOp 124 58 - 102: TypeVector 50(bool) 4 - 103: 102(bvec4) SpecConstantOp 170 101 62 - 104: 50(bool) SpecConstantOp 155 103 - 105: 59(ivec4) SpecConstantOp 124 58 - 106: 50(bool) SpecConstantOp 154 0 - 107: TypeVector 6(float) 2 -108(int_float_double_vec2): TypeStruct 8(int) 6(float) 13(float) 107(fvec2) - 109: 6(float) Constant 1065353216 - 110: 107(fvec2) SpecConstantComposite 15 109 - 111:108(int_float_double_vec2) SpecConstantComposite 9 7 14 110 - 112: 107(fvec2) SpecConstantComposite 15 109 - 113:108(int_float_double_vec2) SpecConstantComposite 9 7 14 112 - 114: 8(int) SpecConstantOp 81 111 0 - 115: 8(int) SpecConstantOp 81 113 0 - 116: 50(bool) SpecConstantOp 170 114 115 - 117: 6(float) SpecConstantOp 81 111 1(GLSL.std.450) - 118: 6(float) SpecConstantOp 81 113 1(GLSL.std.450) - 119: 50(bool) SpecConstantOp 180 117 118 - 120: 50(bool) SpecConstantOp 167 116 119 - 121: 13(float) SpecConstantOp 81 111 2 - 122: 13(float) SpecConstantOp 81 113 2 - 123: 50(bool) SpecConstantOp 180 121 122 - 124: 50(bool) SpecConstantOp 167 120 123 - 125: 107(fvec2) SpecConstantOp 81 111 3 - 126: 107(fvec2) SpecConstantOp 81 113 3 - 127: TypeVector 50(bool) 2 - 128: 127(bvec2) SpecConstantOp 180 125 126 - 129: 50(bool) SpecConstantOp 155 128 - 130: 50(bool) SpecConstantOp 167 124 129 - 131: 8(int) SpecConstantOp 81 111 0 - 132: 8(int) SpecConstantOp 81 113 0 - 133: 6(float) SpecConstantOp 81 111 1(GLSL.std.450) - 134: 6(float) SpecConstantOp 81 113 1(GLSL.std.450) - 135: 50(bool) SpecConstantOp 182 133 134 - 136: 50(bool) SpecConstantOp 166 0 135 - 137: 13(float) SpecConstantOp 81 111 2 - 138: 13(float) SpecConstantOp 81 113 2 - 139: 50(bool) SpecConstantOp 182 137 138 - 140: 50(bool) SpecConstantOp 166 136 139 - 141: 107(fvec2) SpecConstantOp 81 111 3 - 142: 107(fvec2) SpecConstantOp 81 113 3 - 143: 127(bvec2) SpecConstantOp 182 141 142 - 144: 50(bool) SpecConstantOp 154 143 - 145: 50(bool) SpecConstantOp 166 140 144 - 146: TypeArray 6(float) 26 - 147: 146 SpecConstantComposite 7 7 - 148: 146 SpecConstantComposite 7 7 - 149: 6(float) SpecConstantOp 81 147 0 - 150: 6(float) SpecConstantOp 81 148 0 - 151: 50(bool) SpecConstantOp 180 149 150 - 152: 6(float) SpecConstantOp 81 147 1(GLSL.std.450) - 153: 6(float) SpecConstantOp 81 148 1(GLSL.std.450) - 154: 50(bool) SpecConstantOp 180 152 153 - 155: 50(bool) SpecConstantOp 167 151 154 - 156: 6(float) SpecConstantOp 81 147 0 - 157: 6(float) SpecConstantOp 81 148 0 - 158: 50(bool) SpecConstantOp 182 156 157 - 159: 6(float) SpecConstantOp 81 147 1(GLSL.std.450) - 160: 6(float) SpecConstantOp 81 148 1(GLSL.std.450) - 161: 50(bool) SpecConstantOp 182 159 160 - 162: 50(bool) SpecConstantOp 166 158 161 + 48: TypeBool + 49: 48(bool) SpecConstantOp 177 9 12 + 50: 48(bool) SpecConstantOp 170 11 11 + 51: 48(bool) SpecConstantOp 173 9 12 + 52: TypeVector 8(int) 4 + 53: 8(int) Constant 30 + 54: 52(ivec4) SpecConstantComposite 39 53 9 9 + 55: TypeVector 10(int) 4 + 56: 10(int) Constant 4294967295 + 57: 10(int) Constant 4294967294 + 58: 55(ivec4) SpecConstantComposite 11 11 56 57 + 59: TypeVector 6(float) 4 + 60: 6(float) Constant 1067450368 + 61: 59(fvec4) SpecConstantComposite 7 60 7 60 + 62: TypeVector 13(float) 4 + 63: 62(fvec4) SpecConstantOp 115 61 + 64: 59(fvec4) SpecConstantOp 115 63 + 65: 52(ivec4) SpecConstantOp 200 54 + 66: 52(ivec4) SpecConstantOp 126 54 + 67: 52(ivec4) ConstantComposite 18 18 18 18 + 68: 52(ivec4) SpecConstantOp 128 54 67 + 69: 52(ivec4) SpecConstantOp 128 54 67 + 70: 52(ivec4) ConstantComposite 21 21 21 21 + 71: 52(ivec4) SpecConstantOp 130 69 70 + 72: 52(ivec4) ConstantComposite 23 23 23 23 + 73: 52(ivec4) SpecConstantOp 130 71 72 + 74: 52(ivec4) SpecConstantOp 132 54 67 + 75: 52(ivec4) ConstantComposite 28 28 28 28 + 76: 52(ivec4) SpecConstantOp 135 74 75 + 77: 52(ivec4) SpecConstantOp 139 54 72 + 78: 52(ivec4) ConstantComposite 37 37 37 37 + 79: 52(ivec4) SpecConstantOp 195 54 78 + 80: 52(ivec4) SpecConstantOp 196 54 67 + 81: 8(int) Constant 1024 + 82: 52(ivec4) ConstantComposite 81 81 81 81 + 83: 52(ivec4) SpecConstantOp 197 54 82 + 84: 10(int) Constant 2048 + 85: 55(ivec4) ConstantComposite 84 84 84 84 + 86: 55(ivec4) SpecConstantOp 198 58 85 + 87: 10(int) Constant 0 + 88: 8(int) SpecConstantOp 81 54 0 + 89: TypeVector 8(int) 2 + 90: 89(ivec2) SpecConstantOp 79 54 54 1(GLSL.std.450) 0 + 91: TypeVector 8(int) 3 + 92: 91(ivec3) SpecConstantOp 79 54 54 2 1(GLSL.std.450) 0 + 93: 52(ivec4) SpecConstantOp 79 54 54 1(GLSL.std.450) 2 0 3 4(main): 2 Function None 3 5: Label Return diff --git a/Test/spv.specConstantOperations.vert b/Test/spv.specConstantOperations.vert index 93588bf8..9de96aee 100644 --- a/Test/spv.specConstantOperations.vert +++ b/Test/spv.specConstantOperations.vert @@ -41,12 +41,11 @@ const uint sp_uint_shift_left = sp_uint << 2; // Bitwise And, Or, Xor const int sp_sint_or_256 = sp_sint | 0x100; const uint sp_uint_xor_512 = sp_uint ^ 0x200; -const int sp_sint_and_sp_uint = sp_sint & int(sp_uint); -// Scalar comparison +/* // Scalar comparison */ const bool sp_int_lt_sp_sint = sp_int < sp_sint; -const bool sp_uint_lt_sp_sint = sp_uint < sp_sint; -const bool sp_sint_lt_sp_uint = sp_sint < sp_uint; +const bool sp_uint_equal_sp_uint = sp_uint == sp_uint; +const bool sp_int_gt_sp_sint = sp_int > sp_sint; // // Vectors @@ -60,7 +59,7 @@ const dvec4 fv_to_dv = dvec4(fv); const vec4 dv_to_fv = vec4(fv_to_dv); // Negate and Not -const vec4 not_iv = ~iv; +const ivec4 not_iv = ~iv; const ivec4 negate_iv = -iv; // Add and Subtract @@ -80,7 +79,6 @@ const ivec4 iv_shift_left = iv << 2; // Bitwise And, Or, Xor const ivec4 iv_or_1024 = iv | 0x400; const uvec4 uv_xor_2048 = uv ^ 0x800; -const ivec4 iv_and_uv = iv & ivec4(uv); // Swizzles const int iv_x = iv.x; @@ -88,40 +86,5 @@ const ivec2 iv_yx = iv.yx; const ivec3 iv_zyx = iv.zyx; const ivec4 iv_yzxw = iv.yzxw; -// Vector comparison, only == and != are supported and allowd. -const bool iv_equal_uv = iv == uv; -const bool iv_not_equal_uv = iv != uv; - -// -// Composite types other than vectors -// - -// Struct -struct int_float_double_vec2 { - int i; - float f; - double d; - vec2 v; -}; - -const int_float_double_vec2 sp_struct_a = { - sp_int, sp_float, float_to_double, - vec2(double_to_float, 1.0) -}; - -const int_float_double_vec2 sp_struct_b = { - sp_int, sp_float, float_to_double, - vec2(double_to_float, 1.0) -}; - -const bool struct_a_equal_struct_b = sp_struct_a == sp_struct_b; -const bool struct_a_not_equal_struct_b = sp_struct_a != sp_struct_b; - -// Array -const float array_a[2] = {sp_float, sp_float}; -const float array_b[2] = {sp_float, sp_float}; -const bool array_a_equal_array_b = array_a == array_b; -const bool array_a_not_equal_array_b = array_a != array_b; - void main() {}