wined3d: Do not create separate dummy texture for each texture image unit.

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 2016-10-03 00:38:37 +02:00 committed by Alexandre Julliard
parent a2ca4244bb
commit a4ce86c8f7
3 changed files with 94 additions and 120 deletions

View File

@ -1511,7 +1511,7 @@ static int context_choose_pixel_format(const struct wined3d_device *device, HDC
}
/* Context activation is done by the caller. */
static void bind_dummy_textures(const struct wined3d_device *device, const struct wined3d_context *context)
void context_bind_dummy_textures(const struct wined3d_device *device, const struct wined3d_context *context)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
unsigned int i, count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
@ -1521,32 +1521,21 @@ static void bind_dummy_textures(const struct wined3d_device *device, const struc
GL_EXTCALL(glActiveTexture(GL_TEXTURE0 + i));
checkGLcall("glActiveTexture");
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[i]);
checkGLcall("glBindTexture");
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_textures.tex_2d);
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
{
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[i]);
checkGLcall("glBindTexture");
}
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_textures.tex_rect);
if (gl_info->supported[EXT_TEXTURE3D])
{
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[i]);
checkGLcall("glBindTexture");
}
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_textures.tex_3d);
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
{
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[i]);
checkGLcall("glBindTexture");
}
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_textures.tex_cube);
if (gl_info->supported[EXT_TEXTURE_ARRAY])
{
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_texture_2d_array[i]);
checkGLcall("glBindTexture");
}
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_textures.tex_2d_array);
checkGLcall("Bind dummy textures");
}
}
@ -1993,8 +1982,8 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
/* If this happens to be the first context for the device, dummy textures
* are not created yet. In that case, they will be created (and bound) by
* create_dummy_textures right after this context is initialized. */
if (device->dummy_texture_2d[0])
bind_dummy_textures(device, ret);
if (device->dummy_textures.tex_2d)
context_bind_dummy_textures(device, ret);
TRACE("Created context %p.\n", ret);
@ -2393,23 +2382,23 @@ void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint
/* nothing to do */
break;
case GL_TEXTURE_2D:
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[unit]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_textures.tex_2d);
checkGLcall("glBindTexture");
break;
case GL_TEXTURE_2D_ARRAY:
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_texture_2d_array[unit]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_textures.tex_2d_array);
checkGLcall("glBindTexture");
break;
case GL_TEXTURE_RECTANGLE_ARB:
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[unit]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_textures.tex_rect);
checkGLcall("glBindTexture");
break;
case GL_TEXTURE_CUBE_MAP:
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[unit]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_textures.tex_cube);
checkGLcall("glBindTexture");
break;
case GL_TEXTURE_3D:
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[unit]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_textures.tex_3d);
checkGLcall("glBindTexture");
break;
default:

View File

