mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
hlsl: fix vector multiplication
This commit is contained in:
committed by
Dzmitry Malyshau
parent
c526383cf8
commit
cc91c77f7a
@@ -14,6 +14,15 @@ const LOCATION_SEMANTIC: &str = "LOC";
|
|||||||
/// Shorthand result used internally by the backend
|
/// Shorthand result used internally by the backend
|
||||||
pub(super) type BackendResult = Result<(), Error>;
|
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
|
/// Structure contains information required for generating
|
||||||
/// wrapped structure of all entry points arguments
|
/// wrapped structure of all entry points arguments
|
||||||
struct EntryPointBinding {
|
struct EntryPointBinding {
|
||||||
@@ -100,7 +109,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
|||||||
|
|
||||||
// Write all structs
|
// Write all structs
|
||||||
for (handle, ty) in module.types.iter() {
|
for (handle, ty) in module.types.iter() {
|
||||||
if let crate::TypeInner::Struct {
|
if let TypeInner::Struct {
|
||||||
top_level,
|
top_level,
|
||||||
ref members,
|
ref members,
|
||||||
..
|
..
|
||||||
@@ -500,7 +509,11 @@ impl<'a, W: Write> Writer<'a, W> {
|
|||||||
_ => unreachable!(),
|
_ => 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, "]")?;
|
write!(self.out, "]")?;
|
||||||
@@ -1088,13 +1101,17 @@ impl<'a, W: Write> Writer<'a, W> {
|
|||||||
write!(self.out, ")")?
|
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 {
|
Expression::Binary {
|
||||||
op: crate::BinaryOperator::Multiply,
|
op: crate::BinaryOperator::Multiply,
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
} if func_ctx.info[left].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) =>
|
|| func_ctx.info[right]
|
||||||
|
.ty
|
||||||
|
.inner_with(&module.types)
|
||||||
|
.is_matrix() =>
|
||||||
{
|
{
|
||||||
write!(self.out, "mul(")?;
|
write!(self.out, "mul(")?;
|
||||||
self.write_expr(module, left, func_ctx)?;
|
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
|
// 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) {
|
let ms = match *func_ctx.info[image].ty.inner_with(&module.types) {
|
||||||
crate::TypeInner::Image {
|
TypeInner::Image {
|
||||||
class: crate::ImageClass::Sampled { multi, .. },
|
class: crate::ImageClass::Sampled { multi, .. },
|
||||||
..
|
..
|
||||||
}
|
}
|
||||||
| crate::TypeInner::Image {
|
| TypeInner::Image {
|
||||||
class: crate::ImageClass::Depth { multi },
|
class: crate::ImageClass::Depth { multi },
|
||||||
..
|
..
|
||||||
} => multi,
|
} => multi,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ struct FragmentInput_main {
|
|||||||
|
|
||||||
VertexOutput main(VertexInput_main vertexinput_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;
|
return vertexoutput1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ float4 main1(FragmentInput_main fragmentinput_main) : SV_Target0
|
|||||||
if ((color.w == 0.0)) {
|
if ((color.w == 0.0)) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
float4 premultiplied = mul(color.w, color);
|
float4 premultiplied = (color.w * color);
|
||||||
return premultiplied;
|
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));
|
float3 light_dir = normalize((light.pos.xyz - fragmentinput_fs_main.position1.xyz));
|
||||||
float diffuse = max(0.0, dot(normal, light_dir));
|
float diffuse = max(0.0, dot(normal, light_dir));
|
||||||
float3 _expr34 = color;
|
float3 _expr34 = color;
|
||||||
color = (_expr34 + mul((_e25 * diffuse), light.color.xyz));
|
color = (_expr34 + ((_e25 * diffuse) * light.color.xyz));
|
||||||
uint _expr40 = i;
|
uint _expr40 = i;
|
||||||
i = (_expr40 + 1u);
|
i = (_expr40 + 1u);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user