vkd3d-shader: Implement tex2Dproj().
Merge request reports
Activity
- Resolved by Nikolay Sivov
I suggest adding at least this test at the end of
tests/sampler.shader_test
:[pixel shader todo] sampler sam; float4 p; float4 main() : sv_target { return tex2Dproj(sam, p); } [test] uniform 0 float4 1.0 1.0 1234.0 2.0 todo draw quad todo probe all rgba (0.25, 0.0, 0.25, 0.0)
I confirmed that is the expected behavior using the minitestbot.
Even though to get this to pass we need to lower combined sample expressions, but that seems close in the horizon (!209 (merged)).
Edited by Francisco CasasYes, that was exactly the reason for a lack of tests. I'm going to wait for !209 (merged) to get in first.
2455 unsigned int dim_count; 2456 2457 if (instr->type != HLSL_IR_RESOURCE_LOAD) 2458 return false; 2459 load = hlsl_ir_resource_load(instr); 2460 if (load->load_type != HLSL_RESOURCE_SAMPLE_PROJ) 2461 return false; 2462 2463 dim_count = hlsl_sampler_dim_count(load->sampling_dim); 2464 if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(W, W, W, W), dim_count, load->coords.node, &instr->loc))) 2465 return false; 2466 list_add_before(&instr->entry, &swizzle->entry); 2467 2468 operands[0] = load->coords.node; 2469 operands[1] = swizzle; 2470 if (!(coords = hlsl_new_expr(ctx, HLSL_OP2_DIV, operands, hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, dim_count), Just to summarize what we discussed in IRC: there are few hlsl_ir_expr ops that are allowed to handle different types of arguments and return value. My understanding is that HLSL_OP2_DIV is not one of them (like, e.g. HLSL_OP2_DOT). When replacing this hlsl_new_expr() call with a call to hlsl_new_binary_expr(), the assertion should hold true.
This is not happening however, because
load->coords.node
is float4 and the swizzle is float2 (or float3 for tex3Dproj). What is missing is to create a new .XY (or .XYZ) swizzle forload->coords.node
and pass it as arg1 instead ofload->coords.node
directly.Edited by Francisco CasasAfter some thought, I think that what we are missing is a pass that lowers 1D combined samples to 2D. But only combined samples. So we end up with something like:// Only 1D combined samples (with load->sampler == NULL) get converted into 2D. hlsl_transform_ir(ctx, lower_1d_combined_samples_to_2d, body, NULL); // ... if (profile->major_version >= 4) { hlsl_transform_ir(ctx, lower_tex_proj, body, NULL); } // ... if (profile->major_version >= 4) { hlsl_transform_ir(ctx, lower_combined_samples, body, NULL); // From !209 } // ...
If we do this, you wouldn't have to worry about 1D HLSL_RESOURCE_SAMPLE_PROJ here.Edited by Francisco CasasNative pretty much throws whatever junk into the y coordinate for regular tex1D(). It's more consistent with tex1Dproj() but I don't think that's saying much. I doubt we want to worry that much about what we're putting in the y coordinate.
I also don't think that tex1D() should really emit anything 1d. It seems like it should just emit 2D IR.
changed this line in version 2 of the diff
So, SM1 doesn't care what we pass in the Y component of the
src0
oftexld
nortexldp
when we are working with tex1D() and tex1Dproj(), we don't have to worry about making any transformation to 2D.It is for SM4 that we have to care about making the second coordinate 0.5. Since this is also true for tex1D(), my opinion is that this should be deferred to a later pass:
if (profile->major_version >= 4) { // Lower [tex1Dproj -> 1d sample] normally. hlsl_transform_ir(ctx, lower_tex_proj, body, NULL); // Add a 0.5 component to the coords of 1D combined sample resource loads, making them 2D. hlsl_transform_ir(ctx, lower_1d_combined_samples_to_2d, body, NULL); } // ... hlsl_transform_ir(ctx, lower_combined_samples, body, NULL); // as in !209
Edited by Francisco CasasI don't see how it ever makes sense to emit a 1D load in the IR from intrinsic_tex1D(). The load is fundamentally 2D, regardless of profile version. Lowering is a thing to deal with differences between profile bytecode, or high-level constructions that can't easily be emitted already lowered; I don't see how either applies here?
It's not to make sense as a load, but to be able to tell them apart later. If it was tex2D() initially there is nothing else to do, if it was tex1D(), SM4 needs to do something (checking for combined sampling case to distinguish it from regular SM4 1D load).
What was proposed is to produce something "common" for functions, and then have multiple passes to fix that up, instead of producing final result immediately.
I'm trying to say that we can just implement tex1D(s, coords) as if it were tex2D(s, float2(coords.x, 0.5)) in the intrinsic handler. Similarly tex1Dproj(s, coords) can be tex2Dproj(s, float4(coords.x, 0.5, 0, coords.w)). The only potential difference is that native throws different garbage into the y coordinate, depending on shader target, but I'm not really sure that it matters.
mentioned in merge request !209 (merged)
added 5 commits
- ff7d6956 - vkd3d-shader/hlsl: Implement tex2Dproj().
- b96e4fbb - vkd3d-shader/hlsl: Implement tex1Dproj().
- d7ee8062 - vkd3d-shader/hlsl: Implement tex3Dproj().
- 6bed0f5c - vkd3d-shader/d3dbc: Disallow 1D sampler types when writing sampler declaration.
- 2be036db - vkd3d-shader/hlsl: Implement texCUBEproj().
Toggle commit listadded 12 commits
-
2be036db...ebf75735 - 7 commits from branch
wine:master
- 9af19825 - vkd3d-shader/hlsl: Implement tex2Dproj().
- 5aef0583 - vkd3d-shader/hlsl: Implement tex1Dproj().
- 4b102240 - vkd3d-shader/hlsl: Implement tex3Dproj().
- f4ae421f - vkd3d-shader/d3dbc: Disallow 1D sampler types when writing sampler declaration.
- 6d33de96 - vkd3d-shader/hlsl: Implement texCUBEproj().
Toggle commit list-
2be036db...ebf75735 - 7 commits from branch
added 68 commits
-
6d33de96...d5a0b3af - 63 commits from branch
wine:master
- 9228c3c6 - vkd3d-shader/hlsl: Implement tex2Dproj().
- 2c3b5605 - vkd3d-shader/hlsl: Implement tex1Dproj().
- 2437b1fc - vkd3d-shader/hlsl: Implement tex3Dproj().
- 3e12f71c - vkd3d-shader/d3dbc: Disallow 1D sampler types when writing sampler declaration.
- 8d577925 - vkd3d-shader/hlsl: Implement texCUBEproj().
Toggle commit list-
6d33de96...d5a0b3af - 63 commits from branch
added 96 commits
-
8d577925...f95ab2a5 - 91 commits from branch
wine:master
- edd6a89c - vkd3d-shader/hlsl: Implement tex2Dproj().
- 8e6e34ed - vkd3d-shader/hlsl: Implement tex1Dproj().
- 7ff00d19 - vkd3d-shader/hlsl: Implement tex3Dproj().
- 31f5326f - vkd3d-shader/d3dbc: Disallow 1D sampler types when writing sampler declaration.
- 5bde8419 - vkd3d-shader/hlsl: Implement texCUBEproj().
Toggle commit list-
8d577925...f95ab2a5 - 91 commits from branch
added 11 commits
-
5bde8419...3d49b59a - 6 commits from branch
wine:master
- 196e28f2 - vkd3d-shader/hlsl: Implement tex2Dproj().
- 15a76316 - vkd3d-shader/hlsl: Implement tex1Dproj().
- b5d7401a - vkd3d-shader/hlsl: Implement tex3Dproj().
- 098dac4d - vkd3d-shader/d3dbc: Disallow 1D sampler types when writing sampler declaration.
- 1c30a5af - vkd3d-shader/hlsl: Implement texCUBEproj().
Toggle commit list-
5bde8419...3d49b59a - 6 commits from branch
added 13 commits
-
1c30a5af...0d1bc77b - 8 commits from branch
wine:master
- 9883c297 - vkd3d-shader/hlsl: Implement tex2Dproj().
- 37dca4be - vkd3d-shader/hlsl: Implement tex1Dproj().
- 0135b967 - vkd3d-shader/hlsl: Implement tex3Dproj().
- 8e5766a6 - vkd3d-shader/d3dbc: Disallow 1D sampler types when writing sampler declaration.
- 3ba8b20c - vkd3d-shader/hlsl: Implement texCUBEproj().
Toggle commit list-
1c30a5af...0d1bc77b - 8 commits from branch
added 161 commits
-
3ba8b20c...45541dd9 - 157 commits from branch
wine:master
- 53220d11 - vkd3d-shader/hlsl: Implement tex2Dproj().
- 8d0c2026 - vkd3d-shader/hlsl: Implement tex1Dproj().
- d1edfe8a - vkd3d-shader/hlsl: Implement tex3Dproj().
- 936f8512 - vkd3d-shader/hlsl: Implement texCUBEproj().
Toggle commit list-
3ba8b20c...45541dd9 - 157 commits from branch
added 332 commits
-
936f8512...0805ce12 - 329 commits from branch
wine:master
- 25d9ae36 - vkd3d-shader/hlsl: Implement tex2Dproj().
- 4c7f83fc - vkd3d-shader/hlsl: Implement tex3Dproj().
- 2c19a5a6 - vkd3d-shader/hlsl: Implement texCUBEproj().
Toggle commit list-
936f8512...0805ce12 - 329 commits from branch