HLSL: Add min*{float,int,uint} types

These HLSL types are guaranteed to have at least the given number of bits, but may have more.

min{16,10}float is mapped to EbtFloat at medium precision -> SPIRV RelaxedPrecision
min{16,12}int and min16uint are mapped to mediump -> SPIR-V RelaxedPrecision
This commit is contained in:
steve-lunarg 2016-10-26 19:18:55 -06:00
parent e19e68d431
commit 3226b0835c
6 changed files with 428 additions and 2 deletions

View File

@ -0,0 +1,222 @@
hlsl.mintypes.frag
Shader version: 450
gl_FragCoord origin is upper left
0:? Sequence
0:9 Function Definition: main( (temp structure{temp 4-component vector of float Color})
0:9 Function Parameters:
0:? Sequence
0:40 add (temp mediump 2-component vector of float)
0:40 'mf16_2' (temp mediump 2-component vector of float)
0:40 'mf16' (temp mediump float)
0:41 add (temp mediump 2-component vector of float)
0:41 'mf10_2' (temp mediump 2-component vector of float)
0:41 'mf10' (temp mediump float)
0:42 add (temp mediump 2-component vector of int)
0:42 'mi16_2' (temp mediump 2-component vector of int)
0:42 'mi16' (temp mediump int)
0:43 add (temp mediump 2-component vector of int)
0:43 'mi12_2' (temp mediump 2-component vector of int)
0:43 'mi12' (temp mediump int)
0:44 add (temp mediump 2-component vector of uint)
0:44 'mu16_2' (temp mediump 2-component vector of uint)
0:44 'mu16' (temp mediump uint)
0:47 move second child to first child (temp 4-component vector of float)
0:47 Color: direct index for structure (temp 4-component vector of float)
0:47 'psout' (temp structure{temp 4-component vector of float Color})
0:47 Constant:
0:47 0 (const int)
0:47 Constant:
0:47 0.000000
0:47 0.000000
0:47 0.000000
0:47 0.000000
0:48 Sequence
0:48 Sequence
0:48 move second child to first child (temp 4-component vector of float)
0:? 'Color' (layout(location=0 ) out 4-component vector of float)
0:48 Color: direct index for structure (temp 4-component vector of float)
0:48 'psout' (temp structure{temp 4-component vector of float Color})
0:48 Constant:
0:48 0 (const int)
0:48 Branch: Return
0:? Linker Objects
0:? 'Color' (layout(location=0 ) out 4-component vector of float)
0:? 'anon@0' (uniform block{layout(offset=0 ) uniform mediump float b1a, layout(offset=4 ) uniform mediump float b1b})
Linked fragment stage:
Shader version: 450
gl_FragCoord origin is upper left
0:? Sequence
0:9 Function Definition: main( (temp structure{temp 4-component vector of float Color})
0:9 Function Parameters:
0:? Sequence
0:40 add (temp mediump 2-component vector of float)
0:40 'mf16_2' (temp mediump 2-component vector of float)
0:40 'mf16' (temp mediump float)
0:41 add (temp mediump 2-component vector of float)
0:41 'mf10_2' (temp mediump 2-component vector of float)
0:41 'mf10' (temp mediump float)
0:42 add (temp mediump 2-component vector of int)
0:42 'mi16_2' (temp mediump 2-component vector of int)
0:42 'mi16' (temp mediump int)
0:43 add (temp mediump 2-component vector of int)
0:43 'mi12_2' (temp mediump 2-component vector of int)
0:43 'mi12' (temp mediump int)
0:44 add (temp mediump 2-component vector of uint)
0:44 'mu16_2' (temp mediump 2-component vector of uint)
0:44 'mu16' (temp mediump uint)
0:47 move second child to first child (temp 4-component vector of float)
0:47 Color: direct index for structure (temp 4-component vector of float)
0:47 'psout' (temp structure{temp 4-component vector of float Color})
0:47 Constant:
0:47 0 (const int)
0:47 Constant:
0:47 0.000000
0:47 0.000000
0:47 0.000000
0:47 0.000000
0:48 Sequence
0:48 Sequence
0:48 move second child to first child (temp 4-component vector of float)
0:? 'Color' (layout(location=0 ) out 4-component vector of float)
0:48 Color: direct index for structure (temp 4-component vector of float)
0:48 'psout' (temp structure{temp 4-component vector of float Color})
0:48 Constant:
0:48 0 (const int)
0:48 Branch: Return
0:? Linker Objects
0:? 'Color' (layout(location=0 ) out 4-component vector of float)
0:? 'anon@0' (uniform block{layout(offset=0 ) uniform mediump float b1a, layout(offset=4 ) uniform mediump float b1b})
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 65
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 58
ExecutionMode 4 OriginUpperLeft
Name 4 "main"
Name 9 "mf16_2"
Name 12 "mf16"
Name 16 "mf10_2"
Name 18 "mf10"
Name 25 "mi16_2"
Name 28 "mi16"
Name 32 "mi12_2"
Name 34 "mi12"
Name 41 "mu16_2"
Name 44 "mu16"
Name 49 "PS_OUTPUT"
MemberName 49(PS_OUTPUT) 0 "Color"
Name 51 "psout"
Name 58 "Color"
Name 62 "$Global"
MemberName 62($Global) 0 "b1a"
MemberName 62($Global) 1 "b1b"
Name 64 ""
Decorate 9(mf16_2) RelaxedPrecision
Decorate 10 RelaxedPrecision
Decorate 12(mf16) RelaxedPrecision
Decorate 13 RelaxedPrecision
Decorate 14 RelaxedPrecision
Decorate 15 RelaxedPrecision
Decorate 16(mf10_2) RelaxedPrecision
Decorate 17 RelaxedPrecision
Decorate 18(mf10) RelaxedPrecision
Decorate 19 RelaxedPrecision
Decorate 20 RelaxedPrecision
Decorate 21 RelaxedPrecision
Decorate 25(mi16_2) RelaxedPrecision
Decorate 26 RelaxedPrecision
Decorate 28(mi16) RelaxedPrecision
Decorate 29 RelaxedPrecision
Decorate 30 RelaxedPrecision
Decorate 31 RelaxedPrecision
Decorate 32(mi12_2) RelaxedPrecision
Decorate 33 RelaxedPrecision
Decorate 34(mi12) RelaxedPrecision
Decorate 35 RelaxedPrecision
Decorate 36 RelaxedPrecision
Decorate 37 RelaxedPrecision
Decorate 41(mu16_2) RelaxedPrecision
Decorate 42 RelaxedPrecision
Decorate 44(mu16) RelaxedPrecision
Decorate 45 RelaxedPrecision
Decorate 46 RelaxedPrecision
Decorate 47 RelaxedPrecision
Decorate 58(Color) Location 0
MemberDecorate 62($Global) 0 RelaxedPrecision
MemberDecorate 62($Global) 1 RelaxedPrecision
Decorate 62($Global) Block
Decorate 64 DescriptorSet 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 2
8: TypePointer Function 7(fvec2)
11: TypePointer Function 6(float)
22: TypeInt 32 1
23: TypeVector 22(int) 2
24: TypePointer Function 23(ivec2)
27: TypePointer Function 22(int)
38: TypeInt 32 0
39: TypeVector 38(int) 2
40: TypePointer Function 39(ivec2)
43: TypePointer Function 38(int)
48: TypeVector 6(float) 4
49(PS_OUTPUT): TypeStruct 48(fvec4)
50: TypePointer Function 49(PS_OUTPUT)
52: 22(int) Constant 0
53: 6(float) Constant 0
54: 48(fvec4) ConstantComposite 53 53 53 53
55: TypePointer Function 48(fvec4)
57: TypePointer Output 48(fvec4)
58(Color): 57(ptr) Variable Output
62($Global): TypeStruct 6(float) 6(float)
63: TypePointer Uniform 62($Global)
64: 63(ptr) Variable Uniform
4(main): 2 Function None 3
5: Label
9(mf16_2): 8(ptr) Variable Function
12(mf16): 11(ptr) Variable Function
16(mf10_2): 8(ptr) Variable Function
18(mf10): 11(ptr) Variable Function
25(mi16_2): 24(ptr) Variable Function
28(mi16): 27(ptr) Variable Function
32(mi12_2): 24(ptr) Variable Function
34(mi12): 27(ptr) Variable Function
41(mu16_2): 40(ptr) Variable Function
44(mu16): 43(ptr) Variable Function
51(psout): 50(ptr) Variable Function
10: 7(fvec2) Load 9(mf16_2)
13: 6(float) Load 12(mf16)
14: 7(fvec2) CompositeConstruct 13 13
15: 7(fvec2) FAdd 10 14
17: 7(fvec2) Load 16(mf10_2)
19: 6(float) Load 18(mf10)
20: 7(fvec2) CompositeConstruct 19 19
21: 7(fvec2) FAdd 17 20
26: 23(ivec2) Load 25(mi16_2)
29: 22(int) Load 28(mi16)
30: 23(ivec2) CompositeConstruct 29 29
31: 23(ivec2) IAdd 26 30
33: 23(ivec2) Load 32(mi12_2)
35: 22(int) Load 34(mi12)
36: 23(ivec2) CompositeConstruct 35 35
37: 23(ivec2) IAdd 33 36
42: 39(ivec2) Load 41(mu16_2)
45: 38(int) Load 44(mu16)
46: 39(ivec2) CompositeConstruct 45 45
47: 39(ivec2) IAdd 42 46
56: 55(ptr) AccessChain 51(psout) 52
Store 56 54
59: 55(ptr) AccessChain 51(psout) 52
60: 48(fvec4) Load 59
Store 58(Color) 60
Return
FunctionEnd

49
Test/hlsl.mintypes.frag Normal file
View File

@ -0,0 +1,49 @@
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
uniform min16float b1a, b1b;
PS_OUTPUT main()
{
min16float mf16;
min16float1 mf16_1;
min16float2 mf16_2;
min16float3 mf16_3;
min16float4 mf16_4;
min10float mf10;
min10float1 mf10_1;
min10float2 mf10_2;
min10float3 mf10_3;
min10float4 mf12_4;
min16int mi16;
min16int1 mi16_1;
min16int2 mi16_2;
min16int3 mi16_3;
min16int4 mi16_4;
min12int mi12;
min12int1 mi12_1;
min12int2 mi12_2;
min12int3 mi12_3;
min12int4 mi12_4;
min16uint mu16;
min16uint1 mu16_1;
min16uint2 mu16_2;
min16uint3 mu16_3;
min16uint4 mu16_4;
mf16_2 + mf16;
mf10_2 + mf10;
mi16_2 + mi16;
mi12_2 + mi12;
mu16_2 + mu16;
PS_OUTPUT psout;
psout.Color = 0;
return psout;
}

View File

@ -146,6 +146,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.logical.unary.frag", "main"},
{"hlsl.logical.binary.frag", "main"},
{"hlsl.logical.binary.vec.frag", "main"},
{"hlsl.mintypes.frag", "main"},
{"hlsl.multiEntry.vert", "RealEntrypoint"},
{"hlsl.multiReturn.frag", "main"},
{"hlsl.matrixindex.frag", "main"},

View File

@ -465,7 +465,7 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type)
// whatever comes from acceptQualifier.
assert(qualifier.layoutFormat == ElfNone);
qualifier.layoutFormat = type.getQualifier().layoutFormat;
qualifier.precision = type.getQualifier().precision;
type.getQualifier() = qualifier;
}
@ -967,6 +967,14 @@ bool HlslGrammar::acceptTextureType(TType& type)
// Otherwise, return false, and don't advance
bool HlslGrammar::acceptType(TType& type)
{
// Basic types for min* types, broken out here in case of future
// changes, e.g, to use native halfs.
static const TBasicType min16float_bt = EbtFloat;
static const TBasicType min10float_bt = EbtFloat;
static const TBasicType min16int_bt = EbtInt;
static const TBasicType min12int_bt = EbtInt;
static const TBasicType min16uint_bt = EbtUint;
switch (peek()) {
case EHTokVector:
return acceptVectorTemplateType(type);
@ -1118,6 +1126,91 @@ bool HlslGrammar::acceptType(TType& type)
new(&type) TType(EbtBool, EvqTemporary, 4);
break;
case EHTokMin16float:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin16float1:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin16float2:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin16float3:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin16float4:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokMin10float:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin10float1:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin10float2:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin10float3:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin10float4:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokMin16int:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin16int1:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin16int2:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin16int3:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin16int4:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokMin12int:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin12int1:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin12int2:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin12int3:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin12int4:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokMin16uint:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin16uint1:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin16uint2:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin16uint3:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin16uint4:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokInt1x1:
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 1);
break;

View File

@ -136,7 +136,7 @@ void HlslScanContext::fillInKeywordMap()
(*KeywordMap)["min10float"] = EHTokMin10float;
(*KeywordMap)["min16int"] = EHTokMin16int;
(*KeywordMap)["min12int"] = EHTokMin12int;
(*KeywordMap)["min16uint"] = EHTokMin16int;
(*KeywordMap)["min16uint"] = EHTokMin16uint;
(*KeywordMap)["bool1"] = EHTokBool1;
(*KeywordMap)["bool2"] = EHTokBool2;
@ -159,6 +159,27 @@ void HlslScanContext::fillInKeywordMap()
(*KeywordMap)["uint3"] = EHTokUint3;
(*KeywordMap)["uint4"] = EHTokUint4;
(*KeywordMap)["min16float1"] = EHTokMin16float1;
(*KeywordMap)["min16float2"] = EHTokMin16float2;
(*KeywordMap)["min16float3"] = EHTokMin16float3;
(*KeywordMap)["min16float4"] = EHTokMin16float4;
(*KeywordMap)["min10float1"] = EHTokMin10float1;
(*KeywordMap)["min10float2"] = EHTokMin10float2;
(*KeywordMap)["min10float3"] = EHTokMin10float3;
(*KeywordMap)["min10float4"] = EHTokMin10float4;
(*KeywordMap)["min16int1"] = EHTokMin16int1;
(*KeywordMap)["min16int2"] = EHTokMin16int2;
(*KeywordMap)["min16int3"] = EHTokMin16int3;
(*KeywordMap)["min16int4"] = EHTokMin16int4;
(*KeywordMap)["min12int1"] = EHTokMin12int1;
(*KeywordMap)["min12int2"] = EHTokMin12int2;
(*KeywordMap)["min12int3"] = EHTokMin12int3;
(*KeywordMap)["min12int4"] = EHTokMin12int4;
(*KeywordMap)["min16uint1"] = EHTokMin16uint1;
(*KeywordMap)["min16uint2"] = EHTokMin16uint2;
(*KeywordMap)["min16uint3"] = EHTokMin16uint3;
(*KeywordMap)["min16uint4"] = EHTokMin16uint4;
(*KeywordMap)["int1x1"] = EHTokInt1x1;
(*KeywordMap)["int1x2"] = EHTokInt1x2;
(*KeywordMap)["int1x3"] = EHTokInt1x3;
@ -518,6 +539,26 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier()
case EHTokUint2:
case EHTokUint3:
case EHTokUint4:
case EHTokMin16float1:
case EHTokMin16float2:
case EHTokMin16float3:
case EHTokMin16float4:
case EHTokMin10float1:
case EHTokMin10float2:
case EHTokMin10float3:
case EHTokMin10float4:
case EHTokMin16int1:
case EHTokMin16int2:
case EHTokMin16int3:
case EHTokMin16int4:
case EHTokMin12int1:
case EHTokMin12int2:
case EHTokMin12int3:
case EHTokMin12int4:
case EHTokMin16uint1:
case EHTokMin16uint2:
case EHTokMin16uint3:
case EHTokMin16uint4:
// matrix types
case EHTokInt1x1:

View File

@ -108,6 +108,26 @@ enum EHlslTokenClass {
EHTokUint2,
EHTokUint3,
EHTokUint4,
EHTokMin16float1,
EHTokMin16float2,
EHTokMin16float3,
EHTokMin16float4,
EHTokMin10float1,
EHTokMin10float2,
EHTokMin10float3,
EHTokMin10float4,
EHTokMin16int1,
EHTokMin16int2,
EHTokMin16int3,
EHTokMin16int4,
EHTokMin12int1,
EHTokMin12int2,
EHTokMin12int3,
EHTokMin12int4,
EHTokMin16uint1,
EHTokMin16uint2,
EHTokMin16uint3,
EHTokMin16uint4,
// matrix types
EHTokInt1x1,