diff options
author | Chia-I Wu <[email protected]> | 2014-09-04 13:56:32 +0800 |
---|---|---|
committer | Chia-I Wu <[email protected]> | 2014-09-09 13:31:36 +0800 |
commit | 55f80a3290cb0e07db780265369eb504573b4e62 (patch) | |
tree | 73f26e1b54ea39df331af02fe9092e42351da75f | |
parent | dab4a676f7590e94640461ad454911e09d95fa88 (diff) |
ilo: make ilo_cp based on ilo_builder
This makes ilo_cp use the builder to manage batch buffers, and use
ilo_builder_decode() to replace ilo_3d_pipeline_dump().
-rw-r--r-- | src/gallium/drivers/ilo/Makefile.sources | 1 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_3d.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_3d_pipeline.c | 16 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_3d_pipeline.h | 3 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c | 648 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c | 9 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c | 4 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_blitter_blt.c | 11 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_context.c | 15 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_context.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_cp.c | 236 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_cp.h | 114 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_gpe_gen6.h | 27 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_gpe_gen7.h | 2 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_query.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/ilo/ilo_transfer.c | 2 |
16 files changed, 114 insertions, 979 deletions
diff --git a/src/gallium/drivers/ilo/Makefile.sources b/src/gallium/drivers/ilo/Makefile.sources index 7f0cf75938d..dbcbfb9fee7 100644 --- a/src/gallium/drivers/ilo/Makefile.sources +++ b/src/gallium/drivers/ilo/Makefile.sources @@ -2,7 +2,6 @@ C_SOURCES := \ ilo_3d.c \ ilo_3d.h \ ilo_3d_pipeline.c \ - ilo_3d_pipeline_dump.c \ ilo_3d_pipeline_gen6.c \ ilo_3d_pipeline_gen6.h \ ilo_3d_pipeline_gen7.c \ diff --git a/src/gallium/drivers/ilo/ilo_3d.c b/src/gallium/drivers/ilo/ilo_3d.c index 48984ba006a..e6c72d35484 100644 --- a/src/gallium/drivers/ilo/ilo_3d.c +++ b/src/gallium/drivers/ilo/ilo_3d.c @@ -396,7 +396,7 @@ void ilo_3d_cp_flushed(struct ilo_3d *hw3d) { if (ilo_debug & ILO_DEBUG_3D) - ilo_3d_pipeline_dump(hw3d->pipeline); + ilo_builder_decode(&hw3d->cp->builder); /* invalidate the pipeline */ ilo_3d_pipeline_invalidate(hw3d->pipeline, diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline.c b/src/gallium/drivers/ilo/ilo_3d_pipeline.c index 1152a7ffc3e..bea5406404f 100644 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline.c +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline.c @@ -172,10 +172,10 @@ ilo_3d_pipeline_emit_draw(struct ilo_3d_pipeline *p, while (true) { - struct ilo_cp_jmp_buf jmp; + struct ilo_builder_snapshot snapshot; /* we will rewind if aperture check below fails */ - ilo_cp_setjmp(p->cp, &jmp); + ilo_builder_batch_snapshot(&p->cp->builder, &snapshot); handle_invalid_batch_bo(p, false); @@ -184,13 +184,13 @@ ilo_3d_pipeline_emit_draw(struct ilo_3d_pipeline *p, p->emit_draw(p, ilo); ilo_cp_assert_no_implicit_flush(p->cp, false); - if (intel_winsys_can_submit_bo(ilo->winsys, &p->cp->bo, 1)) { + if (ilo_builder_validate(&ilo->cp->builder, 0, NULL)) { success = true; break; } /* rewind */ - ilo_cp_longjmp(p->cp, &jmp); + ilo_builder_batch_restore(&p->cp->builder, &snapshot); if (ilo_cp_empty(p->cp)) { success = false; @@ -279,10 +279,10 @@ ilo_3d_pipeline_emit_rectlist(struct ilo_3d_pipeline *p, ilo_cp_flush(p->cp, "out of space"); while (true) { - struct ilo_cp_jmp_buf jmp; + struct ilo_builder_snapshot snapshot; /* we will rewind if aperture check below fails */ - ilo_cp_setjmp(p->cp, &jmp); + ilo_builder_batch_snapshot(&p->cp->builder, &snapshot); handle_invalid_batch_bo(p, false); @@ -290,9 +290,9 @@ ilo_3d_pipeline_emit_rectlist(struct ilo_3d_pipeline *p, p->emit_rectlist(p, blitter); ilo_cp_assert_no_implicit_flush(p->cp, false); - if (!intel_winsys_can_submit_bo(blitter->ilo->winsys, &p->cp->bo, 1)) { + if (!ilo_builder_validate(&p->cp->builder, 0, NULL)) { /* rewind */ - ilo_cp_longjmp(p->cp, &jmp); + ilo_builder_batch_restore(&p->cp->builder, &snapshot); /* flush and try again */ if (!ilo_cp_empty(p->cp)) { diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline.h b/src/gallium/drivers/ilo/ilo_3d_pipeline.h index 90c626e5274..d5771c49641 100644 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline.h +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline.h @@ -194,7 +194,4 @@ ilo_3d_pipeline_get_sample_position(struct ilo_3d_pipeline *p, unsigned sample_index, float *x, float *y); -void -ilo_3d_pipeline_dump(struct ilo_3d_pipeline *p); - #endif /* ILO_3D_PIPELINE_H */ diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c b/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c deleted file mode 100644 index de47e8d4558..00000000000 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline_dump.c +++ /dev/null @@ -1,648 +0,0 @@ -/* - * Copyright © 2007 Intel Corporation - * Copyright (C) 2012-2013 LunarG, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - * - * Authors: - * Eric Anholt <[email protected]> - * Chia-I Wu <[email protected]> - */ - -#include "intel_winsys.h" - -#include "ilo_cp.h" -#include "ilo_3d_pipeline.h" - -#define PRINTFLIKE(f, a) _util_printf_format(f, a) -typedef short GLshort; -typedef int GLint; -typedef unsigned char GLubyte; -typedef unsigned int GLuint; -typedef float GLfloat; -#include <stdint.h> -#include <stdarg.h> -#include <stdio.h> -#include "brw_structs.h" -#include "brw_defines.h" - -struct intel_context { - int gen; - - struct { - struct { - void *virtual; - } *bo, bo_dst; - } batch; -}; - -struct brw_context { - struct intel_context intel; -}; - -static void -batch_out(struct brw_context *brw, const char *name, uint32_t offset, - int index, char *fmt, ...) PRINTFLIKE(5, 6); - -static void -batch_out(struct brw_context *brw, const char *name, uint32_t offset, - int index, char *fmt, ...) -{ - struct intel_context *intel = &brw->intel; - uint32_t *data = intel->batch.bo->virtual + offset; - va_list va; - - fprintf(stderr, "0x%08x: 0x%08x: %8s: ", - offset + index * 4, data[index], name); - va_start(va, fmt); - vfprintf(stderr, fmt, va); - va_end(va); -} - -static const char * -get_965_surfacetype(unsigned int surfacetype) -{ - switch (surfacetype) { - case 0: return "1D"; - case 1: return "2D"; - case 2: return "3D"; - case 3: return "CUBE"; - case 4: return "BUFFER"; - case 7: return "NULL"; - default: return "unknown"; - } -} - -static const char * -get_965_surface_format(unsigned int surface_format) -{ - switch (surface_format) { - case 0x000: return "r32g32b32a32_float"; - case 0x0c1: return "b8g8r8a8_unorm"; - case 0x100: return "b5g6r5_unorm"; - case 0x102: return "b5g5r5a1_unorm"; - case 0x104: return "b4g4r4a4_unorm"; - default: return "unknown"; - } -} - -static void dump_vs_state(struct brw_context *brw, uint32_t offset) -{ - struct intel_context *intel = &brw->intel; - const char *name = "VS_STATE"; - struct brw_vs_unit_state *vs = intel->batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "thread0\n"); - batch_out(brw, name, offset, 1, "thread1\n"); - batch_out(brw, name, offset, 2, "thread2\n"); - batch_out(brw, name, offset, 3, "thread3\n"); - batch_out(brw, name, offset, 4, "thread4: %d threads\n", - vs->thread4.max_threads + 1); - batch_out(brw, name, offset, 5, "vs5\n"); - batch_out(brw, name, offset, 6, "vs6\n"); -} - -static void dump_gs_state(struct brw_context *brw, uint32_t offset) -{ - struct intel_context *intel = &brw->intel; - const char *name = "GS_STATE"; - struct brw_gs_unit_state *gs = intel->batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "thread0\n"); - batch_out(brw, name, offset, 1, "thread1\n"); - batch_out(brw, name, offset, 2, "thread2\n"); - batch_out(brw, name, offset, 3, "thread3\n"); - batch_out(brw, name, offset, 4, "thread4: %d threads\n", - gs->thread4.max_threads + 1); - batch_out(brw, name, offset, 5, "vs5\n"); - batch_out(brw, name, offset, 6, "vs6\n"); -} - -static void dump_clip_state(struct brw_context *brw, uint32_t offset) -{ - struct intel_context *intel = &brw->intel; - const char *name = "CLIP_STATE"; - struct brw_clip_unit_state *clip = intel->batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "thread0\n"); - batch_out(brw, name, offset, 1, "thread1\n"); - batch_out(brw, name, offset, 2, "thread2\n"); - batch_out(brw, name, offset, 3, "thread3\n"); - batch_out(brw, name, offset, 4, "thread4: %d threads\n", - clip->thread4.max_threads + 1); - batch_out(brw, name, offset, 5, "clip5\n"); - batch_out(brw, name, offset, 6, "clip6\n"); - batch_out(brw, name, offset, 7, "vp xmin %f\n", clip->viewport_xmin); - batch_out(brw, name, offset, 8, "vp xmax %f\n", clip->viewport_xmax); - batch_out(brw, name, offset, 9, "vp ymin %f\n", clip->viewport_ymin); - batch_out(brw, name, offset, 10, "vp ymax %f\n", clip->viewport_ymax); -} - -static void dump_sf_state(struct brw_context *brw, uint32_t offset) -{ - struct intel_context *intel = &brw->intel; - const char *name = "SF_STATE"; - struct brw_sf_unit_state *sf = intel->batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "thread0\n"); - batch_out(brw, name, offset, 1, "thread1\n"); - batch_out(brw, name, offset, 2, "thread2\n"); - batch_out(brw, name, offset, 3, "thread3\n"); - batch_out(brw, name, offset, 4, "thread4: %d threads\n", - sf->thread4.max_threads + 1); - batch_out(brw, name, offset, 5, "sf5: viewport offset\n"); - batch_out(brw, name, offset, 6, "sf6\n"); - batch_out(brw, name, offset, 7, "sf7\n"); -} - -static void dump_wm_state(struct brw_context *brw, uint32_t offset) -{ - struct intel_context *intel = &brw->intel; - const char *name = "WM_STATE"; - struct brw_wm_unit_state *wm = intel->batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "thread0\n"); - batch_out(brw, name, offset, 1, "thread1\n"); - batch_out(brw, name, offset, 2, "thread2\n"); - batch_out(brw, name, offset, 3, "thread3\n"); - batch_out(brw, name, offset, 4, "wm4\n"); - batch_out(brw, name, offset, 5, "wm5: %s%s%s%s%s%s, %d threads\n", - wm->wm5.enable_8_pix ? "8pix" : "", - wm->wm5.enable_16_pix ? "16pix" : "", - wm->wm5.program_uses_depth ? ", uses depth" : "", - wm->wm5.program_computes_depth ? ", computes depth" : "", - wm->wm5.program_uses_killpixel ? ", kills" : "", - wm->wm5.thread_dispatch_enable ? "" : ", no dispatch", - wm->wm5.max_threads + 1); - batch_out(brw, name, offset, 6, "depth offset constant %f\n", - wm->global_depth_offset_constant); - batch_out(brw, name, offset, 7, "depth offset scale %f\n", - wm->global_depth_offset_scale); - batch_out(brw, name, offset, 8, "wm8: kernel 1 (gen5+)\n"); - batch_out(brw, name, offset, 9, "wm9: kernel 2 (gen5+)\n"); - batch_out(brw, name, offset, 10, "wm10: kernel 3 (gen5+)\n"); -} - -static void dump_surface_state(struct brw_context *brw, uint32_t offset) -{ - const char *name = "SURF"; - uint32_t *surf = brw->intel.batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "%s %s\n", - get_965_surfacetype(GET_FIELD(surf[0], BRW_SURFACE_TYPE)), - get_965_surface_format(GET_FIELD(surf[0], BRW_SURFACE_FORMAT))); - batch_out(brw, name, offset, 1, "offset\n"); - batch_out(brw, name, offset, 2, "%dx%d size, %d mips\n", - GET_FIELD(surf[2], BRW_SURFACE_WIDTH) + 1, - GET_FIELD(surf[2], BRW_SURFACE_HEIGHT) + 1, - GET_FIELD(surf[2], BRW_SURFACE_LOD)); - batch_out(brw, name, offset, 3, "pitch %d, %s tiled\n", - GET_FIELD(surf[3], BRW_SURFACE_PITCH) + 1, - (surf[3] & BRW_SURFACE_TILED) ? - ((surf[3] & BRW_SURFACE_TILED_Y) ? "Y" : "X") : "not"); - batch_out(brw, name, offset, 4, "mip base %d\n", - GET_FIELD(surf[4], BRW_SURFACE_MIN_LOD)); - batch_out(brw, name, offset, 5, "x,y offset: %d,%d\n", - GET_FIELD(surf[5], BRW_SURFACE_X_OFFSET), - GET_FIELD(surf[5], BRW_SURFACE_Y_OFFSET)); -} - -static void dump_gen7_surface_state(struct brw_context *brw, uint32_t offset) -{ - const char *name = "SURF"; - uint32_t *surf = brw->intel.batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "%s %s\n", - get_965_surfacetype(GET_FIELD(surf[0], BRW_SURFACE_TYPE)), - get_965_surface_format(GET_FIELD(surf[0], BRW_SURFACE_FORMAT))); - batch_out(brw, name, offset, 1, "offset\n"); - batch_out(brw, name, offset, 2, "%dx%d size, %d mips\n", - GET_FIELD(surf[2], GEN7_SURFACE_WIDTH) + 1, - GET_FIELD(surf[2], GEN7_SURFACE_HEIGHT) + 1, - surf[5] & INTEL_MASK(3, 0)); - batch_out(brw, name, offset, 3, "pitch %d, %stiled\n", - (surf[3] & INTEL_MASK(17, 0)) + 1, - (surf[0] & (1 << 14)) ? "" : "not "); - batch_out(brw, name, offset, 4, "mip base %d\n", - GET_FIELD(surf[5], GEN7_SURFACE_MIN_LOD)); - batch_out(brw, name, offset, 5, "x,y offset: %d,%d\n", - GET_FIELD(surf[5], BRW_SURFACE_X_OFFSET), - GET_FIELD(surf[5], BRW_SURFACE_Y_OFFSET)); -} - -static void -dump_sdc(struct brw_context *brw, uint32_t offset) -{ - const char *name = "SDC"; - struct intel_context *intel = &brw->intel; - - if (intel->gen >= 5 && intel->gen <= 6) { - struct gen5_sampler_default_color *sdc = (intel->batch.bo->virtual + - offset); - batch_out(brw, name, offset, 0, "unorm rgba\n"); - batch_out(brw, name, offset, 1, "r %f\n", sdc->f[0]); - batch_out(brw, name, offset, 2, "b %f\n", sdc->f[1]); - batch_out(brw, name, offset, 3, "g %f\n", sdc->f[2]); - batch_out(brw, name, offset, 4, "a %f\n", sdc->f[3]); - batch_out(brw, name, offset, 5, "half float rg\n"); - batch_out(brw, name, offset, 6, "half float ba\n"); - batch_out(brw, name, offset, 7, "u16 rg\n"); - batch_out(brw, name, offset, 8, "u16 ba\n"); - batch_out(brw, name, offset, 9, "s16 rg\n"); - batch_out(brw, name, offset, 10, "s16 ba\n"); - batch_out(brw, name, offset, 11, "s8 rgba\n"); - } else { - struct brw_sampler_default_color *sdc = (intel->batch.bo->virtual + - offset); - batch_out(brw, name, offset, 0, "r %f\n", sdc->color[0]); - batch_out(brw, name, offset, 1, "g %f\n", sdc->color[1]); - batch_out(brw, name, offset, 2, "b %f\n", sdc->color[2]); - batch_out(brw, name, offset, 3, "a %f\n", sdc->color[3]); - } -} - -static void dump_sampler_state(struct brw_context *brw, - uint32_t offset, uint32_t size) -{ - struct intel_context *intel = &brw->intel; - int i; - struct brw_sampler_state *samp = intel->batch.bo->virtual + offset; - - assert(intel->gen < 7); - - for (i = 0; i < size / sizeof(*samp); i++) { - char name[20]; - - sprintf(name, "WM SAMP%d", i); - batch_out(brw, name, offset, 0, "filtering\n"); - batch_out(brw, name, offset, 1, "wrapping, lod\n"); - batch_out(brw, name, offset, 2, "default color pointer\n"); - batch_out(brw, name, offset, 3, "chroma key, aniso\n"); - - samp++; - offset += sizeof(*samp); - } -} - -static void dump_gen7_sampler_state(struct brw_context *brw, - uint32_t offset, uint32_t size) -{ - struct intel_context *intel = &brw->intel; - struct gen7_sampler_state *samp = intel->batch.bo->virtual + offset; - int i; - - assert(intel->gen >= 7); - - for (i = 0; i < size / sizeof(*samp); i++) { - char name[20]; - - sprintf(name, "WM SAMP%d", i); - batch_out(brw, name, offset, 0, "filtering\n"); - batch_out(brw, name, offset, 1, "wrapping, lod\n"); - batch_out(brw, name, offset, 2, "default color pointer\n"); - batch_out(brw, name, offset, 3, "chroma key, aniso\n"); - - samp++; - offset += sizeof(*samp); - } -} - - -static void dump_sf_viewport_state(struct brw_context *brw, - uint32_t offset) -{ - struct intel_context *intel = &brw->intel; - const char *name = "SF VP"; - struct brw_sf_viewport *vp = intel->batch.bo->virtual + offset; - - assert(intel->gen < 7); - - batch_out(brw, name, offset, 0, "m00 = %f\n", vp->viewport.m00); - batch_out(brw, name, offset, 1, "m11 = %f\n", vp->viewport.m11); - batch_out(brw, name, offset, 2, "m22 = %f\n", vp->viewport.m22); - batch_out(brw, name, offset, 3, "m30 = %f\n", vp->viewport.m30); - batch_out(brw, name, offset, 4, "m31 = %f\n", vp->viewport.m31); - batch_out(brw, name, offset, 5, "m32 = %f\n", vp->viewport.m32); - - batch_out(brw, name, offset, 6, "top left = %d,%d\n", - vp->scissor.xmin, vp->scissor.ymin); - batch_out(brw, name, offset, 7, "bottom right = %d,%d\n", - vp->scissor.xmax, vp->scissor.ymax); -} - -static void dump_clip_viewport_state(struct brw_context *brw, - uint32_t offset) -{ - struct intel_context *intel = &brw->intel; - const char *name = "CLIP VP"; - struct brw_clipper_viewport *vp = intel->batch.bo->virtual + offset; - - assert(intel->gen < 7); - - batch_out(brw, name, offset, 0, "xmin = %f\n", vp->xmin); - batch_out(brw, name, offset, 1, "xmax = %f\n", vp->xmax); - batch_out(brw, name, offset, 2, "ymin = %f\n", vp->ymin); - batch_out(brw, name, offset, 3, "ymax = %f\n", vp->ymax); -} - -static void dump_sf_clip_viewport_state(struct brw_context *brw, - uint32_t offset) -{ - struct intel_context *intel = &brw->intel; - const char *name = "SF_CLIP VP"; - struct gen7_sf_clip_viewport *vp = intel->batch.bo->virtual + offset; - - assert(intel->gen >= 7); - - batch_out(brw, name, offset, 0, "m00 = %f\n", vp->viewport.m00); - batch_out(brw, name, offset, 1, "m11 = %f\n", vp->viewport.m11); - batch_out(brw, name, offset, 2, "m22 = %f\n", vp->viewport.m22); - batch_out(brw, name, offset, 3, "m30 = %f\n", vp->viewport.m30); - batch_out(brw, name, offset, 4, "m31 = %f\n", vp->viewport.m31); - batch_out(brw, name, offset, 5, "m32 = %f\n", vp->viewport.m32); - batch_out(brw, name, offset, 6, "guardband xmin = %f\n", vp->guardband.xmin); - batch_out(brw, name, offset, 7, "guardband xmax = %f\n", vp->guardband.xmax); - batch_out(brw, name, offset, 8, "guardband ymin = %f\n", vp->guardband.ymin); - batch_out(brw, name, offset, 9, "guardband ymax = %f\n", vp->guardband.ymax); -} - - -static void dump_cc_viewport_state(struct brw_context *brw, uint32_t offset) -{ - const char *name = "CC VP"; - struct brw_cc_viewport *vp = brw->intel.batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "min_depth = %f\n", vp->min_depth); - batch_out(brw, name, offset, 1, "max_depth = %f\n", vp->max_depth); -} - -static void dump_depth_stencil_state(struct brw_context *brw, uint32_t offset) -{ - const char *name = "D_S"; - struct gen6_depth_stencil_state *ds = brw->intel.batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, - "stencil %sable, func %d, write %sable\n", - ds->ds0.stencil_enable ? "en" : "dis", - ds->ds0.stencil_func, - ds->ds0.stencil_write_enable ? "en" : "dis"); - batch_out(brw, name, offset, 1, - "stencil test mask 0x%x, write mask 0x%x\n", - ds->ds1.stencil_test_mask, ds->ds1.stencil_write_mask); - batch_out(brw, name, offset, 2, - "depth test %sable, func %d, write %sable\n", - ds->ds2.depth_test_enable ? "en" : "dis", - ds->ds2.depth_test_func, - ds->ds2.depth_write_enable ? "en" : "dis"); -} - -static void dump_cc_state_gen4(struct brw_context *brw, uint32_t offset) -{ - const char *name = "CC"; - - batch_out(brw, name, offset, 0, "cc0\n"); - batch_out(brw, name, offset, 1, "cc1\n"); - batch_out(brw, name, offset, 2, "cc2\n"); - batch_out(brw, name, offset, 3, "cc3\n"); - batch_out(brw, name, offset, 4, "cc4: viewport offset\n"); - batch_out(brw, name, offset, 5, "cc5\n"); - batch_out(brw, name, offset, 6, "cc6\n"); - batch_out(brw, name, offset, 7, "cc7\n"); -} - -static void dump_cc_state_gen6(struct brw_context *brw, uint32_t offset) -{ - const char *name = "CC"; - struct gen6_color_calc_state *cc = brw->intel.batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, - "alpha test format %s, round disable %d, stencil ref %d, " - "bf stencil ref %d\n", - cc->cc0.alpha_test_format ? "FLOAT32" : "UNORM8", - cc->cc0.round_disable, - cc->cc0.stencil_ref, - cc->cc0.bf_stencil_ref); - batch_out(brw, name, offset, 1, "\n"); - batch_out(brw, name, offset, 2, "constant red %f\n", cc->constant_r); - batch_out(brw, name, offset, 3, "constant green %f\n", cc->constant_g); - batch_out(brw, name, offset, 4, "constant blue %f\n", cc->constant_b); - batch_out(brw, name, offset, 5, "constant alpha %f\n", cc->constant_a); -} - -static void dump_blend_state(struct brw_context *brw, uint32_t offset) -{ - const char *name = "BLEND"; - - batch_out(brw, name, offset, 0, "\n"); - batch_out(brw, name, offset, 1, "\n"); -} - -static void -dump_scissor(struct brw_context *brw, uint32_t offset) -{ - const char *name = "SCISSOR"; - struct intel_context *intel = &brw->intel; - struct gen6_scissor_rect *scissor = intel->batch.bo->virtual + offset; - - batch_out(brw, name, offset, 0, "xmin %d, ymin %d\n", - scissor->xmin, scissor->ymin); - batch_out(brw, name, offset, 1, "xmax %d, ymax %d\n", - scissor->xmax, scissor->ymax); -} - -static void -dump_vs_constants(struct brw_context *brw, uint32_t offset, uint32_t size) -{ - const char *name = "VS_CONST"; - struct intel_context *intel = &brw->intel; - uint32_t *as_uint = intel->batch.bo->virtual + offset; - float *as_float = intel->batch.bo->virtual + offset; - int i; - - for (i = 0; i < size / 4; i += 4) { - batch_out(brw, name, offset, i, "%3d: (% f % f % f % f) (0x%08x 0x%08x 0x%08x 0x%08x)\n", - i / 4, - as_float[i], as_float[i + 1], as_float[i + 2], as_float[i + 3], - as_uint[i], as_uint[i + 1], as_uint[i + 2], as_uint[i + 3]); - } -} - -static void -dump_wm_constants(struct brw_context *brw, uint32_t offset, uint32_t size) -{ - const char *name = "WM_CONST"; - struct intel_context *intel = &brw->intel; - uint32_t *as_uint = intel->batch.bo->virtual + offset; - float *as_float = intel->batch.bo->virtual + offset; - int i; - - for (i = 0; i < size / 4; i += 4) { - batch_out(brw, name, offset, i, "%3d: (% f % f % f % f) (0x%08x 0x%08x 0x%08x 0x%08x)\n", - i / 4, - as_float[i], as_float[i + 1], as_float[i + 2], as_float[i + 3], - as_uint[i], as_uint[i + 1], as_uint[i + 2], as_uint[i + 3]); - } -} - -static void dump_binding_table(struct brw_context *brw, uint32_t offset, - uint32_t size) -{ - char name[20]; - int i; - uint32_t *data = brw->intel.batch.bo->virtual + offset; - - for (i = 0; i < size / 4; i++) { - if (data[i] == 0) - continue; - - sprintf(name, "BIND%d", i); - batch_out(brw, name, offset, i, "surface state address\n"); - } -} - -static bool -init_brw(struct brw_context *brw, struct ilo_3d_pipeline *p) -{ - brw->intel.gen = ILO_GEN_GET_MAJOR(p->dev->gen); - brw->intel.batch.bo = &brw->intel.batch.bo_dst; - - brw->intel.batch.bo_dst.virtual = intel_bo_map(p->cp->bo, false); - if (!brw->intel.batch.bo_dst.virtual) - return false; - - return true; -} - -static void -dump_3d_state(struct ilo_3d_pipeline *p) -{ - struct brw_context brw; - int num_states, i; - - if (!init_brw(&brw, p)) - return; - - if (brw.intel.gen >= 7) { - dump_cc_viewport_state(&brw, p->state.CC_VIEWPORT); - dump_sf_clip_viewport_state(&brw, p->state.SF_CLIP_VIEWPORT); - } - else { - dump_clip_viewport_state(&brw, p->state.CLIP_VIEWPORT); - dump_sf_viewport_state(&brw, p->state.SF_VIEWPORT); - dump_cc_viewport_state(&brw, p->state.CC_VIEWPORT); - } - - dump_blend_state(&brw, p->state.BLEND_STATE); - dump_cc_state_gen6(&brw, p->state.COLOR_CALC_STATE); - dump_depth_stencil_state(&brw, p->state.DEPTH_STENCIL_STATE); - - /* VS */ - num_states = p->state.vs.BINDING_TABLE_STATE_size; - for (i = 0; i < num_states; i++) { - if (brw.intel.gen < 7) - dump_surface_state(&brw, p->state.vs.SURFACE_STATE[i]); - else - dump_gen7_surface_state(&brw, p->state.vs.SURFACE_STATE[i]); - } - dump_binding_table(&brw, p->state.vs.BINDING_TABLE_STATE, num_states * 4); - - num_states = 0; - for (i = 0; i < Elements(p->state.vs.SAMPLER_BORDER_COLOR_STATE); i++) { - if (!p->state.vs.SAMPLER_BORDER_COLOR_STATE[i]) - continue; - - dump_sdc(&brw, p->state.vs.SAMPLER_BORDER_COLOR_STATE[i]); - num_states++; - } - if (brw.intel.gen < 7) - dump_sampler_state(&brw, p->state.vs.SAMPLER_STATE, num_states * 16); - else - dump_gen7_sampler_state(&brw, p->state.vs.SAMPLER_STATE, num_states * 16); - - if (p->state.vs.PUSH_CONSTANT_BUFFER_size) { - dump_vs_constants(&brw, p->state.vs.PUSH_CONSTANT_BUFFER, - p->state.vs.PUSH_CONSTANT_BUFFER_size); - } - - /* GS */ - num_states = p->state.gs.BINDING_TABLE_STATE_size; - for (i = 0; i < num_states; i++) { - if (!p->state.gs.SURFACE_STATE[i]) - continue; - - if (brw.intel.gen < 7) - dump_surface_state(&brw, p->state.gs.SURFACE_STATE[i]); - else - dump_gen7_surface_state(&brw, p->state.gs.SURFACE_STATE[i]); - } - dump_binding_table(&brw, p->state.gs.BINDING_TABLE_STATE, num_states * 4); - - /* WM */ - num_states = p->state.wm.BINDING_TABLE_STATE_size; - for (i = 0; i < num_states; i++) { - if (!p->state.wm.SURFACE_STATE[i]) - continue; - - if (brw.intel.gen < 7) - dump_surface_state(&brw, p->state.wm.SURFACE_STATE[i]); - else - dump_gen7_surface_state(&brw, p->state.wm.SURFACE_STATE[i]); - } - dump_binding_table(&brw, p->state.wm.BINDING_TABLE_STATE, num_states * 4); - - num_states = 0; - for (i = 0; i < Elements(p->state.wm.SAMPLER_BORDER_COLOR_STATE); i++) { - if (!p->state.wm.SAMPLER_BORDER_COLOR_STATE[i]) - continue; - - dump_sdc(&brw, p->state.wm.SAMPLER_BORDER_COLOR_STATE[i]); - num_states++; - } - if (brw.intel.gen < 7) - dump_sampler_state(&brw, p->state.wm.SAMPLER_STATE, num_states * 16); - else - dump_gen7_sampler_state(&brw, p->state.wm.SAMPLER_STATE, num_states * 16); - - if (p->state.wm.PUSH_CONSTANT_BUFFER_size) { - dump_wm_constants(&brw, p->state.wm.PUSH_CONSTANT_BUFFER, - p->state.wm.PUSH_CONSTANT_BUFFER_size); - } - - dump_scissor(&brw, p->state.SCISSOR_RECT); - - (void) dump_vs_state; - (void) dump_gs_state; - (void) dump_clip_state; - (void) dump_sf_state; - (void) dump_wm_state; - (void) dump_cc_state_gen4; - - intel_bo_unmap(p->cp->bo); -} - -/** - * Dump the pipeline. - */ -void -ilo_3d_pipeline_dump(struct ilo_3d_pipeline *p) -{ - ilo_cp_dump(p->cp); - dump_3d_state(p); -} diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c index 227492a41bf..3bff8961ce8 100644 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c @@ -215,11 +215,14 @@ gen6_pipeline_common_base_address(struct ilo_3d_pipeline *p, /* STATE_BASE_ADDRESS */ if (session->state_bo_changed || session->kernel_bo_changed || session->batch_bo_changed) { + const struct ilo_builder_writer *bat = + &p->cp->builder.writers[ILO_BUILDER_WRITER_BATCH]; + if (p->dev->gen == ILO_GEN(6)) gen6_wa_pipe_control_post_sync(p, false); gen6_emit_STATE_BASE_ADDRESS(p->dev, - NULL, p->cp->bo, p->cp->bo, NULL, ilo->hw3d->kernel.bo, + NULL, bat->bo, bat->bo, NULL, ilo->hw3d->kernel.bo, 0, 0, 0, 0, p->cp); /* @@ -1633,8 +1636,8 @@ gen6_rectlist_commands(struct ilo_3d_pipeline *p, gen6_emit_STATE_BASE_ADDRESS(p->dev, NULL, /* General State Base */ - p->cp->bo, /* Surface State Base */ - p->cp->bo, /* Dynamic State Base */ + p->cp->builder.writers[0].bo, /* Surface State Base */ + p->cp->builder.writers[0].bo, /* Dynamic State Base */ NULL, /* Indirect Object Base */ NULL, /* Instruction Base */ 0, 0, 0, 0, p->cp); diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c index 557e5a8a271..f8c335aac78 100644 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen7.c @@ -802,8 +802,8 @@ gen7_rectlist_commands(struct ilo_3d_pipeline *p, gen6_emit_STATE_BASE_ADDRESS(p->dev, NULL, /* General State Base */ - p->cp->bo, /* Surface State Base */ - p->cp->bo, /* Dynamic State Base */ + p->cp->builder.writers[0].bo, /* Surface State Base */ + p->cp->builder.writers[0].bo, /* Dynamic State Base */ NULL, /* Indirect Object Base */ NULL, /* Instruction Base */ 0, 0, 0, 0, p->cp); diff --git a/src/gallium/drivers/ilo/ilo_blitter_blt.c b/src/gallium/drivers/ilo/ilo_blitter_blt.c index b9156412aee..703aef236b0 100644 --- a/src/gallium/drivers/ilo/ilo_blitter_blt.c +++ b/src/gallium/drivers/ilo/ilo_blitter_blt.c @@ -321,7 +321,7 @@ ilo_blitter_blt_begin(struct ilo_blitter *blitter, int max_cmd_size, struct intel_bo *src, enum intel_tiling_mode src_tiling) { struct ilo_context *ilo = blitter->ilo; - struct intel_bo *aper_check[3]; + struct intel_bo *aper_check[2]; int count; uint32_t swctrl; @@ -330,16 +330,15 @@ ilo_blitter_blt_begin(struct ilo_blitter *blitter, int max_cmd_size, ilo_cp_set_owner(ilo->cp, NULL, 0); /* check aperture space */ - aper_check[0] = ilo->cp->bo; - aper_check[1] = dst; - count = 2; + aper_check[0] = dst; + count = 1; if (src) { - aper_check[2] = src; + aper_check[1] = src; count++; } - if (!intel_winsys_can_submit_bo(ilo->winsys, aper_check, count)) + if (!ilo_builder_validate(&ilo->cp->builder, count, aper_check)) ilo_cp_flush(ilo->cp, "out of aperture"); /* set BCS_SWCTRL */ diff --git a/src/gallium/drivers/ilo/ilo_context.c b/src/gallium/drivers/ilo/ilo_context.c index 04df389c6c2..119d940e3f9 100644 --- a/src/gallium/drivers/ilo/ilo_context.c +++ b/src/gallium/drivers/ilo/ilo_context.c @@ -46,13 +46,6 @@ ilo_context_cp_flushed(struct ilo_cp *cp, void *data) { struct ilo_context *ilo = ilo_context(data); - if (ilo->last_cp_bo) - intel_bo_unreference(ilo->last_cp_bo); - - /* remember the just flushed bo, on which fences could wait */ - ilo->last_cp_bo = cp->bo; - intel_bo_reference(ilo->last_cp_bo); - ilo_3d_cp_flushed(ilo->hw3d); } @@ -68,7 +61,7 @@ ilo_flush(struct pipe_context *pipe, if (f) { *f = (struct pipe_fence_handle *) - ilo_fence_create(pipe->screen, ilo->last_cp_bo); + ilo_fence_create(pipe->screen, ilo->cp->last_submitted_bo); } } @@ -79,9 +72,6 @@ ilo_context_destroy(struct pipe_context *pipe) ilo_cleanup_states(ilo); - if (ilo->last_cp_bo) - intel_bo_unreference(ilo->last_cp_bo); - if (ilo->uploader) u_upload_destroy(ilo->uploader); @@ -119,8 +109,7 @@ ilo_context_create(struct pipe_screen *screen, void *priv) util_slab_create(&ilo->transfer_mempool, sizeof(struct ilo_transfer), 64, UTIL_SLAB_SINGLETHREADED); - /* 8192 DWords */ - ilo->cp = ilo_cp_create(ilo->winsys, 8192, is->dev.has_llc); + ilo->cp = ilo_cp_create(ilo->dev, ilo->winsys); ilo->shader_cache = ilo_shader_cache_create(); if (ilo->cp) ilo->hw3d = ilo_3d_create(ilo->cp, ilo->dev); diff --git a/src/gallium/drivers/ilo/ilo_context.h b/src/gallium/drivers/ilo/ilo_context.h index a5c1ce0755a..d3c74a4db1b 100644 --- a/src/gallium/drivers/ilo/ilo_context.h +++ b/src/gallium/drivers/ilo/ilo_context.h @@ -53,7 +53,6 @@ struct ilo_context { struct util_slab_mempool transfer_mempool; struct ilo_cp *cp; - struct intel_bo *last_cp_bo; struct ilo_shader_cache *shader_cache; struct ilo_3d *hw3d; diff --git a/src/gallium/drivers/ilo/ilo_cp.c b/src/gallium/drivers/ilo/ilo_cp.c index 3ddec6c7bd9..4f65d443f49 100644 --- a/src/gallium/drivers/ilo/ilo_cp.c +++ b/src/gallium/drivers/ilo/ilo_cp.c @@ -25,168 +25,46 @@ * Chia-I Wu <[email protected]> */ -#include "genhw/genhw.h" #include "intel_winsys.h" #include "ilo_cp.h" -/* the size of the private space */ -static const int ilo_cp_private = 2; - -/** - * Dump the contents of the parser bo. This can only be called in the flush - * callback. - */ -void -ilo_cp_dump(struct ilo_cp *cp) -{ - ilo_printf("dumping %d bytes\n", cp->used * 4); - if (cp->used) - intel_winsys_decode_bo(cp->winsys, cp->bo, cp->used * 4); -} - -/** - * Save the command parser state for rewind. - * - * Note that this cannot rewind a flush, and the caller must make sure - * that does not happend. - */ -void -ilo_cp_setjmp(struct ilo_cp *cp, struct ilo_cp_jmp_buf *jmp) +static struct intel_bo * +ilo_cp_end_batch(struct ilo_cp *cp, unsigned *used) { - jmp->id = pointer_to_intptr(cp->bo); - - jmp->size = cp->size; - jmp->used = cp->used; - jmp->stolen = cp->stolen; - /* save reloc count to rewind ilo_cp_write_bo() */ - jmp->reloc_count = intel_bo_get_reloc_count(cp->bo); -} - -/** - * Rewind to the saved state. - */ -void -ilo_cp_longjmp(struct ilo_cp *cp, const struct ilo_cp_jmp_buf *jmp) -{ - if (jmp->id != pointer_to_intptr(cp->bo)) { - assert(!"invalid use of CP longjmp"); - return; - } - - cp->size = jmp->size; - cp->used = jmp->used; - cp->stolen = jmp->stolen; - intel_bo_truncate_relocs(cp->bo, jmp->reloc_count); -} - -/** - * Clear the parser buffer. - */ -static void -ilo_cp_clear_buffer(struct ilo_cp *cp) -{ - cp->cmd_cur = 0; - cp->cmd_end = 0; - - cp->used = 0; - cp->stolen = 0; - - /* - * Recalculate cp->size. This is needed not only because cp->stolen is - * reset above, but also that ilo_cp_private are added to cp->size in - * ilo_cp_end_buffer(). - */ - cp->size = cp->bo_size - ilo_cp_private; -} - -/** - * Add MI_BATCH_BUFFER_END to the private space of the parser buffer. - */ -static void -ilo_cp_end_buffer(struct ilo_cp *cp) -{ - /* make the private space available */ - cp->size += ilo_cp_private; - - assert(cp->used + 2 <= cp->size); - - cp->ptr[cp->used++] = GEN6_MI_CMD(MI_BATCH_BUFFER_END); - - /* - * From the Sandy Bridge PRM, volume 1 part 1, page 107: - * - * "The batch buffer must be QWord aligned and a multiple of QWords in - * length." - */ - if (cp->used & 1) - cp->ptr[cp->used++] = GEN6_MI_CMD(MI_NOOP); -} - -/** - * Upload the parser buffer to the bo. - */ -static int -ilo_cp_upload_buffer(struct ilo_cp *cp) -{ - int err; - - if (!cp->sys) { - intel_bo_unmap(cp->bo); - return 0; - } - - err = intel_bo_pwrite(cp->bo, 0, cp->used * 4, cp->ptr); - if (likely(!err && cp->stolen)) { - const int offset = cp->bo_size - cp->stolen; - - err = intel_bo_pwrite(cp->bo, offset * 4, - cp->stolen * 4, &cp->ptr[offset]); - } - - return err; -} - -/** - * Reallocate the parser bo. - */ -static void -ilo_cp_realloc_bo(struct ilo_cp *cp) -{ - struct intel_bo *bo; + ilo_cp_set_owner(cp, NULL, 0); - /* - * allocate the new bo before unreferencing the old one so that they - * won't point at the same address, which is needed for jmpbuf - */ - bo = intel_winsys_alloc_buffer(cp->winsys, - "batch buffer", cp->bo_size * 4, true); - if (unlikely(!bo)) { - /* reuse the old one */ - bo = cp->bo; - intel_bo_reference(bo); + if (!ilo_builder_batch_used(&cp->builder)) { + ilo_builder_batch_discard(&cp->builder); + return NULL; } - if (cp->bo) - intel_bo_unreference(cp->bo); - cp->bo = bo; + /* see ilo_cp_space() */ + assert(ilo_builder_batch_space(&cp->builder) >= 2); + ilo_builder_batch_mi_batch_buffer_end(&cp->builder); - if (!cp->sys) - cp->ptr = intel_bo_map(cp->bo, true); + return ilo_builder_end(&cp->builder, used); } /** - * Execute the parser bo. + * Flush the command parser and execute the commands. When the parser buffer + * is empty, the callback is not invoked. */ -static int -ilo_cp_exec_bo(struct ilo_cp *cp) +void +ilo_cp_flush_internal(struct ilo_cp *cp) { const bool do_exec = !(ilo_debug & ILO_DEBUG_NOHW); + struct intel_bo *bo; + unsigned used; int err; + bo = ilo_cp_end_batch(cp, &used); + if (!bo) + return; + if (likely(do_exec)) { err = intel_winsys_submit_bo(cp->winsys, cp->ring, - cp->bo, cp->used * 4, cp->render_ctx, cp->one_off_flags); + bo, used, cp->render_ctx, cp->one_off_flags); } else { err = 0; @@ -194,42 +72,17 @@ ilo_cp_exec_bo(struct ilo_cp *cp) cp->one_off_flags = 0; - return err; -} - -/** - * Flush the command parser and execute the commands. When the parser buffer - * is empty, the callback is not invoked. - */ -void -ilo_cp_flush_internal(struct ilo_cp *cp) -{ - int err; - - ilo_cp_set_owner(cp, NULL, 0); - - /* sanity check */ - assert(cp->bo_size == cp->size + cp->stolen + ilo_cp_private); + if (!err) { + if (cp->last_submitted_bo) + intel_bo_unreference(cp->last_submitted_bo); + cp->last_submitted_bo = bo; + intel_bo_reference(cp->last_submitted_bo); - if (!cp->used) { - /* return the space stolen and etc. */ - ilo_cp_clear_buffer(cp); - - return; + if (cp->flush_callback) + cp->flush_callback(cp, cp->flush_callback_data); } - ilo_cp_end_buffer(cp); - - /* upload and execute */ - err = ilo_cp_upload_buffer(cp); - if (likely(!err)) - err = ilo_cp_exec_bo(cp); - - if (likely(!err && cp->flush_callback)) - cp->flush_callback(cp, cp->flush_callback_data); - - ilo_cp_clear_buffer(cp); - ilo_cp_realloc_bo(cp); + ilo_builder_begin(&cp->builder); } /** @@ -238,16 +91,9 @@ ilo_cp_flush_internal(struct ilo_cp *cp) void ilo_cp_destroy(struct ilo_cp *cp) { - if (cp->bo) { - if (!cp->sys) - intel_bo_unmap(cp->bo); - - intel_bo_unreference(cp->bo); - } + ilo_builder_reset(&cp->builder); intel_winsys_destroy_context(cp->winsys, cp->render_ctx); - - FREE(cp->sys); FREE(cp); } @@ -255,7 +101,7 @@ ilo_cp_destroy(struct ilo_cp *cp) * Create a command parser. */ struct ilo_cp * -ilo_cp_create(struct intel_winsys *winsys, int size, bool direct_map) +ilo_cp_create(const struct ilo_dev_info *dev, struct intel_winsys *winsys) { struct ilo_cp *cp; @@ -273,26 +119,12 @@ ilo_cp_create(struct intel_winsys *winsys, int size, bool direct_map) cp->ring = INTEL_RING_RENDER; cp->no_implicit_flush = false; - cp->bo_size = size; + ilo_builder_init(&cp->builder, dev, winsys); - if (!direct_map) { - cp->sys = MALLOC(cp->bo_size * 4); - if (!cp->sys) { - FREE(cp); - return NULL; - } - - cp->ptr = cp->sys; - } - - ilo_cp_realloc_bo(cp); - if (!cp->bo) { - FREE(cp->sys); - FREE(cp); + if (!ilo_builder_begin(&cp->builder)) { + ilo_cp_destroy(cp); return NULL; } - ilo_cp_clear_buffer(cp); - return cp; } diff --git a/src/gallium/drivers/ilo/ilo_cp.h b/src/gallium/drivers/ilo/ilo_cp.h index b4963022b00..bdc75c63d87 100644 --- a/src/gallium/drivers/ilo/ilo_cp.h +++ b/src/gallium/drivers/ilo/ilo_cp.h @@ -30,6 +30,7 @@ #include "intel_winsys.h" +#include "ilo_builder.h" #include "ilo_common.h" struct ilo_cp; @@ -58,27 +59,16 @@ struct ilo_cp { bool no_implicit_flush; unsigned one_off_flags; - int bo_size; - struct intel_bo *bo; - uint32_t *sys; + struct ilo_builder builder; + struct intel_bo *last_submitted_bo; + unsigned pos; uint32_t *ptr; - int size, used, stolen; - int cmd_cur, cmd_end; }; -/** - * Jump buffer to save command parser state for rewind. - */ -struct ilo_cp_jmp_buf { - intptr_t id; - int size, used, stolen; - int reloc_count; -}; - struct ilo_cp * -ilo_cp_create(struct intel_winsys *winsys, int size, bool direct_map); +ilo_cp_create(const struct ilo_dev_info *dev, struct intel_winsys *winsys); void ilo_cp_destroy(struct ilo_cp *cp); @@ -90,32 +80,21 @@ static inline void ilo_cp_flush(struct ilo_cp *cp, const char *reason) { if (ilo_debug & ILO_DEBUG_FLUSH) { - ilo_printf("cp flushed for %s with %d+%d DWords (%.1f%%) because of %s\n", - (cp->ring == INTEL_RING_RENDER) ? "render" : "other", - cp->used, cp->stolen, - (float) (100 * (cp->used + cp->stolen)) / cp->bo_size, - reason); + ilo_printf("cp flushed for %s because of %s: ", + (cp->ring == INTEL_RING_RENDER) ? "render" : "other", reason); + ilo_builder_batch_print_stats(&cp->builder); } ilo_cp_flush_internal(cp); } -void -ilo_cp_dump(struct ilo_cp *cp); - -void -ilo_cp_setjmp(struct ilo_cp *cp, struct ilo_cp_jmp_buf *jmp); - -void -ilo_cp_longjmp(struct ilo_cp *cp, const struct ilo_cp_jmp_buf *jmp); - /** * Return true if the parser buffer is empty. */ static inline bool ilo_cp_empty(struct ilo_cp *cp) { - return !cp->used; + return !ilo_builder_batch_used(&cp->builder); } /** @@ -124,7 +103,12 @@ ilo_cp_empty(struct ilo_cp *cp) static inline int ilo_cp_space(struct ilo_cp *cp) { - return cp->size - cp->used; + const int space = ilo_builder_batch_space(&cp->builder); + const int mi_batch_buffer_end_space = 2; + + assert(space >= cp->owner_reserve + mi_batch_buffer_end_space); + + return space - cp->owner_reserve - mi_batch_buffer_end_space; } /** @@ -135,8 +119,7 @@ ilo_cp_implicit_flush(struct ilo_cp *cp) { if (cp->no_implicit_flush) { assert(!"unexpected command parser flush"); - /* discard the commands */ - cp->used = 0; + ilo_builder_batch_discard(&cp->builder); } ilo_cp_flush(cp, "out of space (implicit)"); @@ -201,7 +184,6 @@ ilo_cp_set_owner(struct ilo_cp *cp, const struct ilo_cp_owner *owner, const bool no_implicit_flush = cp->no_implicit_flush; /* reclaim the reserved space */ - cp->size += cp->owner_reserve; cp->owner_reserve = 0; /* invoke the release callback */ @@ -215,15 +197,13 @@ ilo_cp_set_owner(struct ilo_cp *cp, const struct ilo_cp_owner *owner, if (cp->owner_reserve != reserve) { const int extra = reserve - cp->owner_reserve; - if (cp->used > cp->size - extra) { + if (ilo_cp_space(cp) < extra) { ilo_cp_implicit_flush(cp); - assert(cp->used <= cp->size - reserve); - cp->size -= reserve; + assert(ilo_cp_space(cp) >= reserve); cp->owner_reserve = reserve; } else { - cp->size -= extra; cp->owner_reserve += extra; } } @@ -240,57 +220,47 @@ ilo_cp_set_owner(struct ilo_cp *cp, const struct ilo_cp_owner *owner, static inline void ilo_cp_begin(struct ilo_cp *cp, int cmd_size) { - if (cp->used + cmd_size > cp->size) { + if (ilo_cp_space(cp) < cmd_size) { ilo_cp_implicit_flush(cp); - assert(cp->used + cmd_size <= cp->size); + assert(ilo_cp_space(cp) >= cmd_size); } - assert(cp->cmd_cur == cp->cmd_end); - cp->cmd_cur = cp->used; - cp->cmd_end = cp->cmd_cur + cmd_size; - cp->used = cp->cmd_end; + cp->pos = ilo_builder_batch_pointer(&cp->builder, cmd_size, &cp->ptr); + + cp->cmd_cur = 0; + cp->cmd_end = cmd_size; } /** * Begin writing data to a space stolen from the top of the parser buffer. * - * \param desc informative description of the data to be written + * \param item builder item type * \param data_size in dwords * \param align in dwords * \param bo_offset in bytes to the stolen space */ static inline void -ilo_cp_steal(struct ilo_cp *cp, const char *desc, +ilo_cp_steal(struct ilo_cp *cp, enum ilo_builder_item_type item, int data_size, int align, uint32_t *bo_offset) { - int pad, steal; - if (!align) align = 1; - pad = (cp->bo_size - cp->stolen - data_size) % align; - steal = data_size + pad; - /* flush if there is not enough space after stealing */ - if (cp->used > cp->size - steal) { + if (ilo_cp_space(cp) < data_size + align - 1) { ilo_cp_implicit_flush(cp); - - pad = (cp->bo_size - cp->stolen - data_size) % align; - steal = data_size + steal; - - assert(cp->used <= cp->size - steal); + assert(ilo_cp_space(cp) >= data_size + align - 1); } - cp->size -= steal; - cp->stolen += steal; + cp->pos = ilo_builder_state_pointer(&cp->builder, + item, align << 2, data_size, &cp->ptr) >> 2; - assert(cp->cmd_cur == cp->cmd_end); - cp->cmd_cur = cp->bo_size - cp->stolen; - cp->cmd_end = cp->cmd_cur + data_size; + cp->cmd_cur = 0; + cp->cmd_end = data_size; /* offset in cp->bo */ if (bo_offset) - *bo_offset = cp->cmd_cur * 4; + *bo_offset = cp->pos << 2; } /** @@ -323,20 +293,14 @@ static inline void ilo_cp_write_bo(struct ilo_cp *cp, uint32_t val, struct intel_bo *bo, uint32_t flags) { - uint64_t presumed_offset; - if (bo) { - intel_bo_add_reloc(cp->bo, cp->cmd_cur * 4, bo, val, flags, - &presumed_offset); + ilo_builder_batch_reloc(&cp->builder, cp->pos + cp->cmd_cur, + bo, val, flags); + cp->cmd_cur++; } else { - presumed_offset = 0; + ilo_cp_write(cp, 0); } - - /* 32-bit addressing */ - assert(presumed_offset == (uint64_t) ((uint32_t) presumed_offset)); - - ilo_cp_write(cp, (uint32_t) presumed_offset); } /** @@ -357,12 +321,12 @@ ilo_cp_end(struct ilo_cp *cp) * change is made to the parser. */ static inline void * -ilo_cp_steal_ptr(struct ilo_cp *cp, const char *desc, +ilo_cp_steal_ptr(struct ilo_cp *cp, enum ilo_builder_item_type item, int data_size, int align, uint32_t *bo_offset) { void *ptr; - ilo_cp_steal(cp, desc, data_size, align, bo_offset); + ilo_cp_steal(cp, item, data_size, align, bo_offset); ptr = &cp->ptr[cp->cmd_cur]; cp->cmd_cur = cp->cmd_end; diff --git a/src/gallium/drivers/ilo/ilo_gpe_gen6.h b/src/gallium/drivers/ilo/ilo_gpe_gen6.h index 473337228af..24f7d156934 100644 --- a/src/gallium/drivers/ilo/ilo_gpe_gen6.h +++ b/src/gallium/drivers/ilo/ilo_gpe_gen6.h @@ -1946,7 +1946,7 @@ gen6_emit_INTERFACE_DESCRIPTOR_DATA(const struct ilo_dev_info *dev, ILO_GPE_VALID_GEN(dev, 6, 6); - dw = ilo_cp_steal_ptr(cp, "INTERFACE_DESCRIPTOR_DATA", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_BLOB, state_len, state_align, &state_offset); for (i = 0; i < num_ids; i++) { @@ -1989,7 +1989,7 @@ gen6_emit_SF_VIEWPORT(const struct ilo_dev_info *dev, */ assert(num_viewports && num_viewports <= 16); - dw = ilo_cp_steal_ptr(cp, "SF_VIEWPORT", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_SF_VIEWPORT, state_len, state_align, &state_offset); for (i = 0; i < num_viewports; i++) { @@ -2031,7 +2031,7 @@ gen6_emit_CLIP_VIEWPORT(const struct ilo_dev_info *dev, */ assert(num_viewports && num_viewports <= 16); - dw = ilo_cp_steal_ptr(cp, "CLIP_VIEWPORT", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_CLIP_VIEWPORT, state_len, state_align, &state_offset); for (i = 0; i < num_viewports; i++) { @@ -2068,7 +2068,7 @@ gen6_emit_CC_VIEWPORT(const struct ilo_dev_info *dev, */ assert(num_viewports && num_viewports <= 16); - dw = ilo_cp_steal_ptr(cp, "CC_VIEWPORT", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_CC_VIEWPORT, state_len, state_align, &state_offset); for (i = 0; i < num_viewports; i++) { @@ -2096,7 +2096,7 @@ gen6_emit_COLOR_CALC_STATE(const struct ilo_dev_info *dev, ILO_GPE_VALID_GEN(dev, 6, 7.5); - dw = ilo_cp_steal_ptr(cp, "COLOR_CALC_STATE", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_COLOR_CALC, state_len, state_align, &state_offset); dw[0] = stencil_ref->ref_value[0] << 24 | @@ -2142,7 +2142,7 @@ gen6_emit_BLEND_STATE(const struct ilo_dev_info *dev, state_len = 2 * num_targets; - dw = ilo_cp_steal_ptr(cp, "BLEND_STATE", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_BLEND, state_len, state_align, &state_offset); for (i = 0; i < num_targets; i++) { @@ -2249,7 +2249,7 @@ gen6_emit_DEPTH_STENCIL_STATE(const struct ilo_dev_info *dev, ILO_GPE_VALID_GEN(dev, 6, 7.5); - dw = ilo_cp_steal_ptr(cp, "DEPTH_STENCIL_STATE", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_DEPTH_STENCIL, state_len, state_align, &state_offset); dw[0] = dsa->payload[0]; @@ -2279,7 +2279,7 @@ gen6_emit_SCISSOR_RECT(const struct ilo_dev_info *dev, */ assert(num_viewports && num_viewports <= 16); - dw = ilo_cp_steal_ptr(cp, "SCISSOR_RECT", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_SCISSOR_RECT, state_len, state_align, &state_offset); memcpy(dw, scissor->payload, state_len * 4); @@ -2309,7 +2309,7 @@ gen6_emit_BINDING_TABLE_STATE(const struct ilo_dev_info *dev, if (!num_surface_states) return 0; - dw = ilo_cp_steal_ptr(cp, "BINDING_TABLE_STATE", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_BINDING_TABLE, state_len, state_align, &state_offset); memcpy(dw, surface_states, num_surface_states * sizeof(surface_states[0])); @@ -2329,7 +2329,8 @@ gen6_emit_SURFACE_STATE(const struct ilo_dev_info *dev, ILO_GPE_VALID_GEN(dev, 6, 7.5); - ilo_cp_steal(cp, "SURFACE_STATE", state_len, state_align, &state_offset); + ilo_cp_steal(cp, ILO_BUILDER_ITEM_SURFACE, + state_len, state_align, &state_offset); STATIC_ASSERT(Elements(surf->payload) >= 8); @@ -2418,7 +2419,7 @@ gen6_emit_SAMPLER_STATE(const struct ilo_dev_info *dev, if (!num_samplers) return 0; - dw = ilo_cp_steal_ptr(cp, "SAMPLER_STATE", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_SAMPLER, state_len, state_align, &state_offset); for (i = 0; i < num_samplers; i++) { @@ -2514,7 +2515,7 @@ gen6_emit_SAMPLER_BORDER_COLOR_STATE(const struct ilo_dev_info *dev, ILO_GPE_VALID_GEN(dev, 6, 7.5); - dw = ilo_cp_steal_ptr(cp, "SAMPLER_BORDER_COLOR_STATE", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_BLOB, state_len, state_align, &state_offset); /* see ilo_gpe_init_sampler_cso() */ @@ -2539,7 +2540,7 @@ gen6_emit_push_constant_buffer(const struct ilo_dev_info *dev, ILO_GPE_VALID_GEN(dev, 6, 7.5); - buf = ilo_cp_steal_ptr(cp, "PUSH_CONSTANT_BUFFER", + buf = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_BLOB, state_len, state_align, &state_offset); /* zero out the unused range */ diff --git a/src/gallium/drivers/ilo/ilo_gpe_gen7.h b/src/gallium/drivers/ilo/ilo_gpe_gen7.h index 0fab6e3474d..f3059ae9fd9 100644 --- a/src/gallium/drivers/ilo/ilo_gpe_gen7.h +++ b/src/gallium/drivers/ilo/ilo_gpe_gen7.h @@ -1158,7 +1158,7 @@ gen7_emit_SF_CLIP_VIEWPORT(const struct ilo_dev_info *dev, */ assert(num_viewports && num_viewports <= 16); - dw = ilo_cp_steal_ptr(cp, "SF_CLIP_VIEWPORT", + dw = ilo_cp_steal_ptr(cp, ILO_BUILDER_ITEM_SF_VIEWPORT, state_len, state_align, &state_offset); for (i = 0; i < num_viewports; i++) { diff --git a/src/gallium/drivers/ilo/ilo_query.c b/src/gallium/drivers/ilo/ilo_query.c index 72fc1c70a70..c789397d12c 100644 --- a/src/gallium/drivers/ilo/ilo_query.c +++ b/src/gallium/drivers/ilo/ilo_query.c @@ -185,7 +185,7 @@ ilo_get_query_result(struct pipe_context *pipe, struct pipe_query *query, return false; if (q->bo) { - if (intel_bo_has_reloc(ilo->cp->bo, q->bo)) + if (ilo_builder_has_reloc(&ilo->cp->builder, q->bo)) ilo_cp_flush(ilo->cp, "syncing for queries"); if (!wait && intel_bo_is_busy(q->bo)) diff --git a/src/gallium/drivers/ilo/ilo_transfer.c b/src/gallium/drivers/ilo/ilo_transfer.c index de6f4324b9a..50eda3da56a 100644 --- a/src/gallium/drivers/ilo/ilo_transfer.c +++ b/src/gallium/drivers/ilo/ilo_transfer.c @@ -1045,7 +1045,7 @@ copy_staging_resource(struct ilo_context *ilo, static bool is_bo_busy(struct ilo_context *ilo, struct intel_bo *bo, bool *need_flush) { - const bool referenced = intel_bo_has_reloc(ilo->cp->bo, bo); + const bool referenced = ilo_builder_has_reloc(&ilo->cp->builder, bo); if (need_flush) *need_flush = referenced; |