Commit 68800366 authored by Ilia Mirkin's avatar Ilia Mirkin

st/mesa: add support for SSBO binding and GLSL intrinsics

Signed-off-by: Ilia Mirkin's avatarIlia Mirkin <imirkin@alum.mit.edu>

v1 -> v2: some 80 char reformatting
parent 9d6f9ccf
......@@ -410,6 +410,7 @@ STATETRACKER_FILES = \
state_tracker/st_atom_shader.c \
state_tracker/st_atom_shader.h \
state_tracker/st_atom_stipple.c \
state_tracker/st_atom_storagebuf.c \
state_tracker/st_atom_tess.c \
state_tracker/st_atom_texture.c \
state_tracker/st_atom_viewport.c \
......
......@@ -80,6 +80,11 @@ static const struct st_tracked_state *atoms[] =
&st_bind_tes_atomics,
&st_bind_fs_atomics,
&st_bind_gs_atomics,
&st_bind_vs_ssbos,
&st_bind_tcs_ssbos,
&st_bind_tes_ssbos,
&st_bind_fs_ssbos,
&st_bind_gs_ssbos,
&st_update_pixel_transfer,
&st_update_tess,
......
......@@ -83,6 +83,11 @@ extern const struct st_tracked_state st_bind_vs_atomics;
extern const struct st_tracked_state st_bind_gs_atomics;
extern const struct st_tracked_state st_bind_tcs_atomics;
extern const struct st_tracked_state st_bind_tes_atomics;
extern const struct st_tracked_state st_bind_fs_ssbos;
extern const struct st_tracked_state st_bind_vs_ssbos;
extern const struct st_tracked_state st_bind_gs_ssbos;
extern const struct st_tracked_state st_bind_tcs_ssbos;
extern const struct st_tracked_state st_bind_tes_ssbos;
extern const struct st_tracked_state st_update_pixel_transfer;
extern const struct st_tracked_state st_update_tess;
......
/**************************************************************************
*
* Copyright 2014 Ilia Mirkin. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "main/imports.h"
#include "program/prog_parameter.h"
#include "program/prog_print.h"
#include "compiler/glsl/ir_uniform.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "util/u_surface.h"
#include "st_debug.h"
#include "st_cb_bufferobjects.h"
#include "st_context.h"
#include "st_atom.h"
#include "st_program.h"
static void
st_bind_ssbos(struct st_context *st, struct gl_shader *shader,
unsigned shader_type)
{
unsigned i;
struct pipe_shader_buffer buffers[MAX_SHADER_STORAGE_BUFFERS];
struct gl_program_constants *c = &st->ctx->Const.Program[shader->Stage];
if (!shader || !st->pipe->set_shader_buffers)
return;
for (i = 0; i < shader->NumShaderStorageBlocks; i++) {
struct gl_shader_storage_buffer_binding *binding;
struct st_buffer_object *st_obj;
struct pipe_shader_buffer *sb = &buffers[i];
binding = &st->ctx->ShaderStorageBufferBindings[
shader->ShaderStorageBlocks[i]->Binding];
st_obj = st_buffer_object(binding->BufferObject);
sb->buffer = st_obj->buffer;
if (sb->buffer) {
sb->buffer_offset = binding->Offset;
sb->buffer_size = sb->buffer->width0 - binding->Offset;
/* AutomaticSize is FALSE if the buffer was set with BindBufferRange.
* Take the minimum just to be sure.
*/
if (!binding->AutomaticSize)
sb->buffer_size = MIN2(sb->buffer_size, (unsigned) binding->Size);
}
else {
sb->buffer_offset = 0;
sb->buffer_size = 0;
}
}
st->pipe->set_shader_buffers(st->pipe, shader_type, c->MaxAtomicBuffers,
shader->NumShaderStorageBlocks, buffers);
/* clear out any stale shader buffers */
if (shader->NumShaderStorageBlocks < c->MaxShaderStorageBlocks)
st->pipe->set_shader_buffers(
st->pipe, shader_type,
c->MaxAtomicBuffers + shader->NumShaderStorageBlocks,
c->MaxShaderStorageBlocks - shader->NumShaderStorageBlocks,
NULL);
}
static void bind_vs_ssbos(struct st_context *st)
{
struct gl_shader_program *prog =
st->ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
if (!prog)
return;
st_bind_ssbos(st, prog->_LinkedShaders[MESA_SHADER_VERTEX],
PIPE_SHADER_VERTEX);
}
const struct st_tracked_state st_bind_vs_ssbos = {
"st_bind_vs_ssbos",
{
0,
ST_NEW_VERTEX_PROGRAM | ST_NEW_STORAGE_BUFFER,
},
bind_vs_ssbos
};
static void bind_fs_ssbos(struct st_context *st)
{
struct gl_shader_program *prog =
st->ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
if (!prog)
return;
st_bind_ssbos(st, prog->_LinkedShaders[MESA_SHADER_FRAGMENT],
PIPE_SHADER_FRAGMENT);
}
const struct st_tracked_state st_bind_fs_ssbos = {
"st_bind_fs_ssbos",
{
0,
ST_NEW_FRAGMENT_PROGRAM | ST_NEW_STORAGE_BUFFER,
},
bind_fs_ssbos
};
static void bind_gs_ssbos(struct st_context *st)
{
struct gl_shader_program *prog =
st->ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
if (!prog)
return;
st_bind_ssbos(st, prog->_LinkedShaders[MESA_SHADER_GEOMETRY],
PIPE_SHADER_GEOMETRY);
}
const struct st_tracked_state st_bind_gs_ssbos = {
"st_bind_gs_ssbos",
{
0,
ST_NEW_GEOMETRY_PROGRAM | ST_NEW_STORAGE_BUFFER,
},
bind_gs_ssbos
};
static void bind_tcs_ssbos(struct st_context *st)
{
struct gl_shader_program *prog =
st->ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
if (!prog)
return;
st_bind_ssbos(st, prog->_LinkedShaders[MESA_SHADER_TESS_CTRL],
PIPE_SHADER_TESS_CTRL);
}
const struct st_tracked_state st_bind_tcs_ssbos = {
"st_bind_tcs_ssbos",
{
0,
ST_NEW_TESSCTRL_PROGRAM | ST_NEW_STORAGE_BUFFER,
},
bind_tcs_ssbos
};
static void bind_tes_ssbos(struct st_context *st)
{
struct gl_shader_program *prog =
st->ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
if (!prog)
return;
st_bind_ssbos(st, prog->_LinkedShaders[MESA_SHADER_TESS_EVAL],
PIPE_SHADER_TESS_EVAL);
}
const struct st_tracked_state st_bind_tes_ssbos = {
"st_bind_tes_ssbos",
{
0,
ST_NEW_TESSEVAL_PROGRAM | ST_NEW_STORAGE_BUFFER,
},
bind_tes_ssbos
};
......@@ -238,6 +238,7 @@ st_bufferobj_data(struct gl_context *ctx,
bind = PIPE_BIND_COMMAND_ARGS_BUFFER;
break;
case GL_ATOMIC_COUNTER_BUFFER:
case GL_SHADER_STORAGE_BUFFER:
bind = PIPE_BIND_SHADER_BUFFER;
break;
default:
......
......@@ -351,6 +351,7 @@ static void st_init_driver_flags(struct gl_driver_flags *f)
f->NewDefaultTessLevels = ST_NEW_TESS_STATE;
f->NewTextureBuffer = ST_NEW_SAMPLER_VIEWS;
f->NewAtomicBuffer = ST_NEW_ATOMIC_BUFFER;
f->NewShaderStorageBuffer = ST_NEW_STORAGE_BUFFER;
}
struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
......
......@@ -63,6 +63,7 @@ struct u_upload_mgr;
#define ST_NEW_TESSEVAL_PROGRAM (1 << 10)
#define ST_NEW_SAMPLER_VIEWS (1 << 11)
#define ST_NEW_ATOMIC_BUFFER (1 << 12)
#define ST_NEW_STORAGE_BUFFER (1 << 13)
struct st_state_flags {
......
......@@ -220,7 +220,8 @@ void st_init_limits(struct pipe_screen *screen,
pc->MaxAtomicCounters = MAX_ATOMIC_COUNTERS;
pc->MaxAtomicBuffers = screen->get_shader_param(
screen, sh, PIPE_SHADER_CAP_MAX_SHADER_BUFFERS);
screen, sh, PIPE_SHADER_CAP_MAX_SHADER_BUFFERS) / 2;
pc->MaxShaderStorageBlocks = pc->MaxAtomicBuffers;
/* Gallium doesn't really care about local vs. env parameters so use the
* same limits.
......@@ -350,6 +351,17 @@ void st_init_limits(struct pipe_screen *screen,
if (c->MaxCombinedAtomicBuffers > 0)
extensions->ARB_shader_atomic_counters = GL_TRUE;
c->MaxCombinedShaderOutputResources = c->MaxDrawBuffers;
c->ShaderStorageBufferOffsetAlignment =
screen->get_param(screen, PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT);
if (c->ShaderStorageBufferOffsetAlignment) {
c->MaxCombinedShaderStorageBlocks = c->MaxShaderStorageBufferBindings =
c->MaxCombinedAtomicBuffers;
c->MaxCombinedShaderOutputResources +=
c->MaxCombinedShaderStorageBlocks;
c->MaxShaderStorageBlockSize = 1 << 27;
}
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment