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.
This commit is contained in:
Henri Verbeet 2014-12-03 10:28:09 +01:00 committed by Alexandre Julliard
parent 5ccda82acc
commit f5cef43738
6 changed files with 218 additions and 175 deletions

View File

@ -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))
{

View File

@ -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);
}
}

View File

@ -1064,52 +1064,56 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont
/* Declare texture samplers */
for (i = 0; i < shader->limits->sampler; ++i)
{
if (reg_maps->sampler_type[i])
{
BOOL shadow_sampler = version->type == WINED3D_SHADER_TYPE_PIXEL && (ps_args->shadow & (1 << i));
BOOL tex_rect;
BOOL shadow_sampler, tex_rect;
switch (reg_maps->sampler_type[i])
{
case WINED3DSTT_1D:
if (shadow_sampler)
shader_addline(buffer, "uniform sampler1DShadow %s_sampler%u;\n", prefix, i);
if (!reg_maps->resource_type[i])
continue;
shadow_sampler = version->type == WINED3D_SHADER_TYPE_PIXEL && (ps_args->shadow & (1 << i));
switch (reg_maps->resource_type[i])
{
case WINED3D_SHADER_RESOURCE_TEXTURE_1D:
if (shadow_sampler)
shader_addline(buffer, "uniform sampler1DShadow %s_sampler%u;\n", prefix, i);
else
shader_addline(buffer, "uniform sampler1D %s_sampler%u;\n", prefix, i);
break;
case WINED3D_SHADER_RESOURCE_TEXTURE_2D:
tex_rect = version->type == WINED3D_SHADER_TYPE_PIXEL && (ps_args->np2_fixup & (1 << i));
tex_rect = tex_rect && gl_info->supported[ARB_TEXTURE_RECTANGLE];
if (shadow_sampler)
{
if (tex_rect)
shader_addline(buffer, "uniform sampler2DRectShadow %s_sampler%u;\n", prefix, i);
else
shader_addline(buffer, "uniform sampler1D %s_sampler%u;\n", prefix, i);
break;
case WINED3DSTT_2D:
tex_rect = version->type == WINED3D_SHADER_TYPE_PIXEL && (ps_args->np2_fixup & (1 << i));
tex_rect = tex_rect && gl_info->supported[ARB_TEXTURE_RECTANGLE];
if (shadow_sampler)
{
if (tex_rect)
shader_addline(buffer, "uniform sampler2DRectShadow %s_sampler%u;\n", prefix, i);
else
shader_addline(buffer, "uniform sampler2DShadow %s_sampler%u;\n", prefix, i);
}
shader_addline(buffer, "uniform sampler2DShadow %s_sampler%u;\n", prefix, i);
}
else
{
if (tex_rect)
shader_addline(buffer, "uniform sampler2DRect %s_sampler%u;\n", prefix, i);
else
{
if (tex_rect)
shader_addline(buffer, "uniform sampler2DRect %s_sampler%u;\n", prefix, i);
else
shader_addline(buffer, "uniform sampler2D %s_sampler%u;\n", prefix, i);
}
break;
case WINED3DSTT_CUBE:
if (shadow_sampler)
FIXME("Unsupported Cube shadow sampler.\n");
shader_addline(buffer, "uniform samplerCube %s_sampler%u;\n", prefix, i);
break;
case WINED3DSTT_VOLUME:
if (shadow_sampler)
FIXME("Unsupported 3D shadow sampler.\n");
shader_addline(buffer, "uniform sampler3D %s_sampler%u;\n", prefix, i);
break;
default:
shader_addline(buffer, "uniform unsupported_sampler %s_sampler%u;\n", prefix, i);
FIXME("Unrecognized sampler type: %#x\n", reg_maps->sampler_type[i]);
break;
}
shader_addline(buffer, "uniform sampler2D %s_sampler%u;\n", prefix, i);
}
break;
case WINED3D_SHADER_RESOURCE_TEXTURE_3D:
if (shadow_sampler)
FIXME("Unsupported 3D shadow sampler.\n");
shader_addline(buffer, "uniform sampler3D %s_sampler%u;\n", prefix, i);
break;
case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE:
if (shadow_sampler)
FIXME("Unsupported Cube shadow sampler.\n");
shader_addline(buffer, "uniform samplerCube %s_sampler%u;\n", prefix, i);
break;
default:
shader_addline(buffer, "uniform unsupported_sampler %s_sampler%u;\n", prefix, i);
FIXME("Unhandled resource type %#x.\n", reg_maps->resource_type[i]);
break;
}
}
@ -1130,17 +1134,16 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont
for (i = 0; i < shader->limits->sampler; ++i)
{
if (reg_maps->sampler_type[i])
if (!reg_maps->resource_type[i] || !(ps_args->np2_fixup & (1 << i)))
continue;
if (reg_maps->resource_type[i] != WINED3D_SHADER_RESOURCE_TEXTURE_2D)
{
if (!(ps_args->np2_fixup & (1 << i))) continue;
if (WINED3DSTT_2D != reg_maps->sampler_type[i]) {
FIXME("Non-2D texture is flagged for NP2 texcoord fixup.\n");
continue;
}
fixup->idx[i] = cur++;
FIXME("Non-2D texture is flagged for NP2 texcoord fixup.\n");
continue;
}
fixup->idx[i] = cur++;
}
fixup->num_consts = (cur + 1) >> 1;
@ -1885,20 +1888,21 @@ static const char *shader_glsl_get_rel_op(enum wined3d_shader_rel_op op)
}
static void shader_glsl_get_sample_function(const struct wined3d_shader_context *ctx,
DWORD sampler_idx, DWORD flags, struct glsl_sample_function *sample_function)
DWORD resource_idx, DWORD flags, struct glsl_sample_function *sample_function)
{
enum wined3d_sampler_texture_type sampler_type = ctx->reg_maps->sampler_type[sampler_idx];
enum wined3d_shader_resource_type resource_type = ctx->reg_maps->resource_type[resource_idx];
const struct wined3d_gl_info *gl_info = ctx->gl_info;
BOOL shadow = ctx->reg_maps->shader_version.type == WINED3D_SHADER_TYPE_PIXEL
&& (((const struct shader_glsl_ctx_priv *)ctx->backend_data)->cur_ps_args->shadow & (1 << sampler_idx));
&& (((const struct shader_glsl_ctx_priv *)ctx->backend_data)->cur_ps_args->shadow & (1 << resource_idx));
BOOL projected = flags & WINED3D_GLSL_SAMPLE_PROJECTED;
BOOL texrect = flags & WINED3D_GLSL_SAMPLE_NPOT && gl_info->supported[ARB_TEXTURE_RECTANGLE];
BOOL lod = flags & WINED3D_GLSL_SAMPLE_LOD;
BOOL grad = flags & WINED3D_GLSL_SAMPLE_GRAD;
/* Note that there's no such thing as a projected cube texture. */
switch(sampler_type) {
case WINED3DSTT_1D:
switch (resource_type)
{
case WINED3D_SHADER_RESOURCE_TEXTURE_1D:
if (shadow)
{
if (lod)
@ -1949,7 +1953,7 @@ static void shader_glsl_get_sample_function(const struct wined3d_shader_context
}
break;
case WINED3DSTT_2D:
case WINED3D_SHADER_RESOURCE_TEXTURE_2D:
if (shadow)
{
if (texrect)
@ -2052,40 +2056,7 @@ static void shader_glsl_get_sample_function(const struct wined3d_shader_context
}
break;
case WINED3DSTT_CUBE:
if (shadow)
{
FIXME("Unsupported Cube shadow function.\n");
sample_function->name = "unsupportedCubeShadow";
sample_function->coord_mask = 0;
}
else
{
if (lod)
{
sample_function->name = "textureCubeLod";
}
else if (grad)
{
if (gl_info->supported[EXT_GPU_SHADER4])
sample_function->name = "textureCubeGrad";
else if (gl_info->supported[ARB_SHADER_TEXTURE_LOD])
sample_function->name = "textureCubeGradARB";
else
{
FIXME("Unsupported Cube grad function.\n");
sample_function->name = "unsupportedCubeGrad";
}
}
else
{
sample_function->name = "textureCube";
}
sample_function->coord_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
}
break;
case WINED3DSTT_VOLUME:
case WINED3D_SHADER_RESOURCE_TEXTURE_3D:
if (shadow)
{
FIXME("Unsupported 3D shadow function.\n");
@ -2118,10 +2089,43 @@ static void shader_glsl_get_sample_function(const struct wined3d_shader_context
}
break;
case WINED3D_SHADER_RESOURCE_TEXTURE_CUBE:
if (shadow)
{
FIXME("Unsupported Cube shadow function.\n");
sample_function->name = "unsupportedCubeShadow";
sample_function->coord_mask = 0;
}
else
{
if (lod)
{
sample_function->name = "textureCubeLod";
}
else if (grad)
{
if (gl_info->supported[EXT_GPU_SHADER4])
sample_function->name = "textureCubeGrad";
else if (gl_info->supported[ARB_SHADER_TEXTURE_LOD])
sample_function->name = "textureCubeGradARB";
else
{
FIXME("Unsupported Cube grad function.\n");
sample_function->name = "unsupportedCubeGrad";
}
}
else
{
sample_function->name = "textureCube";
}
sample_function->coord_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
}
break;
default:
sample_function->name = "";
sample_function->coord_mask = 0;
FIXME("Unrecognized sampler type: %#x;\n", sampler_type);
FIXME("Unhandled resource type %#x.\n", resource_type);
break;
}
}
@ -3449,25 +3453,25 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
ins->ctx->reg_maps->shader_version.minor);
struct glsl_sample_function sample_function;
DWORD sample_flags = 0;
DWORD sampler_idx;
DWORD resource_idx;
DWORD mask = 0, swizzle;
const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
/* 1.0-1.4: Use destination register as sampler source.
* 2.0+: Use provided sampler source. */
if (shader_version < WINED3D_SHADER_VERSION(2,0))
sampler_idx = ins->dst[0].reg.idx[0].offset;
resource_idx = ins->dst[0].reg.idx[0].offset;
else
sampler_idx = ins->src[1].reg.idx[0].offset;
resource_idx = ins->src[1].reg.idx[0].offset;
if (shader_version < WINED3D_SHADER_VERSION(1,4))
{
DWORD flags = (priv->cur_ps_args->tex_transform >> sampler_idx * WINED3D_PSARGS_TEXTRANSFORM_SHIFT)
DWORD flags = (priv->cur_ps_args->tex_transform >> resource_idx * WINED3D_PSARGS_TEXTRANSFORM_SHIFT)
& WINED3D_PSARGS_TEXTRANSFORM_MASK;
enum wined3d_sampler_texture_type sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
enum wined3d_shader_resource_type resource_type = ins->ctx->reg_maps->resource_type[resource_idx];
/* Projected cube textures don't make a lot of sense, the resulting coordinates stay the same. */
if (flags & WINED3D_PSARGS_PROJECTED && sampler_type != WINED3DSTT_CUBE)
if (flags & WINED3D_PSARGS_PROJECTED && resource_type != WINED3D_SHADER_RESOURCE_TEXTURE_CUBE)
{
sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED;
switch (flags & ~WINED3D_PSARGS_PROJECTED)
@ -3503,7 +3507,7 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
else
{
if ((ins->flags & WINED3DSI_TEXLD_PROJECT)
&& ins->ctx->reg_maps->sampler_type[sampler_idx] != WINED3DSTT_CUBE)
&& ins->ctx->reg_maps->resource_type[resource_idx] != WINED3D_SHADER_RESOURCE_TEXTURE_CUBE)
{
/* ps 2.0 texldp instruction always divides by the fourth component. */
sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED;
@ -3511,10 +3515,10 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
}
}
if (priv->cur_ps_args->np2_fixup & (1 << sampler_idx))
if (priv->cur_ps_args->np2_fixup & (1 << resource_idx))
sample_flags |= WINED3D_GLSL_SAMPLE_NPOT;
shader_glsl_get_sample_function(ins->ctx, sampler_idx, sample_flags, &sample_function);
shader_glsl_get_sample_function(ins->ctx, resource_idx, sample_flags, &sample_function);
mask |= sample_function.coord_mask;
if (shader_version < WINED3D_SHADER_VERSION(2,0)) swizzle = WINED3DSP_NOSWIZZLE;
@ -3526,8 +3530,8 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
{
char coord_mask[6];
shader_glsl_write_mask_to_str(mask, coord_mask);
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, NULL,
"T%u%s", sampler_idx, coord_mask);
shader_glsl_gen_sample_code(ins, resource_idx, &sample_function, swizzle, NULL, NULL, NULL,
"T%u%s", resource_idx, coord_mask);
}
else
{
@ -3537,10 +3541,10 @@ static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
{
struct glsl_src_param bias;
shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &bias);
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, bias.param_str,
shader_glsl_gen_sample_code(ins, resource_idx, &sample_function, swizzle, NULL, NULL, bias.param_str,
"%s", coord_param.param_str);
} else {
shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, NULL,
shader_glsl_gen_sample_code(ins, resource_idx, &sample_function, swizzle, NULL, NULL, NULL,
"%s", coord_param.param_str);
}
}
@ -4677,7 +4681,7 @@ static GLhandleARB find_glsl_pshader(const struct wined3d_context *context,
memset(np2fixup, 0, sizeof(*np2fixup));
*np2fixup_info = args->np2_fixup ? np2fixup : NULL;
pixelshader_update_samplers(shader, args->tex_types);
pixelshader_update_resource_types(shader, args->tex_types);
shader_buffer_clear(buffer);
ret = shader_glsl_generate_pshader(context, buffer, shader, args, np2fixup);

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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;