1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (c) 2011-2013 Luc Verhaegen <libv@skynet.be> 3bf215546Sopenharmony_ci * Copyright (c) 2017-2019 Lima Project 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license, 9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 13bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 14bf215546Sopenharmony_ci * of the Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci * 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "util/format/u_format.h" 27bf215546Sopenharmony_ci#include "util/u_memory.h" 28bf215546Sopenharmony_ci#include "util/u_inlines.h" 29bf215546Sopenharmony_ci#include "util/u_helpers.h" 30bf215546Sopenharmony_ci#include "util/u_debug.h" 31bf215546Sopenharmony_ci#include "util/u_framebuffer.h" 32bf215546Sopenharmony_ci#include "util/u_viewport.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#include "pipe/p_state.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#include "lima_screen.h" 37bf215546Sopenharmony_ci#include "lima_context.h" 38bf215546Sopenharmony_ci#include "lima_format.h" 39bf215546Sopenharmony_ci#include "lima_resource.h" 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_cistatic void 42bf215546Sopenharmony_cilima_set_framebuffer_state(struct pipe_context *pctx, 43bf215546Sopenharmony_ci const struct pipe_framebuffer_state *framebuffer) 44bf215546Sopenharmony_ci{ 45bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci /* make sure there are always single job in this context */ 48bf215546Sopenharmony_ci if (lima_debug & LIMA_DEBUG_SINGLE_JOB) 49bf215546Sopenharmony_ci lima_flush(ctx); 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci struct lima_context_framebuffer *fb = &ctx->framebuffer; 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci util_copy_framebuffer_state(&fb->base, framebuffer); 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci ctx->job = NULL; 56bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_FRAMEBUFFER; 57bf215546Sopenharmony_ci} 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_cistatic void 60bf215546Sopenharmony_cilima_set_polygon_stipple(struct pipe_context *pctx, 61bf215546Sopenharmony_ci const struct pipe_poly_stipple *stipple) 62bf215546Sopenharmony_ci{ 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci} 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_cistatic void * 67bf215546Sopenharmony_cilima_create_depth_stencil_alpha_state(struct pipe_context *pctx, 68bf215546Sopenharmony_ci const struct pipe_depth_stencil_alpha_state *cso) 69bf215546Sopenharmony_ci{ 70bf215546Sopenharmony_ci struct lima_depth_stencil_alpha_state *so; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci so = CALLOC_STRUCT(lima_depth_stencil_alpha_state); 73bf215546Sopenharmony_ci if (!so) 74bf215546Sopenharmony_ci return NULL; 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci so->base = *cso; 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci return so; 79bf215546Sopenharmony_ci} 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_cistatic void 82bf215546Sopenharmony_cilima_bind_depth_stencil_alpha_state(struct pipe_context *pctx, void *hwcso) 83bf215546Sopenharmony_ci{ 84bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci ctx->zsa = hwcso; 87bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_ZSA; 88bf215546Sopenharmony_ci} 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_cistatic void 91bf215546Sopenharmony_cilima_delete_depth_stencil_alpha_state(struct pipe_context *pctx, void *hwcso) 92bf215546Sopenharmony_ci{ 93bf215546Sopenharmony_ci FREE(hwcso); 94bf215546Sopenharmony_ci} 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_cistatic void * 97bf215546Sopenharmony_cilima_create_rasterizer_state(struct pipe_context *pctx, 98bf215546Sopenharmony_ci const struct pipe_rasterizer_state *cso) 99bf215546Sopenharmony_ci{ 100bf215546Sopenharmony_ci struct lima_rasterizer_state *so; 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci so = CALLOC_STRUCT(lima_rasterizer_state); 103bf215546Sopenharmony_ci if (!so) 104bf215546Sopenharmony_ci return NULL; 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci so->base = *cso; 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci return so; 109bf215546Sopenharmony_ci} 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_cistatic void 112bf215546Sopenharmony_cilima_bind_rasterizer_state(struct pipe_context *pctx, void *hwcso) 113bf215546Sopenharmony_ci{ 114bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci ctx->rasterizer = hwcso; 117bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_RASTERIZER; 118bf215546Sopenharmony_ci} 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_cistatic void 121bf215546Sopenharmony_cilima_delete_rasterizer_state(struct pipe_context *pctx, void *hwcso) 122bf215546Sopenharmony_ci{ 123bf215546Sopenharmony_ci FREE(hwcso); 124bf215546Sopenharmony_ci} 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_cistatic void * 127bf215546Sopenharmony_cilima_create_blend_state(struct pipe_context *pctx, 128bf215546Sopenharmony_ci const struct pipe_blend_state *cso) 129bf215546Sopenharmony_ci{ 130bf215546Sopenharmony_ci struct lima_blend_state *so; 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci so = CALLOC_STRUCT(lima_blend_state); 133bf215546Sopenharmony_ci if (!so) 134bf215546Sopenharmony_ci return NULL; 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci so->base = *cso; 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_ci return so; 139bf215546Sopenharmony_ci} 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_cistatic void 142bf215546Sopenharmony_cilima_bind_blend_state(struct pipe_context *pctx, void *hwcso) 143bf215546Sopenharmony_ci{ 144bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci ctx->blend = hwcso; 147bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_BLEND; 148bf215546Sopenharmony_ci} 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_cistatic void 151bf215546Sopenharmony_cilima_delete_blend_state(struct pipe_context *pctx, void *hwcso) 152bf215546Sopenharmony_ci{ 153bf215546Sopenharmony_ci FREE(hwcso); 154bf215546Sopenharmony_ci} 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_cistatic void * 157bf215546Sopenharmony_cilima_create_vertex_elements_state(struct pipe_context *pctx, unsigned num_elements, 158bf215546Sopenharmony_ci const struct pipe_vertex_element *elements) 159bf215546Sopenharmony_ci{ 160bf215546Sopenharmony_ci struct lima_vertex_element_state *so; 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ci so = CALLOC_STRUCT(lima_vertex_element_state); 163bf215546Sopenharmony_ci if (!so) 164bf215546Sopenharmony_ci return NULL; 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ci memcpy(so->pipe, elements, sizeof(*elements) * num_elements); 167bf215546Sopenharmony_ci so->num_elements = num_elements; 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci return so; 170bf215546Sopenharmony_ci} 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_cistatic void 173bf215546Sopenharmony_cilima_bind_vertex_elements_state(struct pipe_context *pctx, void *hwcso) 174bf215546Sopenharmony_ci{ 175bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_ci ctx->vertex_elements = hwcso; 178bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_VERTEX_ELEM; 179bf215546Sopenharmony_ci} 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_cistatic void 182bf215546Sopenharmony_cilima_delete_vertex_elements_state(struct pipe_context *pctx, void *hwcso) 183bf215546Sopenharmony_ci{ 184bf215546Sopenharmony_ci FREE(hwcso); 185bf215546Sopenharmony_ci} 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_cistatic void 188bf215546Sopenharmony_cilima_set_vertex_buffers(struct pipe_context *pctx, 189bf215546Sopenharmony_ci unsigned start_slot, unsigned count, 190bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 191bf215546Sopenharmony_ci bool take_ownership, 192bf215546Sopenharmony_ci const struct pipe_vertex_buffer *vb) 193bf215546Sopenharmony_ci{ 194bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 195bf215546Sopenharmony_ci struct lima_context_vertex_buffer *so = &ctx->vertex_buffers; 196bf215546Sopenharmony_ci 197bf215546Sopenharmony_ci util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, 198bf215546Sopenharmony_ci vb, start_slot, count, 199bf215546Sopenharmony_ci unbind_num_trailing_slots, 200bf215546Sopenharmony_ci take_ownership); 201bf215546Sopenharmony_ci so->count = util_last_bit(so->enabled_mask); 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_VERTEX_BUFF; 204bf215546Sopenharmony_ci} 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_cistatic void 207bf215546Sopenharmony_cilima_set_viewport_states(struct pipe_context *pctx, 208bf215546Sopenharmony_ci unsigned start_slot, 209bf215546Sopenharmony_ci unsigned num_viewports, 210bf215546Sopenharmony_ci const struct pipe_viewport_state *viewport) 211bf215546Sopenharmony_ci{ 212bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ci /* reverse calculate the parameter of glViewport */ 215bf215546Sopenharmony_ci ctx->viewport.left = ctx->ext_viewport.left = 216bf215546Sopenharmony_ci viewport->translate[0] - fabsf(viewport->scale[0]); 217bf215546Sopenharmony_ci ctx->viewport.right = ctx->ext_viewport.right = 218bf215546Sopenharmony_ci viewport->translate[0] + fabsf(viewport->scale[0]); 219bf215546Sopenharmony_ci ctx->viewport.bottom = ctx->ext_viewport.bottom = 220bf215546Sopenharmony_ci viewport->translate[1] - fabsf(viewport->scale[1]); 221bf215546Sopenharmony_ci ctx->viewport.top = ctx->ext_viewport.top = 222bf215546Sopenharmony_ci viewport->translate[1] + fabsf(viewport->scale[1]); 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_ci /* reverse calculate the parameter of glDepthRange */ 225bf215546Sopenharmony_ci float near, far; 226bf215546Sopenharmony_ci bool halfz = ctx->rasterizer && ctx->rasterizer->base.clip_halfz; 227bf215546Sopenharmony_ci util_viewport_zmin_zmax(viewport, halfz, &near, &far); 228bf215546Sopenharmony_ci 229bf215546Sopenharmony_ci ctx->viewport.near = ctx->rasterizer && ctx->rasterizer->base.depth_clip_near ? near : 0.0f; 230bf215546Sopenharmony_ci ctx->viewport.far = ctx->rasterizer && ctx->rasterizer->base.depth_clip_far ? far : 1.0f; 231bf215546Sopenharmony_ci 232bf215546Sopenharmony_ci ctx->viewport.transform = *viewport; 233bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_VIEWPORT; 234bf215546Sopenharmony_ci} 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_cistatic void 237bf215546Sopenharmony_cilima_set_scissor_states(struct pipe_context *pctx, 238bf215546Sopenharmony_ci unsigned start_slot, 239bf215546Sopenharmony_ci unsigned num_scissors, 240bf215546Sopenharmony_ci const struct pipe_scissor_state *scissor) 241bf215546Sopenharmony_ci{ 242bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 243bf215546Sopenharmony_ci 244bf215546Sopenharmony_ci ctx->scissor = *scissor; 245bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_SCISSOR; 246bf215546Sopenharmony_ci} 247bf215546Sopenharmony_ci 248bf215546Sopenharmony_cistatic void 249bf215546Sopenharmony_cilima_set_blend_color(struct pipe_context *pctx, 250bf215546Sopenharmony_ci const struct pipe_blend_color *blend_color) 251bf215546Sopenharmony_ci{ 252bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ci ctx->blend_color = *blend_color; 255bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_BLEND_COLOR; 256bf215546Sopenharmony_ci} 257bf215546Sopenharmony_ci 258bf215546Sopenharmony_cistatic void 259bf215546Sopenharmony_cilima_set_stencil_ref(struct pipe_context *pctx, 260bf215546Sopenharmony_ci const struct pipe_stencil_ref stencil_ref) 261bf215546Sopenharmony_ci{ 262bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 263bf215546Sopenharmony_ci 264bf215546Sopenharmony_ci ctx->stencil_ref = stencil_ref; 265bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_STENCIL_REF; 266bf215546Sopenharmony_ci} 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_cistatic void 269bf215546Sopenharmony_cilima_set_clip_state(struct pipe_context *pctx, 270bf215546Sopenharmony_ci const struct pipe_clip_state *clip) 271bf215546Sopenharmony_ci{ 272bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 273bf215546Sopenharmony_ci ctx->clip = *clip; 274bf215546Sopenharmony_ci 275bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_CLIP; 276bf215546Sopenharmony_ci} 277bf215546Sopenharmony_ci 278bf215546Sopenharmony_cistatic void 279bf215546Sopenharmony_cilima_set_constant_buffer(struct pipe_context *pctx, 280bf215546Sopenharmony_ci enum pipe_shader_type shader, uint index, 281bf215546Sopenharmony_ci bool pass_reference, 282bf215546Sopenharmony_ci const struct pipe_constant_buffer *cb) 283bf215546Sopenharmony_ci{ 284bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 285bf215546Sopenharmony_ci struct lima_context_constant_buffer *so = ctx->const_buffer + shader; 286bf215546Sopenharmony_ci 287bf215546Sopenharmony_ci assert(index == 0); 288bf215546Sopenharmony_ci 289bf215546Sopenharmony_ci if (unlikely(!cb)) { 290bf215546Sopenharmony_ci so->buffer = NULL; 291bf215546Sopenharmony_ci so->size = 0; 292bf215546Sopenharmony_ci } else { 293bf215546Sopenharmony_ci assert(!cb->buffer); 294bf215546Sopenharmony_ci 295bf215546Sopenharmony_ci so->buffer = cb->user_buffer + cb->buffer_offset; 296bf215546Sopenharmony_ci so->size = cb->buffer_size; 297bf215546Sopenharmony_ci } 298bf215546Sopenharmony_ci 299bf215546Sopenharmony_ci so->dirty = true; 300bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_CONST_BUFF; 301bf215546Sopenharmony_ci 302bf215546Sopenharmony_ci} 303bf215546Sopenharmony_ci 304bf215546Sopenharmony_cistatic void * 305bf215546Sopenharmony_cilima_create_sampler_state(struct pipe_context *pctx, 306bf215546Sopenharmony_ci const struct pipe_sampler_state *cso) 307bf215546Sopenharmony_ci{ 308bf215546Sopenharmony_ci struct lima_sampler_state *so = CALLOC_STRUCT(lima_sampler_state); 309bf215546Sopenharmony_ci if (!so) 310bf215546Sopenharmony_ci return NULL; 311bf215546Sopenharmony_ci 312bf215546Sopenharmony_ci memcpy(so, cso, sizeof(*cso)); 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_ci return so; 315bf215546Sopenharmony_ci} 316bf215546Sopenharmony_ci 317bf215546Sopenharmony_cistatic void 318bf215546Sopenharmony_cilima_sampler_state_delete(struct pipe_context *pctx, void *sstate) 319bf215546Sopenharmony_ci{ 320bf215546Sopenharmony_ci free(sstate); 321bf215546Sopenharmony_ci} 322bf215546Sopenharmony_ci 323bf215546Sopenharmony_cistatic void 324bf215546Sopenharmony_cilima_sampler_states_bind(struct pipe_context *pctx, 325bf215546Sopenharmony_ci enum pipe_shader_type shader, unsigned start, 326bf215546Sopenharmony_ci unsigned nr, void **hwcso) 327bf215546Sopenharmony_ci{ 328bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 329bf215546Sopenharmony_ci struct lima_texture_stateobj *lima_tex = &ctx->tex_stateobj; 330bf215546Sopenharmony_ci unsigned i; 331bf215546Sopenharmony_ci unsigned new_nr = 0; 332bf215546Sopenharmony_ci 333bf215546Sopenharmony_ci assert(start == 0); 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ci for (i = 0; i < nr; i++) { 336bf215546Sopenharmony_ci if (hwcso[i]) 337bf215546Sopenharmony_ci new_nr = i + 1; 338bf215546Sopenharmony_ci lima_tex->samplers[i] = hwcso[i]; 339bf215546Sopenharmony_ci } 340bf215546Sopenharmony_ci 341bf215546Sopenharmony_ci for (; i < lima_tex->num_samplers; i++) { 342bf215546Sopenharmony_ci lima_tex->samplers[i] = NULL; 343bf215546Sopenharmony_ci } 344bf215546Sopenharmony_ci 345bf215546Sopenharmony_ci lima_tex->num_samplers = new_nr; 346bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_TEXTURES; 347bf215546Sopenharmony_ci} 348bf215546Sopenharmony_ci 349bf215546Sopenharmony_cistatic struct pipe_sampler_view * 350bf215546Sopenharmony_cilima_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *prsc, 351bf215546Sopenharmony_ci const struct pipe_sampler_view *cso) 352bf215546Sopenharmony_ci{ 353bf215546Sopenharmony_ci struct lima_sampler_view *so = CALLOC_STRUCT(lima_sampler_view); 354bf215546Sopenharmony_ci 355bf215546Sopenharmony_ci if (!so) 356bf215546Sopenharmony_ci return NULL; 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci so->base = *cso; 359bf215546Sopenharmony_ci 360bf215546Sopenharmony_ci pipe_reference(NULL, &prsc->reference); 361bf215546Sopenharmony_ci so->base.texture = prsc; 362bf215546Sopenharmony_ci so->base.reference.count = 1; 363bf215546Sopenharmony_ci so->base.context = pctx; 364bf215546Sopenharmony_ci 365bf215546Sopenharmony_ci uint8_t sampler_swizzle[4] = { cso->swizzle_r, cso->swizzle_g, 366bf215546Sopenharmony_ci cso->swizzle_b, cso->swizzle_a }; 367bf215546Sopenharmony_ci const uint8_t *format_swizzle = lima_format_get_texel_swizzle(cso->format); 368bf215546Sopenharmony_ci util_format_compose_swizzles(format_swizzle, sampler_swizzle, so->swizzle); 369bf215546Sopenharmony_ci 370bf215546Sopenharmony_ci return &so->base; 371bf215546Sopenharmony_ci} 372bf215546Sopenharmony_ci 373bf215546Sopenharmony_cistatic void 374bf215546Sopenharmony_cilima_sampler_view_destroy(struct pipe_context *pctx, 375bf215546Sopenharmony_ci struct pipe_sampler_view *pview) 376bf215546Sopenharmony_ci{ 377bf215546Sopenharmony_ci struct lima_sampler_view *view = lima_sampler_view(pview); 378bf215546Sopenharmony_ci 379bf215546Sopenharmony_ci pipe_resource_reference(&pview->texture, NULL); 380bf215546Sopenharmony_ci 381bf215546Sopenharmony_ci free(view); 382bf215546Sopenharmony_ci} 383bf215546Sopenharmony_ci 384bf215546Sopenharmony_cistatic void 385bf215546Sopenharmony_cilima_set_sampler_views(struct pipe_context *pctx, 386bf215546Sopenharmony_ci enum pipe_shader_type shader, 387bf215546Sopenharmony_ci unsigned start, unsigned nr, 388bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 389bf215546Sopenharmony_ci bool take_ownership, 390bf215546Sopenharmony_ci struct pipe_sampler_view **views) 391bf215546Sopenharmony_ci{ 392bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 393bf215546Sopenharmony_ci struct lima_texture_stateobj *lima_tex = &ctx->tex_stateobj; 394bf215546Sopenharmony_ci int i; 395bf215546Sopenharmony_ci unsigned new_nr = 0; 396bf215546Sopenharmony_ci 397bf215546Sopenharmony_ci assert(start == 0); 398bf215546Sopenharmony_ci 399bf215546Sopenharmony_ci for (i = 0; i < nr; i++) { 400bf215546Sopenharmony_ci if (views[i]) 401bf215546Sopenharmony_ci new_nr = i + 1; 402bf215546Sopenharmony_ci 403bf215546Sopenharmony_ci if (take_ownership) { 404bf215546Sopenharmony_ci pipe_sampler_view_reference(&lima_tex->textures[i], NULL); 405bf215546Sopenharmony_ci lima_tex->textures[i] = views[i]; 406bf215546Sopenharmony_ci } else { 407bf215546Sopenharmony_ci pipe_sampler_view_reference(&lima_tex->textures[i], views[i]); 408bf215546Sopenharmony_ci } 409bf215546Sopenharmony_ci } 410bf215546Sopenharmony_ci 411bf215546Sopenharmony_ci for (; i < lima_tex->num_textures; i++) { 412bf215546Sopenharmony_ci pipe_sampler_view_reference(&lima_tex->textures[i], NULL); 413bf215546Sopenharmony_ci } 414bf215546Sopenharmony_ci 415bf215546Sopenharmony_ci lima_tex->num_textures = new_nr; 416bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_TEXTURES; 417bf215546Sopenharmony_ci} 418bf215546Sopenharmony_ci 419bf215546Sopenharmony_cistatic void 420bf215546Sopenharmony_cilima_set_sample_mask(struct pipe_context *pctx, 421bf215546Sopenharmony_ci unsigned sample_mask) 422bf215546Sopenharmony_ci{ 423bf215546Sopenharmony_ci struct lima_context *ctx = lima_context(pctx); 424bf215546Sopenharmony_ci ctx->sample_mask = sample_mask & ((1 << LIMA_MAX_SAMPLES) - 1); 425bf215546Sopenharmony_ci ctx->dirty |= LIMA_CONTEXT_DIRTY_SAMPLE_MASK; 426bf215546Sopenharmony_ci} 427bf215546Sopenharmony_ci 428bf215546Sopenharmony_civoid 429bf215546Sopenharmony_cilima_state_init(struct lima_context *ctx) 430bf215546Sopenharmony_ci{ 431bf215546Sopenharmony_ci ctx->base.set_framebuffer_state = lima_set_framebuffer_state; 432bf215546Sopenharmony_ci ctx->base.set_polygon_stipple = lima_set_polygon_stipple; 433bf215546Sopenharmony_ci ctx->base.set_viewport_states = lima_set_viewport_states; 434bf215546Sopenharmony_ci ctx->base.set_scissor_states = lima_set_scissor_states; 435bf215546Sopenharmony_ci ctx->base.set_blend_color = lima_set_blend_color; 436bf215546Sopenharmony_ci ctx->base.set_stencil_ref = lima_set_stencil_ref; 437bf215546Sopenharmony_ci ctx->base.set_clip_state = lima_set_clip_state; 438bf215546Sopenharmony_ci 439bf215546Sopenharmony_ci ctx->base.set_vertex_buffers = lima_set_vertex_buffers; 440bf215546Sopenharmony_ci ctx->base.set_constant_buffer = lima_set_constant_buffer; 441bf215546Sopenharmony_ci 442bf215546Sopenharmony_ci ctx->base.create_depth_stencil_alpha_state = lima_create_depth_stencil_alpha_state; 443bf215546Sopenharmony_ci ctx->base.bind_depth_stencil_alpha_state = lima_bind_depth_stencil_alpha_state; 444bf215546Sopenharmony_ci ctx->base.delete_depth_stencil_alpha_state = lima_delete_depth_stencil_alpha_state; 445bf215546Sopenharmony_ci 446bf215546Sopenharmony_ci ctx->base.create_rasterizer_state = lima_create_rasterizer_state; 447bf215546Sopenharmony_ci ctx->base.bind_rasterizer_state = lima_bind_rasterizer_state; 448bf215546Sopenharmony_ci ctx->base.delete_rasterizer_state = lima_delete_rasterizer_state; 449bf215546Sopenharmony_ci 450bf215546Sopenharmony_ci ctx->base.create_blend_state = lima_create_blend_state; 451bf215546Sopenharmony_ci ctx->base.bind_blend_state = lima_bind_blend_state; 452bf215546Sopenharmony_ci ctx->base.delete_blend_state = lima_delete_blend_state; 453bf215546Sopenharmony_ci 454bf215546Sopenharmony_ci ctx->base.create_vertex_elements_state = lima_create_vertex_elements_state; 455bf215546Sopenharmony_ci ctx->base.bind_vertex_elements_state = lima_bind_vertex_elements_state; 456bf215546Sopenharmony_ci ctx->base.delete_vertex_elements_state = lima_delete_vertex_elements_state; 457bf215546Sopenharmony_ci 458bf215546Sopenharmony_ci ctx->base.create_sampler_state = lima_create_sampler_state; 459bf215546Sopenharmony_ci ctx->base.delete_sampler_state = lima_sampler_state_delete; 460bf215546Sopenharmony_ci ctx->base.bind_sampler_states = lima_sampler_states_bind; 461bf215546Sopenharmony_ci 462bf215546Sopenharmony_ci ctx->base.create_sampler_view = lima_create_sampler_view; 463bf215546Sopenharmony_ci ctx->base.sampler_view_destroy = lima_sampler_view_destroy; 464bf215546Sopenharmony_ci ctx->base.set_sampler_views = lima_set_sampler_views; 465bf215546Sopenharmony_ci 466bf215546Sopenharmony_ci ctx->base.set_sample_mask = lima_set_sample_mask; 467bf215546Sopenharmony_ci} 468bf215546Sopenharmony_ci 469bf215546Sopenharmony_civoid 470bf215546Sopenharmony_cilima_state_fini(struct lima_context *ctx) 471bf215546Sopenharmony_ci{ 472bf215546Sopenharmony_ci struct lima_context_vertex_buffer *so = &ctx->vertex_buffers; 473bf215546Sopenharmony_ci 474bf215546Sopenharmony_ci util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, NULL, 475bf215546Sopenharmony_ci 0, 0, ARRAY_SIZE(so->vb), false); 476bf215546Sopenharmony_ci 477bf215546Sopenharmony_ci pipe_surface_reference(&ctx->framebuffer.base.cbufs[0], NULL); 478bf215546Sopenharmony_ci pipe_surface_reference(&ctx->framebuffer.base.zsbuf, NULL); 479bf215546Sopenharmony_ci} 480