Commit 81a63f1d by Neil Henning

Add conversion folding when the source is a constant.

This change adds unary conversion folding when the source is a constant. This fixes an ISV issue whereby: ``` const float16_t f = float16_t(42.0); ``` Wouldn't compile because the conversion operator would always produce an EvqTemporary when it could have produced an EvqConst. I've also added a test case that proves out that all basic-type to basic-type conversions work.
parent 0e6c82ce
spv.16bitstorage-int.frag spv.16bitstorage-int.frag
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 171 // Id's are bound by 172
Capability Shader Capability Shader
Capability StorageUniformBufferBlock16 Capability StorageUniformBufferBlock16
...@@ -204,7 +204,10 @@ spv.16bitstorage-int.frag ...@@ -204,7 +204,10 @@ spv.16bitstorage-int.frag
114: 20(int) Constant 7 114: 20(int) Constant 7
115: 20(int) Constant 6 115: 20(int) Constant 6
116: TypePointer Uniform 20(int) 116: TypePointer Uniform 20(int)
166: 39(ivec2) ConstantComposite 32 33 166: 6(int16_t) Constant 1
167: 6(int16_t) Constant 2
168: 7(i16vec2) ConstantComposite 166 167
170: 6(int16_t) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
69(x0): 68(ptr) Variable Function 69(x0): 68(ptr) Variable Function
...@@ -324,11 +327,9 @@ spv.16bitstorage-int.frag ...@@ -324,11 +327,9 @@ spv.16bitstorage-int.frag
164: 6(int16_t) Load 163 164: 6(int16_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21 165: 28(ptr) AccessChain 19(b2) 21
Store 165 164 Store 165 164
167: 7(i16vec2) SConvert 166 169: 42(ptr) AccessChain 19(b2) 32
168: 42(ptr) AccessChain 19(b2) 32 Store 169 168
Store 168 167 171: 28(ptr) AccessChain 19(b2) 21
169: 6(int16_t) SConvert 58 Store 171 170
170: 28(ptr) AccessChain 19(b2) 21
Store 170 169
Return Return
FunctionEnd FunctionEnd
...@@ -205,8 +205,10 @@ spv.16bitstorage-uint.frag ...@@ -205,8 +205,10 @@ spv.16bitstorage-uint.frag
115: 20(int) Constant 7 115: 20(int) Constant 7
116: 20(int) Constant 6 116: 20(int) Constant 6
117: TypePointer Uniform 9(int) 117: TypePointer Uniform 9(int)
167: 39(ivec2) ConstantComposite 82 10 167: 6(int16_t) Constant 1
170: 9(int) Constant 3 168: 6(int16_t) Constant 2
169: 7(i16vec2) ConstantComposite 167 168
171: 6(int16_t) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
69(x0): 68(ptr) Variable Function 69(x0): 68(ptr) Variable Function
...@@ -326,10 +328,8 @@ spv.16bitstorage-uint.frag ...@@ -326,10 +328,8 @@ spv.16bitstorage-uint.frag
165: 6(int16_t) Load 164 165: 6(int16_t) Load 164
166: 28(ptr) AccessChain 19(b2) 21 166: 28(ptr) AccessChain 19(b2) 21
Store 166 165 Store 166 165
168: 7(i16vec2) UConvert 167 170: 42(ptr) AccessChain 19(b2) 32
169: 42(ptr) AccessChain 19(b2) 32 Store 170 169
Store 169 168
171: 6(int16_t) UConvert 170
172: 28(ptr) AccessChain 19(b2) 21 172: 28(ptr) AccessChain 19(b2) 21
Store 172 171 Store 172 171
Return Return
......
spv.16bitstorage.frag spv.16bitstorage.frag
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 173 // Id's are bound by 172
Capability Shader Capability Shader
Capability StorageUniformBufferBlock16 Capability StorageUniformBufferBlock16
...@@ -204,9 +204,10 @@ spv.16bitstorage.frag ...@@ -204,9 +204,10 @@ spv.16bitstorage.frag
114: 20(int) Constant 7 114: 20(int) Constant 7
115: 20(int) Constant 6 115: 20(int) Constant 6
116: TypePointer Uniform 20(int) 116: TypePointer Uniform 20(int)
166: 37(float) Constant 1073741824 166:6(float16_t) Constant 15360
167: 40(fvec2) ConstantComposite 83 166 167:6(float16_t) Constant 16384
170: 37(float) Constant 1077936128 168: 7(f16vec2) ConstantComposite 166 167
170:6(float16_t) Constant 16896
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
70(x0): 69(ptr) Variable Function 70(x0): 69(ptr) Variable Function
...@@ -326,11 +327,9 @@ spv.16bitstorage.frag ...@@ -326,11 +327,9 @@ spv.16bitstorage.frag
164:6(float16_t) Load 163 164:6(float16_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21 165: 28(ptr) AccessChain 19(b2) 21
Store 165 164 Store 165 164
168: 7(f16vec2) FConvert 167
169: 43(ptr) AccessChain 19(b2) 32 169: 43(ptr) AccessChain 19(b2) 32
Store 169 168 Store 169 168
171:6(float16_t) FConvert 170 171: 28(ptr) AccessChain 19(b2) 21
172: 28(ptr) AccessChain 19(b2) 21 Store 171 170
Store 172 171
Return Return
FunctionEnd FunctionEnd
spv.8bitstorage-int.frag spv.8bitstorage-int.frag
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 171 // Id's are bound by 172
Capability Shader Capability Shader
Capability CapabilityUniformAndStorageBuffer8BitAccess Capability CapabilityUniformAndStorageBuffer8BitAccess
...@@ -203,7 +203,10 @@ spv.8bitstorage-int.frag ...@@ -203,7 +203,10 @@ spv.8bitstorage-int.frag
114: 20(int) Constant 7 114: 20(int) Constant 7
115: 20(int) Constant 6 115: 20(int) Constant 6
116: TypePointer Uniform 20(int) 116: TypePointer Uniform 20(int)
166: 39(ivec2) ConstantComposite 32 33 166: 6(int8_t) Constant 1
167: 6(int8_t) Constant 2
168: 7(i8vec2) ConstantComposite 166 167
170: 6(int8_t) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
69(x0): 68(ptr) Variable Function 69(x0): 68(ptr) Variable Function
...@@ -323,11 +326,9 @@ spv.8bitstorage-int.frag ...@@ -323,11 +326,9 @@ spv.8bitstorage-int.frag
164: 6(int8_t) Load 163 164: 6(int8_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21 165: 28(ptr) AccessChain 19(b2) 21
Store 165 164 Store 165 164
167: 7(i8vec2) SConvert 166 169: 42(ptr) AccessChain 19(b2) 32
168: 42(ptr) AccessChain 19(b2) 32 Store 169 168
Store 168 167 171: 28(ptr) AccessChain 19(b2) 21
169: 6(int8_t) SConvert 58 Store 171 170
170: 28(ptr) AccessChain 19(b2) 21
Store 170 169
Return Return
FunctionEnd FunctionEnd
...@@ -204,8 +204,10 @@ spv.8bitstorage-uint.frag ...@@ -204,8 +204,10 @@ spv.8bitstorage-uint.frag
115: 20(int) Constant 7 115: 20(int) Constant 7
116: 20(int) Constant 6 116: 20(int) Constant 6
117: TypePointer Uniform 9(int) 117: TypePointer Uniform 9(int)
167: 39(ivec2) ConstantComposite 82 10 167: 6(int8_t) Constant 1
170: 9(int) Constant 3 168: 6(int8_t) Constant 2
169: 7(i8vec2) ConstantComposite 167 168
171: 6(int8_t) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
69(x0): 68(ptr) Variable Function 69(x0): 68(ptr) Variable Function
...@@ -325,10 +327,8 @@ spv.8bitstorage-uint.frag ...@@ -325,10 +327,8 @@ spv.8bitstorage-uint.frag
165: 6(int8_t) Load 164 165: 6(int8_t) Load 164
166: 28(ptr) AccessChain 19(b2) 21 166: 28(ptr) AccessChain 19(b2) 21
Store 166 165 Store 166 165
168: 7(i8vec2) UConvert 167 170: 42(ptr) AccessChain 19(b2) 32
169: 42(ptr) AccessChain 19(b2) 32 Store 170 169
Store 169 168
171: 6(int8_t) UConvert 170
172: 28(ptr) AccessChain 19(b2) 21 172: 28(ptr) AccessChain 19(b2) 21
Store 172 171 Store 172 171
Return Return
......
#version 450
#extension GL_KHX_shader_explicit_arithmetic_types : require
const bool bool_init = true;
const int8_t int8_t_init = int8_t(-1);
const int16_t int16_t_init = int16_t(-2);
const int32_t int32_t_init = int32_t(-3);
const int64_t int64_t_init = int64_t(-4);
const uint8_t uint8_t_init = uint8_t(1);
const uint16_t uint16_t_init = uint16_t(2);
const uint32_t uint32_t_init = uint32_t(3);
const uint64_t uint64_t_init = uint64_t(4);
const float16_t float16_t_init = float16_t(42.0);
const float32_t float32_t_init = float32_t(13.0);
const float64_t float64_t_init = float64_t(-4.0);
#define TYPE_TO_TYPE(x, y) \
const x y##_to_##x = x(y##_init)
#define TYPE_TO(x) \
TYPE_TO_TYPE(x, bool); \
TYPE_TO_TYPE(x, int8_t); \
TYPE_TO_TYPE(x, int16_t); \
TYPE_TO_TYPE(x, int32_t); \
TYPE_TO_TYPE(x, int64_t); \
TYPE_TO_TYPE(x, uint8_t); \
TYPE_TO_TYPE(x, uint16_t); \
TYPE_TO_TYPE(x, uint32_t); \
TYPE_TO_TYPE(x, uint64_t); \
TYPE_TO_TYPE(x, float16_t); \
TYPE_TO_TYPE(x, float32_t); \
TYPE_TO_TYPE(x, float64_t)
TYPE_TO(bool);
TYPE_TO(int8_t);
TYPE_TO(int16_t);
TYPE_TO(int32_t);
TYPE_TO(int64_t);
TYPE_TO(uint8_t);
TYPE_TO(uint16_t);
TYPE_TO(uint32_t);
TYPE_TO(uint64_t);
TYPE_TO(float16_t);
TYPE_TO(float32_t);
TYPE_TO(float64_t);
void main() {}
...@@ -489,7 +489,7 @@ bool TIntermediate::isConversionAllowed(TOperator op, TIntermTyped* node) const ...@@ -489,7 +489,7 @@ bool TIntermediate::isConversionAllowed(TOperator op, TIntermTyped* node) const
// This is 'mechanism' here, it does any conversion told. // This is 'mechanism' here, it does any conversion told.
// It is about basic type, not about shape. // It is about basic type, not about shape.
// The policy comes from the shader or the calling code. // The policy comes from the shader or the calling code.
TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped* node) const TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped* node) const
{ {
// //
// Add a new newNode for the conversion. // Add a new newNode for the conversion.
...@@ -712,7 +712,11 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped ...@@ -712,7 +712,11 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
TType newType(convertTo, EvqTemporary, node->getVectorSize(), node->getMatrixCols(), node->getMatrixRows()); TType newType(convertTo, EvqTemporary, node->getVectorSize(), node->getMatrixCols(), node->getMatrixRows());
newNode = addUnaryNode(newOp, node, node->getLoc(), newType); newNode = addUnaryNode(newOp, node, node->getLoc(), newType);
// TODO: it seems that some unary folding operations should occur here, but are not if (node->getAsConstantUnion()) {
TIntermTyped* folded = node->getAsConstantUnion()->fold(newOp, newType);
if (folded)
return folded;
}
// Propagate specialization-constant-ness, if allowed // Propagate specialization-constant-ness, if allowed
if (node->getType().getQualifier().isSpecConstant() && isSpecializationOperation(*newNode)) if (node->getType().getQualifier().isSpecConstant() && isSpecializationOperation(*newNode))
...@@ -1021,7 +1025,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt ...@@ -1021,7 +1025,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
// //
// Add a new newNode for the conversion. // Add a new newNode for the conversion.
// //
TIntermUnary* newNode = createConversion(promoteTo, node); TIntermTyped* newNode = createConversion(promoteTo, node);
return newNode; return newNode;
} }
......
...@@ -732,7 +732,7 @@ protected: ...@@ -732,7 +732,7 @@ protected:
bool specConstantPropagates(const TIntermTyped&, const TIntermTyped&); bool specConstantPropagates(const TIntermTyped&, const TIntermTyped&);
void performTextureUpgradeAndSamplerRemovalTransformation(TIntermNode* root); void performTextureUpgradeAndSamplerRemovalTransformation(TIntermNode* root);
bool isConversionAllowed(TOperator op, TIntermTyped* node) const; bool isConversionAllowed(TOperator op, TIntermTyped* node) const;
TIntermUnary* createConversion(TBasicType convertTo, TIntermTyped* node) const; TIntermTyped* createConversion(TBasicType convertTo, TIntermTyped* node) const;
std::tuple<TBasicType, TBasicType> getConversionDestinatonType(TBasicType type0, TBasicType type1, TOperator op) const; std::tuple<TBasicType, TBasicType> getConversionDestinatonType(TBasicType type0, TBasicType type1, TOperator op) const;
bool extensionRequested(const char *extension) const {return requestedExtensions.find(extension) != requestedExtensions.end();} bool extensionRequested(const char *extension) const {return requestedExtensions.find(extension) != requestedExtensions.end();}
static const char* getResourceName(TResourceType); static const char* getResourceName(TResourceType);
......
...@@ -231,6 +231,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -231,6 +231,7 @@ INSTANTIATE_TEST_CASE_P(
"precise_struct_block.vert", "precise_struct_block.vert",
"maxClipDistances.vert", "maxClipDistances.vert",
"findFunction.frag", "findFunction.frag",
"constantUnaryConversion.comp"
})), })),
FileNameAsCustomTestSuffix FileNameAsCustomTestSuffix
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment