vkd3d-shader/hlsl: Implement SampleBias() method.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2023-04-19 19:24:14 +02:00 committed by Alexandre Julliard
parent c166ab9727
commit af4bb03795
Notes: Alexandre Julliard 2023-04-26 22:59:27 +02:00
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/172
5 changed files with 60 additions and 12 deletions

View File

@ -2383,6 +2383,7 @@ static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const stru
[HLSL_RESOURCE_LOAD] = "load_resource",
[HLSL_RESOURCE_SAMPLE] = "sample",
[HLSL_RESOURCE_SAMPLE_LOD] = "sample_lod",
[HLSL_RESOURCE_SAMPLE_LOD_BIAS] = "sample_biased",
[HLSL_RESOURCE_GATHER_RED] = "gather_red",
[HLSL_RESOURCE_GATHER_GREEN] = "gather_green",
[HLSL_RESOURCE_GATHER_BLUE] = "gather_blue",

View File

@ -588,6 +588,7 @@ enum hlsl_resource_load_type
HLSL_RESOURCE_LOAD,
HLSL_RESOURCE_SAMPLE,
HLSL_RESOURCE_SAMPLE_LOD,
HLSL_RESOURCE_SAMPLE_LOD_BIAS,
HLSL_RESOURCE_GATHER_RED,
HLSL_RESOURCE_GATHER_GREEN,
HLSL_RESOURCE_GATHER_BLUE,

View File

@ -3819,21 +3819,26 @@ static bool add_gather_method_call(struct hlsl_ctx *ctx, struct list *instrs, st
return true;
}
static bool add_sample_level_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
static bool add_sample_lod_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
const struct hlsl_type *object_type = object->data_type;
struct hlsl_resource_load_params load_params = {.type = HLSL_RESOURCE_SAMPLE_LOD};
struct hlsl_resource_load_params load_params = { 0 };
const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim);
const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim);
const struct hlsl_type *sampler_type;
struct hlsl_ir_resource_load *load;
if (!strcmp(name, "SampleLevel"))
load_params.type = HLSL_RESOURCE_SAMPLE_LOD;
else
load_params.type = HLSL_RESOURCE_SAMPLE_LOD_BIAS;
if (params->args_count < 3 || params->args_count > 4 + !!offset_dim)
{
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Wrong number of arguments to method 'SampleLevel': expected from 3 to %u, but got %u.",
4 + !!offset_dim, params->args_count);
"Wrong number of arguments to method '%s': expected from 3 to %u, but got %u.",
name, 4 + !!offset_dim, params->args_count);
return false;
}
@ -3845,7 +3850,7 @@ static bool add_sample_level_method_call(struct hlsl_ctx *ctx, struct list *inst
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 SampleLevel(): expected 'sampler', but got '%s'.", string->buffer);
"Wrong type for argument 0 of %s(): expected 'sampler', but got '%s'.", name, string->buffer);
hlsl_release_string_buffer(ctx, string);
return false;
}
@ -3920,7 +3925,13 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
&& object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS
&& object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY)
{
return add_sample_level_method_call(ctx, instrs, object, name, params, loc);
return add_sample_lod_method_call(ctx, instrs, object, name, params, loc);
}
else if (!strcmp(name, "SampleBias")
&& object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS
&& object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY)
{
return add_sample_lod_method_call(ctx, instrs, object, name, params, loc);
}
else
{

View File

@ -3700,14 +3700,30 @@ static void write_sm4_ld(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buf
}
static void write_sm4_sample(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer,
const struct hlsl_type *resource_type, const struct hlsl_ir_node *dst,
const struct hlsl_deref *resource, const struct hlsl_deref *sampler,
const struct hlsl_ir_node *coords, const struct hlsl_ir_node *texel_offset)
const struct hlsl_ir_resource_load *load)
{
const struct hlsl_type *resource_type = load->resource.var->data_type;
const struct hlsl_ir_node *texel_offset = load->texel_offset.node;
const struct hlsl_ir_node *coords = load->coords.node;
const struct hlsl_deref *resource = &load->resource;
const struct hlsl_deref *sampler = &load->sampler;
const struct hlsl_ir_node *dst = &load->node;
struct sm4_instruction instr;
memset(&instr, 0, sizeof(instr));
instr.opcode = VKD3D_SM4_OP_SAMPLE;
switch (load->load_type)
{
case HLSL_RESOURCE_SAMPLE:
instr.opcode = VKD3D_SM4_OP_SAMPLE;
break;
case HLSL_RESOURCE_SAMPLE_LOD_BIAS:
instr.opcode = VKD3D_SM4_OP_SAMPLE_B;
break;
default:
vkd3d_unreachable();
}
if (texel_offset)
{
@ -3727,6 +3743,12 @@ static void write_sm4_sample(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer
sm4_src_from_deref(ctx, &instr.srcs[2], sampler, sampler->var->data_type, VKD3DSP_WRITEMASK_ALL);
instr.src_count = 3;
if (load->load_type == HLSL_RESOURCE_SAMPLE_LOD_BIAS)
{
sm4_src_from_node(&instr.srcs[3], load->lod.node, VKD3DSP_WRITEMASK_ALL);
++instr.src_count;
}
write_sm4_instruction(buffer, &instr);
}
@ -4478,13 +4500,13 @@ static void write_sm4_resource_load(struct hlsl_ctx *ctx,
break;
case HLSL_RESOURCE_SAMPLE:
case HLSL_RESOURCE_SAMPLE_LOD_BIAS:
if (!load->sampler.var)
{
hlsl_fixme(ctx, &load->node.loc, "SM4 combined sample expression.");
return;
}
write_sm4_sample(ctx, buffer, resource_type, &load->node,
&load->resource, &load->sampler, coords, texel_offset);
write_sm4_sample(ctx, buffer, load);
break;
case HLSL_RESOURCE_GATHER_RED:

View File

@ -32,3 +32,16 @@ float4 main() : sv_target
[test]
draw quad
probe all rgba (0.25, 0, 0.25, 0)
[pixel shader]
SamplerState s;
Texture2D t;
float4 main() : sv_target
{
return t.SampleBias(s, float2(0.5, 0.5), 0.0);
}
[test]
draw quad
probe all rgba (0.25, 0, 0.25, 0)