mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-28 17:19:11 +01:00
fix(hlsl-out): pass 1/w in fragment @builtin(position).w (#10733)
This commit is contained in:
1 parent
dcf21900e5
commit
66d5a64f2e
17 files changed
+32
-21
No files matched your search
@@ -253,6 +253,7 @@ By @sagudev in [#10307](https://github.com/gfx-rs/wgpu/pull/10307).
|
||||
- Fix invalid GLSL for `textureLoad` with a `u32` level or sample index under the `Restrict` and `ReadZeroSkipWrite` bounds check policies. By @ilyas-mallah in [#XXXXX](https://github.com/gfx-rs/wgpu/pull/XXXXX).
|
||||
- Fix `var<immediate>` members being read from the wrong offsets on DX12 when a nested struct is not 16-byte aligned. By @DouglasDwyer in [#10581](https://github.com/gfx-rs/wgpu/pull/10581).
|
||||
- Disallow usage of `ray_query` as a binding. By @szymros in [#10832](https://github.com/gfx-rs/wgpu/pull/10832)
|
||||
- Fix `@builtin(position).w` in fragment shaders on DX12. The HLSL backend now provides 1/w of the clip-space position, as WGSL specifies and the other backends already do, instead of w. By @abdymazhit in [#10733](https://github.com/gfx-rs/wgpu/pull/10733).
|
||||
|
||||
#### Validation
|
||||
|
||||
|
||||
+1
-1
@@ -375,7 +375,7 @@ fails-if(metal) webgpu:shader,execution,robust_access_vertex:vertex_buffer_acces
|
||||
webgpu:shader,execution,shader_io,fragment_builtins:inputs,front_facing:*
|
||||
webgpu:shader,execution,shader_io,fragment_builtins:inputs,interStage,centroid:*
|
||||
fails-if(vulkan) webgpu:shader,execution,shader_io,fragment_builtins:inputs,interStage:*
|
||||
fails-if(dx12,vulkan) webgpu:shader,execution,shader_io,fragment_builtins:inputs,position:*
|
||||
fails-if(vulkan) webgpu:shader,execution,shader_io,fragment_builtins:inputs,position:*
|
||||
webgpu:shader,execution,shader_io,fragment_builtins:inputs,sample_index:*
|
||||
fails-if(dx12,vulkan) webgpu:shader,execution,shader_io,fragment_builtins:inputs,sample_mask:*
|
||||
webgpu:shader,execution,shader_io,fragment_builtins:primitive_index,*
|
||||
|
||||
@@ -1004,6 +1004,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
ep_input.local_invocation_index_name.as_ref().unwrap()
|
||||
)?;
|
||||
}
|
||||
// WGSL's fragment `position.w` is 1/w of the clip position, D3D's `SV_Position.w` is w.
|
||||
Some(crate::Binding::BuiltIn(crate::BuiltIn::Position { .. }))
|
||||
if ep.stage == ShaderStage::Fragment =>
|
||||
{
|
||||
write!(
|
||||
self.out,
|
||||
"float4({0}.{1}.xyz, 1.0 / {0}.{1}.w)",
|
||||
ep_input.arg_name, fake_member.name,
|
||||
)?;
|
||||
}
|
||||
Some(crate::Binding::Location {
|
||||
interpolation: Some(crate::Interpolation::PerVertex),
|
||||
..
|
||||
|
||||
@@ -7,7 +7,7 @@ struct FragmentInput_func {
|
||||
float4 func(FragmentInput_func fragmentinput_func) : SV_Target0
|
||||
{
|
||||
float input_location = fragmentinput_func.input_location_1;
|
||||
float4 arbitrary_position = fragmentinput_func.arbitrary_position_1;
|
||||
float4 arbitrary_position = float4(fragmentinput_func.arbitrary_position_1.xyz, 1.0 / fragmentinput_func.arbitrary_position_1.w);
|
||||
uint index = fragmentinput_func.index_1;
|
||||
return float4(arbitrary_position.xy, input_location, float(index));
|
||||
}
|
||||
@@ -4,6 +4,6 @@ struct FragmentInput_main {
|
||||
|
||||
float main(FragmentInput_main fragmentinput_main) : SV_DepthGreaterEqual
|
||||
{
|
||||
float4 pos = fragmentinput_main.pos_1;
|
||||
float4 pos = float4(fragmentinput_main.pos_1.xyz, 1.0 / fragmentinput_main.pos_1.w);
|
||||
return (pos.z + 0.1);
|
||||
}
|
||||
@@ -33,14 +33,14 @@ Output ConstructOutput(float4 arg0, float arg1) {
|
||||
|
||||
Output agree_first(FragmentInput_agree_first fragmentinput_agree_first)
|
||||
{
|
||||
float4 pos = fragmentinput_agree_first.pos_4;
|
||||
float4 pos = float4(fragmentinput_agree_first.pos_4.xyz, 1.0 / fragmentinput_agree_first.pos_4.w);
|
||||
const Output output = ConstructOutput(float4(0.4, 0.3, 0.2, 0.1), (pos.z - 0.1));
|
||||
return output;
|
||||
}
|
||||
|
||||
Output agree_second(FragmentInput_agree_second fragmentinput_agree_second)
|
||||
{
|
||||
float4 pos_1 = fragmentinput_agree_second.pos_5;
|
||||
float4 pos_1 = float4(fragmentinput_agree_second.pos_5.xyz, 1.0 / fragmentinput_agree_second.pos_5.w);
|
||||
const Output output_1 = ConstructOutput(float4(0.1, 0.2, 0.3, 0.4), (pos_1.z - 0.2));
|
||||
return output_1;
|
||||
}
|
||||
@@ -54,14 +54,14 @@ DisagreeingOutput ConstructDisagreeingOutput(float4 arg0, float arg1) {
|
||||
|
||||
DisagreeingOutput disagree_conservative(FragmentInput_disagree_conservative fragmentinput_disagree_conservative)
|
||||
{
|
||||
float4 pos_2 = fragmentinput_disagree_conservative.pos_6;
|
||||
float4 pos_2 = float4(fragmentinput_disagree_conservative.pos_6.xyz, 1.0 / fragmentinput_disagree_conservative.pos_6.w);
|
||||
const DisagreeingOutput disagreeingoutput = ConstructDisagreeingOutput(float4(0.4, 0.3, 0.2, 0.1), (pos_2.z + 0.1));
|
||||
return disagreeingoutput;
|
||||
}
|
||||
|
||||
DisagreeingOutput disagree_unrestricted(FragmentInput_disagree_unrestricted fragmentinput_disagree_unrestricted)
|
||||
{
|
||||
float4 pos_3 = fragmentinput_disagree_unrestricted.pos_7;
|
||||
float4 pos_3 = float4(fragmentinput_disagree_unrestricted.pos_7.xyz, 1.0 / fragmentinput_disagree_unrestricted.pos_7.w);
|
||||
const DisagreeingOutput disagreeingoutput_1 = ConstructDisagreeingOutput(float4(0.1, 0.2, 0.3, 0.4), (pos_3.z * 2.0));
|
||||
return disagreeingoutput_1;
|
||||
}
|
||||
@@ -4,6 +4,6 @@ struct FragmentInput_main {
|
||||
|
||||
void main(FragmentInput_main fragmentinput_main)
|
||||
{
|
||||
float4 pos = fragmentinput_main.pos_1;
|
||||
float4 pos = float4(fragmentinput_main.pos_1.xyz, 1.0 / fragmentinput_main.pos_1.w);
|
||||
return;
|
||||
}
|
||||
@@ -4,6 +4,6 @@ struct FragmentInput_main {
|
||||
|
||||
float main(FragmentInput_main fragmentinput_main) : SV_DepthLessEqual
|
||||
{
|
||||
float4 pos = fragmentinput_main.pos_1;
|
||||
float4 pos = float4(fragmentinput_main.pos_1.xyz, 1.0 / fragmentinput_main.pos_1.w);
|
||||
return (pos.z - 0.1);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ ColorAndDepth ConstructColorAndDepth(float4 arg0, float arg1) {
|
||||
|
||||
FragmentOutput_color_and_depth color_and_depth(FragmentInput_color_and_depth fragmentinput_color_and_depth)
|
||||
{
|
||||
float4 pos = fragmentinput_color_and_depth.pos_3;
|
||||
float4 pos = float4(fragmentinput_color_and_depth.pos_3.xyz, 1.0 / fragmentinput_color_and_depth.pos_3.w);
|
||||
const ColorAndDepth coloranddepth = ConstructColorAndDepth(float4(0.4, 0.3, 0.2, 0.1), pos.z);
|
||||
const FragmentOutput_color_and_depth coloranddepth_1 = { coloranddepth.color };
|
||||
return coloranddepth_1;
|
||||
@@ -46,13 +46,13 @@ OnlyDepth ConstructOnlyDepth(float arg0) {
|
||||
|
||||
void only_depth(FragmentInput_only_depth fragmentinput_only_depth)
|
||||
{
|
||||
float4 pos_1 = fragmentinput_only_depth.pos_4;
|
||||
float4 pos_1 = float4(fragmentinput_only_depth.pos_4.xyz, 1.0 / fragmentinput_only_depth.pos_4.w);
|
||||
return;
|
||||
}
|
||||
|
||||
ColorAndDepth unrestricted(FragmentInput_unrestricted fragmentinput_unrestricted)
|
||||
{
|
||||
float4 pos_2 = fragmentinput_unrestricted.pos_5;
|
||||
float4 pos_2 = float4(fragmentinput_unrestricted.pos_5.xyz, 1.0 / fragmentinput_unrestricted.pos_5.w);
|
||||
const ColorAndDepth coloranddepth_2 = ConstructColorAndDepth(float4(0.1, 0.2, 0.3, 0.4), (pos_2.z * 2.0));
|
||||
return coloranddepth_2;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ FragmentOutput ConstructFragmentOutput(float arg0, uint arg1, float arg2) {
|
||||
|
||||
FragmentOutput fragment(FragmentInput_fragment fragmentinput_fragment)
|
||||
{
|
||||
VertexOutput in_ = { fragmentinput_fragment.position_1, fragmentinput_fragment._varying_1 };
|
||||
VertexOutput in_ = { float4(fragmentinput_fragment.position_1.xyz, 1.0 / fragmentinput_fragment.position_1.w), fragmentinput_fragment._varying_1 };
|
||||
bool front_facing = fragmentinput_fragment.front_facing_1;
|
||||
uint sample_index = fragmentinput_fragment.sample_index_1;
|
||||
uint sample_mask = fragmentinput_fragment.sample_mask_1;
|
||||
|
||||
@@ -67,6 +67,6 @@ VertexOutput_vert_main vert_main()
|
||||
|
||||
void frag_main(FragmentInput_frag_main fragmentinput_frag_main)
|
||||
{
|
||||
FragmentInput val = { fragmentinput_frag_main.position_1, fragmentinput_frag_main._flat_1, fragmentinput_frag_main.flat_first_1, fragmentinput_frag_main.flat_either_1, fragmentinput_frag_main._linear_1, fragmentinput_frag_main.linear_centroid_1, fragmentinput_frag_main.linear_sample_1, fragmentinput_frag_main.linear_center_1, fragmentinput_frag_main.perspective_1, fragmentinput_frag_main.perspective_centroid_1, fragmentinput_frag_main.perspective_sample_1, fragmentinput_frag_main.perspective_center_1 };
|
||||
FragmentInput val = { float4(fragmentinput_frag_main.position_1.xyz, 1.0 / fragmentinput_frag_main.position_1.w), fragmentinput_frag_main._flat_1, fragmentinput_frag_main.flat_first_1, fragmentinput_frag_main.flat_either_1, fragmentinput_frag_main._linear_1, fragmentinput_frag_main.linear_centroid_1, fragmentinput_frag_main.linear_sample_1, fragmentinput_frag_main.linear_center_1, fragmentinput_frag_main.perspective_1, fragmentinput_frag_main.perspective_centroid_1, fragmentinput_frag_main.perspective_sample_1, fragmentinput_frag_main.perspective_center_1 };
|
||||
return;
|
||||
}
|
||||
@@ -63,6 +63,6 @@ VertexOutput_vert_main vert_main()
|
||||
|
||||
void frag_main(FragmentInput_frag_main fragmentinput_frag_main)
|
||||
{
|
||||
FragmentInput val = { fragmentinput_frag_main.position_1, fragmentinput_frag_main._flat_1, fragmentinput_frag_main.flat_either_1, fragmentinput_frag_main._linear_1, fragmentinput_frag_main.linear_centroid_1, fragmentinput_frag_main.linear_sample_1, fragmentinput_frag_main.linear_center_1, fragmentinput_frag_main.perspective_1, fragmentinput_frag_main.perspective_centroid_1, fragmentinput_frag_main.perspective_sample_1, fragmentinput_frag_main.perspective_center_1 };
|
||||
FragmentInput val = { float4(fragmentinput_frag_main.position_1.xyz, 1.0 / fragmentinput_frag_main.position_1.w), fragmentinput_frag_main._flat_1, fragmentinput_frag_main.flat_either_1, fragmentinput_frag_main._linear_1, fragmentinput_frag_main.linear_centroid_1, fragmentinput_frag_main.linear_sample_1, fragmentinput_frag_main.linear_center_1, fragmentinput_frag_main.perspective_1, fragmentinput_frag_main.perspective_centroid_1, fragmentinput_frag_main.perspective_sample_1, fragmentinput_frag_main.perspective_center_1 };
|
||||
return;
|
||||
}
|
||||
@@ -263,7 +263,7 @@ void ms_divergent(uint3 thread_id_1 : SV_GroupThreadID, uint local_invocation_in
|
||||
|
||||
float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
|
||||
{
|
||||
VertexOutput vertex = { fragmentinput_fs_main.position_3, fragmentinput_fs_main.color_3 };
|
||||
VertexOutput vertex = { float4(fragmentinput_fs_main.position_3.xyz, 1.0 / fragmentinput_fs_main.position_3.w), fragmentinput_fs_main.color_3 };
|
||||
PrimitiveInput primitive = { fragmentinput_fs_main.colorMask_3 };
|
||||
return (vertex.color * primitive.colorMask);
|
||||
}
|
||||
@@ -90,7 +90,7 @@ Light ConstructLight(float4x4 arg0, float4 arg1, float4 arg2) {
|
||||
|
||||
float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
|
||||
{
|
||||
VertexOutput in_ = { fragmentinput_fs_main.proj_position_1, fragmentinput_fs_main.world_normal_1, fragmentinput_fs_main.world_position_1 };
|
||||
VertexOutput in_ = { float4(fragmentinput_fs_main.proj_position_1.xyz, 1.0 / fragmentinput_fs_main.proj_position_1.w), fragmentinput_fs_main.world_normal_1, fragmentinput_fs_main.world_position_1 };
|
||||
float3 color = c_ambient;
|
||||
uint i = 0u;
|
||||
|
||||
@@ -129,7 +129,7 @@ float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
|
||||
|
||||
float4 fs_main_without_storage(FragmentInput_fs_main_without_storage fragmentinput_fs_main_without_storage) : SV_Target0
|
||||
{
|
||||
VertexOutput in_1 = { fragmentinput_fs_main_without_storage.proj_position_2, fragmentinput_fs_main_without_storage.world_normal_2, fragmentinput_fs_main_without_storage.world_position_2 };
|
||||
VertexOutput in_1 = { float4(fragmentinput_fs_main_without_storage.proj_position_2.xyz, 1.0 / fragmentinput_fs_main_without_storage.proj_position_2.w), fragmentinput_fs_main_without_storage.world_normal_2, fragmentinput_fs_main_without_storage.world_position_2 };
|
||||
float3 color_1 = c_ambient;
|
||||
uint i_1 = 0u;
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ VertexOutput_vs_main vs_main(uint vertex_index : SV_VertexID)
|
||||
|
||||
float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
|
||||
{
|
||||
VertexOutput in_ = { fragmentinput_fs_main.position_1, fragmentinput_fs_main.uv_1 };
|
||||
VertexOutput in_ = { float4(fragmentinput_fs_main.position_1.xyz, 1.0 / fragmentinput_fs_main.position_1.w), fragmentinput_fs_main.uv_1 };
|
||||
float4 _e4 = r_texture.Sample(r_sampler, in_.uv);
|
||||
return _e4;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ bool test_any_and_all_for_bool()
|
||||
|
||||
float4 derivatives(FragmentInput_derivatives fragmentinput_derivatives) : SV_Target0
|
||||
{
|
||||
float4 foo = fragmentinput_derivatives.foo_1;
|
||||
float4 foo = float4(fragmentinput_derivatives.foo_1.xyz, 1.0 / fragmentinput_derivatives.foo_1.w);
|
||||
float4 x = (float4)0;
|
||||
float4 y = (float4)0;
|
||||
float4 z = (float4)0;
|
||||
|
||||
@@ -12,6 +12,6 @@ struct FragmentInput_fs_main {
|
||||
|
||||
float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
|
||||
{
|
||||
FragmentIn v_out = { fragmentinput_fs_main.value, fragmentinput_fs_main.value2_, fragmentinput_fs_main.position };
|
||||
FragmentIn v_out = { fragmentinput_fs_main.value, fragmentinput_fs_main.value2_, float4(fragmentinput_fs_main.position.xyz, 1.0 / fragmentinput_fs_main.position.w) };
|
||||
return float4(v_out.value, v_out.value, v_out.value2_, v_out.value2_);
|
||||
}
|
||||
Reference in new issue
Block a user