Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/wined3d/arb_program_shader.c | 31 +++++++++++++++--------- dlls/wined3d/glsl_shader.c | 33 ++++++++++++++++++------- dlls/wined3d/shader.c | 40 +++++++++++++------------------ dlls/wined3d/wined3d_private.h | 3 ++- 4 files changed, 62 insertions(+), 45 deletions(-)
diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c index c07b23ae71..15d13a234b 100644 --- a/dlls/wined3d/arb_program_shader.c +++ b/dlls/wined3d/arb_program_shader.c @@ -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; + BOOL pshader = shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type); + struct shader_arb_ctx_priv *priv = ins->ctx->backend_data; struct wined3d_string_buffer *buffer = ins->ctx->buffer; - const char *tex_type; + enum wined3d_shader_resource_type resource_type; + struct color_fixup_masks masks; + const char *tex_dst = dst_str; BOOL np2_fixup = FALSE; - struct shader_arb_ctx_priv *priv = ins->ctx->backend_data; + const char *tex_type; const char *mod; - BOOL pshader = shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type); - const char *tex_dst = dst_str; - struct color_fixup_masks masks;
- /* 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"); diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 53169b8e46..452f5d15d9 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -2282,6 +2282,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; @@ -2446,7 +2447,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"; @@ -2523,7 +2528,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; }
@@ -3469,7 +3474,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); @@ -3483,6 +3488,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)) @@ -5201,6 +5210,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. */ @@ -5209,11 +5219,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) @@ -5252,7 +5265,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; @@ -7735,10 +7748,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; @@ -8586,8 +8603,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; diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index 68cea78778..73acb65a19 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -4220,35 +4220,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, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 77813515b4..f9596e9c85 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4455,7 +4455,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;