Commit 70942e5f by John Kessenich Committed by GitHub

Merge pull request #905 from KhronosGroup/flatten-opaque-structs

SPV: When passing structs of opaque types, flatten and pass the membe…
parents d66c5b12 f3150742
hlsl.aliasOpaque.frag
Shader version: 500
gl_FragCoord origin is upper left
0:? Sequence
0:12 Function Definition: osCall(struct-OS-p1-f1-t211; ( temp 4-component vector of float)
0:12 Function Parameters:
0:? 'ss' ( in sampler)
0:? 'a' ( in float)
0:? 'tex' ( in texture2D)
0:? Sequence
0:13 Branch: Return with expression
0:13 vector-scale ( temp 4-component vector of float)
0:? 'a' ( in float)
0:13 texture ( temp 4-component vector of float)
0:13 Construct combined texture-sampler ( temp sampler2D)
0:? 'tex' ( in texture2D)
0:? 'ss' ( in sampler)
0:? Constant:
0:? 0.200000
0:? 0.300000
0:17 Function Definition: @main( ( temp 4-component vector of float)
0:17 Function Parameters:
0:? Sequence
0:19 'gss2' ( uniform sampler)
0:20 'gss' ( uniform sampler)
0:21 'gtex' ( uniform texture2D)
0:22 move second child to first child ( temp float)
0:? 'a' ( temp float)
0:22 Constant:
0:22 3.000000
0:28 Branch: Return with expression
0:28 Function Call: osCall(struct-OS-p1-f1-t211; ( temp 4-component vector of float)
0:? 'gss' ( uniform sampler)
0:? 'a' ( temp float)
0:? 'gtex' ( uniform texture2D)
0:17 Function Definition: main( ( temp void)
0:17 Function Parameters:
0:? Sequence
0:17 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:17 Function Call: @main( ( temp 4-component vector of float)
0:? Linker Objects
0:? 'gss' ( uniform sampler)
0:? 'gss2' ( uniform sampler)
0:? 'gtex' ( uniform texture2D)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
Linked fragment stage:
Shader version: 500
gl_FragCoord origin is upper left
0:? Sequence
0:12 Function Definition: osCall(struct-OS-p1-f1-t211; ( temp 4-component vector of float)
0:12 Function Parameters:
0:? 'ss' ( in sampler)
0:? 'a' ( in float)
0:? 'tex' ( in texture2D)
0:? Sequence
0:13 Branch: Return with expression
0:13 vector-scale ( temp 4-component vector of float)
0:? 'a' ( in float)
0:13 texture ( temp 4-component vector of float)
0:13 Construct combined texture-sampler ( temp sampler2D)
0:? 'tex' ( in texture2D)
0:? 'ss' ( in sampler)
0:? Constant:
0:? 0.200000
0:? 0.300000
0:17 Function Definition: @main( ( temp 4-component vector of float)
0:17 Function Parameters:
0:? Sequence
0:19 'gss2' ( uniform sampler)
0:20 'gss' ( uniform sampler)
0:21 'gtex' ( uniform texture2D)
0:22 move second child to first child ( temp float)
0:? 'a' ( temp float)
0:22 Constant:
0:22 3.000000
0:28 Branch: Return with expression
0:28 Function Call: osCall(struct-OS-p1-f1-t211; ( temp 4-component vector of float)
0:? 'gss' ( uniform sampler)
0:? 'a' ( temp float)
0:? 'gtex' ( uniform texture2D)
0:17 Function Definition: main( ( temp void)
0:17 Function Parameters:
0:? Sequence
0:17 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:17 Function Call: @main( ( temp 4-component vector of float)
0:? Linker Objects
0:? 'gss' ( uniform sampler)
0:? 'gss2' ( uniform sampler)
0:? 'gtex' ( uniform texture2D)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 48
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 46
ExecutionMode 4 OriginUpperLeft
Source HLSL 500
Name 4 "main"
Name 17 "osCall(struct-OS-p1-f1-t211;"
Name 14 "ss"
Name 15 "a"
Name 16 "tex"
Name 20 "@main("
Name 35 "gss2"
Name 36 "gss"
Name 37 "gtex"
Name 38 "a"
Name 40 "param"
Name 46 "@entryPointOutput"
Decorate 35(gss2) DescriptorSet 0
Decorate 36(gss) DescriptorSet 0
Decorate 37(gtex) DescriptorSet 0
Decorate 46(@entryPointOutput) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeSampler
7: TypePointer UniformConstant 6
8: TypeFloat 32
9: TypePointer Function 8(float)
10: TypeImage 8(float) 2D sampled format:Unknown
11: TypePointer UniformConstant 10
12: TypeVector 8(float) 4
13: TypeFunction 12(fvec4) 7(ptr) 9(ptr) 11(ptr)
19: TypeFunction 12(fvec4)
25: TypeSampledImage 10
27: TypeVector 8(float) 2
28: 8(float) Constant 1045220557
29: 8(float) Constant 1050253722
30: 27(fvec2) ConstantComposite 28 29
35(gss2): 7(ptr) Variable UniformConstant
36(gss): 7(ptr) Variable UniformConstant
37(gtex): 11(ptr) Variable UniformConstant
39: 8(float) Constant 1077936128
45: TypePointer Output 12(fvec4)
46(@entryPointOutput): 45(ptr) Variable Output
4(main): 2 Function None 3
5: Label
47: 12(fvec4) FunctionCall 20(@main()
Store 46(@entryPointOutput) 47
Return
FunctionEnd
17(osCall(struct-OS-p1-f1-t211;): 12(fvec4) Function None 13
14(ss): 7(ptr) FunctionParameter
15(a): 9(ptr) FunctionParameter
16(tex): 11(ptr) FunctionParameter
18: Label
22: 8(float) Load 15(a)
23: 10 Load 16(tex)
24: 6 Load 14(ss)
26: 25 SampledImage 23 24
31: 12(fvec4) ImageSampleImplicitLod 26 30
32: 12(fvec4) VectorTimesScalar 31 22
ReturnValue 32
FunctionEnd
20(@main(): 12(fvec4) Function None 19
21: Label
38(a): 9(ptr) Variable Function
40(param): 9(ptr) Variable Function
Store 38(a) 39
41: 8(float) Load 38(a)
Store 40(param) 41
42: 12(fvec4) FunctionCall 17(osCall(struct-OS-p1-f1-t211;) 36(gss) 40(param) 37(gtex)
ReturnValue 42
FunctionEnd
struct OS {
SamplerState ss;
float a;
Texture2D tex;
};
SamplerState gss;
SamplerState gss2;
Texture2D gtex;
float4 osCall(OS s)
{
return s.a * s.tex.Sample(s.ss, float2(0.2, 0.3));
}
float4 main() : SV_TARGET0
{
OS os;
os.ss = gss2;
os.ss = gss;
os.tex = gtex;
os.a = 3.0;
// this should give an error
//SamplerState localss;
//localss = gss2;
return osCall(os);
}
struct os {
sampler2D s2D;
};
struct os2 {
sampler2D s2D;
Texture2D tex;
};
Texture2D tex;
os s;
os2 s2;
float4 osCall1(os s)
{
return tex.Sample(s.s2D, float2(0.2, 0.3));
}
float4 osCall2(os s, float2 f2)
{
return tex.Sample(s.s2D, f2);
}
float4 os2Call1(os2 s)
{
return s.tex.Sample(s.s2D, float2(0.2, 0.3));
}
float4 os2Call2(os2 s, float2 f2)
{
return s.tex.Sample(s.s2D, f2);
}
float4 main() : SV_TARGET0
{
return osCall1(s) +
osCall2(s, float2(0.2, 0.3)) +
os2Call1(s2) +
os2Call2(s2, float2(0.2, 0.3));
}
......@@ -81,6 +81,7 @@ INSTANTIATE_TEST_CASE_P(
ToSpirv, HlslCompileTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.amend.frag", "f1"},
{"hlsl.aliasOpaque.frag", "main"},
{"hlsl.array.frag", "PixelShaderFunction"},
{"hlsl.array.implicit-size.frag", "PixelShaderFunction"},
{"hlsl.array.multidim.frag", "main"},
......@@ -114,6 +115,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.float1.frag", "PixelShaderFunction"},
{"hlsl.float4.frag", "PixelShaderFunction"},
{"hlsl.flatten.return.frag", "main"},
{"hlsl.flattenOpaque.frag", "main"},
{"hlsl.forLoop.frag", "PixelShaderFunction"},
{"hlsl.gather.array.dx10.frag", "main"},
{"hlsl.gather.basic.dx10.frag", "main"},
......
......@@ -96,6 +96,7 @@ public:
void decomposeGeometryMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void pushFrontArguments(TIntermTyped* front, TIntermTyped*& arguments);
void addInputArgumentConversions(const TFunction&, TIntermTyped*&);
void expandArguments(const TSourceLoc&, const TFunction&, TIntermTyped*&);
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermOperator&);
void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
TFunction* makeConstructorCall(const TSourceLoc&, const TType&);
......@@ -186,7 +187,8 @@ public:
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr) override;
// Apply L-value conversions. E.g, turning a write to a RWTexture into an ImageStore.
TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped* node);
TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped*& node);
TIntermTyped* handleSamplerLvalue(const TSourceLoc&, const char* op, TIntermTyped*& node);
bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
TLayoutFormat getLayoutFromTxType(const TSourceLoc&, const TType&);
......@@ -236,13 +238,14 @@ protected:
// Array and struct flattening
TIntermTyped* flattenAccess(TIntermTyped* base, int member);
bool shouldFlattenUniform(const TType&) const;
TIntermTyped* flattenAccess(int uniqueId, int member, const TType&);
bool shouldFlatten(const TType&) const;
bool wasFlattened(const TIntermTyped* node) const;
bool wasFlattened(int id) const { return flattenMap.find(id) != flattenMap.end(); }
int addFlattenedMember(const TSourceLoc& loc, const TVariable&, const TType&, TFlattenData&, const TString& name, bool track);
bool isFinalFlattening(const TType& type) const { return !(type.isStruct() || type.isArray()); }
// Structure splitting (splits interstage builtin types into its own struct)
// Structure splitting (splits interstage built-in types into its own struct)
TIntermTyped* splitAccessStruct(const TSourceLoc& loc, TIntermTyped*& base, int& member);
void splitAccessArray(const TSourceLoc& loc, TIntermTyped* base, TIntermTyped* index);
TType& split(TType& type, TString name, const TType* outerStructType = nullptr);
......
......@@ -502,7 +502,7 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
static const EShLanguageMask EShLangAll = EShLanguageMask(EShLangCount - 1);
// These are the actual stage masks defined in the documentation, in case they are
// needed for furture validation. For now, they are commented out, and set below
// needed for future validation. For now, they are commented out, and set below
// to EShLangAll, to allow any intrinsic to be used in any shader, which is legal
// if it is not called.
//
......
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