From c0bb4ba9e665e40a325d82aa2ee48d7b8abd603b Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 22 Aug 2007 12:24:51 -0600 Subject: Rework of shader constant buffers. They're now totally independent of the actual shaders. Also, implemented in terms of pipe_buffer_handles/objects. --- src/mesa/pipe/softpipe/sp_context.c | 1 + src/mesa/pipe/softpipe/sp_context.h | 7 ++++++- src/mesa/pipe/softpipe/sp_draw_arrays.c | 31 +++++++++++++++++++++++++++++++ src/mesa/pipe/softpipe/sp_quad_fs.c | 3 ++- src/mesa/pipe/softpipe/sp_state.h | 4 ++++ src/mesa/pipe/softpipe/sp_state_fs.c | 25 ++++++++++++++++++++++++- 6 files changed, 68 insertions(+), 3 deletions(-) (limited to 'src/mesa/pipe/softpipe') diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index ab9becc99e..5404b7f790 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -237,6 +237,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.set_blend_state = softpipe_set_blend_state; softpipe->pipe.set_clip_state = softpipe_set_clip_state; softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state; + softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer; softpipe->pipe.set_depth_state = softpipe_set_depth_test_state; softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_fs_state = softpipe_set_fs_state; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 14ae9f2105..6458573917 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -33,6 +33,7 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" +#include "pipe/p_defines.h" #include "sp_quad.h" @@ -64,6 +65,7 @@ enum interp_mode { #define SP_NEW_STENCIL 0x1000 #define SP_NEW_VERTEX 0x2000 #define SP_NEW_VS 0x4000 +#define SP_NEW_CONSTANTS 0x8000 struct softpipe_context { @@ -78,6 +80,7 @@ struct softpipe_context { struct pipe_blend_color blend_color; struct pipe_clear_color_state clear_color; struct pipe_clip_state clip; + struct pipe_constant_buffer constants[2]; struct pipe_depth_state depth_test; struct pipe_framebuffer_state framebuffer; struct pipe_shader_state fs; @@ -105,7 +108,9 @@ struct softpipe_context { * Mapped vertex buffers */ ubyte *mapped_vbuffer[PIPE_ATTRIB_MAX]; - + + /** Mapped constant buffers */ + void *mapped_constants[PIPE_SHADER_TYPES]; /* FS + setup derived state: */ diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index 0392b6b64e..5198a493da 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -43,6 +43,34 @@ +static void +softpipe_map_constant_buffers(struct softpipe_context *sp) +{ + struct pipe_winsys *ws = sp->pipe.winsys; + uint i; + for (i = 0; i < 2; i++) { + if (sp->constants[i].size) + sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer, + PIPE_BUFFER_FLAG_READ); + } + + draw_set_mapped_constant_buffer(sp->draw, + sp->mapped_constants[PIPE_SHADER_VERTEX]); +} + +static void +softpipe_unmap_constant_buffers(struct softpipe_context *sp) +{ + struct pipe_winsys *ws = sp->pipe.winsys; + uint i; + for (i = 0; i < 2; i++) { + if (sp->constants[i].size) + ws->buffer_unmap(ws, sp->constants[i].buffer); + sp->mapped_constants[i] = NULL; + } +} + + boolean softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, unsigned count) @@ -81,6 +109,8 @@ softpipe_draw_elements(struct pipe_context *pipe, softpipe_map_surfaces(sp); + softpipe_map_constant_buffers(sp); + /* * Map vertex buffers */ @@ -123,6 +153,7 @@ softpipe_draw_elements(struct pipe_context *pipe, } softpipe_unmap_surfaces(sp); + softpipe_unmap_constant_buffers(sp); return TRUE; } diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index c20f09d309..ceba94aa94 100755 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -33,6 +33,7 @@ */ #include "pipe/p_util.h" +#include "pipe/p_defines.h" #include "sp_context.h" #include "sp_headers.h" @@ -83,7 +84,7 @@ shade_quad( qss->samplers ); /* Consts does not require 16 byte alignment. */ - machine.Consts = softpipe->fs.constants->constant; + machine.Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT]; machine.Inputs = ALIGN16_ASSIGN(inputs); machine.Outputs = ALIGN16_ASSIGN(outputs); diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 5e1ecd94e0..354580b2a5 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -52,6 +52,10 @@ void softpipe_set_clear_color_state( struct pipe_context *, void softpipe_set_clip_state( struct pipe_context *, const struct pipe_clip_state * ); +void softpipe_set_constant_buffer(struct pipe_context *, + uint shader, uint index, + const struct pipe_constant_buffer *buf); + void softpipe_set_depth_test_state( struct pipe_context *, const struct pipe_depth_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index bab407f047..9e3ff6d35c 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -28,6 +28,8 @@ #include "sp_context.h" #include "sp_state.h" +#include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "pipe/draw/draw_context.h" @@ -53,3 +55,24 @@ void softpipe_set_vs_state( struct pipe_context *pipe, draw_set_vertex_shader(softpipe->draw, vs); } + + +void softpipe_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + const struct pipe_constant_buffer *buf) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct pipe_winsys *ws = pipe->winsys; + + assert(shader < PIPE_SHADER_TYPES); + assert(index == 0); + + /* note: reference counting */ + ws->buffer_unreference(ws, &softpipe->constants[shader].buffer); + softpipe->constants[shader].buffer = ws->buffer_reference(ws, buf->buffer); + softpipe->constants[shader].size = buf->size; + + softpipe->dirty |= SP_NEW_CONSTANTS; +} + + -- cgit v1.2.3