From b84d9ad9c1ae9a0e4e5615b160826599ed4646da Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Fri, 24 Sep 2021 01:05:31 +1200 Subject: [PATCH 01/11] panfrost: Implement GL_EXT_clip_control I didn't realise it would be this simple before seeing the Lima implementation. --- docs/features.txt | 2 +- src/gallium/drivers/panfrost/pan_cmdstream.c | 5 +++-- src/gallium/drivers/panfrost/pan_screen.c | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index bed129f3b530..0fb5675a13cd 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -213,7 +213,7 @@ GL 4.4, GLSL 4.40 -- all DONE: i965/gen8+, nvc0, r600, radeonsi, llvmpipe, zink GL 4.5, GLSL 4.50 -- all DONE: nvc0, r600, radeonsi, llvmpipe, zink GL_ARB_ES3_1_compatibility DONE (i965/hsw+, softpipe, virgl) - GL_ARB_clip_control DONE (freedreno, i965, nv50, softpipe, virgl, lima) + GL_ARB_clip_control DONE (freedreno, i965, nv50, softpipe, virgl, lima, panfrost) GL_ARB_conditional_render_inverted DONE (freedreno, i965, nv50, softpipe, virgl, panfrost, d3d12) GL_ARB_cull_distance DONE (freedreno/a6xx, i965, nv50, softpipe, virgl) GL_ARB_derivative_control DONE (i965, nv50, softpipe, virgl) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 1ef8d09bd2b7..27b1d9178faf 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -29,6 +29,7 @@ #include "util/u_helpers.h" #include "util/u_draw.h" #include "util/u_memory.h" +#include "util/u_viewport.h" #include "pipe/p_defines.h" #include "pipe/p_state.h" #include "gallium/auxiliary/util/u_blend.h" @@ -693,8 +694,8 @@ panfrost_emit_viewport(struct panfrost_batch *batch) float vp_maxx = vp->translate[0] + fabsf(vp->scale[0]); float vp_miny = vp->translate[1] - fabsf(vp->scale[1]); float vp_maxy = vp->translate[1] + fabsf(vp->scale[1]); - float minz = (vp->translate[2] - fabsf(vp->scale[2])); - float maxz = (vp->translate[2] + fabsf(vp->scale[2])); + float minz, maxz; + util_viewport_zmin_zmax(vp, rast->clip_halfz, &minz, &maxz); /* Scissor to the intersection of viewport and to the scissor, clamped * to the framebuffer */ diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index b6e40b1db3bb..deced3d10d2a 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -122,6 +122,7 @@ panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param) case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT: case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION: case PIPE_CAP_SHADER_PACK_HALF_FLOAT: + case PIPE_CAP_CLIP_HALFZ: return 1; case PIPE_CAP_MAX_RENDER_TARGETS: -- GitLab From 6ff4c525e9f854c897df64ba1c1a513d6c51e9b7 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Fri, 4 Feb 2022 19:53:41 +1300 Subject: [PATCH 02/11] panfrost: Handle NULL depth resources in batch_to_fb_info Otherwise we might try to preload data from a resource that does not exist. Also fix a NULL dereference which could happen in that situation. --- src/gallium/drivers/panfrost/pan_job.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index 6e051fd892d7..243fb7e3cf06 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -529,22 +529,22 @@ panfrost_batch_to_fb_info(const struct panfrost_batch *batch, fb->zs.discard.z = !reserve && !(batch->resolve & PIPE_CLEAR_DEPTH); fb->zs.discard.s = !reserve && !(batch->resolve & PIPE_CLEAR_STENCIL); - if (!fb->zs.clear.z && + if (!fb->zs.clear.z && z_rsrc && ((batch->read & PIPE_CLEAR_DEPTH) || ((batch->draws & PIPE_CLEAR_DEPTH) && - z_rsrc && BITSET_TEST(z_rsrc->valid.data, z_view->first_level)))) + BITSET_TEST(z_rsrc->valid.data, z_view->first_level)))) fb->zs.preload.z = true; - if (!fb->zs.clear.s && + if (!fb->zs.clear.s && s_rsrc && ((batch->read & PIPE_CLEAR_STENCIL) || ((batch->draws & PIPE_CLEAR_STENCIL) && - s_rsrc && BITSET_TEST(s_rsrc->valid.data, s_view->first_level)))) + BITSET_TEST(s_rsrc->valid.data, s_view->first_level)))) fb->zs.preload.s = true; /* Preserve both component if we have a combined ZS view and * one component needs to be preserved. */ - if (s_view == z_view && fb->zs.discard.z != fb->zs.discard.s) { + if (z_view && s_view == z_view && fb->zs.discard.z != fb->zs.discard.s) { bool valid = BITSET_TEST(z_rsrc->valid.data, z_view->first_level); fb->zs.discard.z = false; -- GitLab From ea56253becdb2e2983992bb2d84d2f27d619183e Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Sun, 4 Oct 2020 00:25:41 +1300 Subject: [PATCH 03/11] panfrost: Skip clearing buffers that don't exist Nine doesn't bother setting the buffers exactly, and just uses PIPE_CLEAR_COLOR. Reviewed-by: Alyssa Rosenzweig --- src/gallium/drivers/panfrost/pan_job.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index 243fb7e3cf06..b2820c29ced6 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -857,6 +857,8 @@ panfrost_batch_clear(struct panfrost_batch *batch, for (unsigned i = 0; i < ctx->pipe_framebuffer.nr_cbufs; ++i) { if (!(buffers & (PIPE_CLEAR_COLOR0 << i))) continue; + if (!ctx->pipe_framebuffer.cbufs[i]) + continue; enum pipe_format format = ctx->pipe_framebuffer.cbufs[i]->format; pan_pack_color(batch->clear_color[i], color, format, false); -- GitLab From be34880f4fe376bb21116f9bd305a5e26420814e Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Mon, 19 Oct 2020 00:36:10 +1300 Subject: [PATCH 04/11] nine: Make vdecl_index_map always signed vdecl_index_map needs to be able to store negative values, but char is not signed on all platforms, so change it to int8_t. --- src/gallium/frontends/nine/nine_state.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gallium/frontends/nine/nine_state.c b/src/gallium/frontends/nine/nine_state.c index 1365f1c937d0..049535e4f751 100644 --- a/src/gallium/frontends/nine/nine_state.c +++ b/src/gallium/frontends/nine/nine_state.c @@ -840,7 +840,7 @@ update_vertex_elements(struct NineDevice9 *device) const struct NineVertexShader9 *vs; unsigned n, b, i; int index; - char vdecl_index_map[16]; /* vs->num_inputs <= 16 */ + int8_t vdecl_index_map[16]; /* vs->num_inputs <= 16 */ uint16_t used_streams = 0; int dummy_vbo_stream = -1; BOOL need_dummy_vbo = FALSE; @@ -3041,7 +3041,7 @@ update_vertex_elements_sw(struct NineDevice9 *device) const struct NineVertexShader9 *vs; unsigned n, b, i; int index; - char vdecl_index_map[16]; /* vs->num_inputs <= 16 */ + int8_t vdecl_index_map[16]; /* vs->num_inputs <= 16 */ char used_streams[device->caps.MaxStreams]; int dummy_vbo_stream = -1; BOOL need_dummy_vbo = FALSE; -- GitLab From 0d0464dc5331728ef9136d18a931f77e14e1e984 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Mon, 5 Oct 2020 20:25:00 +1300 Subject: [PATCH 05/11] ttn: Only call get_disk_shader_cache when it is set p_screen.h states that the function may be NULL if the driver doesn't support an on-disk shader cache. Fixes: 4db880d8057 ("ttn: Implement disk cache") --- src/gallium/auxiliary/nir/tgsi_to_nir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c index c103c0062523..bc5c16ea44bb 100644 --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c @@ -2603,7 +2603,7 @@ tgsi_to_nir(const void *tgsi_tokens, uint8_t key[CACHE_KEY_SIZE]; unsigned processor; - if (allow_disk_cache) + if (allow_disk_cache && screen->get_disk_shader_cache) cache = screen->get_disk_shader_cache(screen); /* Look first in the cache */ -- GitLab From d7b44284b7151678f847d4847801d147c3cb2f2a Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Thu, 15 Jul 2021 14:30:53 +1200 Subject: [PATCH 06/11] st/nine: Only enable thread_submit by default on x86 Possibly the bug breaking this is in box86, but given that there aren't a whole lot of other reasons to be using Nine with a non-x86 Mesa, disable the feature unless we are running on x86. --- src/gallium/targets/d3dadapter9/drm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gallium/targets/d3dadapter9/drm.c b/src/gallium/targets/d3dadapter9/drm.c index ced9d5bac2de..cab2347c57db 100644 --- a/src/gallium/targets/d3dadapter9/drm.c +++ b/src/gallium/targets/d3dadapter9/drm.c @@ -47,6 +47,12 @@ #define DBG_CHANNEL DBG_ADAPTER +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) +#define DEFAULT_THREADSUBMIT true +#else +#define DEFAULT_THREADSUBMIT false +#endif + const driOptionDescription __driConfigOptionsNine[] = { DRI_CONF_SECTION_PERFORMANCE DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1) @@ -54,7 +60,7 @@ const driOptionDescription __driConfigOptionsNine[] = { DRI_CONF_SECTION_NINE DRI_CONF_NINE_OVERRIDEVENDOR(-1) DRI_CONF_NINE_THROTTLE(-2) - DRI_CONF_NINE_THREADSUBMIT(true) + DRI_CONF_NINE_THREADSUBMIT(DEFAULT_THREADSUBMIT) DRI_CONF_NINE_ALLOWDISCARDDELAYEDRELEASE(true) DRI_CONF_NINE_TEARFREEDISCARD(true) DRI_CONF_NINE_CSMT(-1) -- GitLab From fc56003febc95641a73c75adfc3ff656819efda0 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Thu, 14 Oct 2021 16:29:38 +1300 Subject: [PATCH 07/11] nine,aux/cso: Always update all samplers While bind_sampler_states is specified to not change samplers above start + num_samplers, several drivers ignore this, as otherwise they cannot easily determine the total number of samplers. Add a CSO function to set the maximum sampler number, and call it before updating the samplers. TODO: How much does this hurt performance? --- src/gallium/auxiliary/cso_cache/cso_context.c | 6 ++++++ src/gallium/auxiliary/cso_cache/cso_context.h | 3 +++ src/gallium/frontends/nine/nine_state.c | 8 ++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 111de3f0e247..b0a9e5de61bf 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -1251,6 +1251,12 @@ cso_single_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage, ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, (int)idx); } +void +cso_set_max_sampler(struct cso_context *ctx, int max_sampler_seen) +{ + ctx->max_sampler_seen = max_sampler_seen; +} + /** * Send staged sampler state to the driver. */ diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index 3c5b60642097..f6eaa6a499f3 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -80,6 +80,9 @@ void cso_single_sampler(struct cso_context *cso, enum pipe_shader_type shader_stage, unsigned idx, const struct pipe_sampler_state *states); +void +cso_set_max_sampler(struct cso_context *ctx, int max_sampler_seen); + void cso_single_sampler_done(struct cso_context *cso, enum pipe_shader_type shader_stage); diff --git a/src/gallium/frontends/nine/nine_state.c b/src/gallium/frontends/nine/nine_state.c index 049535e4f751..4244c5f3f1ad 100644 --- a/src/gallium/frontends/nine/nine_state.c +++ b/src/gallium/frontends/nine/nine_state.c @@ -1040,8 +1040,10 @@ update_textures_and_samplers(struct NineDevice9 *device) false, view); context->enabled_sampler_count_ps = num_textures; - if (commit_samplers) + if (commit_samplers) { + cso_set_max_sampler(context->cso, num_textures - 1); cso_single_sampler_done(context->cso, PIPE_SHADER_FRAGMENT); + } commit_samplers = FALSE; sampler_mask = context->programmable_vs ? context->vs->sampler_mask : 0; @@ -1085,8 +1087,10 @@ update_textures_and_samplers(struct NineDevice9 *device) false, view); context->enabled_sampler_count_vs = num_textures; - if (commit_samplers) + if (commit_samplers) { + cso_set_max_sampler(context->cso, num_textures - 1); cso_single_sampler_done(context->cso, PIPE_SHADER_VERTEX); + } } /* State commit only */ -- GitLab From 1adc5da4f46f92d26a8e0c4eb51a99a1aced2b9e Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Sun, 4 Oct 2020 00:23:38 +1300 Subject: [PATCH 08/11] nine: Add panfrost as a supported driver Tested with most of the CodeSampler DX9 samples, running under Wine emulated with box86: https://web.archive.org/web/20161003152649/http://www.codesampler.com/dx9src.htm Reviewed-by: Alyssa Rosenzweig --- meson.build | 3 ++- src/gallium/targets/d3dadapter9/meson.build | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 9f93ad52be76..d0bb7342938a 100644 --- a/meson.build +++ b/meson.build @@ -890,7 +890,8 @@ if with_gallium_st_nine error('The nine state tracker requires gallium softpipe/llvmpipe.') elif not (with_gallium_radeonsi or with_gallium_nouveau or with_gallium_r600 or with_gallium_r300 or with_gallium_svga or with_gallium_i915 - or with_gallium_iris or with_gallium_crocus or with_gallium_zink) + or with_gallium_iris or with_gallium_crocus or with_gallium_zink + or with_gallium_panfrost) error('The nine state tracker requires at least one non-swrast gallium driver.') endif if not with_dri3 diff --git a/src/gallium/targets/d3dadapter9/meson.build b/src/gallium/targets/d3dadapter9/meson.build index c51c9ff1bf36..2bca29357cae 100644 --- a/src/gallium/targets/d3dadapter9/meson.build +++ b/src/gallium/targets/d3dadapter9/meson.build @@ -64,7 +64,8 @@ libgallium_nine = shared_library( dep_selinux, dep_libdrm, dep_llvm, dep_thread, idep_xmlconfig, idep_mesautil, idep_nir, driver_swrast, driver_r300, driver_r600, driver_radeonsi, driver_nouveau, - driver_i915, driver_svga, driver_iris, driver_crocus, driver_zink + driver_i915, driver_svga, driver_iris, driver_crocus, driver_zink, + driver_kmsro, driver_panfrost, ], name_prefix : '', version : '.'.join(nine_version), -- GitLab From b74bab41f7d87b87f2fd216900d1610629298d61 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Fri, 4 Feb 2022 19:56:40 +1300 Subject: [PATCH 09/11] nine: Use 2D textures rather than 1D textures Mali hardware doesn't allow using 1D texture instructions with 2D textures. Because D3D9 does not support actual 1D textures, just replace the texture instructions with 2D ones. TODO: Does this break other hardware? --- src/gallium/frontends/nine/nine_ff.c | 2 +- src/gallium/frontends/nine/nine_shader.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gallium/frontends/nine/nine_ff.c b/src/gallium/frontends/nine/nine_ff.c index 6c9f896ad21d..2af51bebf857 100644 --- a/src/gallium/frontends/nine/nine_ff.c +++ b/src/gallium/frontends/nine/nine_ff.c @@ -1410,7 +1410,7 @@ nine_ff_build_ps(struct NineDevice9 *device, struct nine_ff_ps_key *key) struct ureg_src texture_coord = ps.vT[s]; struct ureg_dst delta; switch (key->ts[s].textarget) { - case 0: target = TGSI_TEXTURE_1D; break; + case 0: target = TGSI_TEXTURE_2D; break; case 1: target = TGSI_TEXTURE_2D; break; case 2: target = TGSI_TEXTURE_3D; break; case 3: target = TGSI_TEXTURE_CUBE; break; diff --git a/src/gallium/frontends/nine/nine_shader.c b/src/gallium/frontends/nine/nine_shader.c index aa2680160f98..9c4b6240f863 100644 --- a/src/gallium/frontends/nine/nine_shader.c +++ b/src/gallium/frontends/nine/nine_shader.c @@ -2159,7 +2159,7 @@ static inline unsigned d3dstt_to_tgsi_tex(BYTE sampler_type) { switch (sampler_type) { - case NINED3DSTT_1D: return TGSI_TEXTURE_1D; + case NINED3DSTT_1D: return TGSI_TEXTURE_2D; case NINED3DSTT_2D: return TGSI_TEXTURE_2D; case NINED3DSTT_VOLUME: return TGSI_TEXTURE_3D; case NINED3DSTT_CUBE: return TGSI_TEXTURE_CUBE; @@ -2172,7 +2172,7 @@ static inline unsigned d3dstt_to_tgsi_tex_shadow(BYTE sampler_type) { switch (sampler_type) { - case NINED3DSTT_1D: return TGSI_TEXTURE_SHADOW1D; + case NINED3DSTT_1D: return TGSI_TEXTURE_SHADOW2D; case NINED3DSTT_2D: return TGSI_TEXTURE_SHADOW2D; case NINED3DSTT_VOLUME: case NINED3DSTT_CUBE: @@ -2186,7 +2186,7 @@ ps1x_sampler_type(const struct nine_shader_info *info, unsigned stage) { boolean shadow = !!(info->sampler_mask_shadow & (1 << stage)); switch ((info->sampler_ps1xtypes >> (stage * 2)) & 0x3) { - case 1: return shadow ? TGSI_TEXTURE_SHADOW1D : TGSI_TEXTURE_1D; + case 1: return shadow ? TGSI_TEXTURE_SHADOW2D : TGSI_TEXTURE_2D; case 0: return shadow ? TGSI_TEXTURE_SHADOW2D : TGSI_TEXTURE_2D; case 3: return TGSI_TEXTURE_3D; default: -- GitLab From a1f9ced8a67e54af7c4b44adb66c5c2bcbd1faeb Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Sun, 4 Oct 2020 00:25:11 +1300 Subject: [PATCH 10/11] [HACK] panfrost: Implement clear_render_target --- src/gallium/drivers/panfrost/pan_resource.c | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index 583b86d95458..f08eb9117975 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -757,6 +757,38 @@ panfrost_resource_destroy(struct pipe_screen *screen, free(rsrc); } +static void +panfrost_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const union pipe_color_union *color, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, + bool render_condition_enabled) +{ + struct panfrost_context *ctx = pan_context(pipe); + + /* TODO: dstx, etc. */ + + struct pipe_framebuffer_state tmp = {0}; + util_copy_framebuffer_state(&tmp, &ctx->pipe_framebuffer); + + struct pipe_framebuffer_state fb = { + .width = dst->width, + .height = dst->height, + .layers = 1, + .samples = 1, + .nr_cbufs = 1, + .cbufs[0] = dst, + }; + pipe->set_framebuffer_state(pipe, &fb); + + struct panfrost_batch *batch = panfrost_get_fresh_batch_for_fbo(ctx, "Clear render target"); + panfrost_batch_clear(batch, PIPE_CLEAR_COLOR0, color, 0, 0); + + pipe->set_framebuffer_state(pipe, &tmp); + util_unreference_framebuffer_state(&tmp); +} + /* Most of the time we can do CPU-side transfers, but sometimes we need to use * the 3D pipe for this. Let's wrap u_blitter to blit to/from staging textures. * Code adapted from freedreno */ @@ -1444,6 +1476,7 @@ panfrost_resource_context_init(struct pipe_context *pctx) pctx->texture_unmap = u_transfer_helper_transfer_unmap; pctx->create_surface = panfrost_create_surface; pctx->surface_destroy = panfrost_surface_destroy; + pctx->clear_render_target = panfrost_clear_render_target; pctx->resource_copy_region = util_resource_copy_region; pctx->blit = panfrost_blit; pctx->generate_mipmap = panfrost_generate_mipmap; -- GitLab From 9abf575069dd2f50325f6c59608a0bf7d1f49b32 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Thu, 14 Oct 2021 16:30:55 +1300 Subject: [PATCH 11/11] [HACK] panfrost: Implement clear_depth_stencil --- src/gallium/drivers/panfrost/pan_resource.c | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index f08eb9117975..8bdd64d3bb51 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -789,6 +789,39 @@ panfrost_clear_render_target(struct pipe_context *pipe, util_unreference_framebuffer_state(&tmp); } +static void +panfrost_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, + bool render_condition_enabled) +{ + struct panfrost_context *ctx = pan_context(pipe); + + /* TODO: dstx, etc. */ + + struct pipe_framebuffer_state tmp; + util_copy_framebuffer_state(&tmp, &ctx->pipe_framebuffer); + + struct pipe_framebuffer_state fb = { + .width = dst->width, + .height = dst->height, + .layers = 1, + .samples = 1, + .nr_cbufs = 0, + .zsbuf = dst, + }; + pipe->set_framebuffer_state(pipe, &fb); + + struct panfrost_batch *batch = panfrost_get_fresh_batch_for_fbo(ctx, "Clear depth/stencil"); + panfrost_batch_clear(batch, clear_flags, NULL, depth, stencil); + + pipe->set_framebuffer_state(pipe, &tmp); + util_unreference_framebuffer_state(&tmp); +} + /* Most of the time we can do CPU-side transfers, but sometimes we need to use * the 3D pipe for this. Let's wrap u_blitter to blit to/from staging textures. * Code adapted from freedreno */ @@ -1477,6 +1510,7 @@ panfrost_resource_context_init(struct pipe_context *pctx) pctx->create_surface = panfrost_create_surface; pctx->surface_destroy = panfrost_surface_destroy; pctx->clear_render_target = panfrost_clear_render_target; + pctx->clear_depth_stencil = panfrost_clear_depth_stencil; pctx->resource_copy_region = util_resource_copy_region; pctx->blit = panfrost_blit; pctx->generate_mipmap = panfrost_generate_mipmap; -- GitLab