wined3d: Do not modify shader register maps in backends.

Signed-off-by: Paul Gofman <gofmanp@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2019-07-03 17:56:40 +03:00 committed by Alexandre Julliard
parent 577c28d362
commit 9607a427de
4 changed files with 63 additions and 46 deletions

View File

@ -1407,18 +1407,28 @@ static const char *shader_arb_get_modifier(const struct wined3d_shader_instructi
static void shader_hw_sample(const struct wined3d_shader_instruction *ins, DWORD sampler_idx,
const char *dst_str, const char *coord_reg, WORD flags, const char *dsx, const char *dsy)
{
enum wined3d_shader_resource_type resource_type = ins->ctx->reg_maps->resource_info[sampler_idx].type;
struct wined3d_string_buffer *buffer = ins->ctx->buffer;
const char *tex_type;
BOOL np2_fixup = FALSE;
struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
const char *mod;
BOOL pshader = shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type);
const char *tex_dst = dst_str;
struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
struct wined3d_string_buffer *buffer = ins->ctx->buffer;
enum wined3d_shader_resource_type resource_type;
struct color_fixup_masks masks;
const char *tex_dst = dst_str;
BOOL np2_fixup = FALSE;
const char *tex_type;
const char *mod;
/* D3D vertex shader sampler IDs are vertex samplers(0-3), not global d3d samplers */
if(!pshader) sampler_idx += WINED3D_MAX_FRAGMENT_SAMPLERS;
if (pshader)
{
resource_type = pixelshader_get_resource_type(ins->ctx->reg_maps, sampler_idx,
priv->cur_ps_args->super.tex_types);
}
else
{
resource_type = ins->ctx->reg_maps->resource_info[sampler_idx].type;
/* D3D vertex shader sampler IDs are vertex samplers(0-3), not global d3d samplers */
sampler_idx += WINED3D_MAX_FRAGMENT_SAMPLERS;
}
switch (resource_type)
{
@ -1432,7 +1442,8 @@ static void shader_hw_sample(const struct wined3d_shader_instruction *ins, DWORD
tex_type = "RECT";
else
tex_type = "2D";
if (shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type))
if (pshader)
{
if (priv->cur_np2fixup_info->super.active & (1u << sampler_idx))
{
@ -4297,8 +4308,6 @@ static struct arb_ps_compiled_shader *find_arb_pshader(struct wined3d_context_gl
shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
pixelshader_update_resource_types(shader, args->super.tex_types);
if (!string_buffer_init(&buffer))
{
ERR("Failed to initialize shader buffer.\n");

View File

@ -2144,6 +2144,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context_gl *c
const struct wined3d_gl_info *gl_info = context_gl->c.gl_info;
const struct wined3d_shader_indexable_temp *idx_temp_reg;
unsigned int uniform_block_base, uniform_block_count;
enum wined3d_shader_resource_type resource_type;
const struct wined3d_shader_lconst *lconst;
const char *prefix;
unsigned int i;
@ -2299,7 +2300,11 @@ static void shader_generate_glsl_declarations(const struct wined3d_context_gl *c
}
shadow_sampler = glsl_is_shadow_sampler(shader, ps_args, entry->resource_idx, entry->sampler_idx);
switch (reg_maps->resource_info[entry->resource_idx].type)
resource_type = version->type == WINED3D_SHADER_TYPE_PIXEL
? pixelshader_get_resource_type(reg_maps, entry->resource_idx, ps_args->tex_types)
: reg_maps->resource_info[entry->resource_idx].type;
switch (resource_type)
{
case WINED3D_SHADER_RESOURCE_BUFFER:
sampler_type = "samplerBuffer";
@ -2376,7 +2381,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context_gl *c
default:
sampler_type = "unsupported_sampler";
FIXME("Unhandled resource type %#x.\n", reg_maps->resource_info[entry->resource_idx].type);
FIXME("Unhandled resource type %#x.\n", resource_type);
break;
}
@ -3322,7 +3327,7 @@ static void shader_glsl_get_coord_size(enum wined3d_shader_resource_type resourc
static void shader_glsl_get_sample_function(const struct wined3d_shader_context *ctx,
DWORD resource_idx, DWORD sampler_idx, DWORD flags, struct glsl_sample_function *sample_function)
{
enum wined3d_shader_resource_type resource_type = ctx->reg_maps->resource_info[resource_idx].type;
enum wined3d_shader_resource_type resource_type;
struct shader_glsl_ctx_priv *priv = ctx->backend_data;
const struct wined3d_gl_info *gl_info = ctx->gl_info;
BOOL shadow = glsl_is_shadow_sampler(ctx->shader, priv->cur_ps_args, resource_idx, sampler_idx);
@ -3336,6 +3341,10 @@ static void shader_glsl_get_sample_function(const struct wined3d_shader_context
const char *base = "texture", *type_part = "", *suffix = "";
unsigned int coord_size, deriv_size;
resource_type = ctx->reg_maps->shader_version.type == WINED3D_SHADER_TYPE_PIXEL
? pixelshader_get_resource_type(ctx->reg_maps, resource_idx, priv->cur_ps_args->tex_types)
: ctx->reg_maps->resource_info[resource_idx].type;
sample_function->data_type = ctx->reg_maps->resource_info[resource_idx].data_type;
if (resource_type >= ARRAY_SIZE(resource_type_info))
@ -5054,6 +5063,7 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
DWORD resource_idx;
DWORD mask = 0, swizzle;
const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
enum wined3d_shader_resource_type resource_type;
/* 1.0-1.4: Use destination register as sampler source.
* 2.0+: Use provided sampler source. */
@ -5062,11 +5072,14 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
else
resource_idx = ins->src[1].reg.idx[0].offset;
resource_type = ins->ctx->reg_maps->shader_version.type == WINED3D_SHADER_TYPE_PIXEL
? pixelshader_get_resource_type(ins->ctx->reg_maps, resource_idx, priv->cur_ps_args->tex_types)
: ins->ctx->reg_maps->resource_info[resource_idx].type;
if (shader_version < WINED3D_SHADER_VERSION(1,4))
{
DWORD flags = (priv->cur_ps_args->tex_transform >> resource_idx * WINED3D_PSARGS_TEXTRANSFORM_SHIFT)
& WINED3D_PSARGS_TEXTRANSFORM_MASK;
enum wined3d_shader_resource_type resource_type = ins->ctx->reg_maps->resource_info[resource_idx].type;
/* Projected cube textures don't make a lot of sense, the resulting coordinates stay the same. */
if (flags & WINED3D_PSARGS_PROJECTED && resource_type != WINED3D_SHADER_RESOURCE_TEXTURE_CUBE)
@ -5105,7 +5118,7 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
else
{
if ((ins->flags & WINED3DSI_TEXLD_PROJECT)
&& ins->ctx->reg_maps->resource_info[resource_idx].type != WINED3D_SHADER_RESOURCE_TEXTURE_CUBE)
&& resource_type != WINED3D_SHADER_RESOURCE_TEXTURE_CUBE)
{
/* ps 2.0 texldp instruction always divides by the fourth component. */
sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED;
@ -7588,10 +7601,14 @@ static GLuint shader_glsl_generate_fragment_shader(const struct wined3d_context_
for (i = 0; i < shader->limits->sampler; ++i)
{
if (!reg_maps->resource_info[i].type || !(args->np2_fixup & (1u << i)))
enum wined3d_shader_resource_type resource_type;
resource_type = pixelshader_get_resource_type(reg_maps, i, args->tex_types);
if (!resource_type || !(args->np2_fixup & (1u << i)))
continue;
if (reg_maps->resource_info[i].type != WINED3D_SHADER_RESOURCE_TEXTURE_2D)
if (resource_type != WINED3D_SHADER_RESOURCE_TEXTURE_2D)
{
FIXME("Non-2D texture is flagged for NP2 texcoord fixup.\n");
continue;
@ -8439,8 +8456,6 @@ static GLuint find_glsl_fragment_shader(const struct wined3d_context_gl *context
memset(np2fixup, 0, sizeof(*np2fixup));
*np2fixup_info = args->np2_fixup ? np2fixup : NULL;
pixelshader_update_resource_types(shader, args->tex_types);
string_buffer_clear(buffer);
ret = shader_glsl_generate_fragment_shader(context_gl, buffer, string_buffers, shader, args, np2fixup);
gl_shaders[shader_data->num_gl_shaders++].id = ret;

View File

@ -4200,35 +4200,27 @@ static HRESULT pixel_shader_init(struct wined3d_shader *shader, struct wined3d_d
return WINED3D_OK;
}
void pixelshader_update_resource_types(struct wined3d_shader *shader, WORD tex_types)
enum wined3d_shader_resource_type pixelshader_get_resource_type(const struct wined3d_shader_reg_maps *reg_maps,
unsigned int resource_idx, WORD tex_types)
{
struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
struct wined3d_shader_resource_info *resource_info = reg_maps->resource_info;
unsigned int i;
if (reg_maps->shader_version.major != 1) return;
for (i = 0; i < shader->limits->sampler; ++i)
static enum wined3d_shader_resource_type shader_resource_type_from_shader_tex_types[] =
{
/* We don't sample from this sampler. */
if (!resource_info[i].type)
continue;
WINED3D_SHADER_RESOURCE_TEXTURE_2D, /* WINED3D_SHADER_TEX_2D */
WINED3D_SHADER_RESOURCE_TEXTURE_3D, /* WINED3D_SHADER_TEX_3D */
WINED3D_SHADER_RESOURCE_TEXTURE_CUBE, /* WINED3D_SHADER_TEX_CUBE */
};
switch ((tex_types >> i * WINED3D_PSARGS_TEXTYPE_SHIFT) & WINED3D_PSARGS_TEXTYPE_MASK)
{
case WINED3D_SHADER_TEX_2D:
resource_info[i].type = WINED3D_SHADER_RESOURCE_TEXTURE_2D;
break;
unsigned int idx;
case WINED3D_SHADER_TEX_3D:
resource_info[i].type = WINED3D_SHADER_RESOURCE_TEXTURE_3D;
break;
if (reg_maps->shader_version.major != 1)
return reg_maps->resource_info[resource_idx].type;
case WINED3D_SHADER_TEX_CUBE:
resource_info[i].type = WINED3D_SHADER_RESOURCE_TEXTURE_CUBE;
break;
}
}
if (!reg_maps->resource_info[resource_idx].type)
return 0;
idx = (tex_types >> resource_idx * WINED3D_PSARGS_TEXTYPE_SHIFT) & WINED3D_PSARGS_TEXTYPE_MASK;
assert(idx < ARRAY_SIZE(shader_resource_type_from_shader_tex_types));
return shader_resource_type_from_shader_tex_types[idx];
}
HRESULT CDECL wined3d_shader_create_cs(struct wined3d_device *device, const struct wined3d_shader_desc *desc,

View File

@ -4444,7 +4444,8 @@ struct wined3d_shader
} u;
};
void pixelshader_update_resource_types(struct wined3d_shader *shader, WORD tex_types) DECLSPEC_HIDDEN;
enum wined3d_shader_resource_type pixelshader_get_resource_type(const struct wined3d_shader_reg_maps *reg_maps,
unsigned int resource_idx, WORD tex_types) DECLSPEC_HIDDEN;
void find_ps_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
BOOL position_transformed, struct ps_compile_args *args,
const struct wined3d_context *context) DECLSPEC_HIDDEN;