X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Firis%2Firis_clear.c;h=3d60c6bfbe3a3b06606eb2b889c27f8ce8f8dfc5;hb=4064a6cd207811434e5400a613b3833fbda6b787;hp=ff78352a9f2d70e62cdb2a6728ed3d229862e70c;hpb=30b9ed92ea423a4857023ca5e2222ae409672fa5;p=mesa.git diff --git a/src/gallium/drivers/iris/iris_clear.c b/src/gallium/drivers/iris/iris_clear.c index ff78352a9f2..3d60c6bfbe3 100644 --- a/src/gallium/drivers/iris/iris_clear.c +++ b/src/gallium/drivers/iris/iris_clear.c @@ -27,14 +27,13 @@ #include "pipe/p_context.h" #include "pipe/p_screen.h" #include "util/u_inlines.h" -#include "util/u_format.h" +#include "util/format/u_format.h" #include "util/u_upload_mgr.h" #include "util/ralloc.h" #include "iris_context.h" #include "iris_resource.h" #include "iris_screen.h" #include "intel/compiler/brw_compiler.h" -#include "util/format_srgb.h" static bool iris_is_color_fast_clear_compatible(struct iris_context *ice, @@ -69,13 +68,15 @@ can_fast_clear_color(struct iris_context *ice, struct pipe_resource *p_res, unsigned level, const struct pipe_box *box, - enum isl_format format, enum isl_format render_format, union isl_color_value color) { struct iris_resource *res = (void *) p_res; - if (res->aux.usage == ISL_AUX_USAGE_NONE) + if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR) + return false; + + if (!isl_aux_usage_has_fast_clears(res->aux.usage)) return false; /* Check for partial clear */ @@ -85,13 +86,24 @@ can_fast_clear_color(struct iris_context *ice, return false; } + /* Disable sRGB fast-clears for non-0/1 color values. For texturing and + * draw calls, HW expects the clear color to be in two different color + * spaces after sRGB fast-clears - sRGB in the former and linear in the + * latter. By limiting the allowable values to 0/1, both color space + * requirements are satisfied. + */ + if (isl_format_is_srgb(render_format) && + !isl_color_value_is_zero_one(color, render_format)) { + return false; + } + /* We store clear colors as floats or uints as needed. If there are * texture views in play, the formats will not properly be respected * during resolves because the resolve operations only know about the * resource and not the renderbuffer. */ - if (isl_format_srgb_to_linear(render_format) != - isl_format_srgb_to_linear(format)) { + if (!iris_render_formats_color_compatible(render_format, res->surf.format, + color)) { return false; } @@ -99,7 +111,7 @@ can_fast_clear_color(struct iris_context *ice, * see intel_miptree_create_for_dri_image() */ - if (!iris_is_color_fast_clear_compatible(ice, format, color)) + if (!iris_is_color_fast_clear_compatible(ice, res->surf.format, color)) return false; return true; @@ -108,7 +120,6 @@ can_fast_clear_color(struct iris_context *ice, static union isl_color_value convert_fast_clear_color(struct iris_context *ice, struct iris_resource *res, - enum isl_format render_format, const union isl_color_value color) { union isl_color_value override_color = color; @@ -135,7 +146,7 @@ convert_fast_clear_color(struct iris_context *ice, if (util_format_is_unorm(format)) { for (int i = 0; i < 4; i++) - override_color.f32[i] = CLAMP(override_color.f32[i], 0.0f, 1.0f); + override_color.f32[i] = SATURATE(override_color.f32[i]); } else if (util_format_is_snorm(format)) { for (int i = 0; i < 4; i++) override_color.f32[i] = CLAMP(override_color.f32[i], -1.0f, 1.0f); @@ -172,14 +183,6 @@ convert_fast_clear_color(struct iris_context *ice, override_color.f32[3] = 1.0f; } - /* Handle linear to SRGB conversion */ - if (isl_format_is_srgb(render_format)) { - for (int i = 0; i < 3; i++) { - override_color.f32[i] = - util_format_linear_to_srgb_float(override_color.f32[i]); - } - } - return override_color; } @@ -197,7 +200,7 @@ fast_clear_color(struct iris_context *ice, const enum isl_aux_state aux_state = iris_resource_get_aux_state(res, level, box->z); - color = convert_fast_clear_color(ice, res, format, color); + color = convert_fast_clear_color(ice, res, color); bool color_changed = !!memcmp(&res->aux.clear_color, &color, sizeof(color)); @@ -216,7 +219,7 @@ fast_clear_color(struct iris_context *ice, * is not something that should happen often, we stall on the CPU here * to resolve the predication, and then proceed. */ - ice->vtbl.resolve_conditional_render(ice); + batch->screen->vtbl.resolve_conditional_render(ice); if (ice->state.predicate == IRIS_PREDICATE_STATE_DONT_RENDER) return; @@ -251,7 +254,7 @@ fast_clear_color(struct iris_context *ice, * Fortunately, few applications ever change their clear color at * different levels/layers, so this shouldn't happen often. */ - iris_resource_prepare_access(ice, batch, res, + iris_resource_prepare_access(ice, res, res_lvl, 1, layer, 1, res->aux.usage, false); @@ -293,6 +296,8 @@ fast_clear_color(struct iris_context *ice, "fast clear: pre-flush", PIPE_CONTROL_RENDER_TARGET_FLUSH); + iris_batch_sync_region_start(batch); + /* If we reach this point, we need to fast clear to change the state to * ISL_AUX_STATE_CLEAR, or to update the fast clear color (or both). */ @@ -302,16 +307,10 @@ fast_clear_color(struct iris_context *ice, blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags); struct blorp_surf surf; - iris_blorp_surf_for_resource(&ice->vtbl, &surf, p_res, res->aux.usage, - level, true); - - /* In newer gens (> 9), the hardware will do a linear -> sRGB conversion of - * the clear color during the fast clear, if the surface format is of sRGB - * type. We use the linear version of the surface format here to prevent - * that from happening, since we already do our own linear -> sRGB - * conversion in convert_fast_clear_color(). - */ - blorp_fast_clear(&blorp_batch, &surf, isl_format_srgb_to_linear(format), + iris_blorp_surf_for_resource(&batch->screen->isl_dev, &surf, + p_res, res->aux.usage, level, true); + + blorp_fast_clear(&blorp_batch, &surf, format, ISL_SWIZZLE_IDENTITY, level, box->z, box->depth, box->x, box->y, box->x + box->width, box->y + box->height); @@ -319,10 +318,12 @@ fast_clear_color(struct iris_context *ice, iris_emit_end_of_pipe_sync(batch, "fast clear: post flush", PIPE_CONTROL_RENDER_TARGET_FLUSH); + iris_batch_sync_region_end(batch); iris_resource_set_aux_state(ice, res, level, box->z, box->depth, ISL_AUX_STATE_CLEAR); - ice->state.dirty |= IRIS_ALL_DIRTY_BINDINGS; + ice->state.dirty |= IRIS_DIRTY_RENDER_BUFFER; + ice->state.stage_dirty |= IRIS_ALL_STAGE_DIRTY_BINDINGS; return; } @@ -351,12 +352,12 @@ clear_color(struct iris_context *ice, } if (p_res->target == PIPE_BUFFER) - util_range_add(&res->valid_buffer_range, box->x, box->x + box->width); + util_range_add(&res->base, &res->valid_buffer_range, box->x, box->x + box->width); iris_batch_maybe_flush(batch, 1500); bool can_fast_clear = can_fast_clear_color(ice, p_res, level, box, - res->surf.format, format, color); + format, color); if (can_fast_clear) { fast_clear_color(ice, res, level, box, format, color, blorp_flags); @@ -365,15 +366,17 @@ clear_color(struct iris_context *ice, bool color_write_disable[4] = { false, false, false, false }; enum isl_aux_usage aux_usage = - iris_resource_render_aux_usage(ice, res, format, - false, false); + iris_resource_render_aux_usage(ice, res, format, false); iris_resource_prepare_render(ice, batch, res, level, box->z, box->depth, aux_usage); + iris_emit_buffer_barrier_for(batch, res->bo, IRIS_DOMAIN_RENDER_WRITE); struct blorp_surf surf; - iris_blorp_surf_for_resource(&ice->vtbl, &surf, p_res, aux_usage, level, - true); + iris_blorp_surf_for_resource(&batch->screen->isl_dev, &surf, + p_res, aux_usage, level, true); + + iris_batch_sync_region_start(batch); struct blorp_batch blorp_batch; blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags); @@ -388,6 +391,8 @@ clear_color(struct iris_context *ice, color, color_write_disable); blorp_batch_finish(&blorp_batch); + iris_batch_sync_region_end(batch); + iris_flush_and_dirty_for_history(ice, batch, res, PIPE_CONTROL_RENDER_TARGET_FLUSH, "cache history: post color clear"); @@ -404,6 +409,12 @@ can_fast_clear_depth(struct iris_context *ice, float depth) { struct pipe_resource *p_res = (void *) res; + struct pipe_context *ctx = (void *) ice; + struct iris_screen *screen = (void *) ctx->screen; + const struct gen_device_info *devinfo = &screen->devinfo; + + if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR) + return false; /* Check for partial clears */ if (box->x > 0 || box->y > 0 || @@ -415,7 +426,10 @@ can_fast_clear_depth(struct iris_context *ice, if (!(res->aux.has_hiz & (1 << level))) return false; - return true; + return blorp_can_hiz_clear_depth(devinfo, &res->surf, res->aux.usage, + level, box->z, box->x, box->y, + box->x + box->width, + box->y + box->height); } static void @@ -462,7 +476,7 @@ fast_clear_depth(struct iris_context *ice, * even more complex, so the easiest thing to do when the fast clear * depth is changing is to stall on the CPU and resolve the predication. */ - ice->vtbl.resolve_conditional_render(ice); + batch->screen->vtbl.resolve_conditional_render(ice); if (ice->state.predicate == IRIS_PREDICATE_STATE_DONT_RENDER) return; @@ -509,7 +523,11 @@ fast_clear_depth(struct iris_context *ice, for (unsigned l = 0; l < box->depth; l++) { enum isl_aux_state aux_state = iris_resource_get_aux_state(res, level, box->z + l); - if (aux_state != ISL_AUX_STATE_CLEAR) { + if (update_clear_depth || aux_state != ISL_AUX_STATE_CLEAR) { + if (aux_state == ISL_AUX_STATE_CLEAR) { + perf_debug(&ice->dbg, "Performing HiZ clear just to update the " + "depth clear value\n"); + } iris_hiz_exec(ice, batch, res, level, box->z + l, 1, ISL_AUX_OP_FAST_CLEAR, update_clear_depth); @@ -565,41 +583,57 @@ clear_depth_stencil(struct iris_context *ice, /* At this point, we might have fast cleared the depth buffer. So if there's * no stencil clear pending, return early. */ - if (!(clear_depth || clear_stencil)) { + if (!(clear_depth || (clear_stencil && stencil_res))) { return; } - if (z_res) { + if (clear_depth && z_res) { iris_resource_prepare_depth(ice, batch, z_res, level, box->z, box->depth); - iris_blorp_surf_for_resource(&ice->vtbl, &z_surf, &z_res->base, - z_res->aux.usage, level, true); + iris_emit_buffer_barrier_for(batch, z_res->bo, IRIS_DOMAIN_DEPTH_WRITE); + iris_blorp_surf_for_resource(&batch->screen->isl_dev, + &z_surf, &z_res->base, z_res->aux.usage, + level, true); } + uint8_t stencil_mask = clear_stencil && stencil_res ? 0xff : 0; + if (stencil_mask) { + iris_resource_prepare_access(ice, stencil_res, level, 1, box->z, + box->depth, stencil_res->aux.usage, false); + iris_emit_buffer_barrier_for(batch, stencil_res->bo, + IRIS_DOMAIN_DEPTH_WRITE); + iris_blorp_surf_for_resource(&batch->screen->isl_dev, + &stencil_surf, &stencil_res->base, + stencil_res->aux.usage, level, true); + } + + iris_batch_sync_region_start(batch); + struct blorp_batch blorp_batch; blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags); - if (stencil_res) { - iris_blorp_surf_for_resource(&ice->vtbl, &stencil_surf, - &stencil_res->base, stencil_res->aux.usage, - level, true); - } - blorp_clear_depth_stencil(&blorp_batch, &z_surf, &stencil_surf, level, box->z, box->depth, box->x, box->y, box->x + box->width, box->y + box->height, clear_depth && z_res, depth, - clear_stencil && stencil_res ? 0xff : 0, stencil); + stencil_mask, stencil); blorp_batch_finish(&blorp_batch); + iris_batch_sync_region_end(batch); + iris_flush_and_dirty_for_history(ice, batch, res, 0, "cache history: post slow ZS clear"); - if (z_res) { + if (clear_depth && z_res) { iris_resource_finish_depth(ice, z_res, level, box->z, box->depth, true); } + + if (stencil_mask) { + iris_resource_finish_write(ice, stencil_res, level, box->z, box->depth, + stencil_res->aux.usage); + } } /** @@ -610,6 +644,7 @@ clear_depth_stencil(struct iris_context *ice, static void iris_clear(struct pipe_context *ctx, unsigned buffers, + const struct pipe_scissor_state *scissor_state, const union pipe_color_union *p_color, double depth, unsigned stencil) @@ -619,15 +654,23 @@ iris_clear(struct pipe_context *ctx, assert(buffers != 0); + struct pipe_box box = { + .width = cso_fb->width, + .height = cso_fb->height, + }; + + if (scissor_state) { + box.x = scissor_state->minx; + box.y = scissor_state->miny; + box.width = MIN2(box.width, scissor_state->maxx - scissor_state->minx); + box.height = MIN2(box.height, scissor_state->maxy - scissor_state->miny); + } + if (buffers & PIPE_CLEAR_DEPTHSTENCIL) { struct pipe_surface *psurf = cso_fb->zsbuf; - struct pipe_box box = { - .width = cso_fb->width, - .height = cso_fb->height, - .depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1, - .z = psurf->u.tex.first_layer, - }; + box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1; + box.z = psurf->u.tex.first_layer, clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box, true, buffers & PIPE_CLEAR_DEPTH, buffers & PIPE_CLEAR_STENCIL, @@ -642,12 +685,8 @@ iris_clear(struct pipe_context *ctx, if (buffers & (PIPE_CLEAR_COLOR0 << i)) { struct pipe_surface *psurf = cso_fb->cbufs[i]; struct iris_surface *isurf = (void *) psurf; - struct pipe_box box = { - .width = cso_fb->width, - .height = cso_fb->height, - .depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1, - .z = psurf->u.tex.first_layer, - }; + box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1, + box.z = psurf->u.tex.first_layer, clear_color(ice, psurf->texture, psurf->u.tex.level, &box, true, isurf->view.format, isurf->view.swizzle, @@ -671,20 +710,24 @@ iris_clear_texture(struct pipe_context *ctx, { struct iris_context *ice = (void *) ctx; struct iris_screen *screen = (void *) ctx->screen; + struct iris_resource *res = (void *) p_res; const struct gen_device_info *devinfo = &screen->devinfo; + if (iris_resource_unfinished_aux_import(res)) + iris_resource_finish_aux_import(ctx->screen, res); + if (util_format_is_depth_or_stencil(p_res->format)) { - const struct util_format_description *fmt_desc = - util_format_description(p_res->format); + const struct util_format_unpack_description *unpack = + util_format_unpack_description(p_res->format); float depth = 0.0; uint8_t stencil = 0; - if (fmt_desc->unpack_z_float) - fmt_desc->unpack_z_float(&depth, 0, data, 0, 1, 1); + if (unpack->unpack_z_float) + util_format_unpack_z_float(p_res->format, &depth, data, 1); - if (fmt_desc->unpack_s_8uint) - fmt_desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1); + if (unpack->unpack_s_8uint) + util_format_unpack_s_8uint(p_res->format, &stencil, data, 1); clear_depth_stencil(ice, p_res, level, box, true, true, true, depth, stencil);