Commit f5cef437 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Store resource types instead of sampler types in struct wined3d_shader_reg_maps.

The difference doesn't really matter for SM1-3 since resources and samplers are always tied together, but in SM4 they're separate.
parent 5ccda82a
......@@ -1390,8 +1390,8 @@ 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_type[sampler_idx];
struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
DWORD sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
const char *tex_type;
BOOL np2_fixup = FALSE;
struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
......@@ -1404,12 +1404,13 @@ static void shader_hw_sample(const struct wined3d_shader_instruction *ins, DWORD
/* D3D vertex shader sampler IDs are vertex samplers(0-3), not global d3d samplers */
if(!pshader) sampler_idx += MAX_FRAGMENT_SAMPLERS;
switch(sampler_type) {
case WINED3DSTT_1D:
switch (resource_type)
{
case WINED3D_SHADER_RESOURCE_TEXTURE_1D:
tex_type = "1D";
break;
case WINED3DSTT_2D:
case WINED3D_SHADER_RESOURCE_TEXTURE_2D:
shader = ins->ctx->shader;
device = shader->device;
gl_info = &device->adapter->gl_info;
......@@ -1429,16 +1430,16 @@ static void shader_hw_sample(const struct wined3d_shader_instruction *ins, DWORD
}
break;
case WINED3DSTT_VOLUME:
case WINED3D_SHADER_RESOURCE_TEXTURE_3D:
tex_type = "3D";
break;
case WINED3DSTT_CUBE:
case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE:
tex_type = "CUBE";
break;
default:
ERR("Unexpected texture type %d\n", sampler_type);
ERR("Unexpected resource type %#x.\n", resource_type);
tex_type = "";
}
......@@ -4376,7 +4377,7 @@ static struct arb_ps_compiled_shader *find_arb_pshader(struct wined3d_shader *sh
shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
pixelshader_update_samplers(shader, args->super.tex_types);
pixelshader_update_resource_types(shader, args->super.tex_types);
if (!shader_buffer_init(&buffer))
{
......
......@@ -2585,14 +2585,14 @@ static void context_map_fixed_function_samplers(struct wined3d_context *context,
static void context_map_psamplers(struct wined3d_context *context, const struct wined3d_state *state)
{
const enum wined3d_sampler_texture_type *sampler_type =
state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.sampler_type;
const enum wined3d_shader_resource_type *resource_type =
state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.resource_type;
unsigned int i;
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
{
if (sampler_type[i] && context->tex_unit_map[i] != i)
if (resource_type[i] && context->tex_unit_map[i] != i)
{
context_map_stage(context, i, i);
context_invalidate_state(context, STATE_SAMPLER(i));
......@@ -2603,8 +2603,8 @@ static void context_map_psamplers(struct wined3d_context *context, const struct
}
static BOOL context_unit_free_for_vs(const struct wined3d_context *context,
const enum wined3d_sampler_texture_type *pshader_sampler_tokens,
const enum wined3d_sampler_texture_type *vshader_sampler_tokens, DWORD unit)
const enum wined3d_shader_resource_type *ps_resource_types,
const enum wined3d_shader_resource_type *vs_resource_types, DWORD unit)
{
DWORD current_mapping = context->rev_tex_unit_map[unit];
......@@ -2616,39 +2616,39 @@ static BOOL context_unit_free_for_vs(const struct wined3d_context *context,
{
/* Used by a fragment sampler */
if (!pshader_sampler_tokens)
if (!ps_resource_types)
{
/* No pixel shader, check fixed function */
return current_mapping >= MAX_TEXTURES || !(context->fixed_function_usage_map & (1 << current_mapping));
}
/* Pixel shader, check the shader's sampler map */
return !pshader_sampler_tokens[current_mapping];
return !ps_resource_types[current_mapping];
}
/* Used by a vertex sampler */
return !vshader_sampler_tokens[current_mapping - MAX_FRAGMENT_SAMPLERS];
return !vs_resource_types[current_mapping - MAX_FRAGMENT_SAMPLERS];
}
static void context_map_vsamplers(struct wined3d_context *context, BOOL ps, const struct wined3d_state *state)
{
const enum wined3d_sampler_texture_type *vshader_sampler_type =
state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.sampler_type;
const enum wined3d_sampler_texture_type *pshader_sampler_type = NULL;
const enum wined3d_shader_resource_type *vs_resource_type =
state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.resource_type;
const enum wined3d_shader_resource_type *ps_resource_type = NULL;
const struct wined3d_gl_info *gl_info = context->gl_info;
int start = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers) - 1;
int i;
/* Note that we only care if a resource is used or not, not the
* resource's specific type. Otherwise we'd need to call
* shader_update_samplers() here for 1.x pixelshaders. */
if (ps)
{
/* Note that we only care if a sampler is sampled or not, not the sampler's specific type.
* Otherwise we'd need to call shader_update_samplers() here for 1.x pixelshaders. */
pshader_sampler_type = state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.sampler_type;
}
ps_resource_type = state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.resource_type;
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) {
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i)
{
DWORD vsampler_idx = i + MAX_FRAGMENT_SAMPLERS;
if (vshader_sampler_type[i])
if (vs_resource_type[i])
{
if (context->tex_unit_map[vsampler_idx] != WINED3D_UNMAPPED_STAGE)
{
......@@ -2658,7 +2658,7 @@ static void context_map_vsamplers(struct wined3d_context *context, BOOL ps, cons
while (start >= 0)
{
if (context_unit_free_for_vs(context, pshader_sampler_type, vshader_sampler_type, start))
if (context_unit_free_for_vs(context, ps_resource_type, vs_resource_type, start))
{
context_map_stage(context, vsampler_idx, start);
context_invalidate_state(context, STATE_SAMPLER(vsampler_idx));
......@@ -2930,7 +2930,7 @@ static void context_preload_textures(struct wined3d_context *context, const stru
{
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i)
{
if (state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.sampler_type[i])
if (state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.resource_type[i])
context_preload_texture(context, state, MAX_FRAGMENT_SAMPLERS + i);
}
}
......@@ -2939,7 +2939,7 @@ static void context_preload_textures(struct wined3d_context *context, const stru
{
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
{
if (state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.sampler_type[i])
if (state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.resource_type[i])
context_preload_texture(context, state, i);
}
}
......
......@@ -662,14 +662,13 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
reg_maps->fog = 1;
break;
/* Save sampler usage token. */
case WINED3DSPR_SAMPLER:
if (reg_idx >= ARRAY_SIZE(reg_maps->sampler_type))
if (reg_idx >= ARRAY_SIZE(reg_maps->resource_type))
{
ERR("Invalid sampler index %u.\n", reg_idx);
ERR("Invalid resource index %u.\n", reg_idx);
break;
}
reg_maps->sampler_type[reg_idx] = semantic->sampler_type;
reg_maps->resource_type[reg_idx] = semantic->resource_type;
break;
default:
......@@ -897,11 +896,8 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
|| ins.handler_idx == WINED3DSIH_TEXREG2GB
|| ins.handler_idx == WINED3DSIH_TEXREG2RGB))
{
/* Fake sampler usage, only set reserved bit and type. */
DWORD sampler_code = ins.dst[i].reg.idx[0].offset;
TRACE("Setting fake 2D sampler for 1.x pixelshader.\n");
reg_maps->sampler_type[sampler_code] = WINED3DSTT_2D;
TRACE("Setting fake 2D resource for 1.x pixelshader.\n");
reg_maps->resource_type[ins.dst[i].reg.idx[0].offset] = WINED3D_SHADER_RESOURCE_TEXTURE_2D;
/* texbem is only valid with < 1.4 pixel shaders */
if (ins.handler_idx == WINED3DSIH_TEXBEM
......@@ -1002,12 +998,23 @@ static void shader_dump_decl_usage(const struct wined3d_shader_semantic *semanti
if (semantic->reg.reg.type == WINED3DSPR_SAMPLER)
{
switch (semantic->sampler_type)
switch (semantic->resource_type)
{
case WINED3DSTT_2D: TRACE("_2d"); break;
case WINED3DSTT_CUBE: TRACE("_cube"); break;
case WINED3DSTT_VOLUME: TRACE("_volume"); break;
default: TRACE("_unknown_ttype(0x%08x)", semantic->sampler_type);
case WINED3D_SHADER_RESOURCE_TEXTURE_2D:
TRACE("_2d");
break;
case WINED3D_SHADER_RESOURCE_TEXTURE_3D:
TRACE("_volume");
break;
case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE:
TRACE("_cube");
break;
default:
TRACE("_unknown_ttype(0x%08x)", semantic->resource_type);
break;
}
}
else
......@@ -2125,10 +2132,10 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3
if (!state->shader[WINED3D_SHADER_TYPE_VERTEX])
{
enum wined3d_shader_resource_type resource_type = shader->reg_maps.resource_type[i];
unsigned int j;
unsigned int index = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
DWORD max_valid = WINED3D_TTFF_COUNT4;
enum wined3d_sampler_texture_type sampler_type = shader->reg_maps.sampler_type[i];
for (j = 0; j < state->vertex_declaration->element_count; ++j)
{
......@@ -2148,15 +2155,17 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3
tex_transform, max_valid);
tex_transform = max_valid;
}
if ((sampler_type == WINED3DSTT_1D && tex_transform > WINED3D_TTFF_COUNT1)
|| (sampler_type == WINED3DSTT_2D && tex_transform > WINED3D_TTFF_COUNT2)
|| (sampler_type == WINED3DSTT_VOLUME && tex_transform > WINED3D_TTFF_COUNT3))
if ((resource_type == WINED3D_SHADER_RESOURCE_TEXTURE_1D && tex_transform > WINED3D_TTFF_COUNT1)
|| (resource_type == WINED3D_SHADER_RESOURCE_TEXTURE_2D
&& tex_transform > WINED3D_TTFF_COUNT2)
|| (resource_type == WINED3D_SHADER_RESOURCE_TEXTURE_3D
&& tex_transform > WINED3D_TTFF_COUNT3))
tex_transform |= WINED3D_PSARGS_PROJECTED;
else
{
WARN("Application requested projected texture with unsuitable texture coordinates.\n");
WARN("(texture unit %u, transform flags %#x, sampler type %u).\n",
i, tex_transform, sampler_type);
i, tex_transform, resource_type);
}
}
else
......@@ -2173,7 +2182,7 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3
{
const struct wined3d_texture *texture = state->textures[i];
if (!shader->reg_maps.sampler_type[i])
if (!shader->reg_maps.resource_type[i])
continue;
/* Treat unbound textures as 2D. The dummy texture will provide
......@@ -2202,7 +2211,7 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
{
if (!shader->reg_maps.sampler_type[i])
if (!shader->reg_maps.resource_type[i])
continue;
texture = state->textures[i];
......@@ -2370,10 +2379,10 @@ static HRESULT pixelshader_init(struct wined3d_shader *shader, struct wined3d_de
return WINED3D_OK;
}
void pixelshader_update_samplers(struct wined3d_shader *shader, WORD tex_types)
void pixelshader_update_resource_types(struct wined3d_shader *shader, WORD tex_types)
{
struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
enum wined3d_sampler_texture_type *sampler_type = reg_maps->sampler_type;
enum wined3d_shader_resource_type *resource_type = reg_maps->resource_type;
unsigned int i;
if (reg_maps->shader_version.major != 1) return;
......@@ -2381,20 +2390,21 @@ void pixelshader_update_samplers(struct wined3d_shader *shader, WORD tex_types)
for (i = 0; i < shader->limits->sampler; ++i)
{
/* We don't sample from this sampler. */
if (!sampler_type[i]) continue;
if (!resource_type[i])
continue;
switch ((tex_types >> i * WINED3D_PSARGS_TEXTYPE_SHIFT) & WINED3D_PSARGS_TEXTYPE_MASK)
{
case WINED3D_SHADER_TEX_2D:
sampler_type[i] = WINED3DSTT_2D;
resource_type[i] = WINED3D_SHADER_RESOURCE_TEXTURE_2D;
break;
case WINED3D_SHADER_TEX_3D:
sampler_type[i] = WINED3DSTT_VOLUME;
resource_type[i] = WINED3D_SHADER_RESOURCE_TEXTURE_3D;
break;
case WINED3D_SHADER_TEX_CUBE:
sampler_type[i] = WINED3DSTT_CUBE;
resource_type[i] = WINED3D_SHADER_RESOURCE_TEXTURE_CUBE;
break;
}
}
......
......@@ -36,8 +36,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
#define WINED3DSP_DCL_USAGEINDEX_MASK (0xf << WINED3DSP_DCL_USAGEINDEX_SHIFT)
/* DCL sampler type */
#define WINED3DSP_TEXTURETYPE_SHIFT 27
#define WINED3DSP_TEXTURETYPE_MASK (0xf << WINED3DSP_TEXTURETYPE_SHIFT)
#define WINED3D_SM1_RESOURCE_TYPE_SHIFT 27
#define WINED3D_SM1_RESOURCE_TYPE_MASK (0xf << WINED3D_SM1_RESOURCE_TYPE_SHIFT)
/* Opcode-related masks */
#define WINED3DSI_OPCODE_MASK 0x0000ffff
......@@ -99,6 +99,15 @@ enum WINED3DSHADER_ADDRESSMODE_TYPE
WINED3DSHADER_ADDRMODE_RELATIVE = 1 << WINED3DSHADER_ADDRESSMODE_SHIFT,
};
enum wined3d_sm1_resource_type
{
WINED3D_SM1_RESOURCE_UNKNOWN = 0x0,
WINED3D_SM1_RESOURCE_TEXTURE_1D = 0x1,
WINED3D_SM1_RESOURCE_TEXTURE_2D = 0x2,
WINED3D_SM1_RESOURCE_TEXTURE_CUBE = 0x3,
WINED3D_SM1_RESOURCE_TEXTURE_3D = 0x4,
};
enum wined3d_sm1_opcode
{
WINED3D_SM1_OP_NOP = 0x00,
......@@ -377,6 +386,15 @@ static const struct wined3d_sm1_opcode_info ps_opcode_table[] =
{0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
};
static const enum wined3d_shader_resource_type resource_type_table[] =
{
/* WINED3D_SM1_RESOURCE_UNKNOWN */ WINED3D_SHADER_RESOURCE_NONE,
/* WINED3D_SM1_RESOURCE_TEXTURE_1D */ WINED3D_SHADER_RESOURCE_TEXTURE_1D,
/* WINED3D_SM1_RESOURCE_TEXTURE_2D */ WINED3D_SHADER_RESOURCE_TEXTURE_2D,
/* WINED3D_SM1_RESOURCE_TEXTURE_CUBE */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
/* WINED3D_SM1_RESOURCE_TEXTURE_3D */ WINED3D_SHADER_RESOURCE_TEXTURE_3D,
};
/* Read a parameter opcode from the input stream,
* and possibly a relative addressing token.
* Return the number of tokens read */
......@@ -612,12 +630,22 @@ static void shader_sm1_read_dst_param(struct wined3d_sm1_data *priv, const DWORD
static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_semantic *semantic)
{
enum wined3d_sm1_resource_type resource_type;
DWORD usage_token = *(*ptr)++;
DWORD dst_token = *(*ptr)++;
semantic->usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
semantic->usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
semantic->sampler_type = (usage_token & WINED3DSP_TEXTURETYPE_MASK) >> WINED3DSP_TEXTURETYPE_SHIFT;
resource_type = (usage_token & WINED3D_SM1_RESOURCE_TYPE_MASK) >> WINED3D_SM1_RESOURCE_TYPE_SHIFT;
if (resource_type >= ARRAY_SIZE(resource_type_table))
{
FIXME("Unhandled resource type %#x.\n", resource_type);
semantic->resource_type = WINED3D_SHADER_RESOURCE_NONE;
}
else
{
semantic->resource_type = resource_type_table[resource_type];
}
shader_parse_dst_param(dst_token, NULL, &semantic->reg);
}
......
......@@ -283,13 +283,13 @@ struct wined3d_settings
extern struct wined3d_settings wined3d_settings DECLSPEC_HIDDEN;
enum wined3d_sampler_texture_type
enum wined3d_shader_resource_type
{
WINED3DSTT_UNKNOWN = 0,
WINED3DSTT_1D = 1,
WINED3DSTT_2D = 2,
WINED3DSTT_CUBE = 3,
WINED3DSTT_VOLUME = 4,
WINED3D_SHADER_RESOURCE_NONE,
WINED3D_SHADER_RESOURCE_TEXTURE_1D,
WINED3D_SHADER_RESOURCE_TEXTURE_2D,
WINED3D_SHADER_RESOURCE_TEXTURE_3D,
WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
};
#define WINED3D_SHADER_CONST_VS_F 0x00000001
......@@ -588,7 +588,7 @@ struct wined3d_shader_reg_maps
WORD local_bool_consts; /* MAX_CONST_B, 16 */
UINT cb_sizes[WINED3D_MAX_CBS];
enum wined3d_sampler_texture_type sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
enum wined3d_shader_resource_type resource_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
BYTE bumpmat; /* MAX_TEXTURES, 8 */
BYTE luminanceparams; /* MAX_TEXTURES, 8 */
......@@ -673,7 +673,7 @@ struct wined3d_shader_semantic
{
enum wined3d_decl_usage usage;
UINT usage_idx;
enum wined3d_sampler_texture_type sampler_type;
enum wined3d_shader_resource_type resource_type;
struct wined3d_shader_dst_param reg;
};
......@@ -2910,7 +2910,7 @@ struct wined3d_shader
} u;
};
void pixelshader_update_samplers(struct wined3d_shader *shader, WORD tex_types) DECLSPEC_HIDDEN;
void pixelshader_update_resource_types(struct wined3d_shader *shader, 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_gl_info *gl_info) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment