#include "pipe/p_context.h"
#include "util/u_memory.h"
#include "util/u_inlines.h"
+#include "util/u_simple_list.h"
+
+#include "rbug/rbug_context.h"
#include "rbug_context.h"
#include "rbug_objects.h"
}
static void
+rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
+{
+
+ if (rb_pipe->draw_blocker & flag) {
+ rb_pipe->draw_blocked |= flag;
+ } else if ((rb_pipe->draw_rule.blocker & flag) &&
+ (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) {
+ int k;
+ boolean block = FALSE;
+ debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
+ (void *) rb_pipe->draw_rule.fs, (void *) rb_pipe->curr.fs,
+ (void *) rb_pipe->draw_rule.vs, (void *) rb_pipe->curr.vs,
+ (void *) rb_pipe->draw_rule.surf, 0,
+ (void *) rb_pipe->draw_rule.texture, 0);
+ if (rb_pipe->draw_rule.fs &&
+ rb_pipe->draw_rule.fs == rb_pipe->curr.fs)
+ block = TRUE;
+ if (rb_pipe->draw_rule.vs &&
+ rb_pipe->draw_rule.vs == rb_pipe->curr.vs)
+ block = TRUE;
+ if (rb_pipe->draw_rule.surf &&
+ rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf)
+ block = TRUE;
+ if (rb_pipe->draw_rule.surf)
+ for (k = 0; k < rb_pipe->curr.nr_cbufs; k++)
+ if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k])
+ block = TRUE;
+ if (rb_pipe->draw_rule.texture) {
+ for (k = 0; k < rb_pipe->curr.num_fs_views; k++)
+ if (rb_pipe->draw_rule.texture == rb_pipe->curr.fs_texs[k])
+ block = TRUE;
+ for (k = 0; k < rb_pipe->curr.num_vs_views; k++) {
+ if (rb_pipe->draw_rule.texture == rb_pipe->curr.vs_texs[k]) {
+ block = TRUE;
+ }
+ }
+ }
+
+ if (block)
+ rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE);
+ }
+
+ if (rb_pipe->draw_blocked)
+ rbug_notify_draw_blocked(rb_pipe);
+
+ /* wait for rbug to clear the blocked flag */
+ while (rb_pipe->draw_blocked & flag) {
+ rb_pipe->draw_blocked |= flag;
+#ifdef PIPE_THREAD_HAVE_CONDVAR
+ pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex);
+#else
+ pipe_mutex_unlock(rb_pipe->draw_mutex);
+#ifdef PIPE_SUBSYSTEM_WINDOWS_USER
+ Sleep(1);
+#endif
+ pipe_mutex_lock(rb_pipe->draw_mutex);
+#endif
+ }
+
+}
+
+static void
rbug_draw_arrays(struct pipe_context *_pipe,
unsigned prim,
unsigned start,
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
+ pipe_mutex_lock(rb_pipe->draw_mutex);
+ rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
+
pipe->draw_arrays(pipe,
prim,
start,
count);
+
+ rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
+ pipe_mutex_unlock(rb_pipe->draw_mutex);
}
static void
struct pipe_context *pipe = rb_pipe->pipe;
struct pipe_resource *indexResource = rb_resource->resource;
+ pipe_mutex_lock(rb_pipe->draw_mutex);
+ rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
+
pipe->draw_elements(pipe,
indexResource,
indexSize,
prim,
start,
count);
+
+ rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
+ pipe_mutex_unlock(rb_pipe->draw_mutex);
}
static void
struct pipe_context *pipe = rb_pipe->pipe;
struct pipe_resource *indexResource = rb_resource->resource;
+ pipe_mutex_lock(rb_pipe->draw_mutex);
+ rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
+
pipe->draw_range_elements(pipe,
indexResource,
indexSize,
mode,
start,
count);
+
+ rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
+ pipe_mutex_unlock(rb_pipe->draw_mutex);
}
static struct pipe_query *
rbug_get_query_result(struct pipe_context *_pipe,
struct pipe_query *query,
boolean wait,
- uint64_t *result)
+ void *result)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
static void *
rbug_create_fs_state(struct pipe_context *_pipe,
- const struct pipe_shader_state *fs)
+ const struct pipe_shader_state *state)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
+ void *result;
+
+ result = pipe->create_fs_state(pipe, state);
+ if (!result)
+ return NULL;
- return pipe->create_fs_state(pipe,
- fs);
+ return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT);
}
static void
rbug_bind_fs_state(struct pipe_context *_pipe,
- void *fs)
+ void *_fs)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
+ void *fs;
+ fs = rbug_shader_unwrap(_fs);
+ rb_pipe->curr.fs = rbug_shader(_fs);
pipe->bind_fs_state(pipe,
fs);
}
static void
rbug_delete_fs_state(struct pipe_context *_pipe,
- void *fs)
+ void *_fs)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
- struct pipe_context *pipe = rb_pipe->pipe;
+ struct rbug_shader *rb_shader = rbug_shader(_fs);
- pipe->delete_fs_state(pipe,
- fs);
+ rbug_shader_destroy(rb_pipe, rb_shader);
}
static void *
rbug_create_vs_state(struct pipe_context *_pipe,
- const struct pipe_shader_state *vs)
+ const struct pipe_shader_state *state)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
+ void *result;
- return pipe->create_vs_state(pipe,
- vs);
+ result = pipe->create_vs_state(pipe, state);
+ if (!result)
+ return NULL;
+
+ return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX);
}
static void
rbug_bind_vs_state(struct pipe_context *_pipe,
- void *vs)
+ void *_vs)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
+ void *vs;
+ vs = rbug_shader_unwrap(_vs);
+ rb_pipe->curr.vs = rbug_shader(_vs);
pipe->bind_vs_state(pipe,
vs);
}
static void
rbug_delete_vs_state(struct pipe_context *_pipe,
- void *vs)
+ void *_vs)
+{
+ struct rbug_context *rb_pipe = rbug_context(_pipe);
+ struct rbug_shader *rb_shader = rbug_shader(_vs);
+
+ rbug_shader_destroy(rb_pipe, rb_shader);
+}
+
+static void *
+rbug_create_gs_state(struct pipe_context *_pipe,
+ const struct pipe_shader_state *state)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
struct pipe_context *pipe = rb_pipe->pipe;
+ void *result;
+
+ result = pipe->create_gs_state(pipe, state);
+ if (!result)
+ return NULL;
- pipe->delete_vs_state(pipe,
- vs);
+ return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM);
}
+static void
+rbug_bind_gs_state(struct pipe_context *_pipe,
+ void *_gs)
+{
+ struct rbug_context *rb_pipe = rbug_context(_pipe);
+ struct pipe_context *pipe = rb_pipe->pipe;
+ void *gs;
+
+ gs = rbug_shader_unwrap(_gs);
+ rb_pipe->curr.gs = rbug_shader(_gs);
+ pipe->bind_gs_state(pipe,
+ gs);
+}
+
+static void
+rbug_delete_gs_state(struct pipe_context *_pipe,
+ void *_gs)
+{
+ struct rbug_context *rb_pipe = rbug_context(_pipe);
+ struct rbug_shader *rb_shader = rbug_shader(_gs);
+
+ rbug_shader_destroy(rb_pipe, rb_shader);
+}
static void *
rbug_create_vertex_elements_state(struct pipe_context *_pipe,
struct pipe_framebuffer_state *state = NULL;
unsigned i;
+ rb_pipe->curr.nr_cbufs = 0;
+ memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs));
+
/* unwrap the input state */
if (_state) {
memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
- for(i = 0; i < _state->nr_cbufs; i++)
+
+ rb_pipe->curr.nr_cbufs = _state->nr_cbufs;
+ for(i = 0; i < _state->nr_cbufs; i++) {
unwrapped_state.cbufs[i] = rbug_surface_unwrap(_state->cbufs[i]);
- for (; i < PIPE_MAX_COLOR_BUFS; i++)
- unwrapped_state.cbufs[i] = NULL;
+ if (_state->cbufs[i])
+ rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture);
+ }
unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf);
state = &unwrapped_state;
}
struct pipe_sampler_view **views = NULL;
unsigned i;
+ rb_pipe->curr.num_fs_views = 0;
+ memset(rb_pipe->curr.fs_views, 0, sizeof(rb_pipe->curr.fs_views));
+ memset(rb_pipe->curr.fs_texs, 0, sizeof(rb_pipe->curr.fs_texs));
+ memset(unwrapped_views, 0, sizeof(unwrapped_views));
+
if (_views) {
- for (i = 0; i < num; i++)
+ rb_pipe->curr.num_fs_views = num;
+ for (i = 0; i < num; i++) {
+ rb_pipe->curr.fs_views[i] = rbug_sampler_view(_views[i]);
+ rb_pipe->curr.fs_texs[i] = rbug_resource(_views[i] ? _views[i]->texture : NULL);
unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
- for (; i < PIPE_MAX_SAMPLERS; i++)
- unwrapped_views[i] = NULL;
-
+ }
views = unwrapped_views;
}
struct pipe_sampler_view **views = NULL;
unsigned i;
+ rb_pipe->curr.num_vs_views = 0;
+ memset(rb_pipe->curr.vs_views, 0, sizeof(rb_pipe->curr.vs_views));
+ memset(rb_pipe->curr.vs_texs, 0, sizeof(rb_pipe->curr.vs_texs));
+ memset(unwrapped_views, 0, sizeof(unwrapped_views));
+
if (_views) {
- for (i = 0; i < num; i++)
+ rb_pipe->curr.num_vs_views = num;
+ for (i = 0; i < num; i++) {
+ rb_pipe->curr.vs_views[i] = rbug_sampler_view(_views[i]);
+ rb_pipe->curr.vs_texs[i] = rbug_resource(_views[i]->texture);
unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
- for (; i < PIPE_MAX_VERTEX_SAMPLERS; i++)
- unwrapped_views[i] = NULL;
-
+ }
views = unwrapped_views;
}
num_buffers,
buffers);
}
+
static void
-rbug_surface_copy(struct pipe_context *_pipe,
- struct pipe_surface *_dst,
- unsigned dstx,
- unsigned dsty,
- struct pipe_surface *_src,
- unsigned srcx,
- unsigned srcy,
- unsigned width,
- unsigned height)
+rbug_set_sample_mask(struct pipe_context *_pipe,
+ unsigned sample_mask)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
- struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
- struct rbug_surface *rb_surface_src = rbug_surface(_src);
struct pipe_context *pipe = rb_pipe->pipe;
- struct pipe_surface *dst = rb_surface_dst->surface;
- struct pipe_surface *src = rb_surface_src->surface;
- pipe->surface_copy(pipe,
- dst,
- dstx,
- dsty,
- src,
- srcx,
- srcy,
- width,
- height);
+ pipe->set_sample_mask(pipe, sample_mask);
}
static void
-rbug_surface_fill(struct pipe_context *_pipe,
- struct pipe_surface *_dst,
- unsigned dstx,
- unsigned dsty,
- unsigned width,
- unsigned height,
- unsigned value)
+rbug_resource_copy_region(struct pipe_context *_pipe,
+ struct pipe_resource *_dst,
+ struct pipe_subresource subdst,
+ unsigned dstx,
+ unsigned dsty,
+ unsigned dstz,
+ struct pipe_resource *_src,
+ struct pipe_subresource subsrc,
+ unsigned srcx,
+ unsigned srcy,
+ unsigned srcz,
+ unsigned width,
+ unsigned height)
{
struct rbug_context *rb_pipe = rbug_context(_pipe);
- struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
+ struct rbug_resource *rb_resource_dst = rbug_resource(_dst);
+ struct rbug_resource *rb_resource_src = rbug_resource(_src);
struct pipe_context *pipe = rb_pipe->pipe;
- struct pipe_surface *dst = rb_surface_dst->surface;
-
- pipe->surface_fill(pipe,
- dst,
- dstx,
- dsty,
- width,
- height,
- value);
+ struct pipe_resource *dst = rb_resource_dst->resource;
+ struct pipe_resource *src = rb_resource_src->resource;
+
+ pipe->resource_copy_region(pipe,
+ dst,
+ subdst,
+ dstx,
+ dsty,
+ dstz,
+ src,
+ subsrc,
+ srcx,
+ srcy,
+ srcz,
+ width,
+ height);
}
static void
}
static void
+rbug_clear_render_target(struct pipe_context *_pipe,
+ struct pipe_surface *_dst,
+ const float *rgba,
+ unsigned dstx, unsigned dsty,
+ unsigned width, unsigned height)
+{
+ struct rbug_context *rb_pipe = rbug_context(_pipe);
+ struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
+ struct pipe_context *pipe = rb_pipe->pipe;
+ struct pipe_surface *dst = rb_surface_dst->surface;
+
+ pipe->clear_render_target(pipe,
+ dst,
+ rgba,
+ dstx,
+ dsty,
+ width,
+ height);
+}
+
+static void
+rbug_clear_depth_stencil(struct pipe_context *_pipe,
+ struct pipe_surface *_dst,
+ unsigned clear_flags,
+ double depth,
+ unsigned stencil,
+ unsigned dstx, unsigned dsty,
+ unsigned width, unsigned height)
+{
+ struct rbug_context *rb_pipe = rbug_context(_pipe);
+ struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
+ struct pipe_context *pipe = rb_pipe->pipe;
+ struct pipe_surface *dst = rb_surface_dst->surface;
+
+ pipe->clear_depth_stencil(pipe,
+ dst,
+ clear_flags,
+ depth,
+ stencil,
+ dstx,
+ dsty,
+ width,
+ height);
+}
+
+static void
rbug_flush(struct pipe_context *_pipe,
unsigned flags,
struct pipe_fence_handle **fence)
rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
{
struct rbug_context *rb_pipe;
- (void)rbug_screen(_screen);
+ struct rbug_screen *rb_screen = rbug_screen(_screen);
+
+ if (!rb_screen)
+ return NULL;
rb_pipe = CALLOC_STRUCT(rbug_context);
- if (!rb_pipe) {
+ if (!rb_pipe)
return NULL;
- }
+
+ pipe_mutex_init(rb_pipe->draw_mutex);
+ pipe_condvar_init(rb_pipe->draw_cond);
+ pipe_mutex_init(rb_pipe->call_mutex);
+ pipe_mutex_init(rb_pipe->list_mutex);
+ make_empty_list(&rb_pipe->shaders);
rb_pipe->base.winsys = NULL;
rb_pipe->base.screen = _screen;
rb_pipe->base.create_vs_state = rbug_create_vs_state;
rb_pipe->base.bind_vs_state = rbug_bind_vs_state;
rb_pipe->base.delete_vs_state = rbug_delete_vs_state;
+ rb_pipe->base.create_gs_state = rbug_create_gs_state;
+ rb_pipe->base.bind_gs_state = rbug_bind_gs_state;
+ rb_pipe->base.delete_gs_state = rbug_delete_gs_state;
rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state;
rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state;
rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state;
rb_pipe->base.set_fragment_sampler_views = rbug_set_fragment_sampler_views;
rb_pipe->base.set_vertex_sampler_views = rbug_set_vertex_sampler_views;
rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers;
- rb_pipe->base.surface_copy = rbug_surface_copy;
- rb_pipe->base.surface_fill = rbug_surface_fill;
+ rb_pipe->base.set_sample_mask = rbug_set_sample_mask;
+ rb_pipe->base.resource_copy_region = rbug_resource_copy_region;
rb_pipe->base.clear = rbug_clear;
+ rb_pipe->base.clear_render_target = rbug_clear_render_target;
+ rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil;
rb_pipe->base.flush = rbug_flush;
rb_pipe->base.is_resource_referenced = rbug_is_resource_referenced;
rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view;
rb_pipe->pipe = pipe;
+ rbug_screen_add_to_list(rb_screen, contexts, rb_pipe);
+
return &rb_pipe->base;
}