[PATCH vkd3d 6/8] vkd3d-shader/glsl: Implement VKD3DSIH_ITOF.

Henri Verbeet hverbeet at gmail.com
Wed Aug 18 07:28:12 CDT 2021


On Wed, 18 Aug 2021 at 06:20, Atharva Nimbalkar <atharvakn at gmail.com> wrote:
> +/* Writes the GLSL variable name that corresponds to the register that the
> + * DX opcode parameter is trying to access */
> +static void shader_glsl_get_register_name(struct vkd3d_glsl_generator *gen,
> +        const struct vkd3d_shader_register *reg, enum vkd3d_data_type data_type,
> +        struct vkd3d_string_buffer *register_name, bool *is_swizzled)
> +{
> +    /* TODO: Add implementation
> +     * Sets an error state as of now
> +     */
> +    if(is_swizzled)
> +        *is_swizzled = false;
> +    vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
> +            "Internal compiler error: Unhandled register type %#x.", reg->type);
> +}
> +
There's a missing space between "if" and "is_swizzled".

> +/* Append the destination part of the instruction to the buffer, return the effective write mask */
> +static void shader_glsl_append_dst(struct vkd3d_glsl_generator *gen,
> +        struct vkd3d_string_buffer *buffer,
> +        const struct vkd3d_shader_instruction *ins,
> +        struct glsl_dst_param *dst_param)
> +{
> +    if (ins->flags & VKD3DSI_PRECISE_XYZW)
> +        vkd3d_string_buffer_printf(dst_param->reg_name, "tmp_precise[%u]", 0);
> +
That doesn't quite do the right thing. vkd3d_string_buffer_printf()
appends to the existing buffer, it doesn't replace it. More, we don't
actually want to modify "dst_param" here. The right thing to do would
probably be to handle VKD3DSI_PRECISE_XYZW in
shader_glsl_print_assignment() instead of here, but there's also no
need to handle VKD3DSI_PRECISE_XYZW in this patch, so it's best
deferred until a later patch.

> +    switch (ins->dst[0].reg.data_type)
> +    {
> +        case VKD3D_DATA_FLOAT:
> +            vkd3d_string_buffer_printf(buffer, "%s%s = %s(",
> +                dst_param->reg_name->buffer, dst_param->mask_str->buffer, shift_glsl_tab[ins->dst[0].shift]);
> +            break;
> +        default:
> +            vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
> +                "Unhandled data type %#x.", ins->dst[0].reg.data_type);
> +            vkd3d_string_buffer_printf(buffer, "%s%s = %s(",
> +                dst_param->reg_name->buffer, dst_param->mask_str->buffer, shift_glsl_tab[ins->dst[0].shift]);
> +            break;
> +    }
> +}
> +
8-space (i.e., double) indent for line continuations, please.

> +static void shader_glsl_cast(struct vkd3d_glsl_generator *gen,
> +        const struct vkd3d_shader_instruction *ins,
> +        const char *vector_constructor, const char *scalar_constructor)
> +{
> +    struct glsl_src_param src_param;
> +    struct glsl_dst_param dst_param;
> +
> +    unsigned int write_mask = glsl_dst_param_init(gen, &ins->dst[0], &dst_param);
> +    uint32_t mask_size = vkd3d_write_mask_component_count(write_mask);
> +    glsl_src_param_init(gen, &ins->src[0], write_mask, &src_param);
> +    if (mask_size > 1)
> +        shader_glsl_print_assignment(gen, ins, &dst_param, "%s%u(%s));\n", vector_constructor, mask_size, src_param.param_str->buffer);
> +    else
> +        shader_glsl_print_assignment(gen, ins, &dst_param, "%s(%s));\n", scalar_constructor, src_param.param_str->buffer);
> +
> +    glsl_src_param_cleanup(&src_param, &gen->string_buffers);
> +    glsl_dst_param_cleanup(&dst_param, &gen->string_buffers);
> +}

We could take shader_glsl_print_assignment() one step further, and
print the trailing ");\n" in shader_glsl_print_assignment() as well,
so that we get the following here:

    if (mask_size > 1)
        shader_glsl_print_assignment(gen, ins, &dst_param, "%s%u(%s)",
                vector_constructor, mask_size, src_param.param_str->buffer);
    else
        shader_glsl_print_assignment(gen, ins, &dst_param, "%s(%s)",
                scalar_constructor, src_param.param_str->buffer);



More information about the wine-devel mailing list