diff --git a/src/compiler/nir/nir_lower_clip.c b/src/compiler/nir/nir_lower_clip.c index 3d60e099356d61dab0fe09bc8ed1252726d87490..6cef3e1cb9ca2dc6534a6bf439784fc7223a20ec 100644 --- a/src/compiler/nir/nir_lower_clip.c +++ b/src/compiler/nir/nir_lower_clip.c @@ -102,7 +102,8 @@ store_clipdist_output(nir_builder *b, nir_variable *out, nir_ssa_def **val) nir_store_output(b, nir_vec4(b, val[0], val[1], val[2], val[3]), nir_imm_int(b, 0), .base = out->data.driver_location, .write_mask = 0xf, - .io_semantics = semantics); + .io_semantics = semantics, + .src_type = nir_type_float32); } static void @@ -117,7 +118,8 @@ load_clipdist_input(nir_builder *b, nir_variable *in, int location_offset, nir_ssa_def *load = nir_load_input(b, 4, 32, nir_imm_int(b, 0), .base = in->data.driver_location + location_offset, - .io_semantics = semantics); + .io_semantics = semantics, + .dest_type = nir_type_float32); val[0] = nir_channel(b, load, 0); val[1] = nir_channel(b, load, 1); diff --git a/src/gallium/drivers/lima/ir/gp/gpir.h b/src/gallium/drivers/lima/ir/gp/gpir.h index 26cbb099a94489eb4432279c658297375f0aaabc..7d413b620e58ae78df8dcc2625ff6d04dd777fae 100644 --- a/src/gallium/drivers/lima/ir/gp/gpir.h +++ b/src/gallium/drivers/lima/ir/gp/gpir.h @@ -388,7 +388,15 @@ struct lima_vs_shader_state; #define GPIR_VECTOR_SSA_VIEWPORT_SCALE 0 #define GPIR_VECTOR_SSA_VIEWPORT_OFFSET 1 -#define GPIR_VECTOR_SSA_NUM 2 +#define GPIR_VECTOR_SSA_CLIP_PLANE0 2 +#define GPIR_VECTOR_SSA_CLIP_PLANE1 3 +#define GPIR_VECTOR_SSA_CLIP_PLANE2 4 +#define GPIR_VECTOR_SSA_CLIP_PLANE3 5 +#define GPIR_VECTOR_SSA_CLIP_PLANE4 6 +#define GPIR_VECTOR_SSA_CLIP_PLANE5 7 +#define GPIR_VECTOR_SSA_CLIP_PLANE6 8 +#define GPIR_VECTOR_SSA_CLIP_PLANE7 9 +#define GPIR_VECTOR_SSA_NUM 10 typedef struct gpir_compiler { struct list_head block_list; diff --git a/src/gallium/drivers/lima/ir/gp/nir.c b/src/gallium/drivers/lima/ir/gp/nir.c index afb43e51435111a7c3c2352c7aa269c8ba49d9f5..feacf8805619efe7af17165db866cc1f7c4bd518 100644 --- a/src/gallium/drivers/lima/ir/gp/nir.c +++ b/src/gallium/drivers/lima/ir/gp/nir.c @@ -274,6 +274,8 @@ static bool gpir_emit_intrinsic(gpir_block *block, nir_instr *ni) return gpir_create_vector_load(block, &instr->dest, GPIR_VECTOR_SSA_VIEWPORT_SCALE); case nir_intrinsic_load_viewport_offset: return gpir_create_vector_load(block, &instr->dest, GPIR_VECTOR_SSA_VIEWPORT_OFFSET); + case nir_intrinsic_load_user_clip_plane: + return gpir_create_vector_load(block, &instr->dest, GPIR_VECTOR_SSA_CLIP_PLANE0 + nir_intrinsic_ucp_id(instr)); case nir_intrinsic_store_output: { gpir_store_node *store = gpir_node_create(block, gpir_op_store_varying); diff --git a/src/gallium/drivers/lima/lima_context.h b/src/gallium/drivers/lima/lima_context.h index 400fa0e979c3068473aeeaf5ab807618d650394f..f7350628297797b41b74eadd898eec6d734ce833 100644 --- a/src/gallium/drivers/lima/lima_context.h +++ b/src/gallium/drivers/lima/lima_context.h @@ -58,6 +58,7 @@ struct lima_fs_bind_state { struct lima_fs_key { struct lima_fs_bind_state *shader_state; uint8_t swizzles[PIPE_MAX_SAMPLERS][4]; + uint8_t ucp_enables; }; #define LIMA_MAX_VARYING_NUM 13 @@ -93,6 +94,7 @@ struct lima_vs_bind_state { struct lima_vs_key { struct lima_vs_bind_state *shader_state; + uint8_t ucp_enables; }; struct lima_rasterizer_state { diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c index 69ef3e3b1b8e856f68369ade988ba209b7f60e6a..5e47363b9c1ba22e8d897312126e1c02443aee1f 100644 --- a/src/gallium/drivers/lima/lima_draw.c +++ b/src/gallium/drivers/lima/lima_draw.c @@ -281,7 +281,7 @@ lima_pack_vs_cmd(struct lima_context *ctx, const struct pipe_draw_info *info, } int uniform_size = MIN2(vs->uniform_size, ccb->size); - int size = uniform_size + vs->constant_size + 32; + int size = uniform_size + vs->constant_size + 32 + PIPE_MAX_CLIP_PLANES * 16; VS_CMD_UNIFORMS_ADDRESS( lima_ctx_buff_va(ctx, lima_ctx_buff_gp_uniform), align(size, 16)); @@ -845,7 +845,7 @@ lima_update_gp_uniform(struct lima_context *ctx) struct lima_vs_shader_state *vs = ctx->vs; int uniform_size = MIN2(vs->uniform_size, ccb->size); - int size = uniform_size + vs->constant_size + 32; + int size = uniform_size + vs->constant_size + 32 + PIPE_MAX_CLIP_PLANES * 16; void *vs_const_buff = lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_uniform, size); @@ -859,8 +859,13 @@ lima_update_gp_uniform(struct lima_context *ctx) ctx->viewport.transform.translate, sizeof(ctx->viewport.transform.translate)); + for (int i = 0; i < PIPE_MAX_CLIP_PLANES; i++) { + memcpy(vs_const_buff + uniform_size + 32 + i * 16, + ctx->clip.ucp[i], sizeof(ctx->clip.ucp[0])); + } + if (vs->constant) - memcpy(vs_const_buff + uniform_size + 32, + memcpy(vs_const_buff + uniform_size + 32 + PIPE_MAX_CLIP_PLANES * 16, vs->constant, vs->constant_size); struct lima_job *job = lima_job_get(ctx); diff --git a/src/gallium/drivers/lima/lima_program.c b/src/gallium/drivers/lima/lima_program.c index 5a04274a9cf03ec96aa2b88bf28c0180d15fd715..1491a4c9cfcc6032deb650626001a1c5940aa950 100644 --- a/src/gallium/drivers/lima/lima_program.c +++ b/src/gallium/drivers/lima/lima_program.c @@ -97,10 +97,21 @@ type_size(const struct glsl_type *type, bool bindless) } void -lima_program_optimize_vs_nir(struct nir_shader *s) +lima_program_optimize_vs_nir(struct nir_shader *s, uint8_t ucp_enables) { bool progress; + /* ucp must be lowered before nir_lower_viewport_transform, + * it needs to work with the untransformed position. */ + if (ucp_enables) { + NIR_PASS_V(s, nir_lower_io_to_temporaries, nir_shader_get_entrypoint(s), true, true); + NIR_PASS_V(s, nir_lower_clip_vs, ucp_enables, true, false, NULL); + NIR_PASS_V(s, nir_lower_io_to_temporaries, nir_shader_get_entrypoint(s), true, true); + NIR_PASS_V(s, nir_lower_global_vars_to_local); + NIR_PASS_V(s, nir_split_var_copies); + NIR_PASS_V(s, nir_lower_var_copies); + } + NIR_PASS_V(s, nir_lower_viewport_transform); NIR_PASS_V(s, nir_lower_point_size, 1.0f, 100.0f); NIR_PASS_V(s, nir_lower_io, @@ -202,11 +213,15 @@ lima_vec_to_movs_filter_cb(const nir_instr *instr, unsigned writemask, void lima_program_optimize_fs_nir(struct nir_shader *s, - struct nir_lower_tex_options *tex_options) + struct nir_lower_tex_options *tex_options, + uint8_t ucp_enables) { bool progress; NIR_PASS_V(s, nir_lower_fragcoord_wtrans); + if (ucp_enables) + NIR_PASS_V(s, nir_lower_clip_fs, ucp_enables, false); + NIR_PASS_V(s, nir_lower_io, nir_var_shader_in | nir_var_shader_out, type_size, 0); NIR_PASS_V(s, nir_lower_regs_to_ssa); @@ -294,7 +309,7 @@ lima_fs_compile_shader(struct lima_context *ctx, tex_options.swizzle_result |= (1 << i); } - lima_program_optimize_fs_nir(nir, &tex_options); + lima_program_optimize_fs_nir(nir, &tex_options, key->ucp_enables); if (lima_debug & LIMA_DEBUG_PP) nir_print_shader(nir, stdout); @@ -383,7 +398,7 @@ lima_vs_compile_shader(struct lima_context *ctx, { nir_shader *nir = nir_shader_clone(vs, key->shader_state->base.ir.nir); - lima_program_optimize_vs_nir(nir); + lima_program_optimize_vs_nir(nir, key->ucp_enables); if (lima_debug & LIMA_DEBUG_GP) nir_print_shader(nir, stdout); @@ -430,7 +445,9 @@ lima_get_compiled_vs(struct lima_context *ctx, bool lima_update_vs_state(struct lima_context *ctx) { - if (!(ctx->dirty & LIMA_CONTEXT_DIRTY_UNCOMPILED_VS)) { + if (!(ctx->dirty & (LIMA_CONTEXT_DIRTY_UNCOMPILED_VS | + LIMA_CONTEXT_DIRTY_RASTERIZER | + LIMA_CONTEXT_DIRTY_CLIP))) { return true; } @@ -439,6 +456,12 @@ lima_update_vs_state(struct lima_context *ctx) memset(key, 0, sizeof(*key)); key->shader_state = ctx->bind_vs; + /* user clip planes */ + if (ctx->dirty & (LIMA_CONTEXT_DIRTY_RASTERIZER | LIMA_CONTEXT_DIRTY_CLIP) && + ctx->rasterizer) { + key->ucp_enables = ctx->rasterizer->base.clip_plane_enable; + } + struct lima_vs_shader_state *old_vs = ctx->vs; struct lima_vs_shader_state *vs = lima_get_compiled_vs(ctx, key); @@ -500,6 +523,8 @@ bool lima_update_fs_state(struct lima_context *ctx) { if (!(ctx->dirty & (LIMA_CONTEXT_DIRTY_UNCOMPILED_FS | + LIMA_CONTEXT_DIRTY_RASTERIZER | + LIMA_CONTEXT_DIRTY_CLIP | LIMA_CONTEXT_DIRTY_TEXTURES))) { return true; } @@ -510,6 +535,12 @@ lima_update_fs_state(struct lima_context *ctx) memset(key, 0, sizeof(*key)); key->shader_state = ctx->bind_fs; + /* user clip planes */ + if (ctx->dirty & (LIMA_CONTEXT_DIRTY_RASTERIZER | LIMA_CONTEXT_DIRTY_CLIP) && + ctx->rasterizer) { + key->ucp_enables = ctx->rasterizer->base.clip_plane_enable; + } + if (((ctx->dirty & LIMA_CONTEXT_DIRTY_TEXTURES) && lima_tex->num_samplers && lima_tex->num_textures)) { diff --git a/src/gallium/drivers/lima/lima_program.h b/src/gallium/drivers/lima/lima_program.h index 2eb156912f0953b8f76e9d48892f93571d5f07bc..ac9714feadf5ebc6ff5e487602634652af8f9898 100644 --- a/src/gallium/drivers/lima/lima_program.h +++ b/src/gallium/drivers/lima/lima_program.h @@ -33,10 +33,12 @@ bool lima_update_vs_state(struct lima_context *ctx); bool lima_update_fs_state(struct lima_context *ctx); struct nir_shader; -void lima_program_optimize_vs_nir(struct nir_shader *s); +void lima_program_optimize_vs_nir(struct nir_shader *s, + uint8_t ucp_enables); struct nir_lower_tex_options; void lima_program_optimize_fs_nir(struct nir_shader *s, - struct nir_lower_tex_options *tex_options); + struct nir_lower_tex_options *tex_options, + uint8_t ucp_enables); #endif diff --git a/src/gallium/drivers/lima/lima_screen.c b/src/gallium/drivers/lima/lima_screen.c index 25eb28e2ffb9809fc5ecb3c1fc33238b4ef64ed5..944079109b9165738530f0a87faba9fba18dc777 100644 --- a/src/gallium/drivers/lima/lima_screen.c +++ b/src/gallium/drivers/lima/lima_screen.c @@ -147,7 +147,6 @@ lima_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) case PIPE_CAP_ALPHA_TEST: case PIPE_CAP_FLATSHADE: case PIPE_CAP_TWO_SIDED_COLOR: - case PIPE_CAP_CLIP_PLANES: return 0; case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES: diff --git a/src/gallium/drivers/lima/standalone/lima_compiler_cmdline.c b/src/gallium/drivers/lima/standalone/lima_compiler_cmdline.c index f510e7310520c81ed595e9612680a36904408946..9fac9c3e7e9d224a063887e8371b72c1d32d0551 100644 --- a/src/gallium/drivers/lima/standalone/lima_compiler_cmdline.c +++ b/src/gallium/drivers/lima/standalone/lima_compiler_cmdline.c @@ -220,7 +220,7 @@ main(int argc, char **argv) switch (stage) { case MESA_SHADER_VERTEX: - lima_program_optimize_vs_nir(nir); + lima_program_optimize_vs_nir(nir, 0); nir_print_shader(nir, stdout); @@ -228,7 +228,7 @@ main(int argc, char **argv) gpir_compile_nir(vs, nir, NULL); break; case MESA_SHADER_FRAGMENT: - lima_program_optimize_fs_nir(nir, &tex_options); + lima_program_optimize_fs_nir(nir, &tex_options, 0); nir_print_shader(nir, stdout);