mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Parse the Sample() method.
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
committed by
Alexandre Julliard
parent
4dfe66b1f1
commit
d76d777876
@ -627,8 +627,9 @@ struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
|
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
|
||||||
enum hlsl_resource_load_type type, struct hlsl_ir_var *resource, struct hlsl_ir_node *offset,
|
enum hlsl_resource_load_type type, struct hlsl_ir_var *resource, struct hlsl_ir_node *resource_offset,
|
||||||
struct hlsl_ir_node *coords, const struct vkd3d_shader_location *loc)
|
struct hlsl_ir_var *sampler, struct hlsl_ir_node *sampler_offset, struct hlsl_ir_node *coords,
|
||||||
|
const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_resource_load *load;
|
struct hlsl_ir_resource_load *load;
|
||||||
|
|
||||||
@ -637,7 +638,9 @@ struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struc
|
|||||||
init_node(&load->node, HLSL_IR_RESOURCE_LOAD, data_type, *loc);
|
init_node(&load->node, HLSL_IR_RESOURCE_LOAD, data_type, *loc);
|
||||||
load->load_type = type;
|
load->load_type = type;
|
||||||
load->resource.var = resource;
|
load->resource.var = resource;
|
||||||
hlsl_src_from_node(&load->resource.offset, offset);
|
hlsl_src_from_node(&load->resource.offset, resource_offset);
|
||||||
|
load->sampler.var = sampler;
|
||||||
|
hlsl_src_from_node(&load->sampler.offset, sampler_offset);
|
||||||
hlsl_src_from_node(&load->coords, coords);
|
hlsl_src_from_node(&load->coords, coords);
|
||||||
return load;
|
return load;
|
||||||
}
|
}
|
||||||
@ -1059,12 +1062,19 @@ static void dump_ir_var(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer
|
|||||||
|
|
||||||
static void dump_deref(struct vkd3d_string_buffer *buffer, const struct hlsl_deref *deref)
|
static void dump_deref(struct vkd3d_string_buffer *buffer, const struct hlsl_deref *deref)
|
||||||
{
|
{
|
||||||
vkd3d_string_buffer_printf(buffer, "%s", deref->var->name);
|
if (deref->var)
|
||||||
if (deref->offset.node)
|
|
||||||
{
|
{
|
||||||
vkd3d_string_buffer_printf(buffer, "[");
|
vkd3d_string_buffer_printf(buffer, "%s", deref->var->name);
|
||||||
dump_src(buffer, &deref->offset);
|
if (deref->offset.node)
|
||||||
vkd3d_string_buffer_printf(buffer, "]");
|
{
|
||||||
|
vkd3d_string_buffer_printf(buffer, "[");
|
||||||
|
dump_src(buffer, &deref->offset);
|
||||||
|
vkd3d_string_buffer_printf(buffer, "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vkd3d_string_buffer_printf(buffer, "(nil)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1239,10 +1249,13 @@ static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const stru
|
|||||||
static const char *const type_names[] =
|
static const char *const type_names[] =
|
||||||
{
|
{
|
||||||
[HLSL_RESOURCE_LOAD] = "load_resource",
|
[HLSL_RESOURCE_LOAD] = "load_resource",
|
||||||
|
[HLSL_RESOURCE_SAMPLE] = "sample",
|
||||||
};
|
};
|
||||||
|
|
||||||
vkd3d_string_buffer_printf(buffer, "%s(resource = ", type_names[load->load_type]);
|
vkd3d_string_buffer_printf(buffer, "%s(resource = ", type_names[load->load_type]);
|
||||||
dump_deref(buffer, &load->resource);
|
dump_deref(buffer, &load->resource);
|
||||||
|
vkd3d_string_buffer_printf(buffer, ", sampler = ");
|
||||||
|
dump_deref(buffer, &load->sampler);
|
||||||
vkd3d_string_buffer_printf(buffer, ", coords = ");
|
vkd3d_string_buffer_printf(buffer, ", coords = ");
|
||||||
dump_src(buffer, &load->coords);
|
dump_src(buffer, &load->coords);
|
||||||
vkd3d_string_buffer_printf(buffer, ")");
|
vkd3d_string_buffer_printf(buffer, ")");
|
||||||
@ -1419,6 +1432,7 @@ static void free_ir_loop(struct hlsl_ir_loop *loop)
|
|||||||
static void free_ir_resource_load(struct hlsl_ir_resource_load *load)
|
static void free_ir_resource_load(struct hlsl_ir_resource_load *load)
|
||||||
{
|
{
|
||||||
hlsl_src_remove(&load->coords);
|
hlsl_src_remove(&load->coords);
|
||||||
|
hlsl_src_remove(&load->sampler.offset);
|
||||||
hlsl_src_remove(&load->resource.offset);
|
hlsl_src_remove(&load->resource.offset);
|
||||||
vkd3d_free(load);
|
vkd3d_free(load);
|
||||||
}
|
}
|
||||||
|
@ -376,13 +376,14 @@ struct hlsl_ir_load
|
|||||||
enum hlsl_resource_load_type
|
enum hlsl_resource_load_type
|
||||||
{
|
{
|
||||||
HLSL_RESOURCE_LOAD,
|
HLSL_RESOURCE_LOAD,
|
||||||
|
HLSL_RESOURCE_SAMPLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hlsl_ir_resource_load
|
struct hlsl_ir_resource_load
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node node;
|
struct hlsl_ir_node node;
|
||||||
enum hlsl_resource_load_type load_type;
|
enum hlsl_resource_load_type load_type;
|
||||||
struct hlsl_deref resource;
|
struct hlsl_deref resource, sampler;
|
||||||
struct hlsl_src coords;
|
struct hlsl_src coords;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -703,8 +704,9 @@ struct hlsl_ir_load *hlsl_new_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var
|
|||||||
struct hlsl_type *type, struct vkd3d_shader_location loc);
|
struct hlsl_type *type, struct vkd3d_shader_location loc);
|
||||||
struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc);
|
struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc);
|
||||||
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
|
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
|
||||||
enum hlsl_resource_load_type type, struct hlsl_ir_var *resource, struct hlsl_ir_node *offset,
|
enum hlsl_resource_load_type type, struct hlsl_ir_var *resource, struct hlsl_ir_node *resource_offset,
|
||||||
struct hlsl_ir_node *coords, const struct vkd3d_shader_location *loc);
|
struct hlsl_ir_var *sampler, struct hlsl_ir_node *sampler_offset, struct hlsl_ir_node *coords,
|
||||||
|
const struct vkd3d_shader_location *loc);
|
||||||
struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs);
|
struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs);
|
||||||
struct hlsl_ir_store *hlsl_new_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
struct hlsl_ir_store *hlsl_new_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
||||||
struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc);
|
struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc);
|
||||||
|
@ -1803,7 +1803,51 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(load = hlsl_new_resource_load(ctx, object_type->e.resource_format, HLSL_RESOURCE_LOAD,
|
if (!(load = hlsl_new_resource_load(ctx, object_type->e.resource_format, HLSL_RESOURCE_LOAD,
|
||||||
object_load->src.var, object_load->src.offset.node, coords, loc)))
|
object_load->src.var, object_load->src.offset.node, NULL, NULL, coords, loc)))
|
||||||
|
return false;
|
||||||
|
list_add_tail(instrs, &load->node.entry);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (!strcmp(name, "Sample"))
|
||||||
|
{
|
||||||
|
const unsigned int sampler_dim = sampler_dim_count(object_type->sampler_dim);
|
||||||
|
const struct hlsl_type *sampler_type;
|
||||||
|
struct hlsl_ir_resource_load *load;
|
||||||
|
struct hlsl_ir_load *sampler_load;
|
||||||
|
struct hlsl_ir_node *coords;
|
||||||
|
|
||||||
|
if (params->args_count != 2 && params->args_count != 3)
|
||||||
|
{
|
||||||
|
hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
|
||||||
|
"Wrong number of arguments to method 'Sample': expected 2 or 3, but got %u.", params->args_count);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (params->args_count == 3)
|
||||||
|
FIXME("Ignoring offset parameter.\n");
|
||||||
|
|
||||||
|
sampler_type = params->args[0]->data_type;
|
||||||
|
if (sampler_type->type != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER
|
||||||
|
|| sampler_type->sampler_dim != HLSL_SAMPLER_DIM_GENERIC)
|
||||||
|
{
|
||||||
|
struct vkd3d_string_buffer *string;
|
||||||
|
|
||||||
|
if ((string = hlsl_type_to_string(ctx, sampler_type)))
|
||||||
|
hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
|
||||||
|
"Wrong type for argument 0 of Sample(): expected 'sampler', but got '%s'.", string->buffer);
|
||||||
|
hlsl_release_string_buffer(ctx, string);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Only HLSL_IR_LOAD can return an object. */
|
||||||
|
sampler_load = hlsl_ir_load(params->args[0]);
|
||||||
|
|
||||||
|
if (!(coords = add_implicit_conversion(ctx, instrs, params->args[1],
|
||||||
|
hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, sampler_dim), loc)))
|
||||||
|
coords = params->args[1];
|
||||||
|
|
||||||
|
if (!(load = hlsl_new_resource_load(ctx, object_type->e.resource_format,
|
||||||
|
HLSL_RESOURCE_SAMPLE, object_load->src.var, object_load->src.offset.node,
|
||||||
|
sampler_load->src.var, sampler_load->src.offset.node, coords, loc)))
|
||||||
return false;
|
return false;
|
||||||
list_add_tail(instrs, &load->node.entry);
|
list_add_tail(instrs, &load->node.entry);
|
||||||
return true;
|
return true;
|
||||||
|
@ -651,6 +651,14 @@ static void compute_liveness_recurse(struct hlsl_block *block, unsigned int loop
|
|||||||
var->last_read = max(var->last_read, var_last_read);
|
var->last_read = max(var->last_read, var_last_read);
|
||||||
if (load->resource.offset.node)
|
if (load->resource.offset.node)
|
||||||
load->resource.offset.node->last_read = instr->index;
|
load->resource.offset.node->last_read = instr->index;
|
||||||
|
|
||||||
|
if ((var = load->sampler.var))
|
||||||
|
{
|
||||||
|
var->last_read = max(var->last_read, var_last_read);
|
||||||
|
if (load->sampler.offset.node)
|
||||||
|
load->sampler.offset.node->last_read = instr->index;
|
||||||
|
}
|
||||||
|
|
||||||
load->coords.node->last_read = instr->index;
|
load->coords.node->last_read = instr->index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1449,6 +1449,10 @@ static void write_sm4_resource_load(struct hlsl_ctx *ctx,
|
|||||||
case HLSL_RESOURCE_LOAD:
|
case HLSL_RESOURCE_LOAD:
|
||||||
write_sm4_ld(ctx, buffer, resource_type, &load->node, &load->resource, coords);
|
write_sm4_ld(ctx, buffer, resource_type, &load->node, &load->resource, coords);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case HLSL_RESOURCE_SAMPLE:
|
||||||
|
hlsl_fixme(ctx, load->node.loc, "Resource sample instruction.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user