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
**************************************************************************/
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_context.h"
40
#include "st_program.h"
43
st_binding_to_sb(struct gl_buffer_binding *binding,
44
struct pipe_shader_buffer *sb)
46
struct gl_buffer_object *st_obj = binding->BufferObject;
48
if (st_obj && st_obj->buffer) {
49
sb->buffer = st_obj->buffer;
50
sb->buffer_offset = binding->Offset;
51
sb->buffer_size = st_obj->buffer->width0 - binding->Offset;
53
/* AutomaticSize is FALSE if the buffer was set with BindBufferRange.
54
* Take the minimum just to be sure.
56
if (!binding->AutomaticSize)
57
sb->buffer_size = MIN2(sb->buffer_size, (unsigned) binding->Size);
60
sb->buffer_offset = 0;
66
st_bind_atomics(struct st_context *st, struct gl_program *prog,
67
gl_shader_stage stage)
70
enum pipe_shader_type shader_type = pipe_shader_type_from_mesa(stage);
72
if (!prog || !st->pipe->set_shader_buffers || st->has_hw_atomics)
75
/* For !has_hw_atomics, the atomic counters have been rewritten to be above
76
* the SSBOs used by the program.
78
unsigned buffer_base = prog->info.num_ssbos;
79
unsigned used_bindings = 0;
80
for (i = 0; i < prog->sh.data->NumAtomicBuffers; i++) {
81
struct gl_active_atomic_buffer *atomic =
82
&prog->sh.data->AtomicBuffers[i];
83
struct pipe_shader_buffer sb;
85
st_binding_to_sb(&st->ctx->AtomicBufferBindings[atomic->Binding], &sb);
87
st->pipe->set_shader_buffers(st->pipe, shader_type,
88
buffer_base + atomic->Binding, 1, &sb, 0x1);
89
used_bindings = MAX2(atomic->Binding + 1, used_bindings);
91
st->last_used_atomic_bindings[shader_type] = used_bindings;
95
st_bind_vs_atomics(struct st_context *st)
97
struct gl_program *prog =
98
st->ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
100
st_bind_atomics(st, prog, MESA_SHADER_VERTEX);
104
st_bind_fs_atomics(struct st_context *st)
106
struct gl_program *prog =
107
st->ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
109
st_bind_atomics(st, prog, MESA_SHADER_FRAGMENT);
113
st_bind_gs_atomics(struct st_context *st)
115
struct gl_program *prog =
116
st->ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
118
st_bind_atomics(st, prog, MESA_SHADER_GEOMETRY);
122
st_bind_tcs_atomics(struct st_context *st)
124
struct gl_program *prog =
125
st->ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
127
st_bind_atomics(st, prog, MESA_SHADER_TESS_CTRL);
131
st_bind_tes_atomics(struct st_context *st)
133
struct gl_program *prog =
134
st->ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
136
st_bind_atomics(st, prog, MESA_SHADER_TESS_EVAL);
140
st_bind_cs_atomics(struct st_context *st)
142
if (st->has_hw_atomics) {
143
st_bind_hw_atomic_buffers(st);
146
struct gl_program *prog =
147
st->ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
149
st_bind_atomics(st, prog, MESA_SHADER_COMPUTE);
153
st_bind_hw_atomic_buffers(struct st_context *st)
155
struct pipe_shader_buffer buffers[PIPE_MAX_HW_ATOMIC_BUFFERS];
158
if (!st->has_hw_atomics)
161
for (i = 0; i < st->ctx->Const.MaxAtomicBufferBindings; i++)
162
st_binding_to_sb(&st->ctx->AtomicBufferBindings[i], &buffers[i]);
164
st->pipe->set_hw_atomic_buffers(st->pipe, 0, st->ctx->Const.MaxAtomicBufferBindings, buffers);