• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2014 Ilia Mirkin. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  **************************************************************************/
26 
27 #include "main/imports.h"
28 #include "program/prog_parameter.h"
29 #include "program/prog_print.h"
30 #include "compiler/glsl/ir_uniform.h"
31 
32 #include "pipe/p_context.h"
33 #include "pipe/p_defines.h"
34 #include "util/u_inlines.h"
35 #include "util/u_surface.h"
36 
37 #include "st_debug.h"
38 #include "st_cb_bufferobjects.h"
39 #include "st_context.h"
40 #include "st_atom.h"
41 #include "st_program.h"
42 
43 static void
st_bind_ssbos(struct st_context * st,struct gl_program * prog,enum pipe_shader_type shader_type)44 st_bind_ssbos(struct st_context *st, struct gl_program *prog,
45               enum pipe_shader_type shader_type)
46 {
47    unsigned i;
48    struct pipe_shader_buffer buffers[MAX_SHADER_STORAGE_BUFFERS];
49    struct gl_program_constants *c;
50    int buffer_base;
51    if (!prog || !st->pipe->set_shader_buffers)
52       return;
53 
54    c = &st->ctx->Const.Program[prog->info.stage];
55 
56    buffer_base = st->has_hw_atomics ? 0 : c->MaxAtomicBuffers;
57 
58    for (i = 0; i < prog->info.num_ssbos; i++) {
59       struct gl_buffer_binding *binding;
60       struct st_buffer_object *st_obj;
61       struct pipe_shader_buffer *sb = &buffers[i];
62 
63       binding = &st->ctx->ShaderStorageBufferBindings[
64             prog->sh.ShaderStorageBlocks[i]->Binding];
65       st_obj = st_buffer_object(binding->BufferObject);
66 
67       sb->buffer = st_obj->buffer;
68 
69       if (sb->buffer) {
70          sb->buffer_offset = binding->Offset;
71          sb->buffer_size = sb->buffer->width0 - binding->Offset;
72 
73          /* AutomaticSize is FALSE if the buffer was set with BindBufferRange.
74           * Take the minimum just to be sure.
75           */
76          if (!binding->AutomaticSize)
77             sb->buffer_size = MIN2(sb->buffer_size, (unsigned) binding->Size);
78       }
79       else {
80          sb->buffer_offset = 0;
81          sb->buffer_size = 0;
82       }
83    }
84    st->pipe->set_shader_buffers(st->pipe, shader_type, buffer_base,
85                                 prog->info.num_ssbos, buffers);
86    /* clear out any stale shader buffers */
87    if (prog->info.num_ssbos < c->MaxShaderStorageBlocks)
88       st->pipe->set_shader_buffers(
89             st->pipe, shader_type,
90             buffer_base + prog->info.num_ssbos,
91             c->MaxShaderStorageBlocks - prog->info.num_ssbos,
92             NULL);
93 }
94 
st_bind_vs_ssbos(struct st_context * st)95 void st_bind_vs_ssbos(struct st_context *st)
96 {
97    struct gl_program *prog =
98       st->ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
99 
100    st_bind_ssbos(st, prog, PIPE_SHADER_VERTEX);
101 }
102 
st_bind_fs_ssbos(struct st_context * st)103 void st_bind_fs_ssbos(struct st_context *st)
104 {
105    struct gl_program *prog =
106       st->ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
107 
108    st_bind_ssbos(st, prog, PIPE_SHADER_FRAGMENT);
109 }
110 
st_bind_gs_ssbos(struct st_context * st)111 void st_bind_gs_ssbos(struct st_context *st)
112 {
113    struct gl_program *prog =
114       st->ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
115 
116    st_bind_ssbos(st, prog, PIPE_SHADER_GEOMETRY);
117 }
118 
st_bind_tcs_ssbos(struct st_context * st)119 void st_bind_tcs_ssbos(struct st_context *st)
120 {
121    struct gl_program *prog =
122       st->ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
123 
124    st_bind_ssbos(st, prog, PIPE_SHADER_TESS_CTRL);
125 }
126 
st_bind_tes_ssbos(struct st_context * st)127 void st_bind_tes_ssbos(struct st_context *st)
128 {
129    struct gl_program *prog =
130       st->ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
131 
132    st_bind_ssbos(st, prog, PIPE_SHADER_TESS_EVAL);
133 }
134 
st_bind_cs_ssbos(struct st_context * st)135 void st_bind_cs_ssbos(struct st_context *st)
136 {
137    struct gl_program *prog =
138       st->ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
139 
140    st_bind_ssbos(st, prog, PIPE_SHADER_COMPUTE);
141 }
142