From 9f95af6c4997fc947e9dbdaa4efcbb999e9a48de Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Fri, 24 Jun 2011 20:51:11 +0200 Subject: g/d/remote: rename tr_ to remote_ --- src/gallium/drivers/remote/remote_comms.c | 2 +- src/gallium/drivers/remote/remote_context.c | 1463 +++++++++++++++++++++++++++ src/gallium/drivers/remote/remote_context.h | 70 ++ src/gallium/drivers/remote/remote_screen.c | 663 ++++++++++++ src/gallium/drivers/remote/remote_screen.h | 97 ++ src/gallium/drivers/remote/tr_context.c | 1463 --------------------------- src/gallium/drivers/remote/tr_context.h | 70 -- src/gallium/drivers/remote/tr_screen.c | 663 ------------ src/gallium/drivers/remote/tr_screen.h | 97 -- 9 files changed, 2294 insertions(+), 2294 deletions(-) create mode 100644 src/gallium/drivers/remote/remote_context.c create mode 100644 src/gallium/drivers/remote/remote_context.h create mode 100644 src/gallium/drivers/remote/remote_screen.c create mode 100644 src/gallium/drivers/remote/remote_screen.h delete mode 100644 src/gallium/drivers/remote/tr_context.c delete mode 100644 src/gallium/drivers/remote/tr_context.h delete mode 100644 src/gallium/drivers/remote/tr_screen.c delete mode 100644 src/gallium/drivers/remote/tr_screen.h diff --git a/src/gallium/drivers/remote/remote_comms.c b/src/gallium/drivers/remote/remote_comms.c index bc50cf0374..9f8efb5c1c 100644 --- a/src/gallium/drivers/remote/remote_comms.c +++ b/src/gallium/drivers/remote/remote_comms.c @@ -10,7 +10,7 @@ #include "pipe/p_compiler.h" #include "winsys_bindings.h" -#include "tr_screen.h" +#include "remote_screen.h" #include "remote_messages.h" #include "remote_comms.h" #include "remote_debug.h" diff --git a/src/gallium/drivers/remote/remote_context.c b/src/gallium/drivers/remote/remote_context.c new file mode 100644 index 0000000000..765da14bc2 --- /dev/null +++ b/src/gallium/drivers/remote/remote_context.c @@ -0,0 +1,1463 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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 "util/u_memory.h" +#include "util/u_inlines.h" + +#include "tgsi/tgsi_parse.h" + +#include "pipe/p_screen.h" +#include "pipe/p_shader_tokens.h" + +#include "pipe/p_format.h" +#include "pipe/p_screen.h" + +#include "remote_screen.h" +#include "remote_context.h" +#include "remote_comms.h" +#include "remote_state.h" +#include "remote_util.h" +#include "remote_messages.h" +#include "remote_debug.h" + +static INLINE void +remote_context_set_edgeflags(struct pipe_context *_pipe, + const unsigned *bitfield) +{ + + if(bitfield) { + DBG("Set edge flags: %u\n", *bitfield); + } + else { + DBG("Set edge flags: null\n"); + } + + ALLOC_OUT_MESSAGE(set_edgeflags, message); + + message->base.opcode = REMREQ_SET_EDGEFLAGS; + message->pipe = PIPE_HANDLE(_pipe); + if(bitfield) { + message->isnull = 0; + message->flag = *bitfield; + } + else { + message->isnull = 1; + } + + enqueue_message(message); + +} + +static INLINE void mark_surface_dirty(struct pipe_surface* surf) { + + struct remote_texture* rtex = (struct remote_texture*)surf->texture; + + if(!rtex) { + debug_printf("!!! Surface with no texture encountered\n"); + } + else { + struct remote_buffer* rbuf = (struct remote_buffer*)rtex->backing_buffer; + rbuf->remote_dirty = 1; + } + +} + +static INLINE void mark_framebuffer_dirty(struct pipe_context* pipe) { + + struct remote_context* rctx = (struct remote_context*)pipe; + + for(int i = 0; i < rctx->current_framebuffer_state.nr_cbufs; i++) + if(rctx->current_framebuffer_state.cbufs[i]) + mark_surface_dirty(rctx->current_framebuffer_state.cbufs[i]); + + if(rctx->current_framebuffer_state.zsbuf) + mark_surface_dirty(rctx->current_framebuffer_state.zsbuf); + +} + +static INLINE boolean +remote_context_draw_arrays(struct pipe_context *_pipe, + unsigned mode, unsigned start, unsigned count) +{ + + DBG("Draw arrays: mode %u, start %u, count %u\n", mode, start, count); + + mark_framebuffer_dirty(_pipe); + + ALLOC_OUT_MESSAGE(draw_arrays, message); + + message->base.opcode = REMREQ_DRAW_ARRAYS; + message->pipe = PIPE_HANDLE(_pipe); + message->mode = mode; + message->start = start; + message->count = count; + + enqueue_message(message); + + return true; + /* + QUEUE_AND_WAIT(message, draw_arrays, reply); + PANIC_IF_NULL(reply); + + boolean success = reply->success; + + free_message(reply); + + return success; + */ + +} + + +static INLINE boolean +remote_context_draw_elements(struct pipe_context *_pipe, + struct pipe_resource *indexBuffer, + unsigned indexSize, + unsigned mode, unsigned start, unsigned count) + +{ + + DBG("Draw elements: using index buffer %u, size %u, mode %u, start %u, count %u\n", BUFFER_HANDLE(indexBuffer), indexSize, mode, start, count); + + mark_framebuffer_dirty(_pipe); + + ALLOC_OUT_MESSAGE(draw_elements, message); + + message->base.opcode = REMREQ_DRAW_ELEMENTS; + message->pipe = PIPE_HANDLE(_pipe); + message->buffer = BUFFER_HANDLE(indexBuffer); + message->indexSize = indexSize; + message->mode = mode; + message->start = start; + message->count = count; + + enqueue_message(message); + + return true; + + /* + QUEUE_AND_WAIT(message, draw_elements, reply); + PANIC_IF_NULL(reply); + + boolean success = reply->success; + free_message(reply); + + return success; + */ + +} + + +static INLINE boolean +remote_context_draw_range_elements(struct pipe_context *_pipe, + struct pipe_resource *indexBuffer, + unsigned indexSize, + unsigned minIndex, + unsigned maxIndex, + unsigned mode, + unsigned start, + unsigned count) +{ + + DBG("Draw range elements: using index buffer %u, size %u, mode %u, start %u, count %u, limits %u/%u\n", BUFFER_HANDLE(indexBuffer), indexSize, mode, start, count, minIndex, maxIndex); + + mark_framebuffer_dirty(_pipe); + + ALLOC_OUT_MESSAGE(draw_range_elements, message); + + message->base.opcode = REMREQ_DRAW_RANGE_ELEMENTS; + message->pipe = PIPE_HANDLE(_pipe); + message->buffer = BUFFER_HANDLE(indexBuffer); + message->indexSize = indexSize; + message->minIndex = minIndex; + message->maxIndex = maxIndex; + message->mode = mode; + message->start = start; + message->count = count; + + enqueue_message(message); + return true; + + /* + QUEUE_AND_WAIT(message, draw_range_elements, reply); + + PANIC_IF_NULL(reply); + + boolean success = reply->success; + free_message(reply); + + return success; + */ + +} + +static INLINE void +remote_context_draw_vbo(struct pipe_context *_pipe, + const struct pipe_draw_info *info) +{ +#if 0 + ALLOC_OUT_MESSAGE(draw_vbo, message); + + message->base.opcode = REMREQ_DRAW_VBO; +#endif + DBG("Draw VBO info->mode %x\n", handle, info->mode); +} + +static INLINE struct pipe_query * +remote_context_create_query(struct pipe_context *_pipe, + unsigned query_type) +{ + +// Despite appearances, pipe_query is actually an opaque struct. + + ALLOC_OUT_MESSAGE(create_query, message); + + message->base.opcode = REMREQ_CREATE_QUERY; + message->pipe = PIPE_HANDLE(_pipe); + message->query_type = query_type; + + uint32_t handle = get_fresh_query_handle(_pipe->screen); + + DBG("New query %u, type %x\n", handle, query_type); + + message->handle = handle; + + enqueue_message(message); + + struct remote_pipe_query* opaque = CALLOC_STRUCT(remote_pipe_query); + + PANIC_IF_NULL(opaque); + + opaque->handle = handle; + + return (struct pipe_query*)opaque; + +} + + +static INLINE void +remote_context_destroy_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + + DBG("Destroy query %u\n", QUERY_HANDLE(query)); + + ALLOC_OUT_MESSAGE(destroy_query, message); + + message->base.opcode = REMREQ_DESTROY_QUERY; + message->pipe = PIPE_HANDLE(_pipe); + message->query = QUERY_HANDLE(query); + + enqueue_message(message); + +} + + +static INLINE void +remote_context_begin_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + + DBG("Begin query %u\n", QUERY_HANDLE(query)); + + ALLOC_OUT_MESSAGE(begin_query, message); + + message->base.opcode = REMREQ_BEGIN_QUERY; + message->pipe = PIPE_HANDLE(_pipe); + message->query = QUERY_HANDLE(query); + + enqueue_message(message); + +} + + +static INLINE void +remote_context_end_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + + DBG("End query %u\n", QUERY_HANDLE(query)); + + ALLOC_OUT_MESSAGE(end_query, message); + + message->base.opcode = REMREQ_END_QUERY; + message->pipe = PIPE_HANDLE(_pipe); + message->query = QUERY_HANDLE(query); + + enqueue_message(message); + +} + + +static INLINE boolean +remote_context_get_query_result(struct pipe_context *_pipe, + struct pipe_query *query, + boolean wait, + void *presult) +{ + + DBG("Get query result for query %u\n", QUERY_HANDLE(query)); + + ALLOC_OUT_MESSAGE(get_query_result, message); + + message->base.opcode = REMREQ_GET_QUERY_RESULT; + message->pipe = PIPE_HANDLE(_pipe); + message->query = QUERY_HANDLE(query); + message->wait = wait; + + QUEUE_AND_WAIT(message, get_query_result, reply); + + if(reply) { + (*(uint64_t*)presult) = reply->result; + DBG("Query result: %lu\n", reply->result); + boolean done = reply->done; + free_message(reply); + return done; + } + else { + debug_printf("!!! Got a null reply to get_query_result\n"); + exit(1); + } + +} + + +static INLINE void * +remote_context_create_blend_state(struct pipe_context *_pipe, + const struct pipe_blend_state *state) +{ + ALLOC_OUT_MESSAGE(create_blend_state, message); + + message->base.opcode = REMREQ_CREATE_BLEND_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + uint32_t handle = get_fresh_blend_handle(_pipe->screen); + message->handle = handle; + + DBG("Create blend state %u\n", handle); + + enqueue_message(message); + + struct remote_opaque_blend_state* remote_blend = CALLOC_STRUCT(remote_opaque_blend_state); + + PANIC_IF_NULL(remote_blend); + remote_blend->handle = handle; + return remote_blend; +} + + +static INLINE void +remote_context_bind_blend_state(struct pipe_context *_pipe, + void *state) +{ + + DBG("Bind blend state %u\n", BLEND_HANDLE(state)); + + ALLOC_OUT_MESSAGE(bind_blend_state, message); + + message->base.opcode = REMREQ_BIND_BLEND_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->blend_handle = BLEND_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void +remote_context_delete_blend_state(struct pipe_context *_pipe, + void *state) +{ + DBG("Delete blend state %u\n", BLEND_HANDLE(state)); + + ALLOC_OUT_MESSAGE(delete_blend_state, message); + + message->base.opcode = REMREQ_DELETE_BLEND_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->blend_handle = BLEND_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void * +remote_context_create_sampler_state(struct pipe_context *_pipe, + const struct pipe_sampler_state *state) +{ + + ALLOC_OUT_MESSAGE(create_sampler_state, message); + + message->base.opcode = REMREQ_CREATE_SAMPLER_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + uint32_t handle = get_fresh_sampler_handle(_pipe->screen); + message->handle = handle; + + DBG("Create new sampler state %u\n", handle); + + enqueue_message(message); + + struct remote_opaque_sampler_state* remote_sampler = CALLOC_STRUCT(remote_opaque_sampler_state); + + PANIC_IF_NULL(remote_sampler); + remote_sampler->handle = handle; + return remote_sampler; + +} + + +static INLINE void +remote_context_bind_sampler_states(struct pipe_context *_pipe, + unsigned num_states, void **states) +{ + + DBG("Bind sampler states: %u states\n", num_states); + + struct remreq_bind_sampler_state* header = + allocate_message_memory( + sizeof(struct remreq_bind_sampler_state) + + (num_states * sizeof(uint32_t))); + + header->base.opcode = REMREQ_BIND_SAMPLER_STATE; + header->pipe = PIPE_HANDLE(_pipe); + header->nstates = num_states; + + uint32_t* state_handles = + (uint32_t*)((char*)header + sizeof(struct remreq_bind_sampler_state)); + unsigned i; + for(i = 0; i < num_states; i++) { + state_handles[i] = SAMPLER_HANDLE(states[i]); + } + + enqueue_message(header); +} + + +static INLINE void +remote_context_delete_sampler_state(struct pipe_context *_pipe, + void *state) +{ + + DBG("Delete sampler state %u\n", SAMPLER_HANDLE(state)); + + ALLOC_OUT_MESSAGE(delete_sampler_state, message); + + message->base.opcode = REMREQ_DELETE_SAMPLER_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->sampler_handle = SAMPLER_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void * +remote_context_create_rasterizer_state(struct pipe_context *_pipe, + const struct pipe_rasterizer_state *state) +{ + + ALLOC_OUT_MESSAGE(create_rast_state, message); + + message->base.opcode = REMREQ_CREATE_RAST_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + uint32_t handle = get_fresh_rast_handle(_pipe->screen); + message->handle = handle; + + DBG("Create new rasterizer state: handle %u\n", handle); + + enqueue_message(message); + + struct remote_opaque_rast_state* remote_rast = CALLOC_STRUCT(remote_opaque_rast_state); + + PANIC_IF_NULL(remote_rast); + remote_rast->handle = handle; + return remote_rast; +} + + +static INLINE void +remote_context_bind_rasterizer_state(struct pipe_context *_pipe, + void *state) +{ + + ALLOC_OUT_MESSAGE(bind_rast_state, message); + + message->base.opcode = REMREQ_BIND_RAST_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->rast_handle = RAST_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void +remote_context_delete_rasterizer_state(struct pipe_context *_pipe, + void *state) +{ + DBG("Delete rasterizer state %u\n", RAST_HANDLE(state)); + + ALLOC_OUT_MESSAGE(delete_rast_state, message); + + message->base.opcode = REMREQ_DELETE_RAST_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->rast_handle = RAST_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void * +remote_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe, + const struct pipe_depth_stencil_alpha_state *state) +{ + ALLOC_OUT_MESSAGE(create_dsa_state, message); + + message->base.opcode = REMREQ_CREATE_DSA_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + uint32_t handle = get_fresh_dsa_handle(_pipe->screen); + message->handle = handle; + + DBG("Create depth/stencil/alpha state: handle %u\n", handle); + + enqueue_message(message); + + struct remote_opaque_dsa_state* remote_dsa = CALLOC_STRUCT(remote_opaque_dsa_state); + + PANIC_IF_NULL(remote_dsa); + remote_dsa->handle = handle; + return remote_dsa; +} + + +static INLINE void +remote_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *state) +{ + + DBG("Bind depth/stencil/alpha state %u\n", DSA_HANDLE(state)); + + ALLOC_OUT_MESSAGE(bind_dsa_state, message); + + message->base.opcode = REMREQ_BIND_DSA_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->dsa_handle = DSA_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void +remote_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *state) +{ + + DBG("Delete depth/stencil/alpha state %u\n", DSA_HANDLE(state)); + + ALLOC_OUT_MESSAGE(delete_dsa_state, message); + + message->base.opcode = REMREQ_DELETE_DSA_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->dsa_handle = DSA_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void * +remote_context_create_fs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *state) +{ + int tokens = tgsi_num_tokens(state->tokens); + + struct remreq_create_fs_state* header = + allocate_message_memory( + sizeof(struct remreq_create_fs_state) + + (tokens * sizeof(struct tgsi_token))); + + uint32_t handle = get_fresh_fs_handle(_pipe->screen); + + header->base.opcode = REMREQ_CREATE_FS_STATE; + header->pipe = PIPE_HANDLE(_pipe); + header->fs_handle = handle; + + char* copy_dest = ((char*)header) + sizeof(struct remreq_create_fs_state); + memcpy(copy_dest, (char*)(state->tokens), sizeof(struct tgsi_token) * tokens); + + DBG("Create new FS state: handle %u\n", handle); + + enqueue_message(header); + + struct opaque_remote_fs* retval = CALLOC_STRUCT(opaque_remote_fs); + + PANIC_IF_NULL(retval); + + retval->handle = handle; + + return retval; +} + + +static INLINE void +remote_context_bind_fs_state(struct pipe_context *_pipe, + void *state) +{ + + if(state) { + DBG("Bind fragment shader %u\n", FS_HANDLE(state)); + } + else { + DBG("Bind fragment shader: no shader\n"); + } + + ALLOC_OUT_MESSAGE(bind_fs_state, message); + + message->base.opcode = REMREQ_BIND_FS_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->fs_handle = FS_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void +remote_context_delete_fs_state(struct pipe_context *_pipe, + void *state) +{ + + DBG("Delete fragment shader %u\n", FS_HANDLE(state)); + + ALLOC_OUT_MESSAGE(delete_fs_state, message); + + message->base.opcode = REMREQ_DELETE_FS_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->fs_handle = FS_HANDLE(state); + + enqueue_message(message); +} + + +static INLINE void * +remote_context_create_vs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *state) +{ + + int tokens = tgsi_num_tokens(state->tokens); + + struct remreq_create_vs_state* header = + allocate_message_memory( + sizeof(struct remreq_create_vs_state) + + (tokens * sizeof(struct tgsi_token))); + + uint32_t handle = get_fresh_vs_handle(_pipe->screen); + + DBG("Create new VS state: handle %u\n", handle); + + header->base.opcode = REMREQ_CREATE_VS_STATE; + header->pipe = PIPE_HANDLE(_pipe); + header->vs_handle = handle; + + char* copy_dest = ((char*)header) + sizeof(struct remreq_create_vs_state); + memcpy(copy_dest, (char*)(state->tokens), sizeof(struct tgsi_token) * tokens); + + enqueue_message(header); + + struct opaque_remote_vs* retval = CALLOC_STRUCT(opaque_remote_vs); + + PANIC_IF_NULL(retval); + + retval->handle = handle; + + return retval; + +} + + +static INLINE void +remote_context_bind_vs_state(struct pipe_context *_pipe, + void *state) +{ + + if(state) { + DBG("Bind vertex shader state %u\n", VS_HANDLE(state)); + } + else { + DBG("Bind vertex shader: no shader\n"); + } + + ALLOC_OUT_MESSAGE(bind_vs_state, message); + + message->base.opcode = REMREQ_BIND_VS_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->vs_handle = VS_HANDLE(state); + + enqueue_message(message); + +} + + +static INLINE void +remote_context_delete_vs_state(struct pipe_context *_pipe, + void *state) +{ + + DBG("Delete vertex shader state %u\n", VS_HANDLE(state)); + + ALLOC_OUT_MESSAGE(delete_vs_state, message); + + message->base.opcode = REMREQ_DELETE_VS_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->vs_handle = VS_HANDLE(state); + + enqueue_message(message); + +} + + +static INLINE void +remote_context_set_blend_color(struct pipe_context *_pipe, + const struct pipe_blend_color *state) +{ + + DBG("Set blend color\n"); + + ALLOC_OUT_MESSAGE(set_blend_color, message); + + message->base.opcode = REMREQ_SET_BLEND_COLOR; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + enqueue_message(message); + +} + + +static INLINE void +remote_context_set_clip_state(struct pipe_context *_pipe, + const struct pipe_clip_state *state) +{ + + DBG("Set clip state\n"); + + ALLOC_OUT_MESSAGE(set_clip_state, message); + + message->base.opcode = REMREQ_SET_CLIP_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + enqueue_message(message); + +} + + +static INLINE void +remote_context_set_constant_buffer(struct pipe_context *_pipe, + uint shader, uint index, + struct pipe_resource *buffer) +{ + + DBG("Set constant buffer for shader %u, index %u\n", shader, index); + + ALLOC_OUT_MESSAGE(set_constant_buffer, message); + + message->base.opcode = REMREQ_SET_CONSTANT_BUFFER; + message->pipe = PIPE_HANDLE(_pipe); + message->shader = shader; + message->index = index; + message->buffer = BUFFER_HANDLE(buffer); + /* + char* mapped = (char*)pipe_buffer_map(_pipe->screen, buffer->buffer, PIPE_BUFFER_USAGE_CPU_READ); + + debug_printf("On setting, constant buffer goes like this:\n"); + + int i; + for(i = 0; i < buffer->size; i++) { + debug_printf("%4d ", (int)mapped[i]); + if(i % 8 == 7) + debug_printf("\n"); + } + debug_printf("\n"); + + pipe_buffer_unmap(_pipe->screen, buffer->buffer); + */ + enqueue_message(message); + +} + + +static INLINE void +remote_context_set_framebuffer_state(struct pipe_context *_pipe, + const struct pipe_framebuffer_state *state) +{ + unsigned i; + ALLOC_OUT_MESSAGE(set_framebuffer_state, message); + + message->base.opcode = REMREQ_SET_FRAMEBUFFER_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->fbwidth = state->width; + message->fbheight = state->height; + message->fbnum_cbufs = state->nr_cbufs; + message->fbzsbuf = state->zsbuf ? SURFACE_HANDLE(state->zsbuf) : 0; + for(i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + message->fbcbufs[i] = state->cbufs[i] ? SURFACE_HANDLE(state->cbufs[i]) : 0; + + DBG("Set framebuffer state: %dx%d\n", state->width, state->height); + if(message->fbzsbuf) { + DBG("Z/stencil buffer: %u\n", message->fbzsbuf); + } + else { + DBG("No Z/stencil buffer\n"); + } + + for(i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + if(message->fbcbufs[i]) + DBG("Colour buffer %d: texture %u\n", i, message->fbcbufs[i]); + + enqueue_message(message); + + struct remote_context* rctx = (struct remote_context*)_pipe; + + rctx->current_framebuffer_state = *state; // Struct copy + +} + + +static INLINE void +remote_context_set_polygon_stipple(struct pipe_context *_pipe, + const struct pipe_poly_stipple *state) +{ + + DBG("Set polygon stipple\n"); + + ALLOC_OUT_MESSAGE(set_polygon_stipple, message); + + message->base.opcode = REMREQ_SET_POLYGON_STIPPLE; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + enqueue_message(message); +} + + +static INLINE void +remote_context_set_scissor_state(struct pipe_context *_pipe, + const struct pipe_scissor_state *state) +{ + + DBG("Set scissor state\n"); + + ALLOC_OUT_MESSAGE(set_scissor_state, message); + + message->base.opcode = REMREQ_SET_SCISSOR_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + enqueue_message(message); +} + + +static INLINE void +remote_context_set_viewport_state(struct pipe_context *_pipe, + const struct pipe_viewport_state *state) +{ + + DBG("Set viewport state\n"); + + ALLOC_OUT_MESSAGE(set_viewport_state, message); + + message->base.opcode = REMREQ_SET_VIEWPORT_STATE; + message->pipe = PIPE_HANDLE(_pipe); + message->state = *state; + // Struct copy + + enqueue_message(message); +} + + +#if 0 +static INLINE void +remote_context_set_sampler_textures(struct pipe_context *_pipe, + unsigned num_textures, + struct pipe_texture **textures) +{ + // Similar to below + + DBG("Set sampler textures\n"); + + struct remreq_set_sampler_textures* header = + (struct remreq_set_sampler_textures*) + allocate_message_memory( + sizeof(struct remreq_set_sampler_textures) + + num_textures * sizeof(uint32_t)); + + header->base.opcode = REMREQ_SET_SAMPLER_TEXTURES; + header->pipe = PIPE_HANDLE(_pipe); + header->num_textures = num_textures; + + uint32_t* texhandles = (uint32_t*) + ((char*)header + sizeof(struct remreq_set_sampler_textures)); + + unsigned i; + + for(i = 0; i < num_textures; i++) { + texhandles[i] = textures[i] ? TEXTURE_HANDLE(textures[i]) : 0; + DBG("Sampler slot %d: texture %u\n", i, texhandles[i]); + } + + enqueue_message(header); + +} +#endif + + +static INLINE void +remote_context_set_vertex_buffers(struct pipe_context *_pipe, + unsigned num_buffers, + const struct pipe_vertex_buffer *buffers) +{ + // Each vertex_buffer points to a pipe_buffer, which here is actually + // a remote_pipe_buffer. Flatten those references and send an array + // which gives the buffer by opaque handle + + DBG("Set vertex buffers: %d buffers\n", num_buffers); + + struct remreq_set_vertex_buffers* header = + (struct remreq_set_vertex_buffers*) + allocate_message_memory( + sizeof(struct remreq_set_vertex_buffers) + + (num_buffers * sizeof(struct opaque_pipe_vertex_element))); + + PANIC_IF_NULL(header); + + header->base.opcode = REMREQ_SET_VERTEX_BUFFERS; + header->pipe = PIPE_HANDLE(_pipe); + header->num_buffers = num_buffers; + + struct opaque_pipe_vertex_element* data = + (struct opaque_pipe_vertex_element*) + (((char*)header) + sizeof(struct remreq_set_vertex_buffers)); + + unsigned i; + + for(i = 0; i < num_buffers; i++) { + data[i].stride = buffers[i].stride; + data[i].buffer_offset = buffers[i].buffer_offset; + data[i].buffer = buffers[i].buffer ? BUFFER_HANDLE(buffers[i].buffer) : 0; + DBG("Buffer slot %d assigned buffer handle %u\n", i, data[i].buffer); + } + + enqueue_message(header); + +} + + +static INLINE void +remote_context_set_vertex_elements(struct pipe_context *_pipe, + unsigned num_elements, + const struct pipe_vertex_element *elements) +{ + // Send array + + DBG("Set vertex elements: %u elements\n", num_elements); + + struct remreq_set_vertex_elements* header = + (struct remreq_set_vertex_elements*) + allocate_message_memory( + sizeof(struct remreq_set_vertex_elements) + + num_elements * sizeof(struct pipe_vertex_element)); + + header->base.opcode = REMREQ_SET_VERTEX_ELEMENTS; + header->pipe = PIPE_HANDLE(_pipe); + header->num_elements = num_elements; + + char* dest = ((char*)header) + sizeof(struct remreq_set_vertex_elements); + memcpy(dest, (void*)elements, num_elements * sizeof(struct pipe_vertex_element)); + + enqueue_message(header); + +} + + +static INLINE void +remote_context_surface_copy(struct pipe_context *_pipe, + boolean do_flip, + struct pipe_surface *dest, + unsigned destx, unsigned desty, + struct pipe_surface *src, + unsigned srcx, unsigned srcy, + unsigned width, unsigned height) +{ + + DBG("Surface copy: %u-%ux%u-%ux%u --> %u-%ux%u\n", SURFACE_HANDLE(src), srcx, srcy, srcx + width, srcy + height, SURFACE_HANDLE(dest), destx, desty); + + ALLOC_OUT_MESSAGE(surface_copy, message); + + message->base.opcode = REMREQ_SURFACE_COPY; + message->pipe = PIPE_HANDLE(_pipe); + message->src = SURFACE_HANDLE(src); + message->dest = SURFACE_HANDLE(dest); + message->sx = srcx; + message->sy = srcy; + message->dx = destx; + message->dy = desty; + message->w = width; + message->h = height; + message->do_flip = do_flip; + + enqueue_message(message); + +} + + +static INLINE void +remote_context_surface_fill(struct pipe_context *_pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, + unsigned value) +{ + + DBG("Surface fill: %u-%ux%u-%ux%u with %x\n", PIPE_HANDLE(dst), dstx, dsty, dstx + width, dsty + height, value); + + ALLOC_OUT_MESSAGE(surface_fill, message); + + message->base.opcode = REMREQ_SURFACE_FILL; + message->pipe = PIPE_HANDLE(_pipe); + message->surface = SURFACE_HANDLE(dst); + message->x = dstx; + message->y = dsty; + message->w = width; + message->h = height; + message->value = value; + + enqueue_message(message); + +} + + +static INLINE void +remote_context_clear(struct pipe_context *_pipe, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil) +{ + + DBG("Clear surface %u with %x\n", SURFACE_HANDLE(surface), clearValue); + + ALLOC_OUT_MESSAGE(clear, message); + + message->base.opcode = REMREQ_CLEAR; + message->pipe = PIPE_HANDLE(_pipe); + message->buffers = buffers; + message->has_rgba = rgba != NULL ? 1 : 0; + if (rgba) { + message->rgba[0] = rgba[0]; + message->rgba[1] = rgba[1]; + message->rgba[2] = rgba[2]; + message->rgba[3] = rgba[3]; + } + message->depth = depth; + message->stencil = stencil; + + enqueue_message(message); + +} + + +static INLINE void +remote_context_flush(struct pipe_context *_pipe, + struct pipe_fence_handle **fence) +{ + + DBG("Flush\n"); + + ALLOC_OUT_MESSAGE(flush, message); + + message->base.opcode = REMREQ_FLUSH; + message->pipe = PIPE_HANDLE(_pipe); + + /* !!! I *think* fence is out-only */ + + enqueue_message(message); + + if(fence) *fence = NULL; + +} + + +static INLINE void +remote_context_destroy(struct pipe_context *_pipe) +{ + ALLOC_OUT_MESSAGE(destroy_context, message); + + DBG("Destroying context %u\n", PIPE_HANDLE(_pipe)); + + message->base.opcode = REMREQ_DESTROY_CONTEXT; + message->pipe = PIPE_HANDLE(_pipe); + + enqueue_message(message); + + FREE((struct remote_context*)_pipe); +} + +static INLINE void +remote_context_bind_fragment_sampler_states(struct pipe_context *_pipe, + unsigned num_states, + void **states) +{ + DBG("context_bind_fragment_sampler_states %u\n", PIPE_HANDLE(_pipe)); +} + +static INLINE void +remote_context_bind_vertex_sampler_states(struct pipe_context *_pipe, + unsigned num_states, + void **states) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static INLINE void * +remote_context_create_vertex_elements_state(struct pipe_context *_pipe, + unsigned num_elements, + const struct pipe_vertex_element *elements) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); + return NULL; +} + +static INLINE void +remote_context_bind_vertex_elements_state(struct pipe_context *_pipe, + void *state) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static INLINE void +remote_context_delete_vertex_elements_state(struct pipe_context *_pipe, + void *state) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static INLINE void +remote_context_set_stencil_ref(struct pipe_context *_pipe, + const struct pipe_stencil_ref *state) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static INLINE void +remote_context_set_sample_mask(struct pipe_context *_pipe, + unsigned sample_mask) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static INLINE void +remote_context_set_fragment_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static INLINE void +remote_context_set_vertex_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static struct pipe_sampler_view * +remote_create_sampler_view(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_sampler_view *templ) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); + return NULL; +} + +static void +remote_sampler_view_destroy(struct pipe_context *_pipe, + struct pipe_sampler_view *_view) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + + +static struct pipe_surface * +remote_create_surface(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_surface *surf_tmpl) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); + return NULL; +} + + +static void +remote_surface_destroy(struct pipe_context *_pipe, + struct pipe_surface *_surface) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + + +static INLINE void +remote_context_set_index_buffer(struct pipe_context *_pipe, + const struct pipe_index_buffer *ib) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static INLINE void +remote_context_resource_copy_region(struct pipe_context *_pipe, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static INLINE void +remote_context_clear_render_target(struct pipe_context *_pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + + +static INLINE void +remote_context_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) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + + +static struct pipe_transfer * +remote_context_get_transfer(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); + return NULL; +} + + +static void +remote_context_transfer_destroy(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + + +static void * +remote_context_transfer_map(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); + return NULL; +} + + +static void +remote_context_transfer_flush_region( struct pipe_context *_context, + struct pipe_transfer *_transfer, + const struct pipe_box *box) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + +static void +remote_context_transfer_unmap(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + + +static void +remote_context_transfer_inline_write(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + + +static void remote_redefine_user_buffer(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned offset, unsigned size) +{ + DBG("UNIMPLEMENTED %s\n", __FUNCTION__); +} + + +struct pipe_context * +remote_context_create(struct pipe_screen *screen, + struct pipe_context *pipe) +{ + struct remote_context *tr_ctx; + + DBG("Creating new context for screen %u\n", SCREEN_HANDLE(screen)); + + tr_ctx = CALLOC_STRUCT(remote_context); + if(!tr_ctx) + goto error1; + tr_ctx->base.winsys = screen->winsys; + tr_ctx->base.screen = screen; + tr_ctx->base.destroy = remote_context_destroy; + tr_ctx->base.draw_vbo = remote_context_draw_vbo; // new + tr_ctx->base.create_query = remote_context_create_query; + tr_ctx->base.destroy_query = remote_context_destroy_query; + tr_ctx->base.begin_query = remote_context_begin_query; + tr_ctx->base.end_query = remote_context_end_query; + tr_ctx->base.get_query_result = remote_context_get_query_result; + tr_ctx->base.create_blend_state = remote_context_create_blend_state; + tr_ctx->base.bind_blend_state = remote_context_bind_blend_state; + tr_ctx->base.delete_blend_state = remote_context_delete_blend_state; + tr_ctx->base.create_sampler_state = remote_context_create_sampler_state; + tr_ctx->base.bind_fragment_sampler_states = remote_context_bind_fragment_sampler_states; // new + tr_ctx->base.bind_vertex_sampler_states = remote_context_bind_vertex_sampler_states; // new + tr_ctx->base.delete_sampler_state = remote_context_delete_sampler_state; + tr_ctx->base.create_rasterizer_state = remote_context_create_rasterizer_state; + tr_ctx->base.bind_rasterizer_state = remote_context_bind_rasterizer_state; + tr_ctx->base.delete_rasterizer_state = remote_context_delete_rasterizer_state; + tr_ctx->base.create_depth_stencil_alpha_state = remote_context_create_depth_stencil_alpha_state; + tr_ctx->base.bind_depth_stencil_alpha_state = remote_context_bind_depth_stencil_alpha_state; + tr_ctx->base.delete_depth_stencil_alpha_state = remote_context_delete_depth_stencil_alpha_state; + tr_ctx->base.create_fs_state = remote_context_create_fs_state; + tr_ctx->base.bind_fs_state = remote_context_bind_fs_state; + tr_ctx->base.delete_fs_state = remote_context_delete_fs_state; + tr_ctx->base.create_vs_state = remote_context_create_vs_state; + tr_ctx->base.bind_vs_state = remote_context_bind_vs_state; + tr_ctx->base.delete_vs_state = remote_context_delete_vs_state; + tr_ctx->base.create_vertex_elements_state = remote_context_create_vertex_elements_state; // new + tr_ctx->base.bind_vertex_elements_state = remote_context_bind_vertex_elements_state; // new + tr_ctx->base.delete_vertex_elements_state = remote_context_delete_vertex_elements_state; // new + tr_ctx->base.set_blend_color = remote_context_set_blend_color; + tr_ctx->base.set_stencil_ref = remote_context_set_stencil_ref; // new + tr_ctx->base.set_clip_state = remote_context_set_clip_state; + tr_ctx->base.set_sample_mask = remote_context_set_sample_mask; // new + tr_ctx->base.set_constant_buffer = remote_context_set_constant_buffer; + tr_ctx->base.set_framebuffer_state = remote_context_set_framebuffer_state; + tr_ctx->base.set_polygon_stipple = remote_context_set_polygon_stipple; + tr_ctx->base.set_scissor_state = remote_context_set_scissor_state; + tr_ctx->base.set_viewport_state = remote_context_set_viewport_state; + tr_ctx->base.set_fragment_sampler_views = remote_context_set_fragment_sampler_views; // new + tr_ctx->base.set_vertex_sampler_views = remote_context_set_vertex_sampler_views; // new + tr_ctx->base.create_sampler_view = remote_create_sampler_view; // new + tr_ctx->base.sampler_view_destroy = remote_sampler_view_destroy; // new + tr_ctx->base.create_surface = remote_create_surface; // new + tr_ctx->base.surface_destroy = remote_surface_destroy; // new + tr_ctx->base.set_vertex_buffers = remote_context_set_vertex_buffers; + tr_ctx->base.set_index_buffer = remote_context_set_index_buffer; // new + tr_ctx->base.resource_copy_region = remote_context_resource_copy_region; // new + tr_ctx->base.clear = remote_context_clear; + tr_ctx->base.clear_render_target = remote_context_clear_render_target; // new + tr_ctx->base.clear_depth_stencil = remote_context_clear_depth_stencil; // new + tr_ctx->base.flush = remote_context_flush; + + tr_ctx->base.get_transfer = remote_context_get_transfer; // new + tr_ctx->base.transfer_destroy = remote_context_transfer_destroy; // new + tr_ctx->base.transfer_map = remote_context_transfer_map; // new + tr_ctx->base.transfer_unmap = remote_context_transfer_unmap; // new + tr_ctx->base.transfer_flush_region = remote_context_transfer_flush_region; // new + tr_ctx->base.transfer_inline_write = remote_context_transfer_inline_write; // new + tr_ctx->base.redefine_user_buffer = remote_redefine_user_buffer; // new + +#if 0 + // Old (vgallium 2009) + tr_ctx->base.set_edgeflags = remote_context_set_edgeflags; + tr_ctx->base.draw_arrays = remote_context_draw_arrays; + tr_ctx->base.draw_elements = remote_context_draw_elements; + tr_ctx->base.draw_range_elements = remote_context_draw_range_elements; + tr_ctx->base.bind_sampler_states = remote_context_bind_sampler_states; + tr_ctx->base.set_sampler_textures = remote_context_set_sampler_textures; + tr_ctx->base.set_vertex_elements = remote_context_set_vertex_elements; + tr_ctx->base.surface_copy = remote_context_surface_copy; + tr_ctx->base.surface_fill = remote_context_surface_fill; +#endif + + memset(&tr_ctx->current_framebuffer_state, 0, sizeof(struct pipe_framebuffer_state)); + + ALLOC_OUT_MESSAGE(create_context, message); + + struct remote_screen* remscreen = (struct remote_screen*)screen; + + message->base.opcode = REMREQ_CREATE_CONTEXT; + message->screen = remscreen->remote_handle; + + QUEUE_AND_WAIT(message, create_context, reply); + + if(reply) { + DBG("Got reply: assigned handle %u\n", reply->handle); + tr_ctx->remote_handle = reply->handle; + free_message(reply); + return &tr_ctx->base; + } + else { + return NULL; + } + +error1: + return NULL; +} +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/drivers/remote/remote_context.h b/src/gallium/drivers/remote/remote_context.h new file mode 100644 index 0000000000..600d389586 --- /dev/null +++ b/src/gallium/drivers/remote/remote_context.h @@ -0,0 +1,70 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +#ifndef TR_CONTEXT_H_ +#define TR_CONTEXT_H_ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "pipe/p_context.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct remote_context +{ + struct pipe_context base; + uint32_t remote_handle; + + struct pipe_framebuffer_state current_framebuffer_state; + +}; + + +static INLINE struct remote_context * +remote_context(struct pipe_context *pipe) +{ + assert(pipe); + return (struct remote_context *)pipe; +} + + + +struct pipe_context * +remote_context_create(struct pipe_screen *screen, + struct pipe_context *pipe); + + +#ifdef __cplusplus +} +#endif + +#endif /* TR_CONTEXT_H_ */ diff --git a/src/gallium/drivers/remote/remote_screen.c b/src/gallium/drivers/remote/remote_screen.c new file mode 100644 index 0000000000..3bf5f4e130 --- /dev/null +++ b/src/gallium/drivers/remote/remote_screen.c @@ -0,0 +1,663 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +#ifdef USE_XEN +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" + +#include "remote_state.h" +#include "remote_util.h" +#include "remote_comms.h" +#include "remote_messages.h" +#include "remote_debug.h" +#include "remote_screen.h" +//#include "tr_winsys.h" + +/* A few of the objects dealt with here are refcounted. Of course, the remote side is refcounting too. Since functions + like pipe_texture_reference and so on in some cases just adjust the refcount variable without making a callback, + I can't be sure of always letting the remote side know about references. + + My solution: + + * Each proxy object (e.g. remote_texture) corresponds to exactly one remote reference. + * The proxies themselves are refcounted. So, when a proxy dies, the remote object gets a single deref. + + i.e. the objects in this address space are being refcounted, and their existence corresponds to a single + reference in the remote address space. + +*/ + +int analyse_waits = 0; +// A global to indicate whether we desire print statements reporting on how and why we waited for remote action + +static const char * +remote_screen_get_name(struct pipe_screen *_screen) +{ + + return "Xen virtual 3D\n"; + +} + + +static const char * +remote_screen_get_vendor(struct pipe_screen *_screen) +{ + + return "Chris Smowton\n"; + +} + + +static int +remote_screen_get_param(struct pipe_screen *_screen, + enum pipe_cap param) { + + struct remote_screen* rscreen = (struct remote_screen*)_screen; + + if(rscreen->int_param_is_cached[param]) + return rscreen->cached_int_params[param]; + + ALLOC_OUT_MESSAGE(get_param, message); + + message->base.opcode = REMREQ_GET_PARAM; + message->screen = SCREEN_HANDLE(_screen); + message->param = param; + + if(analyse_waits) + debug_printf("WAIT: get_param\n"); + QUEUE_AND_WAIT(message, get_param, reply); + + DBG("Get integer parameter %d: value is %d\n", param, reply->response); + + rscreen->cached_int_params[param] = reply->response; + rscreen->int_param_is_cached[param] = 1; + int response = reply->response; + free_message(reply); + return response; + +} + +static int +remote_screen_get_shader_param(struct pipe_screen *_screen, unsigned shader, + enum pipe_shader_cap param) +{ + return 0; +} + + +static float +remote_screen_get_paramf(struct pipe_screen *_screen, + enum pipe_cap param) +{ + + struct remote_screen* rscreen = (struct remote_screen*)_screen; + + if(rscreen->float_param_is_cached[param]) + return rscreen->cached_float_params[param]; + + ALLOC_OUT_MESSAGE(get_paramf, message); + + message->base.opcode = REMREQ_GET_PARAMF; + message->screen = SCREEN_HANDLE(_screen); + message->param = param; + + if(analyse_waits) + debug_printf("WAIT: float param\n"); + QUEUE_AND_WAIT(message, get_paramf, reply); + + DBG("Get FP parameter %d: value is %f\n", param, reply->response); + + rscreen->cached_float_params[param] = reply->response; + rscreen->float_param_is_cached[param] = 1; + + float response = reply->response; + free_message(reply); + return response; + +} + + +static boolean +remote_screen_is_format_supported(struct pipe_screen *_screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) +{ + + ALLOC_OUT_MESSAGE(is_format_supported, message); + + message->base.opcode = REMREQ_IS_FORMAT_SUPPORTED; + message->screen = SCREEN_HANDLE(_screen); + message->format = format; + message->target = target; + message->tex_usage = tex_usage; + message->geom_flags = geom_flags; + + if(analyse_waits) + debug_printf("WAIT: format_supported\n"); + QUEUE_AND_WAIT(message, is_format_supported, reply); + + if(reply->response) + DBG("Format query: accepted\n"); + else + DBG("Format query: denied\n"); + + boolean response = reply->response; + free_message(reply); + return response; + +} + +static int get_or_alloc_buffer_handle(struct remote_buffer* rbuf, + struct pipe_screen* screen, + uint32_t* handle) { + + if(rbuf->handle) { + *handle = rbuf->handle; + return 0; + } + else { + *handle = get_fresh_buffer_handle(screen); + rbuf->handle = *handle; + return 1; + } + +} + +static void +remote_screen_destroy(struct pipe_screen *_screen) +{ + struct remote_screen *tr_scr = remote_screen(_screen); + + DBG("Destroying screen %u: closing connection\n", SCREEN_HANDLE(_screen)); + + close(tr_scr->socketfd); + + FREE(tr_scr); +} + +static struct pipe_context * +remote_screen_context_create(struct pipe_screen *_screen, void *priv) +{ + DBG("%s: unimplemented\n", __FUNCTION__); + return NULL; +} + +static void +remote_screen_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *_resource, + unsigned level, unsigned layer, + void *context_private) +{ + DBG("%s: unimplemented\n", __FUNCTION__); +} + + +/******************************************************************** + * texture + */ + +static struct pipe_resource * +remote_screen_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) +{ + struct pipe_resource *result = NULL; + + DBG("%s: unimplemented\n", __FUNCTION__); + return result; +} + +static struct pipe_resource * +remote_screen_resource_from_handle(struct pipe_screen *_screen, + const struct pipe_resource *templ, + struct winsys_handle *handle) +{ + struct pipe_resource *result = NULL; + + DBG("%s: unimplemented\n", __FUNCTION__); + return result; +} + +static boolean +remote_screen_resource_get_handle(struct pipe_screen *_screen, + struct pipe_resource *_resource, + struct winsys_handle *handle) +{ + DBG("%s: unimplemented\n", __FUNCTION__); + return false; +} + +static void +remote_screen_resource_destroy(struct pipe_screen *_screen, + struct pipe_resource *_resource) +{ + DBG("%s: unimplemented\n", __FUNCTION__); +} + +/******************************************************************** + * buffer + */ + +static struct pipe_resource * +remote_screen_user_buffer_create(struct pipe_screen *_screen, + void *data, + unsigned size, + unsigned usage) +{ + DBG("%s: unimplemented\n", __FUNCTION__); + return NULL; +} + + +/******************************************************************** + * fence + */ + + +static void +remote_screen_fence_reference(struct pipe_screen *_screen, + struct pipe_fence_handle **pdst, + struct pipe_fence_handle *src) +{ + DBG("%s: unimplemented\n", __FUNCTION__); +} + + +static boolean +remote_screen_fence_signalled(struct pipe_screen *_screen, + struct pipe_fence_handle *fence) +{ + DBG("%s: unimplemented\n", __FUNCTION__); + return false; +} + + +static boolean +remote_screen_fence_finish(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + uint64_t timeout) +{ + DBG("%s: unimplemented\n", __FUNCTION__); + return false; +} + +#ifdef XEN_HOST +// currently broken +static void setup_xen_connection(struct remote_screen* tr_scr) +{ + // Set up a Xen-IDC connection to describe graphics events to the host + + struct sockaddr_un sun; + + sun.sun_family = AF_UNIX; + strcpy(sun.sun_path, "/var/run/xen3dd-socket"); + + tr_scr->socketfd = socket(PF_UNIX, SOCK_STREAM, 0); + DBG("Socket fd is %d\n", tr_scr->socketfd); + + if(tr_scr->socketfd == -1) { + debug_printf("socket() failed creating a new screen\n"); + exit(1); + } + + if(connect(tr_scr->socketfd, + &sun, + sizeof(sun.sun_family) + strlen(sun.sun_path)) < 0) { + debug_printf("Couldn't connect to /var/run/xen3dd-socket\n"); + exit(1); + } + + DBG("Successfully connected\n"); + + // Now create two initally-empty ring buffers, one for RX and one for TX. + + struct { + uint32_t* grants; + void** map; + } togrant[2] = { + { .grants = tr_scr->rx_grants, .map = &(tr_scr->rx_buffer) }, + { .grants = tr_scr->tx_grants, .map = &(tr_scr->tx_buffer) } + }; + + DBG("tr_scr->rx_grants is %p, tr_scr->tx_grants is %p\n", tr_scr->rx_grants, tr_scr->tx_grants); + + for(int k = 0; k < 4; k++) { + + DBG("RX grant %d is currently %u\n", k, tr_scr->rx_grants[k]); + DBG("TX grant %d is currently %u\n", k, tr_scr->tx_grants[k]); + + } + + for(int i = 0; i < 2; i++) { + int fd = open("/dev/gntmem", O_RDWR); + int ret; + + DBG("Opened /dev/gntmem; got fd %d\n", fd); + + if(fd == -1) { + debug_printf("Failed to open /dev/gntmem\n"); + exit(1); + } + + ret = ioctl(fd, IOCTL_GNTMEM_SET_DOMAIN, 0); + + DBG("set-domain 0 returned %d\n", ret); + + if(ret == -1) { + debug_printf("Failed to set gntmem's target domain\n"); + exit(1); + } + + ret = ioctl(fd, IOCTL_GNTMEM_SET_SIZE, 4); + + DBG("set-size 4 returned %d\n", ret); + + if(ret == -1) { + debug_printf("Failed to create a shareable section of 4 pages\n"); + exit(1); + } + + DBG("Going to write grants starting at address %p\n", togrant[i].grants); + + ret = ioctl(fd, IOCTL_GNTMEM_GET_GRANTS, togrant[i].grants); + + DBG("get-grants returned %d\n", ret); + DBG("After get-grants, have address %p\n", togrant[i].grants); + + for(int j = 0; j < 4; j++) { + + DBG("Grant #%d is %u\n", j, (togrant[i].grants)[j]); + + } + + if(ret == -1) { + debug_printf("Failed to get grants for shared section\n"); + exit(1); + } + + *(togrant[i].map) = (void*)-1; + *(togrant[i].map) = mmap(0, 4096 * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + DBG("Mapped as a shared section: got address %p\n", *(togrant[i].map)); + + if(*(togrant[i].map) == (void*)-1) { + debug_printf("Couldn't mmap our shared section\n"); + exit(1); + } + + close(fd); + // Will remain in existence until an munmap + + // Now init the ring-buffer before we announce to the daemon + uint32_t* initdata = (uint32_t*)*(togrant[i].map); + DBG("Configuring initdata at %p\n", initdata); + uint32_t buffersize = (4096 * 4) - (sizeof(uint32_t) * 3); + initdata[0] = buffersize; + // total buffer size + initdata[1] = 0; + initdata[2] = 0; + // Next byte to read and next-to-write respectively. + // Equality signals the buffer is empty, write = read - 1 signals it is full + } + + DBG("Successfully created ring buffers\n"); + DBG("On exit have rx at %p, tx at %p\n", tr_scr->rx_buffer, tr_scr->tx_buffer); + + // Okay, both ring buffers exist. Now send the grants to the daemon. + struct { + uint32_t rx_grants[4]; + uint32_t tx_grants[4]; + char is_x; + } tosend; + + for(int i = 0; i < 4; i++) { + tosend.rx_grants[i] = tr_scr->rx_grants[i]; + tosend.tx_grants[i] = tr_scr->tx_grants[i]; + } + + tosend.is_x = 0; + + int bytessent = 0; + + while(bytessent < sizeof(tosend)) { + + DBG("Going around; bytessent = %d, about to try to to send %lu on fd %d\n", bytessent, sizeof(tosend) - bytessent, tr_scr->socketfd); + + int sent = send(tr_scr->socketfd, ((char*)&tosend) + bytessent, sizeof(tosend) - bytessent, 0); + + DBG("Just sent %d bytes\n", sent); + + if(sent <= 0) { + debug_printf("Failed to send init message to xen3dd: return %d with errno %d\n", sent, errno); + exit(1); + } + else { + bytessent += sent; + } + + } + + DBG("Successfully relayed that to the compositor\n"); +} +#endif + +static void setup_virtio_connection(struct remote_screen* tr_scr) +{ + DBG("%s: unimplemented\n", __FUNCTION__); +} + +static void setup_host_connection(struct remote_screen* tr_scr) +{ +#ifdef XEN_HOST + setup_xen_connection(tr_scr); +#else + setup_virtio_connection(tr_scr); +#endif +} + +struct pipe_screen * +remote_screen_create(struct pipe_winsys* winsys) +{ + + struct remote_screen* tr_scr = CALLOC_STRUCT(remote_screen); + + memset(tr_scr, 0, sizeof(struct remote_screen)); + + DBG("Creating new screen\n"); + + if(!tr_scr) { + debug_printf("Alloc failed in remote_screen_create!\n"); + return NULL; + } + + tr_scr->base.winsys = winsys; + tr_scr->base.destroy = remote_screen_destroy; + tr_scr->base.get_name = remote_screen_get_name; + tr_scr->base.get_vendor = remote_screen_get_vendor; + tr_scr->base.get_param = remote_screen_get_param; + tr_scr->base.get_shader_param = remote_screen_get_shader_param; + tr_scr->base.get_paramf = remote_screen_get_paramf; + tr_scr->base.is_format_supported = remote_screen_is_format_supported; + tr_scr->base.context_create = remote_screen_context_create; + tr_scr->base.resource_create = remote_screen_resource_create; + tr_scr->base.resource_from_handle = remote_screen_resource_from_handle; + tr_scr->base.resource_get_handle = remote_screen_resource_get_handle; + tr_scr->base.resource_destroy = remote_screen_resource_destroy; + tr_scr->base.user_buffer_create = remote_screen_user_buffer_create; + tr_scr->base.fence_reference = remote_screen_fence_reference; + tr_scr->base.fence_signalled = remote_screen_fence_signalled; + tr_scr->base.fence_finish = remote_screen_fence_finish; + tr_scr->base.flush_frontbuffer = remote_screen_flush_frontbuffer; + tr_scr->last_query_handle = 1; + tr_scr->last_blend_handle = 1; + tr_scr->last_dsa_handle = 1; + tr_scr->last_rast_handle = 1; + tr_scr->last_sampler_handle = 1; + tr_scr->last_fs_handle = 1; + tr_scr->last_vs_handle = 1; + tr_scr->last_texture_handle = 1; + tr_scr->last_surface_handle = 1; + tr_scr->last_buffer_handle = 1; + tr_scr->last_window_handle = 1; + + // Check if the user requests wait analysis + + analyse_waits = 0; + + char* analyse_waits_env = getenv("VG_ANALYSE_WAITS"); + if(analyse_waits_env) { + if(analyse_waits_env[0] == '1') { + debug_printf("Enabled wait analysis\n"); + analyse_waits = 1; + } + } + + setup_host_connection(tr_scr); + + return &(tr_scr->base); +} + +int complete_screen_creation(struct remote_screen* screen) { + + ALLOC_OUT_MESSAGE(create_screen, message); + + message->base.opcode = REMREQ_CREATE_SCREEN; + + DBG("WAIT: Screen creation\n"); + QUEUE_AND_WAIT(message, create_screen, reply); + + uint32_t handle = reply->handle; + + free_message(reply); + + if(!handle) + return 0; + else { + DBG("Got handle %u\n", handle); + screen->remote_handle = handle; + return 1; + } + +} + + +struct remote_screen * +remote_screen(struct pipe_screen *screen) +{ + assert(screen); + assert(screen->destroy == remote_screen_destroy); + return (struct remote_screen *)screen; +} + +// Handle generation functions. Currently these just assign sequential numbers. +// If a 32-bit space for e.g. buffers becomes a problem will need to expand that. + +uint32_t get_fresh_query_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_query_handle++; + +} + +uint32_t get_fresh_blend_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_blend_handle++; + +} + +uint32_t get_fresh_sampler_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_sampler_handle++; + +} + +uint32_t get_fresh_rast_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_rast_handle++; + +} + +uint32_t get_fresh_dsa_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_dsa_handle++; + +} + +uint32_t get_fresh_vs_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_vs_handle++; + +} + +uint32_t get_fresh_fs_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_fs_handle++; + +} + +uint32_t get_fresh_texture_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_texture_handle++; + +} + +uint32_t get_fresh_surface_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_surface_handle++; + +} + +uint32_t get_fresh_buffer_handle(struct pipe_screen* screen) { + + struct remote_screen* remscr = (struct remote_screen*)screen; + return remscr->last_buffer_handle++; + +} +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/drivers/remote/remote_screen.h b/src/gallium/drivers/remote/remote_screen.h new file mode 100644 index 0000000000..704312ad5b --- /dev/null +++ b/src/gallium/drivers/remote/remote_screen.h @@ -0,0 +1,97 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +#ifndef TR_SCREEN_H_ +#define TR_SCREEN_H_ + +#include "pipe/p_screen.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PIPE_MAX_PARAMS 26 + +struct remote_screen +{ + + struct pipe_screen base; + uint32_t remote_handle; + int socketfd; + uint32_t tx_grants[4]; + uint32_t rx_grants[4]; + + void* tx_buffer; + void* rx_buffer; + + uint32_t last_query_handle; + uint32_t last_dsa_handle; + uint32_t last_rast_handle; + uint32_t last_blend_handle; + uint32_t last_sampler_handle; + uint32_t last_vs_handle; + uint32_t last_fs_handle; + uint32_t last_texture_handle; + uint32_t last_surface_handle; + uint32_t last_buffer_handle; + + uint32_t last_window_handle; + + int cached_int_params[PIPE_MAX_PARAMS]; + boolean int_param_is_cached[PIPE_MAX_PARAMS]; + float cached_float_params[PIPE_MAX_PARAMS]; + boolean float_param_is_cached[PIPE_MAX_PARAMS]; + +}; + + +struct remote_screen * +remote_screen(struct pipe_screen *screen); + +struct remote_winsys; + +struct pipe_screen * +remote_screen_create(struct pipe_winsys *winsys); + +int complete_screen_creation(struct remote_screen*); + +uint32_t get_fresh_query_handle(struct pipe_screen*); +uint32_t get_fresh_blend_handle(struct pipe_screen*); +uint32_t get_fresh_rast_handle(struct pipe_screen*); +uint32_t get_fresh_dsa_handle(struct pipe_screen*); +uint32_t get_fresh_vs_handle(struct pipe_screen*); +uint32_t get_fresh_fs_handle(struct pipe_screen*); +uint32_t get_fresh_sampler_handle(struct pipe_screen*); +uint32_t get_fresh_buffer_handle(struct pipe_screen*); +uint32_t get_fresh_texture_handle(struct pipe_screen*); +uint32_t get_fresh_surface_handle(struct pipe_screen*); + +#ifdef __cplusplus +} +#endif + +#endif /* TR_SCREEN_H_ */ diff --git a/src/gallium/drivers/remote/tr_context.c b/src/gallium/drivers/remote/tr_context.c deleted file mode 100644 index 80d8f5afe3..0000000000 --- a/src/gallium/drivers/remote/tr_context.c +++ /dev/null @@ -1,1463 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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 "util/u_memory.h" -#include "util/u_inlines.h" - -#include "tgsi/tgsi_parse.h" - -#include "pipe/p_screen.h" -#include "pipe/p_shader_tokens.h" - -#include "pipe/p_format.h" -#include "pipe/p_screen.h" - -#include "tr_screen.h" -#include "tr_context.h" -#include "remote_comms.h" -#include "remote_state.h" -#include "remote_util.h" -#include "remote_messages.h" -#include "remote_debug.h" - -static INLINE void -remote_context_set_edgeflags(struct pipe_context *_pipe, - const unsigned *bitfield) -{ - - if(bitfield) { - DBG("Set edge flags: %u\n", *bitfield); - } - else { - DBG("Set edge flags: null\n"); - } - - ALLOC_OUT_MESSAGE(set_edgeflags, message); - - message->base.opcode = REMREQ_SET_EDGEFLAGS; - message->pipe = PIPE_HANDLE(_pipe); - if(bitfield) { - message->isnull = 0; - message->flag = *bitfield; - } - else { - message->isnull = 1; - } - - enqueue_message(message); - -} - -static INLINE void mark_surface_dirty(struct pipe_surface* surf) { - - struct remote_texture* rtex = (struct remote_texture*)surf->texture; - - if(!rtex) { - debug_printf("!!! Surface with no texture encountered\n"); - } - else { - struct remote_buffer* rbuf = (struct remote_buffer*)rtex->backing_buffer; - rbuf->remote_dirty = 1; - } - -} - -static INLINE void mark_framebuffer_dirty(struct pipe_context* pipe) { - - struct remote_context* rctx = (struct remote_context*)pipe; - - for(int i = 0; i < rctx->current_framebuffer_state.nr_cbufs; i++) - if(rctx->current_framebuffer_state.cbufs[i]) - mark_surface_dirty(rctx->current_framebuffer_state.cbufs[i]); - - if(rctx->current_framebuffer_state.zsbuf) - mark_surface_dirty(rctx->current_framebuffer_state.zsbuf); - -} - -static INLINE boolean -remote_context_draw_arrays(struct pipe_context *_pipe, - unsigned mode, unsigned start, unsigned count) -{ - - DBG("Draw arrays: mode %u, start %u, count %u\n", mode, start, count); - - mark_framebuffer_dirty(_pipe); - - ALLOC_OUT_MESSAGE(draw_arrays, message); - - message->base.opcode = REMREQ_DRAW_ARRAYS; - message->pipe = PIPE_HANDLE(_pipe); - message->mode = mode; - message->start = start; - message->count = count; - - enqueue_message(message); - - return true; - /* - QUEUE_AND_WAIT(message, draw_arrays, reply); - PANIC_IF_NULL(reply); - - boolean success = reply->success; - - free_message(reply); - - return success; - */ - -} - - -static INLINE boolean -remote_context_draw_elements(struct pipe_context *_pipe, - struct pipe_resource *indexBuffer, - unsigned indexSize, - unsigned mode, unsigned start, unsigned count) - -{ - - DBG("Draw elements: using index buffer %u, size %u, mode %u, start %u, count %u\n", BUFFER_HANDLE(indexBuffer), indexSize, mode, start, count); - - mark_framebuffer_dirty(_pipe); - - ALLOC_OUT_MESSAGE(draw_elements, message); - - message->base.opcode = REMREQ_DRAW_ELEMENTS; - message->pipe = PIPE_HANDLE(_pipe); - message->buffer = BUFFER_HANDLE(indexBuffer); - message->indexSize = indexSize; - message->mode = mode; - message->start = start; - message->count = count; - - enqueue_message(message); - - return true; - - /* - QUEUE_AND_WAIT(message, draw_elements, reply); - PANIC_IF_NULL(reply); - - boolean success = reply->success; - free_message(reply); - - return success; - */ - -} - - -static INLINE boolean -remote_context_draw_range_elements(struct pipe_context *_pipe, - struct pipe_resource *indexBuffer, - unsigned indexSize, - unsigned minIndex, - unsigned maxIndex, - unsigned mode, - unsigned start, - unsigned count) -{ - - DBG("Draw range elements: using index buffer %u, size %u, mode %u, start %u, count %u, limits %u/%u\n", BUFFER_HANDLE(indexBuffer), indexSize, mode, start, count, minIndex, maxIndex); - - mark_framebuffer_dirty(_pipe); - - ALLOC_OUT_MESSAGE(draw_range_elements, message); - - message->base.opcode = REMREQ_DRAW_RANGE_ELEMENTS; - message->pipe = PIPE_HANDLE(_pipe); - message->buffer = BUFFER_HANDLE(indexBuffer); - message->indexSize = indexSize; - message->minIndex = minIndex; - message->maxIndex = maxIndex; - message->mode = mode; - message->start = start; - message->count = count; - - enqueue_message(message); - return true; - - /* - QUEUE_AND_WAIT(message, draw_range_elements, reply); - - PANIC_IF_NULL(reply); - - boolean success = reply->success; - free_message(reply); - - return success; - */ - -} - -static INLINE void -remote_context_draw_vbo(struct pipe_context *_pipe, - const struct pipe_draw_info *info) -{ -#if 0 - ALLOC_OUT_MESSAGE(draw_vbo, message); - - message->base.opcode = REMREQ_DRAW_VBO; -#endif - DBG("Draw VBO info->mode %x\n", handle, info->mode); -} - -static INLINE struct pipe_query * -remote_context_create_query(struct pipe_context *_pipe, - unsigned query_type) -{ - -// Despite appearances, pipe_query is actually an opaque struct. - - ALLOC_OUT_MESSAGE(create_query, message); - - message->base.opcode = REMREQ_CREATE_QUERY; - message->pipe = PIPE_HANDLE(_pipe); - message->query_type = query_type; - - uint32_t handle = get_fresh_query_handle(_pipe->screen); - - DBG("New query %u, type %x\n", handle, query_type); - - message->handle = handle; - - enqueue_message(message); - - struct remote_pipe_query* opaque = CALLOC_STRUCT(remote_pipe_query); - - PANIC_IF_NULL(opaque); - - opaque->handle = handle; - - return (struct pipe_query*)opaque; - -} - - -static INLINE void -remote_context_destroy_query(struct pipe_context *_pipe, - struct pipe_query *query) -{ - - DBG("Destroy query %u\n", QUERY_HANDLE(query)); - - ALLOC_OUT_MESSAGE(destroy_query, message); - - message->base.opcode = REMREQ_DESTROY_QUERY; - message->pipe = PIPE_HANDLE(_pipe); - message->query = QUERY_HANDLE(query); - - enqueue_message(message); - -} - - -static INLINE void -remote_context_begin_query(struct pipe_context *_pipe, - struct pipe_query *query) -{ - - DBG("Begin query %u\n", QUERY_HANDLE(query)); - - ALLOC_OUT_MESSAGE(begin_query, message); - - message->base.opcode = REMREQ_BEGIN_QUERY; - message->pipe = PIPE_HANDLE(_pipe); - message->query = QUERY_HANDLE(query); - - enqueue_message(message); - -} - - -static INLINE void -remote_context_end_query(struct pipe_context *_pipe, - struct pipe_query *query) -{ - - DBG("End query %u\n", QUERY_HANDLE(query)); - - ALLOC_OUT_MESSAGE(end_query, message); - - message->base.opcode = REMREQ_END_QUERY; - message->pipe = PIPE_HANDLE(_pipe); - message->query = QUERY_HANDLE(query); - - enqueue_message(message); - -} - - -static INLINE boolean -remote_context_get_query_result(struct pipe_context *_pipe, - struct pipe_query *query, - boolean wait, - void *presult) -{ - - DBG("Get query result for query %u\n", QUERY_HANDLE(query)); - - ALLOC_OUT_MESSAGE(get_query_result, message); - - message->base.opcode = REMREQ_GET_QUERY_RESULT; - message->pipe = PIPE_HANDLE(_pipe); - message->query = QUERY_HANDLE(query); - message->wait = wait; - - QUEUE_AND_WAIT(message, get_query_result, reply); - - if(reply) { - (*(uint64_t*)presult) = reply->result; - DBG("Query result: %lu\n", reply->result); - boolean done = reply->done; - free_message(reply); - return done; - } - else { - debug_printf("!!! Got a null reply to get_query_result\n"); - exit(1); - } - -} - - -static INLINE void * -remote_context_create_blend_state(struct pipe_context *_pipe, - const struct pipe_blend_state *state) -{ - ALLOC_OUT_MESSAGE(create_blend_state, message); - - message->base.opcode = REMREQ_CREATE_BLEND_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - uint32_t handle = get_fresh_blend_handle(_pipe->screen); - message->handle = handle; - - DBG("Create blend state %u\n", handle); - - enqueue_message(message); - - struct remote_opaque_blend_state* remote_blend = CALLOC_STRUCT(remote_opaque_blend_state); - - PANIC_IF_NULL(remote_blend); - remote_blend->handle = handle; - return remote_blend; -} - - -static INLINE void -remote_context_bind_blend_state(struct pipe_context *_pipe, - void *state) -{ - - DBG("Bind blend state %u\n", BLEND_HANDLE(state)); - - ALLOC_OUT_MESSAGE(bind_blend_state, message); - - message->base.opcode = REMREQ_BIND_BLEND_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->blend_handle = BLEND_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void -remote_context_delete_blend_state(struct pipe_context *_pipe, - void *state) -{ - DBG("Delete blend state %u\n", BLEND_HANDLE(state)); - - ALLOC_OUT_MESSAGE(delete_blend_state, message); - - message->base.opcode = REMREQ_DELETE_BLEND_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->blend_handle = BLEND_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void * -remote_context_create_sampler_state(struct pipe_context *_pipe, - const struct pipe_sampler_state *state) -{ - - ALLOC_OUT_MESSAGE(create_sampler_state, message); - - message->base.opcode = REMREQ_CREATE_SAMPLER_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - uint32_t handle = get_fresh_sampler_handle(_pipe->screen); - message->handle = handle; - - DBG("Create new sampler state %u\n", handle); - - enqueue_message(message); - - struct remote_opaque_sampler_state* remote_sampler = CALLOC_STRUCT(remote_opaque_sampler_state); - - PANIC_IF_NULL(remote_sampler); - remote_sampler->handle = handle; - return remote_sampler; - -} - - -static INLINE void -remote_context_bind_sampler_states(struct pipe_context *_pipe, - unsigned num_states, void **states) -{ - - DBG("Bind sampler states: %u states\n", num_states); - - struct remreq_bind_sampler_state* header = - allocate_message_memory( - sizeof(struct remreq_bind_sampler_state) - + (num_states * sizeof(uint32_t))); - - header->base.opcode = REMREQ_BIND_SAMPLER_STATE; - header->pipe = PIPE_HANDLE(_pipe); - header->nstates = num_states; - - uint32_t* state_handles = - (uint32_t*)((char*)header + sizeof(struct remreq_bind_sampler_state)); - unsigned i; - for(i = 0; i < num_states; i++) { - state_handles[i] = SAMPLER_HANDLE(states[i]); - } - - enqueue_message(header); -} - - -static INLINE void -remote_context_delete_sampler_state(struct pipe_context *_pipe, - void *state) -{ - - DBG("Delete sampler state %u\n", SAMPLER_HANDLE(state)); - - ALLOC_OUT_MESSAGE(delete_sampler_state, message); - - message->base.opcode = REMREQ_DELETE_SAMPLER_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->sampler_handle = SAMPLER_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void * -remote_context_create_rasterizer_state(struct pipe_context *_pipe, - const struct pipe_rasterizer_state *state) -{ - - ALLOC_OUT_MESSAGE(create_rast_state, message); - - message->base.opcode = REMREQ_CREATE_RAST_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - uint32_t handle = get_fresh_rast_handle(_pipe->screen); - message->handle = handle; - - DBG("Create new rasterizer state: handle %u\n", handle); - - enqueue_message(message); - - struct remote_opaque_rast_state* remote_rast = CALLOC_STRUCT(remote_opaque_rast_state); - - PANIC_IF_NULL(remote_rast); - remote_rast->handle = handle; - return remote_rast; -} - - -static INLINE void -remote_context_bind_rasterizer_state(struct pipe_context *_pipe, - void *state) -{ - - ALLOC_OUT_MESSAGE(bind_rast_state, message); - - message->base.opcode = REMREQ_BIND_RAST_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->rast_handle = RAST_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void -remote_context_delete_rasterizer_state(struct pipe_context *_pipe, - void *state) -{ - DBG("Delete rasterizer state %u\n", RAST_HANDLE(state)); - - ALLOC_OUT_MESSAGE(delete_rast_state, message); - - message->base.opcode = REMREQ_DELETE_RAST_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->rast_handle = RAST_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void * -remote_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe, - const struct pipe_depth_stencil_alpha_state *state) -{ - ALLOC_OUT_MESSAGE(create_dsa_state, message); - - message->base.opcode = REMREQ_CREATE_DSA_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - uint32_t handle = get_fresh_dsa_handle(_pipe->screen); - message->handle = handle; - - DBG("Create depth/stencil/alpha state: handle %u\n", handle); - - enqueue_message(message); - - struct remote_opaque_dsa_state* remote_dsa = CALLOC_STRUCT(remote_opaque_dsa_state); - - PANIC_IF_NULL(remote_dsa); - remote_dsa->handle = handle; - return remote_dsa; -} - - -static INLINE void -remote_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, - void *state) -{ - - DBG("Bind depth/stencil/alpha state %u\n", DSA_HANDLE(state)); - - ALLOC_OUT_MESSAGE(bind_dsa_state, message); - - message->base.opcode = REMREQ_BIND_DSA_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->dsa_handle = DSA_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void -remote_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, - void *state) -{ - - DBG("Delete depth/stencil/alpha state %u\n", DSA_HANDLE(state)); - - ALLOC_OUT_MESSAGE(delete_dsa_state, message); - - message->base.opcode = REMREQ_DELETE_DSA_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->dsa_handle = DSA_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void * -remote_context_create_fs_state(struct pipe_context *_pipe, - const struct pipe_shader_state *state) -{ - int tokens = tgsi_num_tokens(state->tokens); - - struct remreq_create_fs_state* header = - allocate_message_memory( - sizeof(struct remreq_create_fs_state) - + (tokens * sizeof(struct tgsi_token))); - - uint32_t handle = get_fresh_fs_handle(_pipe->screen); - - header->base.opcode = REMREQ_CREATE_FS_STATE; - header->pipe = PIPE_HANDLE(_pipe); - header->fs_handle = handle; - - char* copy_dest = ((char*)header) + sizeof(struct remreq_create_fs_state); - memcpy(copy_dest, (char*)(state->tokens), sizeof(struct tgsi_token) * tokens); - - DBG("Create new FS state: handle %u\n", handle); - - enqueue_message(header); - - struct opaque_remote_fs* retval = CALLOC_STRUCT(opaque_remote_fs); - - PANIC_IF_NULL(retval); - - retval->handle = handle; - - return retval; -} - - -static INLINE void -remote_context_bind_fs_state(struct pipe_context *_pipe, - void *state) -{ - - if(state) { - DBG("Bind fragment shader %u\n", FS_HANDLE(state)); - } - else { - DBG("Bind fragment shader: no shader\n"); - } - - ALLOC_OUT_MESSAGE(bind_fs_state, message); - - message->base.opcode = REMREQ_BIND_FS_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->fs_handle = FS_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void -remote_context_delete_fs_state(struct pipe_context *_pipe, - void *state) -{ - - DBG("Delete fragment shader %u\n", FS_HANDLE(state)); - - ALLOC_OUT_MESSAGE(delete_fs_state, message); - - message->base.opcode = REMREQ_DELETE_FS_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->fs_handle = FS_HANDLE(state); - - enqueue_message(message); -} - - -static INLINE void * -remote_context_create_vs_state(struct pipe_context *_pipe, - const struct pipe_shader_state *state) -{ - - int tokens = tgsi_num_tokens(state->tokens); - - struct remreq_create_vs_state* header = - allocate_message_memory( - sizeof(struct remreq_create_vs_state) - + (tokens * sizeof(struct tgsi_token))); - - uint32_t handle = get_fresh_vs_handle(_pipe->screen); - - DBG("Create new VS state: handle %u\n", handle); - - header->base.opcode = REMREQ_CREATE_VS_STATE; - header->pipe = PIPE_HANDLE(_pipe); - header->vs_handle = handle; - - char* copy_dest = ((char*)header) + sizeof(struct remreq_create_vs_state); - memcpy(copy_dest, (char*)(state->tokens), sizeof(struct tgsi_token) * tokens); - - enqueue_message(header); - - struct opaque_remote_vs* retval = CALLOC_STRUCT(opaque_remote_vs); - - PANIC_IF_NULL(retval); - - retval->handle = handle; - - return retval; - -} - - -static INLINE void -remote_context_bind_vs_state(struct pipe_context *_pipe, - void *state) -{ - - if(state) { - DBG("Bind vertex shader state %u\n", VS_HANDLE(state)); - } - else { - DBG("Bind vertex shader: no shader\n"); - } - - ALLOC_OUT_MESSAGE(bind_vs_state, message); - - message->base.opcode = REMREQ_BIND_VS_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->vs_handle = VS_HANDLE(state); - - enqueue_message(message); - -} - - -static INLINE void -remote_context_delete_vs_state(struct pipe_context *_pipe, - void *state) -{ - - DBG("Delete vertex shader state %u\n", VS_HANDLE(state)); - - ALLOC_OUT_MESSAGE(delete_vs_state, message); - - message->base.opcode = REMREQ_DELETE_VS_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->vs_handle = VS_HANDLE(state); - - enqueue_message(message); - -} - - -static INLINE void -remote_context_set_blend_color(struct pipe_context *_pipe, - const struct pipe_blend_color *state) -{ - - DBG("Set blend color\n"); - - ALLOC_OUT_MESSAGE(set_blend_color, message); - - message->base.opcode = REMREQ_SET_BLEND_COLOR; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - enqueue_message(message); - -} - - -static INLINE void -remote_context_set_clip_state(struct pipe_context *_pipe, - const struct pipe_clip_state *state) -{ - - DBG("Set clip state\n"); - - ALLOC_OUT_MESSAGE(set_clip_state, message); - - message->base.opcode = REMREQ_SET_CLIP_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - enqueue_message(message); - -} - - -static INLINE void -remote_context_set_constant_buffer(struct pipe_context *_pipe, - uint shader, uint index, - struct pipe_resource *buffer) -{ - - DBG("Set constant buffer for shader %u, index %u\n", shader, index); - - ALLOC_OUT_MESSAGE(set_constant_buffer, message); - - message->base.opcode = REMREQ_SET_CONSTANT_BUFFER; - message->pipe = PIPE_HANDLE(_pipe); - message->shader = shader; - message->index = index; - message->buffer = BUFFER_HANDLE(buffer); - /* - char* mapped = (char*)pipe_buffer_map(_pipe->screen, buffer->buffer, PIPE_BUFFER_USAGE_CPU_READ); - - debug_printf("On setting, constant buffer goes like this:\n"); - - int i; - for(i = 0; i < buffer->size; i++) { - debug_printf("%4d ", (int)mapped[i]); - if(i % 8 == 7) - debug_printf("\n"); - } - debug_printf("\n"); - - pipe_buffer_unmap(_pipe->screen, buffer->buffer); - */ - enqueue_message(message); - -} - - -static INLINE void -remote_context_set_framebuffer_state(struct pipe_context *_pipe, - const struct pipe_framebuffer_state *state) -{ - unsigned i; - ALLOC_OUT_MESSAGE(set_framebuffer_state, message); - - message->base.opcode = REMREQ_SET_FRAMEBUFFER_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->fbwidth = state->width; - message->fbheight = state->height; - message->fbnum_cbufs = state->nr_cbufs; - message->fbzsbuf = state->zsbuf ? SURFACE_HANDLE(state->zsbuf) : 0; - for(i = 0; i < PIPE_MAX_COLOR_BUFS; i++) - message->fbcbufs[i] = state->cbufs[i] ? SURFACE_HANDLE(state->cbufs[i]) : 0; - - DBG("Set framebuffer state: %dx%d\n", state->width, state->height); - if(message->fbzsbuf) { - DBG("Z/stencil buffer: %u\n", message->fbzsbuf); - } - else { - DBG("No Z/stencil buffer\n"); - } - - for(i = 0; i < PIPE_MAX_COLOR_BUFS; i++) - if(message->fbcbufs[i]) - DBG("Colour buffer %d: texture %u\n", i, message->fbcbufs[i]); - - enqueue_message(message); - - struct remote_context* rctx = (struct remote_context*)_pipe; - - rctx->current_framebuffer_state = *state; // Struct copy - -} - - -static INLINE void -remote_context_set_polygon_stipple(struct pipe_context *_pipe, - const struct pipe_poly_stipple *state) -{ - - DBG("Set polygon stipple\n"); - - ALLOC_OUT_MESSAGE(set_polygon_stipple, message); - - message->base.opcode = REMREQ_SET_POLYGON_STIPPLE; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - enqueue_message(message); -} - - -static INLINE void -remote_context_set_scissor_state(struct pipe_context *_pipe, - const struct pipe_scissor_state *state) -{ - - DBG("Set scissor state\n"); - - ALLOC_OUT_MESSAGE(set_scissor_state, message); - - message->base.opcode = REMREQ_SET_SCISSOR_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - enqueue_message(message); -} - - -static INLINE void -remote_context_set_viewport_state(struct pipe_context *_pipe, - const struct pipe_viewport_state *state) -{ - - DBG("Set viewport state\n"); - - ALLOC_OUT_MESSAGE(set_viewport_state, message); - - message->base.opcode = REMREQ_SET_VIEWPORT_STATE; - message->pipe = PIPE_HANDLE(_pipe); - message->state = *state; - // Struct copy - - enqueue_message(message); -} - - -#if 0 -static INLINE void -remote_context_set_sampler_textures(struct pipe_context *_pipe, - unsigned num_textures, - struct pipe_texture **textures) -{ - // Similar to below - - DBG("Set sampler textures\n"); - - struct remreq_set_sampler_textures* header = - (struct remreq_set_sampler_textures*) - allocate_message_memory( - sizeof(struct remreq_set_sampler_textures) + - num_textures * sizeof(uint32_t)); - - header->base.opcode = REMREQ_SET_SAMPLER_TEXTURES; - header->pipe = PIPE_HANDLE(_pipe); - header->num_textures = num_textures; - - uint32_t* texhandles = (uint32_t*) - ((char*)header + sizeof(struct remreq_set_sampler_textures)); - - unsigned i; - - for(i = 0; i < num_textures; i++) { - texhandles[i] = textures[i] ? TEXTURE_HANDLE(textures[i]) : 0; - DBG("Sampler slot %d: texture %u\n", i, texhandles[i]); - } - - enqueue_message(header); - -} -#endif - - -static INLINE void -remote_context_set_vertex_buffers(struct pipe_context *_pipe, - unsigned num_buffers, - const struct pipe_vertex_buffer *buffers) -{ - // Each vertex_buffer points to a pipe_buffer, which here is actually - // a remote_pipe_buffer. Flatten those references and send an array - // which gives the buffer by opaque handle - - DBG("Set vertex buffers: %d buffers\n", num_buffers); - - struct remreq_set_vertex_buffers* header = - (struct remreq_set_vertex_buffers*) - allocate_message_memory( - sizeof(struct remreq_set_vertex_buffers) + - (num_buffers * sizeof(struct opaque_pipe_vertex_element))); - - PANIC_IF_NULL(header); - - header->base.opcode = REMREQ_SET_VERTEX_BUFFERS; - header->pipe = PIPE_HANDLE(_pipe); - header->num_buffers = num_buffers; - - struct opaque_pipe_vertex_element* data = - (struct opaque_pipe_vertex_element*) - (((char*)header) + sizeof(struct remreq_set_vertex_buffers)); - - unsigned i; - - for(i = 0; i < num_buffers; i++) { - data[i].stride = buffers[i].stride; - data[i].buffer_offset = buffers[i].buffer_offset; - data[i].buffer = buffers[i].buffer ? BUFFER_HANDLE(buffers[i].buffer) : 0; - DBG("Buffer slot %d assigned buffer handle %u\n", i, data[i].buffer); - } - - enqueue_message(header); - -} - - -static INLINE void -remote_context_set_vertex_elements(struct pipe_context *_pipe, - unsigned num_elements, - const struct pipe_vertex_element *elements) -{ - // Send array - - DBG("Set vertex elements: %u elements\n", num_elements); - - struct remreq_set_vertex_elements* header = - (struct remreq_set_vertex_elements*) - allocate_message_memory( - sizeof(struct remreq_set_vertex_elements) + - num_elements * sizeof(struct pipe_vertex_element)); - - header->base.opcode = REMREQ_SET_VERTEX_ELEMENTS; - header->pipe = PIPE_HANDLE(_pipe); - header->num_elements = num_elements; - - char* dest = ((char*)header) + sizeof(struct remreq_set_vertex_elements); - memcpy(dest, (void*)elements, num_elements * sizeof(struct pipe_vertex_element)); - - enqueue_message(header); - -} - - -static INLINE void -remote_context_surface_copy(struct pipe_context *_pipe, - boolean do_flip, - struct pipe_surface *dest, - unsigned destx, unsigned desty, - struct pipe_surface *src, - unsigned srcx, unsigned srcy, - unsigned width, unsigned height) -{ - - DBG("Surface copy: %u-%ux%u-%ux%u --> %u-%ux%u\n", SURFACE_HANDLE(src), srcx, srcy, srcx + width, srcy + height, SURFACE_HANDLE(dest), destx, desty); - - ALLOC_OUT_MESSAGE(surface_copy, message); - - message->base.opcode = REMREQ_SURFACE_COPY; - message->pipe = PIPE_HANDLE(_pipe); - message->src = SURFACE_HANDLE(src); - message->dest = SURFACE_HANDLE(dest); - message->sx = srcx; - message->sy = srcy; - message->dx = destx; - message->dy = desty; - message->w = width; - message->h = height; - message->do_flip = do_flip; - - enqueue_message(message); - -} - - -static INLINE void -remote_context_surface_fill(struct pipe_context *_pipe, - struct pipe_surface *dst, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, - unsigned value) -{ - - DBG("Surface fill: %u-%ux%u-%ux%u with %x\n", PIPE_HANDLE(dst), dstx, dsty, dstx + width, dsty + height, value); - - ALLOC_OUT_MESSAGE(surface_fill, message); - - message->base.opcode = REMREQ_SURFACE_FILL; - message->pipe = PIPE_HANDLE(_pipe); - message->surface = SURFACE_HANDLE(dst); - message->x = dstx; - message->y = dsty; - message->w = width; - message->h = height; - message->value = value; - - enqueue_message(message); - -} - - -static INLINE void -remote_context_clear(struct pipe_context *_pipe, - unsigned buffers, - const float *rgba, - double depth, - unsigned stencil) -{ - - DBG("Clear surface %u with %x\n", SURFACE_HANDLE(surface), clearValue); - - ALLOC_OUT_MESSAGE(clear, message); - - message->base.opcode = REMREQ_CLEAR; - message->pipe = PIPE_HANDLE(_pipe); - message->buffers = buffers; - message->has_rgba = rgba != NULL ? 1 : 0; - if (rgba) { - message->rgba[0] = rgba[0]; - message->rgba[1] = rgba[1]; - message->rgba[2] = rgba[2]; - message->rgba[3] = rgba[3]; - } - message->depth = depth; - message->stencil = stencil; - - enqueue_message(message); - -} - - -static INLINE void -remote_context_flush(struct pipe_context *_pipe, - struct pipe_fence_handle **fence) -{ - - DBG("Flush\n"); - - ALLOC_OUT_MESSAGE(flush, message); - - message->base.opcode = REMREQ_FLUSH; - message->pipe = PIPE_HANDLE(_pipe); - - /* !!! I *think* fence is out-only */ - - enqueue_message(message); - - if(fence) *fence = NULL; - -} - - -static INLINE void -remote_context_destroy(struct pipe_context *_pipe) -{ - ALLOC_OUT_MESSAGE(destroy_context, message); - - DBG("Destroying context %u\n", PIPE_HANDLE(_pipe)); - - message->base.opcode = REMREQ_DESTROY_CONTEXT; - message->pipe = PIPE_HANDLE(_pipe); - - enqueue_message(message); - - FREE((struct remote_context*)_pipe); -} - -static INLINE void -remote_context_bind_fragment_sampler_states(struct pipe_context *_pipe, - unsigned num_states, - void **states) -{ - DBG("context_bind_fragment_sampler_states %u\n", PIPE_HANDLE(_pipe)); -} - -static INLINE void -remote_context_bind_vertex_sampler_states(struct pipe_context *_pipe, - unsigned num_states, - void **states) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static INLINE void * -remote_context_create_vertex_elements_state(struct pipe_context *_pipe, - unsigned num_elements, - const struct pipe_vertex_element *elements) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); - return NULL; -} - -static INLINE void -remote_context_bind_vertex_elements_state(struct pipe_context *_pipe, - void *state) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static INLINE void -remote_context_delete_vertex_elements_state(struct pipe_context *_pipe, - void *state) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static INLINE void -remote_context_set_stencil_ref(struct pipe_context *_pipe, - const struct pipe_stencil_ref *state) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static INLINE void -remote_context_set_sample_mask(struct pipe_context *_pipe, - unsigned sample_mask) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static INLINE void -remote_context_set_fragment_sampler_views(struct pipe_context *_pipe, - unsigned num, - struct pipe_sampler_view **views) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static INLINE void -remote_context_set_vertex_sampler_views(struct pipe_context *_pipe, - unsigned num, - struct pipe_sampler_view **views) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static struct pipe_sampler_view * -remote_create_sampler_view(struct pipe_context *_pipe, - struct pipe_resource *_resource, - const struct pipe_sampler_view *templ) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); - return NULL; -} - -static void -remote_sampler_view_destroy(struct pipe_context *_pipe, - struct pipe_sampler_view *_view) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - - -static struct pipe_surface * -remote_create_surface(struct pipe_context *_pipe, - struct pipe_resource *_resource, - const struct pipe_surface *surf_tmpl) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); - return NULL; -} - - -static void -remote_surface_destroy(struct pipe_context *_pipe, - struct pipe_surface *_surface) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - - -static INLINE void -remote_context_set_index_buffer(struct pipe_context *_pipe, - const struct pipe_index_buffer *ib) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static INLINE void -remote_context_resource_copy_region(struct pipe_context *_pipe, - struct pipe_resource *dst, - unsigned dst_level, - unsigned dstx, unsigned dsty, unsigned dstz, - struct pipe_resource *src, - unsigned src_level, - const struct pipe_box *src_box) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static INLINE void -remote_context_clear_render_target(struct pipe_context *_pipe, - struct pipe_surface *dst, - const float *rgba, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - - -static INLINE void -remote_context_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) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - - -static struct pipe_transfer * -remote_context_get_transfer(struct pipe_context *_context, - struct pipe_resource *_resource, - unsigned level, - unsigned usage, - const struct pipe_box *box) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); - return NULL; -} - - -static void -remote_context_transfer_destroy(struct pipe_context *_context, - struct pipe_transfer *_transfer) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - - -static void * -remote_context_transfer_map(struct pipe_context *_context, - struct pipe_transfer *_transfer) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); - return NULL; -} - - -static void -remote_context_transfer_flush_region( struct pipe_context *_context, - struct pipe_transfer *_transfer, - const struct pipe_box *box) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - -static void -remote_context_transfer_unmap(struct pipe_context *_context, - struct pipe_transfer *_transfer) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - - -static void -remote_context_transfer_inline_write(struct pipe_context *_context, - struct pipe_resource *_resource, - unsigned level, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned layer_stride) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - - -static void remote_redefine_user_buffer(struct pipe_context *_context, - struct pipe_resource *_resource, - unsigned offset, unsigned size) -{ - DBG("UNIMPLEMENTED %s\n", __FUNCTION__); -} - - -struct pipe_context * -remote_context_create(struct pipe_screen *screen, - struct pipe_context *pipe) -{ - struct remote_context *tr_ctx; - - DBG("Creating new context for screen %u\n", SCREEN_HANDLE(screen)); - - tr_ctx = CALLOC_STRUCT(remote_context); - if(!tr_ctx) - goto error1; - tr_ctx->base.winsys = screen->winsys; - tr_ctx->base.screen = screen; - tr_ctx->base.destroy = remote_context_destroy; - tr_ctx->base.draw_vbo = remote_context_draw_vbo; // new - tr_ctx->base.create_query = remote_context_create_query; - tr_ctx->base.destroy_query = remote_context_destroy_query; - tr_ctx->base.begin_query = remote_context_begin_query; - tr_ctx->base.end_query = remote_context_end_query; - tr_ctx->base.get_query_result = remote_context_get_query_result; - tr_ctx->base.create_blend_state = remote_context_create_blend_state; - tr_ctx->base.bind_blend_state = remote_context_bind_blend_state; - tr_ctx->base.delete_blend_state = remote_context_delete_blend_state; - tr_ctx->base.create_sampler_state = remote_context_create_sampler_state; - tr_ctx->base.bind_fragment_sampler_states = remote_context_bind_fragment_sampler_states; // new - tr_ctx->base.bind_vertex_sampler_states = remote_context_bind_vertex_sampler_states; // new - tr_ctx->base.delete_sampler_state = remote_context_delete_sampler_state; - tr_ctx->base.create_rasterizer_state = remote_context_create_rasterizer_state; - tr_ctx->base.bind_rasterizer_state = remote_context_bind_rasterizer_state; - tr_ctx->base.delete_rasterizer_state = remote_context_delete_rasterizer_state; - tr_ctx->base.create_depth_stencil_alpha_state = remote_context_create_depth_stencil_alpha_state; - tr_ctx->base.bind_depth_stencil_alpha_state = remote_context_bind_depth_stencil_alpha_state; - tr_ctx->base.delete_depth_stencil_alpha_state = remote_context_delete_depth_stencil_alpha_state; - tr_ctx->base.create_fs_state = remote_context_create_fs_state; - tr_ctx->base.bind_fs_state = remote_context_bind_fs_state; - tr_ctx->base.delete_fs_state = remote_context_delete_fs_state; - tr_ctx->base.create_vs_state = remote_context_create_vs_state; - tr_ctx->base.bind_vs_state = remote_context_bind_vs_state; - tr_ctx->base.delete_vs_state = remote_context_delete_vs_state; - tr_ctx->base.create_vertex_elements_state = remote_context_create_vertex_elements_state; // new - tr_ctx->base.bind_vertex_elements_state = remote_context_bind_vertex_elements_state; // new - tr_ctx->base.delete_vertex_elements_state = remote_context_delete_vertex_elements_state; // new - tr_ctx->base.set_blend_color = remote_context_set_blend_color; - tr_ctx->base.set_stencil_ref = remote_context_set_stencil_ref; // new - tr_ctx->base.set_clip_state = remote_context_set_clip_state; - tr_ctx->base.set_sample_mask = remote_context_set_sample_mask; // new - tr_ctx->base.set_constant_buffer = remote_context_set_constant_buffer; - tr_ctx->base.set_framebuffer_state = remote_context_set_framebuffer_state; - tr_ctx->base.set_polygon_stipple = remote_context_set_polygon_stipple; - tr_ctx->base.set_scissor_state = remote_context_set_scissor_state; - tr_ctx->base.set_viewport_state = remote_context_set_viewport_state; - tr_ctx->base.set_fragment_sampler_views = remote_context_set_fragment_sampler_views; // new - tr_ctx->base.set_vertex_sampler_views = remote_context_set_vertex_sampler_views; // new - tr_ctx->base.create_sampler_view = remote_create_sampler_view; // new - tr_ctx->base.sampler_view_destroy = remote_sampler_view_destroy; // new - tr_ctx->base.create_surface = remote_create_surface; // new - tr_ctx->base.surface_destroy = remote_surface_destroy; // new - tr_ctx->base.set_vertex_buffers = remote_context_set_vertex_buffers; - tr_ctx->base.set_index_buffer = remote_context_set_index_buffer; // new - tr_ctx->base.resource_copy_region = remote_context_resource_copy_region; // new - tr_ctx->base.clear = remote_context_clear; - tr_ctx->base.clear_render_target = remote_context_clear_render_target; // new - tr_ctx->base.clear_depth_stencil = remote_context_clear_depth_stencil; // new - tr_ctx->base.flush = remote_context_flush; - - tr_ctx->base.get_transfer = remote_context_get_transfer; // new - tr_ctx->base.transfer_destroy = remote_context_transfer_destroy; // new - tr_ctx->base.transfer_map = remote_context_transfer_map; // new - tr_ctx->base.transfer_unmap = remote_context_transfer_unmap; // new - tr_ctx->base.transfer_flush_region = remote_context_transfer_flush_region; // new - tr_ctx->base.transfer_inline_write = remote_context_transfer_inline_write; // new - tr_ctx->base.redefine_user_buffer = remote_redefine_user_buffer; // new - -#if 0 - // Old (vgallium 2009) - tr_ctx->base.set_edgeflags = remote_context_set_edgeflags; - tr_ctx->base.draw_arrays = remote_context_draw_arrays; - tr_ctx->base.draw_elements = remote_context_draw_elements; - tr_ctx->base.draw_range_elements = remote_context_draw_range_elements; - tr_ctx->base.bind_sampler_states = remote_context_bind_sampler_states; - tr_ctx->base.set_sampler_textures = remote_context_set_sampler_textures; - tr_ctx->base.set_vertex_elements = remote_context_set_vertex_elements; - tr_ctx->base.surface_copy = remote_context_surface_copy; - tr_ctx->base.surface_fill = remote_context_surface_fill; -#endif - - memset(&tr_ctx->current_framebuffer_state, 0, sizeof(struct pipe_framebuffer_state)); - - ALLOC_OUT_MESSAGE(create_context, message); - - struct remote_screen* remscreen = (struct remote_screen*)screen; - - message->base.opcode = REMREQ_CREATE_CONTEXT; - message->screen = remscreen->remote_handle; - - QUEUE_AND_WAIT(message, create_context, reply); - - if(reply) { - DBG("Got reply: assigned handle %u\n", reply->handle); - tr_ctx->remote_handle = reply->handle; - free_message(reply); - return &tr_ctx->base; - } - else { - return NULL; - } - -error1: - return NULL; -} -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/drivers/remote/tr_context.h b/src/gallium/drivers/remote/tr_context.h deleted file mode 100644 index 600d389586..0000000000 --- a/src/gallium/drivers/remote/tr_context.h +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef TR_CONTEXT_H_ -#define TR_CONTEXT_H_ - - -#include "pipe/p_compiler.h" -#include "util/u_debug.h" -#include "pipe/p_context.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - -struct remote_context -{ - struct pipe_context base; - uint32_t remote_handle; - - struct pipe_framebuffer_state current_framebuffer_state; - -}; - - -static INLINE struct remote_context * -remote_context(struct pipe_context *pipe) -{ - assert(pipe); - return (struct remote_context *)pipe; -} - - - -struct pipe_context * -remote_context_create(struct pipe_screen *screen, - struct pipe_context *pipe); - - -#ifdef __cplusplus -} -#endif - -#endif /* TR_CONTEXT_H_ */ diff --git a/src/gallium/drivers/remote/tr_screen.c b/src/gallium/drivers/remote/tr_screen.c deleted file mode 100644 index dfa49ba4af..0000000000 --- a/src/gallium/drivers/remote/tr_screen.c +++ /dev/null @@ -1,663 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifdef USE_XEN -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "util/u_inlines.h" -#include "pipe/p_defines.h" -#include "util/u_memory.h" - -#include "remote_state.h" -#include "remote_util.h" -#include "remote_comms.h" -#include "remote_messages.h" -#include "remote_debug.h" -#include "tr_screen.h" -//#include "tr_winsys.h" - -/* A few of the objects dealt with here are refcounted. Of course, the remote side is refcounting too. Since functions - like pipe_texture_reference and so on in some cases just adjust the refcount variable without making a callback, - I can't be sure of always letting the remote side know about references. - - My solution: - - * Each proxy object (e.g. remote_texture) corresponds to exactly one remote reference. - * The proxies themselves are refcounted. So, when a proxy dies, the remote object gets a single deref. - - i.e. the objects in this address space are being refcounted, and their existence corresponds to a single - reference in the remote address space. - -*/ - -int analyse_waits = 0; -// A global to indicate whether we desire print statements reporting on how and why we waited for remote action - -static const char * -remote_screen_get_name(struct pipe_screen *_screen) -{ - - return "Xen virtual 3D\n"; - -} - - -static const char * -remote_screen_get_vendor(struct pipe_screen *_screen) -{ - - return "Chris Smowton\n"; - -} - - -static int -remote_screen_get_param(struct pipe_screen *_screen, - enum pipe_cap param) { - - struct remote_screen* rscreen = (struct remote_screen*)_screen; - - if(rscreen->int_param_is_cached[param]) - return rscreen->cached_int_params[param]; - - ALLOC_OUT_MESSAGE(get_param, message); - - message->base.opcode = REMREQ_GET_PARAM; - message->screen = SCREEN_HANDLE(_screen); - message->param = param; - - if(analyse_waits) - debug_printf("WAIT: get_param\n"); - QUEUE_AND_WAIT(message, get_param, reply); - - DBG("Get integer parameter %d: value is %d\n", param, reply->response); - - rscreen->cached_int_params[param] = reply->response; - rscreen->int_param_is_cached[param] = 1; - int response = reply->response; - free_message(reply); - return response; - -} - -static int -remote_screen_get_shader_param(struct pipe_screen *_screen, unsigned shader, - enum pipe_shader_cap param) -{ - return 0; -} - - -static float -remote_screen_get_paramf(struct pipe_screen *_screen, - enum pipe_cap param) -{ - - struct remote_screen* rscreen = (struct remote_screen*)_screen; - - if(rscreen->float_param_is_cached[param]) - return rscreen->cached_float_params[param]; - - ALLOC_OUT_MESSAGE(get_paramf, message); - - message->base.opcode = REMREQ_GET_PARAMF; - message->screen = SCREEN_HANDLE(_screen); - message->param = param; - - if(analyse_waits) - debug_printf("WAIT: float param\n"); - QUEUE_AND_WAIT(message, get_paramf, reply); - - DBG("Get FP parameter %d: value is %f\n", param, reply->response); - - rscreen->cached_float_params[param] = reply->response; - rscreen->float_param_is_cached[param] = 1; - - float response = reply->response; - free_message(reply); - return response; - -} - - -static boolean -remote_screen_is_format_supported(struct pipe_screen *_screen, - enum pipe_format format, - enum pipe_texture_target target, - unsigned tex_usage, - unsigned geom_flags) -{ - - ALLOC_OUT_MESSAGE(is_format_supported, message); - - message->base.opcode = REMREQ_IS_FORMAT_SUPPORTED; - message->screen = SCREEN_HANDLE(_screen); - message->format = format; - message->target = target; - message->tex_usage = tex_usage; - message->geom_flags = geom_flags; - - if(analyse_waits) - debug_printf("WAIT: format_supported\n"); - QUEUE_AND_WAIT(message, is_format_supported, reply); - - if(reply->response) - DBG("Format query: accepted\n"); - else - DBG("Format query: denied\n"); - - boolean response = reply->response; - free_message(reply); - return response; - -} - -static int get_or_alloc_buffer_handle(struct remote_buffer* rbuf, - struct pipe_screen* screen, - uint32_t* handle) { - - if(rbuf->handle) { - *handle = rbuf->handle; - return 0; - } - else { - *handle = get_fresh_buffer_handle(screen); - rbuf->handle = *handle; - return 1; - } - -} - -static void -remote_screen_destroy(struct pipe_screen *_screen) -{ - struct remote_screen *tr_scr = remote_screen(_screen); - - DBG("Destroying screen %u: closing connection\n", SCREEN_HANDLE(_screen)); - - close(tr_scr->socketfd); - - FREE(tr_scr); -} - -static struct pipe_context * -remote_screen_context_create(struct pipe_screen *_screen, void *priv) -{ - DBG("%s: unimplemented\n", __FUNCTION__); - return NULL; -} - -static void -remote_screen_flush_frontbuffer(struct pipe_screen *_screen, - struct pipe_resource *_resource, - unsigned level, unsigned layer, - void *context_private) -{ - DBG("%s: unimplemented\n", __FUNCTION__); -} - - -/******************************************************************** - * texture - */ - -static struct pipe_resource * -remote_screen_resource_create(struct pipe_screen *_screen, - const struct pipe_resource *templat) -{ - struct pipe_resource *result = NULL; - - DBG("%s: unimplemented\n", __FUNCTION__); - return result; -} - -static struct pipe_resource * -remote_screen_resource_from_handle(struct pipe_screen *_screen, - const struct pipe_resource *templ, - struct winsys_handle *handle) -{ - struct pipe_resource *result = NULL; - - DBG("%s: unimplemented\n", __FUNCTION__); - return result; -} - -static boolean -remote_screen_resource_get_handle(struct pipe_screen *_screen, - struct pipe_resource *_resource, - struct winsys_handle *handle) -{ - DBG("%s: unimplemented\n", __FUNCTION__); - return false; -} - -static void -remote_screen_resource_destroy(struct pipe_screen *_screen, - struct pipe_resource *_resource) -{ - DBG("%s: unimplemented\n", __FUNCTION__); -} - -/******************************************************************** - * buffer - */ - -static struct pipe_resource * -remote_screen_user_buffer_create(struct pipe_screen *_screen, - void *data, - unsigned size, - unsigned usage) -{ - DBG("%s: unimplemented\n", __FUNCTION__); - return NULL; -} - - -/******************************************************************** - * fence - */ - - -static void -remote_screen_fence_reference(struct pipe_screen *_screen, - struct pipe_fence_handle **pdst, - struct pipe_fence_handle *src) -{ - DBG("%s: unimplemented\n", __FUNCTION__); -} - - -static boolean -remote_screen_fence_signalled(struct pipe_screen *_screen, - struct pipe_fence_handle *fence) -{ - DBG("%s: unimplemented\n", __FUNCTION__); - return false; -} - - -static boolean -remote_screen_fence_finish(struct pipe_screen *_screen, - struct pipe_fence_handle *fence, - uint64_t timeout) -{ - DBG("%s: unimplemented\n", __FUNCTION__); - return false; -} - -#ifdef XEN_HOST -// currently broken -static void setup_xen_connection(struct remote_screen* tr_scr) -{ - // Set up a Xen-IDC connection to describe graphics events to the host - - struct sockaddr_un sun; - - sun.sun_family = AF_UNIX; - strcpy(sun.sun_path, "/var/run/xen3dd-socket"); - - tr_scr->socketfd = socket(PF_UNIX, SOCK_STREAM, 0); - DBG("Socket fd is %d\n", tr_scr->socketfd); - - if(tr_scr->socketfd == -1) { - debug_printf("socket() failed creating a new screen\n"); - exit(1); - } - - if(connect(tr_scr->socketfd, - &sun, - sizeof(sun.sun_family) + strlen(sun.sun_path)) < 0) { - debug_printf("Couldn't connect to /var/run/xen3dd-socket\n"); - exit(1); - } - - DBG("Successfully connected\n"); - - // Now create two initally-empty ring buffers, one for RX and one for TX. - - struct { - uint32_t* grants; - void** map; - } togrant[2] = { - { .grants = tr_scr->rx_grants, .map = &(tr_scr->rx_buffer) }, - { .grants = tr_scr->tx_grants, .map = &(tr_scr->tx_buffer) } - }; - - DBG("tr_scr->rx_grants is %p, tr_scr->tx_grants is %p\n", tr_scr->rx_grants, tr_scr->tx_grants); - - for(int k = 0; k < 4; k++) { - - DBG("RX grant %d is currently %u\n", k, tr_scr->rx_grants[k]); - DBG("TX grant %d is currently %u\n", k, tr_scr->tx_grants[k]); - - } - - for(int i = 0; i < 2; i++) { - int fd = open("/dev/gntmem", O_RDWR); - int ret; - - DBG("Opened /dev/gntmem; got fd %d\n", fd); - - if(fd == -1) { - debug_printf("Failed to open /dev/gntmem\n"); - exit(1); - } - - ret = ioctl(fd, IOCTL_GNTMEM_SET_DOMAIN, 0); - - DBG("set-domain 0 returned %d\n", ret); - - if(ret == -1) { - debug_printf("Failed to set gntmem's target domain\n"); - exit(1); - } - - ret = ioctl(fd, IOCTL_GNTMEM_SET_SIZE, 4); - - DBG("set-size 4 returned %d\n", ret); - - if(ret == -1) { - debug_printf("Failed to create a shareable section of 4 pages\n"); - exit(1); - } - - DBG("Going to write grants starting at address %p\n", togrant[i].grants); - - ret = ioctl(fd, IOCTL_GNTMEM_GET_GRANTS, togrant[i].grants); - - DBG("get-grants returned %d\n", ret); - DBG("After get-grants, have address %p\n", togrant[i].grants); - - for(int j = 0; j < 4; j++) { - - DBG("Grant #%d is %u\n", j, (togrant[i].grants)[j]); - - } - - if(ret == -1) { - debug_printf("Failed to get grants for shared section\n"); - exit(1); - } - - *(togrant[i].map) = (void*)-1; - *(togrant[i].map) = mmap(0, 4096 * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - - DBG("Mapped as a shared section: got address %p\n", *(togrant[i].map)); - - if(*(togrant[i].map) == (void*)-1) { - debug_printf("Couldn't mmap our shared section\n"); - exit(1); - } - - close(fd); - // Will remain in existence until an munmap - - // Now init the ring-buffer before we announce to the daemon - uint32_t* initdata = (uint32_t*)*(togrant[i].map); - DBG("Configuring initdata at %p\n", initdata); - uint32_t buffersize = (4096 * 4) - (sizeof(uint32_t) * 3); - initdata[0] = buffersize; - // total buffer size - initdata[1] = 0; - initdata[2] = 0; - // Next byte to read and next-to-write respectively. - // Equality signals the buffer is empty, write = read - 1 signals it is full - } - - DBG("Successfully created ring buffers\n"); - DBG("On exit have rx at %p, tx at %p\n", tr_scr->rx_buffer, tr_scr->tx_buffer); - - // Okay, both ring buffers exist. Now send the grants to the daemon. - struct { - uint32_t rx_grants[4]; - uint32_t tx_grants[4]; - char is_x; - } tosend; - - for(int i = 0; i < 4; i++) { - tosend.rx_grants[i] = tr_scr->rx_grants[i]; - tosend.tx_grants[i] = tr_scr->tx_grants[i]; - } - - tosend.is_x = 0; - - int bytessent = 0; - - while(bytessent < sizeof(tosend)) { - - DBG("Going around; bytessent = %d, about to try to to send %lu on fd %d\n", bytessent, sizeof(tosend) - bytessent, tr_scr->socketfd); - - int sent = send(tr_scr->socketfd, ((char*)&tosend) + bytessent, sizeof(tosend) - bytessent, 0); - - DBG("Just sent %d bytes\n", sent); - - if(sent <= 0) { - debug_printf("Failed to send init message to xen3dd: return %d with errno %d\n", sent, errno); - exit(1); - } - else { - bytessent += sent; - } - - } - - DBG("Successfully relayed that to the compositor\n"); -} -#endif - -static void setup_virtio_connection(struct remote_screen* tr_scr) -{ - DBG("%s: unimplemented\n", __FUNCTION__); -} - -static void setup_host_connection(struct remote_screen* tr_scr) -{ -#ifdef XEN_HOST - setup_xen_connection(tr_scr); -#else - setup_virtio_connection(tr_scr); -#endif -} - -struct pipe_screen * -remote_screen_create(struct pipe_winsys* winsys) -{ - - struct remote_screen* tr_scr = CALLOC_STRUCT(remote_screen); - - memset(tr_scr, 0, sizeof(struct remote_screen)); - - DBG("Creating new screen\n"); - - if(!tr_scr) { - debug_printf("Alloc failed in remote_screen_create!\n"); - return NULL; - } - - tr_scr->base.winsys = winsys; - tr_scr->base.destroy = remote_screen_destroy; - tr_scr->base.get_name = remote_screen_get_name; - tr_scr->base.get_vendor = remote_screen_get_vendor; - tr_scr->base.get_param = remote_screen_get_param; - tr_scr->base.get_shader_param = remote_screen_get_shader_param; - tr_scr->base.get_paramf = remote_screen_get_paramf; - tr_scr->base.is_format_supported = remote_screen_is_format_supported; - tr_scr->base.context_create = remote_screen_context_create; - tr_scr->base.resource_create = remote_screen_resource_create; - tr_scr->base.resource_from_handle = remote_screen_resource_from_handle; - tr_scr->base.resource_get_handle = remote_screen_resource_get_handle; - tr_scr->base.resource_destroy = remote_screen_resource_destroy; - tr_scr->base.user_buffer_create = remote_screen_user_buffer_create; - tr_scr->base.fence_reference = remote_screen_fence_reference; - tr_scr->base.fence_signalled = remote_screen_fence_signalled; - tr_scr->base.fence_finish = remote_screen_fence_finish; - tr_scr->base.flush_frontbuffer = remote_screen_flush_frontbuffer; - tr_scr->last_query_handle = 1; - tr_scr->last_blend_handle = 1; - tr_scr->last_dsa_handle = 1; - tr_scr->last_rast_handle = 1; - tr_scr->last_sampler_handle = 1; - tr_scr->last_fs_handle = 1; - tr_scr->last_vs_handle = 1; - tr_scr->last_texture_handle = 1; - tr_scr->last_surface_handle = 1; - tr_scr->last_buffer_handle = 1; - tr_scr->last_window_handle = 1; - - // Check if the user requests wait analysis - - analyse_waits = 0; - - char* analyse_waits_env = getenv("VG_ANALYSE_WAITS"); - if(analyse_waits_env) { - if(analyse_waits_env[0] == '1') { - debug_printf("Enabled wait analysis\n"); - analyse_waits = 1; - } - } - - setup_host_connection(tr_scr); - - return &(tr_scr->base); -} - -int complete_screen_creation(struct remote_screen* screen) { - - ALLOC_OUT_MESSAGE(create_screen, message); - - message->base.opcode = REMREQ_CREATE_SCREEN; - - DBG("WAIT: Screen creation\n"); - QUEUE_AND_WAIT(message, create_screen, reply); - - uint32_t handle = reply->handle; - - free_message(reply); - - if(!handle) - return 0; - else { - DBG("Got handle %u\n", handle); - screen->remote_handle = handle; - return 1; - } - -} - - -struct remote_screen * -remote_screen(struct pipe_screen *screen) -{ - assert(screen); - assert(screen->destroy == remote_screen_destroy); - return (struct remote_screen *)screen; -} - -// Handle generation functions. Currently these just assign sequential numbers. -// If a 32-bit space for e.g. buffers becomes a problem will need to expand that. - -uint32_t get_fresh_query_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_query_handle++; - -} - -uint32_t get_fresh_blend_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_blend_handle++; - -} - -uint32_t get_fresh_sampler_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_sampler_handle++; - -} - -uint32_t get_fresh_rast_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_rast_handle++; - -} - -uint32_t get_fresh_dsa_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_dsa_handle++; - -} - -uint32_t get_fresh_vs_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_vs_handle++; - -} - -uint32_t get_fresh_fs_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_fs_handle++; - -} - -uint32_t get_fresh_texture_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_texture_handle++; - -} - -uint32_t get_fresh_surface_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_surface_handle++; - -} - -uint32_t get_fresh_buffer_handle(struct pipe_screen* screen) { - - struct remote_screen* remscr = (struct remote_screen*)screen; - return remscr->last_buffer_handle++; - -} -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/drivers/remote/tr_screen.h b/src/gallium/drivers/remote/tr_screen.h deleted file mode 100644 index 704312ad5b..0000000000 --- a/src/gallium/drivers/remote/tr_screen.h +++ /dev/null @@ -1,97 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef TR_SCREEN_H_ -#define TR_SCREEN_H_ - -#include "pipe/p_screen.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PIPE_MAX_PARAMS 26 - -struct remote_screen -{ - - struct pipe_screen base; - uint32_t remote_handle; - int socketfd; - uint32_t tx_grants[4]; - uint32_t rx_grants[4]; - - void* tx_buffer; - void* rx_buffer; - - uint32_t last_query_handle; - uint32_t last_dsa_handle; - uint32_t last_rast_handle; - uint32_t last_blend_handle; - uint32_t last_sampler_handle; - uint32_t last_vs_handle; - uint32_t last_fs_handle; - uint32_t last_texture_handle; - uint32_t last_surface_handle; - uint32_t last_buffer_handle; - - uint32_t last_window_handle; - - int cached_int_params[PIPE_MAX_PARAMS]; - boolean int_param_is_cached[PIPE_MAX_PARAMS]; - float cached_float_params[PIPE_MAX_PARAMS]; - boolean float_param_is_cached[PIPE_MAX_PARAMS]; - -}; - - -struct remote_screen * -remote_screen(struct pipe_screen *screen); - -struct remote_winsys; - -struct pipe_screen * -remote_screen_create(struct pipe_winsys *winsys); - -int complete_screen_creation(struct remote_screen*); - -uint32_t get_fresh_query_handle(struct pipe_screen*); -uint32_t get_fresh_blend_handle(struct pipe_screen*); -uint32_t get_fresh_rast_handle(struct pipe_screen*); -uint32_t get_fresh_dsa_handle(struct pipe_screen*); -uint32_t get_fresh_vs_handle(struct pipe_screen*); -uint32_t get_fresh_fs_handle(struct pipe_screen*); -uint32_t get_fresh_sampler_handle(struct pipe_screen*); -uint32_t get_fresh_buffer_handle(struct pipe_screen*); -uint32_t get_fresh_texture_handle(struct pipe_screen*); -uint32_t get_fresh_surface_handle(struct pipe_screen*); - -#ifdef __cplusplus -} -#endif - -#endif /* TR_SCREEN_H_ */ -- cgit v1.2.3