[PATCH vkd3d 5/6] vkd3d-shader: Write the SM1 constant table.

Henri Verbeet hverbeet at gmail.com
Wed Apr 14 07:57:43 CDT 2021


On Wed, 14 Apr 2021 at 07:03, Zebediah Figura <zfigura at codeweavers.com> wrote:
> diff --git a/include/vkd3d_d3dx9shader.h b/include/vkd3d_d3dx9shader.h
> new file mode 100644
> index 00000000..ba69efbd
> --- /dev/null
> +++ b/include/vkd3d_d3dx9shader.h
Should this be an IDL file? I'm not sure how much of d3dx9shader.h we
intend to provide, but it does have COM interfaces like
ID3DXConstantTable.

> +static void put_string(struct bytecode_buffer *buffer, const char *str)
> +{
> +    unsigned int len = (strlen(str) + 1 + 3) / sizeof(DWORD);
> +
sizeof(*buffer->data), perhaps.

> +    if (buffer->status)
> +        return;
> +
> +    if (!vkd3d_array_reserve((void **)&buffer->data, &buffer->size, buffer->count + len, sizeof(*buffer->data)))
> +    {
> +        buffer->status = E_OUTOFMEMORY;
> +        return;
> +    }
> +
> +    buffer->data[buffer->count + len - 1] = 0xabababab;
> +    strcpy((char *)(buffer->data + buffer->count), str);
> +    buffer->count += len;
> +}
You pretty much never want to use strcpy(). In this particular case,
we already calculated the string length above, and could use memcpy().

> +static void write_sm1_uniforms(struct hlsl_ctx *ctx, struct bytecode_buffer *buffer,
> +        struct hlsl_ir_function_decl *entry_func)
> +{
> +    unsigned int ctab_start, vars_start;
> +    unsigned int uniform_count = 0;
> +    struct hlsl_ir_var *var;
> +
> +    LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry)
> +    {
> +        if (!var->semantic && var->reg.allocated)
> +        {
> +            ++uniform_count;
> +
> +            if (var->is_param && var->is_uniform)
> +            {
> +                char *name;
> +
> +                if (!(name = vkd3d_malloc(strlen(var->name) + 2)))
> +                {
> +                    buffer->status = VKD3D_ERROR_OUT_OF_MEMORY;
> +                    return;
> +                }
> +                name[0] = '$';
> +                strcpy(name + 1, var->name);
> +                vkd3d_free((char *)var->name);
> +                var->name = name;
> +            }
> +        }
> +    }
> +
Likewise.

> +    set_dword(buffer, ctab_start + 1, (buffer->count - ctab_start) * sizeof(DWORD));
> +    put_string(buffer, "vkd3d HLSL shader compiler");
> +
I imagine we would want to include the version here, perhaps even
simply the output of vkd3d_shader_get_version().



More information about the wine-devel mailing list