Parser: Add 64-bit type conversion for specialization constant.

This commit is contained in:
Rex Xu 2016-09-05 16:10:14 +08:00
Родитель 7d01bd6f0b
Коммит 64bcfdb632
8 изменённых файлов: 183 добавлений и 96 удалений

Просмотреть файл

@ -3761,8 +3761,8 @@ spv::Id TGlslangToSpvTraverser::createConversion(glslang::TOperator op, spv::Dec
case glslang::EOpConvInt64ToUint64:
if (builder.isInSpecConstCodeGenMode()) {
// Build zero scalar or vector for OpIAdd.
zero = (op == glslang::EOpConvUintToInt64 ||
op == glslang::EOpConvIntToUint64) ? builder.makeUint64Constant(0) : builder.makeUintConstant(0);
zero = (op == glslang::EOpConvUint64ToInt64 ||
op == glslang::EOpConvInt64ToUint64) ? builder.makeUint64Constant(0) : builder.makeUintConstant(0);
zero = makeSmearedConstant(zero, vectorSize);
// Use OpIAdd, instead of OpBitcast to do the conversion when
// generating for OpSpecConstantOp instruction.

Просмотреть файл

@ -8,7 +8,7 @@ Linked fragment stage:
Missing functionality: shader int64
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 455
// Id's are bound by 478
Capability Shader
Capability Float64
@ -64,6 +64,11 @@ Missing functionality: shader int64
Decorate 452(Block) Block
Decorate 454(block) DescriptorSet 0
Decorate 454(block) Binding 1
Decorate 455 SpecId 100
Decorate 456 SpecId 101
Decorate 457 SpecId 102
Decorate 458 SpecId 103
Decorate 459 SpecId 104
2: TypeVoid
3: TypeFunction 2
14: TypeInt 64 1
@ -145,6 +150,29 @@ Missing functionality: shader int64
452(Block): TypeStruct 134(ivec3) 36(int)
453: TypePointer Uniform 452(Block)
454(block): 453(ptr) Variable Uniform
455: 14(int) SpecConstant 4294967286 4294967295
456: 36(int) SpecConstant 20 0
457: 27(int) SpecConstant 4294967291
458: 17(int) SpecConstant 4
459: 53(bool) SpecConstantTrue
460: 53(bool) SpecConstantOp 171 455 67
461: 53(bool) SpecConstantOp 171 456 67
462: 14(int) SpecConstantOp 169 459 59 58
463: 36(int) SpecConstantOp 169 459 68 67
464: 27(int) SpecConstantOp 114 455
465: 14(int) SpecConstantOp 114 457
466: 17(int) SpecConstantOp 113 456
467: 36(int) SpecConstantOp 113 458
468: 14(int) SpecConstantOp 128 456 67
469: 36(int) SpecConstantOp 128 455 67
470: 17(int) SpecConstantOp 113 456
471: 27(int) SpecConstantOp 128 470 217
472: 14(int) SpecConstantOp 114 457
473: 36(int) SpecConstantOp 128 472 67
474: 27(int) SpecConstantOp 114 455
475: 17(int) SpecConstantOp 128 474 217
476: 36(int) SpecConstantOp 113 458
477: 14(int) SpecConstantOp 128 476 67
4(main): 2 Function None 3
5: Label
Return

Просмотреть файл

@ -61,6 +61,7 @@ Linked vertex stage:
38: TypeFloat 64
39: 38(float) SpecConstant 1413754136 1074340347
40: 6(float) SpecConstant 1078523331
41: 38(float) SpecConstantOp 115 40
50: 8(int) SpecConstant 12
51: TypeArray 7(fvec4) 50
52: TypePointer Input 51
@ -69,6 +70,7 @@ Linked vertex stage:
63: 33(int) SpecConstant 2
67: 38(float) SpecConstant 1413754136 1074340347
68: 6(float) SpecConstant 1078523331
69: 38(float) SpecConstantOp 115 68
75: TypePointer Function 8(int)
77: 8(int) SpecConstant 8
4(main): 2 Function None 3
@ -87,7 +89,6 @@ Linked vertex stage:
Store 20(color) 37
Branch 32
32: Label
41: 38(float) FConvert 40
42: 38(float) FDiv 39 41
43: 6(float) FConvert 42
44: 7(fvec4) Load 20(color)
@ -119,7 +120,6 @@ Linked vertex stage:
Store 20(color) 66
Branch 62
62: Label
69: 38(float) FConvert 68
70: 38(float) FDiv 67 69
71: 6(float) FConvert 70
72: 7(fvec4) Load 20(color)

Просмотреть файл

@ -7,9 +7,10 @@ Linked vertex stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 131
// Id's are bound by 135
Capability Shader
Capability Float64
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main"
@ -22,6 +23,7 @@ Linked vertex stage:
Decorate 40 SpecId 200
Decorate 42 SpecId 202
Decorate 43 SpecId 203
Decorate 45 SpecId 204
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 1
@ -43,93 +45,97 @@ Linked vertex stage:
41: TypeInt 32 0
42: 41(int) SpecConstant 100
43: 6(int) SpecConstant 4294967286
44: 41(int) Constant 0
45: 22(bool) SpecConstantOp 171 19 44
46: 22(bool) SpecConstantOp 171 42 44
47: 6(int) SpecConstantOp 169 45 32 12
48: 41(int) Constant 1
49: 41(int) SpecConstantOp 169 45 48 44
50: 41(int) SpecConstantOp 128 43 44
51: 6(int) SpecConstantOp 128 42 44
52: 6(int) SpecConstantOp 126 19
53: 6(int) SpecConstantOp 200 19
54: 6(int) SpecConstantOp 128 19 20
55: 6(int) SpecConstantOp 128 19 20
56: 6(int) Constant 3
57: 6(int) SpecConstantOp 130 55 56
58: 6(int) Constant 4
59: 6(int) SpecConstantOp 130 54 58
60: 6(int) SpecConstantOp 132 43 20
61: 41(int) Constant 2
62: 41(int) SpecConstantOp 132 42 61
63: 6(int) Constant 5
64: 6(int) SpecConstantOp 135 60 63
65: 41(int) Constant 5
66: 41(int) SpecConstantOp 134 62 65
67: 6(int) SpecConstantOp 139 43 58
68: 41(int) Constant 4
69: 41(int) SpecConstantOp 137 42 68
70: 6(int) SpecConstantOp 132 43 56
71: 6(int) SpecConstantOp 135 70 63
72: 6(int) Constant 10
73: 6(int) SpecConstantOp 195 43 72
74: 6(int) Constant 20
75: 41(int) SpecConstantOp 194 42 74
76: 6(int) SpecConstantOp 196 43 32
77: 41(int) SpecConstantOp 196 42 20
78: 6(int) Constant 256
79: 6(int) SpecConstantOp 197 43 78
80: 41(int) Constant 512
81: 41(int) SpecConstantOp 198 42 80
82: 22(bool) SpecConstantOp 177 19 43
83: 22(bool) SpecConstantOp 170 42 42
84: 22(bool) SpecConstantOp 173 19 43
85: 6(int) Constant 30
86: TypeVector 6(int) 4
87: 86(ivec4) SpecConstantComposite 74 85 19 19
88: 41(int) Constant 4294967295
89: 41(int) Constant 4294967294
90: TypeVector 41(int) 4
91: 90(ivec4) SpecConstantComposite 42 42 88 89
92: TypeVector 22(bool) 4
93: 90(ivec4) ConstantComposite 44 44 44 44
94: 92(bvec4) SpecConstantOp 171 87 93
95: 92(bvec4) SpecConstantOp 171 91 93
96: 86(ivec4) ConstantComposite 12 12 12 12
97: 86(ivec4) ConstantComposite 32 32 32 32
98: 86(ivec4) SpecConstantOp 169 94 97 96
99: 90(ivec4) ConstantComposite 48 48 48 48
100: 90(ivec4) SpecConstantOp 169 94 99 93
101: 90(ivec4) SpecConstantOp 128 87 93
102: 86(ivec4) SpecConstantOp 128 91 93
103: 86(ivec4) SpecConstantOp 200 87
104: 86(ivec4) SpecConstantOp 126 87
105: 86(ivec4) ConstantComposite 20 20 20 20
106: 86(ivec4) SpecConstantOp 128 87 105
107: 86(ivec4) SpecConstantOp 128 87 105
108: 86(ivec4) ConstantComposite 56 56 56 56
109: 86(ivec4) SpecConstantOp 130 107 108
110: 86(ivec4) ConstantComposite 58 58 58 58
111: 86(ivec4) SpecConstantOp 130 109 110
112: 86(ivec4) SpecConstantOp 132 87 105
113: 86(ivec4) ConstantComposite 63 63 63 63
114: 86(ivec4) SpecConstantOp 135 112 113
115: 86(ivec4) SpecConstantOp 139 87 110
116: 86(ivec4) ConstantComposite 72 72 72 72
117: 86(ivec4) SpecConstantOp 195 87 116
118: 86(ivec4) SpecConstantOp 196 87 105
119: 6(int) Constant 1024
120: 86(ivec4) ConstantComposite 119 119 119 119
121: 86(ivec4) SpecConstantOp 197 87 120
122: 41(int) Constant 2048
123: 90(ivec4) ConstantComposite 122 122 122 122
124: 90(ivec4) SpecConstantOp 198 91 123
125: 6(int) SpecConstantOp 81 87 0
126: TypeVector 6(int) 2
127: 126(ivec2) SpecConstantOp 79 87 87 1(GLSL.std.450) 0
128: TypeVector 6(int) 3
129: 128(ivec3) SpecConstantOp 79 87 87 2 1(GLSL.std.450) 0
130: 86(ivec4) SpecConstantOp 79 87 87 1(GLSL.std.450) 2 0 3
44: TypeFloat 64
45: 44(float) SpecConstant 2333366019 1074118410
46: 39(float) SpecConstantOp 115 45
47: 44(float) SpecConstantOp 115 40
48: 41(int) Constant 0
49: 22(bool) SpecConstantOp 171 19 48
50: 22(bool) SpecConstantOp 171 42 48
51: 6(int) SpecConstantOp 169 49 32 12
52: 41(int) Constant 1
53: 41(int) SpecConstantOp 169 49 52 48
54: 41(int) SpecConstantOp 128 43 48
55: 6(int) SpecConstantOp 128 42 48
56: 6(int) SpecConstantOp 126 19
57: 6(int) SpecConstantOp 200 19
58: 6(int) SpecConstantOp 128 19 20
59: 6(int) SpecConstantOp 128 19 20
60: 6(int) Constant 3
61: 6(int) SpecConstantOp 130 59 60
62: 6(int) Constant 4
63: 6(int) SpecConstantOp 130 58 62
64: 6(int) SpecConstantOp 132 43 20
65: 41(int) Constant 2
66: 41(int) SpecConstantOp 132 42 65
67: 6(int) Constant 5
68: 6(int) SpecConstantOp 135 64 67
69: 41(int) Constant 5
70: 41(int) SpecConstantOp 134 66 69
71: 6(int) SpecConstantOp 139 43 62
72: 41(int) Constant 4
73: 41(int) SpecConstantOp 137 42 72
74: 6(int) SpecConstantOp 132 43 60
75: 6(int) SpecConstantOp 135 74 67
76: 6(int) Constant 10
77: 6(int) SpecConstantOp 195 43 76
78: 6(int) Constant 20
79: 41(int) SpecConstantOp 194 42 78
80: 6(int) SpecConstantOp 196 43 32
81: 41(int) SpecConstantOp 196 42 20
82: 6(int) Constant 256
83: 6(int) SpecConstantOp 197 43 82
84: 41(int) Constant 512
85: 41(int) SpecConstantOp 198 42 84
86: 22(bool) SpecConstantOp 177 19 43
87: 22(bool) SpecConstantOp 170 42 42
88: 22(bool) SpecConstantOp 173 19 43
89: 6(int) Constant 30
90: TypeVector 6(int) 4
91: 90(ivec4) SpecConstantComposite 78 89 19 19
92: 41(int) Constant 4294967295
93: 41(int) Constant 4294967294
94: TypeVector 41(int) 4
95: 94(ivec4) SpecConstantComposite 42 42 92 93
96: TypeVector 22(bool) 4
97: 94(ivec4) ConstantComposite 48 48 48 48
98: 96(bvec4) SpecConstantOp 171 91 97
99: 96(bvec4) SpecConstantOp 171 95 97
100: 90(ivec4) ConstantComposite 12 12 12 12
101: 90(ivec4) ConstantComposite 32 32 32 32
102: 90(ivec4) SpecConstantOp 169 98 101 100
103: 94(ivec4) ConstantComposite 52 52 52 52
104: 94(ivec4) SpecConstantOp 169 98 103 97
105: 94(ivec4) SpecConstantOp 128 91 97
106: 90(ivec4) SpecConstantOp 128 95 97
107: 90(ivec4) SpecConstantOp 200 91
108: 90(ivec4) SpecConstantOp 126 91
109: 90(ivec4) ConstantComposite 20 20 20 20
110: 90(ivec4) SpecConstantOp 128 91 109
111: 90(ivec4) SpecConstantOp 128 91 109
112: 90(ivec4) ConstantComposite 60 60 60 60
113: 90(ivec4) SpecConstantOp 130 111 112
114: 90(ivec4) ConstantComposite 62 62 62 62
115: 90(ivec4) SpecConstantOp 130 113 114
116: 90(ivec4) SpecConstantOp 132 91 109
117: 90(ivec4) ConstantComposite 67 67 67 67
118: 90(ivec4) SpecConstantOp 135 116 117
119: 90(ivec4) SpecConstantOp 139 91 114
120: 90(ivec4) ConstantComposite 76 76 76 76
121: 90(ivec4) SpecConstantOp 195 91 120
122: 90(ivec4) SpecConstantOp 196 91 109
123: 6(int) Constant 1024
124: 90(ivec4) ConstantComposite 123 123 123 123
125: 90(ivec4) SpecConstantOp 197 91 124
126: 41(int) Constant 2048
127: 94(ivec4) ConstantComposite 126 126 126 126
128: 94(ivec4) SpecConstantOp 198 95 127
129: 6(int) SpecConstantOp 81 91 0
130: TypeVector 6(int) 2
131: 130(ivec2) SpecConstantOp 79 91 91 1(GLSL.std.450) 0
132: TypeVector 6(int) 3
133: 132(ivec3) SpecConstantOp 79 91 91 2 1(GLSL.std.450) 0
134: 90(ivec4) SpecConstantOp 79 91 91 1(GLSL.std.450) 2 0 3
4(main): 2 Function None 3
5: Label
Return

Просмотреть файл

@ -225,4 +225,37 @@ void builtinFuncs()
// notEqual()
bv = notEqual(u64v, u64vec3(u64));
bv.xy = notEqual(i64v, i64vec2(i64));
}
}
// Type conversion for specialization constant
layout(constant_id = 100) const int64_t si64 = -10L;
layout(constant_id = 101) const uint64_t su64 = 20UL;
layout(constant_id = 102) const int si = -5;
layout(constant_id = 103) const uint su = 4;
layout(constant_id = 104) const bool sb = true;
// bool <-> int64/uint64
const bool i64_to_b = bool(si64);
const bool u64_to_b = bool(su64);
const int64_t b_to_i64 = int64_t(sb);
const uint64_t b_to_u64 = uint64_t(sb);
// int <-> int64
const int i64_to_i = int(si64);
const int64_t i_to_i64 = int64_t(si);
// uint <-> uint64
const uint u64_to_u = uint(su64);
const uint64_t u_to_u64 = uint64_t(su);
// int64 <-> uint64
const int64_t u64_to_i64 = int64_t(su64);
const uint64_t i64_to_u64 = uint64_t(si64);
// int <-> uint64
const int u64_to_i = int(su64);
const uint64_t i_to_u64 = uint64_t(si);
// uint <-> int64
const uint i64_to_u = uint(si64);
const int64_t u_to_i64 = int64_t(su);

