Path: blob/21.2-virgl/src/gallium/drivers/softpipe/sp_state_image.c
4570 views
/*1* Copyright 2016 Red Hat.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#include "sp_context.h"24#include "sp_state.h"25#include "sp_image.h"26#include "sp_buffer.h"2728static void softpipe_set_shader_images(struct pipe_context *pipe,29enum pipe_shader_type shader,30unsigned start,31unsigned num,32unsigned unbind_num_trailing_slots,33const struct pipe_image_view *images)34{35struct softpipe_context *softpipe = softpipe_context(pipe);36unsigned i;37assert(shader < PIPE_SHADER_TYPES);38assert(start + num <= ARRAY_SIZE(softpipe->sampler_views[shader]));3940/* set the new images */41for (i = 0; i < num; i++) {42int idx = start + i;4344if (images) {45pipe_resource_reference(&softpipe->tgsi.image[shader]->sp_iview[idx].resource, images[i].resource);46softpipe->tgsi.image[shader]->sp_iview[idx] = images[i];47}48else {49pipe_resource_reference(&softpipe->tgsi.image[shader]->sp_iview[idx].resource, NULL);50memset(&softpipe->tgsi.image[shader]->sp_iview[idx], 0, sizeof(struct pipe_image_view));51}52}5354for (i = 0; i < unbind_num_trailing_slots; i++) {55int idx = start + num + i;5657pipe_resource_reference(&softpipe->tgsi.image[shader]->sp_iview[idx].resource, NULL);58memset(&softpipe->tgsi.image[shader]->sp_iview[idx], 0, sizeof(struct pipe_image_view));59}60}6162static void softpipe_set_shader_buffers(struct pipe_context *pipe,63enum pipe_shader_type shader,64unsigned start,65unsigned num,66const struct pipe_shader_buffer *buffers,67unsigned writable_bitmask)68{69struct softpipe_context *softpipe = softpipe_context(pipe);70unsigned i;71assert(shader < PIPE_SHADER_TYPES);72assert(start + num <= ARRAY_SIZE(softpipe->buffers[shader]));7374/* set the new images */75for (i = 0; i < num; i++) {76int idx = start + i;7778if (buffers) {79pipe_resource_reference(&softpipe->tgsi.buffer[shader]->sp_bview[idx].buffer, buffers[i].buffer);80softpipe->tgsi.buffer[shader]->sp_bview[idx] = buffers[i];81}82else {83pipe_resource_reference(&softpipe->tgsi.buffer[shader]->sp_bview[idx].buffer, NULL);84memset(&softpipe->tgsi.buffer[shader]->sp_bview[idx], 0, sizeof(struct pipe_shader_buffer));85}86}87}8889void softpipe_init_image_funcs(struct pipe_context *pipe)90{91pipe->set_shader_images = softpipe_set_shader_images;92pipe->set_shader_buffers = softpipe_set_shader_buffers;93}949596