mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Implement the ByteAddressBuffer.Load*() methods.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
committed by
Henri Verbeet
parent
1a28e7d9c6
commit
e5ba79b4f1
Notes:
Henri Verbeet
2024-11-06 23:01:27 +01:00
Approved-by: Elizabeth Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1245
@@ -5603,6 +5603,55 @@ static bool raise_invalid_method_object_type(struct hlsl_ctx *ctx, const struct
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool add_raw_load_method_call(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *object,
|
||||
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
struct hlsl_resource_load_params load_params = {.type = HLSL_RESOURCE_LOAD};
|
||||
struct hlsl_ir_node *load;
|
||||
unsigned int value_dim;
|
||||
|
||||
if (params->args_count != 1 && params->args_count != 2)
|
||||
{
|
||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
|
||||
"Wrong number of arguments to method 'Load': expected between 1 and 2, but got %u.",
|
||||
params->args_count);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (params->args_count == 2)
|
||||
{
|
||||
hlsl_fixme(ctx, loc, "Tiled resource status argument.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (params->args[0]->data_type->class != HLSL_CLASS_SCALAR)
|
||||
{
|
||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Scalar address argument expected for '%s'.", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!strcmp(name, "Load"))
|
||||
value_dim = 1;
|
||||
else if (!strcmp(name, "Load2"))
|
||||
value_dim = 2;
|
||||
else if (!strcmp(name, "Load3"))
|
||||
value_dim = 3;
|
||||
else
|
||||
value_dim = 4;
|
||||
|
||||
if (!(load_params.coords = add_implicit_conversion(ctx, block, params->args[0],
|
||||
hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), loc)))
|
||||
return false;
|
||||
|
||||
load_params.format = hlsl_get_vector_type(ctx, HLSL_TYPE_UINT, value_dim);
|
||||
load_params.resource = object;
|
||||
|
||||
if (!(load = hlsl_new_resource_load(ctx, &load_params, loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, load);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool add_load_method_call(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *object,
|
||||
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
@@ -5612,6 +5661,9 @@ static bool add_load_method_call(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
struct hlsl_ir_node *load;
|
||||
bool multisampled;
|
||||
|
||||
if (object_type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER)
|
||||
return add_raw_load_method_call(ctx, block, object, name, params, loc);
|
||||
|
||||
if (object_type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
|
||||
{
|
||||
hlsl_fixme(ctx, loc, "Method '%s' for structured buffers.", name);
|
||||
@@ -6264,7 +6316,10 @@ texture_methods[] =
|
||||
|
||||
{ "GetDimensions", add_getdimensions_method_call, "00111111111110" },
|
||||
|
||||
{ "Load", add_load_method_call, "00111011110110" },
|
||||
{ "Load", add_load_method_call, "00111011110111" },
|
||||
{ "Load2", add_raw_load_method_call, "00000000000001" },
|
||||
{ "Load3", add_raw_load_method_call, "00000000000001" },
|
||||
{ "Load4", add_raw_load_method_call, "00000000000001" },
|
||||
|
||||
{ "Sample", add_sample_method_call, "00111111001000" },
|
||||
{ "SampleBias", add_sample_lod_method_call, "00111111001000" },
|
||||
|
@@ -4831,7 +4831,15 @@ static void write_sm4_dcl_textures(const struct tpf_compiler *tpf, const struct
|
||||
}
|
||||
else
|
||||
{
|
||||
instr.opcode = VKD3D_SM4_OP_DCL_RESOURCE;
|
||||
switch (component_type->sampler_dim)
|
||||
{
|
||||
case HLSL_SAMPLER_DIM_RAW_BUFFER:
|
||||
instr.opcode = VKD3D_SM5_OP_DCL_RESOURCE_RAW;
|
||||
break;
|
||||
default:
|
||||
instr.opcode = VKD3D_SM4_OP_DCL_RESOURCE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
instr.extra_bits |= (sm4_resource_dimension(component_type) << VKD3D_SM4_RESOURCE_TYPE_SHIFT);
|
||||
|
||||
@@ -5133,12 +5141,15 @@ static void write_sm4_ld(const struct tpf_compiler *tpf, const struct hlsl_ir_no
|
||||
&& (resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS || resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY);
|
||||
bool uav = (hlsl_deref_get_regset(tpf->ctx, resource) == HLSL_REGSET_UAVS);
|
||||
const struct vkd3d_shader_version *version = &tpf->program->shader_version;
|
||||
bool raw = resource_type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER;
|
||||
unsigned int coords_writemask = VKD3DSP_WRITEMASK_ALL;
|
||||
struct sm4_instruction instr;
|
||||
|
||||
memset(&instr, 0, sizeof(instr));
|
||||
if (uav)
|
||||
instr.opcode = VKD3D_SM5_OP_LD_UAV_TYPED;
|
||||
else if (raw)
|
||||
instr.opcode = VKD3D_SM5_OP_LD_RAW;
|
||||
else
|
||||
instr.opcode = multisampled ? VKD3D_SM4_OP_LD2DMS : VKD3D_SM4_OP_LD;
|
||||
|
||||
@@ -6227,6 +6238,7 @@ static void tpf_write_shdr(struct tpf_compiler *tpf, struct hlsl_ir_function_dec
|
||||
const struct hlsl_buffer *cbuffer;
|
||||
struct hlsl_ctx *ctx = tpf->ctx;
|
||||
size_t token_count_position;
|
||||
uint32_t global_flags = 0;
|
||||
|
||||
static const uint16_t shader_types[VKD3D_SHADER_TYPE_COUNT] =
|
||||
{
|
||||
@@ -6248,6 +6260,27 @@ static void tpf_write_shdr(struct tpf_compiler *tpf, struct hlsl_ir_function_dec
|
||||
put_u32(&buffer, vkd3d_make_u32((version->major << 4) | version->minor, shader_types[version->type]));
|
||||
token_count_position = put_u32(&buffer, 0);
|
||||
|
||||
if (version->major == 4)
|
||||
{
|
||||
for (i = 0; i < extern_resources_count; ++i)
|
||||
{
|
||||
const struct extern_resource *resource = &extern_resources[i];
|
||||
const struct hlsl_type *type = resource->component_type;
|
||||
|
||||
if (type && type->class == HLSL_CLASS_TEXTURE && type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER)
|
||||
{
|
||||
global_flags |= VKD3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entry_func->early_depth_test && vkd3d_shader_ver_ge(version, 5, 0))
|
||||
global_flags |= VKD3DSGF_FORCE_EARLY_DEPTH_STENCIL;
|
||||
|
||||
if (global_flags)
|
||||
write_sm4_dcl_global_flags(tpf, global_flags);
|
||||
|
||||
if (version->type == VKD3D_SHADER_TYPE_HULL)
|
||||
{
|
||||
tpf_write_hs_decls(tpf);
|
||||
@@ -6282,9 +6315,6 @@ static void tpf_write_shdr(struct tpf_compiler *tpf, struct hlsl_ir_function_dec
|
||||
write_sm4_dcl_textures(tpf, resource, true);
|
||||
}
|
||||
|
||||
if (entry_func->early_depth_test && vkd3d_shader_ver_ge(version, 5, 0))
|
||||
write_sm4_dcl_global_flags(tpf, VKD3DSGF_FORCE_EARLY_DEPTH_STENCIL);
|
||||
|
||||
if (version->type == VKD3D_SHADER_TYPE_HULL)
|
||||
tpf_write_hs_control_point_phase(tpf);
|
||||
|
||||
|
Reference in New Issue
Block a user