1 /**************************************************************************
3 * Copyright 2014 Ilia Mirkin. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
25 **************************************************************************/
27 #include "main/imports.h"
28 #include "program/prog_parameter.h"
29 #include "program/prog_print.h"
30 #include "compiler/glsl/ir_uniform.h"
32 #include "pipe/p_context.h"
33 #include "pipe/p_defines.h"
34 #include "util/u_inlines.h"
35 #include "util/u_surface.h"
38 #include "st_cb_bufferobjects.h"
39 #include "st_context.h"
41 #include "st_program.h"
44 st_bind_ssbos(struct st_context
*st
, struct gl_linked_shader
*shader
,
48 struct pipe_shader_buffer buffers
[MAX_SHADER_STORAGE_BUFFERS
];
49 struct gl_program_constants
*c
;
51 if (!shader
|| !st
->pipe
->set_shader_buffers
)
54 c
= &st
->ctx
->Const
.Program
[shader
->Stage
];
56 for (i
= 0; i
< shader
->NumShaderStorageBlocks
; i
++) {
57 struct gl_shader_storage_buffer_binding
*binding
;
58 struct st_buffer_object
*st_obj
;
59 struct pipe_shader_buffer
*sb
= &buffers
[i
];
61 binding
= &st
->ctx
->ShaderStorageBufferBindings
[
62 shader
->ShaderStorageBlocks
[i
]->Binding
];
63 st_obj
= st_buffer_object(binding
->BufferObject
);
65 sb
->buffer
= st_obj
->buffer
;
68 sb
->buffer_offset
= binding
->Offset
;
69 sb
->buffer_size
= sb
->buffer
->width0
- binding
->Offset
;
71 /* AutomaticSize is FALSE if the buffer was set with BindBufferRange.
72 * Take the minimum just to be sure.
74 if (!binding
->AutomaticSize
)
75 sb
->buffer_size
= MIN2(sb
->buffer_size
, (unsigned) binding
->Size
);
78 sb
->buffer_offset
= 0;
82 st
->pipe
->set_shader_buffers(st
->pipe
, shader_type
, c
->MaxAtomicBuffers
,
83 shader
->NumShaderStorageBlocks
, buffers
);
84 /* clear out any stale shader buffers */
85 if (shader
->NumShaderStorageBlocks
< c
->MaxShaderStorageBlocks
)
86 st
->pipe
->set_shader_buffers(
87 st
->pipe
, shader_type
,
88 c
->MaxAtomicBuffers
+ shader
->NumShaderStorageBlocks
,
89 c
->MaxShaderStorageBlocks
- shader
->NumShaderStorageBlocks
,
93 static void bind_vs_ssbos(struct st_context
*st
)
95 struct gl_shader_program
*prog
=
96 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
101 st_bind_ssbos(st
, prog
->_LinkedShaders
[MESA_SHADER_VERTEX
],
105 const struct st_tracked_state st_bind_vs_ssbos
= {
108 ST_NEW_VERTEX_PROGRAM
| ST_NEW_STORAGE_BUFFER
,
113 static void bind_fs_ssbos(struct st_context
*st
)
115 struct gl_shader_program
*prog
=
116 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_FRAGMENT
];
121 st_bind_ssbos(st
, prog
->_LinkedShaders
[MESA_SHADER_FRAGMENT
],
122 PIPE_SHADER_FRAGMENT
);
125 const struct st_tracked_state st_bind_fs_ssbos
= {
128 ST_NEW_FRAGMENT_PROGRAM
| ST_NEW_STORAGE_BUFFER
,
133 static void bind_gs_ssbos(struct st_context
*st
)
135 struct gl_shader_program
*prog
=
136 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
];
141 st_bind_ssbos(st
, prog
->_LinkedShaders
[MESA_SHADER_GEOMETRY
],
142 PIPE_SHADER_GEOMETRY
);
145 const struct st_tracked_state st_bind_gs_ssbos
= {
148 ST_NEW_GEOMETRY_PROGRAM
| ST_NEW_STORAGE_BUFFER
,
153 static void bind_tcs_ssbos(struct st_context
*st
)
155 struct gl_shader_program
*prog
=
156 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_CTRL
];
161 st_bind_ssbos(st
, prog
->_LinkedShaders
[MESA_SHADER_TESS_CTRL
],
162 PIPE_SHADER_TESS_CTRL
);
165 const struct st_tracked_state st_bind_tcs_ssbos
= {
168 ST_NEW_TESSCTRL_PROGRAM
| ST_NEW_STORAGE_BUFFER
,
173 static void bind_tes_ssbos(struct st_context
*st
)
175 struct gl_shader_program
*prog
=
176 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_EVAL
];
181 st_bind_ssbos(st
, prog
->_LinkedShaders
[MESA_SHADER_TESS_EVAL
],
182 PIPE_SHADER_TESS_EVAL
);
185 const struct st_tracked_state st_bind_tes_ssbos
= {
188 ST_NEW_TESSEVAL_PROGRAM
| ST_NEW_STORAGE_BUFFER
,
193 static void bind_cs_ssbos(struct st_context
*st
)
195 struct gl_shader_program
*prog
=
196 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_COMPUTE
];
201 st_bind_ssbos(st
, prog
->_LinkedShaders
[MESA_SHADER_COMPUTE
],
202 PIPE_SHADER_COMPUTE
);
205 const struct st_tracked_state st_bind_cs_ssbos
= {
208 ST_NEW_COMPUTE_PROGRAM
| ST_NEW_STORAGE_BUFFER
,