wined3d: Allow using more than MAX_COMBINED_SAMPLERS texture image units.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2017-03-14 13:15:57 +01:00 committed by Alexandre Julliard
parent ea6c61a534
commit 1865352e3f
6 changed files with 101 additions and 55 deletions

View File

@ -1635,7 +1635,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
HGLRC ctx, share_ctx;
DWORD target_usage;
int pixel_format;
unsigned int s;
unsigned int i;
DWORD state;
HDC hdc = 0;
@ -1689,20 +1689,40 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
goto out;
}
/* Initialize the texture unit mapping to a 1:1 mapping */
for (s = 0; s < MAX_COMBINED_SAMPLERS; ++s)
for (i = 0; i < ARRAY_SIZE(ret->tex_unit_map); ++i)
ret->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
for (i = 0; i < ARRAY_SIZE(ret->rev_tex_unit_map); ++i)
ret->rev_tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
if (gl_info->limits.graphics_samplers >= MAX_COMBINED_SAMPLERS)
{
if (s < gl_info->limits.graphics_samplers)
/* Initialize the texture unit mapping to a 1:1 mapping. */
unsigned int base, count;
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_PIXEL, &base, &count);
if (base + MAX_FRAGMENT_SAMPLERS > ARRAY_SIZE(ret->rev_tex_unit_map))
{
ret->tex_unit_map[s] = s;
ret->rev_tex_unit_map[s] = s;
ERR("Unexpected texture unit base index %u.\n", base);
goto out;
}
else
for (i = 0; i < min(count, MAX_FRAGMENT_SAMPLERS); ++i)
{
ret->tex_unit_map[s] = WINED3D_UNMAPPED_STAGE;
ret->rev_tex_unit_map[s] = WINED3D_UNMAPPED_STAGE;
ret->tex_unit_map[i] = base + i;
ret->rev_tex_unit_map[base + i] = i;
}
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_VERTEX, &base, &count);
if (base + MAX_VERTEX_SAMPLERS > ARRAY_SIZE(ret->rev_tex_unit_map))
{
ERR("Unexpected texture unit base index %u.\n", base);
goto out;
}
for (i = 0; i < min(count, MAX_VERTEX_SAMPLERS); ++i)
{
ret->tex_unit_map[MAX_FRAGMENT_SAMPLERS + i] = base + i;
ret->rev_tex_unit_map[base + i] = MAX_FRAGMENT_SAMPLERS + i;
}
}
if (!(ret->texture_type = wined3d_calloc(gl_info->limits.combined_samplers,
sizeof(*ret->texture_type))))
goto out;
@ -1918,11 +1938,11 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
/* Set up the previous texture input for all shader units. This applies to bump mapping, and in d3d
* the previous texture where to source the offset from is always unit - 1.
*/
for (s = 1; s < gl_info->limits.textures; ++s)
for (i = 1; i < gl_info->limits.textures; ++i)
{
context_active_texture(ret, gl_info, s);
context_active_texture(ret, gl_info, i);
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_SHADER_NV,
GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1);
GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + i - 1);
checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ...");
}
}
@ -1948,9 +1968,9 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
if (gl_info->supported[ARB_POINT_SPRITE])
{
for (s = 0; s < gl_info->limits.textures; ++s)
for (i = 0; i < gl_info->limits.textures; ++i)
{
context_active_texture(ret, gl_info, s);
context_active_texture(ret, gl_info, i);
gl_info->gl_ops.gl.p_glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)");
}

View File

@ -3395,8 +3395,8 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info)
static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
{
unsigned int i, sampler_count;
GLfloat gl_floatv[2];
unsigned int i;
GLint gl_max;
gl_info->limits.blends = 1;
@ -3538,7 +3538,6 @@ static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
TRACE("Max vertex samplers: %u.\n", gl_info->limits.vertex_samplers);
TRACE("Max combined samplers: %u.\n", gl_info->limits.combined_samplers);
TRACE("Max vertex attributes: %u.\n", gl_info->limits.vertex_attribs);
gl_info->limits.graphics_samplers = gl_info->limits.combined_samplers;
}
else
{
@ -3647,10 +3646,6 @@ static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS, &gl_max);
gl_info->limits.compute_samplers = gl_max;
TRACE("Max compute samplers: %u.\n", gl_info->limits.compute_samplers);
/* A majority of OpenGL implementations allow to statically partition
* the set of texture bindings into six separate sets. */
if (gl_info->limits.combined_samplers >= MAX_COMBINED_SAMPLERS + gl_info->limits.compute_samplers)
gl_info->limits.graphics_samplers -= gl_info->limits.compute_samplers;
}
if (gl_info->supported[ARB_UNIFORM_BUFFER_OBJECT])
{
@ -3694,6 +3689,25 @@ static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_SAMPLES, &gl_max);
gl_info->limits.samples = gl_max;
}
gl_info->limits.fragment_samplers = min(gl_info->limits.fragment_samplers, MAX_GL_FRAGMENT_SAMPLERS);
sampler_count = gl_info->limits.vertex_samplers + gl_info->limits.fragment_samplers;
if (gl_info->supported[WINED3D_GL_VERSION_3_2] && gl_info->limits.combined_samplers < sampler_count)
{
/* The minimum value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS in OpenGL
* 3.2 is 48 (16 per stage). When tessellation shaders are supported
* the minimum value is increased to 80. */
WARN("Graphics pipeline sampler count %u is greater than combined sampler count %u.\n",
sampler_count, gl_info->limits.combined_samplers);
gl_info->limits.fragment_samplers = min(gl_info->limits.fragment_samplers, 16);
gl_info->limits.vertex_samplers = min(gl_info->limits.vertex_samplers, 16);
}
/* A majority of OpenGL implementations allow us to statically partition
* the set of texture bindings into six separate sets. */
gl_info->limits.graphics_samplers = gl_info->limits.combined_samplers;
if (gl_info->limits.combined_samplers >= sampler_count + gl_info->limits.compute_samplers)
gl_info->limits.graphics_samplers -= gl_info->limits.compute_samplers;
}
/* Context activation is done by the caller. */

