[PATCH 5/5] wined3d: Clear GL textures using glClear() when loading from CLEARED to GPU locations.
Zebediah Figura
zfigura at codeweavers.com
Tue Apr 19 20:20:39 CDT 2022
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
dlls/wined3d/texture.c | 73 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 5979d8d6a28..53d34682ad0 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -3423,14 +3423,87 @@ static void wined3d_texture_gl_unload_location(struct wined3d_texture *texture,
}
}
+static bool use_ffp_clear(const struct wined3d_texture *texture, unsigned int location)
+{
+ if (location == WINED3D_LOCATION_DRAWABLE)
+ return true;
+
+ /* If we are not using FBOs (and not rendering to the drawable), always
+ * upload. The upload should always succeed in this case; we cannot have
+ * ARB_texture_multisample without ARB_framebuffer_object. */
+ if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
+ return false;
+
+ if (location == WINED3D_LOCATION_TEXTURE_RGB
+ && !(texture->resource.format_flags & WINED3DFMT_FLAG_FBO_ATTACHABLE))
+ return false;
+ if (location == WINED3D_LOCATION_TEXTURE_SRGB
+ && !(texture->resource.format_flags & WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB))
+ return false;
+
+ return location & (WINED3D_LOCATION_RB_MULTISAMPLE | WINED3D_LOCATION_RB_RESOLVED
+ | WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB);
+}
+
static void wined3d_texture_gl_clear(struct wined3d_texture *texture,
unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
+ const struct wined3d_format *format = texture->resource.format;
+ const struct wined3d_gl_info *gl_info = context_gl->gl_info;
struct wined3d_bo_address addr;
TRACE("texture %p, sub_resource_idx %u, context %p, location %s.\n",
texture, sub_resource_idx, context, wined3d_debug_location(location));
+ if (use_ffp_clear(texture, location))
+ {
+ GLbitfield clear_mask = 0;
+
+ wined3d_texture_prepare_location(texture, sub_resource_idx, context, location);
+
+ context_gl_apply_texture_draw_state(context_gl, texture, sub_resource_idx, location);
+
+ gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
+ context_invalidate_state(context, STATE_RASTERIZER);
+
+ if (format->depth_size)
+ {
+ gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE);
+ context_invalidate_state(context, STATE_DEPTH_STENCIL);
+
+ if (gl_info->supported[ARB_ES2_COMPATIBILITY])
+ GL_EXTCALL(glClearDepthf(0.0f));
+ else
+ gl_info->gl_ops.gl.p_glClearDepth(0.0);
+ clear_mask |= GL_DEPTH_BUFFER_BIT;
+ }
+
+ if (format->stencil_size)
+ {
+ if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
+ gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
+ gl_info->gl_ops.gl.p_glStencilMask(~0u);
+ context_invalidate_state(context, STATE_DEPTH_STENCIL);
+ gl_info->gl_ops.gl.p_glClearStencil(0);
+ clear_mask |= GL_STENCIL_BUFFER_BIT;
+ }
+
+ if (!format->depth_size && !format->stencil_size)
+ {
+ gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ context_invalidate_state(context, STATE_BLEND);
+ gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ clear_mask |= GL_COLOR_BUFFER_BIT;
+ }
+
+ gl_info->gl_ops.gl.p_glClear(clear_mask);
+ checkGLcall("clear texture");
+
+ wined3d_texture_validate_location(texture, sub_resource_idx, location);
+ return;
+ }
+
wined3d_texture_prepare_location(texture, sub_resource_idx, context, WINED3D_LOCATION_SYSMEM);
wined3d_texture_get_bo_address(texture, sub_resource_idx, &addr, WINED3D_LOCATION_SYSMEM);
memset(addr.addr, 0, texture->sub_resources[sub_resource_idx].size);
--
2.35.1
More information about the wine-devel
mailing list