diff --git a/src/imagination/g5p/g5p_mrt_programs.h b/src/imagination/g5p/g5p_mrt_programs.h index 79ebeae50b0..c328dfd0c28 100644 --- a/src/imagination/g5p/g5p_mrt_programs.h +++ b/src/imagination/g5p/g5p_mrt_programs.h @@ -225,6 +225,28 @@ static inline unsigned g5p_mrt_load_usc_g4p(uint8_t *out) return sizeof(usc); } +/* The A8's LOAD background for one R8 target (AGXMetalA8, a8-passcap r8_load: an R8Unorm target with loadAction + * Load, USC heap 0x1fc0; the same bytes are in the r8 pass's heap at 0x2140): BGRA8's program up to the wait after the + * sample (its first 116 bytes), then, as R8's clear and fragment programs, a zero into half 1 + * (0188 0101 0101 0120 0128 0039) and the one-word emitpix 111c 0900 8200 and END. 136 bytes. The texture state, the + * sampler, the matrix and their three DOUTDs (10000004 10008004 90010006) are BGRA8's; only the state's format + * differs. */ +#define G5P_A8_LOAD_R8_USC_BYTES 136 +static inline unsigned g5p_mrt_load_usc_g4p_r8(uint8_t *out) +{ + static const uint8_t zero_g[12] = {0x88, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x01, 0x28, 0x01, 0x39, 0x00}; + uint8_t bgra[G5P_A8_LOAD_USC_BYTES]; + g5p_mrt_load_usc_g4p(bgra); + unsigned o = G5P_A8_LOAD_USC_BYTES - 8; /* up to and with the wait (4d 00); BGRA8's two-word emitpix and END after */ + memcpy(out, bgra, o); + memcpy(out + o, zero_g, sizeof(zero_g)); + o += sizeof(zero_g); + const unsigned len = g5p_usc_emit(out + o, 1, 0); + if (!len) + return 0; + return o + len + g5p_usc_special(out + o + len, true); +} + static inline unsigned g5p_mrt_clear_usc(uint8_t *out, unsigned n) { if (n > 4) diff --git a/src/imagination/g5p/g5p_usc.c b/src/imagination/g5p/g5p_usc.c index a0db8b64121..c5f23f941bb 100644 --- a/src/imagination/g5p/g5p_usc.c +++ b/src/imagination/g5p/g5p_usc.c @@ -16,6 +16,11 @@ int g5p_usc_g4p_texfetch_level; bool g5p_usc_g4p_vtex; bool g5p_usc_g4p_vtex_apple; bool g5p_usc_g4p_tbo; +bool g5p_usc_g4p_fge_swap; +bool g5p_usc_g4p_pos_iter; +bool g5p_usc_g4p_r8_load; +bool g5p_usc_g4p_cube_alu; +bool g5p_usc_g4p_cube_slots; const char *const g5p_binop_name[G5P_BIN_COUNT] = {"fadd", "fmul", "iadd", "imul", "and", "or", "xor", "ishr", "isub"}; @@ -1147,8 +1152,11 @@ static unsigned sample_g4p(uint8_t *out, const struct g5p_tex *t) "A8 sample captured only as a 2D or cube sample with an implicit LOD"); /* the cube sample: mode 4 (byte 6 0xc8 with the sampler at dword 4), the direction in three temps from the * coordinate dword, no cube-coordinate instruction (AGXMetalA8's f_tex_cube, passcap USC 0x6076: two FMAs and a - * move build r0..r2, then 1a 59 00 41 00 01 c8 01 00 01 00 80). Only the narrow form is captured. */ - CHECK(t->dim != G5P_TEX_CUBE || t->narrow, "A8 cube sample captured only in the narrow form (result straight to the output)"); + * move build r0..r2, then 1a 59 00 41 00 01 c8 01 00 01 00 80). The 32-bit form is byte 1 0x79, as for 2D + * (f_tex_cube_mul, an iOS capture: 1a 79 00 41 00 01 c8 01 00 01 00 80, then 4d 00 and the multiply); with + * PVR_A8_CUBE_ALU=0 only the narrow form is taken. */ + CHECK(t->dim != G5P_TEX_CUBE || t->narrow || g5p_usc_g4p_cube_alu, + "A8 cube sample: the 32-bit form is off (PVR_A8_CUBE_ALU=0)"); /* the explicit level in the register after the coordinate (Apple's sample at a varying level, iOS capture, USC * heap 0x1_02328000 + 0x8814: the iterated coordinate in r0..r1, r2 = r0 * 4.0, then * 1a 59 00 41 00 01 a8 09 00 01 00 80): byte 6 mode 2, byte 7 0x09, byte 10 0. 2D only. */ @@ -1166,7 +1174,18 @@ static unsigned sample_g4p(uint8_t *out, const struct g5p_tex *t) * test passed with it. */ if (t->a8_slots) { const unsigned image_dword = t->image_qword, sampler_dword = t->sampler_qword; /* dwords (g5p_tex) */ - CHECK(t->dim == G5P_TEX_2D, "A8 multi-image sample: 2D only (Apple's form is captured for 2D)"); + /* The cube sample in this form (a8-passcap tex2d_cube_mul, iOS 12.4: a 2D image at common dword 0, the cube's + * at 4, one shared sampler at 8): 1a b9 00 41 00 01 88 01 00 01 00 80 for the 2D sample, 4d 04, then + * 1a b9 0a 41 08 01 c8 01 08 01 00 80 and 4d 00. The cube's image and sampler fields are the 2D sample's + * (byte 4 = image dword * 2, slot 2 in byte 1 bits 7:6) and byte 6 carries mode 4 over 0x88, as the + * single-image form does over 0x80. With a sampler per texture (tex2d_cube_mul2s, samplers at 8 and 12) the + * cube's names its own, slot 3: 1a f9 0a 41 08 01 c8 01 08 01 00 80. Only the 32-bit result is captured in + * this form. */ + CHECK(t->dim == G5P_TEX_2D || (t->dim == G5P_TEX_CUBE && g5p_usc_g4p_cube_slots), + "A8 multi-image sample: 2D or (PVR_A8_CUBE_SLOTS) cube only"); + CHECK(t->dim != G5P_TEX_CUBE || (!t->narrow && !t->lod_reg && !t->read_flag && !t->vtx), + "A8 multi-image cube sample: captured only with a 32-bit result and an implicit level"); + const uint8_t mode = t->dim == G5P_TEX_CUBE ? 4 << 4 : lod_mode; CHECK(!(image_dword % 4) && image_dword <= 124, "A8 multi-image sample: image dword a multiple of 4 below 128"); CHECK(!(sampler_dword % 4) && sampler_dword / 4 <= 11, "A8 multi-image sample: sampler slot 0..11"); CHECK(t->coord_dword <= 31 && !(t->dst_half & 1) && t->dst_half < 64, "A8 sample: coordinate/destination range"); @@ -1183,7 +1202,7 @@ static unsigned sample_g4p(uint8_t *out, const struct g5p_tex *t) } const uint8_t raw[12] = {0x1a, (uint8_t)((slot & 3) << 6 | (t->narrow ? 0x19 : 0x39)), (uint8_t)t->dst_half, 0x41, (uint8_t)(2 * image_dword), (uint8_t)(1 | (slot >> 2) << 1), - (uint8_t)(0x88 | lod_mode | (t->read_flag ? 4 : 0)), lod_byte7, + (uint8_t)(0x88 | mode | (t->read_flag ? 4 : 0)), lod_byte7, (uint8_t)(t->coord_dword << 1), 0x01, 0x00, 0x80}; return finish_g4p(out, raw, sizeof(raw)); } @@ -1975,6 +1994,17 @@ unsigned g5p_usc_position_zw(uint8_t *out, unsigned dst_half, bool set1, bool bo bool minimum = dst_half || set1 || both; bool wide = long_form < 0 ? minimum : long_form; CHECK(!(minimum && !wide), "short position iterator omits nonzero fields"); + if (g5p_usc_g4p && g5p_usc_g4p_pos_iter) { + /* The A8: Apple's A8 compiler reads the position's W and Z with its varying iterator `18 ..`, screen-linear + * (byte 3 without 0x80), one f32 component. Set 0 is `18 09 DD 00` with no slot byte, as Apple reads W next + * to a perspective varying. Set 1 (Z after W) is inferred: the slot byte set << 2 after byte 3 = 0x01, the + * f32 screen-linear shape of Apple's varying reads at other sets (Apple's own set-1 position read is the f16 + * pair `18 11 02 01 00 01 04 00`). The coefficient side (DOUTI items, TA_OUTPUT_SEL with unclamped Z) is the + * A9's, the same words as Apple's A8 output. */ + CHECK(!both, "A8 position iterator: both sets in one read not captured in f32"); + const uint8_t g4[6] = {0x18, 0x09, (uint8_t)dst_half, set1 ? 0x01 : 0x00, 0x04, 0x00}; + return finish_g4p(out, g4, set1 ? 6 : 4); + } uint8_t raw[4] = {8, (both ? 0x10 : 8) | wide, dst_half, set1 ? 2 : 0}; return finish(out, raw, wide ? 4 : 2); } diff --git a/src/imagination/g5p/g5p_usc.h b/src/imagination/g5p/g5p_usc.h index 9ee631fa754..8ffedf5cb1d 100644 --- a/src/imagination/g5p/g5p_usc.h +++ b/src/imagination/g5p/g5p_usc.h @@ -71,6 +71,23 @@ extern bool g5p_usc_g4p_vtex_apple; /* A fragment texel-buffer read on the A8 (st/mesa's pixel-buffer uploads) as a 2D texelFetch of the buffer's linear * state (PVR_A8_TBO, on by default; 0 refuses it) */ extern bool g5p_usc_g4p_tbo; +/* The A8's float ge select as the lt compare/write with the selected values swapped, without the ge relation + * extension (`00 10` after `59 61`), which no A8 capture has and which the A8 ignores: a float ge select through it + * runs as lt on the iPod touch 6. PVR_A8_FGE_SWAP, on by default; 0 gives the extension form. */ +extern bool g5p_usc_g4p_fge_swap; +/* The A8's gl_FragCoord.z/.w read in Apple's form: the varying iterator `18 09 ..` without perspective on the W/Z + * coefficient sets (g5p_usc_position_zw()), in place of the A9's position iterator `08 09 ..`, which no A8 capture + * has and which reads 0 on the iPod touch 6. PVR_A8_POS_ITER, on by default; 0 gives the A9 form. */ +extern bool g5p_usc_g4p_pos_iter; +/* An R8 colour target with loadOp LOAD on the A8, in Apple's form (g5p_mrt_load_usc_g4p_r8(); PVR_A8_R8_LOAD, on by + * default; 0 refuses it, as before) */ +extern bool g5p_usc_g4p_r8_load; +/* The A8's cube sample with 32-bit results that ALU reads after the wait, Apple's + * 1a 79 00 41 00 01 c8 01 CC 01 00 80 (sample_g4p(); PVR_A8_CUBE_ALU, on by default; 0 refuses it, as before) */ +extern bool g5p_usc_g4p_cube_alu; +/* That cube sample in Apple's multi-image layout (sample_g4p() with g5p_tex.a8_slots): images in four-dword slots, then + * one shared sampler or a sampler per texture after them (PVR_A8_CUBE_SLOTS, on by default; 0 refuses it, as before) */ +extern bool g5p_usc_g4p_cube_slots; enum g5p_binop { G5P_BIN_FADD, G5P_BIN_FMUL, G5P_BIN_IADD, G5P_BIN_IMUL, diff --git a/src/imagination/g5p/pco_g5p_general.c b/src/imagination/g5p/pco_g5p_general.c index 2678837f621..0240f5564f7 100644 --- a/src/imagination/g5p/pco_g5p_general.c +++ b/src/imagination/g5p/pco_g5p_general.c @@ -192,6 +192,9 @@ struct gctx { unsigned tex_batch; bool a8_slots; /* the A8's multi-image layout (plan_common) */ unsigned tex_batch_image; /* a8_slots: the common dword of the batch's last sampled image */ + bool a8_cube; /* the A8 program samples a cube (a8_cube_tex()) */ + bool a8_one_sampler; /* a8_slots: one sampler slot after the images, every sample's */ + bool a8_sampler_each; /* a8_slots: texture j's own sampler in slot N + j after the N images */ nir_shader *nir; nir_function_impl *impl; bool vs, half_output; @@ -2262,6 +2265,7 @@ static void plan_common(struct gctx *c) } else { tex_for(c, t); record_lod_sampler(c, t); + c->a8_cube |= a8_cube_tex(t); } continue; } @@ -2445,8 +2449,22 @@ static void plan_common(struct gctx *c) * and the A9 form. */ const unsigned slot_base = next ? align(next, 4) : 0, base_slot = slot_base / 4; const bool a8_multi = g5p_usc_g4p && !c->vs && !qualified && c->ntex && (next || c->ntex >= 2); - const bool a8_each = base_slot + 2 * c->ntex - 1 <= 11, a8_shared = base_slot + c->ntex <= 11; + /* A program that samples a cube and names one sampler for every image (a separate sampler, not combined) takes + * Apple's shared form: the images, then that sampler in the slot after them, as a8-passcap tex2d_cube_mul + * (iOS 12.4: a 2D image to common 0..3 and the cube's to 4..7 in one eight-dword DOUTD, the sampler to 8..11, + * both samples naming slot 2). With a sampler per texture the cube takes the per-texture form below, as + * tex2d_cube_mul2s (the images to 0..7, the two samplers to 8..15 in one eight-dword DOUTD, the cube naming + * slot 3). 2D-only programs keep their flown layout. */ + bool one_sampler = c->a8_cube && g5p_usc_g4p_cube_slots; + for (unsigned i = 0; one_sampler && i < c->ntex; i++) + one_sampler = !c->tex[i].fetch && c->tex[i].needs_sampler && c->tex[i].sset == c->tex[0].sset && + c->tex[i].sbinding == c->tex[0].sbinding && c->tex[i].selement == c->tex[0].selement; + const bool a8_shared = base_slot + c->ntex <= 11; + const bool a8_each = !(one_sampler && a8_shared) && base_slot + 2 * c->ntex - 1 <= 11; c->a8_slots = a8_multi && (a8_each || a8_shared); + /* one image, or the shared form chosen above; not the shared fallback of seven images with distinct samplers */ + c->a8_one_sampler = c->a8_slots && (c->ntex == 1 || (one_sampler && !a8_each)); + c->a8_sampler_each = c->a8_slots && a8_each; c->fetch_sampler_common = sampler_base + sdw * sampler_count; for (unsigned i = 0; c->a8_slots && i < c->ntex; i++) { struct tex_bind *t = &c->tex[i]; @@ -3044,7 +3062,9 @@ struct gsrc4 { unsigned a, b, t, f; }; * false value first. */ static bool cmp_swaps(nir_op op) { - return op == nir_op_fneu || op == nir_op_ige || op == nir_op_ine || op == nir_op_uge; + /* the A8's float ge is the lt compare with the values swapped, as the integer ge (PVR_A8_FGE_SWAP) */ + return op == nir_op_fneu || op == nir_op_ige || op == nir_op_ine || op == nir_op_uge || + (op == nir_op_fge && g5p_usc_g4p_fge_swap); } static void cmp_select_regs(struct gctx *c, nir_op op, unsigned a, unsigned b, unsigned t, unsigned f, unsigned dst, @@ -3064,8 +3084,12 @@ static void cmp_select_regs(struct gctx *c, nir_op op, unsigned a, unsigned b, u case nir_op_ult: code = G5P_ULT; break; default: code = G5P_ULT; ge = true; break; /* uge */ } - unsigned rc = fl && ge ? 0x10 : 0; - bool swap = fl ? ne : (ge || ne); + /* The ge relation extension (`.. 59 61 00 10`) has no A8 capture, and the A8 ignores it: a float ge select + * through it gives lt's value. On the A8 the lt compare with the values swapped (PVR_A8_FGE_SWAP); an unordered + * compare then selects the true value, where ge selects the false one. */ + const bool ge_swap = fl && ge && g5p_usc_g4p_fge_swap; + unsigned rc = fl && ge && !ge_swap ? 0x10 : 0; + bool swap = fl ? (ne || ge_swap) : (ge || ne); if (swap) { unsigned tmp = t; t = f; @@ -5489,15 +5513,32 @@ static void emit_tex_ms_own_sample(struct gctx *c, nir_tex_instr *t, struct tex_ } /* The A8's cube sample, as AGXMetalA8's f_tex_cube: the direction in three consecutive temps (computed: FMAs and a - * move, no cube-coordinate instruction; the hardware selects the face), then the narrow sample in mode 4 */ + * move, no cube-coordinate instruction; the hardware selects the face), then the sample in mode 4: narrow when the + * result goes straight to the output, else (PVR_A8_CUBE_ALU) Apple's 32-bit form, as f_tex_cube_mul (a8-passcap + * tex_cube_mul, USC heap 0x1bf6): 1a 79 00 41 00 01 c8 01 00 01 00 80, the wait 4d 00, then the ALU that reads the + * four 32-bit results. In Apple's multi-image layout (PVR_A8_CUBE_SLOTS), as f_tex2d_cube_mul: the 2D sample, 4d 04, + * 1a b9 0a 41 08 01 c8 01 08 01 00 80 (the cube's image at dword 4, the shared sampler in slot 2), 4d 00; with a + * sampler per texture, as f_tex2d_cube_mul2s: the same with the cube's own sampler in slot 3, + * 1a f9 0a 41 08 01 c8 01 08 01 00 80. */ static void emit_tex_cube_g4p(struct gctx *c, nir_tex_instr *t) { uint8_t raw[G5P_USC_MAX]; struct tex_bind *b = tex_for(c, t); const bool narrow = c->narrow_tex == t; - if (!narrow) - refuse(c, "A8 cube sample whose result feeds arithmetic (only the narrow form, straight to the output, is " - "captured)"); + if (!narrow && !g5p_usc_g4p_cube_alu) + refuse(c, "A8 cube sample whose result feeds arithmetic (PVR_A8_CUBE_ALU=0)"); + /* In Apple's multi-image layout (other images, or other common data first) the cube sample is captured with a + * 32-bit result, the image in its four-dword slot and the samplers after the images: one shared by every image + * (a8-passcap tex2d_cube_mul, slot N) or one per texture (tex2d_cube_mul2s, texture j's in slot N + j; what GL + * through Zink's combined samplers gives). A narrow result is not captured in this layout, and the planner's + * shared fallback (texture 0's sampler for images that name distinct samplers) would sample with the wrong one. */ + if (c->a8_slots && (!g5p_usc_g4p_cube_slots || narrow || !(c->a8_one_sampler || c->a8_sampler_each))) + refuse(c, "A8 cube sample in Apple's multi-image layout (image at common dword %u, sampler at %u, %u images, " + "%s; %s result): captured only with a 32-bit result and one shared sampler or a sampler per texture%s", + b->image, b->sampler, c->ntex, + c->a8_one_sampler ? "one shared sampler" : c->a8_sampler_each ? "a sampler per texture" + : "texture 0's sampler for distinct samplers", + narrow ? "narrow" : "32-bit", g5p_usc_g4p_cube_slots ? "" : " (PVR_A8_CUBE_SLOTS=0)"); nir_def *cd = nir_get_tex_src(t, nir_tex_src_coord); struct ref r[3]; unsigned reg[3]; @@ -5517,12 +5558,28 @@ static void emit_tex_cube_g4p(struct gctx *c, nir_tex_instr *t) c->scratch |= BITFIELD64_RANGE(coord, 3); } struct g5p_tex s = {.image_qword = c->a8_slots ? b->image : b->image / 2, .a8_slots = c->a8_slots, .sampler_qword = b->sampler, .coord_dword = coord, - .coord_control = true, .dim = G5P_TEX_CUBE, .narrow = true}; + .coord_control = true, .dim = G5P_TEX_CUBE, .narrow = narrow}; + unsigned dst = 0; + if (!narrow) + dst = alloc_run(c, 4, "cube sample result"); + s.dst_half = 2 * dst; + a8_image_order(c, b->image); /* Apple's 4d 04 after the 2D sample, before the cube's */ put(c, raw, g5p_usc_sample(raw, &s), "cube sample"); c->tex_coord_pending |= BITFIELD64_RANGE(coord, 3); c->tex_batch++; + c->tex_batch_image = b->image; + if (!narrow) { + /* Apple waits right after the sample, before the ALU that reads it */ + c->tex_pending |= BITFIELD64_RANGE(dst, 4); + for (unsigned k = 0; k < 4; k++) { + struct val *v = V(c, &t->def, k); + v->state = VAL_REG; + v->reg = dst + k; + v->held = true; + } + } tex_flush(c); - c->p->evidence |= PCO_G5P_EV_TEX_CAPTURE; + c->p->evidence |= narrow ? PCO_G5P_EV_TEX_CAPTURE : PCO_G5P_EV_TEX_F32; } /* The A8's vertex-stage sample in Apple's form (PVR_A8_VTEX_APPLE), as AGXMetalA8 compiles v_sample, v_read_f32 and diff --git a/src/imagination/vulkan/pvr_arch_g5p.c b/src/imagination/vulkan/pvr_arch_g5p.c index 654f5f2b2ec..020a75ff1b2 100644 --- a/src/imagination/vulkan/pvr_arch_g5p.c +++ b/src/imagination/vulkan/pvr_arch_g5p.c @@ -238,6 +238,8 @@ g5p_free_programs(struct pvr_device *device, struct pvr_g5p_programs *p) pvr_bo_suballoc_free(p->a8_load_usc); pvr_bo_suballoc_free(p->a8_load_kick.pvr_bo); pvr_bo_suballoc_free(p->a8_load_dma.pvr_bo); + pvr_bo_suballoc_free(p->a8_load_r8_usc); + pvr_bo_suballoc_free(p->a8_load_r8_kick.pvr_bo); for (unsigned i = 0; i < ARRAY_SIZE(p->raw_load); i++) { if (p->raw_load[i]) { g5p_free_programs(device, p->raw_load[i]); @@ -722,11 +724,12 @@ g5p_load_background(struct pvr_cmd_buffer *cmd_buffer, const uint64_t state[][4] * three DOUTDs of 4 + 4 + 6 dwords into common dwords 0, 4 and 8, the target's texture state (its first two qwords), * Apple's load sampler (00000fff 02022400 0 0: the passcap's words) and the 2x3 matrix from the fragment position to the * sample coordinate (identity: 1, 0, 0, 1, 0, 0). Data controls 10000004, 10008004, 90010006; uniform size 3 units, - * common-store size 14 dwords, as Apple's record has them. + * common-store size 14 dwords, as Apple's record has them. An R8 target (a8-passcap r8_load) has the same uploads, + * controls and sampler, with Apple's R8 program behind the kick. */ static VkResult g5p_load_background_g4p(struct pvr_cmd_buffer *cmd_buffer, const uint64_t state[4], uint64_t bgnd[4], - const struct pvr_g5p_programs *p) + const struct pvr_g5p_programs *p, const struct pvr_pds_upload *kick) { static const uint32_t sampler[4] = { 0x00000fff, 0x02022400, 0, 0 }; static const float matrix[6] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }; @@ -749,7 +752,7 @@ g5p_load_background_g4p(struct pvr_cmd_buffer *cmd_buffer, const uint64_t state[ if (result != VK_SUCCESS) return result; pvr_csb_pack (&bgnd[0], CR_PDS_BGRND0_BASE, b0) { - b0.shader_addr = PVR_DEV_ADDR(p->a8_load_kick.data_offset); + b0.shader_addr = PVR_DEV_ADDR(kick->data_offset); b0.texunicode_addr = PVR_DEV_ADDR(p->a8_load_dma.code_offset); } pvr_csb_pack (&bgnd[2], CR_PDS_BGRND2_BASE, b2) { @@ -1246,12 +1249,37 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd /* a linear target loads through its stride texture state (above): Apple's load program samples whatever the * state describes. Without it, a compositor's damage-only redraw into its (linear, shared) output buffer was * refused and the frame never drawn. */ - if (nt != 1 || raw || compact || g->samples != 1 || g->a8_narrow_halves || - (f != VK_FORMAT_B8G8R8A8_UNORM && f != VK_FORMAT_R8G8B8A8_UNORM)) + /* one twiddled R8 target: Apple's R8 load program (a8-passcap r8_load), the same three uploads. A linear R8 + * target and RG8 are not captured. */ + const bool r8 = f == VK_FORMAT_R8_UNORM && g->a8_narrow_halves == 1 && a8_load_twiddled && g5p_usc_g4p_r8_load; + if (nt != 1 || raw || compact || g->samples != 1 || (g->a8_narrow_halves && !r8) || + (f != VK_FORMAT_B8G8R8A8_UNORM && f != VK_FORMAT_R8G8B8A8_UNORM && !r8)) return G5P_REFUSE(cmd_buffer, "A8 LOAD of %s (%u targets, %u samples%s): one single-sample " - "BGRA8/RGBA8 target is captured", vk_Format_to_str(f), nt, g->samples, - a8_load_twiddled ? "" : ", linear"); - result = g5p_load_background_g4p(cmd_buffer, load_state[0], bgnd, p); + "BGRA8/RGBA8 target or one twiddled R8 target is captured%s", vk_Format_to_str(f), nt, + g->samples, a8_load_twiddled ? "" : ", linear", + f == VK_FORMAT_R8_UNORM && !g5p_usc_g4p_r8_load ? " (PVR_A8_R8_LOAD=0)" : ""); + if (r8) { + struct pvr_g5p_programs *programs = &device->g5p->programs; + VkResult lr = VK_SUCCESS; + simple_mtx_lock(&device->g5p->clear_lock); + if (!programs->a8_load_r8_usc) { + uint8_t code[G5P_A8_LOAD_R8_USC_BYTES + 8]; + const unsigned size = g5p_mrt_load_usc_g4p_r8(code); + lr = !size ? vk_errorf(device, VK_ERROR_UNKNOWN, "G5P: A8 R8 load: %s", g5p_usc_error) + : pvr_gpu_upload_usc(device, code, size, 64, &programs->a8_load_r8_usc); + if (lr == VK_SUCCESS) + lr = g5p_upload_kick(device, programs->a8_load_r8_usc, 1, &programs->a8_load_r8_kick); + if (lr != VK_SUCCESS) { + pvr_bo_suballoc_free(programs->a8_load_r8_usc); + programs->a8_load_r8_usc = NULL; + } + } + simple_mtx_unlock(&device->g5p->clear_lock); + if (lr != VK_SUCCESS) + return lr; + } + result = g5p_load_background_g4p(cmd_buffer, load_state[0], bgnd, p, + r8 ? &p->a8_load_r8_kick : &p->a8_load_kick); if (result != VK_SUCCESS) return result; } else if (load) { diff --git a/src/imagination/vulkan/pvr_g5p.h b/src/imagination/vulkan/pvr_g5p.h index 5a58ce35576..1759d23ffad 100644 --- a/src/imagination/vulkan/pvr_g5p.h +++ b/src/imagination/vulkan/pvr_g5p.h @@ -188,6 +188,9 @@ struct pvr_g5p_programs { /* the A8's colour LOAD background (g5p_mrt_load_usc_g4p()): its USC, kick and the three-DOUTD loader */ struct pvr_suballoc_bo *a8_load_usc; struct pvr_pds_upload a8_load_kick, a8_load_dma; + /* its one-target R8 form (g5p_mrt_load_usc_g4p_r8(), lazy: the device's other allocations keep their order) */ + struct pvr_suballoc_bo *a8_load_r8_usc; + struct pvr_pds_upload a8_load_r8_kick; /* raw clear programs by total output words: 2, 4, 8 (two 32-bit integer targets) */ struct pvr_suballoc_bo *raw_clear_usc[4]; /*2/4/8 words, then scalar1 */ /* raw end-of-tile programs by target count: 1, 2 */ diff --git a/src/imagination/vulkan/pvr_physical_device.c b/src/imagination/vulkan/pvr_physical_device.c index c31d049dc33..6122f45d092 100644 --- a/src/imagination/vulkan/pvr_physical_device.c +++ b/src/imagination/vulkan/pvr_physical_device.c @@ -1423,6 +1423,15 @@ VkResult pvr_physical_device_init(struct pvr_physical_device *pdevice, g5p_usc_g4p_vtex = debug_get_bool_option("PVR_A8_VTEX", false) || g5p_usc_g4p_vtex_apple; /* fragment texel-buffer reads (g5p_usc.h) */ g5p_usc_g4p_tbo = debug_get_bool_option("PVR_A8_TBO", true); + /* float ge selects without the ge relation extension (g5p_usc.h) */ + g5p_usc_g4p_fge_swap = debug_get_bool_option("PVR_A8_FGE_SWAP", true); + /* gl_FragCoord.z/w by the A8's varying iterator (g5p_usc.h) */ + g5p_usc_g4p_pos_iter = debug_get_bool_option("PVR_A8_POS_ITER", true); + /* an R8 target's LOAD and a cube sample read by ALU, both in Apple's form from an iOS capture (g5p_usc.h) */ + g5p_usc_g4p_r8_load = debug_get_bool_option("PVR_A8_R8_LOAD", true); + g5p_usc_g4p_cube_alu = debug_get_bool_option("PVR_A8_CUBE_ALU", true); + /* and that cube sample with 2D samples, one shared sampler or one each (Apple's multi-image layout, iOS captures) */ + g5p_usc_g4p_cube_slots = g5p_usc_g4p_cube_alu && debug_get_bool_option("PVR_A8_CUBE_SLOTS", true); } /* The A8 skips refused work by default: a refused program or pass loses its draws (named on stderr) instead of