diff options
author | Dave Airlie <airlied@gmail.com> | 2014-03-27 12:30:11 +1000 |
---|---|---|
committer | Dave Airlie <airlied@gmail.com> | 2014-03-27 12:31:03 +1000 |
commit | 1ab0718af0959c2c2d44daa7a479dea43314bb9c (patch) | |
tree | 4dca315c4f0863be347b043bd32696e6c13178ed | |
parent | e9653e7cdc4aa00aafd70ecafa8b1b617b6ee067 (diff) |
renderer: drop lots of old unused code
-rw-r--r-- | src/gallium/renderer/graw_context.c | 498 | ||||
-rw-r--r-- | src/gallium/renderer/graw_encode.c | 307 | ||||
-rw-r--r-- | src/gallium/renderer/graw_pipe_renderer.c | 203 | ||||
-rw-r--r-- | src/gallium/renderer/graw_pipe_winsys.c | 69 | ||||
-rw-r--r-- | src/gallium/renderer/graw_renderer_glut.c | 50 | ||||
-rw-r--r-- | src/gallium/renderer/graw_renderer_glut.h | 14 | ||||
-rw-r--r-- | src/gallium/renderer/graw_renderer_glx.c | 101 | ||||
-rw-r--r-- | src/gallium/renderer/graw_renderer_glx.h | 9 | ||||
-rw-r--r-- | src/gallium/renderer/graw_shm_renderer.c | 279 | ||||
-rw-r--r-- | src/gallium/renderer/graw_util.c | 93 | ||||
-rw-r--r-- | src/gallium/renderer/graw_util.h | 330 | ||||
-rw-r--r-- | src/gallium/renderer/quad-tex.c | 228 | ||||
-rw-r--r-- | src/gallium/renderer/send_scm.c | 208 | ||||
-rw-r--r-- | src/gallium/renderer/send_scm.h | 19 | ||||
-rw-r--r-- | src/gallium/renderer/tri-instanced.c | 354 | ||||
-rw-r--r-- | src/gallium/renderer/tri.c | 170 |
16 files changed, 0 insertions, 2932 deletions
diff --git a/src/gallium/renderer/graw_context.c b/src/gallium/renderer/graw_context.c deleted file mode 100644 index e26e8834617..00000000000 --- a/src/gallium/renderer/graw_context.c +++ /dev/null @@ -1,498 +0,0 @@ -#include <GL/glew.h> -#include <GL/gl.h> -#include <GL/glut.h> - -#include <stdio.h> -#include "pipe/p_shader_tokens.h" - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_screen.h" -#include "pipe/p_state.h" -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "util/u_transfer.h" -#include "tgsi/tgsi_text.h" - -#include "state_tracker/graw.h" - -#include "graw_protocol.h" - -#include "graw_encode.h" -#include "graw_object.h" - -#include "graw_renderer.h" -#include "graw_renderer_glut.h" -#include "graw_decode.h" -struct graw_screen; - -struct graw_resource { - struct pipe_resource base; - uint32_t res_handle; -}; - -struct graw_buffer { - struct graw_resource base; -}; - -struct graw_texture { - struct graw_resource base; -}; - - -struct graw_vertex_element { - unsigned count; - struct pipe_vertex_element elements[PIPE_MAX_ATTRIBS]; - GLuint vboids[PIPE_MAX_ATTRIBS]; -}; - -struct graw_shader_state { - uint id; - unsigned type; - char *glsl_prog; -}; - -struct graw_sampler_view { - struct pipe_sampler_view base; - uint32_t handle; -}; - -struct graw_context { - struct pipe_context base; - GLuint vaoid; - - struct graw_vertex_element *ve; - int num_vbos; - struct pipe_vertex_buffer vbo[PIPE_MAX_ATTRIBS]; - - struct graw_shader_state *vs; - struct graw_shader_state *fs; - - struct graw_encoder_state *eq; -}; - -static struct pipe_screen encscreen; - -static struct pipe_surface *graw_create_surface(struct pipe_context *ctx, - struct pipe_resource *resource, - const struct pipe_surface *templat) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - struct graw_surface *surf; - struct graw_texture *tex; - struct graw_resource *res = (struct graw_resource *)resource; - uint32_t handle; - handle = graw_object_assign_handle(); - - surf = calloc(1, sizeof(struct graw_surface)); - - surf->base = *templat; - surf->base.texture = NULL; - pipe_resource_reference(&surf->base.texture, resource); - surf->base.context = ctx; - - graw_encoder_create_surface(grctx->eq, handle, res->res_handle, templat); - surf->handle = handle; - return &surf->base; -} - -static void *graw_create_blend_state(struct pipe_context *ctx, - const struct pipe_blend_state *blend_state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - struct pipe_blend_state *state = CALLOC_STRUCT(pipe_blend_state); - uint32_t handle; - handle = graw_object_assign_handle(); - - graw_encode_blend_state(grctx->eq, handle, blend_state); - return (void *)(unsigned long)handle; - -} - -static void graw_bind_blend_state(struct pipe_context *ctx, - void *blend_state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle = (unsigned long)blend_state; - graw_encode_bind_object(grctx->eq, handle, GRAW_OBJECT_BLEND); -} - -static void graw_delete_blend_state(struct pipe_context *ctx, - void *blend_state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle = (unsigned long)blend_state; - graw_encode_delete_object(grctx->eq, handle, GRAW_OBJECT_BLEND); -} - -static void *graw_create_depth_stencil_alpha_state(struct pipe_context *ctx, - const struct pipe_depth_stencil_alpha_state *blend_state) -{ - return NULL; - -} - -static void graw_bind_depth_stencil_alpha_state(struct pipe_context *ctx, - void *blend_state) -{ - -} - -static void *graw_create_rasterizer_state(struct pipe_context *ctx, - const struct pipe_rasterizer_state *rs_state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle; - handle = graw_object_assign_handle(); - - graw_encode_rasterizer_state(grctx->eq, handle, rs_state); - return (void *)(unsigned long)handle; -} - -static void graw_bind_rasterizer_state(struct pipe_context *ctx, - void *rs_state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle = (unsigned long)rs_state; - - graw_encode_bind_object(grctx->eq, handle, GRAW_OBJECT_RASTERIZER); -} - -static void graw_set_framebuffer_state(struct pipe_context *ctx, - const struct pipe_framebuffer_state *state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - graw_encoder_set_framebuffer_state(grctx->eq, state); -} - -static void graw_set_viewport_state(struct pipe_context *ctx, - const struct pipe_viewport_state *state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - graw_encoder_set_viewport_state(grctx->eq, state); -} - -static void *graw_create_vertex_elements_state(struct pipe_context *ctx, - unsigned num_elements, - const struct pipe_vertex_element *elements) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle = graw_object_assign_handle(); - graw_encoder_create_vertex_elements(grctx->eq, handle, - num_elements, elements); - return (void*)(unsigned long)handle; - -} - -static void graw_bind_vertex_elements_state(struct pipe_context *ctx, - void *ve) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle = (unsigned long)ve; - graw_encode_bind_object(grctx->eq, handle, GRAW_OBJECT_VERTEX_ELEMENTS); -} - -static void graw_set_vertex_buffers(struct pipe_context *ctx, - unsigned num_buffers, - const struct pipe_vertex_buffer *buffers) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t res_handles[PIPE_MAX_ATTRIBS]; - struct graw_resource *res; - int i; - - for (i = 0; i < num_buffers; i++) { - res = (struct graw_resource *)buffers[i].buffer; - res_handles[i] = res->res_handle; - } - graw_encoder_set_vertex_buffers(grctx->eq, num_buffers, buffers, res_handles); -} - -static void graw_set_index_buffer(struct pipe_context *ctx, - const struct pipe_index_buffer *buf) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - struct graw_resource *res; - - res = (struct graw_resource *)buf->buffer; - graw_encoder_set_index_buffer(grctx->eq, buf, res->res_handle); -} - -static void graw_transfer_inline_write(struct pipe_context *ctx, - struct pipe_resource *res, - unsigned level, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned layer_stride) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - struct graw_resource *grres = (struct graw_resource *)res; - void *ptr; - - graw_encoder_inline_write(grctx->eq, grres->res_handle, level, usage, - box, data, stride, layer_stride); -} - -static void *graw_create_vs_state(struct pipe_context *ctx, - const struct pipe_shader_state *shader) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle; - int ret; - - handle = graw_object_assign_handle(); - - /* encode VS state */ - ret = graw_encode_shader_state(grctx->eq, handle, - GRAW_OBJECT_VS, shader); - if (ret) - return NULL; - - return (void *)(unsigned long)handle; -} - -static void *graw_create_fs_state(struct pipe_context *ctx, - const struct pipe_shader_state *shader) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle; - int ret; - handle = graw_object_assign_handle(); - - /* encode VS state */ - ret = graw_encode_shader_state(grctx->eq, handle, - GRAW_OBJECT_FS, shader); - if (ret) - return NULL; - - return (void *)(unsigned long)handle; -} - -static void graw_bind_vs_state(struct pipe_context *ctx, - void *vss) -{ - uint32_t handle = (unsigned long)vss; - struct graw_context *grctx = (struct graw_context *)ctx; - - graw_encode_bind_object(grctx->eq, handle, GRAW_OBJECT_VS); -} - - -static void graw_bind_fs_state(struct pipe_context *ctx, - void *vss) -{ - uint32_t handle = (unsigned long)vss; - struct graw_context *grctx = (struct graw_context *)ctx; - - graw_encode_bind_object(grctx->eq, handle, GRAW_OBJECT_FS); -} - -static void graw_clear(struct pipe_context *ctx, - unsigned buffers, - const union pipe_color_union *color, - double depth, unsigned stencil) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - - graw_encode_clear(grctx->eq, buffers, color, depth, stencil); -} - -static void graw_draw_vbo(struct pipe_context *ctx, - const struct pipe_draw_info *info) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - - graw_encoder_draw_vbo(grctx->eq, info); -} - - -static void graw_flush_eq(struct graw_encoder_state *eq, void *closure) -{ - struct graw_context *gr_ctx = closure; - - /* send the buffer to the remote side for decoding - for now jdi */ - graw_decode_block(eq->buf, eq->buf_offset); - eq->buf_offset = 0; -} - -static void graw_flush(struct pipe_context *ctx, - struct pipe_fence_handle **fence) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - - graw_flush_eq(grctx->eq, grctx); -} - -static struct pipe_sampler_view *graw_create_sampler_view(struct pipe_context *ctx, - struct pipe_resource *texture, - const struct pipe_sampler_view *state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - struct graw_sampler_view *grview = CALLOC_STRUCT(graw_sampler_view); - uint32_t handle; - int ret; - struct graw_resource *res; - - if (state == NULL) - return NULL; - - res = (struct graw_resource *)texture; -// handle = graw_object_assign_handle(); -// graw_encode_sampler_view(grctx->eq, handle, res->res_handle, state); - - grview->base = *state; - grview->base.texture = NULL; - pipe_reference(NULL, &texture->reference); - grview->base.texture = texture; -// grview->handle = handle; - return &grview->base; -} - -static void graw_set_fragment_sampler_views(struct pipe_context *ctx, - unsigned num_views, - struct pipe_sampler_view **views) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handles[32]; - int i; - for (i = 0; i < num_views; i++) { - struct graw_sampler_view *grview = (struct graw_sampler_view *)views[i]; - struct graw_resource *grres = (struct graw_resource *)grview->base.texture; - handles[i] = grres->res_handle; - } - graw_encode_set_fragment_sampler_views(grctx->eq, num_views, handles); -} - -static void *graw_create_sampler_state(struct pipe_context *ctx, - const struct pipe_sampler_state *state) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handle; - int ret; - handle = graw_object_assign_handle(); - - graw_encode_sampler_state(grctx->eq, handle, state); - return (void *)(unsigned long)handle; -} - -static void graw_bind_fragment_sampler_states(struct pipe_context *ctx, - unsigned num_samplers, - void **samplers) -{ - struct graw_context *grctx = (struct graw_context *)ctx; - uint32_t handles[32]; - int i; - for (i = 0; i < num_samplers; i++) { - handles[i] = (unsigned long)(samplers[i]); - } - graw_encode_bind_fragment_sampler_states(grctx->eq, num_samplers, handles); -} - -static struct pipe_context *graw_context_create(struct pipe_screen *pscreen, - void *priv) -{ - struct graw_context *gr_ctx; - - gr_ctx = CALLOC_STRUCT(graw_context); - - gr_ctx->eq = graw_encoder_init_queue(); - if (!gr_ctx->eq) { - free(gr_ctx); - return NULL; - } - - gr_ctx->eq->flush = graw_flush_eq; - gr_ctx->eq->closure = gr_ctx; - - gr_ctx->base.create_surface = graw_create_surface; - gr_ctx->base.set_framebuffer_state = graw_set_framebuffer_state; - gr_ctx->base.create_blend_state = graw_create_blend_state; - gr_ctx->base.bind_blend_state = graw_bind_blend_state; - gr_ctx->base.delete_blend_state = graw_delete_blend_state; - gr_ctx->base.create_depth_stencil_alpha_state = graw_create_depth_stencil_alpha_state; - gr_ctx->base.bind_depth_stencil_alpha_state = graw_bind_depth_stencil_alpha_state; - gr_ctx->base.create_rasterizer_state = graw_create_rasterizer_state; - gr_ctx->base.bind_rasterizer_state = graw_bind_rasterizer_state; - gr_ctx->base.set_viewport_state = graw_set_viewport_state; - gr_ctx->base.create_vertex_elements_state = graw_create_vertex_elements_state; - gr_ctx->base.bind_vertex_elements_state = graw_bind_vertex_elements_state; - gr_ctx->base.set_vertex_buffers = graw_set_vertex_buffers; - gr_ctx->base.set_index_buffer = graw_set_index_buffer; - gr_ctx->base.transfer_inline_write = graw_transfer_inline_write; - gr_ctx->base.create_fs_state = graw_create_fs_state; - gr_ctx->base.create_vs_state = graw_create_vs_state; - gr_ctx->base.bind_vs_state = graw_bind_vs_state; - gr_ctx->base.bind_fs_state = graw_bind_fs_state; - gr_ctx->base.clear = graw_clear; - gr_ctx->base.draw_vbo = graw_draw_vbo; - gr_ctx->base.flush = graw_flush; - gr_ctx->base.screen = pscreen; - gr_ctx->base.create_sampler_view = graw_create_sampler_view; - gr_ctx->base.set_fragment_sampler_views = graw_set_fragment_sampler_views; - gr_ctx->base.create_sampler_state = graw_create_sampler_state; - gr_ctx->base.bind_fragment_sampler_states = graw_bind_fragment_sampler_states; - return &gr_ctx->base; -} - -static void graw_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_resource *res, - unsigned level, unsigned layer, - void *winsys_drawable_handle) -{ - struct graw_resource *gres = (struct graw_resource *)res; - - grend_flush_frontbuffer(gres->res_handle); -} - -static struct pipe_resource *graw_resource_create(struct pipe_screen *pscreen, - const struct pipe_resource *template) -{ - struct graw_buffer *buf; - struct graw_texture *tex; - uint32_t handle; - handle = graw_object_assign_handle(); - - if (template->target == PIPE_BUFFER) { - buf = CALLOC_STRUCT(graw_buffer); - buf->base.base = *template; - buf->base.base.screen = pscreen; - pipe_reference_init(&buf->base.base.reference, 1); - graw_renderer_resource_create(handle, template->target, template->format, template->bind, 0, 0, 0); - buf->base.res_handle = handle; - return &buf->base.base; - } else { - tex = CALLOC_STRUCT(graw_texture); - tex->base.base = *template; - tex->base.base.screen = pscreen; - pipe_reference_init(&tex->base.base.reference, 1); - graw_renderer_resource_create(handle, template->target, template->format, template->bind, template->width0, template->height0, template->depth0); - tex->base.res_handle = handle; - return &tex->base.base; - } -} - -struct pipe_screen * -graw_create_window_and_screen( int x, - int y, - unsigned width, - unsigned height, - enum pipe_format format, - void **handle) -{ - - *handle = 5; - graw_renderer_glut_init(x, y, width, height); - graw_renderer_init(); - - encscreen.context_create = graw_context_create; - encscreen.resource_create = graw_resource_create; - encscreen.flush_frontbuffer = graw_flush_frontbuffer; - return &encscreen; -} - -void graw_transfer_write_return(void *data, uint32_t ndw, void *dummy) -{ - -} diff --git a/src/gallium/renderer/graw_encode.c b/src/gallium/renderer/graw_encode.c deleted file mode 100644 index 8b05ade45ef..00000000000 --- a/src/gallium/renderer/graw_encode.c +++ /dev/null @@ -1,307 +0,0 @@ -#include <stdint.h> -#include <string.h> - -#include "util/u_memory.h" -#include "pipe/p_state.h" -#include "graw_protocol.h" -#include "graw_encode.h" -#include "graw_object.h" -#include "tgsi/tgsi_dump.h" - -static unsigned uif(float f) -{ - union { float f; unsigned int ui; } myuif; - myuif.f = f; - return myuif.ui; -} - -int graw_encode_bind_object(struct graw_encoder_state *enc, - uint32_t handle, uint32_t object) -{ - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_BIND_OBJECT, object, 1)); - graw_encoder_write_dword(enc, handle); -} - -int graw_encode_delete_object(struct graw_encoder_state *enc, - uint32_t handle, uint32_t object) -{ - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_DESTROY_OBJECT, object, 1)); - graw_encoder_write_dword(enc, handle); -} - -int graw_encode_blend_state(struct graw_encoder_state *enc, - uint32_t handle, - struct pipe_blend_state *blend_state) -{ - uint32_t tmp; - int i; - - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_CREATE_OBJECT, GRAW_OBJECT_BLEND, 2 + 1)); - graw_encoder_write_dword(enc, handle); - - tmp = (blend_state->independent_blend_enable << 0) | - (blend_state->logicop_enable << 1) | - (blend_state->dither << 3) | - (blend_state->alpha_to_coverage << 4) | - (blend_state->alpha_to_one << 5); - - graw_encoder_write_dword(enc, tmp); - - tmp = blend_state->logicop_func << 0; - graw_encoder_write_dword(enc, tmp); - - for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { - - } - return 0; -} - -int graw_encode_rasterizer_state(struct graw_encoder_state *enc, - uint32_t handle, - struct pipe_rasterizer_state *state) -{ - uint32_t tmp; - - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_CREATE_OBJECT, GRAW_OBJECT_RASTERIZER, 2 + 1)); - graw_encoder_write_dword(enc, handle); - - tmp = (state->flatshade << 0) | - (state->depth_clip << 1) | - (state->gl_rasterization_rules << 2); - graw_encoder_write_dword(enc, tmp); - graw_encoder_write_dword(enc, 0); -} - -int graw_encode_shader_state(struct graw_encoder_state *enc, - uint32_t handle, - uint32_t type, - const struct pipe_shader_state *shader) -{ - uint32_t tmp; - static char str[8192]; - uint32_t len; - - memset(str, 0, 8192); - tgsi_dump_str(shader->tokens, 0, str, sizeof(str)); - - len = strlen(str) + 1; - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_CREATE_OBJECT, type, ((len + 3)/ 4) + 1)); - graw_encoder_write_dword(enc, handle); - graw_encoder_write_block(enc, str, len); - return 0; -} - -int graw_encode_clear(struct graw_encoder_state *enc, - unsigned buffers, - const union pipe_color_union *color, - double depth, unsigned stencil) -{ - int i; - - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_CLEAR, 0, 8)); - - graw_encoder_write_dword(enc, buffers); - for (i = 0; i < 4; i++) - graw_encoder_write_dword(enc, color->ui[i]); - graw_encoder_write_qword(enc, *(uint64_t *)&depth); - graw_encoder_write_dword(enc, stencil); -} - -int graw_encoder_set_framebuffer_state(struct graw_encoder_state *enc, - const struct pipe_framebuffer_state *state) -{ - struct graw_surface *surf = state->cbufs[0]; - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_SET_FRAMEBUFFER_STATE, 0, 2)); - graw_encoder_write_dword(enc, state->nr_cbufs); - graw_encoder_write_dword(enc, surf->handle); - return 0; -} - -int graw_encoder_set_viewport_state(struct graw_encoder_state *enc, - const struct pipe_viewport_state *state) -{ - int i; - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_SET_VIEWPORT_STATE, 0, 8)); - for (i = 0; i < 4; i++) - graw_encoder_write_dword(enc, uif(state->scale[i])); - for (i = 0; i < 4; i++) - graw_encoder_write_dword(enc, uif(state->translate[i])); - return 0; -} - -int graw_encoder_create_vertex_elements(struct graw_encoder_state *enc, - uint32_t handle, - unsigned num_elements, - const struct pipe_vertex_element *element) -{ - int i; - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_CREATE_OBJECT, GRAW_OBJECT_VERTEX_ELEMENTS, (4 * num_elements) + 1)); - graw_encoder_write_dword(enc, handle); - for (i = 0; i < num_elements; i++) { - graw_encoder_write_dword(enc, element[i].src_offset); - graw_encoder_write_dword(enc, element[i].instance_divisor); - graw_encoder_write_dword(enc, element[i].vertex_buffer_index); - graw_encoder_write_dword(enc, element[i].src_format); - } - return 0; -} - -int graw_encoder_set_vertex_buffers(struct graw_encoder_state *enc, - unsigned num_buffers, - const struct pipe_vertex_buffer *buffers, - uint32_t *res_handles) -{ - int i; - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_SET_VERTEX_BUFFERS, 0, (3 * num_buffers))); - for (i = 0; i < num_buffers; i++) { - graw_encoder_write_dword(enc, buffers[i].stride); - graw_encoder_write_dword(enc, buffers[i].buffer_offset); - graw_encoder_write_dword(enc, res_handles[i]); - } -} - -int graw_encoder_set_index_buffer(struct graw_encoder_state *enc, - const struct pipe_index_buffer *ib, - uint32_t res_handle) -{ - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_SET_INDEX_BUFFER, 0, 3)); - graw_encoder_write_dword(enc, res_handle); - graw_encoder_write_dword(enc, ib->index_size); - graw_encoder_write_dword(enc, ib->offset); -} - -int graw_encoder_draw_vbo(struct graw_encoder_state *enc, - const struct pipe_draw_info *info) -{ - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_DRAW_VBO, 0, 5)); - graw_encoder_write_dword(enc, info->start); - graw_encoder_write_dword(enc, info->count); - graw_encoder_write_dword(enc, info->mode); - graw_encoder_write_dword(enc, info->indexed); - graw_encoder_write_dword(enc, info->instance_count); - return 0; -} - -int graw_encoder_create_surface(struct graw_encoder_state *enc, - uint32_t handle, - uint32_t res_handle, - const struct pipe_surface *templat) -{ - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_CREATE_OBJECT, GRAW_SURFACE, 6)); - graw_encoder_write_dword(enc, handle); - graw_encoder_write_dword(enc, res_handle); - graw_encoder_write_dword(enc, templat->width); - graw_encoder_write_dword(enc, templat->height); - graw_encoder_write_dword(enc, templat->usage); - graw_encoder_write_dword(enc, templat->format); - return 0; -} - -int graw_encoder_inline_write(struct graw_encoder_state *enc, - uint32_t res_handle, - unsigned level, unsigned usage, - const struct pipe_box *box, - void *data, unsigned stride, - unsigned layer_stride) -{ - uint32_t size = (stride ? stride : box->width) * box->height; - uint32_t length = 11 + size / 4; - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_RESOURCE_INLINE_WRITE, 0, length)); - graw_encoder_write_dword(enc, res_handle); - graw_encoder_write_dword(enc, level); - graw_encoder_write_dword(enc, usage); - graw_encoder_write_dword(enc, stride); - graw_encoder_write_dword(enc, layer_stride); - graw_encoder_write_dword(enc, box->x); - graw_encoder_write_dword(enc, box->y); - graw_encoder_write_dword(enc, box->z); - graw_encoder_write_dword(enc, box->width); - graw_encoder_write_dword(enc, box->height); - graw_encoder_write_dword(enc, box->depth); - - graw_encoder_write_block(enc, data, size); - -} - -int graw_encoder_flush_frontbuffer(struct graw_encoder_state *enc, - uint32_t res_handle) -{ -// graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_FLUSH_FRONTUBFFER, 0, 1)); - graw_encoder_write_dword(enc, res_handle); - return 0; -} - -int graw_encode_sampler_state(struct graw_encoder_state *enc, - uint32_t handle, - const struct pipe_sampler_state *state) -{ - uint32_t tmp; - - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_CREATE_OBJECT, GRAW_OBJECT_SAMPLER_STATE , 2)); - graw_encoder_write_dword(enc, handle); - - tmp = state->wrap_s | - state->wrap_t << 3 | - state->wrap_r << 6 | - state->min_img_filter << 9 | - state->min_mip_filter << 11 | - state->mag_img_filter << 13; - - graw_encoder_write_dword(enc, tmp); -} - - -int graw_encode_sampler_view(struct graw_encoder_state *enc, - uint32_t handle, - uint32_t res_handle, - const struct pipe_sampler_view *state) -{ - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_CREATE_OBJECT, GRAW_OBJECT_SAMPLER_VIEW ,2)); - graw_encoder_write_dword(enc, handle); - graw_encoder_write_dword(enc, res_handle); -} - -int graw_encode_set_fragment_sampler_views(struct graw_encoder_state *enc, - uint32_t num_handles, - uint32_t *handles) -{ - int i; - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_SET_FRAGMENT_SAMPLER_VIEWS, 0, num_handles)); - for (i = 0; i < num_handles; i++) - graw_encoder_write_dword(enc, handles[i]); - return 0; -} - - -int graw_encode_bind_fragment_sampler_states(struct graw_encoder_state *enc, - uint32_t num_handles, - uint32_t *handles) -{ - int i; - graw_encoder_write_dword(enc, GRAW_CMD0(GRAW_BIND_OBJECT, GRAW_OBJECT_SAMPLER_STATE, num_handles)); - for (i = 0; i < num_handles; i++) - graw_encoder_write_dword(enc, handles[i]); - return 0; -} - - -#define EQ_BUF_SIZE (16*1024) - -struct graw_encoder_state *graw_encoder_init_queue(void) -{ - struct graw_encoder_state *eq; - - eq = CALLOC_STRUCT(graw_encoder_state); - if (!eq) - return NULL; - - eq->buf = malloc(EQ_BUF_SIZE); - if (!eq->buf){ - free(eq); - return NULL; - } - eq->buf_total = EQ_BUF_SIZE; - eq->buf_offset = 0; - return eq; -} - diff --git a/src/gallium/renderer/graw_pipe_renderer.c b/src/gallium/renderer/graw_pipe_renderer.c deleted file mode 100644 index 43605b33fa0..00000000000 --- a/src/gallium/renderer/graw_pipe_renderer.c +++ /dev/null @@ -1,203 +0,0 @@ -#include <stdlib.h> -#include <sys/select.h> -#include <GL/glew.h> -#include <GL/gl.h> -#include <fcntl.h> -#include <unistd.h> -#include <stdint.h> -#include <stdio.h> -#include <signal.h> -#include <assert.h> -#include "pipe/p_state.h" -#include "graw_protocol.h" -#include "graw_pipe_winsys.h" - -#include "graw_renderer_glut.h" -#include "graw_renderer_glx.h" -#include "graw_renderer.h" -#include "graw_decode.h" - -#include <sys/socket.h> -#include <sys/un.h> - -int graw_fd; - -uint32_t cmdbuf[65536]; -uint32_t decbuf[255]; - -static int do_blocked_read(int fd, void *data, uint32_t bytes) -{ - int left = bytes; - int sofar = 0; - - do { - int ret; - - ret = read(fd, data + sofar, left); - if (ret > 0) { - sofar += ret; - left -= ret; - } - if (ret < 0) - return ret; - } while (left > 0); - return sofar; -} - -static int process_cmd(void) -{ - int cmd; - int ret; - uint32_t ndw; - - retry: - ret = do_blocked_read(graw_fd, &cmd, 4); - if (ret == 0) - return -1; - - fprintf(stderr,"cmd is %d %d %d\n", cmd, cmd &0xff, ret); - switch (cmd & 0xff) { - case GRAW_CREATE_RENDERER: - graw_renderer_init_glx(0); -// graw_renderer_glut_init(decbuf[0], decbuf[1], decbuf[2], decbuf[3]); - graw_renderer_init(); - - break; - case GRAW_CREATE_RESOURCE: - ret = do_blocked_read(graw_fd, &decbuf, 7 * sizeof(uint32_t)); - - fprintf(stderr,"resource create\n"); - graw_renderer_resource_create(decbuf[0], decbuf[1], decbuf[2], decbuf[3], decbuf[4], decbuf[5], decbuf[6], 0, 0, 0); - break; - case GRAW_FLUSH_FRONTBUFFER: - ret = do_blocked_read(graw_fd, &decbuf, 1 * sizeof(uint32_t)); - grend_flush_frontbuffer(decbuf[0]); - break; - case GRAW_SUBMIT_CMD: - ndw = cmd >> 16; - fprintf(stderr,"submit cmd pre %d %d\n", ndw, ret); - ret = do_blocked_read(graw_fd, &cmdbuf, ndw * sizeof(uint32_t)); - fprintf(stderr,"submit cmd %d %d\n", ndw, ret); -// graw_decode_block(cmdbuf, ndw); - break; - case GRAW_TRANSFER_PUT: - ndw = cmd >> 16; - ret = do_blocked_read(graw_fd, &cmdbuf, ndw * sizeof(uint32_t)); -// graw_decode_transfer(cmdbuf, ndw); - break; - case GRAW_TRANSFER_GET: - ndw = cmd >> 16; - ret = do_blocked_read(graw_fd, &decbuf, 7 * sizeof(uint32_t)); -// graw_decode_get_transfer(decbuf, ndw); - break; - default: - fprintf(stderr,"read unknown cmd %d\n", cmd); - assert(0); - break; - } - goto retry; -} - -static void pipehandler(void) -{ - fprintf(stderr,"got sigpipe\n"); - graw_renderer_fini_glx(); -} - -static int socket_main(void) -{ - struct sockaddr_un address; - int socket_fd; - socklen_t address_length = 0; - int ret = 0; - fd_set rset, errset; - struct sigaction newact; - - socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); - if(socket_fd < 0) { - printf("socket() failed\n"); - return 1; - } - - unlink("/tmp/.demo_socket"); - - /* start with a clean address structure */ - memset(&address, 0, sizeof(struct sockaddr_un)); - - address.sun_family = AF_UNIX; - snprintf(address.sun_path, PATH_MAX, "/tmp/.demo_socket"); - - if(bind(socket_fd, - (struct sockaddr *) &address, - sizeof(struct sockaddr_un)) != 0) - { - printf("bind() failed\n"); - return 1; - } - - if(listen(socket_fd, 5) != 0) - { - printf("listen() failed\n"); - return 1; - } - relisten: - graw_fd = accept(socket_fd, - (struct sockaddr *) &address, - &address_length); - - memset(&newact, 0, sizeof(struct sigaction)); - newact.sa_handler = SIG_IGN; - sigaction(SIGPIPE, &newact, NULL); - while (ret >= 0) { - FD_ZERO(&rset); - FD_SET(graw_fd, &rset); - - ret = select(graw_fd+1, &rset, NULL, NULL, NULL); - - if (FD_ISSET(graw_fd, &rset)) { - ret = process_cmd(); - if (ret == -1) { - close(graw_fd); - graw_fd = 0; - graw_reset_decode(); - graw_renderer_fini(); - graw_renderer_fini_glx(); - ret = 0; - goto relisten; - } - } - } - return 0; -} - -int main(int argc, char **argv) -{ - socket_main(); -} - -void graw_transfer_write_return(void *data, uint32_t bytes, uint64_t offset, - struct graw_iovec *iov, int iovec_cnt) -{ - uint32_t count = bytes; - while (count) { - int amt = count < 4096 ? count : 4096; - - write(graw_fd, data + (bytes - count), amt); - count -= amt; - } -} -void graw_transfer_write_tex_return(struct pipe_resource *res, - struct pipe_box *box, - uint32_t level, - uint32_t dst_stride, - uint64_t offset, - struct graw_iovec *iov, - int num_iovs, void *myptr, int size, int invert) -{ - fprintf(stderr,"TODO\n"); -} - -void graw_write_fence(unsigned fence_id) -{ - -} diff --git a/src/gallium/renderer/graw_pipe_winsys.c b/src/gallium/renderer/graw_pipe_winsys.c deleted file mode 100644 index 815a124484f..00000000000 --- a/src/gallium/renderer/graw_pipe_winsys.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <stdint.h> -#include <unistd.h> -#include <stdio.h> -#include <fcntl.h> -#include "pipe/p_state.h" -#include "graw_protocol.h" -#include "graw_pipe_winsys.h" -#include "graw_util.h" -int graw_fd; -uint32_t buf[255]; - -void graw_renderer_init(int x, int y, int width, int height) -{ - graw_fd = open(GRAW_PIPENAME, O_RDWR); - - buf[0] = GRAW_CMD0(GRAW_CREATE_RENDERER, 0, 4); - buf[1] = x; - buf[2] = y; - buf[3] = width; - buf[4] = height; - - write(graw_fd, buf, 5 * sizeof(uint32_t)); - -} - -static uint32_t next_handle; -uint32_t graw_object_assign_handle(void) -{ - return next_handle++; -} - -void graw_renderer_resource_create(uint32_t handle, enum pipe_texture_target target, uint32_t bind, uint32_t width, uint32_t height) -{ - buf[0] = GRAW_CMD0(GRAW_CREATE_RESOURCE, 0, 5); - buf[1] = handle; - buf[2] = target; - buf[3] = bind; - buf[4] = width; - buf[5] = height; - write(graw_fd, buf, 6 * sizeof(uint32_t)); -} - -void grend_flush_frontbuffer(uint32_t res_handle) -{ - buf[0] = GRAW_CMD0(GRAW_FLUSH_FRONTBUFFER, 0, 1); - buf[1] = res_handle; - write(graw_fd, buf, 2 * sizeof(uint32_t)); -} - -void graw_decode_block(uint32_t *block, int ndw) -{ - fprintf(stderr,"sending ndw %d\n", ndw); - buf[0] = GRAW_CMD0(GRAW_SUBMIT_CMD, 0, ndw); - write(graw_fd, buf, 1 * sizeof(uint32_t)); - write(graw_fd, block, ndw * sizeof(uint32_t)); -} - -void (*mydraw)(void); - -void -graw_set_display_func( void (*draw)( void ) ) -{ - mydraw = draw; -} -void -graw_main_loop( void ) -{ - (*mydraw)(); -} diff --git a/src/gallium/renderer/graw_renderer_glut.c b/src/gallium/renderer/graw_renderer_glut.c deleted file mode 100644 index 9a5cbc8b4ef..00000000000 --- a/src/gallium/renderer/graw_renderer_glut.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <GL/glew.h> -#include <GL/gl.h> -#include <GL/glut.h> - -#include "graw_renderer_glut.h" - -static void Reshape(int width, int height) -{ - -} - -static void key_esc(unsigned char key, int x, int y) -{ - if (key == 27) exit(0); -} - -void -graw_renderer_glut_init(int x, int y, int width, int height) -{ - static int glut_inited; - int argc = 0; - - if (!glut_inited) { - glut_inited = 1; - glutInit(&argc, NULL); - } - - glutInitWindowSize(width, height); - - glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); - - glutCreateWindow("test"); - - glutReshapeFunc(Reshape); - glutKeyboardFunc(key_esc); -} - -void -graw_set_display_func( void (*draw)( void ) ) -{ - glutDisplayFunc(draw); -} - - -void -graw_main_loop( void ) -{ - glutMainLoop(); -} - diff --git a/src/gallium/renderer/graw_renderer_glut.h b/src/gallium/renderer/graw_renderer_glut.h deleted file mode 100644 index b5a92d5381a..00000000000 --- a/src/gallium/renderer/graw_renderer_glut.h +++ /dev/null @@ -1,14 +0,0 @@ - -#ifndef GRAW_RENDERER_GLUT -#define GRAW_RENDERER_GLUT - -void -graw_renderer_glut_init(int x, int y, int width, int height); - -void -graw_set_display_func( void (*draw)( void ) ); - -void -graw_main_loop( void ); - -#endif diff --git a/src/gallium/renderer/graw_renderer_glx.c b/src/gallium/renderer/graw_renderer_glx.c deleted file mode 100644 index 38b518ad127..00000000000 --- a/src/gallium/renderer/graw_renderer_glx.c +++ /dev/null @@ -1,101 +0,0 @@ -#include <GL/glew.h> - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <GL/gl.h> -#include <GL/glx.h> - -#include <stdio.h> -#include "graw_renderer_glx.h" - -Display *graw_dpy; -Window graw_win; -GLXContext graw_ctx; - -int inited; -void graw_renderer_fini_glx(void) -{ - glXMakeCurrent(graw_dpy, None, NULL); - glXDestroyContext(graw_dpy, graw_ctx); - XDestroyWindow(graw_dpy, graw_win); - XCloseDisplay(graw_dpy); - inited = 0; -} - -void graw_renderer_init_glx(int localrender) -{ - int scrnum; - Window root; - XVisualInfo *visinfo; - int attribs[64]; - int i = 0; - char *displayName = NULL; - XSetWindowAttributes attr; - unsigned long mask; - - if (inited) - return; - graw_dpy = XOpenDisplay(displayName); - - scrnum = DefaultScreen(graw_dpy); - root = RootWindow(graw_dpy, scrnum); - - attribs[i++] = GLX_RGBA; - attribs[i++] = GLX_DOUBLEBUFFER; - attribs[i++] = GLX_RED_SIZE; - attribs[i++] = 1; - attribs[i++] = GLX_GREEN_SIZE; - attribs[i++] = 1; - attribs[i++] = GLX_BLUE_SIZE; - attribs[i++] = 1; - attribs[i++] = GLX_DEPTH_SIZE; - attribs[i++] = 1; - attribs[i++] = None; - - visinfo = glXChooseVisual(graw_dpy, scrnum, attribs); - if (!visinfo) { - fprintf(stderr,"no suitable visual\n"); - return; - } - - graw_ctx = glXCreateContext( graw_dpy, visinfo, NULL, True ); - if (!graw_ctx) { - fprintf(stderr,"Error: glXCreateContext failed\n"); - return; - } - - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap(graw_dpy, root, visinfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - graw_win = XCreateWindow(graw_dpy, root, 0, 0, 1024, 768, - 0, visinfo->depth, InputOutput, - visinfo->visual, mask, &attr); - - glXMakeCurrent(graw_dpy, graw_win, graw_ctx); - inited = 1; - - if (localrender) { - XMapWindow(graw_dpy, graw_win); - } - - glewInit(); - -} - -int process_x_event(void) -{ - if (!graw_dpy) - return; - if (XPending(graw_dpy)) - { - XEvent event; - XNextEvent(graw_dpy, &event); - } -} - -int swap_buffers(void) -{ - glXSwapBuffers(graw_dpy, graw_win); -} diff --git a/src/gallium/renderer/graw_renderer_glx.h b/src/gallium/renderer/graw_renderer_glx.h deleted file mode 100644 index 5c00f295561..00000000000 --- a/src/gallium/renderer/graw_renderer_glx.h +++ /dev/null @@ -1,9 +0,0 @@ - -#ifndef GRAW_RENDERER_GLX -#define GRAW_RENDERER_GLX -void graw_renderer_init_glx(int localrender); -void graw_renderer_fini_glx(void); -int process_x_event(void); -int swap_buffers(void); - -#endif diff --git a/src/gallium/renderer/graw_shm_renderer.c b/src/gallium/renderer/graw_shm_renderer.c deleted file mode 100644 index 583ffb5c02d..00000000000 --- a/src/gallium/renderer/graw_shm_renderer.c +++ /dev/null @@ -1,279 +0,0 @@ -#include <stdio.h> -#include <time.h> - -#include <sys/mman.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <sys/eventfd.h> -#include "send_scm.h" -#include "virgl_hw.h" -#include "pipe/p_state.h" -#include "util/u_format.h" -#include "util/u_math.h" -#include "graw_renderer.h" -#include "graw_renderer_glx.h" - -#define USE_SOCKET 1 - -#define MAPPING_SIZE (64*1024*1024) -int fd; - -int vm_efd; -void *mapping; -int inited; - -extern int localrender; -struct qxl_3d_ram *ramp; - -static int send_irq(int fd, uint32_t pd) -{ - int ret; - uint64_t x = 1; - // fprintf(stderr,"notify 3d %x\n", pd); - - ramp->pad |= pd; - - ret = write(fd, &x, sizeof(uint64_t)); - if (ret != 8) - fprintf(stderr,"vm efd write failed %d %d\n", ret, errno); - return 0; -} - -static int create_listening_socket(char * path) { - - struct sockaddr_un local; - int len, conn_socket; - - if ((conn_socket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - perror("socket"); - exit(1); - } - - umask(0); - - local.sun_family = AF_UNIX; - strcpy(local.sun_path, path); - unlink(local.sun_path); - len = strlen(local.sun_path) + sizeof(local.sun_family); - if (bind(conn_socket, (struct sockaddr *)&local, len) == -1) { - perror("bind"); - exit(1); - } - umask(022); - - if (listen(conn_socket, 5) == -1) { - perror("listen"); - exit(1); - } - return conn_socket; -} - -void graw_renderer_init(void); -int main(int argc, char **argv) -{ - int count = 0; - int conn_socket, maxfd; - fd_set readset; - int vm_sock, vm_efd2; - struct graw_iovec iov; - - if (argc == 2 && !strcmp(argv[1], "-render")) - localrender = 1; - fd = shm_open("dave", O_CREAT|O_RDWR, S_IRWXU); - if (fd == -1) - return -1; - - if (ftruncate(fd, MAPPING_SIZE) != 0) { - fprintf(stderr,"couldn't truncate\n"); - exit(-1); - } - - conn_socket = create_listening_socket("/tmp/shmemsock"); - maxfd = conn_socket; - - /* we only care about one opener in this code */ - for (;;) { - int ret; - FD_ZERO(&readset); - FD_SET(conn_socket, &readset); - ret = select(maxfd+1, &readset, NULL, NULL, NULL); - if (ret == -1) { - perror("select()"); - exit(-1); - } - - printf("got connection.\n"); - { - struct sockaddr_un remote; - socklen_t t = sizeof(remote); - int new_posn = 1; - vm_sock = accept(conn_socket, (struct sockaddr *)&remote, &t); - if (vm_sock == -1) { - perror("accept"); - exit(1); - } - - vm_efd = eventfd(0, 0); - vm_efd2 = eventfd(0, 0); - sendPosition(vm_sock, new_posn); - sendUpdate(vm_sock, -1, sizeof(long), fd); - - sendUpdate(vm_sock, 1, sizeof(long), vm_efd); - sendUpdate(vm_sock, 2, sizeof(long), vm_efd2); - break; - } - } - - mapping = mmap(0, MAPPING_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); - if (!mapping) - return -1; - - ramp = mapping; - - iov.iov_base = mapping; - iov.iov_len = 0; - - SPICE_RING_INIT(&ramp->cmd_3d_ring); - ramp->version = 1; - { - struct virgl_command *cmd; - int notify; - restart: - process_x_event(); - count = 0; - while (SPICE_RING_IS_EMPTY(&ramp->cmd_3d_ring)) { - struct timespec req = {0, 50000000}; - - if (count < 20) - req.tv_nsec = 50000*count; - else if (count < 40) - req.tv_nsec = 500000*count; - else - req.tv_nsec = 50000000; - count++; - graw_renderer_check_fences(); - nanosleep(&req, NULL); - - } - - graw_renderer_check_fences(); - cmd = SPICE_RING_CONS_ITEM(&ramp->cmd_3d_ring); - -// fprintf(stderr, "got cmd %x\n", cmd->type); - - switch (cmd->type) { - case VIRGL_CMD_CREATE_RESOURCE: -// fprintf(stderr,"got res create %d %d\n", cmd->u.res_create.width, -// cmd->u.res_create.height); - graw_renderer_resource_create(cmd->u.res_create.handle, - cmd->u.res_create.target, - cmd->u.res_create.format, - cmd->u.res_create.bind, - cmd->u.res_create.width, - cmd->u.res_create.height, - cmd->u.res_create.depth, - cmd->u.res_create.array_size, - cmd->u.res_create.last_level, - cmd->u.res_create.nr_samples); - break; - case VIRGL_CMD_SUBMIT: -// fprintf(stderr,"cmd submit %lx %d\n", cmd->u.cmd_submit.phy_addr, cmd->u.cmd_submit.size); - - { - graw_decode_block_iov(&iov, 1, cmd->u.cmd_submit.phy_addr, cmd->u.cmd_submit.size / 4); - } - - break; - case VIRGL_CMD_TRANSFER_GET: -// fprintf(stderr,"got transfer get %d\n", cmd->u.transfer_get.res_handle); - graw_renderer_transfer_send_iov(cmd->u.transfer_get.res_handle, - cmd->u.transfer_get.level, - (struct pipe_box *)&cmd->u.transfer_get.box, - cmd->u.transfer_get.phy_addr, - &iov, 1); - break; - case VIRGL_CMD_TRANSFER_PUT: - graw_renderer_transfer_write_iov(cmd->u.transfer_put.res_handle, - cmd->u.transfer_put.dst_level, - cmd->u.transfer_put.src_stride, - (struct pipe_box *)&cmd->u.transfer_put.dst_box, - cmd->u.transfer_put.phy_addr, - &iov, 1); - break; - - case VIRGL_CMD_SET_SCANOUT: - graw_renderer_set_scanout(cmd->u.set_scanout.res_handle, - (struct pipe_box *)&cmd->u.set_scanout.box); - break; - case VIRGL_CMD_FLUSH_BUFFER: - graw_renderer_flush_buffer(cmd->u.flush_buffer.res_handle, - (struct pipe_box *)&cmd->u.flush_buffer.box); - break; - case VIRGL_CMD_RESOURCE_UNREF: - graw_renderer_resource_unref(cmd->u.res_unref.res_handle); - break; - case 0xdeadbeef: - if (inited) { - graw_renderer_fini(); - graw_renderer_fini_glx(); - - } - ramp->last_fence = 0; - graw_renderer_init_glx(localrender); - graw_renderer_init(); - inited = 1; - break; - } - - if (cmd->flags & VIRGL_COMMAND_EMIT_FENCE) - graw_renderer_create_fence(cmd->fence_id); - - SPICE_RING_POP(&ramp->cmd_3d_ring, notify); - - if (notify) { - send_irq(vm_efd, 1); - } - goto restart; - } - -} - -void graw_transfer_write_return(void *data, uint32_t bytes, uint64_t offset, - struct graw_iovec *iov, int num_iovs) -{ - graw_iov_from_buf(iov, num_iovs, offset, data, bytes); -} - -void graw_transfer_write_tex_return(struct pipe_resource *res, - struct pipe_box *box, - uint32_t level, - uint64_t offset, - struct graw_iovec *iov, - int num_iovs, - void *myptr, int size) -{ -#if 0 - int h; - int elsize = util_format_get_blocksize(res->format); - void *dptr = myptr; - int w = u_minify(res->width0, level); - int resh = u_minify(res->height0, level); - - for (h = resh - box->y - 1; h >= resh - box->y - box->height; h--) { - void *sptr = data + (h * elsize * w) + box->x * elsize; - memcpy(dptr, sptr, box->width * elsize); - dptr += box->width * elsize; - } -#endif - graw_iov_from_buf(iov, num_iovs, offset, myptr, size); -} - -void graw_write_fence(unsigned fence_id) -{ - ramp->last_fence = fence_id; - send_irq(vm_efd, 4); -} diff --git a/src/gallium/renderer/graw_util.c b/src/gallium/renderer/graw_util.c deleted file mode 100644 index 29d5aa9f802..00000000000 --- a/src/gallium/renderer/graw_util.c +++ /dev/null @@ -1,93 +0,0 @@ - -#include "pipe/p_compiler.h" -#include "pipe/p_context.h" -#include "pipe/p_shader_tokens.h" -#include "pipe/p_state.h" -#include "tgsi/tgsi_text.h" -#include "util/u_debug.h" -#include "util/u_memory.h" -#include "state_tracker/graw.h" - -#include <GL/glut.h> -/* Helper functions. These are the same for all graw implementations. - */ -PUBLIC void * -graw_parse_geometry_shader(struct pipe_context *pipe, - const char *text) -{ - struct tgsi_token tokens[1024]; - struct pipe_shader_state state; - - if (!tgsi_text_translate(text, tokens, Elements(tokens))) - return NULL; - - state.tokens = tokens; - return pipe->create_gs_state(pipe, &state); -} - -PUBLIC void * -graw_parse_vertex_shader(struct pipe_context *pipe, - const char *text) -{ - struct tgsi_token tokens[1024]; - struct pipe_shader_state state; - - if (!tgsi_text_translate(text, tokens, Elements(tokens))) - return NULL; - - state.tokens = tokens; - return pipe->create_vs_state(pipe, &state); -} - -PUBLIC void * -graw_parse_fragment_shader(struct pipe_context *pipe, - const char *text) -{ - struct tgsi_token tokens[1024]; - struct pipe_shader_state state; - - if (!tgsi_text_translate(text, tokens, Elements(tokens))) - return NULL; - - state.tokens = tokens; - return pipe->create_fs_state(pipe, &state); -} - -static char out_filename[256] = ""; - -PUBLIC boolean -graw_parse_args(int *argi, - int argc, - char *argv[]) -{ - if (strcmp(argv[*argi], "-o") == 0) { - if (*argi + 1 >= argc) { - return FALSE; - } - - strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1); - out_filename[sizeof(out_filename) - 1] = '\0'; - *argi += 2; - return TRUE; - } - - return FALSE; -} - -PUBLIC boolean -graw_save_surface_to_file(struct pipe_context *pipe, - struct pipe_surface *surface, - const char *filename) -{ - if (!filename || !*filename) { - filename = out_filename; - if (!filename || !*filename) { - return FALSE; - } - } - - /* XXX: Make that working in release builds. - */ - debug_dump_surface_bmp(pipe, filename, surface); - return TRUE; -} diff --git a/src/gallium/renderer/graw_util.h b/src/gallium/renderer/graw_util.h deleted file mode 100644 index f06a7271992..00000000000 --- a/src/gallium/renderer/graw_util.h +++ /dev/null @@ -1,330 +0,0 @@ - -#include "state_tracker/graw.h" - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_screen.h" -#include "pipe/p_shader_tokens.h" -#include "pipe/p_state.h" - -#include "util/u_box.h" -#include "util/u_debug.h" -#include "util/u_draw_quad.h" -#include "util/u_format.h" -#include "util/u_inlines.h" -#include "util/u_memory.h" - -#include "graw_renderer_glut.h" - -struct graw_info -{ - struct pipe_screen *screen; - struct pipe_context *ctx; - struct pipe_resource *color_buf[PIPE_MAX_COLOR_BUFS], *zs_buf; - struct pipe_surface *color_surf[PIPE_MAX_COLOR_BUFS], *zs_surf; - void *window; -}; - - - -static INLINE boolean -graw_util_create_window(struct graw_info *info, - int width, int height, - int num_cbufs, bool zstencil_buf) -{ - static const enum pipe_format formats[] = { - PIPE_FORMAT_R8G8B8A8_UNORM, - PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_NONE - }; - enum pipe_format format; - struct pipe_resource resource_temp; - struct pipe_surface surface_temp; - int i; - - memset(info, 0, sizeof(*info)); - - /* It's hard to say whether window or screen should be created - * first. Different environments would prefer one or the other. - * - * Also, no easy way of querying supported formats if the screen - * cannot be created first. - */ - for (i = 0; info->window == NULL && formats[i] != PIPE_FORMAT_NONE; i++) { - info->screen = graw_create_window_and_screen(0, 0, width, height, - formats[i], - &info->window); - format = formats[i]; - } - if (!info->screen || !info->window) { - debug_printf("graw: Failed to create screen/window\n"); - return FALSE; - } - - info->ctx = info->screen->context_create(info->screen, NULL); - if (info->ctx == NULL) { - debug_printf("graw: Failed to create context\n"); - return FALSE; - } - - for (i = 0; i < num_cbufs; i++) { - /* create color texture */ - resource_temp.target = PIPE_TEXTURE_2D; - resource_temp.format = format; - resource_temp.width0 = width; - resource_temp.height0 = height; - resource_temp.depth0 = 1; - resource_temp.array_size = 1; - resource_temp.last_level = 0; - resource_temp.nr_samples = 1; - resource_temp.bind = (PIPE_BIND_RENDER_TARGET | - PIPE_BIND_DISPLAY_TARGET); - info->color_buf[i] = info->screen->resource_create(info->screen, - &resource_temp); - if (info->color_buf[i] == NULL) { - debug_printf("graw: Failed to create color texture\n"); - return FALSE; - } - - /* create color surface */ - surface_temp.format = resource_temp.format; - surface_temp.usage = PIPE_BIND_RENDER_TARGET; - surface_temp.u.tex.level = 0; - surface_temp.u.tex.first_layer = 0; - surface_temp.u.tex.last_layer = 0; - info->color_surf[i] = info->ctx->create_surface(info->ctx, - info->color_buf[i], - &surface_temp); - if (info->color_surf[i] == NULL) { - debug_printf("graw: Failed to get color surface\n"); - return FALSE; - } - } - - /* create Z texture (XXX try other Z/S formats if needed) */ - resource_temp.target = PIPE_TEXTURE_2D; - resource_temp.format = PIPE_FORMAT_S8_UINT_Z24_UNORM; - resource_temp.width0 = width; - resource_temp.height0 = height; - resource_temp.depth0 = 1; - resource_temp.array_size = 1; - resource_temp.last_level = 0; - resource_temp.nr_samples = 1; - resource_temp.bind = PIPE_BIND_DEPTH_STENCIL; - info->zs_buf = info->screen->resource_create(info->screen, &resource_temp); - if (!info->zs_buf) { - debug_printf("graw: Failed to create Z texture\n"); - return FALSE; - } - - /* create z surface */ - surface_temp.format = resource_temp.format; - surface_temp.usage = PIPE_BIND_DEPTH_STENCIL; - surface_temp.u.tex.level = 0; - surface_temp.u.tex.first_layer = 0; - surface_temp.u.tex.last_layer = 0; - info->zs_surf = info->ctx->create_surface(info->ctx, - info->zs_buf, - &surface_temp); - if (info->zs_surf == NULL) { - debug_printf("graw: Failed to get Z surface\n"); - return FALSE; - } - - { - struct pipe_framebuffer_state fb; - memset(&fb, 0, sizeof fb); - fb.nr_cbufs = num_cbufs; - fb.width = width; - fb.height = height; - for (i = 0; i < num_cbufs; i++) - fb.cbufs[i] = info->color_surf[i]; - fb.zsbuf = info->zs_surf; - info->ctx->set_framebuffer_state(info->ctx, &fb); - } - - return TRUE; -} - - -static INLINE void -graw_util_default_state(struct graw_info *info, boolean depth_test) -{ - { - struct pipe_blend_state blend; - void *handle; - memset(&blend, 0, sizeof blend); - blend.rt[0].colormask = PIPE_MASK_RGBA; - handle = info->ctx->create_blend_state(info->ctx, &blend); - info->ctx->bind_blend_state(info->ctx, handle); - } - - { - struct pipe_depth_stencil_alpha_state depthStencilAlpha; - void *handle; - memset(&depthStencilAlpha, 0, sizeof depthStencilAlpha); - depthStencilAlpha.depth.enabled = depth_test; - depthStencilAlpha.depth.writemask = 1; - depthStencilAlpha.depth.func = PIPE_FUNC_LESS; - handle = info->ctx->create_depth_stencil_alpha_state(info->ctx, - &depthStencilAlpha); - info->ctx->bind_depth_stencil_alpha_state(info->ctx, handle); - } - - { - struct pipe_rasterizer_state rasterizer; - void *handle; - memset(&rasterizer, 0, sizeof rasterizer); - rasterizer.cull_face = PIPE_FACE_NONE; - rasterizer.gl_rasterization_rules = 1; - handle = info->ctx->create_rasterizer_state(info->ctx, &rasterizer); - info->ctx->bind_rasterizer_state(info->ctx, handle); - } -} - - -static INLINE void -graw_util_viewport(struct graw_info *info, - float x, float y, - float width, float height, - float near, float far) -{ - float z = near; - float half_width = width / 2.0f; - float half_height = height / 2.0f; - float half_depth = (far - near) / 2.0f; - struct pipe_viewport_state vp; - - vp.scale[0] = half_width; - vp.scale[1] = half_height; - vp.scale[2] = half_depth; - vp.scale[3] = 1.0f; - - vp.translate[0] = half_width + x; - vp.translate[1] = half_height + y; - vp.translate[2] = half_depth + z; - vp.translate[3] = 0.0f; - - info->ctx->set_viewport_state(info->ctx, &vp); -} - - -static INLINE void -graw_util_flush_front(const struct graw_info *info) -{ - info->screen->flush_frontbuffer(info->screen, info->color_buf[0], - 0, 0, info->window); -} - - -static INLINE struct pipe_resource * -graw_util_create_tex2d(const struct graw_info *info, - int width, int height, enum pipe_format format, - const void *data) -{ - const int row_stride = width * util_format_get_blocksize(format); - const int image_bytes = row_stride * height; - struct pipe_resource temp, *tex; - struct pipe_box box; - - temp.target = PIPE_TEXTURE_2D; - temp.format = PIPE_FORMAT_B8G8R8A8_UNORM; - temp.width0 = width; - temp.height0 = height; - temp.depth0 = 1; - temp.last_level = 0; - temp.array_size = 1; - temp.nr_samples = 1; - temp.bind = PIPE_BIND_SAMPLER_VIEW; - - tex = info->screen->resource_create(info->screen, &temp); - if (!tex) { - debug_printf("graw: failed to create texture\n"); - return NULL; - } - - u_box_2d(0, 0, width, height, &box); - - info->ctx->transfer_inline_write(info->ctx, - tex, - 0, - PIPE_TRANSFER_WRITE, - &box, - data, - row_stride, - image_bytes); - - /* Possibly read back & compare against original data: - */ -#if 0 - { - struct pipe_transfer *t; - uint32_t *ptr; - t = pipe_get_transfer(info->ctx, samptex, - 0, 0, /* level, layer */ - PIPE_TRANSFER_READ, - 0, 0, SIZE, SIZE); /* x, y, width, height */ - - ptr = info->ctx->transfer_map(info->ctx, t); - - if (memcmp(ptr, tex2d, sizeof tex2d) != 0) { - assert(0); - exit(9); - } - - info->ctx->transfer_unmap(info->ctx, t); - - info->ctx->transfer_destroy(info->ctx, t); - } -#endif - - return tex; -} - - -static INLINE void * -graw_util_create_simple_sampler(const struct graw_info *info, - unsigned wrap_mode, - unsigned img_filter) -{ - struct pipe_sampler_state sampler_desc; - void *sampler; - - memset(&sampler_desc, 0, sizeof sampler_desc); - sampler_desc.wrap_s = - sampler_desc.wrap_t = - sampler_desc.wrap_r = wrap_mode; - sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler_desc.min_img_filter = - sampler_desc.mag_img_filter = img_filter; - sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE; - sampler_desc.compare_func = 0; - sampler_desc.normalized_coords = 1; - sampler_desc.max_anisotropy = 0; - - sampler = info->ctx->create_sampler_state(info->ctx, &sampler_desc); - - return sampler; -} - - -static INLINE struct pipe_sampler_view * -graw_util_create_simple_sampler_view(const struct graw_info *info, - struct pipe_resource *texture) -{ - struct pipe_sampler_view sv_temp; - struct pipe_sampler_view *sv; - - memset(&sv_temp, 0, sizeof(sv_temp)); - sv_temp.format = texture->format; - sv_temp.texture = texture; - sv_temp.swizzle_r = PIPE_SWIZZLE_RED; - sv_temp.swizzle_g = PIPE_SWIZZLE_GREEN; - sv_temp.swizzle_b = PIPE_SWIZZLE_BLUE; - sv_temp.swizzle_a = PIPE_SWIZZLE_ALPHA; - - sv = info->ctx->create_sampler_view(info->ctx, texture, &sv_temp); - - return sv; -} - diff --git a/src/gallium/renderer/quad-tex.c b/src/gallium/renderer/quad-tex.c deleted file mode 100644 index c865e656eef..00000000000 --- a/src/gallium/renderer/quad-tex.c +++ /dev/null @@ -1,228 +0,0 @@ -/* Display a cleared blue window. This demo has no dependencies on - * any utility code, just the graw interface and gallium. - */ - -#include "graw_util.h" - -static const int WIDTH = 300; -static const int HEIGHT = 300; - -static struct graw_info info; - - -static struct pipe_resource *texture = NULL; -static struct pipe_sampler_view *sv = NULL; -static void *sampler = NULL; - -struct vertex { - float position[4]; - float color[4]; -}; - -static struct vertex vertices[] = -{ - { { 0.9, -0.9, 0.0, 1.0 }, - { 1, 0, 0, 1 } }, - - { { 0.9, 0.9, 0.0, 1.0 }, - { 1, 1, 0, 1 } }, - - { {-0.9, 0.9, 0.0, 1.0 }, - { 0, 1, 0, 1 } }, - - { {-0.9, -0.9, 0.0, 1.0 }, - { 0, 0, 0, 1 } }, -}; - - - - -static void set_vertices( void ) -{ - struct pipe_vertex_element ve[2]; - struct pipe_vertex_buffer vbuf; - void *handle; - - memset(ve, 0, sizeof ve); - - ve[0].src_offset = Offset(struct vertex, position); - ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - ve[1].src_offset = Offset(struct vertex, color); - ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - - handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve); - - memset(&vbuf, 0, sizeof(vbuf)); - vbuf.stride = sizeof( struct vertex ); - vbuf.buffer_offset = 0; - vbuf.buffer = pipe_buffer_create_with_data(info.ctx, - PIPE_BIND_VERTEX_BUFFER, - PIPE_USAGE_STATIC, - sizeof(vertices), - vertices); - - info.ctx->set_vertex_buffers(info.ctx, 1, &vbuf); - - info.ctx->bind_vertex_elements_state(info.ctx, handle); - -} - -static void set_vertex_shader( void ) -{ - void *handle; - const char *text = - "VERT\n" - "DCL IN[0]\n" - "DCL IN[1]\n" - "DCL OUT[0], POSITION\n" - "DCL OUT[1], GENERIC[0]\n" - " 0: MOV OUT[1], IN[1]\n" - " 1: MOV OUT[0], IN[0]\n" - " 2: END\n"; - - handle = graw_parse_vertex_shader(info.ctx, text); - info.ctx->bind_vs_state(info.ctx, handle); -} - -static void set_fragment_shader( void ) -{ - void *handle; - const char *text = - "FRAG\n" - "DCL IN[0], GENERIC[0], PERSPECTIVE\n" - "DCL OUT[0], COLOR\n" - "DCL TEMP[0]\n" - "DCL SAMP[0]\n" - " 0: TXP TEMP[0], IN[0], SAMP[0], 2D\n" - " 1: MOV OUT[0], TEMP[0]\n" - " 2: END\n"; - - handle = graw_parse_fragment_shader(info.ctx, text); - info.ctx->bind_fs_state(info.ctx, handle); -} - - -static void draw( void ) -{ - union pipe_color_union clear_color = { {.5,.5,.5,1} }; - - info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0); - util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, 4); - info.ctx->flush(info.ctx, NULL); - - graw_save_surface_to_file(info.ctx, info.color_surf[0], NULL); - - graw_util_flush_front(&info); -} - - -#define SIZE 16 - -static void init_tex( void ) -{ - ubyte tex2d[SIZE][SIZE][4]; - int s, t; - -#if (SIZE != 2) - for (s = 0; s < SIZE; s++) { - for (t = 0; t < SIZE; t++) { - if (0) { - int x = (s ^ t) & 1; - tex2d[t][s][0] = (x) ? 0 : 63; - tex2d[t][s][1] = (x) ? 0 : 128; - tex2d[t][s][2] = 0; - tex2d[t][s][3] = 0xff; - } - else { - int x = ((s ^ t) >> 2) & 1; - tex2d[t][s][0] = s*255/(SIZE-1); - tex2d[t][s][1] = t*255/(SIZE-1); - tex2d[t][s][2] = (x) ? 0 : 128; - tex2d[t][s][3] = 0xff; - } - } - } -#else - tex2d[0][0][0] = 0; - tex2d[0][0][1] = 255; - tex2d[0][0][2] = 255; - tex2d[0][0][3] = 0; - - tex2d[0][1][0] = 0; - tex2d[0][1][1] = 0; - tex2d[0][1][2] = 255; - tex2d[0][1][3] = 255; - - tex2d[1][0][0] = 255; - tex2d[1][0][1] = 255; - tex2d[1][0][2] = 0; - tex2d[1][0][3] = 255; - - tex2d[1][1][0] = 255; - tex2d[1][1][1] = 0; - tex2d[1][1][2] = 0; - tex2d[1][1][3] = 255; -#endif - - texture = graw_util_create_tex2d(&info, SIZE, SIZE, - PIPE_FORMAT_B8G8R8A8_UNORM, tex2d); - - sv = graw_util_create_simple_sampler_view(&info, texture); - info.ctx->set_fragment_sampler_views(info.ctx, 1, &sv); - - sampler = graw_util_create_simple_sampler(&info, - PIPE_TEX_WRAP_REPEAT, - PIPE_TEX_FILTER_NEAREST); - info.ctx->bind_fragment_sampler_states(info.ctx, 1, &sampler); -} - - -static void init( void ) -{ - if (!graw_util_create_window(&info, WIDTH, HEIGHT, 1, FALSE)) - exit(1); - - graw_util_default_state(&info, FALSE); - - { - struct pipe_rasterizer_state rasterizer; - void *handle; - memset(&rasterizer, 0, sizeof rasterizer); - rasterizer.cull_face = PIPE_FACE_NONE; - rasterizer.gl_rasterization_rules = 1; - rasterizer.depth_clip = 1; - handle = info.ctx->create_rasterizer_state(info.ctx, &rasterizer); - info.ctx->bind_rasterizer_state(info.ctx, handle); - } - - graw_util_viewport(&info, 0, 0, WIDTH, HEIGHT, 30, 1000); - - init_tex(); - - set_vertices(); - set_vertex_shader(); - set_fragment_shader(); -} - - -static void args(int argc, char *argv[]) -{ - int i; - - for (i = 1; i < argc;) { - if (graw_parse_args(&i, argc, argv)) { - continue; - } - exit(1); - } -} - -int main( int argc, char *argv[] ) -{ - args(argc, argv); - init(); - - graw_set_display_func( draw ); - graw_main_loop(); - return 0; -} diff --git a/src/gallium/renderer/send_scm.c b/src/gallium/renderer/send_scm.c deleted file mode 100644 index b1bb4a3a00e..00000000000 --- a/src/gallium/renderer/send_scm.c +++ /dev/null @@ -1,208 +0,0 @@ -#include <stdint.h> -#include <stdlib.h> -#include <errno.h> -#include <stdio.h> -#include <unistd.h> -#include <sys/socket.h> -#include <sys/syscall.h> -#include <sys/un.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <poll.h> -#include "send_scm.h" - -#ifndef POLLRDHUP -#define POLLRDHUP 0x2000 -#endif - -int readUpdate(int fd, long * posn, int * newfd) -{ - struct msghdr msg; - struct iovec iov[1]; - struct cmsghdr *cmptr; - size_t len; - size_t msg_size = sizeof(int); - char control[CMSG_SPACE(msg_size)]; - - msg.msg_name = 0; - msg.msg_namelen = 0; - msg.msg_control = control; - msg.msg_controllen = sizeof(control); - msg.msg_flags = 0; - msg.msg_iov = iov; - msg.msg_iovlen = 1; - - iov[0].iov_base = &posn; - iov[0].iov_len = sizeof(posn); - - do { - len = recvmsg(fd, &msg, 0); - } while (len == (size_t) (-1) && (errno == EINTR || errno == EAGAIN)); - - printf("iov[0].buf is %ld\n", *((long *)iov[0].iov_base)); - printf("len is %ld\n", len); - // TODO: Logging - if (len == (size_t) (-1)) { - perror("recvmsg()"); - return -1; - } - - if (msg.msg_controllen < sizeof(struct cmsghdr)) - return *posn; - - for (cmptr = CMSG_FIRSTHDR(&msg); cmptr != NULL; - cmptr = CMSG_NXTHDR(&msg, cmptr)) { - if (cmptr->cmsg_level != SOL_SOCKET || - cmptr->cmsg_type != SCM_RIGHTS){ - printf("continuing %ld\n", sizeof(size_t)); - printf("read msg_size = %ld\n", msg_size); - if (cmptr->cmsg_len != sizeof(control)) - printf("not equal (%ld != %ld)\n",cmptr->cmsg_len,sizeof(control)); - continue; - } - - memcpy(newfd, CMSG_DATA(cmptr), sizeof(int)); - printf("posn is %ld (fd = %d)\n", *posn, *newfd); - return 0; - } - - fprintf(stderr, "bad data in packet\n"); - return -1; -} - -int readRights(int fd, long count, size_t count_len, int **fds, int msi_vectors) -{ - int j, newfd; - - for (; ;){ - long posn = 0; - - readUpdate(fd, &posn, &newfd); - printf("reading posn %ld ", posn); - fds[posn] = (int *)malloc (msi_vectors * sizeof(int)); - fds[posn][0] = newfd; - for (j = 1; j < msi_vectors; j++) { - readUpdate(fd, &posn, &newfd); - fds[posn][j] = newfd; - printf("%d.", fds[posn][j]); - } - printf("\n"); - - /* stop reading once i've read my own eventfds */ - if (posn == count) - break; - } - - return 0; -} - -int sendKill(int fd, long const posn, size_t posn_len) { - - struct cmsghdr *cmsg; - size_t msg_size = sizeof(int); - char control[CMSG_SPACE(msg_size)]; - struct iovec iov[1]; - size_t len; - struct msghdr msg = { 0, 0, iov, 1, control, sizeof control, 0 }; - - struct pollfd mypollfd; - int rv; - - iov[0].iov_base = (void *) &posn; - iov[0].iov_len = posn_len; - - // from cmsg(3) - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_len = 0; - msg.msg_controllen = cmsg->cmsg_len; - - printf("Killing posn %ld\n", posn); - - // check if the fd is dead or not - mypollfd.fd = fd; - mypollfd.events = POLLRDHUP; - mypollfd.revents = 0; - - rv = poll(&mypollfd, 1, 0); - - printf("rv is %d\n", rv); - - if (rv == 0) { - len = sendmsg(fd, &msg, 0); - if (len == (size_t) (-1)) { - perror("sendmsg()"); - return -1; - } - return (len == posn_len); - } else { - printf("already dead\n"); - return 0; - } -} - -int sendUpdate(int fd, long posn, size_t posn_len, int sendfd) -{ - - struct cmsghdr *cmsg; - size_t msg_size = sizeof(int); - char control[CMSG_SPACE(msg_size)]; - struct iovec iov[1]; - size_t len; - struct msghdr msg = { 0, 0, iov, 1, control, sizeof control, 0 }; - - iov[0].iov_base = (void *) (&posn); - iov[0].iov_len = posn_len; - - // from cmsg(3) - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(msg_size); - msg.msg_controllen = cmsg->cmsg_len; - - memcpy((CMSG_DATA(cmsg)), &sendfd, msg_size); - - len = sendmsg(fd, &msg, 0); - if (len == (size_t) (-1)) { - perror("sendmsg()"); - return -1; - } - - return (len == posn_len); - -} - -int sendPosition(int fd, long const posn) -{ - int rv; - - rv = send(fd, &posn, sizeof(long), 0); - if (rv != sizeof(long)) { - fprintf(stderr, "error sending posn\n"); - return -1; - } - - return 0; -} - -int sendRights(int fd, long const count, size_t count_len, vmguest_t * Live_vms, - long msi_vectors) -{ - /* updates about new guests are sent one at a time */ - - long i, j; - - for (i = 0; i <= count; i++) { - if (Live_vms[i].alive) { - for (j = 0; j < msi_vectors; j++) { - sendUpdate(Live_vms[count].sockfd, i, sizeof(long), - Live_vms[i].efd[j]); - } - } - } - - return 0; - -} diff --git a/src/gallium/renderer/send_scm.h b/src/gallium/renderer/send_scm.h deleted file mode 100644 index 48c9a8da68d..00000000000 --- a/src/gallium/renderer/send_scm.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef SEND_SCM -#define SEND_SCM - -struct vm_guest_conn { - int posn; - int sockfd; - int * efd; - int alive; -}; - -typedef struct vm_guest_conn vmguest_t; - -int readRights(int fd, long count, size_t count_len, int **fds, int msi_vectors); -int sendRights(int fd, long const count, size_t count_len, vmguest_t *Live_vms, long msi_vectors); -int readUpdate(int fd, long * posn, int * newfd); -int sendUpdate(int fd, long const posn, size_t posn_len, int sendfd); -int sendPosition(int fd, long const posn); -int sendKill(int fd, long const posn, size_t posn_len); -#endif diff --git a/src/gallium/renderer/tri-instanced.c b/src/gallium/renderer/tri-instanced.c deleted file mode 100644 index d3de15c32c0..00000000000 --- a/src/gallium/renderer/tri-instanced.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Test draw instancing. - */ - -#include <stdio.h> -#include <string.h> - -#include "state_tracker/graw.h" -#include "pipe/p_screen.h" -#include "pipe/p_context.h" -#include "pipe/p_state.h" -#include "pipe/p_defines.h" - -#include "util/u_memory.h" /* Offset() */ -#include "util/u_draw_quad.h" -#include "util/u_inlines.h" - - -enum pipe_format formats[] = { - PIPE_FORMAT_R8G8B8A8_UNORM, - PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_NONE -}; - -static const int WIDTH = 300; -static const int HEIGHT = 300; - -static struct pipe_screen *screen = NULL; -static struct pipe_context *ctx = NULL; -static struct pipe_surface *surf = NULL; -static struct pipe_resource *tex = NULL; -static void *window = NULL; - -struct vertex { - float position[4]; - float color[4]; -}; - - -static int draw_elements = 0; - - -/** - * Vertex data. - * Each vertex has three attributes: position, color and translation. - * The translation attribute is a per-instance attribute. See - * "instance_divisor" below. - */ -static struct vertex vertices[4] = -{ - { - { 0.0f, -0.3f, 0.0f, 1.0f }, /* pos */ - { 1.0f, 0.0f, 0.0f, 1.0f } /* color */ - }, - { - { -0.2f, 0.3f, 0.0f, 1.0f }, - { 0.0f, 1.0f, 0.0f, 1.0f } - }, - { - { 0.2f, 0.3f, 0.0f, 1.0f }, - { 0.0f, 0.0f, 1.0f, 1.0f } - } -}; - - -#define NUM_INST 5 - -static float inst_data[NUM_INST][4] = -{ - { -0.50f, 0.4f, 0.0f, 0.0f }, - { -0.25f, 0.1f, 0.0f, 0.0f }, - { 0.00f, 0.2f, 0.0f, 0.0f }, - { 0.25f, 0.1f, 0.0f, 0.0f }, - { 0.50f, 0.3f, 0.0f, 0.0f } -}; - - -static ushort indices[3] = { 0, 2, 1 }; - - -static void set_viewport( float x, float y, - float width, float height, - float near, float far) -{ - float z = far; - float half_width = (float)width / 2.0f; - float half_height = (float)height / 2.0f; - float half_depth = ((float)far - (float)near) / 2.0f; - struct pipe_viewport_state vp; - - vp.scale[0] = half_width; - vp.scale[1] = half_height; - vp.scale[2] = half_depth; - vp.scale[3] = 1.0f; - - vp.translate[0] = half_width + x; - vp.translate[1] = half_height + y; - vp.translate[2] = half_depth + z; - vp.translate[3] = 0.0f; - - ctx->set_viewport_state( ctx, &vp ); -} - - -static void set_vertices( void ) -{ - struct pipe_vertex_element ve[3]; - struct pipe_vertex_buffer vbuf[2]; - struct pipe_index_buffer ibuf; - void *handle; - - memset(ve, 0, sizeof ve); - - /* pos */ - ve[0].src_offset = Offset(struct vertex, position); - ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - ve[0].vertex_buffer_index = 0; - - /* color */ - ve[1].src_offset = Offset(struct vertex, color); - ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - ve[1].vertex_buffer_index = 0; - - /* per-instance info */ - ve[2].src_offset = 0; - ve[2].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - ve[2].vertex_buffer_index = 1; - ve[2].instance_divisor = 1; - - handle = ctx->create_vertex_elements_state(ctx, 3, ve); - ctx->bind_vertex_elements_state(ctx, handle); - - - /* vertex data */ - vbuf[0].stride = sizeof( struct vertex ); - vbuf[0].buffer_offset = 0; - vbuf[0].buffer = pipe_buffer_create_with_data(ctx, - PIPE_BIND_VERTEX_BUFFER, - PIPE_USAGE_STATIC, - sizeof(vertices), - vertices); - - /* instance data */ - vbuf[1].stride = sizeof( inst_data[0] ); - vbuf[1].buffer_offset = 0; - vbuf[1].buffer = pipe_buffer_create_with_data(ctx, - PIPE_BIND_VERTEX_BUFFER, - PIPE_USAGE_STATIC, - sizeof(inst_data), - inst_data); - - ctx->set_vertex_buffers(ctx, 2, vbuf); - - /* index data */ - ibuf.buffer = pipe_buffer_create_with_data(ctx, - PIPE_BIND_INDEX_BUFFER, - PIPE_USAGE_STATIC, - sizeof(indices), - indices); - ibuf.offset = 0; - ibuf.index_size = 2; - - ctx->set_index_buffer(ctx, &ibuf); - -} - -static void set_vertex_shader( void ) -{ - void *handle; - const char *text = - "VERT\n" - "DCL IN[0]\n" - "DCL IN[1]\n" - "DCL IN[2]\n" - "DCL OUT[0], POSITION\n" - "DCL OUT[1], COLOR\n" - " 0: MOV OUT[1], IN[1]\n" - " 1: ADD OUT[0], IN[0], IN[2]\n" /* add instance pos to vertex pos */ - " 2: END\n"; - - handle = graw_parse_vertex_shader(ctx, text); - ctx->bind_vs_state(ctx, handle); -} - -static void set_fragment_shader( void ) -{ - void *handle; - const char *text = - "FRAG\n" - "DCL IN[0], COLOR, LINEAR\n" - "DCL OUT[0], COLOR\n" - " 0: MOV OUT[0], IN[0]\n" - " 1: END\n"; - - handle = graw_parse_fragment_shader(ctx, text); - ctx->bind_fs_state(ctx, handle); -} - - -static void draw( void ) -{ - union pipe_color_union clear_color = { {1,0,1,1} }; - struct pipe_draw_info info; - - ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0); - - util_draw_init_info(&info); - info.indexed = (draw_elements != 0); - info.mode = PIPE_PRIM_TRIANGLES; - info.start = 0; - info.count = 3; - /* draw NUM_INST triangles */ - info.instance_count = NUM_INST; - - ctx->draw_vbo(ctx, &info); - - ctx->flush(ctx, NULL); - - graw_save_surface_to_file(ctx, surf, NULL); - - screen->flush_frontbuffer(screen, tex, 0, 0, window); -} - - -static void init( void ) -{ - struct pipe_framebuffer_state fb; - struct pipe_resource templat; - struct pipe_surface surf_tmpl; - int i; - - /* It's hard to say whether window or screen should be created - * first. Different environments would prefer one or the other. - * - * Also, no easy way of querying supported formats if the screen - * cannot be created first. - */ - for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) { - screen = graw_create_window_and_screen(0, 0, 300, 300, - formats[i], - &window); - if (window && screen) - break; - } - if (!screen || !window) { - fprintf(stderr, "Unable to create window\n"); - exit(1); - } - - ctx = screen->context_create(screen, NULL); - if (ctx == NULL) - exit(3); - - templat.target = PIPE_TEXTURE_2D; - templat.format = formats[i]; - templat.width0 = WIDTH; - templat.height0 = HEIGHT; - templat.depth0 = 1; - templat.array_size = 1; - templat.last_level = 0; - templat.nr_samples = 1; - templat.bind = (PIPE_BIND_RENDER_TARGET | - PIPE_BIND_DISPLAY_TARGET); - - tex = screen->resource_create(screen, - &templat); - if (tex == NULL) - exit(4); - - surf_tmpl.format = templat.format; - surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; - surf_tmpl.u.tex.level = 0; - surf_tmpl.u.tex.first_layer = 0; - surf_tmpl.u.tex.last_layer = 0; - surf = ctx->create_surface(ctx, tex, &surf_tmpl); - if (surf == NULL) - exit(5); - - memset(&fb, 0, sizeof fb); - fb.nr_cbufs = 1; - fb.width = WIDTH; - fb.height = HEIGHT; - fb.cbufs[0] = surf; - - ctx->set_framebuffer_state(ctx, &fb); - - { - struct pipe_blend_state blend; - void *handle; - memset(&blend, 0, sizeof blend); - blend.rt[0].colormask = PIPE_MASK_RGBA; - handle = ctx->create_blend_state(ctx, &blend); - ctx->bind_blend_state(ctx, handle); - } - - { - struct pipe_depth_stencil_alpha_state depthstencil; - void *handle; - memset(&depthstencil, 0, sizeof depthstencil); - handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); - ctx->bind_depth_stencil_alpha_state(ctx, handle); - } - - { - struct pipe_rasterizer_state rasterizer; - void *handle; - memset(&rasterizer, 0, sizeof rasterizer); - rasterizer.cull_face = PIPE_FACE_NONE; - rasterizer.gl_rasterization_rules = 1; - rasterizer.depth_clip = 1; - handle = ctx->create_rasterizer_state(ctx, &rasterizer); - ctx->bind_rasterizer_state(ctx, handle); - } - - set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); - set_vertices(); - set_vertex_shader(); - set_fragment_shader(); -} - - -static void options(int argc, char *argv[]) -{ - int i; - - for (i = 1; i < argc;) { - if (graw_parse_args(&i, argc, argv)) { - continue; - } - if (strcmp(argv[i], "-e") == 0) { - draw_elements = 1; - i++; - } - else { - i++; - } - } - if (draw_elements) - printf("Using pipe_context::draw_elements_instanced()\n"); - else - printf("Using pipe_context::draw_arrays_instanced()\n"); -} - - -int main( int argc, char *argv[] ) -{ - options(argc, argv); - - init(); - - graw_set_display_func( draw ); - graw_main_loop(); - return 0; -} diff --git a/src/gallium/renderer/tri.c b/src/gallium/renderer/tri.c deleted file mode 100644 index b99aeb400ac..00000000000 --- a/src/gallium/renderer/tri.c +++ /dev/null @@ -1,170 +0,0 @@ -/* Display a cleared blue window. This demo has no dependencies on - * any utility code, just the graw interface and gallium. - */ - -#include <stdio.h> -#include "graw_util.h" - -static struct graw_info info; - -static const int WIDTH = 300; -static const int HEIGHT = 300; - - -struct vertex { - float position[4]; - float color[4]; -}; - -static boolean FlatShade = FALSE; - - -static struct vertex vertices[3] = -{ - { - { 0.0f, -0.9f, 0.0f, 1.0f }, - { 1.0f, 0.0f, 0.0f, 1.0f } - }, - { - { -0.9f, 0.9f, 0.0f, 1.0f }, - { 0.0f, 1.0f, 0.0f, 1.0f } - }, - { - { 0.9f, 0.9f, 0.0f, 1.0f }, - { 0.0f, 0.0f, 1.0f, 1.0f } - } -}; - - -static void set_vertices( void ) -{ - struct pipe_vertex_element ve[2]; - struct pipe_vertex_buffer vbuf; - void *handle; - - memset(ve, 0, sizeof ve); - - ve[0].src_offset = Offset(struct vertex, position); - ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - ve[1].src_offset = Offset(struct vertex, color); - ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - - handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve); - - - vbuf.stride = sizeof( struct vertex ); - vbuf.buffer_offset = 0; - vbuf.buffer = pipe_buffer_create_with_data(info.ctx, - PIPE_BIND_VERTEX_BUFFER, - PIPE_USAGE_STATIC, - sizeof(vertices), - vertices); - - info.ctx->set_vertex_buffers(info.ctx, 1, &vbuf); - - info.ctx->bind_vertex_elements_state(info.ctx, handle); - -} - - -static void set_vertex_shader( void ) -{ - void *handle; - const char *text = - "VERT\n" - "DCL IN[0]\n" - "DCL IN[1]\n" - "DCL OUT[0], POSITION\n" - "DCL OUT[1], COLOR\n" - " 0: MOV OUT[1], IN[1]\n" - " 1: MOV OUT[0], IN[0]\n" - " 2: END\n"; - - handle = graw_parse_vertex_shader(info.ctx, text); - info.ctx->bind_vs_state(info.ctx, handle); -} - - -static void set_fragment_shader( void ) -{ - void *handle; - const char *text = - "FRAG\n" - "DCL IN[0], COLOR, LINEAR\n" - "DCL OUT[0], COLOR\n" - " 0: MOV OUT[0], IN[0]\n" - " 1: END\n"; - - handle = graw_parse_fragment_shader(info.ctx, text); - info.ctx->bind_fs_state(info.ctx, handle); -} - - -static void draw( void ) -{ - union pipe_color_union clear_color = { {1,0,1,1} }; - - info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0); - util_draw_arrays(info.ctx, PIPE_PRIM_TRIANGLES, 0, 3); - info.ctx->flush(info.ctx, NULL); - - graw_save_surface_to_file(info.ctx, info.color_surf[0], NULL); - graw_util_flush_front(&info); -} - - -static void init( void ) -{ - if (!graw_util_create_window(&info, WIDTH, HEIGHT, 1, FALSE)) - exit(1); - - graw_util_default_state(&info, FALSE); - - { - struct pipe_rasterizer_state rasterizer; - void *handle; - memset(&rasterizer, 0, sizeof rasterizer); - rasterizer.cull_face = PIPE_FACE_NONE; - rasterizer.gl_rasterization_rules = 1; - rasterizer.flatshade = FlatShade; - rasterizer.depth_clip = 1; - handle = info.ctx->create_rasterizer_state(info.ctx, &rasterizer); - info.ctx->bind_rasterizer_state(info.ctx, handle); - } - - - graw_util_viewport(&info, 0, 0, WIDTH, HEIGHT, 30, 1000); - - set_vertices(); - set_vertex_shader(); - set_fragment_shader(); -} - -static void args(int argc, char *argv[]) -{ - int i; - - for (i = 1; i < argc; ) { - if (graw_parse_args(&i, argc, argv)) { - /* ok */ - } - else if (strcmp(argv[i], "-f") == 0) { - FlatShade = TRUE; - i++; - } - else { - printf("Invalid arg %s\n", argv[i]); - exit(1); - } - } -} - -int main( int argc, char *argv[] ) -{ - args(argc, argv); - init(); - - graw_set_display_func( draw ); - graw_main_loop(); - return 0; -} |