Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[glsl-in] Switch implicit type conversion #2273

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/front/glsl/parser/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,14 @@ impl<'source> ParsingContext<'source> {

self.expect(frontend, TokenValue::LeftParen)?;

let selector = {
let (selector, uint) = {
let mut stmt = ctx.stmt_ctx();
let expr = self.parse_expression(frontend, ctx, &mut stmt, body)?;
ctx.lower_expect(stmt, frontend, expr, ExprPos::Rhs, body)?
.0
let (root, meta) =
ctx.lower_expect(stmt, frontend, expr, ExprPos::Rhs, body)?;
let uint = frontend.resolve_type(ctx, root, meta)?.scalar_kind()
== Some(crate::ScalarKind::Uint);
(root, uint)
};

self.expect(frontend, TokenValue::RightParen)?;
Expand All @@ -197,7 +200,10 @@ impl<'source> ParsingContext<'source> {
ConstantInner::Scalar {
value: ScalarValue::Sint(int),
..
} => crate::SwitchValue::I32(int as i32),
} => match uint {
true => crate::SwitchValue::U32(int as u32),
false => crate::SwitchValue::I32(int as i32),
},
ConstantInner::Scalar {
value: ScalarValue::Uint(int),
..
Expand Down
9 changes: 9 additions & 0 deletions tests/in/glsl/statements.frag
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ void switchNoDefault(int a) {
return;
}

void switchCaseImplConv(uint a) {
switch (a) {
case 0:
break;
}

return;
}

void switchNoLastBreak(int a) {
switch (a) {
default:
Expand Down
22 changes: 18 additions & 4 deletions tests/out/wgsl/statements-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,29 @@ fn switchNoDefault(a_2: i32) {
return;
}

fn switchNoLastBreak(a_4: i32) {
var a_5: i32;
var b: i32;
fn switchCaseImplConv(a_4: u32) {
var a_5: u32;

a_5 = a_4;
let _e2 = a_5;
switch _e2 {
case 0u: {
}
default: {
}
}
return;
}

fn switchNoLastBreak(a_6: i32) {
var a_7: i32;
var b: i32;

a_7 = a_6;
let _e2 = a_7;
switch _e2 {
default: {
let _e3 = a_5;
let _e3 = a_7;
b = _e3;
}
}
Expand Down