Path: blob/21.2-virgl/src/gallium/auxiliary/driver_ddebug/dd_context.c
4561 views
/**************************************************************************1*2* Copyright 2015 Advanced Micro Devices, Inc.3* Copyright 2008 VMware, Inc.4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the "Software"),8* to deal in the Software without restriction, including without limitation9* on the rights to use, copy, modify, merge, publish, distribute, sub10* license, and/or sell copies of the Software, and to permit persons to whom11* the Software is furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice (including the next14* paragraph) shall be included in all copies or substantial portions of the15* Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL20* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,21* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR22* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE23* USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "dd_pipe.h"28#include "tgsi/tgsi_parse.h"29#include "util/u_inlines.h"30#include "util/u_memory.h"313233static void34safe_memcpy(void *dst, const void *src, size_t size)35{36if (src)37memcpy(dst, src, size);38else39memset(dst, 0, size);40}414243/********************************************************************44* queries45*/4647static struct pipe_query *48dd_context_create_query(struct pipe_context *_pipe, unsigned query_type,49unsigned index)50{51struct pipe_context *pipe = dd_context(_pipe)->pipe;52struct pipe_query *query;5354query = pipe->create_query(pipe, query_type, index);5556/* Wrap query object. */57if (query) {58struct dd_query *dd_query = CALLOC_STRUCT(dd_query);59if (dd_query) {60dd_query->type = query_type;61dd_query->query = query;62query = (struct pipe_query *)dd_query;63} else {64pipe->destroy_query(pipe, query);65query = NULL;66}67}6869return query;70}7172static struct pipe_query *73dd_context_create_batch_query(struct pipe_context *_pipe, unsigned num_queries,74unsigned *query_types)75{76struct pipe_context *pipe = dd_context(_pipe)->pipe;77struct pipe_query *query;7879query = pipe->create_batch_query(pipe, num_queries, query_types);8081/* Wrap query object. */82if (query) {83struct dd_query *dd_query = CALLOC_STRUCT(dd_query);84if (dd_query) {85/* no special handling for batch queries yet */86dd_query->type = query_types[0];87dd_query->query = query;88query = (struct pipe_query *)dd_query;89} else {90pipe->destroy_query(pipe, query);91query = NULL;92}93}9495return query;96}9798static void99dd_context_destroy_query(struct pipe_context *_pipe,100struct pipe_query *query)101{102struct pipe_context *pipe = dd_context(_pipe)->pipe;103104pipe->destroy_query(pipe, dd_query_unwrap(query));105FREE(query);106}107108static bool109dd_context_begin_query(struct pipe_context *_pipe, struct pipe_query *query)110{111struct dd_context *dctx = dd_context(_pipe);112struct pipe_context *pipe = dctx->pipe;113114return pipe->begin_query(pipe, dd_query_unwrap(query));115}116117static bool118dd_context_end_query(struct pipe_context *_pipe, struct pipe_query *query)119{120struct dd_context *dctx = dd_context(_pipe);121struct pipe_context *pipe = dctx->pipe;122123return pipe->end_query(pipe, dd_query_unwrap(query));124}125126static bool127dd_context_get_query_result(struct pipe_context *_pipe,128struct pipe_query *query, bool wait,129union pipe_query_result *result)130{131struct pipe_context *pipe = dd_context(_pipe)->pipe;132133return pipe->get_query_result(pipe, dd_query_unwrap(query), wait, result);134}135136static void137dd_context_set_active_query_state(struct pipe_context *_pipe, bool enable)138{139struct pipe_context *pipe = dd_context(_pipe)->pipe;140141pipe->set_active_query_state(pipe, enable);142}143144static void145dd_context_render_condition(struct pipe_context *_pipe,146struct pipe_query *query, bool condition,147enum pipe_render_cond_flag mode)148{149struct dd_context *dctx = dd_context(_pipe);150struct pipe_context *pipe = dctx->pipe;151struct dd_draw_state *dstate = &dctx->draw_state;152153pipe->render_condition(pipe, dd_query_unwrap(query), condition, mode);154dstate->render_cond.query = dd_query(query);155dstate->render_cond.condition = condition;156dstate->render_cond.mode = mode;157}158159160/********************************************************************161* constant (immutable) non-shader states162*/163164#define DD_CSO_CREATE(name, shortname) \165static void * \166dd_context_create_##name##_state(struct pipe_context *_pipe, \167const struct pipe_##name##_state *state) \168{ \169struct pipe_context *pipe = dd_context(_pipe)->pipe; \170struct dd_state *hstate = CALLOC_STRUCT(dd_state); \171\172if (!hstate) \173return NULL; \174hstate->cso = pipe->create_##name##_state(pipe, state); \175hstate->state.shortname = *state; \176return hstate; \177}178179#define DD_CSO_BIND(name, shortname) \180static void \181dd_context_bind_##name##_state(struct pipe_context *_pipe, void *state) \182{ \183struct dd_context *dctx = dd_context(_pipe); \184struct pipe_context *pipe = dctx->pipe; \185struct dd_state *hstate = state; \186\187dctx->draw_state.shortname = hstate; \188pipe->bind_##name##_state(pipe, hstate ? hstate->cso : NULL); \189}190191#define DD_CSO_DELETE(name) \192static void \193dd_context_delete_##name##_state(struct pipe_context *_pipe, void *state) \194{ \195struct dd_context *dctx = dd_context(_pipe); \196struct pipe_context *pipe = dctx->pipe; \197struct dd_state *hstate = state; \198\199pipe->delete_##name##_state(pipe, hstate->cso); \200FREE(hstate); \201}202203#define DD_CSO_WHOLE(name, shortname) \204DD_CSO_CREATE(name, shortname) \205DD_CSO_BIND(name, shortname) \206DD_CSO_DELETE(name)207208DD_CSO_WHOLE(blend, blend)209DD_CSO_WHOLE(rasterizer, rs)210DD_CSO_WHOLE(depth_stencil_alpha, dsa)211212DD_CSO_CREATE(sampler, sampler)213DD_CSO_DELETE(sampler)214215static void216dd_context_bind_sampler_states(struct pipe_context *_pipe,217enum pipe_shader_type shader,218unsigned start, unsigned count, void **states)219{220struct dd_context *dctx = dd_context(_pipe);221struct pipe_context *pipe = dctx->pipe;222223memcpy(&dctx->draw_state.sampler_states[shader][start], states,224sizeof(void*) * count);225226if (states) {227void *samp[PIPE_MAX_SAMPLERS];228int i;229230for (i = 0; i < count; i++) {231struct dd_state *s = states[i];232samp[i] = s ? s->cso : NULL;233}234235pipe->bind_sampler_states(pipe, shader, start, count, samp);236}237else238pipe->bind_sampler_states(pipe, shader, start, count, NULL);239}240241static void *242dd_context_create_vertex_elements_state(struct pipe_context *_pipe,243unsigned num_elems,244const struct pipe_vertex_element *elems)245{246struct pipe_context *pipe = dd_context(_pipe)->pipe;247struct dd_state *hstate = CALLOC_STRUCT(dd_state);248249if (!hstate)250return NULL;251hstate->cso = pipe->create_vertex_elements_state(pipe, num_elems, elems);252memcpy(hstate->state.velems.velems, elems, sizeof(elems[0]) * num_elems);253hstate->state.velems.count = num_elems;254return hstate;255}256257DD_CSO_BIND(vertex_elements, velems)258DD_CSO_DELETE(vertex_elements)259260261/********************************************************************262* shaders263*/264265#define DD_SHADER_NOCREATE(NAME, name) \266static void \267dd_context_bind_##name##_state(struct pipe_context *_pipe, void *state) \268{ \269struct dd_context *dctx = dd_context(_pipe); \270struct pipe_context *pipe = dctx->pipe; \271struct dd_state *hstate = state; \272\273dctx->draw_state.shaders[PIPE_SHADER_##NAME] = hstate; \274pipe->bind_##name##_state(pipe, hstate ? hstate->cso : NULL); \275} \276\277static void \278dd_context_delete_##name##_state(struct pipe_context *_pipe, void *state) \279{ \280struct dd_context *dctx = dd_context(_pipe); \281struct pipe_context *pipe = dctx->pipe; \282struct dd_state *hstate = state; \283\284pipe->delete_##name##_state(pipe, hstate->cso); \285if (hstate->state.shader.type == PIPE_SHADER_IR_TGSI) \286tgsi_free_tokens(hstate->state.shader.tokens); \287FREE(hstate); \288}289290#define DD_SHADER(NAME, name) \291static void * \292dd_context_create_##name##_state(struct pipe_context *_pipe, \293const struct pipe_shader_state *state) \294{ \295struct pipe_context *pipe = dd_context(_pipe)->pipe; \296struct dd_state *hstate = CALLOC_STRUCT(dd_state); \297\298if (!hstate) \299return NULL; \300hstate->cso = pipe->create_##name##_state(pipe, state); \301hstate->state.shader = *state; \302if (hstate->state.shader.type == PIPE_SHADER_IR_TGSI) \303hstate->state.shader.tokens = tgsi_dup_tokens(state->tokens); \304return hstate; \305} \306\307DD_SHADER_NOCREATE(NAME, name)308309DD_SHADER(FRAGMENT, fs)310DD_SHADER(VERTEX, vs)311DD_SHADER(GEOMETRY, gs)312DD_SHADER(TESS_CTRL, tcs)313DD_SHADER(TESS_EVAL, tes)314315static void * \316dd_context_create_compute_state(struct pipe_context *_pipe,317const struct pipe_compute_state *state)318{319struct pipe_context *pipe = dd_context(_pipe)->pipe;320struct dd_state *hstate = CALLOC_STRUCT(dd_state);321322if (!hstate)323return NULL;324hstate->cso = pipe->create_compute_state(pipe, state);325326hstate->state.shader.type = state->ir_type;327328if (state->ir_type == PIPE_SHADER_IR_TGSI)329hstate->state.shader.tokens = tgsi_dup_tokens(state->prog);330331return hstate;332}333334DD_SHADER_NOCREATE(COMPUTE, compute)335336/********************************************************************337* immediate states338*/339340#define DD_IMM_STATE(name, type, deref, ref) \341static void \342dd_context_set_##name(struct pipe_context *_pipe, type deref) \343{ \344struct dd_context *dctx = dd_context(_pipe); \345struct pipe_context *pipe = dctx->pipe; \346\347dctx->draw_state.name = deref; \348pipe->set_##name(pipe, ref); \349}350351DD_IMM_STATE(blend_color, const struct pipe_blend_color, *state, state)352DD_IMM_STATE(stencil_ref, const struct pipe_stencil_ref, state, state)353DD_IMM_STATE(clip_state, const struct pipe_clip_state, *state, state)354DD_IMM_STATE(sample_mask, unsigned, sample_mask, sample_mask)355DD_IMM_STATE(min_samples, unsigned, min_samples, min_samples)356DD_IMM_STATE(framebuffer_state, const struct pipe_framebuffer_state, *state, state)357DD_IMM_STATE(polygon_stipple, const struct pipe_poly_stipple, *state, state)358359static void360dd_context_set_constant_buffer(struct pipe_context *_pipe,361enum pipe_shader_type shader, uint index,362bool take_ownership,363const struct pipe_constant_buffer *constant_buffer)364{365struct dd_context *dctx = dd_context(_pipe);366struct pipe_context *pipe = dctx->pipe;367368safe_memcpy(&dctx->draw_state.constant_buffers[shader][index],369constant_buffer, sizeof(*constant_buffer));370pipe->set_constant_buffer(pipe, shader, index, take_ownership, constant_buffer);371}372373static void374dd_context_set_scissor_states(struct pipe_context *_pipe,375unsigned start_slot, unsigned num_scissors,376const struct pipe_scissor_state *states)377{378struct dd_context *dctx = dd_context(_pipe);379struct pipe_context *pipe = dctx->pipe;380381safe_memcpy(&dctx->draw_state.scissors[start_slot], states,382sizeof(*states) * num_scissors);383pipe->set_scissor_states(pipe, start_slot, num_scissors, states);384}385386static void387dd_context_set_viewport_states(struct pipe_context *_pipe,388unsigned start_slot, unsigned num_viewports,389const struct pipe_viewport_state *states)390{391struct dd_context *dctx = dd_context(_pipe);392struct pipe_context *pipe = dctx->pipe;393394safe_memcpy(&dctx->draw_state.viewports[start_slot], states,395sizeof(*states) * num_viewports);396pipe->set_viewport_states(pipe, start_slot, num_viewports, states);397}398399static void dd_context_set_tess_state(struct pipe_context *_pipe,400const float default_outer_level[4],401const float default_inner_level[2])402{403struct dd_context *dctx = dd_context(_pipe);404struct pipe_context *pipe = dctx->pipe;405406memcpy(dctx->draw_state.tess_default_levels, default_outer_level,407sizeof(float) * 4);408memcpy(dctx->draw_state.tess_default_levels+4, default_inner_level,409sizeof(float) * 2);410pipe->set_tess_state(pipe, default_outer_level, default_inner_level);411}412413static void dd_context_set_window_rectangles(struct pipe_context *_pipe,414bool include,415unsigned num_rectangles,416const struct pipe_scissor_state *rects)417{418struct dd_context *dctx = dd_context(_pipe);419struct pipe_context *pipe = dctx->pipe;420421pipe->set_window_rectangles(pipe, include, num_rectangles, rects);422}423424425/********************************************************************426* views427*/428429static struct pipe_surface *430dd_context_create_surface(struct pipe_context *_pipe,431struct pipe_resource *resource,432const struct pipe_surface *surf_tmpl)433{434struct pipe_context *pipe = dd_context(_pipe)->pipe;435struct pipe_surface *view =436pipe->create_surface(pipe, resource, surf_tmpl);437438if (!view)439return NULL;440view->context = _pipe;441return view;442}443444static void445dd_context_surface_destroy(struct pipe_context *_pipe,446struct pipe_surface *surf)447{448struct pipe_context *pipe = dd_context(_pipe)->pipe;449450pipe->surface_destroy(pipe, surf);451}452453static struct pipe_sampler_view *454dd_context_create_sampler_view(struct pipe_context *_pipe,455struct pipe_resource *resource,456const struct pipe_sampler_view *templ)457{458struct pipe_context *pipe = dd_context(_pipe)->pipe;459struct pipe_sampler_view *view =460pipe->create_sampler_view(pipe, resource, templ);461462if (!view)463return NULL;464view->context = _pipe;465return view;466}467468static void469dd_context_sampler_view_destroy(struct pipe_context *_pipe,470struct pipe_sampler_view *view)471{472struct pipe_context *pipe = dd_context(_pipe)->pipe;473474pipe->sampler_view_destroy(pipe, view);475}476477static struct pipe_stream_output_target *478dd_context_create_stream_output_target(struct pipe_context *_pipe,479struct pipe_resource *res,480unsigned buffer_offset,481unsigned buffer_size)482{483struct pipe_context *pipe = dd_context(_pipe)->pipe;484struct pipe_stream_output_target *view =485pipe->create_stream_output_target(pipe, res, buffer_offset,486buffer_size);487488if (!view)489return NULL;490view->context = _pipe;491return view;492}493494static void495dd_context_stream_output_target_destroy(struct pipe_context *_pipe,496struct pipe_stream_output_target *target)497{498struct pipe_context *pipe = dd_context(_pipe)->pipe;499500pipe->stream_output_target_destroy(pipe, target);501}502503504/********************************************************************505* set states506*/507508static void509dd_context_set_sampler_views(struct pipe_context *_pipe,510enum pipe_shader_type shader,511unsigned start, unsigned num,512unsigned unbind_num_trailing_slots,513struct pipe_sampler_view **views)514{515struct dd_context *dctx = dd_context(_pipe);516struct pipe_context *pipe = dctx->pipe;517518safe_memcpy(&dctx->draw_state.sampler_views[shader][start], views,519sizeof(views[0]) * num);520safe_memcpy(&dctx->draw_state.sampler_views[shader][start + num], views,521sizeof(views[0]) * unbind_num_trailing_slots);522pipe->set_sampler_views(pipe, shader, start, num,523unbind_num_trailing_slots, views);524}525526static void527dd_context_set_shader_images(struct pipe_context *_pipe,528enum pipe_shader_type shader,529unsigned start, unsigned num,530unsigned unbind_num_trailing_slots,531const struct pipe_image_view *views)532{533struct dd_context *dctx = dd_context(_pipe);534struct pipe_context *pipe = dctx->pipe;535536safe_memcpy(&dctx->draw_state.shader_images[shader][start], views,537sizeof(views[0]) * num);538safe_memcpy(&dctx->draw_state.shader_images[shader][start + num], NULL,539sizeof(views[0]) * unbind_num_trailing_slots);540pipe->set_shader_images(pipe, shader, start, num,541unbind_num_trailing_slots, views);542}543544static void545dd_context_set_shader_buffers(struct pipe_context *_pipe,546enum pipe_shader_type shader,547unsigned start, unsigned num_buffers,548const struct pipe_shader_buffer *buffers,549unsigned writable_bitmask)550{551struct dd_context *dctx = dd_context(_pipe);552struct pipe_context *pipe = dctx->pipe;553554safe_memcpy(&dctx->draw_state.shader_buffers[shader][start], buffers,555sizeof(buffers[0]) * num_buffers);556pipe->set_shader_buffers(pipe, shader, start, num_buffers, buffers,557writable_bitmask);558}559560static void561dd_context_set_vertex_buffers(struct pipe_context *_pipe,562unsigned start, unsigned num_buffers,563unsigned unbind_num_trailing_slots,564bool take_ownership,565const struct pipe_vertex_buffer *buffers)566{567struct dd_context *dctx = dd_context(_pipe);568struct pipe_context *pipe = dctx->pipe;569570safe_memcpy(&dctx->draw_state.vertex_buffers[start], buffers,571sizeof(buffers[0]) * num_buffers);572safe_memcpy(&dctx->draw_state.vertex_buffers[start + num_buffers], NULL,573sizeof(buffers[0]) * unbind_num_trailing_slots);574pipe->set_vertex_buffers(pipe, start, num_buffers,575unbind_num_trailing_slots, take_ownership,576buffers);577}578579static void580dd_context_set_stream_output_targets(struct pipe_context *_pipe,581unsigned num_targets,582struct pipe_stream_output_target **tgs,583const unsigned *offsets)584{585struct dd_context *dctx = dd_context(_pipe);586struct pipe_context *pipe = dctx->pipe;587struct dd_draw_state *dstate = &dctx->draw_state;588589dstate->num_so_targets = num_targets;590safe_memcpy(dstate->so_targets, tgs, sizeof(*tgs) * num_targets);591safe_memcpy(dstate->so_offsets, offsets, sizeof(*offsets) * num_targets);592pipe->set_stream_output_targets(pipe, num_targets, tgs, offsets);593}594595596static void597dd_context_fence_server_sync(struct pipe_context *_pipe,598struct pipe_fence_handle *fence)599{600struct dd_context *dctx = dd_context(_pipe);601struct pipe_context *pipe = dctx->pipe;602603pipe->fence_server_sync(pipe, fence);604}605606607static void608dd_context_create_fence_fd(struct pipe_context *_pipe,609struct pipe_fence_handle **fence,610int fd,611enum pipe_fd_type type)612{613struct dd_context *dctx = dd_context(_pipe);614struct pipe_context *pipe = dctx->pipe;615616pipe->create_fence_fd(pipe, fence, fd, type);617}618619620void621dd_thread_join(struct dd_context *dctx)622{623mtx_lock(&dctx->mutex);624dctx->kill_thread = true;625cnd_signal(&dctx->cond);626mtx_unlock(&dctx->mutex);627thrd_join(dctx->thread, NULL);628}629630static void631dd_context_destroy(struct pipe_context *_pipe)632{633struct dd_context *dctx = dd_context(_pipe);634struct pipe_context *pipe = dctx->pipe;635636dd_thread_join(dctx);637mtx_destroy(&dctx->mutex);638cnd_destroy(&dctx->cond);639640assert(list_is_empty(&dctx->records));641642if (pipe->set_log_context) {643pipe->set_log_context(pipe, NULL);644645if (dd_screen(dctx->base.screen)->dump_mode == DD_DUMP_ALL_CALLS) {646FILE *f = dd_get_file_stream(dd_screen(dctx->base.screen), 0);647if (f) {648fprintf(f, "Remainder of driver log:\n\n");649}650651u_log_new_page_print(&dctx->log, f);652fclose(f);653}654}655u_log_context_destroy(&dctx->log);656657pipe->destroy(pipe);658FREE(dctx);659}660661662/********************************************************************663* miscellaneous664*/665666static void667dd_context_texture_barrier(struct pipe_context *_pipe, unsigned flags)668{669struct pipe_context *pipe = dd_context(_pipe)->pipe;670671pipe->texture_barrier(pipe, flags);672}673674static void675dd_context_memory_barrier(struct pipe_context *_pipe, unsigned flags)676{677struct pipe_context *pipe = dd_context(_pipe)->pipe;678679pipe->memory_barrier(pipe, flags);680}681682static bool683dd_context_resource_commit(struct pipe_context *_pipe,684struct pipe_resource *resource,685unsigned level, struct pipe_box *box, bool commit)686{687struct pipe_context *pipe = dd_context(_pipe)->pipe;688689return pipe->resource_commit(pipe, resource, level, box, commit);690}691692static void693dd_context_set_compute_resources(struct pipe_context *_pipe,694unsigned start, unsigned count,695struct pipe_surface **resources)696{697struct pipe_context *pipe = dd_context(_pipe)->pipe;698pipe->set_compute_resources(pipe, start, count, resources);699}700701static void702dd_context_set_global_binding(struct pipe_context *_pipe,703unsigned first, unsigned count,704struct pipe_resource **resources,705uint32_t **handles)706{707struct pipe_context *pipe = dd_context(_pipe)->pipe;708pipe->set_global_binding(pipe, first, count, resources, handles);709}710711static void712dd_context_get_sample_position(struct pipe_context *_pipe,713unsigned sample_count, unsigned sample_index,714float *out_value)715{716struct pipe_context *pipe = dd_context(_pipe)->pipe;717718pipe->get_sample_position(pipe, sample_count, sample_index,719out_value);720}721722static void723dd_context_invalidate_resource(struct pipe_context *_pipe,724struct pipe_resource *resource)725{726struct pipe_context *pipe = dd_context(_pipe)->pipe;727728pipe->invalidate_resource(pipe, resource);729}730731static enum pipe_reset_status732dd_context_get_device_reset_status(struct pipe_context *_pipe)733{734struct pipe_context *pipe = dd_context(_pipe)->pipe;735736return pipe->get_device_reset_status(pipe);737}738739static void740dd_context_set_device_reset_callback(struct pipe_context *_pipe,741const struct pipe_device_reset_callback *cb)742{743struct pipe_context *pipe = dd_context(_pipe)->pipe;744745pipe->set_device_reset_callback(pipe, cb);746}747748static void749dd_context_emit_string_marker(struct pipe_context *_pipe,750const char *string, int len)751{752struct dd_context *dctx = dd_context(_pipe);753struct pipe_context *pipe = dctx->pipe;754755pipe->emit_string_marker(pipe, string, len);756dd_parse_apitrace_marker(string, len, &dctx->draw_state.apitrace_call_number);757}758759static void760dd_context_dump_debug_state(struct pipe_context *_pipe, FILE *stream,761unsigned flags)762{763struct pipe_context *pipe = dd_context(_pipe)->pipe;764765pipe->dump_debug_state(pipe, stream, flags);766}767768static uint64_t769dd_context_create_texture_handle(struct pipe_context *_pipe,770struct pipe_sampler_view *view,771const struct pipe_sampler_state *state)772{773struct pipe_context *pipe = dd_context(_pipe)->pipe;774775return pipe->create_texture_handle(pipe, view, state);776}777778static void779dd_context_delete_texture_handle(struct pipe_context *_pipe, uint64_t handle)780{781struct pipe_context *pipe = dd_context(_pipe)->pipe;782783pipe->delete_texture_handle(pipe, handle);784}785786static void787dd_context_make_texture_handle_resident(struct pipe_context *_pipe,788uint64_t handle, bool resident)789{790struct pipe_context *pipe = dd_context(_pipe)->pipe;791792pipe->make_texture_handle_resident(pipe, handle, resident);793}794795static uint64_t796dd_context_create_image_handle(struct pipe_context *_pipe,797const struct pipe_image_view *image)798{799struct pipe_context *pipe = dd_context(_pipe)->pipe;800801return pipe->create_image_handle(pipe, image);802}803804static void805dd_context_delete_image_handle(struct pipe_context *_pipe, uint64_t handle)806{807struct pipe_context *pipe = dd_context(_pipe)->pipe;808809pipe->delete_image_handle(pipe, handle);810}811812static void813dd_context_make_image_handle_resident(struct pipe_context *_pipe,814uint64_t handle, unsigned access,815bool resident)816{817struct pipe_context *pipe = dd_context(_pipe)->pipe;818819pipe->make_image_handle_resident(pipe, handle, access, resident);820}821822static void823dd_context_set_context_param(struct pipe_context *_pipe,824enum pipe_context_param param,825unsigned value)826{827struct pipe_context *pipe = dd_context(_pipe)->pipe;828829pipe->set_context_param(pipe, param, value);830}831832struct pipe_context *833dd_context_create(struct dd_screen *dscreen, struct pipe_context *pipe)834{835struct dd_context *dctx;836837if (!pipe)838return NULL;839840dctx = CALLOC_STRUCT(dd_context);841if (!dctx)842goto fail;843844dctx->pipe = pipe;845dctx->base.priv = pipe->priv; /* expose wrapped priv data */846dctx->base.screen = &dscreen->base;847dctx->base.stream_uploader = pipe->stream_uploader;848dctx->base.const_uploader = pipe->const_uploader;849850dctx->base.destroy = dd_context_destroy;851852CTX_INIT(render_condition);853CTX_INIT(create_query);854CTX_INIT(create_batch_query);855CTX_INIT(destroy_query);856CTX_INIT(begin_query);857CTX_INIT(end_query);858CTX_INIT(get_query_result);859CTX_INIT(set_active_query_state);860CTX_INIT(create_blend_state);861CTX_INIT(bind_blend_state);862CTX_INIT(delete_blend_state);863CTX_INIT(create_sampler_state);864CTX_INIT(bind_sampler_states);865CTX_INIT(delete_sampler_state);866CTX_INIT(create_rasterizer_state);867CTX_INIT(bind_rasterizer_state);868CTX_INIT(delete_rasterizer_state);869CTX_INIT(create_depth_stencil_alpha_state);870CTX_INIT(bind_depth_stencil_alpha_state);871CTX_INIT(delete_depth_stencil_alpha_state);872CTX_INIT(create_fs_state);873CTX_INIT(bind_fs_state);874CTX_INIT(delete_fs_state);875CTX_INIT(create_vs_state);876CTX_INIT(bind_vs_state);877CTX_INIT(delete_vs_state);878CTX_INIT(create_gs_state);879CTX_INIT(bind_gs_state);880CTX_INIT(delete_gs_state);881CTX_INIT(create_tcs_state);882CTX_INIT(bind_tcs_state);883CTX_INIT(delete_tcs_state);884CTX_INIT(create_tes_state);885CTX_INIT(bind_tes_state);886CTX_INIT(delete_tes_state);887CTX_INIT(create_compute_state);888CTX_INIT(bind_compute_state);889CTX_INIT(delete_compute_state);890CTX_INIT(create_vertex_elements_state);891CTX_INIT(bind_vertex_elements_state);892CTX_INIT(delete_vertex_elements_state);893CTX_INIT(set_blend_color);894CTX_INIT(set_stencil_ref);895CTX_INIT(set_sample_mask);896CTX_INIT(set_min_samples);897CTX_INIT(set_clip_state);898CTX_INIT(set_constant_buffer);899CTX_INIT(set_framebuffer_state);900CTX_INIT(set_polygon_stipple);901CTX_INIT(set_scissor_states);902CTX_INIT(set_viewport_states);903CTX_INIT(set_sampler_views);904CTX_INIT(set_tess_state);905CTX_INIT(set_shader_buffers);906CTX_INIT(set_shader_images);907CTX_INIT(set_vertex_buffers);908CTX_INIT(set_window_rectangles);909CTX_INIT(create_stream_output_target);910CTX_INIT(stream_output_target_destroy);911CTX_INIT(set_stream_output_targets);912CTX_INIT(create_fence_fd);913CTX_INIT(fence_server_sync);914CTX_INIT(create_sampler_view);915CTX_INIT(sampler_view_destroy);916CTX_INIT(create_surface);917CTX_INIT(surface_destroy);918CTX_INIT(texture_barrier);919CTX_INIT(memory_barrier);920CTX_INIT(resource_commit);921CTX_INIT(set_compute_resources);922CTX_INIT(set_global_binding);923/* create_video_codec */924/* create_video_buffer */925CTX_INIT(get_sample_position);926CTX_INIT(invalidate_resource);927CTX_INIT(get_device_reset_status);928CTX_INIT(set_device_reset_callback);929CTX_INIT(dump_debug_state);930CTX_INIT(emit_string_marker);931CTX_INIT(create_texture_handle);932CTX_INIT(delete_texture_handle);933CTX_INIT(make_texture_handle_resident);934CTX_INIT(create_image_handle);935CTX_INIT(delete_image_handle);936CTX_INIT(make_image_handle_resident);937CTX_INIT(set_context_param);938939dd_init_draw_functions(dctx);940941u_log_context_init(&dctx->log);942if (pipe->set_log_context)943pipe->set_log_context(pipe, &dctx->log);944945dctx->draw_state.sample_mask = ~0;946947list_inithead(&dctx->records);948(void) mtx_init(&dctx->mutex, mtx_plain);949(void) cnd_init(&dctx->cond);950dctx->thread = u_thread_create(dd_thread_main, dctx);951if (!dctx->thread) {952mtx_destroy(&dctx->mutex);953goto fail;954}955956return &dctx->base;957958fail:959FREE(dctx);960pipe->destroy(pipe);961return NULL;962}963964965