Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
12bc9aa9
Commit
12bc9aa9
authored
Apr 13, 2017
by
steve-lunarg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: HLSL: add Append/ConsumeBuffer support
parent
8e26feb8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
134 additions
and
59 deletions
+134
-59
hlsl.structbuffer.append.frag.out
Test/baseResults/hlsl.structbuffer.append.frag.out
+0
-0
hlsl.structbuffer.incdec.frag.out
Test/baseResults/hlsl.structbuffer.incdec.frag.out
+48
-41
hlsl.structbuffer.append.frag
Test/hlsl.structbuffer.append.frag
+11
-0
Hlsl.FromFile.cpp
gtests/Hlsl.FromFile.cpp
+1
-0
hlslParseHelper.cpp
hlsl/hlslParseHelper.cpp
+72
-17
hlslParseables.cpp
hlsl/hlslParseables.cpp
+2
-1
No files found.
Test/baseResults/hlsl.structbuffer.append.frag.out
0 → 100644
View file @
12bc9aa9
This diff is collapsed.
Click to expand it.
Test/baseResults/hlsl.structbuffer.incdec.frag.out
View file @
12bc9aa9
...
...
@@ -54,11 +54,14 @@ gl_FragCoord origin is upper left
0:16 Sequence
0:16 move second child to first child ( temp uint)
0:16 'c2' ( temp uint)
0:16 AtomicAdd ( temp uint)
0:16 @count: direct index for structure ( temp int)
0:16 'sbuf_rw_d@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:16 add ( temp uint)
0:16 AtomicAdd ( temp uint)
0:16 @count: direct index for structure ( temp int)
0:16 'sbuf_rw_d@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:16 Constant:
0:16 0 (const int)
0:16 Constant:
0:16
0
(const int)
0:16
-1
(const int)
0:16 Constant:
0:16 -1 (const int)
0:18 Branch: Return with expression
...
...
@@ -155,11 +158,14 @@ gl_FragCoord origin is upper left
0:16 Sequence
0:16 move second child to first child ( temp uint)
0:16 'c2' ( temp uint)
0:16 AtomicAdd ( temp uint)
0:16 @count: direct index for structure ( temp int)
0:16 'sbuf_rw_d@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:16 add ( temp uint)
0:16 AtomicAdd ( temp uint)
0:16 @count: direct index for structure ( temp int)
0:16 'sbuf_rw_d@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:16 Constant:
0:16 0 (const int)
0:16 Constant:
0:16
0
(const int)
0:16
-1
(const int)
0:16 Constant:
0:16 -1 (const int)
0:18 Branch: Return with expression
...
...
@@ -199,12 +205,12 @@ gl_FragCoord origin is upper left
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by
69
// Id's are bound by
70
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 6
2 65
EntryPoint Fragment 4 "main" 6
3 66
ExecutionMode 4 OriginUpperLeft
Source HLSL 500
Name 4 "main"
...
...
@@ -222,10 +228,10 @@ gl_FragCoord origin is upper left
Name 36 "sbuf_rw_i@count"
Name 42 "c2"
Name 43 "sbuf_rw_d@count"
Name 6
0
"pos"
Name 6
2
"pos"
Name 6
5
"@entryPointOutput"
Name 6
6
"param"
Name 6
1
"pos"
Name 6
3
"pos"
Name 6
6
"@entryPointOutput"
Name 6
7
"param"
Decorate 19 ArrayStride 16
MemberDecorate 20(sbuf_rw_i) 0 Offset 0
Decorate 20(sbuf_rw_i) BufferBlock
...
...
@@ -236,8 +242,8 @@ gl_FragCoord origin is upper left
Decorate 34(sbuf_rw_i@count) BufferBlock
Decorate 36(sbuf_rw_i@count) DescriptorSet 0
Decorate 43(sbuf_rw_d@count) DescriptorSet 0
Decorate 6
2
(pos) Location 0
Decorate 6
5
(@entryPointOutput) Location 0
Decorate 6
3
(pos) Location 0
Decorate 6
6
(@entryPointOutput) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 0
...
...
@@ -270,20 +276,20 @@ gl_FragCoord origin is upper left
40: 6(int) Constant 1
43(sbuf_rw_d@count): 35(ptr) Variable Uniform
45: 23(int) Constant 4294967295
6
1
: TypePointer Input 6(int)
6
2(pos): 61
(ptr) Variable Input
6
4
: TypePointer Output 9(fvec4)
6
5(@entryPointOutput): 64
(ptr) Variable Output
6
2
: TypePointer Input 6(int)
6
3(pos): 62
(ptr) Variable Input
6
5
: TypePointer Output 9(fvec4)
6
6(@entryPointOutput): 65
(ptr) Variable Output
4(main): 2 Function None 3
5: Label
6
0
(pos): 7(ptr) Variable Function
6
6
(param): 7(ptr) Variable Function
6
3: 6(int) Load 62
(pos)
Store 6
0(pos) 63
6
7: 6(int) Load 60
(pos)
Store 6
6(param) 67
6
8: 9(fvec4) FunctionCall 12(@main(u1;) 66
(param)
Store 6
5(@entryPointOutput) 68
6
1
(pos): 7(ptr) Variable Function
6
7
(param): 7(ptr) Variable Function
6
4: 6(int) Load 63
(pos)
Store 6
1(pos) 64
6
8: 6(int) Load 61
(pos)
Store 6
7(param) 68
6
9: 9(fvec4) FunctionCall 12(@main(u1;) 67
(param)
Store 6
6(@entryPointOutput) 69
Return
FunctionEnd
12(@main(u1;): 9(fvec4) Function None 10
...
...
@@ -300,17 +306,18 @@ gl_FragCoord origin is upper left
Store 33(c1) 41
44: 37(ptr) AccessChain 43(sbuf_rw_d@count) 24
46: 6(int) AtomicIAdd 44 40 17 45
Store 42(c2) 46
47: 7(ptr) AccessChain 16(result) 17
48: 6(int) Load 47
49: 8(float) ConvertUToF 48
50: 7(ptr) AccessChain 16(result) 40
51: 6(int) Load 50
52: 8(float) ConvertUToF 51
53: 6(int) Load 33(c1)
54: 8(float) ConvertUToF 53
55: 6(int) Load 42(c2)
56: 8(float) ConvertUToF 55
57: 9(fvec4) CompositeConstruct 49 52 54 56
ReturnValue 57
47: 6(int) IAdd 46 45
Store 42(c2) 47
48: 7(ptr) AccessChain 16(result) 17
49: 6(int) Load 48
50: 8(float) ConvertUToF 49
51: 7(ptr) AccessChain 16(result) 40
52: 6(int) Load 51
53: 8(float) ConvertUToF 52
54: 6(int) Load 33(c1)
55: 8(float) ConvertUToF 54
56: 6(int) Load 42(c2)
57: 8(float) ConvertUToF 56
58: 9(fvec4) CompositeConstruct 50 53 55 57
ReturnValue 58
FunctionEnd
Test/hlsl.structbuffer.append.frag
0 → 100644
View file @
12bc9aa9
AppendStructuredBuffer
<
float4
>
sbuf_a
;
ConsumeStructuredBuffer
<
float4
>
sbuf_c
;
AppendStructuredBuffer
<
float4
>
sbuf_unused
;
float4
main
(
uint
pos
:
FOO
)
:
SV_Target0
{
sbuf_a
.
Append
(
float4
(
1
,
2
,
3
,
4
));
return
sbuf_c
.
Consume
();
}
gtests/Hlsl.FromFile.cpp
View file @
12bc9aa9
...
...
@@ -245,6 +245,7 @@ INSTANTIATE_TEST_CASE_P(
{
"hlsl.structarray.flatten.frag"
,
"main"
},
{
"hlsl.structarray.flatten.geom"
,
"main"
},
{
"hlsl.structbuffer.frag"
,
"main"
},
{
"hlsl.structbuffer.append.frag"
,
"main"
},
{
"hlsl.structbuffer.atomics.frag"
,
"main"
},
{
"hlsl.structbuffer.byte.frag"
,
"main"
},
{
"hlsl.structbuffer.coherent.frag"
,
"main"
},
...
...
hlsl/hlslParseHelper.cpp
View file @
12bc9aa9
...
...
@@ -2454,7 +2454,7 @@ bool HlslParseContext::hasStructBuffCounter(const TString& name) const
case
EbvRWStructuredBuffer
:
// ...
return
true
;
default
:
return
false
;
//
other builtin types do not have
.
return
false
;
//
the other structuredbfufer types do not have a counter
.
}
}
...
...
@@ -2533,6 +2533,35 @@ void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TInte
bufferObj
=
arguments
->
getAsSymbolNode
();
}
if
(
bufferObj
==
nullptr
||
bufferObj
->
getAsSymbolNode
()
==
nullptr
)
return
;
TString
bufferName
(
bufferObj
->
getAsSymbolNode
()
->
getName
());
const
auto
bivIt
=
structBufferBuiltIn
.
find
(
bufferName
);
if
(
bivIt
==
structBufferBuiltIn
.
end
())
return
;
const
TBuiltInVariable
builtInType
=
bivIt
->
second
;
// Some methods require a hidden internal counter, obtained via getStructBufferCounter().
// This lambda adds something to it and returns the old value.
const
auto
incDecCounter
=
[
&
](
int
incval
)
->
TIntermTyped
*
{
TIntermTyped
*
incrementValue
=
intermediate
.
addConstantUnion
(
incval
,
loc
,
true
);
TIntermTyped
*
counter
=
getStructBufferCounter
(
loc
,
bufferObj
);
// obtain the counter member
if
(
counter
==
nullptr
)
return
nullptr
;
TIntermAggregate
*
counterIncrement
=
new
TIntermAggregate
(
EOpAtomicAdd
);
counterIncrement
->
setType
(
TType
(
EbtUint
,
EvqTemporary
));
counterIncrement
->
setLoc
(
loc
);
counterIncrement
->
getSequence
().
push_back
(
counter
);
counterIncrement
->
getSequence
().
push_back
(
incrementValue
);
return
counterIncrement
;
};
// Index to obtain the runtime sized array out of the buffer.
TIntermTyped
*
argArray
=
indexStructBufferContent
(
loc
,
bufferObj
);
if
(
argArray
==
nullptr
)
...
...
@@ -2545,7 +2574,9 @@ void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TInte
// Byte address buffers index in bytes (only multiples of 4 permitted... not so much a byte address
// buffer then, but that's what it calls itself.
const
bool
isByteAddressBuffer
=
(
argArray
->
getBasicType
()
==
EbtUint
);
const
bool
isByteAddressBuffer
=
(
builtInType
==
EbvByteAddressBuffer
||
builtInType
==
EbvRWByteAddressBuffer
);
if
(
isByteAddressBuffer
)
argIndex
=
intermediate
.
addBinaryNode
(
EOpRightShift
,
argIndex
,
intermediate
.
addConstantUnion
(
2
,
loc
,
true
),
loc
,
TType
(
EbtInt
));
...
...
@@ -2746,28 +2777,50 @@ void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TInte
}
break
;
case
EOpMethodIncrementCounter
:
{
node
=
incDecCounter
(
1
);
break
;
}
case
EOpMethodDecrementCounter
:
{
// These methods require a hidden internal counter, obtained via getStructBufferCounter()
TIntermTyped
*
incrementValue
=
intermediate
.
addConstantUnion
(
op
==
EOpMethodIncrementCounter
?
1
:
-
1
,
loc
,
true
);
TIntermTyped
*
counter
=
getStructBufferCounter
(
loc
,
bufferObj
);
// obtain the counter member
TIntermTyped
*
preIncValue
=
incDecCounter
(
-
1
);
// result is original value
node
=
intermediate
.
addBinaryNode
(
EOpAdd
,
preIncValue
,
intermediate
.
addConstantUnion
(
-
1
,
loc
,
true
),
loc
,
preIncValue
->
getType
());
break
;
}
node
=
incrementValue
;
case
EOpMethodAppend
:
{
TIntermTyped
*
oldCounter
=
incDecCounter
(
1
);
if
(
counter
==
nullptr
)
break
;
TIntermTyped
*
lValue
=
intermediate
.
addIndex
(
EOpIndexIndirect
,
argArray
,
oldCounter
,
loc
);
TIntermTyped
*
rValue
=
argAggregate
->
getSequence
()[
1
]
->
getAsTyped
();
const
TType
derefType
(
argArray
->
getType
(),
0
);
lValue
->
setType
(
derefType
);
node
=
intermediate
.
addAssign
(
EOpAssign
,
lValue
,
rValue
,
loc
);
node
->
setType
(
TType
(
EbtVoid
));
// Append is a void return type
break
;
}
case
EOpMethodConsume
:
{
TIntermTyped
*
oldCounter
=
incDecCounter
(
-
1
);
TIntermTyped
*
newCounter
=
intermediate
.
addBinaryNode
(
EOpAdd
,
oldCounter
,
intermediate
.
addConstantUnion
(
-
1
,
loc
,
true
),
loc
,
oldCounter
->
getType
());
TIntermAggregate
*
counterIncrement
=
new
TIntermAggregate
(
EOpAtomicAdd
);
counterIncrement
->
setType
(
TType
(
EbtUint
,
EvqTemporary
));
counterIncrement
->
setLoc
(
loc
);
counterIncrement
->
getSequence
().
push_back
(
counter
);
counterIncrement
->
getSequence
().
push_back
(
incrementValue
);
node
=
intermediate
.
addIndex
(
EOpIndexIndirect
,
argArray
,
newCounter
,
loc
);
node
=
counterIncrement
;
const
TType
derefType
(
argArray
->
getType
(),
0
);
node
->
setType
(
derefType
);
break
;
}
break
;
default
:
break
;
// most pass through unchanged
...
...
@@ -5954,7 +6007,9 @@ const TFunction* HlslParseContext::findFunction(const TSourceLoc& loc, TFunction
(
candidateList
[
0
]
->
getBuiltInOp
()
==
EOpMethodAppend
||
candidateList
[
0
]
->
getBuiltInOp
()
==
EOpMethodRestartStrip
||
candidateList
[
0
]
->
getBuiltInOp
()
==
EOpMethodIncrementCounter
||
candidateList
[
0
]
->
getBuiltInOp
()
==
EOpMethodDecrementCounter
))
{
candidateList
[
0
]
->
getBuiltInOp
()
==
EOpMethodDecrementCounter
||
candidateList
[
0
]
->
getBuiltInOp
()
==
EOpMethodAppend
||
candidateList
[
0
]
->
getBuiltInOp
()
==
EOpMethodConsume
))
{
return
candidateList
[
0
];
}
...
...
hlsl/hlslParseables.cpp
View file @
12bc9aa9
...
...
@@ -873,6 +873,7 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
{
"InterlockedXor"
,
nullptr
,
nullptr
,
"-"
,
"-"
,
EShLangAll
,
true
},
{
"IncrementCounter"
,
nullptr
,
nullptr
,
"-"
,
"-"
,
EShLangAll
,
true
},
{
"DecrementCounter"
,
nullptr
,
nullptr
,
"-"
,
"-"
,
EShLangAll
,
true
},
{
"Consume"
,
nullptr
,
nullptr
,
"-"
,
"-"
,
EShLangAll
,
true
},
// Mark end of list, since we want to avoid a range-based for, as some compilers don't handle it yet.
{
nullptr
,
nullptr
,
nullptr
,
nullptr
,
nullptr
,
0
,
false
},
...
...
@@ -1184,7 +1185,7 @@ void TBuiltInParseablesHlsl::identifyBuiltIns(int /*version*/, EProfile /*profil
symbolTable
.
relateToOperator
(
BUILTIN_PREFIX
"Store4"
,
EOpMethodStore4
);
symbolTable
.
relateToOperator
(
BUILTIN_PREFIX
"IncrementCounter"
,
EOpMethodIncrementCounter
);
symbolTable
.
relateToOperator
(
BUILTIN_PREFIX
"DecrementCounter"
,
EOpMethodDecrementCounter
);
symbolTable
.
relateToOperator
(
BUILTIN_PREFIX
"Append"
,
EOpMethodAppend
);
// Append is also a GS method: we don't add it twice
symbolTable
.
relateToOperator
(
BUILTIN_PREFIX
"Consume"
,
EOpMethodConsume
);
symbolTable
.
relateToOperator
(
BUILTIN_PREFIX
"InterlockedAdd"
,
EOpInterlockedAdd
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment