1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2015 Advanced Micro Devices, Inc. 4bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc. 5bf215546Sopenharmony_ci * All Rights Reserved. 6bf215546Sopenharmony_ci * 7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 9bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 10bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 11bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 12bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 15bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 16bf215546Sopenharmony_ci * Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 22bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "dd_pipe.h" 29bf215546Sopenharmony_ci#include "tgsi/tgsi_parse.h" 30bf215546Sopenharmony_ci#include "util/u_inlines.h" 31bf215546Sopenharmony_ci#include "util/u_memory.h" 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistatic void 35bf215546Sopenharmony_cisafe_memcpy(void *dst, const void *src, size_t size) 36bf215546Sopenharmony_ci{ 37bf215546Sopenharmony_ci if (src) 38bf215546Sopenharmony_ci memcpy(dst, src, size); 39bf215546Sopenharmony_ci else 40bf215546Sopenharmony_ci memset(dst, 0, size); 41bf215546Sopenharmony_ci} 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci/******************************************************************** 45bf215546Sopenharmony_ci * queries 46bf215546Sopenharmony_ci */ 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_cistatic struct pipe_query * 49bf215546Sopenharmony_cidd_context_create_query(struct pipe_context *_pipe, unsigned query_type, 50bf215546Sopenharmony_ci unsigned index) 51bf215546Sopenharmony_ci{ 52bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 53bf215546Sopenharmony_ci struct pipe_query *query; 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci query = pipe->create_query(pipe, query_type, index); 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci /* Wrap query object. */ 58bf215546Sopenharmony_ci if (query) { 59bf215546Sopenharmony_ci struct dd_query *dd_query = CALLOC_STRUCT(dd_query); 60bf215546Sopenharmony_ci if (dd_query) { 61bf215546Sopenharmony_ci dd_query->type = query_type; 62bf215546Sopenharmony_ci dd_query->query = query; 63bf215546Sopenharmony_ci query = (struct pipe_query *)dd_query; 64bf215546Sopenharmony_ci } else { 65bf215546Sopenharmony_ci pipe->destroy_query(pipe, query); 66bf215546Sopenharmony_ci query = NULL; 67bf215546Sopenharmony_ci } 68bf215546Sopenharmony_ci } 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci return query; 71bf215546Sopenharmony_ci} 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_cistatic struct pipe_query * 74bf215546Sopenharmony_cidd_context_create_batch_query(struct pipe_context *_pipe, unsigned num_queries, 75bf215546Sopenharmony_ci unsigned *query_types) 76bf215546Sopenharmony_ci{ 77bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 78bf215546Sopenharmony_ci struct pipe_query *query; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci query = pipe->create_batch_query(pipe, num_queries, query_types); 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci /* Wrap query object. */ 83bf215546Sopenharmony_ci if (query) { 84bf215546Sopenharmony_ci struct dd_query *dd_query = CALLOC_STRUCT(dd_query); 85bf215546Sopenharmony_ci if (dd_query) { 86bf215546Sopenharmony_ci /* no special handling for batch queries yet */ 87bf215546Sopenharmony_ci dd_query->type = query_types[0]; 88bf215546Sopenharmony_ci dd_query->query = query; 89bf215546Sopenharmony_ci query = (struct pipe_query *)dd_query; 90bf215546Sopenharmony_ci } else { 91bf215546Sopenharmony_ci pipe->destroy_query(pipe, query); 92bf215546Sopenharmony_ci query = NULL; 93bf215546Sopenharmony_ci } 94bf215546Sopenharmony_ci } 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci return query; 97bf215546Sopenharmony_ci} 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_cistatic void 100bf215546Sopenharmony_cidd_context_destroy_query(struct pipe_context *_pipe, 101bf215546Sopenharmony_ci struct pipe_query *query) 102bf215546Sopenharmony_ci{ 103bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci pipe->destroy_query(pipe, dd_query_unwrap(query)); 106bf215546Sopenharmony_ci FREE(query); 107bf215546Sopenharmony_ci} 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_cistatic bool 110bf215546Sopenharmony_cidd_context_begin_query(struct pipe_context *_pipe, struct pipe_query *query) 111bf215546Sopenharmony_ci{ 112bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 113bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci return pipe->begin_query(pipe, dd_query_unwrap(query)); 116bf215546Sopenharmony_ci} 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_cistatic bool 119bf215546Sopenharmony_cidd_context_end_query(struct pipe_context *_pipe, struct pipe_query *query) 120bf215546Sopenharmony_ci{ 121bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 122bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci return pipe->end_query(pipe, dd_query_unwrap(query)); 125bf215546Sopenharmony_ci} 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_cistatic bool 128bf215546Sopenharmony_cidd_context_get_query_result(struct pipe_context *_pipe, 129bf215546Sopenharmony_ci struct pipe_query *query, bool wait, 130bf215546Sopenharmony_ci union pipe_query_result *result) 131bf215546Sopenharmony_ci{ 132bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_ci return pipe->get_query_result(pipe, dd_query_unwrap(query), wait, result); 135bf215546Sopenharmony_ci} 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_cistatic void 138bf215546Sopenharmony_cidd_context_set_active_query_state(struct pipe_context *_pipe, bool enable) 139bf215546Sopenharmony_ci{ 140bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci pipe->set_active_query_state(pipe, enable); 143bf215546Sopenharmony_ci} 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_cistatic void 146bf215546Sopenharmony_cidd_context_render_condition(struct pipe_context *_pipe, 147bf215546Sopenharmony_ci struct pipe_query *query, bool condition, 148bf215546Sopenharmony_ci enum pipe_render_cond_flag mode) 149bf215546Sopenharmony_ci{ 150bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 151bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 152bf215546Sopenharmony_ci struct dd_draw_state *dstate = &dctx->draw_state; 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_ci pipe->render_condition(pipe, dd_query_unwrap(query), condition, mode); 155bf215546Sopenharmony_ci dstate->render_cond.query = dd_query(query); 156bf215546Sopenharmony_ci dstate->render_cond.condition = condition; 157bf215546Sopenharmony_ci dstate->render_cond.mode = mode; 158bf215546Sopenharmony_ci} 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci/******************************************************************** 162bf215546Sopenharmony_ci * constant (immutable) non-shader states 163bf215546Sopenharmony_ci */ 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci#define DD_CSO_CREATE(name, shortname) \ 166bf215546Sopenharmony_ci static void * \ 167bf215546Sopenharmony_ci dd_context_create_##name##_state(struct pipe_context *_pipe, \ 168bf215546Sopenharmony_ci const struct pipe_##name##_state *state) \ 169bf215546Sopenharmony_ci { \ 170bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; \ 171bf215546Sopenharmony_ci struct dd_state *hstate = CALLOC_STRUCT(dd_state); \ 172bf215546Sopenharmony_ci \ 173bf215546Sopenharmony_ci if (!hstate) \ 174bf215546Sopenharmony_ci return NULL; \ 175bf215546Sopenharmony_ci hstate->cso = pipe->create_##name##_state(pipe, state); \ 176bf215546Sopenharmony_ci hstate->state.shortname = *state; \ 177bf215546Sopenharmony_ci return hstate; \ 178bf215546Sopenharmony_ci } 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci#define DD_CSO_BIND(name, shortname) \ 181bf215546Sopenharmony_ci static void \ 182bf215546Sopenharmony_ci dd_context_bind_##name##_state(struct pipe_context *_pipe, void *state) \ 183bf215546Sopenharmony_ci { \ 184bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); \ 185bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; \ 186bf215546Sopenharmony_ci struct dd_state *hstate = state; \ 187bf215546Sopenharmony_ci \ 188bf215546Sopenharmony_ci dctx->draw_state.shortname = hstate; \ 189bf215546Sopenharmony_ci pipe->bind_##name##_state(pipe, hstate ? hstate->cso : NULL); \ 190bf215546Sopenharmony_ci } 191bf215546Sopenharmony_ci 192bf215546Sopenharmony_ci#define DD_CSO_DELETE(name) \ 193bf215546Sopenharmony_ci static void \ 194bf215546Sopenharmony_ci dd_context_delete_##name##_state(struct pipe_context *_pipe, void *state) \ 195bf215546Sopenharmony_ci { \ 196bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); \ 197bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; \ 198bf215546Sopenharmony_ci struct dd_state *hstate = state; \ 199bf215546Sopenharmony_ci \ 200bf215546Sopenharmony_ci pipe->delete_##name##_state(pipe, hstate->cso); \ 201bf215546Sopenharmony_ci FREE(hstate); \ 202bf215546Sopenharmony_ci } 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_ci#define DD_CSO_WHOLE(name, shortname) \ 205bf215546Sopenharmony_ci DD_CSO_CREATE(name, shortname) \ 206bf215546Sopenharmony_ci DD_CSO_BIND(name, shortname) \ 207bf215546Sopenharmony_ci DD_CSO_DELETE(name) 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_ciDD_CSO_WHOLE(blend, blend) 210bf215546Sopenharmony_ciDD_CSO_WHOLE(rasterizer, rs) 211bf215546Sopenharmony_ciDD_CSO_WHOLE(depth_stencil_alpha, dsa) 212bf215546Sopenharmony_ci 213bf215546Sopenharmony_ciDD_CSO_CREATE(sampler, sampler) 214bf215546Sopenharmony_ciDD_CSO_DELETE(sampler) 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_cistatic void 217bf215546Sopenharmony_cidd_context_bind_sampler_states(struct pipe_context *_pipe, 218bf215546Sopenharmony_ci enum pipe_shader_type shader, 219bf215546Sopenharmony_ci unsigned start, unsigned count, void **states) 220bf215546Sopenharmony_ci{ 221bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 222bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_ci memcpy(&dctx->draw_state.sampler_states[shader][start], states, 225bf215546Sopenharmony_ci sizeof(void*) * count); 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_ci if (states) { 228bf215546Sopenharmony_ci void *samp[PIPE_MAX_SAMPLERS]; 229bf215546Sopenharmony_ci int i; 230bf215546Sopenharmony_ci 231bf215546Sopenharmony_ci for (i = 0; i < count; i++) { 232bf215546Sopenharmony_ci struct dd_state *s = states[i]; 233bf215546Sopenharmony_ci samp[i] = s ? s->cso : NULL; 234bf215546Sopenharmony_ci } 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_ci pipe->bind_sampler_states(pipe, shader, start, count, samp); 237bf215546Sopenharmony_ci } 238bf215546Sopenharmony_ci else 239bf215546Sopenharmony_ci pipe->bind_sampler_states(pipe, shader, start, count, NULL); 240bf215546Sopenharmony_ci} 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_cistatic void * 243bf215546Sopenharmony_cidd_context_create_vertex_elements_state(struct pipe_context *_pipe, 244bf215546Sopenharmony_ci unsigned num_elems, 245bf215546Sopenharmony_ci const struct pipe_vertex_element *elems) 246bf215546Sopenharmony_ci{ 247bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 248bf215546Sopenharmony_ci struct dd_state *hstate = CALLOC_STRUCT(dd_state); 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci if (!hstate) 251bf215546Sopenharmony_ci return NULL; 252bf215546Sopenharmony_ci hstate->cso = pipe->create_vertex_elements_state(pipe, num_elems, elems); 253bf215546Sopenharmony_ci memcpy(hstate->state.velems.velems, elems, sizeof(elems[0]) * num_elems); 254bf215546Sopenharmony_ci hstate->state.velems.count = num_elems; 255bf215546Sopenharmony_ci return hstate; 256bf215546Sopenharmony_ci} 257bf215546Sopenharmony_ci 258bf215546Sopenharmony_ciDD_CSO_BIND(vertex_elements, velems) 259bf215546Sopenharmony_ciDD_CSO_DELETE(vertex_elements) 260bf215546Sopenharmony_ci 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_ci/******************************************************************** 263bf215546Sopenharmony_ci * shaders 264bf215546Sopenharmony_ci */ 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ci#define DD_SHADER_NOCREATE(NAME, name) \ 267bf215546Sopenharmony_ci static void \ 268bf215546Sopenharmony_ci dd_context_bind_##name##_state(struct pipe_context *_pipe, void *state) \ 269bf215546Sopenharmony_ci { \ 270bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); \ 271bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; \ 272bf215546Sopenharmony_ci struct dd_state *hstate = state; \ 273bf215546Sopenharmony_ci \ 274bf215546Sopenharmony_ci dctx->draw_state.shaders[PIPE_SHADER_##NAME] = hstate; \ 275bf215546Sopenharmony_ci pipe->bind_##name##_state(pipe, hstate ? hstate->cso : NULL); \ 276bf215546Sopenharmony_ci } \ 277bf215546Sopenharmony_ci \ 278bf215546Sopenharmony_ci static void \ 279bf215546Sopenharmony_ci dd_context_delete_##name##_state(struct pipe_context *_pipe, void *state) \ 280bf215546Sopenharmony_ci { \ 281bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); \ 282bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; \ 283bf215546Sopenharmony_ci struct dd_state *hstate = state; \ 284bf215546Sopenharmony_ci \ 285bf215546Sopenharmony_ci pipe->delete_##name##_state(pipe, hstate->cso); \ 286bf215546Sopenharmony_ci if (hstate->state.shader.type == PIPE_SHADER_IR_TGSI) \ 287bf215546Sopenharmony_ci tgsi_free_tokens(hstate->state.shader.tokens); \ 288bf215546Sopenharmony_ci FREE(hstate); \ 289bf215546Sopenharmony_ci } 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci#define DD_SHADER(NAME, name) \ 292bf215546Sopenharmony_ci static void * \ 293bf215546Sopenharmony_ci dd_context_create_##name##_state(struct pipe_context *_pipe, \ 294bf215546Sopenharmony_ci const struct pipe_shader_state *state) \ 295bf215546Sopenharmony_ci { \ 296bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; \ 297bf215546Sopenharmony_ci struct dd_state *hstate = CALLOC_STRUCT(dd_state); \ 298bf215546Sopenharmony_ci \ 299bf215546Sopenharmony_ci if (!hstate) \ 300bf215546Sopenharmony_ci return NULL; \ 301bf215546Sopenharmony_ci hstate->cso = pipe->create_##name##_state(pipe, state); \ 302bf215546Sopenharmony_ci hstate->state.shader = *state; \ 303bf215546Sopenharmony_ci if (hstate->state.shader.type == PIPE_SHADER_IR_TGSI) \ 304bf215546Sopenharmony_ci hstate->state.shader.tokens = tgsi_dup_tokens(state->tokens); \ 305bf215546Sopenharmony_ci return hstate; \ 306bf215546Sopenharmony_ci } \ 307bf215546Sopenharmony_ci \ 308bf215546Sopenharmony_ci DD_SHADER_NOCREATE(NAME, name) 309bf215546Sopenharmony_ci 310bf215546Sopenharmony_ciDD_SHADER(FRAGMENT, fs) 311bf215546Sopenharmony_ciDD_SHADER(VERTEX, vs) 312bf215546Sopenharmony_ciDD_SHADER(GEOMETRY, gs) 313bf215546Sopenharmony_ciDD_SHADER(TESS_CTRL, tcs) 314bf215546Sopenharmony_ciDD_SHADER(TESS_EVAL, tes) 315bf215546Sopenharmony_ci 316bf215546Sopenharmony_cistatic void * \ 317bf215546Sopenharmony_cidd_context_create_compute_state(struct pipe_context *_pipe, 318bf215546Sopenharmony_ci const struct pipe_compute_state *state) 319bf215546Sopenharmony_ci{ 320bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 321bf215546Sopenharmony_ci struct dd_state *hstate = CALLOC_STRUCT(dd_state); 322bf215546Sopenharmony_ci 323bf215546Sopenharmony_ci if (!hstate) 324bf215546Sopenharmony_ci return NULL; 325bf215546Sopenharmony_ci hstate->cso = pipe->create_compute_state(pipe, state); 326bf215546Sopenharmony_ci 327bf215546Sopenharmony_ci hstate->state.shader.type = state->ir_type; 328bf215546Sopenharmony_ci 329bf215546Sopenharmony_ci if (state->ir_type == PIPE_SHADER_IR_TGSI) 330bf215546Sopenharmony_ci hstate->state.shader.tokens = tgsi_dup_tokens(state->prog); 331bf215546Sopenharmony_ci 332bf215546Sopenharmony_ci return hstate; 333bf215546Sopenharmony_ci} 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ciDD_SHADER_NOCREATE(COMPUTE, compute) 336bf215546Sopenharmony_ci 337bf215546Sopenharmony_ci/******************************************************************** 338bf215546Sopenharmony_ci * immediate states 339bf215546Sopenharmony_ci */ 340bf215546Sopenharmony_ci 341bf215546Sopenharmony_ci#define DD_IMM_STATE(name, type, deref, ref) \ 342bf215546Sopenharmony_ci static void \ 343bf215546Sopenharmony_ci dd_context_set_##name(struct pipe_context *_pipe, type deref) \ 344bf215546Sopenharmony_ci { \ 345bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); \ 346bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; \ 347bf215546Sopenharmony_ci \ 348bf215546Sopenharmony_ci dctx->draw_state.name = deref; \ 349bf215546Sopenharmony_ci pipe->set_##name(pipe, ref); \ 350bf215546Sopenharmony_ci } 351bf215546Sopenharmony_ci 352bf215546Sopenharmony_ciDD_IMM_STATE(blend_color, const struct pipe_blend_color, *state, state) 353bf215546Sopenharmony_ciDD_IMM_STATE(stencil_ref, const struct pipe_stencil_ref, state, state) 354bf215546Sopenharmony_ciDD_IMM_STATE(clip_state, const struct pipe_clip_state, *state, state) 355bf215546Sopenharmony_ciDD_IMM_STATE(sample_mask, unsigned, sample_mask, sample_mask) 356bf215546Sopenharmony_ciDD_IMM_STATE(min_samples, unsigned, min_samples, min_samples) 357bf215546Sopenharmony_ciDD_IMM_STATE(framebuffer_state, const struct pipe_framebuffer_state, *state, state) 358bf215546Sopenharmony_ciDD_IMM_STATE(polygon_stipple, const struct pipe_poly_stipple, *state, state) 359bf215546Sopenharmony_ci 360bf215546Sopenharmony_cistatic void 361bf215546Sopenharmony_cidd_context_set_constant_buffer(struct pipe_context *_pipe, 362bf215546Sopenharmony_ci enum pipe_shader_type shader, uint index, 363bf215546Sopenharmony_ci bool take_ownership, 364bf215546Sopenharmony_ci const struct pipe_constant_buffer *constant_buffer) 365bf215546Sopenharmony_ci{ 366bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 367bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.constant_buffers[shader][index], 370bf215546Sopenharmony_ci constant_buffer, sizeof(*constant_buffer)); 371bf215546Sopenharmony_ci pipe->set_constant_buffer(pipe, shader, index, take_ownership, constant_buffer); 372bf215546Sopenharmony_ci} 373bf215546Sopenharmony_ci 374bf215546Sopenharmony_cistatic void 375bf215546Sopenharmony_cidd_context_set_scissor_states(struct pipe_context *_pipe, 376bf215546Sopenharmony_ci unsigned start_slot, unsigned num_scissors, 377bf215546Sopenharmony_ci const struct pipe_scissor_state *states) 378bf215546Sopenharmony_ci{ 379bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 380bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 381bf215546Sopenharmony_ci 382bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.scissors[start_slot], states, 383bf215546Sopenharmony_ci sizeof(*states) * num_scissors); 384bf215546Sopenharmony_ci pipe->set_scissor_states(pipe, start_slot, num_scissors, states); 385bf215546Sopenharmony_ci} 386bf215546Sopenharmony_ci 387bf215546Sopenharmony_cistatic void 388bf215546Sopenharmony_cidd_context_set_viewport_states(struct pipe_context *_pipe, 389bf215546Sopenharmony_ci unsigned start_slot, unsigned num_viewports, 390bf215546Sopenharmony_ci const struct pipe_viewport_state *states) 391bf215546Sopenharmony_ci{ 392bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 393bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 394bf215546Sopenharmony_ci 395bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.viewports[start_slot], states, 396bf215546Sopenharmony_ci sizeof(*states) * num_viewports); 397bf215546Sopenharmony_ci pipe->set_viewport_states(pipe, start_slot, num_viewports, states); 398bf215546Sopenharmony_ci} 399bf215546Sopenharmony_ci 400bf215546Sopenharmony_cistatic void dd_context_set_tess_state(struct pipe_context *_pipe, 401bf215546Sopenharmony_ci const float default_outer_level[4], 402bf215546Sopenharmony_ci const float default_inner_level[2]) 403bf215546Sopenharmony_ci{ 404bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 405bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 406bf215546Sopenharmony_ci 407bf215546Sopenharmony_ci memcpy(dctx->draw_state.tess_default_levels, default_outer_level, 408bf215546Sopenharmony_ci sizeof(float) * 4); 409bf215546Sopenharmony_ci memcpy(dctx->draw_state.tess_default_levels+4, default_inner_level, 410bf215546Sopenharmony_ci sizeof(float) * 2); 411bf215546Sopenharmony_ci pipe->set_tess_state(pipe, default_outer_level, default_inner_level); 412bf215546Sopenharmony_ci} 413bf215546Sopenharmony_ci 414bf215546Sopenharmony_cistatic void dd_context_set_patch_vertices(struct pipe_context *_pipe, 415bf215546Sopenharmony_ci uint8_t patch_vertices) 416bf215546Sopenharmony_ci{ 417bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 418bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 419bf215546Sopenharmony_ci 420bf215546Sopenharmony_ci pipe->set_patch_vertices(pipe, patch_vertices); 421bf215546Sopenharmony_ci} 422bf215546Sopenharmony_ci 423bf215546Sopenharmony_cistatic void dd_context_set_window_rectangles(struct pipe_context *_pipe, 424bf215546Sopenharmony_ci bool include, 425bf215546Sopenharmony_ci unsigned num_rectangles, 426bf215546Sopenharmony_ci const struct pipe_scissor_state *rects) 427bf215546Sopenharmony_ci{ 428bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 429bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 430bf215546Sopenharmony_ci 431bf215546Sopenharmony_ci pipe->set_window_rectangles(pipe, include, num_rectangles, rects); 432bf215546Sopenharmony_ci} 433bf215546Sopenharmony_ci 434bf215546Sopenharmony_ci 435bf215546Sopenharmony_ci/******************************************************************** 436bf215546Sopenharmony_ci * views 437bf215546Sopenharmony_ci */ 438bf215546Sopenharmony_ci 439bf215546Sopenharmony_cistatic struct pipe_surface * 440bf215546Sopenharmony_cidd_context_create_surface(struct pipe_context *_pipe, 441bf215546Sopenharmony_ci struct pipe_resource *resource, 442bf215546Sopenharmony_ci const struct pipe_surface *surf_tmpl) 443bf215546Sopenharmony_ci{ 444bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 445bf215546Sopenharmony_ci struct pipe_surface *view = 446bf215546Sopenharmony_ci pipe->create_surface(pipe, resource, surf_tmpl); 447bf215546Sopenharmony_ci 448bf215546Sopenharmony_ci if (!view) 449bf215546Sopenharmony_ci return NULL; 450bf215546Sopenharmony_ci view->context = _pipe; 451bf215546Sopenharmony_ci return view; 452bf215546Sopenharmony_ci} 453bf215546Sopenharmony_ci 454bf215546Sopenharmony_cistatic void 455bf215546Sopenharmony_cidd_context_surface_destroy(struct pipe_context *_pipe, 456bf215546Sopenharmony_ci struct pipe_surface *surf) 457bf215546Sopenharmony_ci{ 458bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 459bf215546Sopenharmony_ci 460bf215546Sopenharmony_ci pipe->surface_destroy(pipe, surf); 461bf215546Sopenharmony_ci} 462bf215546Sopenharmony_ci 463bf215546Sopenharmony_cistatic struct pipe_sampler_view * 464bf215546Sopenharmony_cidd_context_create_sampler_view(struct pipe_context *_pipe, 465bf215546Sopenharmony_ci struct pipe_resource *resource, 466bf215546Sopenharmony_ci const struct pipe_sampler_view *templ) 467bf215546Sopenharmony_ci{ 468bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 469bf215546Sopenharmony_ci struct pipe_sampler_view *view = 470bf215546Sopenharmony_ci pipe->create_sampler_view(pipe, resource, templ); 471bf215546Sopenharmony_ci 472bf215546Sopenharmony_ci if (!view) 473bf215546Sopenharmony_ci return NULL; 474bf215546Sopenharmony_ci view->context = _pipe; 475bf215546Sopenharmony_ci return view; 476bf215546Sopenharmony_ci} 477bf215546Sopenharmony_ci 478bf215546Sopenharmony_cistatic void 479bf215546Sopenharmony_cidd_context_sampler_view_destroy(struct pipe_context *_pipe, 480bf215546Sopenharmony_ci struct pipe_sampler_view *view) 481bf215546Sopenharmony_ci{ 482bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 483bf215546Sopenharmony_ci 484bf215546Sopenharmony_ci pipe->sampler_view_destroy(pipe, view); 485bf215546Sopenharmony_ci} 486bf215546Sopenharmony_ci 487bf215546Sopenharmony_cistatic struct pipe_stream_output_target * 488bf215546Sopenharmony_cidd_context_create_stream_output_target(struct pipe_context *_pipe, 489bf215546Sopenharmony_ci struct pipe_resource *res, 490bf215546Sopenharmony_ci unsigned buffer_offset, 491bf215546Sopenharmony_ci unsigned buffer_size) 492bf215546Sopenharmony_ci{ 493bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 494bf215546Sopenharmony_ci struct pipe_stream_output_target *view = 495bf215546Sopenharmony_ci pipe->create_stream_output_target(pipe, res, buffer_offset, 496bf215546Sopenharmony_ci buffer_size); 497bf215546Sopenharmony_ci 498bf215546Sopenharmony_ci if (!view) 499bf215546Sopenharmony_ci return NULL; 500bf215546Sopenharmony_ci view->context = _pipe; 501bf215546Sopenharmony_ci return view; 502bf215546Sopenharmony_ci} 503bf215546Sopenharmony_ci 504bf215546Sopenharmony_cistatic void 505bf215546Sopenharmony_cidd_context_stream_output_target_destroy(struct pipe_context *_pipe, 506bf215546Sopenharmony_ci struct pipe_stream_output_target *target) 507bf215546Sopenharmony_ci{ 508bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 509bf215546Sopenharmony_ci 510bf215546Sopenharmony_ci pipe->stream_output_target_destroy(pipe, target); 511bf215546Sopenharmony_ci} 512bf215546Sopenharmony_ci 513bf215546Sopenharmony_ci 514bf215546Sopenharmony_ci/******************************************************************** 515bf215546Sopenharmony_ci * set states 516bf215546Sopenharmony_ci */ 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_cistatic void 519bf215546Sopenharmony_cidd_context_set_sampler_views(struct pipe_context *_pipe, 520bf215546Sopenharmony_ci enum pipe_shader_type shader, 521bf215546Sopenharmony_ci unsigned start, unsigned num, 522bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 523bf215546Sopenharmony_ci bool take_ownership, 524bf215546Sopenharmony_ci struct pipe_sampler_view **views) 525bf215546Sopenharmony_ci{ 526bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 527bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 528bf215546Sopenharmony_ci 529bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.sampler_views[shader][start], views, 530bf215546Sopenharmony_ci sizeof(views[0]) * num); 531bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.sampler_views[shader][start + num], views, 532bf215546Sopenharmony_ci sizeof(views[0]) * unbind_num_trailing_slots); 533bf215546Sopenharmony_ci pipe->set_sampler_views(pipe, shader, start, num, take_ownership, 534bf215546Sopenharmony_ci unbind_num_trailing_slots, views); 535bf215546Sopenharmony_ci} 536bf215546Sopenharmony_ci 537bf215546Sopenharmony_cistatic void 538bf215546Sopenharmony_cidd_context_set_shader_images(struct pipe_context *_pipe, 539bf215546Sopenharmony_ci enum pipe_shader_type shader, 540bf215546Sopenharmony_ci unsigned start, unsigned num, 541bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 542bf215546Sopenharmony_ci const struct pipe_image_view *views) 543bf215546Sopenharmony_ci{ 544bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 545bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 546bf215546Sopenharmony_ci 547bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.shader_images[shader][start], views, 548bf215546Sopenharmony_ci sizeof(views[0]) * num); 549bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.shader_images[shader][start + num], NULL, 550bf215546Sopenharmony_ci sizeof(views[0]) * unbind_num_trailing_slots); 551bf215546Sopenharmony_ci pipe->set_shader_images(pipe, shader, start, num, 552bf215546Sopenharmony_ci unbind_num_trailing_slots, views); 553bf215546Sopenharmony_ci} 554bf215546Sopenharmony_ci 555bf215546Sopenharmony_cistatic void 556bf215546Sopenharmony_cidd_context_set_shader_buffers(struct pipe_context *_pipe, 557bf215546Sopenharmony_ci enum pipe_shader_type shader, 558bf215546Sopenharmony_ci unsigned start, unsigned num_buffers, 559bf215546Sopenharmony_ci const struct pipe_shader_buffer *buffers, 560bf215546Sopenharmony_ci unsigned writable_bitmask) 561bf215546Sopenharmony_ci{ 562bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 563bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 564bf215546Sopenharmony_ci 565bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.shader_buffers[shader][start], buffers, 566bf215546Sopenharmony_ci sizeof(buffers[0]) * num_buffers); 567bf215546Sopenharmony_ci pipe->set_shader_buffers(pipe, shader, start, num_buffers, buffers, 568bf215546Sopenharmony_ci writable_bitmask); 569bf215546Sopenharmony_ci} 570bf215546Sopenharmony_ci 571bf215546Sopenharmony_cistatic void 572bf215546Sopenharmony_cidd_context_set_vertex_buffers(struct pipe_context *_pipe, 573bf215546Sopenharmony_ci unsigned start, unsigned num_buffers, 574bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 575bf215546Sopenharmony_ci bool take_ownership, 576bf215546Sopenharmony_ci const struct pipe_vertex_buffer *buffers) 577bf215546Sopenharmony_ci{ 578bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 579bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 580bf215546Sopenharmony_ci 581bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.vertex_buffers[start], buffers, 582bf215546Sopenharmony_ci sizeof(buffers[0]) * num_buffers); 583bf215546Sopenharmony_ci safe_memcpy(&dctx->draw_state.vertex_buffers[start + num_buffers], NULL, 584bf215546Sopenharmony_ci sizeof(buffers[0]) * unbind_num_trailing_slots); 585bf215546Sopenharmony_ci pipe->set_vertex_buffers(pipe, start, num_buffers, 586bf215546Sopenharmony_ci unbind_num_trailing_slots, take_ownership, 587bf215546Sopenharmony_ci buffers); 588bf215546Sopenharmony_ci} 589bf215546Sopenharmony_ci 590bf215546Sopenharmony_cistatic void 591bf215546Sopenharmony_cidd_context_set_stream_output_targets(struct pipe_context *_pipe, 592bf215546Sopenharmony_ci unsigned num_targets, 593bf215546Sopenharmony_ci struct pipe_stream_output_target **tgs, 594bf215546Sopenharmony_ci const unsigned *offsets) 595bf215546Sopenharmony_ci{ 596bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 597bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 598bf215546Sopenharmony_ci struct dd_draw_state *dstate = &dctx->draw_state; 599bf215546Sopenharmony_ci 600bf215546Sopenharmony_ci dstate->num_so_targets = num_targets; 601bf215546Sopenharmony_ci safe_memcpy(dstate->so_targets, tgs, sizeof(*tgs) * num_targets); 602bf215546Sopenharmony_ci safe_memcpy(dstate->so_offsets, offsets, sizeof(*offsets) * num_targets); 603bf215546Sopenharmony_ci pipe->set_stream_output_targets(pipe, num_targets, tgs, offsets); 604bf215546Sopenharmony_ci} 605bf215546Sopenharmony_ci 606bf215546Sopenharmony_ci 607bf215546Sopenharmony_cistatic void 608bf215546Sopenharmony_cidd_context_fence_server_sync(struct pipe_context *_pipe, 609bf215546Sopenharmony_ci struct pipe_fence_handle *fence) 610bf215546Sopenharmony_ci{ 611bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 612bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 613bf215546Sopenharmony_ci 614bf215546Sopenharmony_ci pipe->fence_server_sync(pipe, fence); 615bf215546Sopenharmony_ci} 616bf215546Sopenharmony_ci 617bf215546Sopenharmony_ci 618bf215546Sopenharmony_cistatic void 619bf215546Sopenharmony_cidd_context_create_fence_fd(struct pipe_context *_pipe, 620bf215546Sopenharmony_ci struct pipe_fence_handle **fence, 621bf215546Sopenharmony_ci int fd, 622bf215546Sopenharmony_ci enum pipe_fd_type type) 623bf215546Sopenharmony_ci{ 624bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 625bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 626bf215546Sopenharmony_ci 627bf215546Sopenharmony_ci pipe->create_fence_fd(pipe, fence, fd, type); 628bf215546Sopenharmony_ci} 629bf215546Sopenharmony_ci 630bf215546Sopenharmony_ci 631bf215546Sopenharmony_civoid 632bf215546Sopenharmony_cidd_thread_join(struct dd_context *dctx) 633bf215546Sopenharmony_ci{ 634bf215546Sopenharmony_ci mtx_lock(&dctx->mutex); 635bf215546Sopenharmony_ci dctx->kill_thread = true; 636bf215546Sopenharmony_ci cnd_signal(&dctx->cond); 637bf215546Sopenharmony_ci mtx_unlock(&dctx->mutex); 638bf215546Sopenharmony_ci thrd_join(dctx->thread, NULL); 639bf215546Sopenharmony_ci} 640bf215546Sopenharmony_ci 641bf215546Sopenharmony_cistatic void 642bf215546Sopenharmony_cidd_context_destroy(struct pipe_context *_pipe) 643bf215546Sopenharmony_ci{ 644bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 645bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 646bf215546Sopenharmony_ci 647bf215546Sopenharmony_ci dd_thread_join(dctx); 648bf215546Sopenharmony_ci mtx_destroy(&dctx->mutex); 649bf215546Sopenharmony_ci cnd_destroy(&dctx->cond); 650bf215546Sopenharmony_ci 651bf215546Sopenharmony_ci assert(list_is_empty(&dctx->records)); 652bf215546Sopenharmony_ci 653bf215546Sopenharmony_ci if (pipe->set_log_context) { 654bf215546Sopenharmony_ci pipe->set_log_context(pipe, NULL); 655bf215546Sopenharmony_ci 656bf215546Sopenharmony_ci if (dd_screen(dctx->base.screen)->dump_mode == DD_DUMP_ALL_CALLS) { 657bf215546Sopenharmony_ci FILE *f = dd_get_file_stream(dd_screen(dctx->base.screen), 0); 658bf215546Sopenharmony_ci if (f) { 659bf215546Sopenharmony_ci fprintf(f, "Remainder of driver log:\n\n"); 660bf215546Sopenharmony_ci } 661bf215546Sopenharmony_ci 662bf215546Sopenharmony_ci u_log_new_page_print(&dctx->log, f); 663bf215546Sopenharmony_ci fclose(f); 664bf215546Sopenharmony_ci } 665bf215546Sopenharmony_ci } 666bf215546Sopenharmony_ci u_log_context_destroy(&dctx->log); 667bf215546Sopenharmony_ci 668bf215546Sopenharmony_ci pipe->destroy(pipe); 669bf215546Sopenharmony_ci FREE(dctx); 670bf215546Sopenharmony_ci} 671bf215546Sopenharmony_ci 672bf215546Sopenharmony_ci 673bf215546Sopenharmony_ci/******************************************************************** 674bf215546Sopenharmony_ci * miscellaneous 675bf215546Sopenharmony_ci */ 676bf215546Sopenharmony_ci 677bf215546Sopenharmony_cistatic void 678bf215546Sopenharmony_cidd_context_texture_barrier(struct pipe_context *_pipe, unsigned flags) 679bf215546Sopenharmony_ci{ 680bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 681bf215546Sopenharmony_ci 682bf215546Sopenharmony_ci pipe->texture_barrier(pipe, flags); 683bf215546Sopenharmony_ci} 684bf215546Sopenharmony_ci 685bf215546Sopenharmony_cistatic void 686bf215546Sopenharmony_cidd_context_memory_barrier(struct pipe_context *_pipe, unsigned flags) 687bf215546Sopenharmony_ci{ 688bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 689bf215546Sopenharmony_ci 690bf215546Sopenharmony_ci pipe->memory_barrier(pipe, flags); 691bf215546Sopenharmony_ci} 692bf215546Sopenharmony_ci 693bf215546Sopenharmony_cistatic bool 694bf215546Sopenharmony_cidd_context_resource_commit(struct pipe_context *_pipe, 695bf215546Sopenharmony_ci struct pipe_resource *resource, 696bf215546Sopenharmony_ci unsigned level, struct pipe_box *box, bool commit) 697bf215546Sopenharmony_ci{ 698bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 699bf215546Sopenharmony_ci 700bf215546Sopenharmony_ci return pipe->resource_commit(pipe, resource, level, box, commit); 701bf215546Sopenharmony_ci} 702bf215546Sopenharmony_ci 703bf215546Sopenharmony_cistatic void 704bf215546Sopenharmony_cidd_context_set_compute_resources(struct pipe_context *_pipe, 705bf215546Sopenharmony_ci unsigned start, unsigned count, 706bf215546Sopenharmony_ci struct pipe_surface **resources) 707bf215546Sopenharmony_ci{ 708bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 709bf215546Sopenharmony_ci pipe->set_compute_resources(pipe, start, count, resources); 710bf215546Sopenharmony_ci} 711bf215546Sopenharmony_ci 712bf215546Sopenharmony_cistatic void 713bf215546Sopenharmony_cidd_context_set_global_binding(struct pipe_context *_pipe, 714bf215546Sopenharmony_ci unsigned first, unsigned count, 715bf215546Sopenharmony_ci struct pipe_resource **resources, 716bf215546Sopenharmony_ci uint32_t **handles) 717bf215546Sopenharmony_ci{ 718bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 719bf215546Sopenharmony_ci pipe->set_global_binding(pipe, first, count, resources, handles); 720bf215546Sopenharmony_ci} 721bf215546Sopenharmony_ci 722bf215546Sopenharmony_cistatic void 723bf215546Sopenharmony_cidd_context_get_sample_position(struct pipe_context *_pipe, 724bf215546Sopenharmony_ci unsigned sample_count, unsigned sample_index, 725bf215546Sopenharmony_ci float *out_value) 726bf215546Sopenharmony_ci{ 727bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 728bf215546Sopenharmony_ci 729bf215546Sopenharmony_ci pipe->get_sample_position(pipe, sample_count, sample_index, 730bf215546Sopenharmony_ci out_value); 731bf215546Sopenharmony_ci} 732bf215546Sopenharmony_ci 733bf215546Sopenharmony_cistatic void 734bf215546Sopenharmony_cidd_context_invalidate_resource(struct pipe_context *_pipe, 735bf215546Sopenharmony_ci struct pipe_resource *resource) 736bf215546Sopenharmony_ci{ 737bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 738bf215546Sopenharmony_ci 739bf215546Sopenharmony_ci pipe->invalidate_resource(pipe, resource); 740bf215546Sopenharmony_ci} 741bf215546Sopenharmony_ci 742bf215546Sopenharmony_cistatic enum pipe_reset_status 743bf215546Sopenharmony_cidd_context_get_device_reset_status(struct pipe_context *_pipe) 744bf215546Sopenharmony_ci{ 745bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 746bf215546Sopenharmony_ci 747bf215546Sopenharmony_ci return pipe->get_device_reset_status(pipe); 748bf215546Sopenharmony_ci} 749bf215546Sopenharmony_ci 750bf215546Sopenharmony_cistatic void 751bf215546Sopenharmony_cidd_context_set_device_reset_callback(struct pipe_context *_pipe, 752bf215546Sopenharmony_ci const struct pipe_device_reset_callback *cb) 753bf215546Sopenharmony_ci{ 754bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 755bf215546Sopenharmony_ci 756bf215546Sopenharmony_ci pipe->set_device_reset_callback(pipe, cb); 757bf215546Sopenharmony_ci} 758bf215546Sopenharmony_ci 759bf215546Sopenharmony_cistatic void 760bf215546Sopenharmony_cidd_context_emit_string_marker(struct pipe_context *_pipe, 761bf215546Sopenharmony_ci const char *string, int len) 762bf215546Sopenharmony_ci{ 763bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 764bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 765bf215546Sopenharmony_ci 766bf215546Sopenharmony_ci pipe->emit_string_marker(pipe, string, len); 767bf215546Sopenharmony_ci dd_parse_apitrace_marker(string, len, &dctx->draw_state.apitrace_call_number); 768bf215546Sopenharmony_ci} 769bf215546Sopenharmony_ci 770bf215546Sopenharmony_cistatic void 771bf215546Sopenharmony_cidd_context_dump_debug_state(struct pipe_context *_pipe, FILE *stream, 772bf215546Sopenharmony_ci unsigned flags) 773bf215546Sopenharmony_ci{ 774bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 775bf215546Sopenharmony_ci 776bf215546Sopenharmony_ci pipe->dump_debug_state(pipe, stream, flags); 777bf215546Sopenharmony_ci} 778bf215546Sopenharmony_ci 779bf215546Sopenharmony_cistatic uint64_t 780bf215546Sopenharmony_cidd_context_create_texture_handle(struct pipe_context *_pipe, 781bf215546Sopenharmony_ci struct pipe_sampler_view *view, 782bf215546Sopenharmony_ci const struct pipe_sampler_state *state) 783bf215546Sopenharmony_ci{ 784bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 785bf215546Sopenharmony_ci 786bf215546Sopenharmony_ci return pipe->create_texture_handle(pipe, view, state); 787bf215546Sopenharmony_ci} 788bf215546Sopenharmony_ci 789bf215546Sopenharmony_cistatic void 790bf215546Sopenharmony_cidd_context_delete_texture_handle(struct pipe_context *_pipe, uint64_t handle) 791bf215546Sopenharmony_ci{ 792bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 793bf215546Sopenharmony_ci 794bf215546Sopenharmony_ci pipe->delete_texture_handle(pipe, handle); 795bf215546Sopenharmony_ci} 796bf215546Sopenharmony_ci 797bf215546Sopenharmony_cistatic void 798bf215546Sopenharmony_cidd_context_make_texture_handle_resident(struct pipe_context *_pipe, 799bf215546Sopenharmony_ci uint64_t handle, bool resident) 800bf215546Sopenharmony_ci{ 801bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 802bf215546Sopenharmony_ci 803bf215546Sopenharmony_ci pipe->make_texture_handle_resident(pipe, handle, resident); 804bf215546Sopenharmony_ci} 805bf215546Sopenharmony_ci 806bf215546Sopenharmony_cistatic uint64_t 807bf215546Sopenharmony_cidd_context_create_image_handle(struct pipe_context *_pipe, 808bf215546Sopenharmony_ci const struct pipe_image_view *image) 809bf215546Sopenharmony_ci{ 810bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 811bf215546Sopenharmony_ci 812bf215546Sopenharmony_ci return pipe->create_image_handle(pipe, image); 813bf215546Sopenharmony_ci} 814bf215546Sopenharmony_ci 815bf215546Sopenharmony_cistatic void 816bf215546Sopenharmony_cidd_context_delete_image_handle(struct pipe_context *_pipe, uint64_t handle) 817bf215546Sopenharmony_ci{ 818bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 819bf215546Sopenharmony_ci 820bf215546Sopenharmony_ci pipe->delete_image_handle(pipe, handle); 821bf215546Sopenharmony_ci} 822bf215546Sopenharmony_ci 823bf215546Sopenharmony_cistatic void 824bf215546Sopenharmony_cidd_context_make_image_handle_resident(struct pipe_context *_pipe, 825bf215546Sopenharmony_ci uint64_t handle, unsigned access, 826bf215546Sopenharmony_ci bool resident) 827bf215546Sopenharmony_ci{ 828bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 829bf215546Sopenharmony_ci 830bf215546Sopenharmony_ci pipe->make_image_handle_resident(pipe, handle, access, resident); 831bf215546Sopenharmony_ci} 832bf215546Sopenharmony_ci 833bf215546Sopenharmony_cistatic void 834bf215546Sopenharmony_cidd_context_set_context_param(struct pipe_context *_pipe, 835bf215546Sopenharmony_ci enum pipe_context_param param, 836bf215546Sopenharmony_ci unsigned value) 837bf215546Sopenharmony_ci{ 838bf215546Sopenharmony_ci struct pipe_context *pipe = dd_context(_pipe)->pipe; 839bf215546Sopenharmony_ci 840bf215546Sopenharmony_ci pipe->set_context_param(pipe, param, value); 841bf215546Sopenharmony_ci} 842bf215546Sopenharmony_ci 843bf215546Sopenharmony_cistruct pipe_context * 844bf215546Sopenharmony_cidd_context_create(struct dd_screen *dscreen, struct pipe_context *pipe) 845bf215546Sopenharmony_ci{ 846bf215546Sopenharmony_ci struct dd_context *dctx; 847bf215546Sopenharmony_ci 848bf215546Sopenharmony_ci if (!pipe) 849bf215546Sopenharmony_ci return NULL; 850bf215546Sopenharmony_ci 851bf215546Sopenharmony_ci dctx = CALLOC_STRUCT(dd_context); 852bf215546Sopenharmony_ci if (!dctx) 853bf215546Sopenharmony_ci goto fail; 854bf215546Sopenharmony_ci 855bf215546Sopenharmony_ci dctx->pipe = pipe; 856bf215546Sopenharmony_ci dctx->base.priv = pipe->priv; /* expose wrapped priv data */ 857bf215546Sopenharmony_ci dctx->base.screen = &dscreen->base; 858bf215546Sopenharmony_ci dctx->base.stream_uploader = pipe->stream_uploader; 859bf215546Sopenharmony_ci dctx->base.const_uploader = pipe->const_uploader; 860bf215546Sopenharmony_ci 861bf215546Sopenharmony_ci dctx->base.destroy = dd_context_destroy; 862bf215546Sopenharmony_ci 863bf215546Sopenharmony_ci CTX_INIT(render_condition); 864bf215546Sopenharmony_ci CTX_INIT(create_query); 865bf215546Sopenharmony_ci CTX_INIT(create_batch_query); 866bf215546Sopenharmony_ci CTX_INIT(destroy_query); 867bf215546Sopenharmony_ci CTX_INIT(begin_query); 868bf215546Sopenharmony_ci CTX_INIT(end_query); 869bf215546Sopenharmony_ci CTX_INIT(get_query_result); 870bf215546Sopenharmony_ci CTX_INIT(set_active_query_state); 871bf215546Sopenharmony_ci CTX_INIT(create_blend_state); 872bf215546Sopenharmony_ci CTX_INIT(bind_blend_state); 873bf215546Sopenharmony_ci CTX_INIT(delete_blend_state); 874bf215546Sopenharmony_ci CTX_INIT(create_sampler_state); 875bf215546Sopenharmony_ci CTX_INIT(bind_sampler_states); 876bf215546Sopenharmony_ci CTX_INIT(delete_sampler_state); 877bf215546Sopenharmony_ci CTX_INIT(create_rasterizer_state); 878bf215546Sopenharmony_ci CTX_INIT(bind_rasterizer_state); 879bf215546Sopenharmony_ci CTX_INIT(delete_rasterizer_state); 880bf215546Sopenharmony_ci CTX_INIT(create_depth_stencil_alpha_state); 881bf215546Sopenharmony_ci CTX_INIT(bind_depth_stencil_alpha_state); 882bf215546Sopenharmony_ci CTX_INIT(delete_depth_stencil_alpha_state); 883bf215546Sopenharmony_ci CTX_INIT(create_fs_state); 884bf215546Sopenharmony_ci CTX_INIT(bind_fs_state); 885bf215546Sopenharmony_ci CTX_INIT(delete_fs_state); 886bf215546Sopenharmony_ci CTX_INIT(create_vs_state); 887bf215546Sopenharmony_ci CTX_INIT(bind_vs_state); 888bf215546Sopenharmony_ci CTX_INIT(delete_vs_state); 889bf215546Sopenharmony_ci CTX_INIT(create_gs_state); 890bf215546Sopenharmony_ci CTX_INIT(bind_gs_state); 891bf215546Sopenharmony_ci CTX_INIT(delete_gs_state); 892bf215546Sopenharmony_ci CTX_INIT(create_tcs_state); 893bf215546Sopenharmony_ci CTX_INIT(bind_tcs_state); 894bf215546Sopenharmony_ci CTX_INIT(delete_tcs_state); 895bf215546Sopenharmony_ci CTX_INIT(create_tes_state); 896bf215546Sopenharmony_ci CTX_INIT(bind_tes_state); 897bf215546Sopenharmony_ci CTX_INIT(delete_tes_state); 898bf215546Sopenharmony_ci CTX_INIT(create_compute_state); 899bf215546Sopenharmony_ci CTX_INIT(bind_compute_state); 900bf215546Sopenharmony_ci CTX_INIT(delete_compute_state); 901bf215546Sopenharmony_ci CTX_INIT(create_vertex_elements_state); 902bf215546Sopenharmony_ci CTX_INIT(bind_vertex_elements_state); 903bf215546Sopenharmony_ci CTX_INIT(delete_vertex_elements_state); 904bf215546Sopenharmony_ci CTX_INIT(set_blend_color); 905bf215546Sopenharmony_ci CTX_INIT(set_stencil_ref); 906bf215546Sopenharmony_ci CTX_INIT(set_sample_mask); 907bf215546Sopenharmony_ci CTX_INIT(set_min_samples); 908bf215546Sopenharmony_ci CTX_INIT(set_clip_state); 909bf215546Sopenharmony_ci CTX_INIT(set_constant_buffer); 910bf215546Sopenharmony_ci CTX_INIT(set_framebuffer_state); 911bf215546Sopenharmony_ci CTX_INIT(set_polygon_stipple); 912bf215546Sopenharmony_ci CTX_INIT(set_scissor_states); 913bf215546Sopenharmony_ci CTX_INIT(set_viewport_states); 914bf215546Sopenharmony_ci CTX_INIT(set_sampler_views); 915bf215546Sopenharmony_ci CTX_INIT(set_tess_state); 916bf215546Sopenharmony_ci CTX_INIT(set_patch_vertices); 917bf215546Sopenharmony_ci CTX_INIT(set_shader_buffers); 918bf215546Sopenharmony_ci CTX_INIT(set_shader_images); 919bf215546Sopenharmony_ci CTX_INIT(set_vertex_buffers); 920bf215546Sopenharmony_ci CTX_INIT(set_window_rectangles); 921bf215546Sopenharmony_ci CTX_INIT(create_stream_output_target); 922bf215546Sopenharmony_ci CTX_INIT(stream_output_target_destroy); 923bf215546Sopenharmony_ci CTX_INIT(set_stream_output_targets); 924bf215546Sopenharmony_ci CTX_INIT(create_fence_fd); 925bf215546Sopenharmony_ci CTX_INIT(fence_server_sync); 926bf215546Sopenharmony_ci CTX_INIT(create_sampler_view); 927bf215546Sopenharmony_ci CTX_INIT(sampler_view_destroy); 928bf215546Sopenharmony_ci CTX_INIT(create_surface); 929bf215546Sopenharmony_ci CTX_INIT(surface_destroy); 930bf215546Sopenharmony_ci CTX_INIT(texture_barrier); 931bf215546Sopenharmony_ci CTX_INIT(memory_barrier); 932bf215546Sopenharmony_ci CTX_INIT(resource_commit); 933bf215546Sopenharmony_ci CTX_INIT(set_compute_resources); 934bf215546Sopenharmony_ci CTX_INIT(set_global_binding); 935bf215546Sopenharmony_ci /* create_video_codec */ 936bf215546Sopenharmony_ci /* create_video_buffer */ 937bf215546Sopenharmony_ci CTX_INIT(get_sample_position); 938bf215546Sopenharmony_ci CTX_INIT(invalidate_resource); 939bf215546Sopenharmony_ci CTX_INIT(get_device_reset_status); 940bf215546Sopenharmony_ci CTX_INIT(set_device_reset_callback); 941bf215546Sopenharmony_ci CTX_INIT(dump_debug_state); 942bf215546Sopenharmony_ci CTX_INIT(emit_string_marker); 943bf215546Sopenharmony_ci CTX_INIT(create_texture_handle); 944bf215546Sopenharmony_ci CTX_INIT(delete_texture_handle); 945bf215546Sopenharmony_ci CTX_INIT(make_texture_handle_resident); 946bf215546Sopenharmony_ci CTX_INIT(create_image_handle); 947bf215546Sopenharmony_ci CTX_INIT(delete_image_handle); 948bf215546Sopenharmony_ci CTX_INIT(make_image_handle_resident); 949bf215546Sopenharmony_ci CTX_INIT(set_context_param); 950bf215546Sopenharmony_ci 951bf215546Sopenharmony_ci dd_init_draw_functions(dctx); 952bf215546Sopenharmony_ci 953bf215546Sopenharmony_ci u_log_context_init(&dctx->log); 954bf215546Sopenharmony_ci if (pipe->set_log_context) 955bf215546Sopenharmony_ci pipe->set_log_context(pipe, &dctx->log); 956bf215546Sopenharmony_ci 957bf215546Sopenharmony_ci dctx->draw_state.sample_mask = ~0; 958bf215546Sopenharmony_ci 959bf215546Sopenharmony_ci list_inithead(&dctx->records); 960bf215546Sopenharmony_ci (void) mtx_init(&dctx->mutex, mtx_plain); 961bf215546Sopenharmony_ci (void) cnd_init(&dctx->cond); 962bf215546Sopenharmony_ci if (thrd_success != u_thread_create(&dctx->thread,dd_thread_main, dctx)) { 963bf215546Sopenharmony_ci mtx_destroy(&dctx->mutex); 964bf215546Sopenharmony_ci goto fail; 965bf215546Sopenharmony_ci } 966bf215546Sopenharmony_ci 967bf215546Sopenharmony_ci return &dctx->base; 968bf215546Sopenharmony_ci 969bf215546Sopenharmony_cifail: 970bf215546Sopenharmony_ci FREE(dctx); 971bf215546Sopenharmony_ci pipe->destroy(pipe); 972bf215546Sopenharmony_ci return NULL; 973bf215546Sopenharmony_ci} 974