View File

@ -630,8 +630,30 @@ static void shader_glsl_load_samplers(const struct wined3d_context *context,
const DWORD *tex_unit_map;
unsigned int base, count;
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, version->type, &base, &count);
tex_unit_map = version->major >= 4 ? NULL : context->tex_unit_map;
if (reg_maps->shader_version.major >= 4)
{
tex_unit_map = NULL;
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, version->type, &base, &count);
}
else
{
tex_unit_map = context->tex_unit_map;
switch (reg_maps->shader_version.type)
{
case WINED3D_SHADER_TYPE_PIXEL:
base = 0;
count = MAX_FRAGMENT_SAMPLERS;
break;
case WINED3D_SHADER_TYPE_VERTEX:
base = MAX_FRAGMENT_SAMPLERS;
count = MAX_VERTEX_SAMPLERS;
break;
default:
ERR("Unhandled shader type %#x.\n", reg_maps->shader_version.type);
return;
}
}
shader_glsl_load_samplers_range(gl_info, priv, program_id, prefix, base, count, tex_unit_map);
}

View File

@ -815,7 +815,7 @@ void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture,
* called from sampler() in state.c. This means we can't touch anything
* other than whatever happens to be the currently active texture, or we
* would risk marking already applied sampler states dirty again. */
if (context->active_texture < MAX_COMBINED_SAMPLERS)
if (context->active_texture < ARRAY_SIZE(context->rev_tex_unit_map))
{
DWORD active_sampler = context->rev_tex_unit_map[context->active_texture];
if (active_sampler != WINED3D_UNMAPPED_STAGE)

View File

@ -5994,40 +5994,28 @@ void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits *g
void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits *gl_limits,
enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count)
{
static const struct
if (shader_type == WINED3D_SHADER_TYPE_COMPUTE)
{
enum wined3d_shader_type type;
unsigned int base_idx;
unsigned int count;
}
legacy_sampler_info[] =
{
{WINED3D_SHADER_TYPE_PIXEL, 0, MAX_FRAGMENT_SAMPLERS},
{WINED3D_SHADER_TYPE_VERTEX, MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS},
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(legacy_sampler_info); ++i)
{
if (legacy_sampler_info[i].type == shader_type)
{
*base = legacy_sampler_info[i].base_idx;
*count = legacy_sampler_info[i].count;
return;
}
}
if (shader_type != WINED3D_SHADER_TYPE_COMPUTE)
{
*base = *count = 0;
if (gl_limits->combined_samplers == gl_limits->graphics_samplers)
*base = 0;
else
*base = gl_limits->graphics_samplers - 1;
*count = gl_limits->compute_samplers;
return;
}
if (gl_limits->combined_samplers == gl_limits->graphics_samplers)
*base = 0;
else
*base = gl_limits->graphics_samplers - 1;
*count = gl_limits->compute_samplers;
*base = 0;
*count = gl_limits->fragment_samplers;
if (shader_type == WINED3D_SHADER_TYPE_PIXEL)
return;
*base += *count;
*count = gl_limits->vertex_samplers;
if (shader_type == WINED3D_SHADER_TYPE_VERTEX)
return;
*base += *count;
*count = 0;
}
BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)

View File

@ -1629,6 +1629,8 @@ struct wined3d_timestamp_query
void context_alloc_timestamp_query(struct wined3d_context *context, struct wined3d_timestamp_query *query) DECLSPEC_HIDDEN;
void context_free_timestamp_query(struct wined3d_timestamp_query *query) DECLSPEC_HIDDEN;
#define MAX_GL_FRAGMENT_SAMPLERS 32
struct wined3d_context
{
const struct wined3d_gl_info *gl_info;
@ -1748,8 +1750,8 @@ struct wined3d_context
struct wined3d_event_query *buffer_queries[MAX_ATTRIBS];
unsigned int num_buffer_queries;
DWORD tex_unit_map[MAX_COMBINED_SAMPLERS];
DWORD rev_tex_unit_map[MAX_COMBINED_SAMPLERS];
DWORD tex_unit_map[MAX_COMBINED_SAMPLERS];
DWORD rev_tex_unit_map[MAX_GL_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS];
/* Extension emulation */
GLint gl_fog_source;