Path: blob/21.2-virgl/src/gallium/auxiliary/driver_rbug/rbug_objects.c
4561 views
/**************************************************************************1*2* Copyright 2010 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "util/u_inlines.h"28#include "util/u_memory.h"29#include "util/simple_list.h"3031#include "tgsi/tgsi_parse.h"3233#include "rbug_screen.h"34#include "rbug_objects.h"35#include "rbug_context.h"36373839struct pipe_resource *40rbug_resource_create(struct rbug_screen *rb_screen,41struct pipe_resource *resource)42{43struct rbug_resource *rb_resource;4445if (!resource)46goto error;4748assert(resource->screen == rb_screen->screen);4950rb_resource = CALLOC_STRUCT(rbug_resource);51if (!rb_resource)52goto error;5354memcpy(&rb_resource->base, resource, sizeof(struct pipe_resource));5556pipe_reference_init(&rb_resource->base.reference, 1);57rb_resource->base.screen = &rb_screen->base;58rb_resource->resource = resource;5960if (resource->target != PIPE_BUFFER)61rbug_screen_add_to_list(rb_screen, resources, rb_resource);6263return &rb_resource->base;6465error:66pipe_resource_reference(&resource, NULL);67return NULL;68}6970void71rbug_resource_destroy(struct rbug_resource *rb_resource)72{73struct rbug_screen *rb_screen = rbug_screen(rb_resource->base.screen);7475if (rb_resource->base.target != PIPE_BUFFER)76rbug_screen_remove_from_list(rb_screen, resources, rb_resource);7778pipe_resource_reference(&rb_resource->resource, NULL);79FREE(rb_resource);80}818283struct pipe_surface *84rbug_surface_create(struct rbug_context *rb_context,85struct rbug_resource *rb_resource,86struct pipe_surface *surface)87{88struct rbug_surface *rb_surface;8990if (!surface)91goto error;9293assert(surface->texture == rb_resource->resource);9495rb_surface = CALLOC_STRUCT(rbug_surface);96if (!rb_surface)97goto error;9899memcpy(&rb_surface->base, surface, sizeof(struct pipe_surface));100101pipe_reference_init(&rb_surface->base.reference, 1);102rb_surface->base.texture = NULL;103rb_surface->base.context = &rb_context->base;104rb_surface->surface = surface; /* we own the surface already */105pipe_resource_reference(&rb_surface->base.texture, &rb_resource->base);106107return &rb_surface->base;108109error:110pipe_surface_reference(&surface, NULL);111return NULL;112}113114void115rbug_surface_destroy(struct rbug_context *rb_context,116struct rbug_surface *rb_surface)117{118pipe_resource_reference(&rb_surface->base.texture, NULL);119pipe_surface_reference(&rb_surface->surface, NULL);120FREE(rb_surface);121}122123124struct pipe_sampler_view *125rbug_sampler_view_create(struct rbug_context *rb_context,126struct rbug_resource *rb_resource,127struct pipe_sampler_view *view)128{129struct rbug_sampler_view *rb_view;130131if (!view)132goto error;133134assert(view->texture == rb_resource->resource);135136rb_view = MALLOC(sizeof(struct rbug_sampler_view));137138rb_view->base = *view;139rb_view->base.reference.count = 1;140rb_view->base.texture = NULL;141pipe_resource_reference(&rb_view->base.texture, &rb_resource->base);142rb_view->base.context = &rb_context->base;143rb_view->sampler_view = view;144145return &rb_view->base;146error:147return NULL;148}149150void151rbug_sampler_view_destroy(struct rbug_context *rb_context,152struct rbug_sampler_view *rb_view)153{154pipe_resource_reference(&rb_view->base.texture, NULL);155pipe_sampler_view_reference(&rb_view->sampler_view, NULL);156FREE(rb_view);157}158159160struct pipe_transfer *161rbug_transfer_create(struct rbug_context *rb_context,162struct rbug_resource *rb_resource,163struct pipe_transfer *transfer)164{165struct rbug_transfer *rb_transfer;166167if (!transfer)168goto error;169170assert(transfer->resource == rb_resource->resource);171172rb_transfer = CALLOC_STRUCT(rbug_transfer);173if (!rb_transfer)174goto error;175176memcpy(&rb_transfer->base, transfer, sizeof(struct pipe_transfer));177178rb_transfer->base.resource = NULL;179rb_transfer->transfer = transfer;180rb_transfer->pipe = rb_context->pipe;181182pipe_resource_reference(&rb_transfer->base.resource, &rb_resource->base);183assert(rb_transfer->base.resource == &rb_resource->base);184185return &rb_transfer->base;186187error:188if (rb_resource->base.target == PIPE_BUFFER)189rb_context->pipe->buffer_unmap(rb_context->pipe, transfer);190else191rb_context->pipe->texture_unmap(rb_context->pipe, transfer);192return NULL;193}194195void196rbug_transfer_destroy(struct rbug_context *rb_context,197struct rbug_transfer *rb_transfer)198{199pipe_resource_reference(&rb_transfer->base.resource, NULL);200FREE(rb_transfer);201}202203void *204rbug_shader_create(struct rbug_context *rb_context,205const struct pipe_shader_state *state,206void *result, enum rbug_shader_type type)207{208struct rbug_shader *rb_shader = CALLOC_STRUCT(rbug_shader);209210rb_shader->type = type;211rb_shader->shader = result;212if (state->tokens)213rb_shader->tokens = tgsi_dup_tokens(state->tokens);214215/* works on context as well since its just a macro */216rbug_screen_add_to_list(rb_context, shaders, rb_shader);217218return rb_shader;219}220221void222rbug_shader_destroy(struct rbug_context *rb_context,223struct rbug_shader *rb_shader)224{225struct pipe_context *pipe = rb_context->pipe;226227/* works on context as well since its just a macro */228rbug_screen_remove_from_list(rb_context, shaders, rb_shader);229230switch(rb_shader->type) {231case RBUG_SHADER_FRAGMENT:232if (rb_shader->replaced_shader)233pipe->delete_fs_state(pipe, rb_shader->replaced_shader);234pipe->delete_fs_state(pipe, rb_shader->shader);235break;236case RBUG_SHADER_VERTEX:237if (rb_shader->replaced_shader)238pipe->delete_vs_state(pipe, rb_shader->replaced_shader);239pipe->delete_vs_state(pipe, rb_shader->shader);240break;241case RBUG_SHADER_GEOM:242if (rb_shader->replaced_shader)243pipe->delete_gs_state(pipe, rb_shader->replaced_shader);244pipe->delete_gs_state(pipe, rb_shader->shader);245break;246default:247assert(0);248}249250FREE(rb_shader->replaced_tokens);251FREE(rb_shader->tokens);252FREE(rb_shader);253}254255256