WGSL: Flip true/false arguments of select()

This commit is contained in:
Dzmitry Malyshau authored and Dzmitry Malyshau committed 2021-07-16 11:42:12 -04:00
1 parent 10a3a6a827
commit 8eef784416
14 files changed
+32 -23

No files matched your search

+4
View File
@@ -1,5 +1,9 @@
# Change Log
## TBD
- API:
- WGSL `select()` order of true/false is swapped
## v0.5 (2021-06-18)
- development release for wgpu-0.9
- API:
+2 -2
View File
@@ -1245,10 +1245,10 @@ impl<W: Write> Writer<W> {
reject,
} => {
write!(self.out, "select(")?;
self.write_expr(module, accept, func_ctx)?;
write!(self.out, ", ")?;
self.write_expr(module, reject, func_ctx)?;
write!(self.out, ", ")?;
self.write_expr(module, accept, func_ctx)?;
write!(self.out, ", ")?;
self.write_expr(module, condition, func_ctx)?;
write!(self.out, ")")?
}
+4 -1
View File
@@ -96,7 +96,10 @@ pub struct Program<'a> {
}
impl<'a> Program<'a> {
pub fn new(entry_points: &'a FastHashMap<String, ShaderStage>, strip_unused_linkages: bool) -> Program<'a> {
pub fn new(
entry_points: &'a FastHashMap<String, ShaderStage>,
strip_unused_linkages: bool,
) -> Program<'a> {
Program {
version: 0,
profile: Profile::Core,
+4 -2
View File
@@ -1159,8 +1159,10 @@ impl Program<'_> {
let mut expressions = Arena::new();
let mut body = Vec::new();
let can_strip_stage_inputs = self.strip_unused_linkages || stage != ShaderStage::Fragment;
let can_strip_stage_outputs = self.strip_unused_linkages || stage != ShaderStage::Vertex;
let can_strip_stage_inputs =
self.strip_unused_linkages || stage != ShaderStage::Fragment;
let can_strip_stage_outputs =
self.strip_unused_linkages || stage != ShaderStage::Vertex;
for (i, arg) in self.entry_args.iter().enumerate() {
if arg.storage != StorageQualifier::Input {
+2 -2
View File
@@ -1112,10 +1112,10 @@ impl Parser {
}
} else if name == "select" {
lexer.open_arguments()?;
let accept = self.parse_general_expression(lexer, ctx.reborrow())?;
lexer.expect(Token::Separator(','))?;
let reject = self.parse_general_expression(lexer, ctx.reborrow())?;
lexer.expect(Token::Separator(','))?;
let accept = self.parse_general_expression(lexer, ctx.reborrow())?;
lexer.expect(Token::Separator(','))?;
let condition = self.parse_general_expression(lexer, ctx.reborrow())?;
lexer.close_arguments()?;
crate::Expression::Select {
+2 -2
View File
@@ -22,8 +22,8 @@ int unary() {
vec4 selection() {
vec4 vector1_ = vec4(1.0);
vec4 vector2_ = vec4(1.0);
int a = (true ? 0 : 1);
return (true ? vector1_ : vector2_);
int a = (true ? 1 : 0);
return (true ? vector2_ : vector1_);
}
void main() {
+1 -1
View File
@@ -39,7 +39,7 @@ VertexOutput vertex(VertexInput_vertex vertexinput_vertex)
FragmentOutput fragment(FragmentInput_fragment fragmentinput_fragment)
{
uint mask = (fragmentinput_fragment.sample_mask1 & (1u << fragmentinput_fragment.sample_index1));
float color2 = (fragmentinput_fragment.front_facing1 ? 0.0 : 1.0);
float color2 = (fragmentinput_fragment.front_facing1 ? 1.0 : 0.0);
const FragmentOutput fragmentoutput1 = { fragmentinput_fragment.in2.varying, mask, color2 };
return fragmentoutput1;
}
+2 -2
View File
@@ -18,8 +18,8 @@ float4 selection()
{
float4 vector1_ = float4(1.0.xxxx);
float4 vector2_ = float4(1.0.xxxx);
int a = (true ? 0 : 1);
return (true ? vector1_ : vector2_);
int a = (true ? 1 : 0);
return (true ? vector2_ : vector1_);
}
[numthreads(1, 1, 1)]
+1 -1
View File
@@ -47,7 +47,7 @@ fragment fragment1Output fragment1(
) {
const VertexOutput in = { position, varyings1.varying };
metal::uint mask = sample_mask & (1u << sample_index);
float color1 = front_facing ? 0.0 : 1.0;
float color1 = front_facing ? 1.0 : 0.0;
const auto _tmp = FragmentOutput {in.varying, mask, color1};
return fragment1Output { _tmp.depth, _tmp.sample_mask, _tmp.color };
}
+2 -2
View File
@@ -22,8 +22,8 @@ metal::float4 selection(
) {
metal::float4 vector1_ = metal::float4(1.0);
metal::float4 vector2_ = metal::float4(1.0);
int a = true ? 0 : 1;
return true ? vector1_ : vector2_;
int a = true ? 1 : 0;
return true ? vector2_ : vector1_;
}
kernel void main1(
+1 -1
View File
@@ -101,7 +101,7 @@ OpBranch %55
%55 = OpLabel
%56 = OpShiftLeftLogical %6 %5 %47
%57 = OpBitwiseAnd %6 %49 %56
%58 = OpSelect %4 %45 %7 %3
%58 = OpSelect %4 %45 %3 %7
%59 = OpCompositeExtract %4 %36 1
%60 = OpCompositeConstruct %10 %59 %57 %58
%61 = OpCompositeExtract %4 %60 0
+2 -2
View File
@@ -68,9 +68,9 @@ OpBranch %47
%47 = OpLabel
%48 = OpCompositeConstruct %15 %3 %3 %3 %3
%49 = OpCompositeConstruct %15 %3 %3 %3 %3
%50 = OpSelect %9 %12 %14 %11
%50 = OpSelect %9 %12 %11 %14
%53 = OpCompositeConstruct %52 %12 %12 %12 %12
%51 = OpSelect %15 %53 %48 %49
%51 = OpSelect %15 %53 %49 %48
OpReturnValue %51
OpFunctionEnd
%55 = OpFunction %2 None %56
+3 -3
View File
@@ -695,15 +695,15 @@ fn main1() {
let _e78: bool = gl_FrontFacing;
let _e79: vec3<f32> = N2;
let _e80: vec3<f32> = N2;
N2 = select(_e79, -(_e80), _e78);
N2 = select(-(_e80), _e79, _e78);
let _e83: bool = gl_FrontFacing;
let _e84: vec3<f32> = T;
let _e85: vec3<f32> = T;
T = select(_e84, -(_e85), _e83);
T = select(-(_e85), _e84, _e83);
let _e88: bool = gl_FrontFacing;
let _e89: vec3<f32> = B;
let _e90: vec3<f32> = B;
B = select(_e89, -(_e90), _e88);
B = select(-(_e90), _e89, _e88);
let _e93: vec3<f32> = T;
let _e94: vec3<f32> = B;
let _e95: vec3<f32> = N2;
+2 -2
View File
@@ -12,7 +12,7 @@ fn TevPerCompGT(a: f32, b: f32) -> f32 {
b1 = b;
let _e5: f32 = a1;
let _e6: f32 = b1;
return select(1.0, 0.0, (_e5 > _e6));
return select(0.0, 1.0, (_e5 > _e6));
}
fn TevPerCompGT1(a2: vec3<f32>, b2: vec3<f32>) -> vec3<f32> {
@@ -23,7 +23,7 @@ fn TevPerCompGT1(a2: vec3<f32>, b2: vec3<f32>) -> vec3<f32> {
b3 = b2;
let _e5: vec3<f32> = a3;
let _e6: vec3<f32> = b3;
return select(vec3<f32>(1.0), vec3<f32>(0.0), (_e5 > _e6));
return select(vec3<f32>(0.0), vec3<f32>(1.0), (_e5 > _e6));
}
fn main1() {