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