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
48d6e798
Commit
48d6e798
authored
Oct 06, 2017
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SPV: Correct semantics of atomic-counter decrement.
The semantics differ between GLSL/HLSL and SPIR-V. Translate between these.
parent
592e8f04
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
71 deletions
+80
-71
GlslangToSpv.cpp
SPIRV/GlslangToSpv.cpp
+9
-1
spv.atomic.comp.out
Test/baseResults/spv.atomic.comp.out
+69
-68
intermediate.h
glslang/Include/intermediate.h
+2
-2
No files found.
SPIRV/GlslangToSpv.cpp
View file @
48d6e798
...
@@ -4833,6 +4833,7 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv
...
@@ -4833,6 +4833,7 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv
// - there are extra SPV operands with no glslang source
// - there are extra SPV operands with no glslang source
// - compare-exchange swaps the value and comparator
// - compare-exchange swaps the value and comparator
// - compare-exchange has an extra memory semantics
// - compare-exchange has an extra memory semantics
// - EOpAtomicCounterDecrement needs a post decrement
std
::
vector
<
spv
::
Id
>
spvAtomicOperands
;
// hold the spv operands
std
::
vector
<
spv
::
Id
>
spvAtomicOperands
;
// hold the spv operands
auto
opIt
=
operands
.
begin
();
// walk the glslang operands
auto
opIt
=
operands
.
begin
();
// walk the glslang operands
spvAtomicOperands
.
push_back
(
*
(
opIt
++
));
spvAtomicOperands
.
push_back
(
*
(
opIt
++
));
...
@@ -4851,7 +4852,14 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv
...
@@ -4851,7 +4852,14 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv
for
(;
opIt
!=
operands
.
end
();
++
opIt
)
for
(;
opIt
!=
operands
.
end
();
++
opIt
)
spvAtomicOperands
.
push_back
(
*
opIt
);
spvAtomicOperands
.
push_back
(
*
opIt
);
return
builder
.
createOp
(
opCode
,
typeId
,
spvAtomicOperands
);
spv
::
Id
resultId
=
builder
.
createOp
(
opCode
,
typeId
,
spvAtomicOperands
);
// GLSL and HLSL atomic-counter decrement return post-decrement value,
// while SPIR-V returns pre-decrement value. Translate between these semantics.
if
(
op
==
glslang
::
EOpAtomicCounterDecrement
)
resultId
=
builder
.
createBinOp
(
spv
::
OpISub
,
typeId
,
resultId
,
builder
.
makeIntConstant
(
1
));
return
resultId
;
}
}
// Create group invocation operations.
// Create group invocation operations.
...
...
Test/baseResults/spv.atomic.comp.out
View file @
48d6e798
spv.atomic.comp
spv.atomic.comp
// Module Version 10000
// Module Version 10000
// Generated by (magic number): 80001
// Generated by (magic number): 80001
// Id's are bound by 7
3
// Id's are bound by 7
4
Capability Shader
Capability Shader
Capability AtomicStorage
Capability AtomicStorage
...
@@ -17,29 +17,29 @@ spv.atomic.comp
...
@@ -17,29 +17,29 @@ spv.atomic.comp
Name 20 "counter"
Name 20 "counter"
Name 23 "val"
Name 23 "val"
Name 27 "countArr"
Name 27 "countArr"
Name 3
5
"origi"
Name 3
7
"origi"
Name 3
7
"atomi"
Name 3
9
"atomi"
Name 4
0
"origu"
Name 4
2
"origu"
Name 4
2
"atomu"
Name 4
4
"atomu"
Name 4
3
"value"
Name 4
5
"value"
Name 6
0
"dataSSB"
Name 6
2
"dataSSB"
MemberName 6
0
(dataSSB) 0 "f"
MemberName 6
2
(dataSSB) 0 "f"
MemberName 6
0
(dataSSB) 1 "n_frames_rendered"
MemberName 6
2
(dataSSB) 1 "n_frames_rendered"
Name 6
2
"result"
Name 6
4
"result"
Name 7
0
"arrX"
Name 7
1
"arrX"
Name 7
1
"arrY"
Name 7
2
"arrY"
Name 7
2
"arrZ"
Name 7
3
"arrZ"
Decorate 20(counter) Offset 0
Decorate 20(counter) Offset 0
Decorate 20(counter) Binding 0
Decorate 20(counter) Binding 0
Decorate 27(countArr) Offset 4
Decorate 27(countArr) Offset 4
Decorate 27(countArr) Binding 0
Decorate 27(countArr) Binding 0
MemberDecorate 6
0
(dataSSB) 0 Restrict
MemberDecorate 6
2
(dataSSB) 0 Restrict
MemberDecorate 6
0
(dataSSB) 0 Offset 0
MemberDecorate 6
2
(dataSSB) 0 Offset 0
MemberDecorate 6
0
(dataSSB) 1 Restrict
MemberDecorate 6
2
(dataSSB) 1 Restrict
MemberDecorate 6
0
(dataSSB) 1 Offset 16
MemberDecorate 6
2
(dataSSB) 1 Offset 16
Decorate 6
0
(dataSSB) BufferBlock
Decorate 6
2
(dataSSB) BufferBlock
Decorate 6
2
(result) DescriptorSet 0
Decorate 6
4
(result) DescriptorSet 0
Decorate 6
2
(result) Binding 0
Decorate 6
4
(result) Binding 0
2: TypeVoid
2: TypeVoid
3: TypeFunction 2
3: TypeFunction 2
6: TypeInt 32 0
6: TypeInt 32 0
...
@@ -56,29 +56,29 @@ spv.atomic.comp
...
@@ -56,29 +56,29 @@ spv.atomic.comp
27(countArr): 26(ptr) Variable AtomicCounter
27(countArr): 26(ptr) Variable AtomicCounter
28: TypeInt 32 1
28: TypeInt 32 1
29: 28(int) Constant 2
29: 28(int) Constant 2
3
4: TypePointer Function 28(int)
3
3: 28(int) Constant 1
36: TypePointer
Workgroup
28(int)
36: TypePointer
Function
28(int)
37(atomi): 36(ptr) Variable Workgroup
38: TypePointer Workgroup 28(int)
38: 28(int) Constant 3
39(atomi): 38(ptr) Variable Workgroup
4
1: TypePointer Workgroup 6(int)
4
0: 28(int) Constant 3
42(atomu): 41(ptr) Variable Workgroup
43: TypePointer Workgroup 6(int)
4
3(value): 41
(ptr) Variable Workgroup
4
4(atomu): 43
(ptr) Variable Workgroup
46: 6(int) Constant 7
45(value): 43(ptr) Variable Workgroup
51: 28
(int) Constant 7
48: 6
(int) Constant 7
5
5: 6(int) Constant 10
5
3: 28(int) Constant 7
5
8: TypeFloat 32
5
7: 6(int) Constant 10
59: TypeVector 28(int) 4
60: TypeFloat 32
60(dataSSB): TypeStruct 58(float) 59(ivec4)
61: TypeVector 28(int) 4
61: TypePointer Uniform 60(dataSSB
)
62(dataSSB): TypeStruct 60(float) 61(ivec4
)
62(result): 61(ptr) Variable Uniform
63: TypePointer Uniform 62(dataSSB)
63: 28(int) Constant 1
64(result): 63(ptr) Variable Uniform
6
4
: 6(int) Constant 2
6
5
: 6(int) Constant 2
6
5
: TypePointer Uniform 28(int)
6
6
: TypePointer Uniform 28(int)
6
8
: TypeArray 28(int) 14
6
9
: TypeArray 28(int) 14
69: TypePointer Private 68
70: TypePointer Private 69
7
0(arrX): 69
(ptr) Variable Private
7
1(arrX): 70
(ptr) Variable Private
7
1(arrY): 69
(ptr) Variable Private
7
2(arrY): 70
(ptr) Variable Private
7
2(arrZ): 69
(ptr) Variable Private
7
3(arrZ): 70
(ptr) Variable Private
4(main): 2 Function None 3
4(main): 2 Function None 3
5: Label
5: Label
23(val): 22(ptr) Variable Function
23(val): 22(ptr) Variable Function
...
@@ -88,7 +88,8 @@ spv.atomic.comp
...
@@ -88,7 +88,8 @@ spv.atomic.comp
31: 6(int) AtomicLoad 30 14 15
31: 6(int) AtomicLoad 30 14 15
Store 23(val) 31
Store 23(val) 31
32: 6(int) AtomicIDecrement 20(counter) 14 15
32: 6(int) AtomicIDecrement 20(counter) 14 15
33: 6(int) AtomicIIncrement 20(counter) 14 15
34: 6(int) ISub 32 33
35: 6(int) AtomicIIncrement 20(counter) 14 15
Return
Return
FunctionEnd
FunctionEnd
10(func(au1;): 6(int) Function None 8
10(func(au1;): 6(int) Function None 8
...
@@ -99,29 +100,29 @@ spv.atomic.comp
...
@@ -99,29 +100,29 @@ spv.atomic.comp
FunctionEnd
FunctionEnd
12(atoms(): 2 Function None 3
12(atoms(): 2 Function None 3
13: Label
13: Label
3
5(origi): 34
(ptr) Variable Function
3
7(origi): 36
(ptr) Variable Function
4
0
(origu): 22(ptr) Variable Function
4
2
(origu): 22(ptr) Variable Function
39: 28(int) AtomicIAdd 37(atomi) 14 15 38
41: 28(int) AtomicIAdd 39(atomi) 14 15 40
Store 3
5(origi) 39
Store 3
7(origi) 41
4
4: 6(int) Load 43
(value)
4
6: 6(int) Load 45
(value)
4
5: 6(int) AtomicAnd 42(atomu) 14 15 44
4
7: 6(int) AtomicAnd 44(atomu) 14 15 46
Store 4
0(origu) 45
Store 4
2(origu) 47
4
7: 6(int) AtomicOr 42(atomu) 14 15 46
4
9: 6(int) AtomicOr 44(atomu) 14 15 48
Store 4
0(origu) 47
Store 4
2(origu) 49
48: 6(int) AtomicXor 42(atomu) 14 15 46
50: 6(int) AtomicXor 44(atomu) 14 15 48
Store 4
0(origu) 48
Store 4
2(origu) 50
49: 6(int) Load 43
(value)
51: 6(int) Load 45
(value)
5
0: 6(int) AtomicUMin 42(atomu) 14 15 49
5
2: 6(int) AtomicUMin 44(atomu) 14 15 51
Store 4
0(origu) 50
Store 4
2(origu) 52
5
2: 28(int) AtomicSMax 37(atomi) 14 15 51
5
4: 28(int) AtomicSMax 39(atomi) 14 15 53
Store 3
5(origi) 52
Store 3
7(origi) 54
5
3: 28(int) Load 35
(origi)
5
5: 28(int) Load 37
(origi)
5
4: 28(int) AtomicExchange 37(atomi) 14 15 53
5
6: 28(int) AtomicExchange 39(atomi) 14 15 55
Store 3
5(origi) 54
Store 3
7(origi) 56
5
6: 6(int) Load 43
(value)
5
8: 6(int) Load 45
(value)
5
7: 6(int) AtomicCompareExchange 42(atomu) 14 15 15 56 55
5
9: 6(int) AtomicCompareExchange 44(atomu) 14 15 15 58 57
Store 4
0(origu) 57
Store 4
2(origu) 59
6
6: 65(ptr) AccessChain 62(result) 63 64
6
7: 66(ptr) AccessChain 64(result) 33 65
6
7: 28(int) AtomicIAdd 66 14 15 6
3
6
8: 28(int) AtomicIAdd 67 14 15 3
3
Return
Return
FunctionEnd
FunctionEnd
glslang/Include/intermediate.h
View file @
48d6e798
...
@@ -417,8 +417,8 @@ enum TOperator {
...
@@ -417,8 +417,8 @@ enum TOperator {
EOpAtomicExchange
,
EOpAtomicExchange
,
EOpAtomicCompSwap
,
EOpAtomicCompSwap
,
EOpAtomicCounterIncrement
,
EOpAtomicCounterIncrement
,
// results in pre-increment value
EOpAtomicCounterDecrement
,
EOpAtomicCounterDecrement
,
// results in post-decrement value
EOpAtomicCounter
,
EOpAtomicCounter
,
EOpAtomicCounterAdd
,
EOpAtomicCounterAdd
,
EOpAtomicCounterSubtract
,
EOpAtomicCounterSubtract
,
...
...
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