vkd3d-shader: Translate gather4_po instructions.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2018-09-24 10:25:24 +02:00 committed by Alexandre Julliard
parent a553eb1afe
commit 5319cc2420
2 changed files with 25 additions and 9 deletions

View File

@ -5469,25 +5469,38 @@ static void vkd3d_dxbc_compiler_emit_sample_c(struct vkd3d_dxbc_compiler *compil
static void vkd3d_dxbc_compiler_emit_gather4(struct vkd3d_dxbc_compiler *compiler, static void vkd3d_dxbc_compiler_emit_gather4(struct vkd3d_dxbc_compiler *compiler,
const struct vkd3d_shader_instruction *instruction) const struct vkd3d_shader_instruction *instruction)
{ {
const struct vkd3d_shader_src_param *addr, *offset, *resource, *sampler;
uint32_t sampled_type_id, coordinate_id, component_id, dref_id, val_id; uint32_t sampled_type_id, coordinate_id, component_id, dref_id, val_id;
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
const struct vkd3d_shader_dst_param *dst = instruction->dst; const struct vkd3d_shader_dst_param *dst = instruction->dst;
const struct vkd3d_shader_src_param *src = instruction->src; const struct vkd3d_shader_src_param *src = instruction->src;
const struct vkd3d_shader_src_param *resource, *sampler;
SpvImageOperandsMask operands_mask = 0; SpvImageOperandsMask operands_mask = 0;
unsigned int image_operand_count = 0; unsigned int image_operand_count = 0;
struct vkd3d_shader_image image; struct vkd3d_shader_image image;
unsigned int component_idx; unsigned int component_idx;
uint32_t image_operands[1]; uint32_t image_operands[1];
DWORD coordinate_mask; DWORD coordinate_mask;
bool extended_offset;
resource = &src[1]; extended_offset = instruction->handler_idx == VKD3DSIH_GATHER4_PO
sampler = &src[2]; || instruction->handler_idx == VKD3DSIH_GATHER4_PO_C;
addr = &src[0];
offset = extended_offset ? &src[1] : NULL;
resource = &src[1 + extended_offset];
sampler = &src[2 + extended_offset];
vkd3d_dxbc_compiler_prepare_sampled_image(compiler, &image, vkd3d_dxbc_compiler_prepare_sampled_image(compiler, &image,
&resource->reg, &sampler->reg, VKD3D_IMAGE_FLAG_NONE); &resource->reg, &sampler->reg, VKD3D_IMAGE_FLAG_NONE);
if (vkd3d_shader_instruction_has_texel_offset(instruction)) if (offset)
{
vkd3d_spirv_enable_capability(builder, SpvCapabilityImageGatherExtended);
operands_mask |= SpvImageOperandsOffsetMask;
image_operands[image_operand_count++] = vkd3d_dxbc_compiler_emit_load_src(compiler,
offset, (1u << image.resource_type_info->offset_component_count) - 1);
}
else if (vkd3d_shader_instruction_has_texel_offset(instruction))
{ {
operands_mask |= SpvImageOperandsConstOffsetMask; operands_mask |= SpvImageOperandsConstOffsetMask;
image_operands[image_operand_count++] = vkd3d_dxbc_compiler_emit_texel_offset(compiler, image_operands[image_operand_count++] = vkd3d_dxbc_compiler_emit_texel_offset(compiler,
@ -5496,10 +5509,11 @@ static void vkd3d_dxbc_compiler_emit_gather4(struct vkd3d_dxbc_compiler *compile
sampled_type_id = vkd3d_spirv_get_type_id(builder, image.sampled_type, VKD3D_VEC4_SIZE); sampled_type_id = vkd3d_spirv_get_type_id(builder, image.sampled_type, VKD3D_VEC4_SIZE);
coordinate_mask = (1u << image.resource_type_info->coordinate_component_count) - 1; coordinate_mask = (1u << image.resource_type_info->coordinate_component_count) - 1;
coordinate_id = vkd3d_dxbc_compiler_emit_load_src(compiler, &src[0], coordinate_mask); coordinate_id = vkd3d_dxbc_compiler_emit_load_src(compiler, addr, coordinate_mask);
if (instruction->handler_idx == VKD3DSIH_GATHER4_C) if (instruction->handler_idx == VKD3DSIH_GATHER4_C)
{ {
dref_id = vkd3d_dxbc_compiler_emit_load_src(compiler, &src[3], VKD3DSP_WRITEMASK_0); dref_id = vkd3d_dxbc_compiler_emit_load_src(compiler,
&src[3 + extended_offset], VKD3DSP_WRITEMASK_0);
val_id = vkd3d_spirv_build_op_image_dref_gather(builder, sampled_type_id, val_id = vkd3d_spirv_build_op_image_dref_gather(builder, sampled_type_id,
image.sampled_image_id, coordinate_id, dref_id, image.sampled_image_id, coordinate_id, dref_id,
operands_mask, image_operands, image_operand_count); operands_mask, image_operands, image_operand_count);
@ -5508,7 +5522,8 @@ static void vkd3d_dxbc_compiler_emit_gather4(struct vkd3d_dxbc_compiler *compile
{ {
component_idx = vkd3d_swizzle_get_component(sampler->swizzle, 0); component_idx = vkd3d_swizzle_get_component(sampler->swizzle, 0);
/* Nvidia driver requires signed integer type. */ /* Nvidia driver requires signed integer type. */
component_id = vkd3d_dxbc_compiler_get_constant(compiler, VKD3D_TYPE_INT, 1, &component_idx); component_id = vkd3d_dxbc_compiler_get_constant(compiler,
VKD3D_TYPE_INT, 1, &component_idx);
val_id = vkd3d_spirv_build_op_image_gather(builder, sampled_type_id, val_id = vkd3d_spirv_build_op_image_gather(builder, sampled_type_id,
image.sampled_image_id, coordinate_id, component_id, image.sampled_image_id, coordinate_id, component_id,
operands_mask, image_operands, image_operand_count); operands_mask, image_operands, image_operand_count);
@ -6382,6 +6397,7 @@ void vkd3d_dxbc_compiler_handle_instruction(struct vkd3d_dxbc_compiler *compiler
break; break;
case VKD3DSIH_GATHER4: case VKD3DSIH_GATHER4:
case VKD3DSIH_GATHER4_C: case VKD3DSIH_GATHER4_C:
case VKD3DSIH_GATHER4_PO:
vkd3d_dxbc_compiler_emit_gather4(compiler, instruction); vkd3d_dxbc_compiler_emit_gather4(compiler, instruction);
break; break;
case VKD3DSIH_LD_RAW: case VKD3DSIH_LD_RAW:

View File

@ -9870,7 +9870,7 @@ static void test_gather(void)
{ {
const struct vec4 *expected = &expected_gather4_offset[y * rb.width + x]; const struct vec4 *expected = &expected_gather4_offset[y * rb.width + x];
const struct vec4 *got = get_readback_vec4(&rb, x, y); const struct vec4 *got = get_readback_vec4(&rb, x, y);
todo(compare_vec4(got, expected, 0), ok(compare_vec4(got, expected, 0),
"Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n", "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w); got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
} }
@ -9906,7 +9906,7 @@ static void test_gather(void)
{ {
const struct vec4 *expected = &expected_gather4[y * rb.width + x]; const struct vec4 *expected = &expected_gather4[y * rb.width + x];
const struct vec4 *got = get_readback_vec4(&rb, x, y); const struct vec4 *got = get_readback_vec4(&rb, x, y);
todo(compare_vec4(got, expected, 0), ok(compare_vec4(got, expected, 0),
"Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n", "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w); got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
} }