Просмотреть файл

@ -4,12 +4,16 @@ layout(constant_id = 200) const float sp_float = 3.1415926;
layout(constant_id = 201) const int sp_int = 10;
layout(constant_id = 202) const uint sp_uint = 100;
layout(constant_id = 203) const int sp_sint = -10;
layout(constant_id = 204) const double sp_double = 2.718281828459;
//
// Scalars
//
// float <-> double conversion
const float float_from_double = float(sp_double);
const double double_from_float = double(sp_float);
// uint/int <-> bool conversion
const bool bool_from_int = bool(sp_int);
const bool bool_from_uint = bool(sp_uint);

Просмотреть файл

@ -1444,6 +1444,8 @@ bool TIntermediate::isSpecializationOperation(const TIntermOperator& node) const
case EOpIndexIndirect:
case EOpIndexDirectStruct:
case EOpVectorSwizzle:
case EOpConvFloatToDouble:
case EOpConvDoubleToFloat:
return true;
default:
return false;
@ -1474,6 +1476,20 @@ bool TIntermediate::isSpecializationOperation(const TIntermOperator& node) const
case EOpConvBoolToInt:
case EOpConvIntToUint:
case EOpConvBoolToUint:
case EOpConvInt64ToBool:
case EOpConvBoolToInt64:
case EOpConvUint64ToBool:
case EOpConvBoolToUint64:
case EOpConvInt64ToInt:
case EOpConvIntToInt64:
case EOpConvUint64ToUint:
case EOpConvUintToUint64:
case EOpConvInt64ToUint64:
case EOpConvUint64ToInt64:
case EOpConvInt64ToUint:
case EOpConvUintToInt64:
case EOpConvUint64ToInt:
case EOpConvIntToUint64:
// unary operations
case EOpNegative:

Просмотреть файл

@ -4942,7 +4942,7 @@ const TFunction* TParseContext::findFunction120(const TSourceLoc& loc, const TFu
// "When function calls are resolved, an exact type match for all the arguments
// is sought. If an exact match is found, all other functions are ignored, and
// the exact match is used. If no exact match is found, then the implicit
// conversions in section 4.1.10 Implicit Conversions will be applied to find
// conversions in section 4.1.10 Implicit Conversions will be applied to find
// a match. Mismatched types on input parameters (in or inout or default) must
// have a conversion from the calling argument type to the formal parameter type.
// Mismatched types on output parameters (out or inout) must have a conversion