mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 14:55:05 +00:00
hlsl: fix vector multiplication
This commit is contained in:
parent
c526383cf8
commit
cc91c77f7a
@ -14,6 +14,15 @@ const LOCATION_SEMANTIC: &str = "LOC";
|
||||
/// Shorthand result used internally by the backend
|
||||
pub(super) type BackendResult = Result<(), Error>;
|
||||
|
||||
impl TypeInner {
|
||||
fn is_matrix(&self) -> bool {
|
||||
match *self {
|
||||
Self::Matrix { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Structure contains information required for generating
|
||||
/// wrapped structure of all entry points arguments
|
||||
struct EntryPointBinding {
|
||||
@ -100,7 +109,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
|
||||
// Write all structs
|
||||
for (handle, ty) in module.types.iter() {
|
||||
if let crate::TypeInner::Struct {
|
||||
if let TypeInner::Struct {
|
||||
top_level,
|
||||
ref members,
|
||||
..
|
||||
@ -500,7 +509,11 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
crate::ArraySize::Dynamic => write!(self.out, "1")?,
|
||||
crate::ArraySize::Dynamic => {
|
||||
//TODO: https://github.com/gfx-rs/naga/issues/1127
|
||||
log::warn!("Dynamically sized arrays are not properly supported yet");
|
||||
write!(self.out, "1")?
|
||||
}
|
||||
}
|
||||
|
||||
write!(self.out, "]")?;
|
||||
@ -1088,13 +1101,17 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
}
|
||||
// Matrix * Vector has to be written as `mul(Matrix, Vector)`
|
||||
// All of the multiplication can be expressed as `mul`,
|
||||
// except vector * vector, which needs to use the "*" operator.
|
||||
Expression::Binary {
|
||||
op: crate::BinaryOperator::Multiply,
|
||||
left,
|
||||
right,
|
||||
} if func_ctx.info[left].ty.inner_with(&module.types)
|
||||
!= func_ctx.info[right].ty.inner_with(&module.types) =>
|
||||
} if func_ctx.info[left].ty.inner_with(&module.types).is_matrix()
|
||||
|| func_ctx.info[right]
|
||||
.ty
|
||||
.inner_with(&module.types)
|
||||
.is_matrix() =>
|
||||
{
|
||||
write!(self.out, "mul(")?;
|
||||
self.write_expr(module, left, func_ctx)?;
|
||||
@ -1267,11 +1284,11 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
} => {
|
||||
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-load
|
||||
let ms = match *func_ctx.info[image].ty.inner_with(&module.types) {
|
||||
crate::TypeInner::Image {
|
||||
TypeInner::Image {
|
||||
class: crate::ImageClass::Sampled { multi, .. },
|
||||
..
|
||||
}
|
||||
| crate::TypeInner::Image {
|
||||
| TypeInner::Image {
|
||||
class: crate::ImageClass::Depth { multi },
|
||||
..
|
||||
} => multi,
|
||||
|
@ -19,7 +19,7 @@ struct FragmentInput_main {
|
||||
|
||||
VertexOutput main(VertexInput_main vertexinput_main)
|
||||
{
|
||||
const VertexOutput vertexoutput1 = { vertexinput_main.uv2, float4(mul(c_scale, vertexinput_main.pos1), 0.0, 1.0) };
|
||||
const VertexOutput vertexoutput1 = { vertexinput_main.uv2, float4((c_scale * vertexinput_main.pos1), 0.0, 1.0) };
|
||||
return vertexoutput1;
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ float4 main1(FragmentInput_main fragmentinput_main) : SV_Target0
|
||||
if ((color.w == 0.0)) {
|
||||
discard;
|
||||
}
|
||||
float4 premultiplied = mul(color.w, color);
|
||||
float4 premultiplied = (color.w * color);
|
||||
return premultiplied;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
|
||||
float3 light_dir = normalize((light.pos.xyz - fragmentinput_fs_main.position1.xyz));
|
||||
float diffuse = max(0.0, dot(normal, light_dir));
|
||||
float3 _expr34 = color;
|
||||
color = (_expr34 + mul((_e25 * diffuse), light.color.xyz));
|
||||
color = (_expr34 + ((_e25 * diffuse) * light.color.xyz));
|
||||
uint _expr40 = i;
|
||||
i = (_expr40 + 1u);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user