Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Martin Beľa
naga
Commits
ab73ee5d
Commit
ab73ee5d
authored
Jan 01, 2022
by
Martin Beľa
Browse files
Improve SPIRV to WGSL translation
parent
4cb91f2c
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/back/wgsl/writer.rs
View file @
ab73ee5d
use
std
::
env
::
var
;
use
super
::
Error
;
use
crate
::{
back
,
proc
::{
self
,
NameKey
},
valid
,
Handle
,
Module
,
ShaderStage
,
TypeInner
,
};
use
crate
::{
back
,
proc
::{
self
,
NameKey
},
valid
,
Handle
,
Module
,
ShaderStage
,
TypeInner
,
ResourceBinding
,
GlobalVariable
};
use
std
::
fmt
::
Write
;
/// Shorthand result used internally by the backend
...
...
@@ -1672,11 +1669,28 @@ impl<W: Write> Writer<W> {
handle
:
Handle
<
crate
::
GlobalVariable
>
,
)
->
BackendResult
{
let
name
=
self
.names
[
&
NameKey
::
GlobalVariable
(
handle
)]
.clone
();
let
(
storage
,
maybe_access
)
=
storage_class_str
(
global
.class
);
// Write group and dinding attributes if present
if
let
Some
(
ref
binding
)
=
global
.binding
{
let
maybe_binding
=
if
global
.binding
.is_some
()
{
global
.binding
.clone
()
}
else
if
global
.class
==
crate
::
StorageClass
::
PushConstant
{
let
mut
max_group
=
0
;
for
(
_
,
variable
)
in
module
.global_variables
.iter
(){
if
let
Some
(
binding
)
=
&
variable
.binding
{
max_group
=
std
::
cmp
::
max
(
max_group
,
binding
.group
);
}
}
Some
(
ResourceBinding
{
group
:
max_group
+
1
,
binding
:
0
})
}
else
{
None
};
if
let
Some
(
binding
)
=
maybe_binding
{
self
.write_attributes
(
&
[
Attribute
::
Group
(
binding
.group
),
Attribute
::
Group
(
binding
.group
+
1
),
Attribute
::
Binding
(
binding
.binding
),
],
false
,
...
...
@@ -1686,7 +1700,6 @@ impl<W: Write> Writer<W> {
// First write global name and storage class if supported
write!
(
self
.out
,
"var"
)
?
;
let
(
storage
,
maybe_access
)
=
storage_class_str
(
global
.class
);
if
let
Some
(
class
)
=
storage
{
write!
(
self
.out
,
"<{}"
,
class
)
?
;
if
let
Some
(
access
)
=
maybe_access
{
...
...
@@ -1960,7 +1973,7 @@ fn storage_class_str(
"storage"
}
}
Sc
::
PushConstant
=>
"
push_constant
"
,
Sc
::
PushConstant
=>
"
uniform
"
,
Sc
::
WorkGroup
=>
"workgroup"
,
Sc
::
Handle
=>
return
(
None
,
None
),
Sc
::
Function
=>
"function"
,
...
...
src/front/spv/mod.rs
View file @
ab73ee5d
...
...
@@ -1759,6 +1759,46 @@ impl<I: Iterator<Item = u32>> Parser<I> {
);
emitter
.start
(
ctx
.expressions
);
}
Op
::
AtomicIAdd
=>
{
inst
.expect
(
7
)
?
;
let
start
=
self
.data_offset
;
let
result_type_id
=
self
.next
()
?
;
let
result_id
=
self
.next
()
?
;
let
pointer_id
=
self
.next
()
?
;
let
scope_memory_id
=
self
.next
()
?
;
let
memory_semantics_id
=
self
.next
()
?
;
let
value_id
=
self
.next
()
?
;
let
base_expr
=
self
.lookup_expression
.lookup
(
pointer_id
)
?
;
let
base_handle
=
get_expr_handle!
(
pointer_id
,
base_expr
);
let
value_expr
=
self
.lookup_expression
.lookup
(
value_id
)
?
;
let
value_handle
=
get_expr_handle!
(
value_id
,
value_expr
);
let
expr
=
crate
::
Expression
::
AtomicResult
{
kind
:
crate
::
ScalarKind
::
Sint
,
width
:
4
,
comparison
:
false
,
};
let
expr_handle
=
ctx
.expressions
.append
(
expr
,
self
.span_from_with_op
(
start
));
self
.lookup_expression
.insert
(
result_id
,
LookupExpression
{
handle
:
expr_handle
,
type_id
:
result_type_id
,
block_id
,
},
);
block
.push
(
crate
::
Statement
::
Atomic
{
pointer
:
base_handle
,
fun
:
crate
::
AtomicFunction
::
Add
,
value
:
value_handle
,
result
:
expr_handle
,
},
span
,
);
}
// Arithmetic Instructions +, -, *, /, %
Op
::
SNegate
|
Op
::
FNegate
=>
{
inst
.expect
(
4
)
?
;
...
...
src/proc/namer.rs
View file @
ab73ee5d
...
...
@@ -53,6 +53,10 @@ impl Namer {
}
}
if
base
.starts_with
(
"_"
){
return
format!
(
"var_{}"
,
base
);
}
base
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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