From: Conor McCarthy cmccarthy@codeweavers.com
--- libs/vkd3d-shader/spirv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index e8068f3a3..b5bcd1a4c 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -6892,11 +6892,11 @@ static enum GLSLstd450 spirv_compiler_map_ext_glsl_instruction( static void spirv_compiler_emit_ext_glsl_instruction(struct spirv_compiler *compiler, const struct vkd3d_shader_instruction *instruction) { + uint32_t instr_set_id, type_id, val_id, rev_val_id, uint_max_id, condition_id; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; const struct vkd3d_shader_dst_param *dst = instruction->dst; const struct vkd3d_shader_src_param *src = instruction->src; uint32_t src_id[SPIRV_MAX_SRC_COUNT]; - uint32_t instr_set_id, type_id, val_id; unsigned int i, component_count; enum GLSLstd450 glsl_inst;
@@ -6925,8 +6925,12 @@ static void spirv_compiler_emit_ext_glsl_instruction(struct spirv_compiler *comp { /* In D3D bits are numbered from the most significant bit. */ component_count = vsir_write_mask_component_count(dst->write_mask); - val_id = vkd3d_spirv_build_op_isub(builder, type_id, + uint_max_id = spirv_compiler_get_constant_uint_vector(compiler, UINT32_MAX, component_count); + condition_id = vkd3d_spirv_build_op_tr2(builder, &builder->function_stream, SpvOpIEqual, + vkd3d_spirv_get_type_id(builder, VKD3D_SHADER_COMPONENT_BOOL, component_count), val_id, uint_max_id); + rev_val_id = vkd3d_spirv_build_op_isub(builder, type_id, spirv_compiler_get_constant_uint_vector(compiler, 31, component_count), val_id); + val_id = vkd3d_spirv_build_op_select(builder, type_id, condition_id, val_id, rev_val_id); }
spirv_compiler_emit_store_dst(compiler, dst, val_id);
From: Conor McCarthy cmccarthy@codeweavers.com
--- tests/d3d12.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index d2638f312..9237780aa 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -9179,6 +9179,30 @@ static void test_shader_instructions(void) 0x06000086, 0x00102032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0100003e, }; static struct named_shader ps_bits_vector = {"bits_vector", ps_bits_vector_code, sizeof(ps_bits_vector_code)}; + static const DWORD ps_firstbit_raw_code[] = + { + /* Without the fixup instructions emitted by fxc. */ +#if 0 + ps_5_0 + dcl_globalFlags refactoringAllowed + dcl_constantBuffer cb0[1], immediateIndexed + dcl_output o0.xyzw v4:float + firstbit_lo o0.x v4:uint, cb0[0].x v4:uint + firstbit_hi o0.y v4:uint, cb0[0].x v4:uint + firstbit_shi o0.z v4:uint, cb0[0].y v4:int + mov o0.w v4:float, l(0) <s:float> + ret +#endif + 0x43425844, 0xea469de0, 0x78a93361, 0xed27f28b, 0x8c34dd51, 0x00000001, 0x00000100, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000088, 0x00000050, 0x00000022, + 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, + 0x06000088, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000087, 0x00102022, + 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000089, 0x00102042, 0x00000000, 0x0020801a, + 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, + }; + static struct named_shader ps_firstbit_raw = {"firstbit_raw", ps_firstbit_raw_code, sizeof(ps_firstbit_raw_code)}; static const DWORD ps_ishr_code[] = { #if 0 @@ -10553,6 +10577,12 @@ static void test_shader_instructions(void)
{&ps_bits_vector, {{{0x11111111, 0x00080000}}}, {{8, 1, 28, 19}}},
+ {&ps_firstbit_raw, {{{ 0, 0}}}, {{ ~0u, ~0u, ~0u, 0}}}, + {&ps_firstbit_raw, {{{0x80000000, 0x80000000}}}, {{ 31, 0, 1, 0}}}, + {&ps_firstbit_raw, {{{0x80000001, 0x80000001}}}, {{ 0, 0, 1, 0}}}, + {&ps_firstbit_raw, {{{0x11111111, 0x11111111}}}, {{ 0, 3, 3, 0}}}, + {&ps_firstbit_raw, {{{0x00080000, 0xffffffff}}}, {{ 19, 12, ~0u, 0}}}, + {&ps_ishr, {{{0x00000000, 0x00000000, 0x00000000, 0x00000000}, {~0x1fu, 0, 32, 64}}}, {{0x00000000, 0x00000000, 0x00000000, 0x00000000}}}, {&ps_ishr, {{{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}, {~0x1fu, 0, 32, 64}}},