Lines Matching refs:ctx

54 lima_clip_scissor_to_viewport(struct lima_context *ctx)
56 struct lima_context_framebuffer *fb = &ctx->framebuffer;
57 struct pipe_scissor_state *cscissor = &ctx->clipped_scissor;
60 if (ctx->rasterizer && ctx->rasterizer->base.scissor) {
61 struct pipe_scissor_state *scissor = &ctx->scissor;
73 viewport_left = MAX2(ctx->viewport.left, 0);
75 viewport_right = MIN2(MAX2(ctx->viewport.right, 0), fb->base.width);
80 viewport_bottom = MAX2(ctx->viewport.bottom, 0);
82 viewport_top = MIN2(MAX2(ctx->viewport.top, 0), fb->base.height);
89 lima_extend_viewport(struct lima_context *ctx, const struct pipe_draw_info *info)
92 ctx->ext_viewport.left = ctx->viewport.left;
93 ctx->ext_viewport.right = ctx->viewport.right;
94 ctx->ext_viewport.bottom = ctx->viewport.bottom;
95 ctx->ext_viewport.top = ctx->viewport.top;
100 if (!ctx->rasterizer)
103 float line_width = ctx->rasterizer->base.line_width;
108 ctx->ext_viewport.left = ctx->viewport.left - line_width / 2;
109 ctx->ext_viewport.right = ctx->viewport.right + line_width / 2;
110 ctx->ext_viewport.bottom = ctx->viewport.bottom - line_width / 2;
111 ctx->ext_viewport.top = ctx->viewport.top + line_width / 2;
115 lima_is_scissor_zero(struct lima_context *ctx)
117 struct pipe_scissor_state *cscissor = &ctx->clipped_scissor;
123 lima_update_job_wb(struct lima_context *ctx, unsigned buffers)
125 struct lima_job *job = lima_job_get(ctx);
126 struct lima_context_framebuffer *fb = &ctx->framebuffer;
132 lima_flush_job_accessing_bo(ctx, res->bo, true);
133 _mesa_hash_table_insert(ctx->write_jobs, &res->base, job);
141 lima_flush_job_accessing_bo(ctx, res->bo, true);
142 _mesa_hash_table_insert(ctx->write_jobs, &res->base, job);
153 struct lima_context *ctx = lima_context(pctx);
154 struct lima_job *job = lima_job_get(ctx);
160 job = lima_job_get(ctx);
163 lima_update_job_wb(ctx, buffers);
166 if (ctx->framebuffer.base.nr_cbufs && (buffers & PIPE_CLEAR_COLOR0)) {
167 struct lima_surface *surf = lima_surface(ctx->framebuffer.base.cbufs[0]);
188 struct lima_surface *zsbuf = lima_surface(ctx->framebuffer.base.zsbuf);
202 ctx->dirty |= LIMA_CONTEXT_DIRTY_CLEAR;
205 0, ctx->framebuffer.base.width,
206 0, ctx->framebuffer.base.height);
288 lima_pack_vs_cmd(struct lima_context *ctx, const struct pipe_draw_info *info,
292 ctx->const_buffer + PIPE_SHADER_VERTEX;
293 struct lima_vs_compiled_shader *vs = ctx->vs;
294 struct lima_job *job = lima_job_get(ctx);
306 lima_ctx_buff_va(ctx, lima_ctx_buff_gp_uniform),
309 VS_CMD_SHADER_ADDRESS(ctx->vs->bo->va, ctx->vs->state.shader_size);
310 VS_CMD_SHADER_INFO(ctx->vs->state.prefetch, ctx->vs->state.shader_size);
312 int num_outputs = ctx->vs->state.num_outputs;
313 int num_attributes = ctx->vertex_elements->num_elements;
319 lima_ctx_buff_va(ctx, lima_ctx_buff_gp_attribute_info),
323 lima_ctx_buff_va(ctx, lima_ctx_buff_gp_varying_info),
326 unsigned num = info->index_size ? (ctx->max_index - ctx->min_index + 1) : draw->count;
337 lima_pack_plbu_cmd(struct lima_context *ctx, const struct pipe_draw_info *info,
340 struct lima_vs_compiled_shader *vs = ctx->vs;
341 struct pipe_scissor_state *cscissor = &ctx->clipped_scissor;
342 struct lima_job *job = lima_job_get(ctx);
345 PLBU_CMD_VIEWPORT_LEFT(fui(ctx->ext_viewport.left));
346 PLBU_CMD_VIEWPORT_RIGHT(fui(ctx->ext_viewport.right));
347 PLBU_CMD_VIEWPORT_BOTTOM(fui(ctx->ext_viewport.bottom));
348 PLBU_CMD_VIEWPORT_TOP(fui(ctx->ext_viewport.top));
353 int cf = ctx->rasterizer->base.cull_face;
354 int ccw = ctx->rasterizer->base.front_ccw;
366 if (info->mode == PIPE_PRIM_POINTS && ctx->vs->state.point_size_idx == -1)
376 lima_ctx_buff_va(ctx, lima_ctx_buff_pp_plb_rsw),
377 ctx->gp_output->va);
392 PLBU_CMD_DEPTH_RANGE_NEAR(fui(ctx->viewport.near));
393 PLBU_CMD_DEPTH_RANGE_FAR(fui(ctx->viewport.far));
395 if ((info->mode == PIPE_PRIM_POINTS && ctx->vs->state.point_size_idx == -1) ||
399 fui(ctx->rasterizer->base.point_size) : fui(ctx->rasterizer->base.line_width);
404 PLBU_CMD_INDEXED_DEST(ctx->gp_output->va);
406 PLBU_CMD_INDEXED_PT_SIZE(ctx->gp_output->va + ctx->gp_output_point_size_offt);
408 PLBU_CMD_INDICES(ctx->index_res->bo->va + draw->start * info->index_size + ctx->index_offset);
418 PLBU_CMD_DRAW_ELEMENTS(info->mode, ctx->min_index, draw->count);
581 lima_pack_render_state(struct lima_context *ctx, const struct pipe_draw_info *info)
583 struct lima_fs_compiled_shader *fs = ctx->fs;
585 lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_plb_rsw,
595 struct pipe_rt_blend_state *rt = ctx->blend->base.rt;
596 render->blend_color_bg = float_to_ubyte(ctx->blend_color.color[2]) |
597 (float_to_ubyte(ctx->blend_color.color[1]) << 16);
598 render->blend_color_ra = float_to_ubyte(ctx->blend_color.color[0]) |
599 (float_to_ubyte(ctx->blend_color.color[3]) << 16);
620 struct pipe_rasterizer_state *rst = &ctx->rasterizer->base;
621 render->depth_test = lima_calculate_depth_test(&ctx->zsa->base, rst);
623 if (!rst->depth_clip_near || ctx->viewport.near == 0.0f)
625 if (!rst->depth_clip_far || ctx->viewport.far == 1.0f)
636 near = float_to_ushort(ctx->viewport.near);
637 far = float_to_ushort(ctx->viewport.far);
642 struct pipe_stencil_state *stencil = ctx->zsa->base.stencil;
643 struct pipe_stencil_ref *ref = &ctx->stencil_ref;
683 if (ctx->framebuffer.base.samples)
685 if (ctx->blend->base.alpha_to_coverage)
687 if (ctx->blend->base.alpha_to_one)
689 render->multi_sample |= (ctx->sample_mask << 12);
698 if (ctx->zsa->base.alpha_enabled) {
699 render->multi_sample |= ctx->zsa->base.alpha_func;
700 render->stencil_test |= float_to_ubyte(ctx->zsa->base.alpha_ref_value) << 16;
707 ctx->fs->bo->va | (((uint32_t *)ctx->fs->bo->map)[0] & 0x1F);
714 render->aux0 = (ctx->vs->state.varying_stride >> 3);
716 if (ctx->rasterizer->base.front_ccw)
719 if (ctx->blend->base.dither)
723 ctx->zsa->base.alpha_enabled ||
725 ctx->blend->base.alpha_to_coverage) {
742 if (ctx->tex_stateobj.num_samplers) {
744 lima_ctx_buff_va(ctx, lima_ctx_buff_pp_tex_desc);
745 render->aux0 |= ctx->tex_stateobj.num_samplers << 14;
749 if (ctx->const_buffer[PIPE_SHADER_FRAGMENT].buffer) {
751 lima_ctx_buff_va(ctx, lima_ctx_buff_pp_uniform_array);
752 uint32_t size = ctx->buffer_state[lima_ctx_buff_pp_uniform].size;
768 if (ctx->vs->state.num_varyings) {
770 render->varyings_address = ctx->gp_output->va +
771 ctx->gp_output_varyings_offt;
772 for (int i = 0, index = 0; i < ctx->vs->state.num_outputs; i++) {
775 if (i == ctx->vs->state.gl_pos_idx ||
776 i == ctx->vs->state.point_size_idx)
779 struct lima_varying_info *v = ctx->vs->state.varying + i;
802 struct lima_job *job = lima_job_get(ctx);
807 lima_ctx_buff_va(ctx, lima_ctx_buff_pp_plb_rsw));
811 lima_ctx_buff_va(ctx, lima_ctx_buff_pp_plb_rsw));
815 lima_update_gp_attribute_info(struct lima_context *ctx, const struct pipe_draw_info *info,
818 struct lima_job *job = lima_job_get(ctx);
819 struct lima_vertex_element_state *ve = ctx->vertex_elements;
820 struct lima_context_vertex_buffer *vb = &ctx->vertex_buffers;
823 lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_attribute_info,
838 unsigned start = info->index_size ? (ctx->min_index + draw->index_bias) : draw->start;
848 lima_ctx_buff_va(ctx, lima_ctx_buff_gp_attribute_info));
852 lima_update_gp_uniform(struct lima_context *ctx)
855 ctx->const_buffer + PIPE_SHADER_VERTEX;
856 struct lima_vs_compiled_shader *vs = ctx->vs;
861 lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_uniform, size);
867 ctx->viewport.transform.scale,
868 sizeof(ctx->viewport.transform.scale));
870 ctx->viewport.transform.translate,
871 sizeof(ctx->viewport.transform.translate));
877 struct lima_job *job = lima_job_get(ctx);
895 lima_ctx_buff_va(ctx, lima_ctx_buff_gp_uniform));
899 lima_update_pp_uniform(struct lima_context *ctx)
901 const float *const_buff = ctx->const_buffer[PIPE_SHADER_FRAGMENT].buffer;
902 size_t const_buff_size = ctx->const_buffer[PIPE_SHADER_FRAGMENT].size / sizeof(float);
908 lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_uniform,
912 lima_ctx_buff_alloc(ctx, lima_ctx_buff_pp_uniform_array, 4);
917 *array = lima_ctx_buff_va(ctx, lima_ctx_buff_pp_uniform);
919 struct lima_job *job = lima_job_get(ctx);
924 lima_ctx_buff_va(ctx, lima_ctx_buff_pp_uniform));
927 lima_ctx_buff_va(ctx, lima_ctx_buff_pp_uniform_array));
931 lima_update_varying(struct lima_context *ctx, const struct pipe_draw_info *info,
934 struct lima_job *job = lima_job_get(ctx);
935 struct lima_screen *screen = lima_screen(ctx->base.screen);
936 struct lima_vs_compiled_shader *vs = ctx->vs;
938 unsigned num = info->index_size ? (ctx->max_index - ctx->min_index + 1) : draw->count;
941 lima_ctx_buff_alloc(ctx, lima_ctx_buff_gp_varying_info,
971 ctx->gp_output_varyings_offt = gp_output_size;
977 ctx->gp_output_point_size_offt = gp_output_size;
984 ctx->gp_output = lima_bo_create(screen, gp_output_size, 0);
985 assert(ctx->gp_output);
986 lima_job_add_bo(job, LIMA_PIPE_GP, ctx->gp_output, LIMA_SUBMIT_BO_WRITE);
987 lima_job_add_bo(job, LIMA_PIPE_PP, ctx->gp_output, LIMA_SUBMIT_BO_READ);
994 varying[n++] = ctx->gp_output->va;
998 varying[n++] = ctx->gp_output->va + ctx->gp_output_point_size_offt;
1002 varying[n++] = ctx->gp_output->va + ctx->gp_output_varyings_offt +
1011 lima_ctx_buff_va(ctx, lima_ctx_buff_gp_varying_info));
1019 struct lima_context *ctx = lima_context(pctx);
1020 struct lima_context_framebuffer *fb = &ctx->framebuffer;
1024 if (ctx->zsa->base.depth_enabled)
1026 if (ctx->zsa->base.stencil[0].enabled ||
1027 ctx->zsa->base.stencil[1].enabled)
1034 lima_update_job_wb(ctx, buffers);
1036 lima_update_gp_attribute_info(ctx, info, draw);
1038 if ((ctx->dirty & LIMA_CONTEXT_DIRTY_CONST_BUFF &&
1039 ctx->const_buffer[PIPE_SHADER_VERTEX].dirty) ||
1040 ctx->dirty & LIMA_CONTEXT_DIRTY_VIEWPORT ||
1041 ctx->dirty & LIMA_CONTEXT_DIRTY_COMPILED_VS) {
1042 lima_update_gp_uniform(ctx);
1043 ctx->const_buffer[PIPE_SHADER_VERTEX].dirty = false;
1046 lima_update_varying(ctx, info, draw);
1048 lima_pack_vs_cmd(ctx, info, draw);
1050 if (ctx->dirty & LIMA_CONTEXT_DIRTY_CONST_BUFF &&
1051 ctx->const_buffer[PIPE_SHADER_FRAGMENT].dirty) {
1052 lima_update_pp_uniform(ctx);
1053 ctx->const_buffer[PIPE_SHADER_FRAGMENT].dirty = false;
1056 lima_update_textures(ctx);
1058 lima_pack_render_state(ctx, info);
1059 lima_pack_plbu_cmd(ctx, info, draw);
1061 if (ctx->gp_output) {
1062 lima_bo_unreference(ctx->gp_output); /* held by job */
1063 ctx->gp_output = NULL;
1066 ctx->dirty = 0;
1074 struct lima_context *ctx = lima_context(pctx);
1075 struct lima_job *job = lima_job_get(ctx);
1082 ctx->min_index = info->min_index;
1083 ctx->max_index = info->max_index;
1088 util_upload_index_buffer(&ctx->base, info, draw, &indexbuf, &ctx->index_offset, 0x40);
1089 ctx->index_res = lima_resource(indexbuf);
1092 ctx->index_res = lima_resource(info->index.resource);
1093 ctx->index_offset = 0;
1094 needs_indices = !panfrost_minmax_cache_get(ctx->index_res->index_cache, draw->start,
1095 draw->count, &ctx->min_index, &ctx->max_index);
1099 u_vbuf_get_minmax_index(pctx, info, draw, &ctx->min_index, &ctx->max_index);
1101 panfrost_minmax_cache_add(ctx->index_res->index_cache, draw->start, draw->count,
1102 ctx->min_index, ctx->max_index);
1105 lima_job_add_bo(job, LIMA_PIPE_GP, ctx->index_res->bo, LIMA_SUBMIT_BO_READ);
1106 lima_job_add_bo(job, LIMA_PIPE_PP, ctx->index_res->bo, LIMA_SUBMIT_BO_READ);
1160 struct lima_context *ctx = lima_context(pctx);
1162 if (!ctx->uncomp_fs || !ctx->uncomp_vs) {
1167 lima_clip_scissor_to_viewport(ctx);
1168 if (lima_is_scissor_zero(ctx))
1173 lima_extend_viewport(ctx, info);
1175 if (!lima_update_fs_state(ctx) || !lima_update_vs_state(ctx))
1178 struct lima_job *job = lima_job_get(ctx);
1179 job->pp_max_stack_size = MAX2(job->pp_max_stack_size, ctx->fs->state.stack_size);
1182 job->dump, ctx->vs->bo->map, ctx->vs->state.shader_size, false,
1183 "add vs at va %x\n", ctx->vs->bo->va);
1184 lima_dump_shader(job->dump, ctx->vs->bo->map, ctx->vs->state.shader_size, false);
1187 job->dump, ctx->fs->bo->map, ctx->fs->state.shader_size, false,
1188 "add fs at va %x\n", ctx->fs->bo->va);
1189 lima_dump_shader(job->dump, ctx->fs->bo->map, ctx->fs->state.shader_size, true);
1191 lima_job_add_bo(job, LIMA_PIPE_GP, ctx->vs->bo, LIMA_SUBMIT_BO_READ);
1192 lima_job_add_bo(job, LIMA_PIPE_PP, ctx->fs->bo, LIMA_SUBMIT_BO_READ);
1206 lima_update_job_wb(ctx, resolve);
1211 lima_draw_init(struct lima_context *ctx)
1213 ctx->base.clear = lima_clear;
1214 ctx->base.draw_vbo = lima_draw_vbo;