From 14da948b74a4844f4a363d847872bcf60b7ebb84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Mon, 6 Nov 2017 10:55:21 +0100 Subject: [PATCH] wined3d: Create textures views for depth views. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Direct3D a different format is used for sampling depth textures, but this is not the case in OpenGL. We still need to create a texture view when a texture type is different than a view type, or when a shader resource view is being created for a subset of sub-resources. Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/utils.c | 25 ++++++++++++++++++++----- dlls/wined3d/view.c | 4 ++++ dlls/wined3d/wined3d_private.h | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 2a12a918b5a..0e00203ee72 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -285,16 +285,17 @@ struct wined3d_typeless_format_depth_stencil_info enum wined3d_format_id depth_stencil_id; enum wined3d_format_id depth_view_id; enum wined3d_format_id stencil_view_id; + BOOL separate_depth_view_format; }; static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats[] = { {WINED3DFMT_R32G8X24_TYPELESS, WINED3DFMT_D32_FLOAT_S8X24_UINT, - WINED3DFMT_R32_FLOAT_X8X24_TYPELESS, WINED3DFMT_X32_TYPELESS_G8X24_UINT}, + WINED3DFMT_R32_FLOAT_X8X24_TYPELESS, WINED3DFMT_X32_TYPELESS_G8X24_UINT, TRUE}, {WINED3DFMT_R24G8_TYPELESS, WINED3DFMT_D24_UNORM_S8_UINT, - WINED3DFMT_R24_UNORM_X8_TYPELESS, WINED3DFMT_X24_TYPELESS_G8_UINT}, - {WINED3DFMT_R32_TYPELESS, WINED3DFMT_D32_FLOAT}, - {WINED3DFMT_R16_TYPELESS, WINED3DFMT_D16_UNORM}, + WINED3DFMT_R24_UNORM_X8_TYPELESS, WINED3DFMT_X24_TYPELESS_G8_UINT, TRUE}, + {WINED3DFMT_R32_TYPELESS, WINED3DFMT_D32_FLOAT, WINED3DFMT_R32_FLOAT}, + {WINED3DFMT_R16_TYPELESS, WINED3DFMT_D16_UNORM, WINED3DFMT_R16_UNORM}, }; struct wined3d_format_ddi_info @@ -3536,7 +3537,8 @@ static BOOL init_typeless_formats(struct wined3d_gl_info *gl_info) typeless_format->flags[j] &= ~(WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL); } - if ((format_id = typeless_depth_stencil_formats[i].depth_view_id)) + if ((format_id = typeless_depth_stencil_formats[i].depth_view_id) + && typeless_depth_stencil_formats[i].separate_depth_view_format) { if (!(depth_view_format = get_format_internal(gl_info, format_id))) return FALSE; @@ -3753,6 +3755,19 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl return format; } +BOOL wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id, + enum wined3d_format_id view_format_id) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(typeless_depth_stencil_formats); ++i) + { + if (typeless_depth_stencil_formats[i].typeless_id == resource_format_id) + return typeless_depth_stencil_formats[i].depth_view_id == view_format_id; + } + return FALSE; +} + void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment, unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch) { diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index 2ffb718581b..62f087b23a4 100644 --- a/dlls/wined3d/view.c +++ b/dlls/wined3d/view.c @@ -712,6 +712,10 @@ static void wined3d_shader_resource_view_cs_init(void *object) { create_texture_view(&view->gl_view, view_target, desc, texture, view_format); } + else if (wined3d_format_is_depth_view(resource->format->id, view_format->id)) + { + create_texture_view(&view->gl_view, view_target, desc, texture, resource->format); + } else { FIXME("Shader resource view not supported, resource format %s, view format %s.\n", diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 6dce9701728..31d83c76c16 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4244,6 +4244,8 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, const struct wined3d_color *color) DECLSPEC_HIDDEN; void wined3d_format_get_float_color_key(const struct wined3d_format *format, const struct wined3d_color_key *key, struct wined3d_color *float_colors) DECLSPEC_HIDDEN; +BOOL wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id, + enum wined3d_format_id view_format_id) DECLSPEC_HIDDEN; const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion( const struct wined3d_texture *texture, BOOL need_alpha_ck) DECLSPEC_HIDDEN;