vkd3d-shader/glsl: Implement VKD3DSIH_SAMPLE_GRAD.

This commit is contained in:
Henri Verbeet 2024-10-18 21:21:15 +02:00
parent d58282c6d1
commit d477a00734
Notes: Henri Verbeet 2024-10-24 21:02:25 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1211
2 changed files with 44 additions and 23 deletions

View File

@ -20,8 +20,14 @@
struct glsl_resource_type_info struct glsl_resource_type_info
{ {
/* The number of coordinates needed to sample the resource type. */
size_t coord_size; size_t coord_size;
/* Whether the resource type is an array type. */
bool array;
/* Whether the resource type has a shadow/comparison variant. */
bool shadow; bool shadow;
/* The type suffix for resource type. I.e., the "2D" part of "usampler2D"
* or "iimage2D". */
const char *type_suffix; const char *type_suffix;
}; };
@ -102,17 +108,17 @@ static const struct glsl_resource_type_info *shader_glsl_get_resource_type_info(
{ {
static const struct glsl_resource_type_info info[] = static const struct glsl_resource_type_info info[] =
{ {
{0, 0, "None"}, /* VKD3D_SHADER_RESOURCE_NONE */ {0, 0, 0, "None"}, /* VKD3D_SHADER_RESOURCE_NONE */
{1, 0, "Buffer"}, /* VKD3D_SHADER_RESOURCE_BUFFER */ {1, 0, 0, "Buffer"}, /* VKD3D_SHADER_RESOURCE_BUFFER */
{1, 1, "1D"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_1D */ {1, 0, 1, "1D"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_1D */
{2, 1, "2D"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_2D */ {2, 0, 1, "2D"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_2D */
{2, 0, "2DMS"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_2DMS */ {2, 0, 0, "2DMS"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_2DMS */
{3, 0, "3D"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_3D */ {3, 0, 0, "3D"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_3D */
{3, 1, "Cube"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_CUBE */ {3, 0, 1, "Cube"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_CUBE */
{2, 1, "1DArray"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_1DARRAY */ {2, 1, 1, "1DArray"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_1DARRAY */
{3, 1, "2DArray"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_2DARRAY */ {3, 1, 1, "2DArray"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_2DARRAY */
{3, 0, "2DMSArray"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY */ {3, 1, 0, "2DMSArray"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY */
{4, 1, "CubeArray"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY */ {4, 1, 1, "CubeArray"}, /* VKD3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY */
}; };
if (!t || t >= ARRAY_SIZE(info)) if (!t || t >= ARRAY_SIZE(info))
@ -862,10 +868,10 @@ static void shader_glsl_print_shadow_coord(struct vkd3d_string_buffer *buffer, s
static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins) static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_instruction *ins)
{ {
bool shadow_sampler, array, bias, grad, lod, lod_zero, shadow;
const struct glsl_resource_type_info *resource_type_info; const struct glsl_resource_type_info *resource_type_info;
unsigned int resource_id, resource_idx, resource_space; unsigned int resource_id, resource_idx, resource_space;
unsigned int sampler_id, sampler_idx, sampler_space; unsigned int sampler_id, sampler_idx, sampler_space;
bool shadow_sampler, bias, lod, lod_zero, shadow;
const struct vkd3d_shader_descriptor_info1 *d; const struct vkd3d_shader_descriptor_info1 *d;
enum vkd3d_shader_component_type sampled_type; enum vkd3d_shader_component_type sampled_type;
enum vkd3d_shader_resource_type resource_type; enum vkd3d_shader_resource_type resource_type;
@ -875,6 +881,7 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
struct glsl_dst dst; struct glsl_dst dst;
bias = ins->opcode == VKD3DSIH_SAMPLE_B; bias = ins->opcode == VKD3DSIH_SAMPLE_B;
grad = ins->opcode == VKD3DSIH_SAMPLE_GRAD;
lod = ins->opcode == VKD3DSIH_SAMPLE_LOD || ins->opcode == VKD3DSIH_SAMPLE_C_LZ; lod = ins->opcode == VKD3DSIH_SAMPLE_LOD || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ; lod_zero = ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
shadow = ins->opcode == VKD3DSIH_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ; shadow = ins->opcode == VKD3DSIH_SAMPLE_C || ins->opcode == VKD3DSIH_SAMPLE_C_LZ;
@ -909,12 +916,14 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
if ((resource_type_info = shader_glsl_get_resource_type_info(resource_type))) if ((resource_type_info = shader_glsl_get_resource_type_info(resource_type)))
{ {
coord_size = resource_type_info->coord_size; coord_size = resource_type_info->coord_size;
array = resource_type_info->array;
} }
else else
{ {
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
"Internal compiler error: Unhandled resource type %#x.", resource_type); "Internal compiler error: Unhandled resource type %#x.", resource_type);
coord_size = 2; coord_size = 2;
array = false;
} }
sampler_id = ins->src[2].reg.idx[0].offset; sampler_id = ins->src[2].reg.idx[0].offset;
@ -947,7 +956,9 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
glsl_dst_init(&dst, gen, ins, &ins->dst[0]); glsl_dst_init(&dst, gen, ins, &ins->dst[0]);
sample = vkd3d_string_buffer_get(&gen->string_buffers); sample = vkd3d_string_buffer_get(&gen->string_buffers);
if (lod) if (grad)
vkd3d_string_buffer_printf(sample, "textureGrad(");
else if (lod)
vkd3d_string_buffer_printf(sample, "textureLod("); vkd3d_string_buffer_printf(sample, "textureLod(");
else else
vkd3d_string_buffer_printf(sample, "texture("); vkd3d_string_buffer_printf(sample, "texture(");
@ -958,7 +969,16 @@ static void shader_glsl_sample(struct vkd3d_glsl_generator *gen, const struct vk
else else
shader_glsl_print_src(sample, gen, &ins->src[0], shader_glsl_print_src(sample, gen, &ins->src[0],
vkd3d_write_mask_from_component_count(coord_size), ins->src[0].reg.data_type); vkd3d_write_mask_from_component_count(coord_size), ins->src[0].reg.data_type);
if (lod_zero) if (grad)
{
vkd3d_string_buffer_printf(sample, ", ");
shader_glsl_print_src(sample, gen, &ins->src[3],
vkd3d_write_mask_from_component_count(coord_size - array), ins->src[3].reg.data_type);
vkd3d_string_buffer_printf(sample, ", ");
shader_glsl_print_src(sample, gen, &ins->src[4],
vkd3d_write_mask_from_component_count(coord_size - array), ins->src[4].reg.data_type);
}
else if (lod_zero)
{ {
vkd3d_string_buffer_printf(sample, ", 0.0"); vkd3d_string_buffer_printf(sample, ", 0.0");
} }
@ -1564,6 +1584,7 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen,
case VKD3DSIH_SAMPLE_B: case VKD3DSIH_SAMPLE_B:
case VKD3DSIH_SAMPLE_C: case VKD3DSIH_SAMPLE_C:
case VKD3DSIH_SAMPLE_C_LZ: case VKD3DSIH_SAMPLE_C_LZ:
case VKD3DSIH_SAMPLE_GRAD:
case VKD3DSIH_SAMPLE_LOD: case VKD3DSIH_SAMPLE_LOD:
shader_glsl_sample(gen, ins); shader_glsl_sample(gen, ins);
break; break;

View File

@ -26,13 +26,13 @@ float4 main() : sv_target
[test] [test]
uniform 0 float4 0.0 0.0 0.0 0.0 uniform 0 float4 0.0 0.0 0.0 0.0
todo(glsl) draw quad draw quad
probe (0,0) rgba (1.0, 0.0, 1.0, 0.0) probe (0,0) rgba (1.0, 0.0, 1.0, 0.0)
uniform 0 float4 1.0 1.0 1.0 1.0 uniform 0 float4 1.0 1.0 1.0 1.0
todo(glsl) draw quad draw quad
probe (0,0) rgba (0.0, 0.0, 1.0, 0.0) probe (0,0) rgba (0.0, 0.0, 1.0, 0.0)
uniform 0 float4 2.0 2.0 2.0 2.0 uniform 0 float4 2.0 2.0 2.0 2.0
todo(glsl) draw quad draw quad
probe (0,0) rgba (0.0, 0.0, 1.0, 0.0) probe (0,0) rgba (0.0, 0.0, 1.0, 0.0)
[pixel shader fail(sm>=6)] [pixel shader fail(sm>=6)]
@ -46,13 +46,13 @@ float4 main() : sv_target
[test] [test]
uniform 0 float4 0.0 0.0 0.0 0.0 uniform 0 float4 0.0 0.0 0.0 0.0
todo(glsl) draw quad draw quad
probe (0,0) rgba (1.0, 0.0, 1.0, 0.0) probe (0,0) rgba (1.0, 0.0, 1.0, 0.0)
uniform 0 float4 1.0 1.0 1.0 1.0 uniform 0 float4 1.0 1.0 1.0 1.0
todo(glsl) draw quad draw quad
probe (0,0) rgba (0.0, 0.0, 1.0, 0.0) probe (0,0) rgba (0.0, 0.0, 1.0, 0.0)
uniform 0 float4 2.0 2.0 2.0 2.0 uniform 0 float4 2.0 2.0 2.0 2.0
todo(glsl) draw quad draw quad
probe (0,0) rgba (0.0, 0.0, 1.0, 0.0) probe (0,0) rgba (0.0, 0.0, 1.0, 0.0)
[require] [require]
@ -70,11 +70,11 @@ float4 main() : sv_target
[test] [test]
uniform 0 float4 0.0 0.0 0.0 0.0 uniform 0 float4 0.0 0.0 0.0 0.0
todo(glsl) draw quad draw quad
probe (0, 0) rgba (1.0, 0.0, 1.0, 0.0) probe (0, 0) rgba (1.0, 0.0, 1.0, 0.0)
uniform 0 float4 1.0 1.0 1.0 1.0 uniform 0 float4 1.0 1.0 1.0 1.0
todo(glsl) draw quad draw quad
probe (0, 0) rgba (0.0, 0.0, 1.0, 0.0) probe (0, 0) rgba (0.0, 0.0, 1.0, 0.0)
uniform 0 float4 2.0 2.0 2.0 2.0 uniform 0 float4 2.0 2.0 2.0 2.0
todo(glsl) draw quad draw quad
probe (0, 0) rgba (0.0, 0.0, 1.0, 0.0) probe (0, 0) rgba (0.0, 0.0, 1.0, 0.0)