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
// Module Version 10000
// Generated by (magic number): 80007
// Id's are bound by 171
// Id's are bound by 172
Capability Shader
Capability StorageUniformBufferBlock16
......@@ -204,7 +204,10 @@ spv.16bitstorage-int.frag
114: 20(int) Constant 7
115: 20(int) Constant 6
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
5: Label
69(x0): 68(ptr) Variable Function
......@@ -324,11 +327,9 @@ spv.16bitstorage-int.frag
164: 6(int16_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21
Store 165 164
167: 7(i16vec2) SConvert 166
168: 42(ptr) AccessChain 19(b2) 32
Store 168 167
169: 6(int16_t) SConvert 58
170: 28(ptr) AccessChain 19(b2) 21
Store 170 169
169: 42(ptr) AccessChain 19(b2) 32
Store 169 168
171: 28(ptr) AccessChain 19(b2) 21
Store 171 170
Return
FunctionEnd
......@@ -205,8 +205,10 @@ spv.16bitstorage-uint.frag
115: 20(int) Constant 7
116: 20(int) Constant 6
117: TypePointer Uniform 9(int)
167: 39(ivec2) ConstantComposite 82 10
170: 9(int) Constant 3
167: 6(int16_t) Constant 1
168: 6(int16_t) Constant 2
169: 7(i16vec2) ConstantComposite 167 168
171: 6(int16_t) Constant 3
4(main): 2 Function None 3
5: Label
69(x0): 68(ptr) Variable Function
......@@ -326,10 +328,8 @@ spv.16bitstorage-uint.frag
165: 6(int16_t) Load 164
166: 28(ptr) AccessChain 19(b2) 21
Store 166 165
168: 7(i16vec2) UConvert 167
169: 42(ptr) AccessChain 19(b2) 32
Store 169 168
171: 6(int16_t) UConvert 170
170: 42(ptr) AccessChain 19(b2) 32
Store 170 169
172: 28(ptr) AccessChain 19(b2) 21
Store 172 171
Return
......
spv.16bitstorage.frag
// Module Version 10000
// Generated by (magic number): 80007
// Id's are bound by 173
// Id's are bound by 172
Capability Shader
Capability StorageUniformBufferBlock16
......@@ -204,9 +204,10 @@ spv.16bitstorage.frag
114: 20(int) Constant 7
115: 20(int) Constant 6
116: TypePointer Uniform 20(int)
166: 37(float) Constant 1073741824
167: 40(fvec2) ConstantComposite 83 166
170: 37(float) Constant 1077936128
166:6(float16_t) Constant 15360
167:6(float16_t) Constant 16384
168: 7(f16vec2) ConstantComposite 166 167
170:6(float16_t) Constant 16896
4(main): 2 Function None 3
5: Label
70(x0): 69(ptr) Variable Function
......@@ -326,11 +327,9 @@ spv.16bitstorage.frag
164:6(float16_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21
Store 165 164
168: 7(f16vec2) FConvert 167
169: 43(ptr) AccessChain 19(b2) 32
Store 169 168
171:6(float16_t) FConvert 170
172: 28(ptr) AccessChain 19(b2) 21
Store 172 171
171: 28(ptr) AccessChain 19(b2) 21
Store 171 170
Return
FunctionEnd
spv.8bitstorage-int.frag
// Module Version 10000
// Generated by (magic number): 80007
// Id's are bound by 171
// Id's are bound by 172
Capability Shader
Capability CapabilityUniformAndStorageBuffer8BitAccess
......@@ -203,7 +203,10 @@ spv.8bitstorage-int.frag
114: 20(int) Constant 7
115: 20(int) Constant 6
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
5: Label
69(x0): 68(ptr) Variable Function
......@@ -323,11 +326,9 @@ spv.8bitstorage-int.frag
164: 6(int8_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21
Store 165 164
167: 7(i8vec2) SConvert 166
168: 42(ptr) AccessChain 19(b2) 32
Store 168 167
169: 6(int8_t) SConvert 58
170: 28(ptr) AccessChain 19(b2) 21
Store 170 169
169: 42(ptr) AccessChain 19(b2) 32
Store 169 168
171: 28(ptr) AccessChain 19(b2) 21
Store 171 170
Return
FunctionEnd
......@@ -204,8 +204,10 @@ spv.8bitstorage-uint.frag
115: 20(int) Constant 7
116: 20(int) Constant 6
117: TypePointer Uniform 9(int)
167: 39(ivec2) ConstantComposite 82 10
170: 9(int) Constant 3
167: 6(int8_t) Constant 1
168: 6(int8_t) Constant 2
169: 7(i8vec2) ConstantComposite 167 168
171: 6(int8_t) Constant 3
4(main): 2 Function None 3
5: Label
69(x0): 68(ptr) Variable Function
......@@ -325,10 +327,8 @@ spv.8bitstorage-uint.frag
165: 6(int8_t) Load 164
166: 28(ptr) AccessChain 19(b2) 21
Store 166 165
168: 7(i8vec2) UConvert 167
169: 42(ptr) AccessChain 19(b2) 32
Store 169 168
171: 6(int8_t) UConvert 170
170: 42(ptr) AccessChain 19(b2) 32
Store 170 169
172: 28(ptr) AccessChain 19(b2) 21
Store 172 171
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
// This is 'mechanism' here, it does any conversion told.
// It is about basic type, not about shape.
// 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.
......@@ -712,7 +712,11 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
TType newType(convertTo, EvqTemporary, node->getVectorSize(), node->getMatrixCols(), node->getMatrixRows());
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
if (node->getType().getQualifier().isSpecConstant() && isSpecializationOperation(*newNode))
......@@ -1021,7 +1025,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
//
// Add a new newNode for the conversion.
//
TIntermUnary* newNode = createConversion(promoteTo, node);
TIntermTyped* newNode = createConversion(promoteTo, node);
return newNode;
}
......
......@@ -732,7 +732,7 @@ protected:
bool specConstantPropagates(const TIntermTyped&, const TIntermTyped&);
void performTextureUpgradeAndSamplerRemovalTransformation(TIntermNode* root);
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;
bool extensionRequested(const char *extension) const {return requestedExtensions.find(extension) != requestedExtensions.end();}
static const char* getResourceName(TResourceType);
......
......@@ -231,6 +231,7 @@ INSTANTIATE_TEST_CASE_P(
"precise_struct_block.vert",
"maxClipDistances.vert",
"findFunction.frag",
"constantUnaryConversion.comp"
})),
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