diff options
Diffstat (limited to 'src')
22 files changed, 2197 insertions, 50 deletions
diff --git a/src/mesa/pipe/cell/common.h b/src/mesa/pipe/cell/common.h index c4bad4194a..da7de78803 100644 --- a/src/mesa/pipe/cell/common.h +++ b/src/mesa/pipe/cell/common.h @@ -1,13 +1,94 @@ +/************************************************************************** + * + * Copyright 2007 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. + * + **************************************************************************/ + +/** + * Types and tokens which are common to the SPU and PPU code. + */ + #ifndef CELL_COMMON_H #define CELL_COMMON_H +#include "pipe/p_util.h" + + +#define ALIGN16 __attribute__( (aligned( 16 )) ) + +#define ASSERT_ALIGN16(ptr) \ + assert((((unsigned long) (ptr)) & 0xf) == 0); + + + +#define TILE_SIZE 32 + + +#define CELL_CMD_EXIT 1 +#define CELL_CMD_FRAMEBUFFER 2 +#define CELL_CMD_CLEAR_TILES 3 +#define CELL_CMD_INVERT_TILES 4 +#define CELL_CMD_FINISH 5 + -struct init_info +/** + * Tell SPUs about the framebuffer size, location + */ +struct cell_command_framebuffer { - int foo; - int bar; -}; + void *start; + int width, height; + unsigned format; +} ALIGN16; + + +/** + * Clear framebuffer tiles to given value/color. + */ +struct cell_command_clear_tiles +{ + uint value; +} ALIGN16; + + +/** XXX unions don't seem to work */ +struct cell_command +{ + struct cell_command_framebuffer fb; + struct cell_command_clear_tiles clear; +} ALIGN16; + + +struct cell_init_info +{ + unsigned id; + unsigned num_spus; + struct cell_command *cmd; +} ALIGN16; + + #endif /* CELL_COMMON_H */ diff --git a/src/mesa/pipe/cell/ppu/Makefile b/src/mesa/pipe/cell/ppu/Makefile index c987d54e02..f597784d65 100644 --- a/src/mesa/pipe/cell/ppu/Makefile +++ b/src/mesa/pipe/cell/ppu/Makefile @@ -17,7 +17,18 @@ SPU_CODE_MODULE = ../spu/g3d_spu.a SOURCES = \ cell_context.c \ - cell_surface.c + cell_flush.c \ + cell_state_blend.c \ + cell_state_clip.c \ + cell_state_fs.c \ + cell_state_rasterizer.c \ + cell_state_sampler.c \ + cell_state_surface.c \ + cell_state_vertex.c \ + cell_spu.c \ + cell_surface.c \ + cell_winsys.c + OBJECTS = $(SOURCES:.c=.o) \ @@ -42,7 +53,7 @@ $(CELL_LIB): $(OBJECTS) $(SPU_CODE_MODULE) clean: - rm -f *.o $(CELL_LIB) + rm -f *.o *~ $(CELL_LIB) diff --git a/src/mesa/pipe/cell/ppu/cell_context.c b/src/mesa/pipe/cell/ppu/cell_context.c index a8f6cba2fa..68543ecf30 100644 --- a/src/mesa/pipe/cell/ppu/cell_context.c +++ b/src/mesa/pipe/cell/ppu/cell_context.c @@ -32,45 +32,232 @@ #include <stdio.h> -#include <libspe.h> -#include <libmisc.h> -#include "pipe/cell/ppu/cell_context.h" + +#include "pipe/p_defines.h" +#include "pipe/p_format.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" #include "pipe/cell/common.h" +#include "pipe/draw/draw_context.h" +#include "cell_context.h" +#include "cell_flush.h" +#include "cell_state.h" +#include "cell_surface.h" +#include "cell_spu.h" -#define NUM_SPUS 6 -extern spe_program_handle_t g3d_spu; +static boolean +cell_is_format_supported( struct pipe_context *pipe, + enum pipe_format format, uint type ) +{ + struct cell_context *cell = cell_context( pipe ); -static speid_t speid[NUM_SPUS]; -static struct init_info inits[NUM_SPUS]; + switch (type) { + case PIPE_TEXTURE: + /* cell supports all texture formats, XXX for now anyway */ + return TRUE; + case PIPE_SURFACE: + /* cell supports all (off-screen) surface formats, XXX for now */ + return TRUE; + case PIPE_SCREEN_SURFACE: + return format == cell->winsys->preferredFormat; + default: + assert(0); + return FALSE; + } +} -static void -start_spus(void) +static int cell_get_param(struct pipe_context *pipe, int param) { - int i; - - for (i = 0; i < NUM_SPUS; i++) { - inits[i].foo = i; - inits[i].bar = i * 10; - - speid[i] = spe_create_thread(0, /* gid */ - &g3d_spu, /* spe program handle */ - &inits[i], /* argp */ - NULL, /* envp */ - -1, /* mask */ - 0 ); /* flags */ + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return 8; + case PIPE_CAP_NPOT_TEXTURES: + return 1; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return 1; + case PIPE_CAP_S3TC: + return 0; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 0; + case PIPE_CAP_POINT_SPRITE: + return 1; + case PIPE_CAP_MAX_RENDER_TARGETS: + return 1; + case PIPE_CAP_OCCLUSION_QUERY: + return 1; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 1; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return 12; /* max 2Kx2K */ + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return 8; /* max 128x128x128 */ + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return 12; /* max 2Kx2K */ + default: + return 0; + } +} + +static float cell_get_paramf(struct pipe_context *pipe, int param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 255.0; /* arbitrary */ + + case PIPE_CAP_MAX_POINT_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 255.0; /* arbitrary */ + + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 0.0; + + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0; /* arbitrary */ + + default: + return 0; } } +static const char * +cell_get_name( struct pipe_context *pipe ) +{ + return "Cell"; +} + +static const char * +cell_get_vendor( struct pipe_context *pipe ) +{ + return "Tungsten Graphics, Inc."; +} + + + +static void +cell_destroy_context( struct pipe_context *pipe ) +{ + struct cell_context *cell = cell_context(pipe); + + cell_spu_exit(cell); + wait_spus(cell->num_spus); + + free(cell); +} + + -void cell_create_context(void) + +struct pipe_context * +cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws) { - printf("cell_create_context\n"); + struct cell_context *cell; + + cell = CALLOC_STRUCT(cell_context); + if (!cell) + return NULL; + + cell->winsys = cws; + cell->pipe.winsys = winsys; + cell->pipe.destroy = cell_destroy_context; + + /* queries */ + cell->pipe.is_format_supported = cell_is_format_supported; + cell->pipe.get_name = cell_get_name; + cell->pipe.get_vendor = cell_get_vendor; + cell->pipe.get_param = cell_get_param; + cell->pipe.get_paramf = cell_get_paramf; + + + /* state setters */ + cell->pipe.create_alpha_test_state = cell_create_alpha_test_state; + cell->pipe.bind_alpha_test_state = cell_bind_alpha_test_state; + cell->pipe.delete_alpha_test_state = cell_delete_alpha_test_state; + + cell->pipe.create_blend_state = cell_create_blend_state; + cell->pipe.bind_blend_state = cell_bind_blend_state; + cell->pipe.delete_blend_state = cell_delete_blend_state; + + cell->pipe.create_sampler_state = cell_create_sampler_state; + cell->pipe.bind_sampler_state = cell_bind_sampler_state; + cell->pipe.delete_sampler_state = cell_delete_sampler_state; + + cell->pipe.create_depth_stencil_state = cell_create_depth_stencil_state; + cell->pipe.bind_depth_stencil_state = cell_bind_depth_stencil_state; + cell->pipe.delete_depth_stencil_state = cell_delete_depth_stencil_state; + + cell->pipe.create_rasterizer_state = cell_create_rasterizer_state; + cell->pipe.bind_rasterizer_state = cell_bind_rasterizer_state; + cell->pipe.delete_rasterizer_state = cell_delete_rasterizer_state; + + cell->pipe.create_fs_state = cell_create_fs_state; + cell->pipe.bind_fs_state = cell_bind_fs_state; + cell->pipe.delete_fs_state = cell_delete_fs_state; + + cell->pipe.create_vs_state = cell_create_vs_state; + cell->pipe.bind_vs_state = cell_bind_vs_state; + cell->pipe.delete_vs_state = cell_delete_vs_state; + + cell->pipe.set_blend_color = cell_set_blend_color; + cell->pipe.set_clip_state = cell_set_clip_state; + cell->pipe.set_clear_color_state = cell_set_clear_color_state; + cell->pipe.set_constant_buffer = cell_set_constant_buffer; +#if 0 + cell->pipe.set_feedback_state = cell_set_feedback_state; +#endif + + cell->pipe.set_framebuffer_state = cell_set_framebuffer_state; + + cell->pipe.set_polygon_stipple = cell_set_polygon_stipple; + cell->pipe.set_sampler_units = cell_set_sampler_units; + cell->pipe.set_scissor_state = cell_set_scissor_state; + cell->pipe.set_texture_state = cell_set_texture_state; + cell->pipe.set_viewport_state = cell_set_viewport_state; + + cell->pipe.set_vertex_buffer = cell_set_vertex_buffer; + cell->pipe.set_vertex_element = cell_set_vertex_element; +#if 0 + cell->pipe.set_feedback_buffer = cell_set_feedback_buffer; + + cell->pipe.draw_arrays = cell_draw_arrays; + cell->pipe.draw_elements = cell_draw_elements; +#endif + + cell->pipe.clear = cell_clear_surface; + cell->pipe.flush = cell_flush; + +#if 0 + cell->pipe.begin_query = cell_begin_query; + cell->pipe.end_query = cell_end_query; + cell->pipe.wait_query = cell_wait_query; + + /* textures */ + cell->pipe.mipmap_tree_layout = cell_mipmap_tree_layout; + cell->pipe.get_tex_surface = cell_get_tex_surface; +#endif + + + cell->draw = draw_create(); + + /* + * SPU stuff + */ + cell->num_spus = 6; /* XXX >6 seems to fail */ + + cell_start_spus(cell->num_spus); - start_spus(); +#if 0 + test_spus(cell); + wait_spus(); +#endif - /* TODO: do something with the SPUs! */ + return &cell->pipe; } diff --git a/src/mesa/pipe/cell/ppu/cell_context.h b/src/mesa/pipe/cell/ppu/cell_context.h index b4d93d1414..a64692081d 100644 --- a/src/mesa/pipe/cell/ppu/cell_context.h +++ b/src/mesa/pipe/cell/ppu/cell_context.h @@ -31,16 +31,61 @@ #include "pipe/p_context.h" - +#include "cell_winsys.h" struct cell_context { struct pipe_context pipe; - int spu_info; + struct cell_winsys *winsys; + + const struct pipe_alpha_test_state *alpha_test; + const struct pipe_blend_state *blend; + const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + const struct pipe_depth_stencil_state *depth_stencil; + const struct pipe_rasterizer_state *rasterizer; + + struct pipe_blend_color blend_color; + struct pipe_clear_color_state clear_color; + struct pipe_clip_state clip; + struct pipe_constant_buffer constants[2]; + struct pipe_feedback_state feedback; + struct pipe_framebuffer_state framebuffer; + struct pipe_poly_stipple poly_stipple; + struct pipe_scissor_state scissor; + struct softpipe_texture *texture[PIPE_MAX_SAMPLERS]; + struct pipe_viewport_state viewport; + struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; + struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; + uint sampler_units[PIPE_MAX_SAMPLERS]; + uint dirty; + + /** The primitive drawing context */ + struct draw_context *draw; + struct draw_stage *setup; + struct draw_stage *vbuf; + + + uint num_spus; + + }; +static INLINE struct cell_context * +cell_context(struct pipe_context *pipe) +{ + return (struct cell_context *) pipe; +} + + +extern struct pipe_context * +cell_create_context(struct pipe_winsys *ws, struct cell_winsys *cws); + + + + + #endif /* CELL_CONTEXT_H */ diff --git a/src/mesa/pipe/cell/ppu/cell_flush.c b/src/mesa/pipe/cell/ppu/cell_flush.c new file mode 100644 index 0000000000..e844d13f06 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_flush.c @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright 2007 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 <cbe_mfc.h> + +#include "cell_context.h" +#include "cell_flush.h" +#include "cell_spu.h" + + +void +cell_flush(struct pipe_context *pipe, unsigned flags) +{ + struct cell_context *cell = cell_context(pipe); + uint i; + + printf("%s\n", __FUNCTION__); + + /* Send CMD_FINISH to all SPUs */ + for (i = 0; i < cell->num_spus; i++) { + send_mbox_message(control_ps_area[i], CELL_CMD_FINISH); + } + + /* Wait for ack */ + for (i = 0; i < cell->num_spus; i++) { + uint k = wait_mbox_message(control_ps_area[i]); + assert(k == CELL_CMD_FINISH); + } +} diff --git a/src/mesa/pipe/cell/ppu/cell_flush.h b/src/mesa/pipe/cell/ppu/cell_flush.h new file mode 100644 index 0000000000..cf1a104f97 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_flush.h @@ -0,0 +1,35 @@ +/************************************************************************** + * + * Copyright 2007 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 CELL_FLUSH +#define CELL_FLUSH + +extern void +cell_flush(struct pipe_context *pipe, unsigned flags); + +#endif diff --git a/src/mesa/pipe/cell/ppu/cell_spu.c b/src/mesa/pipe/cell/ppu/cell_spu.c new file mode 100644 index 0000000000..ed56250ff1 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_spu.c @@ -0,0 +1,223 @@ +/************************************************************************** + * + * Copyright 2007 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 <cbe_mfc.h> + +#include "cell_spu.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "pipe/cell/common.h" + + +/* +helpful headers: +/opt/ibm/cell-sdk/prototype/src/include/ppu/cbe_mfc.h +*/ + + +/** + * SPU/SPE handles, etc + */ +speid_t speid[MAX_SPUS]; +spe_spu_control_area_t *control_ps_area[MAX_SPUS]; + + +/** + * Data sent to SPUs + */ +struct cell_init_info inits[MAX_SPUS] ALIGN16; +struct cell_command command[MAX_SPUS] ALIGN16; + + +/** + * Write a 1-word message to the given SPE mailbox. + */ +void +send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg) +{ + while (_spe_in_mbox_status(ca) < 1) + ; + _spe_in_mbox_write(ca, msg); +} + + +/** + * Wait for a 1-word message to arrive in given mailbox. + */ +uint +wait_mbox_message(spe_spu_control_area_t *ca) +{ + uint k; + while (_spe_out_mbox_status(ca) < 1) + ; + k = _spe_out_mbox_read(ca); + return k; +} + + +/** + * Create the SPU threads + */ +void +cell_start_spus(uint num_spus) +{ + uint i; + + assert((sizeof(struct cell_command) & 0xf) == 0); + ASSERT_ALIGN16(&command[0]); + ASSERT_ALIGN16(&command[1]); + + assert((sizeof(struct cell_init_info) & 0xf) == 0); + ASSERT_ALIGN16(&inits[0]); + ASSERT_ALIGN16(&inits[1]); + + /* XXX do we need to create a gid with spe_create_group()? */ + + for (i = 0; i < num_spus; i++) { + inits[i].id = i; + inits[i].num_spus = num_spus; + inits[i].cmd = &command[i]; + + speid[i] = spe_create_thread(0, /* gid */ + &g3d_spu, /* spe program handle */ + &inits[i], /* argp */ + NULL, /* envp */ + -1, /* mask */ + SPE_MAP_PS/*0*/ ); /* flags */ + + control_ps_area[i] = spe_get_ps_area(speid[i], SPE_CONTROL_AREA); + assert(control_ps_area[i]); + } +} + + +/** wait for all SPUs to finish working */ +/** XXX temporary */ +void +finish_all(uint num_spus) +{ + uint i; + + for (i = 0; i < num_spus; i++) { + send_mbox_message(control_ps_area[i], CELL_CMD_FINISH); + } + for (i = 0; i < num_spus; i++) { + /* wait for mbox message */ + unsigned k; + while (_spe_out_mbox_status(control_ps_area[i]) < 1) + ; + k = _spe_out_mbox_read(control_ps_area[i]); + assert(k == CELL_CMD_FINISH); + } +} + + +/** + ** Send test commands (XXX temporary) + **/ +void +test_spus(struct cell_context *cell) +{ + uint i; + struct pipe_surface *surf = cell->framebuffer.cbufs[0]; + + printf("PPU: sleep(2)\n\n\n"); + sleep(2); + + for (i = 0; i < cell->num_spus; i++) { + command[i].fb.start = surf->map; + command[i].fb.width = surf->width; + command[i].fb.height = surf->height; + command[i].fb.format = PIPE_FORMAT_A8R8G8B8_UNORM; + send_mbox_message(control_ps_area[i], CELL_CMD_FRAMEBUFFER); + } + + for (i = 0; i < cell->num_spus; i++) { + command[i].clear.value = 0xff880044; /* XXX */ + send_mbox_message(control_ps_area[i], CELL_CMD_CLEAR_TILES); + } + + finish_all(cell->num_spus); + + { + uint *b = (uint*) surf->map; + printf("PPU: Clear results: 0x%x 0x%x 0x%x 0x%x\n", + b[0], b[1000], b[2000], b[3000]); + } + + for (i = 0; i < cell->num_spus; i++) { + send_mbox_message(control_ps_area[i], CELL_CMD_INVERT_TILES); + } + + finish_all(cell->num_spus); + + { + uint *b = (uint*) surf->map; + printf("PPU: Inverted results: 0x%x 0x%x 0x%x 0x%x\n", + b[0], b[1000], b[2000], b[3000]); + } + + + + for (i = 0; i < cell->num_spus; i++) { + send_mbox_message(control_ps_area[i], CELL_CMD_EXIT); + } +} + + +/** + * Wait for all SPUs to exit/return. + */ +void +wait_spus(uint num_spus) +{ + int i, status; + + for (i = 0; i < num_spus; i++) { + spe_wait( speid[i], &status, 1 ); + } +} + + +/** + * Tell all the SPUs to stop/exit. + */ +void +cell_spu_exit(struct cell_context *cell) +{ + uint i; + int status; + + for (i = 0; i < cell->num_spus; i++) { + send_mbox_message(control_ps_area[i], CELL_CMD_EXIT); + } + + for (i = 0; i < cell->num_spus; i++) { + spe_wait( speid[i], &status, 1 ); + } +} diff --git a/src/mesa/pipe/cell/ppu/cell_spu.h b/src/mesa/pipe/cell/ppu/cell_spu.h new file mode 100644 index 0000000000..dcbc72573f --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_spu.h @@ -0,0 +1,81 @@ +/************************************************************************** + * + * Copyright 2007 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 CELL_SPU +#define CELL_SPU + + +#include <libspe.h> +#include <libmisc.h> +#include "pipe/cell/common.h" + +#include "cell_context.h" + + +#define MAX_SPUS 7 + +/** + * SPU/SPE handles, etc + */ +extern spe_program_handle_t g3d_spu; +extern speid_t speid[MAX_SPUS]; +extern spe_spu_control_area_t *control_ps_area[MAX_SPUS]; + + +/** + * Data sent to SPUs + */ +extern struct cell_init_info inits[MAX_SPUS] ALIGN16; +extern struct cell_command command[MAX_SPUS] ALIGN16; + + +void +send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg); + +uint +wait_mbox_message(spe_spu_control_area_t *ca); + + +void +cell_start_spus(uint num_spus); + + +void +finish_all(uint num_spus); + +void +test_spus(struct cell_context *cell); + + +void +wait_spus(uint num_spus); + +void +cell_spu_exit(struct cell_context *cell); + + +#endif /* CELL_SPU */ diff --git a/src/mesa/pipe/cell/ppu/cell_state.h b/src/mesa/pipe/cell/ppu/cell_state.h new file mode 100644 index 0000000000..033767d29b --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state.h @@ -0,0 +1,117 @@ + + +#ifndef CELL_STATE_H +#define CELL_STATE_H + + +#define CELL_NEW_VIEWPORT 0x1 +#define CELL_NEW_RASTERIZER 0x2 +#define CELL_NEW_FS 0x4 +#define CELL_NEW_BLEND 0x8 +#define CELL_NEW_CLIP 0x10 +#define CELL_NEW_SCISSOR 0x20 +#define CELL_NEW_STIPPLE 0x40 +#define CELL_NEW_FRAMEBUFFER 0x80 +#define CELL_NEW_ALPHA_TEST 0x100 +#define CELL_NEW_DEPTH_STENCIL 0x200 +#define CELL_NEW_SAMPLER 0x400 +#define CELL_NEW_TEXTURE 0x800 +#define CELL_NEW_VERTEX 0x1000 +#define CELL_NEW_VS 0x2000 +#define CELL_NEW_CONSTANTS 0x4000 + + + +extern void +cell_set_framebuffer_state( struct pipe_context *, + const struct pipe_framebuffer_state * ); + + +extern void * +cell_create_alpha_test_state(struct pipe_context *, + const struct pipe_alpha_test_state *); +extern void +cell_bind_alpha_test_state(struct pipe_context *, void *); +extern void +cell_delete_alpha_test_state(struct pipe_context *, void *); + +extern void * +cell_create_blend_state(struct pipe_context *, const struct pipe_blend_state *); +extern void cell_bind_blend_state(struct pipe_context *, void *); +extern void cell_delete_blend_state(struct pipe_context *, void *); + +extern void cell_set_blend_color( struct pipe_context *pipe, + const struct pipe_blend_color *blend_color ); + + +void * +cell_create_sampler_state(struct pipe_context *, + const struct pipe_sampler_state *); + +extern void +cell_bind_sampler_state(struct pipe_context *, unsigned, void *); + +extern void +cell_delete_sampler_state(struct pipe_context *, void *); + + +extern void * +cell_create_depth_stencil_state(struct pipe_context *, + const struct pipe_depth_stencil_state *); + +extern void +cell_bind_depth_stencil_state(struct pipe_context *, void *); + +extern void +cell_delete_depth_stencil_state(struct pipe_context *, void *); + + +void *cell_create_fs_state(struct pipe_context *, + const struct pipe_shader_state *); +void cell_bind_fs_state(struct pipe_context *, void *); +void cell_delete_fs_state(struct pipe_context *, void *); +void *cell_create_vs_state(struct pipe_context *, + const struct pipe_shader_state *); +void cell_bind_vs_state(struct pipe_context *, void *); +void cell_delete_vs_state(struct pipe_context *, void *); + + +void * +cell_create_rasterizer_state(struct pipe_context *, + const struct pipe_rasterizer_state *); +void cell_bind_rasterizer_state(struct pipe_context *, void *); +void cell_delete_rasterizer_state(struct pipe_context *, void *); + + +void cell_set_clip_state( struct pipe_context *, + const struct pipe_clip_state * ); + +void cell_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + const struct pipe_constant_buffer *buf); + +void cell_set_polygon_stipple( struct pipe_context *, + const struct pipe_poly_stipple * ); + +void cell_set_sampler_units( struct pipe_context *, + uint numSamplers, const uint *units ); + +void cell_set_scissor_state( struct pipe_context *, + const struct pipe_scissor_state * ); + +void cell_set_texture_state( struct pipe_context *, + unsigned unit, struct pipe_texture * ); + +void cell_set_vertex_element(struct pipe_context *, + unsigned index, + const struct pipe_vertex_element *); + +void cell_set_vertex_buffer(struct pipe_context *, + unsigned index, + const struct pipe_vertex_buffer *); + +void cell_set_viewport_state( struct pipe_context *, + const struct pipe_viewport_state * ); + + +#endif diff --git a/src/mesa/pipe/cell/ppu/cell_state_blend.c b/src/mesa/pipe/cell/ppu/cell_state_blend.c new file mode 100644 index 0000000000..e807463d90 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state_blend.c @@ -0,0 +1,128 @@ +/************************************************************************** + * + * Copyright 2007 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. + * + **************************************************************************/ + +/* Authors: Keith Whitwell <keith@tungstengraphics.com> + */ + +#include "pipe/p_util.h" +#include "cell_context.h" +#include "cell_state.h" + +void * +cell_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend) +{ + struct pipe_blend_state *state = MALLOC( sizeof(struct pipe_blend_state) ); + memcpy(state, blend, sizeof(struct pipe_blend_state)); + return state; +} + +void cell_bind_blend_state( struct pipe_context *pipe, + void *blend ) +{ + struct cell_context *cell = cell_context(pipe); + + cell->blend = (const struct pipe_blend_state *)blend; + + cell->dirty |= CELL_NEW_BLEND; +} + +void cell_delete_blend_state(struct pipe_context *pipe, + void *blend) +{ + FREE( blend ); +} + + +void cell_set_blend_color( struct pipe_context *pipe, + const struct pipe_blend_color *blend_color ) +{ + struct cell_context *cell = cell_context(pipe); + + cell->blend_color = *blend_color; + + cell->dirty |= CELL_NEW_BLEND; +} + + +/** XXX move someday? Or consolidate all these simple state setters + * into one file. + */ + +void * +cell_create_alpha_test_state(struct pipe_context *pipe, + const struct pipe_alpha_test_state *alpha) +{ + struct pipe_alpha_test_state *state = MALLOC( sizeof(struct pipe_alpha_test_state) ); + memcpy(state, alpha, sizeof(struct pipe_alpha_test_state)); + return state; +} + +void +cell_bind_alpha_test_state(struct pipe_context *pipe, + void *alpha) +{ + struct cell_context *cell = cell_context(pipe); + + cell->alpha_test = (const struct pipe_alpha_test_state *)alpha; + + cell->dirty |= CELL_NEW_ALPHA_TEST; +} + +void +cell_delete_alpha_test_state(struct pipe_context *pipe, + void *alpha) +{ + FREE( alpha ); +} + +void * +cell_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *depth_stencil) +{ + struct pipe_depth_stencil_state *state = + MALLOC( sizeof(struct pipe_depth_stencil_state) ); + memcpy(state, depth_stencil, sizeof(struct pipe_depth_stencil_state)); + return state; +} + +void +cell_bind_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + struct cell_context *cell = cell_context(pipe); + + cell->depth_stencil = (const struct pipe_depth_stencil_state *)depth_stencil; + + cell->dirty |= CELL_NEW_DEPTH_STENCIL; +} + +void +cell_delete_depth_stencil_state(struct pipe_context *pipe, void *depth) +{ + FREE( depth ); +} diff --git a/src/mesa/pipe/cell/ppu/cell_state_clip.c b/src/mesa/pipe/cell/ppu/cell_state_clip.c new file mode 100644 index 0000000000..4f43665941 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state_clip.c @@ -0,0 +1,84 @@ +/************************************************************************** + * + * Copyright 2007 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. + * + **************************************************************************/ + +/* Authors: Keith Whitwell <keith@tungstengraphics.com> + */ + +#include "cell_context.h" +#include "cell_state.h" +#include "pipe/draw/draw_context.h" + + +void cell_set_clip_state( struct pipe_context *pipe, + const struct pipe_clip_state *clip ) +{ + struct cell_context *cell = cell_context(pipe); + + /* pass the clip state to the draw module */ + draw_set_clip_state(cell->draw, clip); +} + + + +/* Called when driver state tracker notices changes to the viewport + * matrix: + */ +void cell_set_viewport_state( struct pipe_context *pipe, + const struct pipe_viewport_state *viewport ) +{ + struct cell_context *cell = cell_context(pipe); + + cell->viewport = *viewport; /* struct copy */ + cell->dirty |= CELL_NEW_VIEWPORT; + + /* pass the viewport info to the draw module */ + draw_set_viewport_state(cell->draw, viewport); + + /* Using tnl/ and vf/ modules is temporary while getting started. + * Full pipe will have vertex shader, vertex fetch of its own. + */ +} + + +void cell_set_scissor_state( struct pipe_context *pipe, + const struct pipe_scissor_state *scissor ) +{ + struct cell_context *cell = cell_context(pipe); + + memcpy( &cell->scissor, scissor, sizeof(*scissor) ); + cell->dirty |= CELL_NEW_SCISSOR; +} + + +void cell_set_polygon_stipple( struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple ) +{ + struct cell_context *cell = cell_context(pipe); + + memcpy( &cell->poly_stipple, stipple, sizeof(*stipple) ); + cell->dirty |= CELL_NEW_STIPPLE; +} diff --git a/src/mesa/pipe/cell/ppu/cell_state_fs.c b/src/mesa/pipe/cell/ppu/cell_state_fs.c new file mode 100644 index 0000000000..910f210cdc --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state_fs.c @@ -0,0 +1,195 @@ +/************************************************************************** + * + * Copyright 2007 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 "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" +#if 0 +#include "pipe/draw/draw_context.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/llvm/gallivm.h" +#include "pipe/tgsi/util/tgsi_dump.h" +#include "pipe/tgsi/exec/tgsi_sse2.h" +#endif + +#include "cell_context.h" +#include "cell_state.h" + + +void * cell_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct cell_context *cell = cell_context(pipe); + + return malloc(5); /* XXX temp */ + +#if 0 + /* Decide whether we'll be codegenerating this shader and if so do + * that now. + */ + + struct sp_fragment_shader_state *state = MALLOC( sizeof(struct sp_fragment_shader_state) ); + state->shader = *templ; + + if( cell->dump_fs ) { + tgsi_dump( + state->shader.tokens, + 0 ); + } + +#if defined(__i386__) || defined(__386__) + if (cell->use_sse) { + x86_init_func( &state->sse2_program ); + tgsi_emit_sse2_fs( state->shader.tokens, &state->sse2_program ); + } +#endif + +#ifdef MESA_LLVM + state->llvm_prog = gallivm_from_tgsi(state->shader.tokens, GALLIVM_FS); + if (!gallivm_global_cpu_engine()) { + gallivm_cpu_engine_create(state->llvm_prog); + } + else + gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state->llvm_prog); +#endif + return state; +#endif +} + +void cell_bind_fs_state(struct pipe_context *pipe, void *fs) +{ + struct cell_context *cell = cell_context(pipe); +#if 0 + cell->fs = (struct sp_fragment_shader_state *) fs; + + cell->dirty |= SP_NEW_FS; +#endif +} + +void cell_delete_fs_state(struct pipe_context *pipe, + void *shader) +{ +#if 0 + struct sp_fragment_shader_state *state = shader; + +#if defined(__i386__) || defined(__386__) + x86_release_func( &state->sse2_program ); +#endif + + FREE( state ); +#endif +} + + +void * +cell_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + return malloc(5); /* XXX */ +#if 0 + struct cell_context *cell = cell_context(pipe); + struct sp_vertex_shader_state *state; + + state = MALLOC( sizeof(struct sp_vertex_shader_state) ); + if (state == NULL ) { + return NULL; + } + + state->state = MALLOC( sizeof(struct pipe_shader_state) ); + if (state->state == NULL) { + FREE( state ); + return NULL; + } + memcpy( state->state, templ, sizeof(struct pipe_shader_state) ); + + state->draw_data = draw_create_vertex_shader(cell->draw, + state->state); + if (state->draw_data == NULL) { + FREE( state->state ); + FREE( state ); + return NULL; + } + + return state; +#endif +} + + + +void +cell_bind_vs_state(struct pipe_context *pipe, void *vs) +{ +#if 0 + struct cell_context *cell = cell_context(pipe); + + cell->vs = (const struct sp_vertex_shader_state *)vs; + + draw_bind_vertex_shader(cell->draw, cell->vs->draw_data); + + cell->dirty |= SP_NEW_VS; +#endif +} + +void +cell_delete_vs_state(struct pipe_context *pipe, void *vs) +{ +#if 0 + struct cell_context *cell = cell_context(pipe); + + struct sp_vertex_shader_state *state = + (struct sp_vertex_shader_state *)vs; + + draw_delete_vertex_shader(cell->draw, state->draw_data); + FREE( state->state ); + FREE( state ); +#endif +} + + + +void cell_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + const struct pipe_constant_buffer *buf) +{ +#if 0 + struct cell_context *cell = cell_context(pipe); + struct pipe_winsys *ws = pipe->winsys; + + assert(shader < PIPE_SHADER_TYPES); + assert(index == 0); + + /* note: reference counting */ + ws->buffer_reference(ws, + &cell->constants[shader].buffer, + buf->buffer); + cell->constants[shader].size = buf->size; + + cell->dirty |= SP_NEW_CONSTANTS; +#endif +} + + diff --git a/src/mesa/pipe/cell/ppu/cell_state_rasterizer.c b/src/mesa/pipe/cell/ppu/cell_state_rasterizer.c new file mode 100644 index 0000000000..11e7de7309 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state_rasterizer.c @@ -0,0 +1,65 @@ +/************************************************************************** + * + * Copyright 2007 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 "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/draw/draw_context.h" +#include "cell_context.h" +#include "cell_state.h" + + +void * +cell_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *setup) +{ + struct pipe_rasterizer_state *state = + MALLOC( sizeof(struct pipe_rasterizer_state) ); + memcpy(state, setup, sizeof(struct pipe_rasterizer_state)); + return state; +} + + +void +cell_bind_rasterizer_state(struct pipe_context *pipe, void *setup) +{ + struct cell_context *cell = cell_context(pipe); + + /* pass-through to draw module */ + draw_set_rasterizer_state(cell->draw, setup); + + cell->rasterizer = (struct pipe_rasterizer_state *)setup; + + cell->dirty |= CELL_NEW_RASTERIZER; +} + +void +cell_delete_rasterizer_state(struct pipe_context *pipe, void *rasterizer) +{ + FREE( rasterizer ); +} + + diff --git a/src/mesa/pipe/cell/ppu/cell_state_sampler.c b/src/mesa/pipe/cell/ppu/cell_state_sampler.c new file mode 100644 index 0000000000..c2a180ed30 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state_sampler.c @@ -0,0 +1,100 @@ +/************************************************************************** + * + * Copyright 2007 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. + * + **************************************************************************/ + +/* Authors: + * Brian Paul + */ + +#include "pipe/p_util.h" +#include "cell_context.h" +#include "cell_state.h" +#if 0 +#include "cell_texture.h" +#include "cell_tile_cache.h" +#endif + + +void * +cell_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + struct pipe_sampler_state *state = MALLOC( sizeof(struct pipe_sampler_state) ); + memcpy(state, sampler, sizeof(struct pipe_sampler_state)); + return state; +} + +void +cell_bind_sampler_state(struct pipe_context *pipe, + unsigned unit, void *sampler) +{ + struct cell_context *cell = cell_context(pipe); + + assert(unit < PIPE_MAX_SAMPLERS); + cell->sampler[unit] = (struct pipe_sampler_state *)sampler; + + cell->dirty |= CELL_NEW_SAMPLER; +} + + +void +cell_delete_sampler_state(struct pipe_context *pipe, + void *sampler) +{ + FREE( sampler ); +} + + +void +cell_set_texture_state(struct pipe_context *pipe, + unsigned unit, + struct pipe_texture *texture) +{ + struct cell_context *cell = cell_context(pipe); + + assert(unit < PIPE_MAX_SAMPLERS); + +#if 0 + cell->texture[unit] = cell_texture(texture); /* ptr, not struct */ + cell_tile_cache_set_texture(cell->tex_cache[unit], texture); +#endif + + cell->dirty |= CELL_NEW_TEXTURE; +} + + +void +cell_set_sampler_units(struct pipe_context *pipe, + uint num_samplers, const uint *units ) +{ + struct cell_context *cell = cell_context(pipe); + uint i; + for (i = 0; i < num_samplers; i++) + cell->sampler_units[i] = units[i]; + cell->dirty |= CELL_NEW_SAMPLER; +} + + diff --git a/src/mesa/pipe/cell/ppu/cell_state_surface.c b/src/mesa/pipe/cell/ppu/cell_state_surface.c new file mode 100644 index 0000000000..f7330caf5e --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state_surface.c @@ -0,0 +1,99 @@ + + +#include "cell_context.h" +#include "cell_state.h" + +void +cell_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct cell_context *cell = cell_context(pipe); + + cell->framebuffer = *fb; + + cell->dirty |= CELL_NEW_FRAMEBUFFER; + +#if 0 + struct pipe_surface *ps; + uint i; + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + /* check if changing cbuf */ + if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) { + /* flush old */ + sp_flush_tile_cache(sp, sp->cbuf_cache[i]); + /* unmap old */ + ps = sp->framebuffer.cbufs[i]; + if (ps && ps->map) + pipe_surface_unmap(ps); + /* map new */ + ps = fb->cbufs[i]; + if (ps) + pipe_surface_map(ps); + /* assign new */ + sp->framebuffer.cbufs[i] = fb->cbufs[i]; + + /* update cache */ + sp_tile_cache_set_surface(sp, sp->cbuf_cache[i], ps); + } + } + + sp->framebuffer.num_cbufs = fb->num_cbufs; + + /* zbuf changing? */ + if (sp->framebuffer.zbuf != fb->zbuf) { + /* flush old */ + sp_flush_tile_cache(sp, sp->zbuf_cache); + /* unmap old */ + ps = sp->framebuffer.zbuf; + if (ps && ps->map) + pipe_surface_unmap(ps); + if (sp->framebuffer.sbuf == sp->framebuffer.zbuf) { + /* combined z/stencil */ + sp->framebuffer.sbuf = NULL; + } + /* map new */ + ps = fb->zbuf; + if (ps) + pipe_surface_map(ps); + /* assign new */ + sp->framebuffer.zbuf = fb->zbuf; + + /* update cache */ + sp_tile_cache_set_surface(sp, sp->zbuf_cache, ps); + } + + /* XXX combined depth/stencil here */ + + /* sbuf changing? */ + if (sp->framebuffer.sbuf != fb->sbuf) { + /* flush old */ + sp_flush_tile_cache(sp, sp->sbuf_cache_sep); + /* unmap old */ + ps = sp->framebuffer.sbuf; + if (ps && ps->map) + pipe_surface_unmap(ps); + /* map new */ + ps = fb->sbuf; + if (ps && fb->sbuf != fb->zbuf) + pipe_surface_map(ps); + /* assign new */ + sp->framebuffer.sbuf = fb->sbuf; + + /* update cache */ + if (fb->sbuf != fb->zbuf) { + /* separate stencil buf */ + sp->sbuf_cache = sp->sbuf_cache_sep; + sp_tile_cache_set_surface(sp, sp->sbuf_cache, ps); + } + else { + /* combined depth/stencil */ + sp->sbuf_cache = sp->zbuf_cache; + sp_tile_cache_set_surface(sp, sp->sbuf_cache, ps); + } + } + + sp->dirty |= SP_NEW_FRAMEBUFFER; +#endif +} + diff --git a/src/mesa/pipe/cell/ppu/cell_state_vertex.c b/src/mesa/pipe/cell/ppu/cell_state_vertex.c new file mode 100644 index 0000000000..0f01e920f9 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state_vertex.c @@ -0,0 +1,63 @@ +/************************************************************************** + * + * Copyright 2007 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. + * + **************************************************************************/ + +/* Authors: Keith Whitwell <keith@tungstengraphics.com> + */ + + +#include "cell_context.h" +#include "cell_state.h" + +#include "pipe/draw/draw_context.h" + + +void +cell_set_vertex_element(struct pipe_context *pipe, + unsigned index, + const struct pipe_vertex_element *attrib) +{ + struct cell_context *cell = cell_context(pipe); + assert(index < PIPE_ATTRIB_MAX); + cell->vertex_element[index] = *attrib; /* struct copy */ + cell->dirty |= CELL_NEW_VERTEX; + + draw_set_vertex_element(cell->draw, index, attrib); +} + + +void +cell_set_vertex_buffer(struct pipe_context *pipe, + unsigned index, + const struct pipe_vertex_buffer *buffer) +{ + struct cell_context *cell = cell_context(pipe); + assert(index < PIPE_ATTRIB_MAX); + cell->vertex_buffer[index] = *buffer; /* struct copy */ + cell->dirty |= CELL_NEW_VERTEX; + + draw_set_vertex_buffer(cell->draw, index, buffer); +} diff --git a/src/mesa/pipe/cell/ppu/cell_surface.c b/src/mesa/pipe/cell/ppu/cell_surface.c index 2c4b6e640b..1692960244 100644 --- a/src/mesa/pipe/cell/ppu/cell_surface.c +++ b/src/mesa/pipe/cell/ppu/cell_surface.c @@ -1,9 +1,106 @@ +/************************************************************************** + * + * Copyright 2007 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. + * + **************************************************************************/ + +/** + * Authors + * Brian Paul + */ #include <stdio.h> +#include <assert.h> +#include <stdint.h> +#include "pipe/p_inlines.h" +#include "pipe/p_util.h" +#include "pipe/cell/common.h" +#include "cell_context.h" +#include "cell_surface.h" +#include "cell_spu.h" + -void cell_create_surface(void) +struct pipe_surface * +cell_create_surface(int width, int height) { +#if 0 + /* XXX total hack */ + struct pipe_surface *ps = CALLOC_STRUCT(pipe_surface); + printf("cell_create_surface\n"); + ps->width = width; + ps->height = height; + + ps->region = CALLOC_STRUCT(pipe_region); + ps->region->map = align_malloc(width * height * 4, 16); + return ps; +#endif + return NULL; +} + + + +void +cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps, + unsigned clearValue) +{ + struct cell_context *cell = cell_context(pipe); + uint i; + + printf("%s 0x%08x\n", __FUNCTION__, clearValue); + + { + char s[100]; + pf_sprint_name(s, ps->format); + printf("format = %s\n", s); + } + + if (!ps->map) + pipe_surface_map(ps); + + for (i = 0; i < cell->num_spus; i++) { + command[i].fb.start = ps->map; + command[i].fb.width = ps->width; + command[i].fb.height = ps->height; + command[i].fb.format = ps->format; + send_mbox_message(control_ps_area[i], CELL_CMD_FRAMEBUFFER); + } + + for (i = 0; i < cell->num_spus; i++) { + command[i].clear.value = clearValue | (i << 21); + send_mbox_message(control_ps_area[i], CELL_CMD_CLEAR_TILES); + } +} + + +void +cell_set_clear_color_state(struct pipe_context *pipe, + const struct pipe_clear_color_state *clear) +{ + struct cell_context *cell = cell_context(pipe); + + cell->clear_color = *clear; /* struct copy */ } diff --git a/src/mesa/pipe/cell/ppu/cell_surface.h b/src/mesa/pipe/cell/ppu/cell_surface.h new file mode 100644 index 0000000000..8b42ba02d5 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_surface.h @@ -0,0 +1,49 @@ +/************************************************************************** + * + * Copyright 2007 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 CELL_SURFACE +#define CELL_SURFACE + + +#include "pipe/p_state.h" + + +extern struct pipe_surface * +cell_create_surface(int width, int height); + +extern void +cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps, + unsigned clearValue); + + +extern void +cell_set_clear_color_state(struct pipe_context *pipe, + const struct pipe_clear_color_state *clear); + + +#endif /* CELL_SURFACE */ diff --git a/src/mesa/pipe/cell/ppu/cell_winsys.c b/src/mesa/pipe/cell/ppu/cell_winsys.c new file mode 100644 index 0000000000..ebabce3c8f --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_winsys.c @@ -0,0 +1,40 @@ +/************************************************************************** + * + * Copyright 2007 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 "pipe/p_util.h" +#include "cell_winsys.h" + + +struct cell_winsys * +cell_get_winsys(uint format) +{ + struct cell_winsys *cws = CALLOC_STRUCT(cell_winsys); + if (cws) + cws->preferredFormat = format; + return cws; +} diff --git a/src/mesa/pipe/cell/ppu/cell_winsys.h b/src/mesa/pipe/cell/ppu/cell_winsys.h new file mode 100644 index 0000000000..ae2af5696b --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_winsys.h @@ -0,0 +1,50 @@ +/************************************************************************** + * + * Copyright 2007 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 CELL_WINSYS_H +#define CELL_WINSYS_H + +#include "pipe/p_compiler.h" + + +/** + * Very simple winsys at this time. + * Will probably eventually add SPU control info. + */ +struct cell_winsys +{ + uint preferredFormat; +}; + + +extern struct cell_winsys * +cell_get_winsys(uint format); + + + +#endif diff --git a/src/mesa/pipe/cell/spu/main.c b/src/mesa/pipe/cell/spu/main.c index e8d5fdccbf..226d81b4ca 100644 --- a/src/mesa/pipe/cell/spu/main.c +++ b/src/mesa/pipe/cell/spu/main.c @@ -1,15 +1,241 @@ -/* main.c for cell SPU code */ +/************************************************************************** + * + * Copyright 2007 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. + * + **************************************************************************/ + + +/* main() for Cell SPU code */ #include <stdio.h> +#include <assert.h> #include <libmisc.h> #include <spu_mfcio.h> #include "tri.h" #include "pipe/cell/common.h" +/* +helpful headers: +/usr/lib/gcc/spu/4.1.1/include/spu_mfcio.h +/opt/ibm/cell-sdk/prototype/sysroot/usr/include/libmisc.h +*/ + +static struct cell_init_info init; + +struct framebuffer { + void *start; + uint width, height; + uint width_tiles, height_tiles; /**< width and height in tiles */ +}; +static struct framebuffer fb; + + +static int DefaultTag = 1; + + + +static inline void +wait_on_mask(unsigned tag) +{ + mfc_write_tag_mask( tag ); + mfc_read_tag_status_any(); +} + + + +static void +get_tile(const struct framebuffer *fb, uint tx, uint ty, uint *tile) +{ + uint offset = ty * fb->width_tiles + tx; + uint bytesPerTile = TILE_SIZE * TILE_SIZE * 4; + ubyte *src = (ubyte *) fb->start + offset * bytesPerTile; + int tag = DefaultTag; + + assert(tx < fb->width_tiles); + assert(ty < fb->height_tiles); + ASSERT_ALIGN16(tile); + /* + printf("get_tile: dest: %p src: 0x%x size: %d\n", + tile, (unsigned int) src, bytesPerTile); + */ + mfc_get(tile, /* dest in local memory */ + (unsigned int) src, /* src in main memory */ + bytesPerTile, + tag, + 0, /* tid */ + 0 /* rid */); +} + +static void +put_tile(const struct framebuffer *fb, uint tx, uint ty, const uint *tile) +{ + uint offset = ty * fb->width_tiles + tx; + uint bytesPerTile = TILE_SIZE * TILE_SIZE * 4; + ubyte *dst = (ubyte *) fb->start + offset * bytesPerTile; + int tag = DefaultTag; + + assert(tx < fb->width_tiles); + assert(ty < fb->height_tiles); + ASSERT_ALIGN16(tile); + /* + printf("put_tile: src: %p dst: 0x%x size: %d\n", + tile, (unsigned int) dst, bytesPerTile); + */ + mfc_put((void *) tile, /* src in local memory */ + (unsigned int) dst, /* dst in main mory */ + bytesPerTile, + tag, + 0, /* tid */ + 0 /* rid */); +} + + + +static void +clear_tiles(const struct cell_command_clear_tiles *clear) +{ + uint num_tiles = fb.width_tiles * fb.height_tiles; + uint i; + uint tile[TILE_SIZE * TILE_SIZE] ALIGN16; + + for (i = 0; i < TILE_SIZE * TILE_SIZE; i++) + tile[i] = clear->value; + + printf("SPU: %s num=%d w=%d h=%d\n", + __FUNCTION__, num_tiles, fb.width_tiles, fb.height_tiles); + for (i = init.id; i < num_tiles; i += init.num_spus) { + uint tx = i % fb.width_tiles; + uint ty = i / fb.width_tiles; + put_tile(&fb, tx, ty, tile); + /* XXX we don't want this here, but it fixes bad tile results */ + wait_on_mask(1 << DefaultTag); + } +} + + +/** Invert all pixels in all tiles */ +static void +invert_tiles(void) +{ + uint num_tiles = fb.width_tiles * fb.height_tiles; + uint i, j; + uint tile[TILE_SIZE * TILE_SIZE] ALIGN16; + + for (i = init.id; i < num_tiles; i += init.num_spus) { + uint tx = i % fb.width_tiles; + uint ty = i / fb.width_tiles; + + get_tile(&fb, tx, ty, tile); + wait_on_mask(1 << DefaultTag); + + for (j = 0; j < TILE_SIZE * TILE_SIZE; j++) { + tile[j] = ~tile[j]; + } + + put_tile(&fb, tx, ty, tile); + } +} + + +struct cell_command cmd ALIGN16; + + +/** + * Temporary/simple main loop for SPEs: Get a command, execute it, repeat. + */ +static void +main_loop(void) +{ + int exitFlag = 0; + printf("SPU %u: Enter main loop\n", init.id); + + assert((sizeof(struct cell_command) & 0xf) == 0); + ASSERT_ALIGN16(&cmd); + + while (!exitFlag) { + unsigned opcode; + int tag = 0; + + printf("SPU %u: Wait for cmd...\n", init.id); + + /* read/wait from mailbox */ + opcode = (unsigned int) spu_read_in_mbox(); + + printf("SPU %u: got cmd %u\n", init.id, opcode); + + /* command payload */ + mfc_get(&cmd, /* dest */ + (unsigned int) init.cmd, /* src */ + sizeof(struct cell_command), /* bytes */ + tag, + 0, /* tid */ + 0 /* rid */); + wait_on_mask( 1 << tag ); + + switch (opcode) { + case CELL_CMD_EXIT: + printf("SPU %u: EXIT\n", init.id); + exitFlag = 1; + break; + case CELL_CMD_FRAMEBUFFER: + printf("SPU %u: FRAMEBUFFER: %d x %d at %p\n", init.id, + cmd.fb.width, + cmd.fb.height, + cmd.fb.start); + fb.width = cmd.fb.width; + fb.height = cmd.fb.height; + fb.width_tiles = fb.width / TILE_SIZE; + fb.height_tiles = fb.height / TILE_SIZE; + fb.start = cmd.fb.start; + break; + case CELL_CMD_CLEAR_TILES: + printf("SPU %u: CLEAR to 0x%08x\n", init.id, cmd.clear.value); + clear_tiles(&cmd.clear); + break; + case CELL_CMD_INVERT_TILES: + printf("SPU %u: INVERT_TILES\n", init.id); + invert_tiles(); + break; + case CELL_CMD_FINISH: + printf("SPU %u: FINISH\n", init.id); + /* wait for all outstanding DMAs to finish */ + mfc_write_tag_mask(~0); + mfc_read_tag_status_all(); + /* send mbox message to PPU */ + spu_write_out_mbox(CELL_CMD_FINISH); + break; + default: + printf("Bad opcode!\n"); + } + + } + + printf("SPU %u: Exit main loop\n", init.id); +} -static struct init_info init; int @@ -19,11 +245,18 @@ main(unsigned long long speid, { int tag = 0; - mfc_get(&init, (unsigned int) argp, sizeof(struct init_info), tag, 0, 0); + (void) speid; + (void) envp; - printf("Enter spu main(): init.foo=%d\n", init.foo); + mfc_get(&init, /* dest */ + (unsigned int) argp, /* src */ + sizeof(struct cell_init_info), /* bytes */ + tag, + 0, /* tid */ + 0 /* rid */); + wait_on_mask( 1 << tag ); - draw_triangle(0, 1, 2); + main_loop(); return 0; } diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 68f9c39116..ec171e3d9a 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -42,6 +42,52 @@ #include "pipe/p_context.h" #include "pipe/softpipe/sp_winsys.h" +#ifdef GALLIUM_CELL +#include "pipe/cell/ppu/cell_context.h" +#include "pipe/cell/ppu/cell_winsys.h" +#endif + + +/** XXX from Mesa core */ +static void * +align_malloc(size_t bytes, unsigned long alignment) +{ +#if defined(HAVE_POSIX_MEMALIGN) + void *mem; + + (void) posix_memalign(& mem, alignment, bytes); + return mem; +#else + uintptr_t ptr, buf; + + assert( alignment > 0 ); + + ptr = (uintptr_t) malloc(bytes + alignment + sizeof(void *)); + if (!ptr) + return NULL; + + buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1); + *(uintptr_t *)(buf - sizeof(void *)) = ptr; + + return (void *) buf; +#endif /* defined(HAVE_POSIX_MEMALIGN) */ +} + + +/** XXX from Mesa core */ +static void +align_free(void *ptr) +{ +#if defined(HAVE_POSIX_MEMALIGN) + free(ptr); +#else + void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); + void *realAddr = *cubbyHole; + free(realAddr); +#endif /* defined(HAVE_POSIX_MEMALIGN) */ +} + + /** * Low-level OS/window system memory buffer @@ -59,7 +105,8 @@ struct xm_buffer struct xmesa_surface { struct pipe_surface surface; - /* no extra fields for now */ + + int tileSize; }; @@ -138,7 +185,7 @@ xm_buffer_reference(struct pipe_winsys *pws, if (oldBuf->refcount == 0) { if (oldBuf->data) { if (!oldBuf->userBuffer) - free(oldBuf->data); + align_free(oldBuf->data); oldBuf->data = NULL; } free(oldBuf); @@ -163,8 +210,8 @@ xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, assert(!xm_buf->userBuffer); if (xm_buf->size != size) { if (xm_buf->data) - free(xm_buf->data); - xm_buf->data = malloc(size); + align_free(xm_buf->data); + xm_buf->data = align_malloc(size, 16); xm_buf->size = size; } if (data) @@ -198,6 +245,45 @@ xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, /** + * Display a surface that's in a tiled configuration. That is, all the + * pixels for a TILE_SIZExTILE_SIZE block are contiguous in memory. + */ +static void +xmesa_display_surface_tiled(XMesaBuffer b, const struct pipe_surface *surf) +{ + XImage *ximage = b->tempImage; + struct xm_buffer *xm_buf = xm_bo(surf->buffer); + const int TILE_SIZE = 32; + uint x, y; + + /* check that the XImage has been previously initialized */ + assert(ximage->format); + assert(ximage->bitmap_unit); + + /* update XImage's fields */ + ximage->width = TILE_SIZE; + ximage->height = TILE_SIZE; + ximage->bytes_per_line = TILE_SIZE * 4; + + for (y = 0; y < surf->height; y += TILE_SIZE) { + for (x = 0; x < surf->width; x += TILE_SIZE) { + int dx = x; + int dy = y; + int tx = x / TILE_SIZE; + int ty = y / TILE_SIZE; + int offset = ty * (surf->width / TILE_SIZE) + tx; + offset *= 4 * TILE_SIZE * TILE_SIZE; + + ximage->data = (char *) xm_buf->data + offset; + + XPutImage(b->xm_visual->display, b->drawable, b->gc, + ximage, 0, 0, dx, dy, TILE_SIZE, TILE_SIZE); + } + } +} + + +/** * Display/copy the image in the surface into the X window specified * by the XMesaBuffer. */ @@ -206,6 +292,13 @@ xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf) { XImage *ximage = b->tempImage; struct xm_buffer *xm_buf = xm_bo(surf->buffer); + const struct xmesa_surface *xm_surf + = xmesa_surface((struct pipe_surface *) surf); + + if (xm_surf->tileSize) { + xmesa_display_surface_tiled(b, surf); + return; + } /* check that the XImage has been previously initialized */ assert(ximage->format); @@ -234,7 +327,6 @@ xm_flush_frontbuffer(struct pipe_winsys *pws, * this would be the place to copy the Ximage to the on-screen Window. */ XMesaContext xmctx = (XMesaContext) context_private; - xmesa_display_surface(xmctx->xm_buffer, surf); } @@ -318,6 +410,12 @@ xm_surface_alloc(struct pipe_winsys *ws, enum pipe_format pipeFormat) xms->surface.refcount = 1; xms->surface.winsys = ws; +#ifdef GALLIUM_CELL + if (getenv("GALLIUM_CELL")) { + xms->tileSize = 32; /** probably temporary */ + } +#endif + return &xms->surface; } @@ -413,12 +511,24 @@ struct pipe_context * xmesa_create_pipe_context(XMesaContext xmesa, uint pixelformat) { struct pipe_winsys *pws = xmesa_get_pipe_winsys(); - struct softpipe_winsys *spws = xmesa_get_softpipe_winsys(pixelformat); struct pipe_context *pipe; - pipe = softpipe_create( pws, spws ); - if (pipe) - pipe->priv = xmesa; - - return pipe; +#ifdef GALLIUM_CELL + if (getenv("GALLIUM_CELL")) { + struct cell_winsys *cws = cell_get_winsys(pixelformat); + pipe = cell_create_context(pws, cws); + if (pipe) + pipe->priv = xmesa; + return pipe; + } + else +#endif + { + struct softpipe_winsys *spws = xmesa_get_softpipe_winsys(pixelformat); + pipe = softpipe_create( pws, spws ); + if (pipe) + pipe->priv = xmesa; + + return pipe; + } } |