vkd3d-shader/fx: Fix the unpacked size and stride fields of the fx_4_0 types.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2024-09-02 01:59:20 +02:00 committed by Henri Verbeet
parent 9673b660d4
commit 6d28cc131b
Notes: Henri Verbeet 2024-09-04 11:48:06 +02:00
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1030

View File

@ -590,32 +590,30 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
uint32_t offset;
uint32_t type;
};
uint32_t name_offset, offset, total_size, packed_size, stride, numeric_desc;
uint32_t name_offset, offset, unpacked_size, packed_size, stride, numeric_desc;
struct vkd3d_bytecode_buffer *buffer = &fx->unstructured;
struct field_offsets *field_offsets = NULL;
const struct hlsl_type *element_type;
struct hlsl_ctx *ctx = fx->ctx;
uint32_t elements_count = 0;
const char *name;
size_t i;
/* Resolve arrays to element type and number of elements. */
if (type->class == HLSL_CLASS_ARRAY)
{
elements_count = hlsl_get_multiarray_size(type);
type = hlsl_get_multiarray_element_type(type);
}
element_type = hlsl_get_multiarray_element_type(type);
name = get_fx_4_type_name(type);
name = get_fx_4_type_name(element_type);
name_offset = write_string(name, fx);
if (type->class == HLSL_CLASS_STRUCT)
if (element_type->class == HLSL_CLASS_STRUCT)
{
if (!(field_offsets = hlsl_calloc(ctx, type->e.record.field_count, sizeof(*field_offsets))))
if (!(field_offsets = hlsl_calloc(ctx, element_type->e.record.field_count, sizeof(*field_offsets))))
return 0;
for (i = 0; i < type->e.record.field_count; ++i)
for (i = 0; i < element_type->e.record.field_count; ++i)
{
const struct hlsl_struct_field *field = &type->e.record.fields[i];
const struct hlsl_struct_field *field = &element_type->e.record.fields[i];
field_offsets[i].name = write_string(field->name, fx);
field_offsets[i].semantic = write_string(field->semantic.raw_name, fx);
@ -626,7 +624,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
offset = put_u32_unaligned(buffer, name_offset);
switch (type->class)
switch (element_type->class)
{
case HLSL_CLASS_SCALAR:
case HLSL_CLASS_VECTOR:
@ -665,32 +663,32 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
vkd3d_unreachable();
case HLSL_CLASS_VOID:
FIXME("Writing type class %u is not implemented.\n", type->class);
FIXME("Writing type class %u is not implemented.\n", element_type->class);
set_status(fx, VKD3D_ERROR_NOT_IMPLEMENTED);
return 0;
}
/* Structures can only contain numeric fields, this is validated during variable declaration. */
total_size = stride = type->reg_size[HLSL_REGSET_NUMERIC] * sizeof(float);
unpacked_size = type->reg_size[HLSL_REGSET_NUMERIC] * sizeof(float);
packed_size = 0;
if (is_numeric_fx_4_type(type))
packed_size = hlsl_type_component_count(type) * sizeof(float);
if (is_numeric_fx_4_type(element_type))
packed_size = hlsl_type_component_count(element_type) * sizeof(float);
if (elements_count)
{
total_size *= elements_count;
packed_size *= elements_count;
}
stride = element_type->reg_size[HLSL_REGSET_NUMERIC] * sizeof(float);
stride = align(stride, 4 * sizeof(float));
put_u32_unaligned(buffer, elements_count);
put_u32_unaligned(buffer, total_size);
put_u32_unaligned(buffer, unpacked_size);
put_u32_unaligned(buffer, stride);
put_u32_unaligned(buffer, packed_size);
if (type->class == HLSL_CLASS_STRUCT)
if (element_type->class == HLSL_CLASS_STRUCT)
{
put_u32_unaligned(buffer, type->e.record.field_count);
for (i = 0; i < type->e.record.field_count; ++i)
put_u32_unaligned(buffer, element_type->e.record.field_count);
for (i = 0; i < element_type->e.record.field_count; ++i)
{
const struct field_offsets *field = &field_offsets[i];
@ -706,7 +704,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
put_u32_unaligned(buffer, 0); /* Interface count */
}
}
else if (type->class == HLSL_CLASS_TEXTURE)
else if (element_type->class == HLSL_CLASS_TEXTURE)
{
static const uint32_t texture_type[] =
{
@ -722,13 +720,13 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
[HLSL_SAMPLER_DIM_CUBEARRAY] = 23,
};
put_u32_unaligned(buffer, texture_type[type->sampler_dim]);
put_u32_unaligned(buffer, texture_type[element_type->sampler_dim]);
}
else if (type->class == HLSL_CLASS_SAMPLER)
else if (element_type->class == HLSL_CLASS_SAMPLER)
{
put_u32_unaligned(buffer, 21);
}
else if (type->class == HLSL_CLASS_UAV)
else if (element_type->class == HLSL_CLASS_UAV)
{
static const uint32_t uav_type[] =
{
@ -741,60 +739,60 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co
[HLSL_SAMPLER_DIM_STRUCTURED_BUFFER] = 40,
};
put_u32_unaligned(buffer, uav_type[type->sampler_dim]);
put_u32_unaligned(buffer, uav_type[element_type->sampler_dim]);
}
else if (type->class == HLSL_CLASS_DEPTH_STENCIL_VIEW)
else if (element_type->class == HLSL_CLASS_DEPTH_STENCIL_VIEW)
{
put_u32_unaligned(buffer, 20);
}
else if (type->class == HLSL_CLASS_RENDER_TARGET_VIEW)
else if (element_type->class == HLSL_CLASS_RENDER_TARGET_VIEW)
{
put_u32_unaligned(buffer, 19);
}
else if (type->class == HLSL_CLASS_PIXEL_SHADER)
else if (element_type->class == HLSL_CLASS_PIXEL_SHADER)
{
put_u32_unaligned(buffer, 5);
}
else if (type->class == HLSL_CLASS_VERTEX_SHADER)
else if (element_type->class == HLSL_CLASS_VERTEX_SHADER)
{
put_u32_unaligned(buffer, 6);
}
else if (type->class == HLSL_CLASS_RASTERIZER_STATE)
else if (element_type->class == HLSL_CLASS_RASTERIZER_STATE)
{
put_u32_unaligned(buffer, 4);
}
else if (type->class == HLSL_CLASS_DEPTH_STENCIL_STATE)
else if (element_type->class == HLSL_CLASS_DEPTH_STENCIL_STATE)
{
put_u32_unaligned(buffer, 3);
}
else if (type->class == HLSL_CLASS_BLEND_STATE)
else if (element_type->class == HLSL_CLASS_BLEND_STATE)
{
put_u32_unaligned(buffer, 2);
}
else if (type->class == HLSL_CLASS_STRING)
else if (element_type->class == HLSL_CLASS_STRING)
{
put_u32_unaligned(buffer, 1);
}
else if (hlsl_is_numeric_type(type))
else if (hlsl_is_numeric_type(element_type))
{
numeric_desc = get_fx_4_numeric_type_description(type, fx);
numeric_desc = get_fx_4_numeric_type_description(element_type, fx);
put_u32_unaligned(buffer, numeric_desc);
}
else if (type->class == HLSL_CLASS_COMPUTE_SHADER)
else if (element_type->class == HLSL_CLASS_COMPUTE_SHADER)
{
put_u32_unaligned(buffer, 28);
}
else if (type->class == HLSL_CLASS_HULL_SHADER)
else if (element_type->class == HLSL_CLASS_HULL_SHADER)
{
put_u32_unaligned(buffer, 29);
}
else if (type->class == HLSL_CLASS_DOMAIN_SHADER)
else if (element_type->class == HLSL_CLASS_DOMAIN_SHADER)
{
put_u32_unaligned(buffer, 30);
}
else
{
FIXME("Type %u is not supported.\n", type->class);
FIXME("Type %u is not supported.\n", element_type->class);
set_status(fx, VKD3D_ERROR_NOT_IMPLEMENTED);
}