mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Co-authored-by: Jim Blandy <jimb@red-bean.com> Fixes #4581.
This commit is contained in:
parent
e16f7b4083
commit
a3b6900d4d
@ -40,6 +40,13 @@ Bottom level categories:
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## v0.18.2 (2023-XX-XX)
|
||||||
|
|
||||||
|
(naga version 0.14.2)
|
||||||
|
|
||||||
|
#### Naga
|
||||||
|
- When evaluating const-expressions and generating SPIR-V, properly handle `Compose` expressions whose operands are `Splat` expressions. Such expressions are created and marked as constant by the constant evaluator. By @jimblandy in [#4695](https://github.com/gfx-rs/wgpu/pull/4695).
|
||||||
|
|
||||||
## v0.18.1 (2023-11-15)
|
## v0.18.1 (2023-11-15)
|
||||||
|
|
||||||
(naga version 0.14.1)
|
(naga version 0.14.1)
|
||||||
|
@ -661,17 +661,19 @@ pub fn flatten_compose<'arenas>(
|
|||||||
expressions: &'arenas crate::Arena<crate::Expression>,
|
expressions: &'arenas crate::Arena<crate::Expression>,
|
||||||
types: &'arenas crate::UniqueArena<crate::Type>,
|
types: &'arenas crate::UniqueArena<crate::Type>,
|
||||||
) -> impl Iterator<Item = crate::Handle<crate::Expression>> + 'arenas {
|
) -> impl Iterator<Item = crate::Handle<crate::Expression>> + 'arenas {
|
||||||
// Returning `impl Iterator` is a bit tricky. We may or may not want to
|
// Returning `impl Iterator` is a bit tricky. We may or may not
|
||||||
// flatten the components, but we have to settle on a single concrete
|
// want to flatten the components, but we have to settle on a
|
||||||
// type to return. The below is a single iterator chain that handles
|
// single concrete type to return. This function returns a single
|
||||||
// both the flattening and non-flattening cases.
|
// iterator chain that handles both the flattening and
|
||||||
|
// non-flattening cases.
|
||||||
let (size, is_vector) = if let crate::TypeInner::Vector { size, .. } = types[ty].inner {
|
let (size, is_vector) = if let crate::TypeInner::Vector { size, .. } = types[ty].inner {
|
||||||
(size as usize, true)
|
(size as usize, true)
|
||||||
} else {
|
} else {
|
||||||
(components.len(), false)
|
(components.len(), false)
|
||||||
};
|
};
|
||||||
|
|
||||||
fn flattener<'c>(
|
/// Flatten `Compose` expressions if `is_vector` is true.
|
||||||
|
fn flatten_compose<'c>(
|
||||||
component: &'c crate::Handle<crate::Expression>,
|
component: &'c crate::Handle<crate::Expression>,
|
||||||
is_vector: bool,
|
is_vector: bool,
|
||||||
expressions: &'c crate::Arena<crate::Expression>,
|
expressions: &'c crate::Arena<crate::Expression>,
|
||||||
@ -688,14 +690,35 @@ pub fn flatten_compose<'arenas>(
|
|||||||
std::slice::from_ref(component)
|
std::slice::from_ref(component)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expressions like `vec4(vec3(vec2(6, 7), 8), 9)` require us to flatten
|
/// Flatten `Splat` expressions if `is_vector` is true.
|
||||||
// two levels.
|
fn flatten_splat<'c>(
|
||||||
|
component: &'c crate::Handle<crate::Expression>,
|
||||||
|
is_vector: bool,
|
||||||
|
expressions: &'c crate::Arena<crate::Expression>,
|
||||||
|
) -> impl Iterator<Item = crate::Handle<crate::Expression>> {
|
||||||
|
let mut expr = *component;
|
||||||
|
let mut count = 1;
|
||||||
|
if is_vector {
|
||||||
|
if let crate::Expression::Splat { size, value } = expressions[expr] {
|
||||||
|
expr = value;
|
||||||
|
count = size as usize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::iter::repeat(expr).take(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expressions like `vec4(vec3(vec2(6, 7), 8), 9)` require us to
|
||||||
|
// flatten up to two levels of `Compose` expressions.
|
||||||
|
//
|
||||||
|
// Expressions like `vec4(vec3(1.0), 1.0)` require us to flatten
|
||||||
|
// `Splat` expressions. Fortunately, the operand of a `Splat` must
|
||||||
|
// be a scalar, so we can stop there.
|
||||||
components
|
components
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(move |component| flattener(component, is_vector, expressions))
|
.flat_map(move |component| flatten_compose(component, is_vector, expressions))
|
||||||
.flat_map(move |component| flattener(component, is_vector, expressions))
|
.flat_map(move |component| flatten_compose(component, is_vector, expressions))
|
||||||
|
.flat_map(move |component| flatten_splat(component, is_vector, expressions))
|
||||||
.take(size)
|
.take(size)
|
||||||
.cloned()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -9,6 +9,7 @@ fn main() {
|
|||||||
non_constant_initializers();
|
non_constant_initializers();
|
||||||
splat_of_constant();
|
splat_of_constant();
|
||||||
compose_of_constant();
|
compose_of_constant();
|
||||||
|
compose_of_splat();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swizzle the value of nested Compose expressions.
|
// Swizzle the value of nested Compose expressions.
|
||||||
@ -79,3 +80,7 @@ fn map_texture_kind(texture_kind: i32) -> u32 {
|
|||||||
default: { return 0u; }
|
default: { return 0u; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compose_of_splat() {
|
||||||
|
var x = vec4f(vec3f(1.0), 2.0).wzyx;
|
||||||
|
}
|
||||||
|
@ -57,6 +57,10 @@ void compose_of_constant() {
|
|||||||
ivec4 out_5 = ivec4(-4, -4, -4, -4);
|
ivec4 out_5 = ivec4(-4, -4, -4, -4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void compose_of_splat() {
|
||||||
|
vec4 x_1 = vec4(2.0, 1.0, 1.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
uint map_texture_kind(int texture_kind) {
|
uint map_texture_kind(int texture_kind) {
|
||||||
switch(texture_kind) {
|
switch(texture_kind) {
|
||||||
case 0: {
|
case 0: {
|
||||||
@ -81,6 +85,7 @@ void main() {
|
|||||||
non_constant_initializers();
|
non_constant_initializers();
|
||||||
splat_of_constant();
|
splat_of_constant();
|
||||||
compose_of_constant();
|
compose_of_constant();
|
||||||
|
compose_of_splat();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,12 @@ void compose_of_constant()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void compose_of_splat()
|
||||||
|
{
|
||||||
|
float4 x_1 = float4(2.0, 1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
uint map_texture_kind(int texture_kind)
|
uint map_texture_kind(int texture_kind)
|
||||||
{
|
{
|
||||||
switch(texture_kind) {
|
switch(texture_kind) {
|
||||||
@ -88,5 +94,6 @@ void main()
|
|||||||
non_constant_initializers();
|
non_constant_initializers();
|
||||||
splat_of_constant();
|
splat_of_constant();
|
||||||
compose_of_constant();
|
compose_of_constant();
|
||||||
|
compose_of_splat();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,11 @@ void compose_of_constant(
|
|||||||
metal::int4 out_5 = metal::int4(-4, -4, -4, -4);
|
metal::int4 out_5 = metal::int4(-4, -4, -4, -4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void compose_of_splat(
|
||||||
|
) {
|
||||||
|
metal::float4 x_1 = metal::float4(2.0, 1.0, 1.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
uint map_texture_kind(
|
uint map_texture_kind(
|
||||||
int texture_kind
|
int texture_kind
|
||||||
) {
|
) {
|
||||||
@ -88,5 +93,6 @@ kernel void main_(
|
|||||||
non_constant_initializers();
|
non_constant_initializers();
|
||||||
splat_of_constant();
|
splat_of_constant();
|
||||||
compose_of_constant();
|
compose_of_constant();
|
||||||
|
compose_of_splat();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
; SPIR-V
|
; SPIR-V
|
||||||
; Version: 1.1
|
; Version: 1.1
|
||||||
; Generator: rspirv
|
; Generator: rspirv
|
||||||
; Bound: 91
|
; Bound: 100
|
||||||
OpCapability Shader
|
OpCapability Shader
|
||||||
%1 = OpExtInstImport "GLSL.std.450"
|
%1 = OpExtInstImport "GLSL.std.450"
|
||||||
OpMemoryModel Logical GLSL450
|
OpMemoryModel Logical GLSL450
|
||||||
OpEntryPoint GLCompute %83 "main"
|
OpEntryPoint GLCompute %91 "main"
|
||||||
OpExecutionMode %83 LocalSize 2 3 1
|
OpExecutionMode %91 LocalSize 2 3 1
|
||||||
%2 = OpTypeVoid
|
%2 = OpTypeVoid
|
||||||
%3 = OpTypeInt 32 0
|
%3 = OpTypeInt 32 0
|
||||||
%4 = OpTypeInt 32 1
|
%4 = OpTypeInt 32 1
|
||||||
%5 = OpTypeVector %4 4
|
%5 = OpTypeVector %4 4
|
||||||
%6 = OpTypeFloat 32
|
%7 = OpTypeFloat 32
|
||||||
%7 = OpTypeVector %6 4
|
%6 = OpTypeVector %7 4
|
||||||
%8 = OpConstant %3 2
|
%8 = OpConstant %3 2
|
||||||
%9 = OpConstant %4 3
|
%9 = OpConstant %4 3
|
||||||
%10 = OpConstant %4 4
|
%10 = OpConstant %4 4
|
||||||
%11 = OpConstant %4 8
|
%11 = OpConstant %4 8
|
||||||
%12 = OpConstant %6 3.141
|
%12 = OpConstant %7 3.141
|
||||||
%13 = OpConstant %6 6.282
|
%13 = OpConstant %7 6.282
|
||||||
%14 = OpConstant %6 0.44444445
|
%14 = OpConstant %7 0.44444445
|
||||||
%15 = OpConstant %6 0.0
|
%15 = OpConstant %7 0.0
|
||||||
%16 = OpConstantComposite %7 %14 %15 %15 %15
|
%16 = OpConstantComposite %6 %14 %15 %15 %15
|
||||||
%17 = OpConstant %4 0
|
%17 = OpConstant %4 0
|
||||||
%18 = OpConstant %4 1
|
%18 = OpConstant %4 1
|
||||||
%19 = OpConstant %4 2
|
%19 = OpConstant %4 2
|
||||||
@ -37,12 +37,16 @@ OpExecutionMode %83 LocalSize 2 3 1
|
|||||||
%48 = OpConstantNull %5
|
%48 = OpConstantNull %5
|
||||||
%59 = OpConstant %4 -4
|
%59 = OpConstant %4 -4
|
||||||
%60 = OpConstantComposite %5 %59 %59 %59 %59
|
%60 = OpConstantComposite %5 %59 %59 %59 %59
|
||||||
%70 = OpTypeFunction %3 %4
|
%69 = OpConstant %7 1.0
|
||||||
%71 = OpConstant %3 10
|
%70 = OpConstant %7 2.0
|
||||||
%72 = OpConstant %3 20
|
%71 = OpConstantComposite %6 %70 %69 %69 %69
|
||||||
%73 = OpConstant %3 30
|
%73 = OpTypePointer Function %6
|
||||||
%74 = OpConstant %3 0
|
%78 = OpTypeFunction %3 %4
|
||||||
%81 = OpConstantNull %3
|
%79 = OpConstant %3 10
|
||||||
|
%80 = OpConstant %3 20
|
||||||
|
%81 = OpConstant %3 30
|
||||||
|
%82 = OpConstant %3 0
|
||||||
|
%89 = OpConstantNull %3
|
||||||
%21 = OpFunction %2 None %22
|
%21 = OpFunction %2 None %22
|
||||||
%20 = OpLabel
|
%20 = OpLabel
|
||||||
%24 = OpVariable %25 Function %23
|
%24 = OpVariable %25 Function %23
|
||||||
@ -99,33 +103,41 @@ OpBranch %66
|
|||||||
%66 = OpLabel
|
%66 = OpLabel
|
||||||
OpReturn
|
OpReturn
|
||||||
OpFunctionEnd
|
OpFunctionEnd
|
||||||
%69 = OpFunction %3 None %70
|
%68 = OpFunction %2 None %22
|
||||||
%68 = OpFunctionParameter %4
|
|
||||||
%67 = OpLabel
|
%67 = OpLabel
|
||||||
OpBranch %75
|
%72 = OpVariable %73 Function %71
|
||||||
%75 = OpLabel
|
OpBranch %74
|
||||||
OpSelectionMerge %76 None
|
%74 = OpLabel
|
||||||
OpSwitch %68 %80 0 %77 1 %78 2 %79
|
OpReturn
|
||||||
%77 = OpLabel
|
OpFunctionEnd
|
||||||
OpReturnValue %71
|
%77 = OpFunction %3 None %78
|
||||||
%78 = OpLabel
|
%76 = OpFunctionParameter %4
|
||||||
OpReturnValue %72
|
%75 = OpLabel
|
||||||
%79 = OpLabel
|
OpBranch %83
|
||||||
OpReturnValue %73
|
%83 = OpLabel
|
||||||
%80 = OpLabel
|
OpSelectionMerge %84 None
|
||||||
OpReturnValue %74
|
OpSwitch %76 %88 0 %85 1 %86 2 %87
|
||||||
%76 = OpLabel
|
%85 = OpLabel
|
||||||
OpReturnValue %81
|
OpReturnValue %79
|
||||||
OpFunctionEnd
|
%86 = OpLabel
|
||||||
%83 = OpFunction %2 None %22
|
OpReturnValue %80
|
||||||
%82 = OpLabel
|
%87 = OpLabel
|
||||||
OpBranch %84
|
OpReturnValue %81
|
||||||
%84 = OpLabel
|
%88 = OpLabel
|
||||||
%85 = OpFunctionCall %2 %21
|
OpReturnValue %82
|
||||||
%86 = OpFunctionCall %2 %28
|
%84 = OpLabel
|
||||||
%87 = OpFunctionCall %2 %33
|
OpReturnValue %89
|
||||||
%88 = OpFunctionCall %2 %38
|
OpFunctionEnd
|
||||||
%89 = OpFunctionCall %2 %58
|
%91 = OpFunction %2 None %22
|
||||||
%90 = OpFunctionCall %2 %64
|
%90 = OpLabel
|
||||||
|
OpBranch %92
|
||||||
|
%92 = OpLabel
|
||||||
|
%93 = OpFunctionCall %2 %21
|
||||||
|
%94 = OpFunctionCall %2 %28
|
||||||
|
%95 = OpFunctionCall %2 %33
|
||||||
|
%96 = OpFunctionCall %2 %38
|
||||||
|
%97 = OpFunctionCall %2 %58
|
||||||
|
%98 = OpFunctionCall %2 %64
|
||||||
|
%99 = OpFunctionCall %2 %68
|
||||||
OpReturn
|
OpReturn
|
||||||
OpFunctionEnd
|
OpFunctionEnd
|
@ -55,6 +55,11 @@ fn compose_of_constant() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compose_of_splat() {
|
||||||
|
var x_1: vec4<f32> = vec4<f32>(2.0, 1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fn map_texture_kind(texture_kind: i32) -> u32 {
|
fn map_texture_kind(texture_kind: i32) -> u32 {
|
||||||
switch texture_kind {
|
switch texture_kind {
|
||||||
case 0: {
|
case 0: {
|
||||||
@ -80,5 +85,6 @@ fn main() {
|
|||||||
non_constant_initializers();
|
non_constant_initializers();
|
||||||
splat_of_constant();
|
splat_of_constant();
|
||||||
compose_of_constant();
|
compose_of_constant();
|
||||||
|
compose_of_splat();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user