mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
hlsl: remove the boolean casts for unary operators
This commit is contained in:
committed by
Dzmitry Malyshau
parent
cc91c77f7a
commit
bbfa9a0f9e
@@ -100,6 +100,9 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
}
|
||||
|
||||
// Extra newline for readability
|
||||
writeln!(self.out)?;
|
||||
|
||||
// Save all entry point output types
|
||||
let ep_results = module
|
||||
.entry_points
|
||||
@@ -487,8 +490,6 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
}
|
||||
writeln!(self.out, ";")?;
|
||||
// End with extra newline for readability
|
||||
writeln!(self.out)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1352,32 +1353,12 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
Expression::Unary { op, expr } => {
|
||||
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-operators#unary-operators
|
||||
let convert_to_bool = if let TypeInner::Scalar {
|
||||
kind: crate::ScalarKind::Bool,
|
||||
..
|
||||
} = *func_ctx.info[expr].ty.inner_with(&module.types)
|
||||
{
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
let op_str = match op {
|
||||
crate::UnaryOperator::Negate => "-",
|
||||
crate::UnaryOperator::Not => "!",
|
||||
};
|
||||
write!(self.out, "({}", op_str)?;
|
||||
|
||||
if convert_to_bool {
|
||||
write!(self.out, "bool(")?;
|
||||
}
|
||||
|
||||
write!(self.out, "{}", op_str)?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
|
||||
if convert_to_bool {
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
Expression::As { expr, kind, .. } => {
|
||||
let inner = func_ctx.info[expr].ty.inner_with(&module.types);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
struct ComputeInput_main {
|
||||
uint3 global_id1 : SV_DispatchThreadID;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void main()
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
Texture2D<uint4> image_mipmapped_src : register(t0);
|
||||
Texture2DMS<uint4> image_multisampled_src : register(t3);
|
||||
Texture2DMS<float> image_depth_multisampled_src : register(t4);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
struct VertexOutput {
|
||||
float4 position : SV_Position;
|
||||
linear float varying : LOC1;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
struct FragmentInput {
|
||||
float4 position : SV_Position;
|
||||
nointerpolation uint flat : LOC0;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
float4 splat()
|
||||
{
|
||||
float2 a = (((float2(1.0.xx) + float2(2.0.xx)) - float2(3.0.xx)) / float2(4.0.xx));
|
||||
@@ -7,10 +8,10 @@ float4 splat()
|
||||
|
||||
int unary()
|
||||
{
|
||||
if ((!true)) {
|
||||
if (!true) {
|
||||
return 1;
|
||||
} else {
|
||||
return (!bool(1));
|
||||
return !1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
struct gl_PerVertex {
|
||||
float4 gl_Position : SV_Position;
|
||||
float gl_PointSize : PSIZE;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
static const float3 c_ambient = float3(0.05, 0.05, 0.05);
|
||||
|
||||
static const uint c_max_lights = 10;
|
||||
|
||||
struct Globals {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
struct VertexOutput {
|
||||
float4 position : SV_Position;
|
||||
linear float3 uv : LOC0;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
struct FragmentInput_derivatives {
|
||||
float4 foo1 : SV_Position;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user