@ -684,7 +684,7 @@ static void create_dummy_textures(struct wined3d_device *device, struct wined3d_
{
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
unsigned int i, j, count;
unsigned int i;
DWORD color;
if (d3d_info->wined3d_creation_flags & WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR)
@ -696,121 +696,101 @@ static void create_dummy_textures(struct wined3d_device *device, struct wined3d_
* OpenGL will only allow that when a valid texture is bound.
* We emulate this by creating dummy textures and binding them
* to each texture stage when the currently set D3D texture is NULL. */
count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
for (i = 0; i < count; ++i)
context_active_texture(context, gl_info, 0);
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_2d);
checkGLcall("glGenTextures");
TRACE("Dummy 2D texture given name %u.\n", device->dummy_textures.tex_2d);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_textures.tex_2d);
checkGLcall("glBindTexture");
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
checkGLcall("glTexImage2D");
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
{
/* Make appropriate texture active */
context_active_texture(context, gl_info, i);
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_2d[i]);
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_rect);
checkGLcall("glGenTextures");
TRACE("Dummy 2D texture %u given name %u.\n", i, device->dummy_texture_2d[i]);
TRACE("Dummy rectangle texture given name %u.\n", device->dummy_textures.tex_rect);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_texture_2d[i]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_textures.tex_rect);
checkGLcall("glBindTexture");
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0,
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
checkGLcall("glTexImage2D");
}
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
if (gl_info->supported[EXT_TEXTURE3D])
{
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_3d);
checkGLcall("glGenTextures");
TRACE("Dummy 3D texture given name %u.\n", device->dummy_textures.tex_3d);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_textures.tex_3d);
checkGLcall("glBindTexture");
GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
checkGLcall("glTexImage3D");
}
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
{
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_cube);
checkGLcall("glGenTextures");
TRACE("Dummy cube texture given name %u.\n", device->dummy_textures.tex_cube);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_textures.tex_cube);
checkGLcall("glBindTexture");
for (i = GL_TEXTURE_CUBE_MAP_POSITIVE_X; i <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; ++i)
{
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_rect[i]);
checkGLcall("glGenTextures");
TRACE("Dummy rectangle texture %u given name %u.\n", i, device->dummy_texture_rect[i]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_texture_rect[i]);
checkGLcall("glBindTexture");
gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, 1, 1, 0,
gl_info->gl_ops.gl.p_glTexImage2D(i, 0, GL_RGBA8, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
checkGLcall("glTexImage2D");
}
if (gl_info->supported[EXT_TEXTURE3D])
{
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_3d[i]);
checkGLcall("glGenTextures");
TRACE("Dummy 3D texture %u given name %u.\n", i, device->dummy_texture_3d[i]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_texture_3d[i]);
checkGLcall("glBindTexture");
GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
checkGLcall("glTexImage3D");
}
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
{
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_cube[i]);
checkGLcall("glGenTextures");
TRACE("Dummy cube texture %u given name %u.\n", i, device->dummy_texture_cube[i]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_texture_cube[i]);
checkGLcall("glBindTexture");
for (j = GL_TEXTURE_CUBE_MAP_POSITIVE_X; j <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; ++j)
{
gl_info->gl_ops.gl.p_glTexImage2D(j, 0, GL_RGBA8, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color);
checkGLcall("glTexImage2D");
}
}
if (gl_info->supported[EXT_TEXTURE_ARRAY])
{
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_texture_2d_array[i]);
checkGLcall("glGenTextures");
TRACE("Dummy 2D array texture %u given name %u.\n", i, device->dummy_texture_2d_array[i]);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_texture_2d_array[i]);
checkGLcall("glBindTexture");
GL_EXTCALL(glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 1, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
checkGLcall("glTexImage3D");
}
}
if (gl_info->supported[EXT_TEXTURE_ARRAY])
{
gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_2d_array);
checkGLcall("glGenTextures");
TRACE("Dummy 2D array texture given name %u.\n", device->dummy_textures.tex_2d_array);
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_textures.tex_2d_array);
checkGLcall("glBindTexture");
GL_EXTCALL(glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 1, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color));
checkGLcall("glTexImage3D");
}
context_bind_dummy_textures(device, context);
}
/* Context activation is done by the caller. */
static void destroy_dummy_textures(struct wined3d_device *device, const struct wined3d_gl_info *gl_info)
{
unsigned int count = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers);
if (gl_info->supported[EXT_TEXTURE_ARRAY])
{
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_2d_array);
checkGLcall("glDeleteTextures(count, device->dummy_texture_2d_array)");
}
gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_2d_array);
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
{
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_cube);
checkGLcall("glDeleteTextures(count, device->dummy_texture_cube)");
}
gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_cube);
if (gl_info->supported[EXT_TEXTURE3D])
{
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_3d);
checkGLcall("glDeleteTextures(count, device->dummy_texture_3d)");
}
gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_3d);
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
{
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_rect);
checkGLcall("glDeleteTextures(count, device->dummy_texture_rect)");
}
gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_rect);
gl_info->gl_ops.gl.p_glDeleteTextures(count, device->dummy_texture_2d);
checkGLcall("glDeleteTextures(count, device->dummy_texture_2d)");
gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_2d);
memset(device->dummy_texture_2d_array, 0, count * sizeof(*device->dummy_texture_2d_array));
memset(device->dummy_texture_cube, 0, count * sizeof(*device->dummy_texture_cube));
memset(device->dummy_texture_3d, 0, count * sizeof(*device->dummy_texture_3d));
memset(device->dummy_texture_rect, 0, count * sizeof(*device->dummy_texture_rect));
memset(device->dummy_texture_2d, 0, count * sizeof(*device->dummy_texture_2d));
checkGLcall("Delete dummy textures");
memset(&device->dummy_textures, 0, sizeof(device->dummy_textures));
}
/* Context activation is done by the caller. */

View File

@ -1720,6 +1720,8 @@ void context_apply_fbo_state_blit(struct wined3d_context *context, GLenum target
struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location) DECLSPEC_HIDDEN;
void context_active_texture(struct wined3d_context *context, const struct wined3d_gl_info *gl_info,
unsigned int unit) DECLSPEC_HIDDEN;
void context_bind_dummy_textures(const struct wined3d_device *device,
const struct wined3d_context *context) DECLSPEC_HIDDEN;
void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name) DECLSPEC_HIDDEN;
void context_check_fbo_status(const struct wined3d_context *context, GLenum target) DECLSPEC_HIDDEN;
struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, struct wined3d_texture *target,
@ -2484,11 +2486,14 @@ struct wined3d_device
struct wined3d_texture *logo_texture;
/* Textures for when no other textures are mapped */
GLuint dummy_texture_2d[MAX_COMBINED_SAMPLERS];
GLuint dummy_texture_rect[MAX_COMBINED_SAMPLERS];
GLuint dummy_texture_3d[MAX_COMBINED_SAMPLERS];
GLuint dummy_texture_cube[MAX_COMBINED_SAMPLERS];
GLuint dummy_texture_2d_array[MAX_COMBINED_SAMPLERS];
struct
{
GLuint tex_2d;
GLuint tex_rect;
GLuint tex_3d;
GLuint tex_cube;
GLuint tex_2d_array;
} dummy_textures;
/* Default sampler used to emulate the direct resource access without using wined3d_sampler */
GLuint default_sampler;