/**************************************************************************
*
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* 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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * 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.
/**
* @file
- *
+ *
* Wrap the cso cache & hash mechanisms in a simplified
* pipe-driver-specific interface.
*
- * @author Zack Rusin <zack@tungstengraphics.com>
- * @author Keith Whitwell <keith@tungstengraphics.com>
+ * @author Zack Rusin <zackr@vmware.com>
+ * @author Keith Whitwell <keithw@vmware.com>
*/
#include "pipe/p_state.h"
+#include "util/u_draw.h"
+#include "util/u_framebuffer.h"
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_vbuf.h"
#include "tgsi/tgsi_parse.h"
#include "cso_cache/cso_context.h"
#include "cso_cache/cso_hash.h"
#include "cso_context.h"
-struct cso_context {
- struct pipe_context *pipe;
- struct cso_cache *cache;
+/**
+ * Info related to samplers and sampler views.
+ * We have one of these for fragment samplers and another for vertex samplers.
+ */
+struct sampler_info
+{
struct {
void *samplers[PIPE_MAX_SAMPLERS];
unsigned nr_samplers;
-
- void *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS];
- unsigned nr_vertex_samplers;
} hw;
void *samplers[PIPE_MAX_SAMPLERS];
unsigned nr_samplers;
- void *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS];
- unsigned nr_vertex_samplers;
-
- unsigned nr_samplers_saved;
void *samplers_saved[PIPE_MAX_SAMPLERS];
+ unsigned nr_samplers_saved;
+
+ struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+ unsigned nr_views;
+
+ struct pipe_sampler_view *views_saved[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+ unsigned nr_views_saved;
+};
+
+
- unsigned nr_vertex_samplers_saved;
- void *vertex_samplers_saved[PIPE_MAX_VERTEX_SAMPLERS];
+struct cso_context {
+ struct pipe_context *pipe;
+ struct cso_cache *cache;
+ struct u_vbuf *vbuf;
+
+ boolean has_geometry_shader;
+ boolean has_streamout;
- uint nr_fragment_sampler_views;
- struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
+ struct sampler_info samplers[PIPE_SHADER_TYPES];
- uint nr_vertex_sampler_views;
- struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
+ struct pipe_vertex_buffer aux_vertex_buffer_current;
+ struct pipe_vertex_buffer aux_vertex_buffer_saved;
+ unsigned aux_vertex_buffer_index;
- uint nr_fragment_sampler_views_saved;
- struct pipe_sampler_view *fragment_sampler_views_saved[PIPE_MAX_SAMPLERS];
+ struct pipe_constant_buffer aux_constbuf_current[PIPE_SHADER_TYPES];
+ struct pipe_constant_buffer aux_constbuf_saved[PIPE_SHADER_TYPES];
- uint nr_vertex_sampler_views_saved;
- struct pipe_sampler_view *vertex_sampler_views_saved[PIPE_MAX_VERTEX_SAMPLERS];
+ unsigned nr_so_targets;
+ struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_BUFFERS];
+
+ unsigned nr_so_targets_saved;
+ struct pipe_stream_output_target *so_targets_saved[PIPE_MAX_SO_BUFFERS];
/** Current and saved state.
* The saved state is used as a 1-deep stack.
void *blend, *blend_saved;
void *depth_stencil, *depth_stencil_saved;
void *rasterizer, *rasterizer_saved;
- void *fragment_shader, *fragment_shader_saved, *geometry_shader;
- void *vertex_shader, *vertex_shader_saved, *geometry_shader_saved;
+ void *fragment_shader, *fragment_shader_saved;
+ void *vertex_shader, *vertex_shader_saved;
+ void *geometry_shader, *geometry_shader_saved;
void *velements, *velements_saved;
+ struct pipe_query *render_condition, *render_condition_saved;
+ uint render_condition_mode, render_condition_mode_saved;
+ boolean render_condition_cond, render_condition_cond_saved;
struct pipe_clip_state clip;
struct pipe_clip_state clip_saved;
struct pipe_framebuffer_state fb, fb_saved;
struct pipe_viewport_state vp, vp_saved;
struct pipe_blend_color blend_color;
+ unsigned sample_mask, sample_mask_saved;
+ unsigned min_samples, min_samples_saved;
struct pipe_stencil_ref stencil_ref, stencil_ref_saved;
};
-static void
-free_framebuffer_state(struct pipe_framebuffer_state *fb);
-
-
static boolean delete_blend_state(struct cso_context *ctx, void *state)
{
struct cso_blend *cso = (struct cso_blend *)state;
static boolean delete_depth_stencil_state(struct cso_context *ctx, void *state)
{
- struct cso_depth_stencil_alpha *cso = (struct cso_depth_stencil_alpha *)state;
+ struct cso_depth_stencil_alpha *cso =
+ (struct cso_depth_stencil_alpha *)state;
if (ctx->depth_stencil == cso->data)
return FALSE;
return TRUE;
}
-static boolean delete_fs_state(struct cso_context *ctx, void *state)
-{
- struct cso_fragment_shader *cso = (struct cso_fragment_shader *)state;
- if (ctx->fragment_shader == cso->data)
- return FALSE;
- if (cso->delete_state)
- cso->delete_state(cso->context, cso->data);
- FREE(state);
- return TRUE;
-}
-
-static boolean delete_vs_state(struct cso_context *ctx, void *state)
-{
- struct cso_vertex_shader *cso = (struct cso_vertex_shader *)state;
- if (ctx->vertex_shader == cso->data)
- return TRUE;
- if (cso->delete_state)
- cso->delete_state(cso->context, cso->data);
- FREE(state);
- return FALSE;
-}
-
static boolean delete_vertex_elements(struct cso_context *ctx,
void *state)
{
switch (type) {
case CSO_BLEND:
return delete_blend_state(ctx, state);
- break;
case CSO_SAMPLER:
return delete_sampler_state(ctx, state);
- break;
case CSO_DEPTH_STENCIL_ALPHA:
return delete_depth_stencil_state(ctx, state);
- break;
case CSO_RASTERIZER:
return delete_rasterizer_state(ctx, state);
- break;
- case CSO_FRAGMENT_SHADER:
- return delete_fs_state(ctx, state);
- break;
- case CSO_VERTEX_SHADER:
- return delete_vs_state(ctx, state);
- break;
case CSO_VELEMENTS:
return delete_vertex_elements(ctx, state);
- break;
default:
assert(0);
FREE(state);
return FALSE;
}
-static INLINE void sanitize_hash(struct cso_hash *hash, enum cso_cache_type type,
- int max_size, void *user_data)
+static INLINE void
+sanitize_hash(struct cso_hash *hash, enum cso_cache_type type,
+ int max_size, void *user_data)
{
struct cso_context *ctx = (struct cso_context *)user_data;
/* if we're approach the maximum size, remove fourth of the entries
}
}
+static void cso_init_vbuf(struct cso_context *cso)
+{
+ struct u_vbuf_caps caps;
+
+ /* Install u_vbuf if there is anything unsupported. */
+ if (u_vbuf_get_caps(cso->pipe->screen, &caps)) {
+ cso->vbuf = u_vbuf_create(cso->pipe, &caps,
+ cso->aux_vertex_buffer_index);
+ }
+}
struct cso_context *cso_create_context( struct pipe_context *pipe )
{
ctx);
ctx->pipe = pipe;
+ ctx->sample_mask = ~0;
+
+ ctx->aux_vertex_buffer_index = 0; /* 0 for now */
+
+ cso_init_vbuf(ctx);
/* Enable for testing: */
if (0) cso_set_maximum_cache_size( ctx->cache, 4 );
+ if (pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY,
+ PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
+ ctx->has_geometry_shader = TRUE;
+ }
+ if (pipe->screen->get_param(pipe->screen,
+ PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS) != 0) {
+ ctx->has_streamout = TRUE;
+ }
+
return ctx;
out:
- cso_destroy_context( ctx );
+ cso_destroy_context( ctx );
return NULL;
}
-
/**
* Prior to context destruction, this function unbinds all state objects.
*/
void cso_release_all( struct cso_context *ctx )
{
- unsigned i;
-
+ unsigned i, shader;
+
if (ctx->pipe) {
ctx->pipe->bind_blend_state( ctx->pipe, NULL );
ctx->pipe->bind_rasterizer_state( ctx->pipe, NULL );
- ctx->pipe->bind_fragment_sampler_states( ctx->pipe, 0, NULL );
- if (ctx->pipe->bind_vertex_sampler_states)
- ctx->pipe->bind_vertex_sampler_states(ctx->pipe, 0, NULL);
+
+ {
+ static struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS] = { NULL };
+ static void *zeros[PIPE_MAX_SAMPLERS] = { NULL };
+ struct pipe_screen *scr = ctx->pipe->screen;
+ unsigned sh;
+ for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
+ int maxsam = scr->get_shader_param(scr, sh,
+ PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS);
+ int maxview = scr->get_shader_param(scr, sh,
+ PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS);
+ assert(maxsam <= PIPE_MAX_SAMPLERS);
+ assert(maxview <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
+ if (maxsam > 0) {
+ ctx->pipe->bind_sampler_states(ctx->pipe, sh, 0, maxsam, zeros);
+ }
+ if (maxview > 0) {
+ ctx->pipe->set_sampler_views(ctx->pipe, sh, 0, maxview, views);
+ }
+ }
+ }
+
ctx->pipe->bind_depth_stencil_alpha_state( ctx->pipe, NULL );
ctx->pipe->bind_fs_state( ctx->pipe, NULL );
ctx->pipe->bind_vs_state( ctx->pipe, NULL );
ctx->pipe->bind_vertex_elements_state( ctx->pipe, NULL );
+
+ if (ctx->has_streamout)
+ ctx->pipe->set_stream_output_targets(ctx->pipe, 0, NULL, NULL);
}
- for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
- pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL);
- pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i], NULL);
+ /* free fragment sampler views */
+ for (shader = 0; shader < Elements(ctx->samplers); shader++) {
+ struct sampler_info *info = &ctx->samplers[shader];
+ for (i = 0; i < PIPE_MAX_SHADER_SAMPLER_VIEWS; i++) {
+ pipe_sampler_view_reference(&info->views[i], NULL);
+ pipe_sampler_view_reference(&info->views_saved[i], NULL);
+ }
}
- for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
- pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL);
- pipe_sampler_view_reference(&ctx->vertex_sampler_views_saved[i], NULL);
+ util_unreference_framebuffer_state(&ctx->fb);
+ util_unreference_framebuffer_state(&ctx->fb_saved);
+
+ pipe_resource_reference(&ctx->aux_vertex_buffer_current.buffer, NULL);
+ pipe_resource_reference(&ctx->aux_vertex_buffer_saved.buffer, NULL);
+
+ for (i = 0; i < PIPE_SHADER_TYPES; i++) {
+ pipe_resource_reference(&ctx->aux_constbuf_current[i].buffer, NULL);
+ pipe_resource_reference(&ctx->aux_constbuf_saved[i].buffer, NULL);
}
- free_framebuffer_state(&ctx->fb);
- free_framebuffer_state(&ctx->fb_saved);
+ for (i = 0; i < PIPE_MAX_SO_BUFFERS; i++) {
+ pipe_so_target_reference(&ctx->so_targets[i], NULL);
+ pipe_so_target_reference(&ctx->so_targets_saved[i], NULL);
+ }
if (ctx->cache) {
cso_cache_delete( ctx->cache );
}
+/**
+ * Free the CSO context. NOTE: the state tracker should have previously called
+ * cso_release_all().
+ */
void cso_destroy_context( struct cso_context *ctx )
{
if (ctx) {
- /*cso_release_all( ctx );*/
+ if (ctx->vbuf)
+ u_vbuf_destroy(ctx->vbuf);
FREE( ctx );
}
}
struct cso_hash_iter iter;
void *handle;
- key_size = templ->independent_blend_enable ? sizeof(struct pipe_blend_state) :
- (char *)&(templ->rt[1]) - (char *)templ;
+ key_size = templ->independent_blend_enable ?
+ sizeof(struct pipe_blend_state) :
+ (char *)&(templ->rt[1]) - (char *)templ;
hash_key = cso_construct_key((void*)templ, key_size);
- iter = cso_find_state_template(ctx->cache, hash_key, CSO_BLEND, (void*)templ, key_size);
+ iter = cso_find_state_template(ctx->cache, hash_key, CSO_BLEND,
+ (void*)templ, key_size);
if (cso_hash_iter_is_null(iter)) {
struct cso_blend *cso = MALLOC(sizeof(struct cso_blend));
if (!cso)
return PIPE_ERROR_OUT_OF_MEMORY;
+ memset(&cso->state, 0, sizeof cso->state);
memcpy(&cso->state, templ, key_size);
cso->data = ctx->pipe->create_blend_state(ctx->pipe, &cso->state);
cso->delete_state = (cso_state_callback)ctx->pipe->delete_blend_state;
-enum pipe_error cso_single_sampler(struct cso_context *ctx,
- unsigned idx,
- const struct pipe_sampler_state *templ)
-{
- void *handle = NULL;
-
- if (templ != NULL) {
- unsigned key_size = sizeof(struct pipe_sampler_state);
- unsigned hash_key = cso_construct_key((void*)templ, key_size);
- struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
- hash_key, CSO_SAMPLER,
- (void*)templ, key_size);
-
- if (cso_hash_iter_is_null(iter)) {
- struct cso_sampler *cso = MALLOC(sizeof(struct cso_sampler));
- if (!cso)
- return PIPE_ERROR_OUT_OF_MEMORY;
-
- memcpy(&cso->state, templ, sizeof(*templ));
- cso->data = ctx->pipe->create_sampler_state(ctx->pipe, &cso->state);
- cso->delete_state = (cso_state_callback)ctx->pipe->delete_sampler_state;
- cso->context = ctx->pipe;
-
- iter = cso_insert_state(ctx->cache, hash_key, CSO_SAMPLER, cso);
- if (cso_hash_iter_is_null(iter)) {
- FREE(cso);
- return PIPE_ERROR_OUT_OF_MEMORY;
- }
-
- handle = cso->data;
- }
- else {
- handle = ((struct cso_sampler *)cso_hash_iter_data(iter))->data;
- }
- }
-
- ctx->samplers[idx] = handle;
- return PIPE_OK;
-}
-
enum pipe_error
-cso_single_vertex_sampler(struct cso_context *ctx,
- unsigned idx,
- const struct pipe_sampler_state *templ)
-{
- void *handle = NULL;
-
- if (templ != NULL) {
- unsigned key_size = sizeof(struct pipe_sampler_state);
- unsigned hash_key = cso_construct_key((void*)templ, key_size);
- struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
- hash_key, CSO_SAMPLER,
- (void*)templ, key_size);
-
- if (cso_hash_iter_is_null(iter)) {
- struct cso_sampler *cso = MALLOC(sizeof(struct cso_sampler));
- if (!cso)
- return PIPE_ERROR_OUT_OF_MEMORY;
-
- memcpy(&cso->state, templ, sizeof(*templ));
- cso->data = ctx->pipe->create_sampler_state(ctx->pipe, &cso->state);
- cso->delete_state = (cso_state_callback)ctx->pipe->delete_sampler_state;
- cso->context = ctx->pipe;
-
- iter = cso_insert_state(ctx->cache, hash_key, CSO_SAMPLER, cso);
- if (cso_hash_iter_is_null(iter)) {
- FREE(cso);
- return PIPE_ERROR_OUT_OF_MEMORY;
- }
-
- handle = cso->data;
- }
- else {
- handle = ((struct cso_sampler *)cso_hash_iter_data(iter))->data;
- }
- }
-
- ctx->vertex_samplers[idx] = handle;
- return PIPE_OK;
-}
-
-void cso_single_sampler_done( struct cso_context *ctx )
-{
- unsigned i;
-
- /* find highest non-null sampler */
- for (i = PIPE_MAX_SAMPLERS; i > 0; i--) {
- if (ctx->samplers[i - 1] != NULL)
- break;
- }
-
- ctx->nr_samplers = i;
-
- if (ctx->hw.nr_samplers != ctx->nr_samplers ||
- memcmp(ctx->hw.samplers,
- ctx->samplers,
- ctx->nr_samplers * sizeof(void *)) != 0)
- {
- memcpy(ctx->hw.samplers, ctx->samplers, ctx->nr_samplers * sizeof(void *));
- ctx->hw.nr_samplers = ctx->nr_samplers;
-
- ctx->pipe->bind_fragment_sampler_states(ctx->pipe, ctx->nr_samplers, ctx->samplers);
- }
-}
-
-void
-cso_single_vertex_sampler_done(struct cso_context *ctx)
-{
- unsigned i;
-
- /* find highest non-null sampler */
- for (i = PIPE_MAX_VERTEX_SAMPLERS; i > 0; i--) {
- if (ctx->vertex_samplers[i - 1] != NULL)
- break;
- }
-
- ctx->nr_vertex_samplers = i;
-
- if (ctx->hw.nr_vertex_samplers != ctx->nr_vertex_samplers ||
- memcmp(ctx->hw.vertex_samplers,
- ctx->vertex_samplers,
- ctx->nr_vertex_samplers * sizeof(void *)) != 0)
- {
- memcpy(ctx->hw.vertex_samplers,
- ctx->vertex_samplers,
- ctx->nr_vertex_samplers * sizeof(void *));
- ctx->hw.nr_vertex_samplers = ctx->nr_vertex_samplers;
-
- ctx->pipe->bind_vertex_sampler_states(ctx->pipe,
- ctx->nr_vertex_samplers,
- ctx->vertex_samplers);
- }
-}
-
-/*
- * If the function encouters any errors it will return the
- * last one. Done to always try to set as many samplers
- * as possible.
- */
-enum pipe_error cso_set_samplers( struct cso_context *ctx,
- unsigned nr,
- const struct pipe_sampler_state **templates )
-{
- unsigned i;
- enum pipe_error temp, error = PIPE_OK;
-
- /* TODO: fastpath
- */
-
- for (i = 0; i < nr; i++) {
- temp = cso_single_sampler( ctx, i, templates[i] );
- if (temp != PIPE_OK)
- error = temp;
- }
-
- for ( ; i < ctx->nr_samplers; i++) {
- temp = cso_single_sampler( ctx, i, NULL );
- if (temp != PIPE_OK)
- error = temp;
- }
-
- cso_single_sampler_done( ctx );
-
- return error;
-}
-
-void cso_save_samplers(struct cso_context *ctx)
-{
- ctx->nr_samplers_saved = ctx->nr_samplers;
- memcpy(ctx->samplers_saved, ctx->samplers, sizeof(ctx->samplers));
-}
-
-void cso_restore_samplers(struct cso_context *ctx)
-{
- ctx->nr_samplers = ctx->nr_samplers_saved;
- memcpy(ctx->samplers, ctx->samplers_saved, sizeof(ctx->samplers));
- cso_single_sampler_done( ctx );
-}
-
-/*
- * If the function encouters any errors it will return the
- * last one. Done to always try to set as many samplers
- * as possible.
- */
-enum pipe_error cso_set_vertex_samplers(struct cso_context *ctx,
- unsigned nr,
- const struct pipe_sampler_state **templates)
-{
- unsigned i;
- enum pipe_error temp, error = PIPE_OK;
-
- /* TODO: fastpath
- */
-
- for (i = 0; i < nr; i++) {
- temp = cso_single_vertex_sampler( ctx, i, templates[i] );
- if (temp != PIPE_OK)
- error = temp;
- }
-
- for ( ; i < ctx->nr_samplers; i++) {
- temp = cso_single_vertex_sampler( ctx, i, NULL );
- if (temp != PIPE_OK)
- error = temp;
- }
-
- cso_single_vertex_sampler_done( ctx );
-
- return error;
-}
-
-void
-cso_save_vertex_samplers(struct cso_context *ctx)
-{
- ctx->nr_vertex_samplers_saved = ctx->nr_vertex_samplers;
- memcpy(ctx->vertex_samplers_saved, ctx->vertex_samplers, sizeof(ctx->vertex_samplers));
-}
-
-void
-cso_restore_vertex_samplers(struct cso_context *ctx)
-{
- ctx->nr_vertex_samplers = ctx->nr_vertex_samplers_saved;
- memcpy(ctx->vertex_samplers, ctx->vertex_samplers_saved, sizeof(ctx->vertex_samplers));
- cso_single_vertex_sampler_done(ctx);
-}
-
-
-enum pipe_error cso_set_depth_stencil_alpha(struct cso_context *ctx,
- const struct pipe_depth_stencil_alpha_state *templ)
+cso_set_depth_stencil_alpha(struct cso_context *ctx,
+ const struct pipe_depth_stencil_alpha_state *templ)
{
unsigned key_size = sizeof(struct pipe_depth_stencil_alpha_state);
unsigned hash_key = cso_construct_key((void*)templ, key_size);
struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
- hash_key,
+ hash_key,
CSO_DEPTH_STENCIL_ALPHA,
(void*)templ, key_size);
void *handle;
if (cso_hash_iter_is_null(iter)) {
- struct cso_depth_stencil_alpha *cso = MALLOC(sizeof(struct cso_depth_stencil_alpha));
+ struct cso_depth_stencil_alpha *cso =
+ MALLOC(sizeof(struct cso_depth_stencil_alpha));
if (!cso)
return PIPE_ERROR_OUT_OF_MEMORY;
memcpy(&cso->state, templ, sizeof(*templ));
- cso->data = ctx->pipe->create_depth_stencil_alpha_state(ctx->pipe, &cso->state);
- cso->delete_state = (cso_state_callback)ctx->pipe->delete_depth_stencil_alpha_state;
+ cso->data = ctx->pipe->create_depth_stencil_alpha_state(ctx->pipe,
+ &cso->state);
+ cso->delete_state =
+ (cso_state_callback)ctx->pipe->delete_depth_stencil_alpha_state;
cso->context = ctx->pipe;
- iter = cso_insert_state(ctx->cache, hash_key, CSO_DEPTH_STENCIL_ALPHA, cso);
+ iter = cso_insert_state(ctx->cache, hash_key,
+ CSO_DEPTH_STENCIL_ALPHA, cso);
if (cso_hash_iter_is_null(iter)) {
FREE(cso);
return PIPE_ERROR_OUT_OF_MEMORY;
handle = cso->data;
}
else {
- handle = ((struct cso_depth_stencil_alpha *)cso_hash_iter_data(iter))->data;
+ handle = ((struct cso_depth_stencil_alpha *)
+ cso_hash_iter_data(iter))->data;
}
if (ctx->depth_stencil != handle) {
{
if (ctx->depth_stencil != ctx->depth_stencil_saved) {
ctx->depth_stencil = ctx->depth_stencil_saved;
- ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, ctx->depth_stencil_saved);
+ ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe,
+ ctx->depth_stencil_saved);
}
ctx->depth_stencil_saved = NULL;
}
unsigned key_size = sizeof(struct pipe_rasterizer_state);
unsigned hash_key = cso_construct_key((void*)templ, key_size);
struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
- hash_key, CSO_RASTERIZER,
+ hash_key,
+ CSO_RASTERIZER,
(void*)templ, key_size);
void *handle = NULL;
memcpy(&cso->state, templ, sizeof(*templ));
cso->data = ctx->pipe->create_rasterizer_state(ctx->pipe, &cso->state);
- cso->delete_state = (cso_state_callback)ctx->pipe->delete_rasterizer_state;
+ cso->delete_state =
+ (cso_state_callback)ctx->pipe->delete_rasterizer_state;
cso->context = ctx->pipe;
iter = cso_insert_state(ctx->cache, hash_key, CSO_RASTERIZER, cso);
}
-
-enum pipe_error cso_set_fragment_shader_handle(struct cso_context *ctx,
- void *handle )
+void cso_set_fragment_shader_handle(struct cso_context *ctx, void *handle )
{
if (ctx->fragment_shader != handle) {
ctx->fragment_shader = handle;
ctx->pipe->bind_fs_state(ctx->pipe, handle);
}
- return PIPE_OK;
}
void cso_delete_fragment_shader(struct cso_context *ctx, void *handle )
ctx->pipe->delete_fs_state(ctx->pipe, handle);
}
-/* Not really working:
- */
-#if 0
-enum pipe_error cso_set_fragment_shader(struct cso_context *ctx,
- const struct pipe_shader_state *templ)
-{
- const struct tgsi_token *tokens = templ->tokens;
- unsigned num_tokens = tgsi_num_tokens(tokens);
- size_t tokens_size = num_tokens*sizeof(struct tgsi_token);
- unsigned hash_key = cso_construct_key((void*)tokens, tokens_size);
- struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
- hash_key,
- CSO_FRAGMENT_SHADER,
- (void*)tokens,
- sizeof(*templ)); /* XXX correct? tokens_size? */
- void *handle = NULL;
-
- if (cso_hash_iter_is_null(iter)) {
- struct cso_fragment_shader *cso = MALLOC(sizeof(struct cso_fragment_shader) + tokens_size);
- struct tgsi_token *cso_tokens = (struct tgsi_token *)((char *)cso + sizeof(*cso));
-
- if (!cso)
- return PIPE_ERROR_OUT_OF_MEMORY;
-
- memcpy(cso_tokens, tokens, tokens_size);
- cso->state.tokens = cso_tokens;
- cso->data = ctx->pipe->create_fs_state(ctx->pipe, &cso->state);
- cso->delete_state = (cso_state_callback)ctx->pipe->delete_fs_state;
- cso->context = ctx->pipe;
-
- iter = cso_insert_state(ctx->cache, hash_key, CSO_FRAGMENT_SHADER, cso);
- if (cso_hash_iter_is_null(iter)) {
- FREE(cso);
- return PIPE_ERROR_OUT_OF_MEMORY;
- }
-
- handle = cso->data;
- }
- else {
- handle = ((struct cso_fragment_shader *)cso_hash_iter_data(iter))->data;
- }
-
- return cso_set_fragment_shader_handle( ctx, handle );
-}
-#endif
-
void cso_save_fragment_shader(struct cso_context *ctx)
{
assert(!ctx->fragment_shader_saved);
}
-enum pipe_error cso_set_vertex_shader_handle(struct cso_context *ctx,
- void *handle )
+void cso_set_vertex_shader_handle(struct cso_context *ctx, void *handle)
{
if (ctx->vertex_shader != handle) {
ctx->vertex_shader = handle;
ctx->pipe->bind_vs_state(ctx->pipe, handle);
}
- return PIPE_OK;
}
void cso_delete_vertex_shader(struct cso_context *ctx, void *handle )
ctx->pipe->delete_vs_state(ctx->pipe, handle);
}
-
-/* Not really working:
- */
-#if 0
-enum pipe_error cso_set_vertex_shader(struct cso_context *ctx,
- const struct pipe_shader_state *templ)
+void cso_save_vertex_shader(struct cso_context *ctx)
{
- unsigned hash_key = cso_construct_key((void*)templ,
- sizeof(struct pipe_shader_state));
- struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
- hash_key, CSO_VERTEX_SHADER,
- (void*)templ,
- sizeof(*templ));
- void *handle = NULL;
-
- if (cso_hash_iter_is_null(iter)) {
- struct cso_vertex_shader *cso = MALLOC(sizeof(struct cso_vertex_shader));
-
- if (!cso)
- return PIPE_ERROR_OUT_OF_MEMORY;
-
- memcpy(cso->state, templ, sizeof(*templ));
- cso->data = ctx->pipe->create_vs_state(ctx->pipe, &cso->state);
- cso->delete_state = (cso_state_callback)ctx->pipe->delete_vs_state;
- cso->context = ctx->pipe;
-
- iter = cso_insert_state(ctx->cache, hash_key, CSO_VERTEX_SHADER, cso);
- if (cso_hash_iter_is_null(iter)) {
- FREE(cso);
- return PIPE_ERROR_OUT_OF_MEMORY;
- }
-
- handle = cso->data;
- }
- else {
- handle = ((struct cso_vertex_shader *)cso_hash_iter_data(iter))->data;
- }
-
- return cso_set_vertex_shader_handle( ctx, handle );
-}
-#endif
-
-
-
-void cso_save_vertex_shader(struct cso_context *ctx)
-{
- assert(!ctx->vertex_shader_saved);
- ctx->vertex_shader_saved = ctx->vertex_shader;
-}
+ assert(!ctx->vertex_shader_saved);
+ ctx->vertex_shader_saved = ctx->vertex_shader;
+}
void cso_restore_vertex_shader(struct cso_context *ctx)
{
}
-/**
- * Copy framebuffer state from src to dst with refcounting of surfaces.
- */
-static void
-copy_framebuffer_state(struct pipe_framebuffer_state *dst,
- const struct pipe_framebuffer_state *src)
-{
- uint i;
-
- dst->width = src->width;
- dst->height = src->height;
- dst->nr_cbufs = src->nr_cbufs;
- for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
- pipe_surface_reference(&dst->cbufs[i], src->cbufs[i]);
- }
- pipe_surface_reference(&dst->zsbuf, src->zsbuf);
-}
-
-
-static void
-free_framebuffer_state(struct pipe_framebuffer_state *fb)
-{
- uint i;
-
- for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
- pipe_surface_reference(&fb->cbufs[i], NULL);
- }
- pipe_surface_reference(&fb->zsbuf, NULL);
-}
-
-
-enum pipe_error cso_set_framebuffer(struct cso_context *ctx,
- const struct pipe_framebuffer_state *fb)
+void cso_set_framebuffer(struct cso_context *ctx,
+ const struct pipe_framebuffer_state *fb)
{
if (memcmp(&ctx->fb, fb, sizeof(*fb)) != 0) {
- copy_framebuffer_state(&ctx->fb, fb);
+ util_copy_framebuffer_state(&ctx->fb, fb);
ctx->pipe->set_framebuffer_state(ctx->pipe, fb);
}
- return PIPE_OK;
}
void cso_save_framebuffer(struct cso_context *ctx)
{
- copy_framebuffer_state(&ctx->fb_saved, &ctx->fb);
+ util_copy_framebuffer_state(&ctx->fb_saved, &ctx->fb);
}
void cso_restore_framebuffer(struct cso_context *ctx)
{
if (memcmp(&ctx->fb, &ctx->fb_saved, sizeof(ctx->fb))) {
- copy_framebuffer_state(&ctx->fb, &ctx->fb_saved);
+ util_copy_framebuffer_state(&ctx->fb, &ctx->fb_saved);
ctx->pipe->set_framebuffer_state(ctx->pipe, &ctx->fb);
- free_framebuffer_state(&ctx->fb_saved);
+ util_unreference_framebuffer_state(&ctx->fb_saved);
}
}
-enum pipe_error cso_set_viewport(struct cso_context *ctx,
- const struct pipe_viewport_state *vp)
+void cso_set_viewport(struct cso_context *ctx,
+ const struct pipe_viewport_state *vp)
{
if (memcmp(&ctx->vp, vp, sizeof(*vp))) {
ctx->vp = *vp;
- ctx->pipe->set_viewport_state(ctx->pipe, vp);
+ ctx->pipe->set_viewport_states(ctx->pipe, 0, 1, vp);
}
- return PIPE_OK;
}
void cso_save_viewport(struct cso_context *ctx)
{
if (memcmp(&ctx->vp, &ctx->vp_saved, sizeof(ctx->vp))) {
ctx->vp = ctx->vp_saved;
- ctx->pipe->set_viewport_state(ctx->pipe, &ctx->vp);
+ ctx->pipe->set_viewport_states(ctx->pipe, 0, 1, &ctx->vp);
}
}
-enum pipe_error cso_set_blend_color(struct cso_context *ctx,
- const struct pipe_blend_color *bc)
+void cso_set_blend_color(struct cso_context *ctx,
+ const struct pipe_blend_color *bc)
{
if (memcmp(&ctx->blend_color, bc, sizeof(ctx->blend_color))) {
ctx->blend_color = *bc;
ctx->pipe->set_blend_color(ctx->pipe, bc);
}
- return PIPE_OK;
}
-enum pipe_error cso_set_stencil_ref(struct cso_context *ctx,
- const struct pipe_stencil_ref *sr)
+void cso_set_sample_mask(struct cso_context *ctx, unsigned sample_mask)
+{
+ if (ctx->sample_mask != sample_mask) {
+ ctx->sample_mask = sample_mask;
+ ctx->pipe->set_sample_mask(ctx->pipe, sample_mask);
+ }
+}
+
+void cso_save_sample_mask(struct cso_context *ctx)
+{
+ ctx->sample_mask_saved = ctx->sample_mask;
+}
+
+void cso_restore_sample_mask(struct cso_context *ctx)
+{
+ cso_set_sample_mask(ctx, ctx->sample_mask_saved);
+}
+
+void cso_set_min_samples(struct cso_context *ctx, unsigned min_samples)
+{
+ if (ctx->min_samples != min_samples && ctx->pipe->set_min_samples) {
+ ctx->min_samples = min_samples;
+ ctx->pipe->set_min_samples(ctx->pipe, min_samples);
+ }
+}
+
+void cso_save_min_samples(struct cso_context *ctx)
+{
+ ctx->min_samples_saved = ctx->min_samples;
+}
+
+void cso_restore_min_samples(struct cso_context *ctx)
+{
+ cso_set_min_samples(ctx, ctx->min_samples_saved);
+}
+
+void cso_set_stencil_ref(struct cso_context *ctx,
+ const struct pipe_stencil_ref *sr)
{
if (memcmp(&ctx->stencil_ref, sr, sizeof(ctx->stencil_ref))) {
ctx->stencil_ref = *sr;
ctx->pipe->set_stencil_ref(ctx->pipe, sr);
}
- return PIPE_OK;
}
void cso_save_stencil_ref(struct cso_context *ctx)
void cso_restore_stencil_ref(struct cso_context *ctx)
{
- if (memcmp(&ctx->stencil_ref, &ctx->stencil_ref_saved, sizeof(ctx->stencil_ref))) {
+ if (memcmp(&ctx->stencil_ref, &ctx->stencil_ref_saved,
+ sizeof(ctx->stencil_ref))) {
ctx->stencil_ref = ctx->stencil_ref_saved;
ctx->pipe->set_stencil_ref(ctx->pipe, &ctx->stencil_ref);
}
}
-enum pipe_error cso_set_geometry_shader_handle(struct cso_context *ctx,
- void *handle)
+void cso_set_render_condition(struct cso_context *ctx,
+ struct pipe_query *query,
+ boolean condition, uint mode)
{
- if (ctx->geometry_shader != handle) {
+ struct pipe_context *pipe = ctx->pipe;
+
+ if (ctx->render_condition != query ||
+ ctx->render_condition_mode != mode ||
+ ctx->render_condition_cond != condition) {
+ pipe->render_condition(pipe, query, condition, mode);
+ ctx->render_condition = query;
+ ctx->render_condition_cond = condition;
+ ctx->render_condition_mode = mode;
+ }
+}
+
+void cso_save_render_condition(struct cso_context *ctx)
+{
+ ctx->render_condition_saved = ctx->render_condition;
+ ctx->render_condition_cond_saved = ctx->render_condition_cond;
+ ctx->render_condition_mode_saved = ctx->render_condition_mode;
+}
+
+void cso_restore_render_condition(struct cso_context *ctx)
+{
+ cso_set_render_condition(ctx, ctx->render_condition_saved,
+ ctx->render_condition_cond_saved,
+ ctx->render_condition_mode_saved);
+}
+
+void cso_set_geometry_shader_handle(struct cso_context *ctx, void *handle)
+{
+ assert(ctx->has_geometry_shader || !handle);
+
+ if (ctx->has_geometry_shader && ctx->geometry_shader != handle) {
ctx->geometry_shader = handle;
ctx->pipe->bind_gs_state(ctx->pipe, handle);
}
- return PIPE_OK;
}
void cso_delete_geometry_shader(struct cso_context *ctx, void *handle)
void cso_save_geometry_shader(struct cso_context *ctx)
{
+ if (!ctx->has_geometry_shader) {
+ return;
+ }
+
assert(!ctx->geometry_shader_saved);
ctx->geometry_shader_saved = ctx->geometry_shader;
}
void cso_restore_geometry_shader(struct cso_context *ctx)
{
+ if (!ctx->has_geometry_shader) {
+ return;
+ }
+
if (ctx->geometry_shader_saved != ctx->geometry_shader) {
ctx->pipe->bind_gs_state(ctx->pipe, ctx->geometry_shader_saved);
ctx->geometry_shader = ctx->geometry_shader_saved;
clip_state_cpy(struct pipe_clip_state *dst,
const struct pipe_clip_state *src)
{
- dst->nr = src->nr;
- if (src->nr) {
- memcpy(dst->ucp, src->ucp, src->nr * sizeof(src->ucp[0]));
- }
+ memcpy(dst->ucp, src->ucp, sizeof(dst->ucp));
}
static INLINE int
clip_state_cmp(const struct pipe_clip_state *a,
const struct pipe_clip_state *b)
{
- if (a->nr != b->nr) {
- return 1;
- }
- if (a->nr) {
- return memcmp(a->ucp, b->ucp, a->nr * sizeof(a->ucp[0]));
- }
- return 0;
+ return memcmp(a->ucp, b->ucp, sizeof(a->ucp));
}
void
}
}
-enum pipe_error cso_set_vertex_elements(struct cso_context *ctx,
- unsigned count,
- const struct pipe_vertex_element *states)
+enum pipe_error
+cso_set_vertex_elements(struct cso_context *ctx,
+ unsigned count,
+ const struct pipe_vertex_element *states)
{
+ struct u_vbuf *vbuf = ctx->vbuf;
unsigned key_size, hash_key;
struct cso_hash_iter iter;
void *handle;
struct cso_velems_state velems_state;
- /* need to include the count into the stored state data too.
- Otherwise first few count pipe_vertex_elements could be identical even if count
- is different, and there's no guarantee the hash would be different in that
- case neither */
+ if (vbuf) {
+ u_vbuf_set_vertex_elements(vbuf, count, states);
+ return PIPE_OK;
+ }
+
+ /* Need to include the count into the stored state data too.
+ * Otherwise first few count pipe_vertex_elements could be identical
+ * even if count is different, and there's no guarantee the hash would
+ * be different in that case neither.
+ */
key_size = sizeof(struct pipe_vertex_element) * count + sizeof(unsigned);
velems_state.count = count;
- memcpy(velems_state.velems, states, sizeof(struct pipe_vertex_element) * count);
+ memcpy(velems_state.velems, states,
+ sizeof(struct pipe_vertex_element) * count);
hash_key = cso_construct_key((void*)&velems_state, key_size);
- iter = cso_find_state_template(ctx->cache, hash_key, CSO_VELEMENTS, (void*)&velems_state, key_size);
+ iter = cso_find_state_template(ctx->cache, hash_key, CSO_VELEMENTS,
+ (void*)&velems_state, key_size);
if (cso_hash_iter_is_null(iter)) {
struct cso_velements *cso = MALLOC(sizeof(struct cso_velements));
return PIPE_ERROR_OUT_OF_MEMORY;
memcpy(&cso->state, &velems_state, key_size);
- cso->data = ctx->pipe->create_vertex_elements_state(ctx->pipe, count, &cso->state.velems[0]);
- cso->delete_state = (cso_state_callback)ctx->pipe->delete_vertex_elements_state;
+ cso->data = ctx->pipe->create_vertex_elements_state(ctx->pipe, count,
+ &cso->state.velems[0]);
+ cso->delete_state =
+ (cso_state_callback) ctx->pipe->delete_vertex_elements_state;
cso->context = ctx->pipe;
iter = cso_insert_state(ctx->cache, hash_key, CSO_VELEMENTS, cso);
void cso_save_vertex_elements(struct cso_context *ctx)
{
+ struct u_vbuf *vbuf = ctx->vbuf;
+
+ if (vbuf) {
+ u_vbuf_save_vertex_elements(vbuf);
+ return;
+ }
+
assert(!ctx->velements_saved);
ctx->velements_saved = ctx->velements;
}
void cso_restore_vertex_elements(struct cso_context *ctx)
{
+ struct u_vbuf *vbuf = ctx->vbuf;
+
+ if (vbuf) {
+ u_vbuf_restore_vertex_elements(vbuf);
+ return;
+ }
+
if (ctx->velements != ctx->velements_saved) {
ctx->velements = ctx->velements_saved;
ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->velements_saved);
ctx->velements_saved = NULL;
}
-/* fragment sampler view state */
+/* vertex buffers */
+
+void cso_set_vertex_buffers(struct cso_context *ctx,
+ unsigned start_slot, unsigned count,
+ const struct pipe_vertex_buffer *buffers)
+{
+ struct u_vbuf *vbuf = ctx->vbuf;
+
+ if (vbuf) {
+ u_vbuf_set_vertex_buffers(vbuf, start_slot, count, buffers);
+ return;
+ }
+
+ /* Save what's in the auxiliary slot, so that we can save and restore it
+ * for meta ops. */
+ if (start_slot <= ctx->aux_vertex_buffer_index &&
+ start_slot+count > ctx->aux_vertex_buffer_index) {
+ if (buffers) {
+ const struct pipe_vertex_buffer *vb =
+ buffers + (ctx->aux_vertex_buffer_index - start_slot);
+
+ pipe_resource_reference(&ctx->aux_vertex_buffer_current.buffer,
+ vb->buffer);
+ memcpy(&ctx->aux_vertex_buffer_current, vb,
+ sizeof(struct pipe_vertex_buffer));
+ }
+ else {
+ pipe_resource_reference(&ctx->aux_vertex_buffer_current.buffer,
+ NULL);
+ ctx->aux_vertex_buffer_current.user_buffer = NULL;
+ }
+ }
+
+ ctx->pipe->set_vertex_buffers(ctx->pipe, start_slot, count, buffers);
+}
+
+void cso_save_aux_vertex_buffer_slot(struct cso_context *ctx)
+{
+ struct u_vbuf *vbuf = ctx->vbuf;
+
+ if (vbuf) {
+ u_vbuf_save_aux_vertex_buffer_slot(vbuf);
+ return;
+ }
+
+ pipe_resource_reference(&ctx->aux_vertex_buffer_saved.buffer,
+ ctx->aux_vertex_buffer_current.buffer);
+ memcpy(&ctx->aux_vertex_buffer_saved, &ctx->aux_vertex_buffer_current,
+ sizeof(struct pipe_vertex_buffer));
+}
+
+void cso_restore_aux_vertex_buffer_slot(struct cso_context *ctx)
+{
+ struct u_vbuf *vbuf = ctx->vbuf;
+
+ if (vbuf) {
+ u_vbuf_restore_aux_vertex_buffer_slot(vbuf);
+ return;
+ }
+
+ cso_set_vertex_buffers(ctx, ctx->aux_vertex_buffer_index, 1,
+ &ctx->aux_vertex_buffer_saved);
+ pipe_resource_reference(&ctx->aux_vertex_buffer_saved.buffer, NULL);
+}
+
+unsigned cso_get_aux_vertex_buffer_slot(struct cso_context *ctx)
+{
+ return ctx->aux_vertex_buffer_index;
+}
+
+
+/**************** fragment/vertex sampler view state *************************/
+
+static enum pipe_error
+single_sampler(struct cso_context *ctx,
+ struct sampler_info *info,
+ unsigned idx,
+ const struct pipe_sampler_state *templ)
+{
+ void *handle = NULL;
+
+ if (templ != NULL) {
+ unsigned key_size = sizeof(struct pipe_sampler_state);
+ unsigned hash_key = cso_construct_key((void*)templ, key_size);
+ struct cso_hash_iter iter =
+ cso_find_state_template(ctx->cache,
+ hash_key, CSO_SAMPLER,
+ (void *) templ, key_size);
+
+ if (cso_hash_iter_is_null(iter)) {
+ struct cso_sampler *cso = MALLOC(sizeof(struct cso_sampler));
+ if (!cso)
+ return PIPE_ERROR_OUT_OF_MEMORY;
+
+ memcpy(&cso->state, templ, sizeof(*templ));
+ cso->data = ctx->pipe->create_sampler_state(ctx->pipe, &cso->state);
+ cso->delete_state =
+ (cso_state_callback) ctx->pipe->delete_sampler_state;
+ cso->context = ctx->pipe;
+
+ iter = cso_insert_state(ctx->cache, hash_key, CSO_SAMPLER, cso);
+ if (cso_hash_iter_is_null(iter)) {
+ FREE(cso);
+ return PIPE_ERROR_OUT_OF_MEMORY;
+ }
+
+ handle = cso->data;
+ }
+ else {
+ handle = ((struct cso_sampler *)cso_hash_iter_data(iter))->data;
+ }
+ }
+
+ info->samplers[idx] = handle;
+
+ return PIPE_OK;
+}
+
+enum pipe_error
+cso_single_sampler(struct cso_context *ctx,
+ unsigned shader_stage,
+ unsigned idx,
+ const struct pipe_sampler_state *templ)
+{
+ return single_sampler(ctx, &ctx->samplers[shader_stage], idx, templ);
+}
+
+
+
+static void
+single_sampler_done(struct cso_context *ctx, unsigned shader_stage)
+{
+ struct sampler_info *info = &ctx->samplers[shader_stage];
+ unsigned i;
+
+ /* find highest non-null sampler */
+ for (i = PIPE_MAX_SAMPLERS; i > 0; i--) {
+ if (info->samplers[i - 1] != NULL)
+ break;
+ }
+
+ info->nr_samplers = i;
+
+ if (info->hw.nr_samplers != info->nr_samplers ||
+ memcmp(info->hw.samplers,
+ info->samplers,
+ info->nr_samplers * sizeof(void *)) != 0)
+ {
+ memcpy(info->hw.samplers,
+ info->samplers,
+ info->nr_samplers * sizeof(void *));
+
+ /* set remaining slots/pointers to null */
+ for (i = info->nr_samplers; i < info->hw.nr_samplers; i++)
+ info->samplers[i] = NULL;
+
+ ctx->pipe->bind_sampler_states(ctx->pipe, shader_stage, 0,
+ MAX2(info->nr_samplers,
+ info->hw.nr_samplers),
+ info->samplers);
+
+ info->hw.nr_samplers = info->nr_samplers;
+ }
+}
void
-cso_set_fragment_sampler_views(struct cso_context *cso,
- uint count,
- struct pipe_sampler_view **views)
+cso_single_sampler_done(struct cso_context *ctx, unsigned shader_stage)
{
- uint i;
+ single_sampler_done(ctx, shader_stage);
+}
+
+
+/*
+ * If the function encouters any errors it will return the
+ * last one. Done to always try to set as many samplers
+ * as possible.
+ */
+enum pipe_error
+cso_set_samplers(struct cso_context *ctx,
+ unsigned shader_stage,
+ unsigned nr,
+ const struct pipe_sampler_state **templates)
+{
+ struct sampler_info *info = &ctx->samplers[shader_stage];
+ unsigned i;
+ enum pipe_error temp, error = PIPE_OK;
+
+ /* TODO: fastpath
+ */
+
+ for (i = 0; i < nr; i++) {
+ temp = single_sampler(ctx, info, i, templates[i]);
+ if (temp != PIPE_OK)
+ error = temp;
+ }
+
+ for ( ; i < info->nr_samplers; i++) {
+ temp = single_sampler(ctx, info, i, NULL);
+ if (temp != PIPE_OK)
+ error = temp;
+ }
+
+ single_sampler_done(ctx, shader_stage);
+
+ return error;
+}
+
+void
+cso_save_samplers(struct cso_context *ctx, unsigned shader_stage)
+{
+ struct sampler_info *info = &ctx->samplers[shader_stage];
+ info->nr_samplers_saved = info->nr_samplers;
+ memcpy(info->samplers_saved, info->samplers, sizeof(info->samplers));
+}
+
+
+void
+cso_restore_samplers(struct cso_context *ctx, unsigned shader_stage)
+{
+ struct sampler_info *info = &ctx->samplers[shader_stage];
+ info->nr_samplers = info->nr_samplers_saved;
+ memcpy(info->samplers, info->samplers_saved, sizeof(info->samplers));
+ single_sampler_done(ctx, shader_stage);
+}
+
+void
+cso_set_sampler_views(struct cso_context *ctx,
+ unsigned shader_stage,
+ unsigned count,
+ struct pipe_sampler_view **views)
+{
+ struct sampler_info *info = &ctx->samplers[shader_stage];
+ unsigned i;
+ boolean any_change = FALSE;
+
+ /* reference new views */
for (i = 0; i < count; i++) {
- pipe_sampler_view_reference(&cso->fragment_sampler_views[i], views[i]);
+ any_change |= info->views[i] != views[i];
+ pipe_sampler_view_reference(&info->views[i], views[i]);
}
- for (; i < cso->nr_fragment_sampler_views; i++) {
- pipe_sampler_view_reference(&cso->fragment_sampler_views[i], NULL);
+ /* unref extra old views, if any */
+ for (; i < info->nr_views; i++) {
+ any_change |= info->views[i] != NULL;
+ pipe_sampler_view_reference(&info->views[i], NULL);
}
- cso->pipe->set_fragment_sampler_views(cso->pipe,
- MAX2(count, cso->nr_fragment_sampler_views),
- cso->fragment_sampler_views);
+ /* bind the new sampler views */
+ if (any_change) {
+ ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0,
+ MAX2(info->nr_views, count),
+ info->views);
+ }
- cso->nr_fragment_sampler_views = count;
+ info->nr_views = count;
}
+
void
-cso_save_fragment_sampler_views(struct cso_context *cso)
+cso_save_sampler_views(struct cso_context *ctx, unsigned shader_stage)
{
- uint i;
+ struct sampler_info *info = &ctx->samplers[shader_stage];
+ unsigned i;
- cso->nr_fragment_sampler_views_saved = cso->nr_fragment_sampler_views;
+ info->nr_views_saved = info->nr_views;
- for (i = 0; i < cso->nr_fragment_sampler_views; i++) {
- assert(!cso->fragment_sampler_views_saved[i]);
+ for (i = 0; i < info->nr_views; i++) {
+ assert(!info->views_saved[i]);
+ pipe_sampler_view_reference(&info->views_saved[i], info->views[i]);
+ }
+}
+
+
+void
+cso_restore_sampler_views(struct cso_context *ctx, unsigned shader_stage)
+{
+ struct sampler_info *info = &ctx->samplers[shader_stage];
+ unsigned i, nr_saved = info->nr_views_saved;
+ unsigned num;
- pipe_sampler_view_reference(&cso->fragment_sampler_views_saved[i],
- cso->fragment_sampler_views[i]);
+ for (i = 0; i < nr_saved; i++) {
+ pipe_sampler_view_reference(&info->views[i], NULL);
+ /* move the reference from one pointer to another */
+ info->views[i] = info->views_saved[i];
+ info->views_saved[i] = NULL;
}
+ for (; i < info->nr_views; i++) {
+ pipe_sampler_view_reference(&info->views[i], NULL);
+ }
+
+ num = MAX2(info->nr_views, nr_saved);
+
+ /* bind the old/saved sampler views */
+ ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0, num, info->views);
+
+ info->nr_views = nr_saved;
+ info->nr_views_saved = 0;
}
+
void
-cso_restore_fragment_sampler_views(struct cso_context *cso)
+cso_set_stream_outputs(struct cso_context *ctx,
+ unsigned num_targets,
+ struct pipe_stream_output_target **targets,
+ const unsigned *offsets)
{
+ struct pipe_context *pipe = ctx->pipe;
uint i;
- for (i = 0; i < cso->nr_fragment_sampler_views_saved; i++) {
- pipe_sampler_view_reference(&cso->fragment_sampler_views[i], cso->fragment_sampler_views_saved[i]);
- pipe_sampler_view_reference(&cso->fragment_sampler_views_saved[i], NULL);
+ if (!ctx->has_streamout) {
+ assert(num_targets == 0);
+ return;
}
- for (; i < cso->nr_fragment_sampler_views; i++) {
- pipe_sampler_view_reference(&cso->fragment_sampler_views[i], NULL);
+
+ if (ctx->nr_so_targets == 0 && num_targets == 0) {
+ /* Nothing to do. */
+ return;
}
- cso->pipe->set_fragment_sampler_views(cso->pipe,
- MAX2(cso->nr_fragment_sampler_views, cso->nr_fragment_sampler_views_saved),
- cso->fragment_sampler_views);
+ /* reference new targets */
+ for (i = 0; i < num_targets; i++) {
+ pipe_so_target_reference(&ctx->so_targets[i], targets[i]);
+ }
+ /* unref extra old targets, if any */
+ for (; i < ctx->nr_so_targets; i++) {
+ pipe_so_target_reference(&ctx->so_targets[i], NULL);
+ }
- cso->nr_fragment_sampler_views = cso->nr_fragment_sampler_views_saved;
- cso->nr_fragment_sampler_views_saved = 0;
+ pipe->set_stream_output_targets(pipe, num_targets, targets,
+ offsets);
+ ctx->nr_so_targets = num_targets;
}
+void
+cso_save_stream_outputs(struct cso_context *ctx)
+{
+ uint i;
+
+ if (!ctx->has_streamout) {
+ return;
+ }
-/* vertex sampler view state */
+ ctx->nr_so_targets_saved = ctx->nr_so_targets;
+
+ for (i = 0; i < ctx->nr_so_targets; i++) {
+ assert(!ctx->so_targets_saved[i]);
+ pipe_so_target_reference(&ctx->so_targets_saved[i], ctx->so_targets[i]);
+ }
+}
void
-cso_set_vertex_sampler_views(struct cso_context *cso,
- uint count,
- struct pipe_sampler_view **views)
+cso_restore_stream_outputs(struct cso_context *ctx)
{
+ struct pipe_context *pipe = ctx->pipe;
uint i;
+ unsigned offset[PIPE_MAX_SO_BUFFERS];
- for (i = 0; i < count; i++) {
- pipe_sampler_view_reference(&cso->vertex_sampler_views[i], views[i]);
+ if (!ctx->has_streamout) {
+ return;
+ }
+
+ if (ctx->nr_so_targets == 0 && ctx->nr_so_targets_saved == 0) {
+ /* Nothing to do. */
+ return;
+ }
+
+ assert(ctx->nr_so_targets_saved <= PIPE_MAX_SO_BUFFERS);
+ for (i = 0; i < ctx->nr_so_targets_saved; i++) {
+ pipe_so_target_reference(&ctx->so_targets[i], NULL);
+ /* move the reference from one pointer to another */
+ ctx->so_targets[i] = ctx->so_targets_saved[i];
+ ctx->so_targets_saved[i] = NULL;
+ /* -1 means append */
+ offset[i] = (unsigned)-1;
}
- for (; i < cso->nr_vertex_sampler_views; i++) {
- pipe_sampler_view_reference(&cso->vertex_sampler_views[i], NULL);
+ for (; i < ctx->nr_so_targets; i++) {
+ pipe_so_target_reference(&ctx->so_targets[i], NULL);
}
- cso->pipe->set_vertex_sampler_views(cso->pipe,
- MAX2(count, cso->nr_vertex_sampler_views),
- cso->vertex_sampler_views);
+ pipe->set_stream_output_targets(pipe, ctx->nr_so_targets_saved,
+ ctx->so_targets, offset);
- cso->nr_vertex_sampler_views = count;
+ ctx->nr_so_targets = ctx->nr_so_targets_saved;
+ ctx->nr_so_targets_saved = 0;
}
+/* constant buffers */
+
void
-cso_save_vertex_sampler_views(struct cso_context *cso)
+cso_set_constant_buffer(struct cso_context *cso, unsigned shader_stage,
+ unsigned index, struct pipe_constant_buffer *cb)
{
- uint i;
+ struct pipe_context *pipe = cso->pipe;
- cso->nr_vertex_sampler_views_saved = cso->nr_vertex_sampler_views;
+ pipe->set_constant_buffer(pipe, shader_stage, index, cb);
- for (i = 0; i < cso->nr_vertex_sampler_views; i++) {
- assert(!cso->vertex_sampler_views_saved[i]);
+ if (index == 0) {
+ util_copy_constant_buffer(&cso->aux_constbuf_current[shader_stage], cb);
+ }
+}
- pipe_sampler_view_reference(&cso->vertex_sampler_views_saved[i],
- cso->vertex_sampler_views[i]);
+void
+cso_set_constant_buffer_resource(struct cso_context *cso,
+ unsigned shader_stage,
+ unsigned index,
+ struct pipe_resource *buffer)
+{
+ if (buffer) {
+ struct pipe_constant_buffer cb;
+ cb.buffer = buffer;
+ cb.buffer_offset = 0;
+ cb.buffer_size = buffer->width0;
+ cb.user_buffer = NULL;
+ cso_set_constant_buffer(cso, shader_stage, index, &cb);
+ } else {
+ cso_set_constant_buffer(cso, shader_stage, index, NULL);
}
}
void
-cso_restore_vertex_sampler_views(struct cso_context *cso)
+cso_save_constant_buffer_slot0(struct cso_context *cso,
+ unsigned shader_stage)
{
- uint i;
+ util_copy_constant_buffer(&cso->aux_constbuf_saved[shader_stage],
+ &cso->aux_constbuf_current[shader_stage]);
+}
+
+void
+cso_restore_constant_buffer_slot0(struct cso_context *cso,
+ unsigned shader_stage)
+{
+ cso_set_constant_buffer(cso, shader_stage, 0,
+ &cso->aux_constbuf_saved[shader_stage]);
+ pipe_resource_reference(&cso->aux_constbuf_saved[shader_stage].buffer,
+ NULL);
+}
+
+/* drawing */
+
+void
+cso_set_index_buffer(struct cso_context *cso,
+ const struct pipe_index_buffer *ib)
+{
+ struct u_vbuf *vbuf = cso->vbuf;
- for (i = 0; i < cso->nr_vertex_sampler_views_saved; i++) {
- pipe_sampler_view_reference(&cso->vertex_sampler_views[i], cso->vertex_sampler_views_saved[i]);
- pipe_sampler_view_reference(&cso->vertex_sampler_views_saved[i], NULL);
+ if (vbuf) {
+ u_vbuf_set_index_buffer(vbuf, ib);
+ } else {
+ struct pipe_context *pipe = cso->pipe;
+ pipe->set_index_buffer(pipe, ib);
}
- for (; i < cso->nr_vertex_sampler_views; i++) {
- pipe_sampler_view_reference(&cso->vertex_sampler_views[i], NULL);
+}
+
+void
+cso_draw_vbo(struct cso_context *cso,
+ const struct pipe_draw_info *info)
+{
+ struct u_vbuf *vbuf = cso->vbuf;
+
+ if (vbuf) {
+ u_vbuf_draw_vbo(vbuf, info);
+ } else {
+ struct pipe_context *pipe = cso->pipe;
+ pipe->draw_vbo(pipe, info);
}
+}
+
+void
+cso_draw_arrays(struct cso_context *cso, uint mode, uint start, uint count)
+{
+ struct pipe_draw_info info;
+
+ util_draw_init_info(&info);
+
+ info.mode = mode;
+ info.start = start;
+ info.count = count;
+ info.min_index = start;
+ info.max_index = start + count - 1;
+
+ cso_draw_vbo(cso, &info);
+}
+
+void
+cso_draw_arrays_instanced(struct cso_context *cso, uint mode,
+ uint start, uint count,
+ uint start_instance, uint instance_count)
+{
+ struct pipe_draw_info info;
+
+ util_draw_init_info(&info);
- cso->pipe->set_vertex_sampler_views(cso->pipe,
- MAX2(cso->nr_vertex_sampler_views, cso->nr_vertex_sampler_views_saved),
- cso->vertex_sampler_views);
+ info.mode = mode;
+ info.start = start;
+ info.count = count;
+ info.min_index = start;
+ info.max_index = start + count - 1;
+ info.start_instance = start_instance;
+ info.instance_count = instance_count;
- cso->nr_vertex_sampler_views = cso->nr_vertex_sampler_views_saved;
- cso->nr_vertex_sampler_views_saved = 0;
+ cso_draw_vbo(cso, &info);
}