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_binding_to_sb(struct gl_buffer_binding
*binding
,
45 struct pipe_shader_buffer
*sb
)
47 struct st_buffer_object
*st_obj
=
48 st_buffer_object(binding
->BufferObject
);
50 if (st_obj
&& st_obj
->buffer
) {
51 sb
->buffer
= st_obj
->buffer
;
52 sb
->buffer_offset
= binding
->Offset
;
53 sb
->buffer_size
= st_obj
->buffer
->width0
- binding
->Offset
;
55 /* AutomaticSize is FALSE if the buffer was set with BindBufferRange.
56 * Take the minimum just to be sure.
58 if (!binding
->AutomaticSize
)
59 sb
->buffer_size
= MIN2(sb
->buffer_size
, (unsigned) binding
->Size
);
62 sb
->buffer_offset
= 0;
68 st_bind_atomics(struct st_context
*st
, struct gl_program
*prog
,
69 enum pipe_shader_type shader_type
)
73 if (!prog
|| !st
->pipe
->set_shader_buffers
|| st
->has_hw_atomics
)
76 for (i
= 0; i
< prog
->sh
.data
->NumAtomicBuffers
; i
++) {
77 struct gl_active_atomic_buffer
*atomic
=
78 &prog
->sh
.data
->AtomicBuffers
[i
];
79 struct pipe_shader_buffer sb
;
81 st_binding_to_sb(&st
->ctx
->AtomicBufferBindings
[atomic
->Binding
], &sb
);
83 st
->pipe
->set_shader_buffers(st
->pipe
, shader_type
,
84 atomic
->Binding
, 1, &sb
, 0x1);
89 st_bind_vs_atomics(struct st_context
*st
)
91 struct gl_program
*prog
=
92 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
94 st_bind_atomics(st
, prog
, PIPE_SHADER_VERTEX
);
98 st_bind_fs_atomics(struct st_context
*st
)
100 struct gl_program
*prog
=
101 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_FRAGMENT
];
103 st_bind_atomics(st
, prog
, PIPE_SHADER_FRAGMENT
);
107 st_bind_gs_atomics(struct st_context
*st
)
109 struct gl_program
*prog
=
110 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
];
112 st_bind_atomics(st
, prog
, PIPE_SHADER_GEOMETRY
);
116 st_bind_tcs_atomics(struct st_context
*st
)
118 struct gl_program
*prog
=
119 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_CTRL
];
121 st_bind_atomics(st
, prog
, PIPE_SHADER_TESS_CTRL
);
125 st_bind_tes_atomics(struct st_context
*st
)
127 struct gl_program
*prog
=
128 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_EVAL
];
130 st_bind_atomics(st
, prog
, PIPE_SHADER_TESS_EVAL
);
134 st_bind_cs_atomics(struct st_context
*st
)
136 if (st
->has_hw_atomics
) {
137 st_bind_hw_atomic_buffers(st
);
140 struct gl_program
*prog
=
141 st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_COMPUTE
];
143 st_bind_atomics(st
, prog
, PIPE_SHADER_COMPUTE
);
147 st_bind_hw_atomic_buffers(struct st_context
*st
)
149 struct pipe_shader_buffer buffers
[PIPE_MAX_HW_ATOMIC_BUFFERS
];
152 if (!st
->has_hw_atomics
)
155 for (i
= 0; i
< st
->ctx
->Const
.MaxAtomicBufferBindings
; i
++)
156 st_binding_to_sb(&st
->ctx
->AtomicBufferBindings
[i
], &buffers
[i
]);
158 st
->pipe
->set_hw_atomic_buffers(st
->pipe
, 0, st
->ctx
->Const
.MaxAtomicBufferBindings
, buffers
);