1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2016 Red Hat. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "sp_context.h" 25bf215546Sopenharmony_ci#include "sp_state.h" 26bf215546Sopenharmony_ci#include "sp_image.h" 27bf215546Sopenharmony_ci#include "sp_buffer.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_cistatic void softpipe_set_shader_images(struct pipe_context *pipe, 30bf215546Sopenharmony_ci enum pipe_shader_type shader, 31bf215546Sopenharmony_ci unsigned start, 32bf215546Sopenharmony_ci unsigned num, 33bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 34bf215546Sopenharmony_ci const struct pipe_image_view *images) 35bf215546Sopenharmony_ci{ 36bf215546Sopenharmony_ci struct softpipe_context *softpipe = softpipe_context(pipe); 37bf215546Sopenharmony_ci unsigned i; 38bf215546Sopenharmony_ci assert(shader < PIPE_SHADER_TYPES); 39bf215546Sopenharmony_ci assert(start + num <= ARRAY_SIZE(softpipe->sampler_views[shader])); 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci /* set the new images */ 42bf215546Sopenharmony_ci for (i = 0; i < num; i++) { 43bf215546Sopenharmony_ci int idx = start + i; 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci if (images) { 46bf215546Sopenharmony_ci pipe_resource_reference(&softpipe->tgsi.image[shader]->sp_iview[idx].resource, images[i].resource); 47bf215546Sopenharmony_ci softpipe->tgsi.image[shader]->sp_iview[idx] = images[i]; 48bf215546Sopenharmony_ci } 49bf215546Sopenharmony_ci else { 50bf215546Sopenharmony_ci pipe_resource_reference(&softpipe->tgsi.image[shader]->sp_iview[idx].resource, NULL); 51bf215546Sopenharmony_ci memset(&softpipe->tgsi.image[shader]->sp_iview[idx], 0, sizeof(struct pipe_image_view)); 52bf215546Sopenharmony_ci } 53bf215546Sopenharmony_ci } 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci for (i = 0; i < unbind_num_trailing_slots; i++) { 56bf215546Sopenharmony_ci int idx = start + num + i; 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci pipe_resource_reference(&softpipe->tgsi.image[shader]->sp_iview[idx].resource, NULL); 59bf215546Sopenharmony_ci memset(&softpipe->tgsi.image[shader]->sp_iview[idx], 0, sizeof(struct pipe_image_view)); 60bf215546Sopenharmony_ci } 61bf215546Sopenharmony_ci} 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_cistatic void softpipe_set_shader_buffers(struct pipe_context *pipe, 64bf215546Sopenharmony_ci enum pipe_shader_type shader, 65bf215546Sopenharmony_ci unsigned start, 66bf215546Sopenharmony_ci unsigned num, 67bf215546Sopenharmony_ci const struct pipe_shader_buffer *buffers, 68bf215546Sopenharmony_ci unsigned writable_bitmask) 69bf215546Sopenharmony_ci{ 70bf215546Sopenharmony_ci struct softpipe_context *softpipe = softpipe_context(pipe); 71bf215546Sopenharmony_ci unsigned i; 72bf215546Sopenharmony_ci assert(shader < PIPE_SHADER_TYPES); 73bf215546Sopenharmony_ci assert(start + num <= ARRAY_SIZE(softpipe->buffers[shader])); 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci /* set the new images */ 76bf215546Sopenharmony_ci for (i = 0; i < num; i++) { 77bf215546Sopenharmony_ci int idx = start + i; 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_ci if (buffers) { 80bf215546Sopenharmony_ci pipe_resource_reference(&softpipe->tgsi.buffer[shader]->sp_bview[idx].buffer, buffers[i].buffer); 81bf215546Sopenharmony_ci softpipe->tgsi.buffer[shader]->sp_bview[idx] = buffers[i]; 82bf215546Sopenharmony_ci } 83bf215546Sopenharmony_ci else { 84bf215546Sopenharmony_ci pipe_resource_reference(&softpipe->tgsi.buffer[shader]->sp_bview[idx].buffer, NULL); 85bf215546Sopenharmony_ci memset(&softpipe->tgsi.buffer[shader]->sp_bview[idx], 0, sizeof(struct pipe_shader_buffer)); 86bf215546Sopenharmony_ci } 87bf215546Sopenharmony_ci } 88bf215546Sopenharmony_ci} 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_civoid softpipe_init_image_funcs(struct pipe_context *pipe) 91bf215546Sopenharmony_ci{ 92bf215546Sopenharmony_ci pipe->set_shader_images = softpipe_set_shader_images; 93bf215546Sopenharmony_ci pipe->set_shader_buffers = softpipe_set_shader_buffers; 94bf215546Sopenharmony_ci} 95