diff options
author | Ben Skeggs <skeggsb@gmail.com> | 2008-01-16 13:14:19 +1100 |
---|---|---|
committer | Ben Skeggs <skeggsb@gmail.com> | 2008-01-16 13:14:19 +1100 |
commit | 3119e9a14b66fcfb08fcc3563602273dd2e1893c (patch) | |
tree | 74ff685faec3430b66d70522b6ed717f57e54f00 | |
parent | 9de335f5807553bc9251931ba3e80c4b454b5818 (diff) | |
parent | 587e2becc237bc1c900a1c0ba114a1a0192690ff (diff) |
Merge branch 'upstream-gallium-0.1' into darktama-gallium-0.1
Conflicts:
src/mesa/pipe/Makefile
94 files changed, 3636 insertions, 2592 deletions
diff --git a/configs/linux-cell b/configs/linux-cell index 3ac49b3659..2551530f31 100644 --- a/configs/linux-cell +++ b/configs/linux-cell @@ -33,7 +33,7 @@ GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread \ SPU_CC = /usr/bin/spu-gcc -SPU_CFLAGS = -g -W -Wall -Winline -Wno-main -I. -I $(SDK)/spu/include -include spu_intrinsics.h -I $(TOP)/src/mesa/ +SPU_CFLAGS = -g -W -Wall -Winline -Wmissing-prototypes -Wno-main -I. -I $(SDK)/spu/include -include spu_intrinsics.h -I $(TOP)/src/mesa/ SPU_LFLAGS = -L$(SDK)/spu/lib -Wl,-N -lmisc diff --git a/configs/linux-llvm b/configs/linux-llvm index 6d1f31daa2..915189f462 100644 --- a/configs/linux-llvm +++ b/configs/linux-llvm @@ -1,3 +1,4 @@ +# -*-makefile-*- # Configuration for Linux and LLVM with debugging info include $(TOP)/configs/linux @@ -5,7 +6,7 @@ include $(TOP)/configs/linux CONFIG_NAME = linux-llvm OPT_FLAGS = -g -ansi -pedantic -DEFINES += -DDEBUG -DDEBUG_MATH +DEFINES += -DDEBUG -DDEBUG_MATH -DMESA_LLVM=1 LLVM_VERSION := $(shell llvm-config --version) @@ -18,9 +19,8 @@ else endif ifeq ($(MESA_LLVM),1) -# LLVM_CFLAGS=`llvm-config --cflags` -DMESA_LLVM=1 - LLVM_CFLAGS=-DMESA_LLVM=1 - LLVM_CXXFLAGS=`llvm-config --cxxflags` -DMESA_LLVM=1 -Wno-long-long +# LLVM_CFLAGS=`llvm-config --cflags` + LLVM_CXXFLAGS=`llvm-config --cxxflags` -Wno-long-long LLVM_LDFLAGS=`llvm-config --ldflags` LLVM_LIBS=`llvm-config --libs` MKLIB_OPTIONS=-cplusplus diff --git a/src/mesa/Makefile b/src/mesa/Makefile index dd8e2c3762..681c566140 100644 --- a/src/mesa/Makefile +++ b/src/mesa/Makefile @@ -20,14 +20,17 @@ CELL_LIB = $(TOP)/src/mesa/pipe/cell/ppu/libcell.a CELL_LIB_SPU = $(TOP)/src/mesa/pipe/cell/spu/g3d_spu.a endif +ifeq ($(CONFIG_NAME), linux-llvm) +LLVM_LIB = $(TOP)/src/mesa/pipe/llvm/libgallivm.a +endif .SUFFIXES : .cpp .c.o: - $(CC) -c $(LLVM_CFLAGS) $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ .cpp.o: - $(CXX) -c $(LLVM_CXXFLAGS) $(INCLUDE_DIRS) $(CXXFLAGS) $< -o $@ + $(CXX) -c $(INCLUDE_DIRS) $(CXXFLAGS) $< -o $@ .S.o: $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ @@ -120,12 +123,12 @@ stand-alone: depend subdirs $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$ osmesa-only: depend subdirs $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_NAME) # Make the GL library -$(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(STAND_ALONE_OBJECTS) $(PIPE_LIB) $(CELL_LIB) $(CELL_LIB_SPU) +$(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(STAND_ALONE_OBJECTS) $(PIPE_LIB) $(CELL_LIB) $(CELL_LIB_SPU) $(LLVM_LIB) @ $(TOP)/bin/mklib -o $(GL_LIB) \ -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \ -install $(TOP)/$(LIB_DIR) \ $(MKLIB_OPTIONS) $(STAND_ALONE_OBJECTS) \ - $(PIPE_LIB) $(CELL_LIB) $(CELL_LIB_SPU) $(GL_LIB_DEPS) + $(PIPE_LIB) $(CELL_LIB) $(CELL_LIB_SPU) $(LLVM_LIB) $(GL_LIB_DEPS) # Make the OSMesa library $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_NAME): $(OSMESA_DRIVER_OBJECTS) $(OSMESA16_OBJECTS) diff --git a/src/mesa/pipe/Makefile b/src/mesa/pipe/Makefile index fbd36d95f7..6012b2bcea 100644 --- a/src/mesa/pipe/Makefile +++ b/src/mesa/pipe/Makefile @@ -6,8 +6,12 @@ ifeq ($(CONFIG_NAME), linux-cell) CELL_DIR = cell endif -SUBDIRS = softpipe i915simple i965simple nv40 nv50 failover \ - pipebuffer $(CELL_DIR) +ifeq ($(CONFIG_NAME), linux-llvm) +LLVM_DIR = llvm +endif + +SUBDIRS = softpipe i915simple i965simple nv40 nv50 failover pipebuffer \ + $(CELL_DIR) $(LLVM_DIR) default: subdirs diff --git a/src/mesa/pipe/Makefile.template b/src/mesa/pipe/Makefile.template index 8c2f84b328..3cd07660b6 100644 --- a/src/mesa/pipe/Makefile.template +++ b/src/mesa/pipe/Makefile.template @@ -8,6 +8,7 @@ COMMON_SOURCES = OBJECTS = $(C_SOURCES:.c=.o) \ + $(CPP_SOURCES:.cpp=.o) \ $(ASM_SOURCES:.S=.o) @@ -22,7 +23,10 @@ INCLUDES = \ ##### RULES ##### .c.o: - $(CC) -c $(INCLUDES) $(LLVM_CFLAGS) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.cpp.o: + $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DRIVER_DEFINES) $< -o $@ .S.o: $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ @@ -37,10 +41,10 @@ $(LIBNAME): $(OBJECTS) Makefile $(TOP)/src/mesa/pipe/Makefile.template $(TOP)/bin/mklib -o $@ -static $(OBJECTS) -depend: $(C_SOURCES) $(ASM_SOURCES) $(SYMLINKS) +depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) rm -f depend touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) \ + $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) \ $(ASM_SOURCES) 2> /dev/null diff --git a/src/mesa/pipe/cell/common.h b/src/mesa/pipe/cell/common.h index f7f1e2eb41..29d1cbedda 100644 --- a/src/mesa/pipe/cell/common.h +++ b/src/mesa/pipe/cell/common.h @@ -35,6 +35,7 @@ #include "pipe/p_compiler.h" #include "pipe/p_util.h" +#include "pipe/p_format.h" /** for sanity checking */ @@ -46,11 +47,25 @@ #define TILE_SIZE 32 -#define CELL_CMD_EXIT 1 -#define CELL_CMD_FRAMEBUFFER 2 -#define CELL_CMD_CLEAR_TILES 3 -#define CELL_CMD_TRIANGLE 4 -#define CELL_CMD_FINISH 5 +/** + * The low byte of a mailbox word contains the command opcode. + * Remaining higher bytes are command specific. + */ +#define CELL_CMD_OPCODE_MASK 0xf + +#define CELL_CMD_EXIT 1 +#define CELL_CMD_FRAMEBUFFER 2 +#define CELL_CMD_CLEAR_SURFACE 3 +#define CELL_CMD_FINISH 4 +#define CELL_CMD_RENDER 5 +#define CELL_CMD_BATCH 6 +#define CELL_CMD_STATE_DEPTH_STENCIL 7 + + +#define CELL_NUM_BATCH_BUFFERS 2 +#define CELL_BATCH_BUFFER_SIZE 1024 /**< 16KB would be the max */ + +#define CELL_BATCH_FINISHED 0x1234 /**< mbox message */ /** @@ -58,25 +73,36 @@ */ struct cell_command_framebuffer { - void *start; + uint opcode; int width, height; - unsigned format; + void *color_start, *depth_start; + enum pipe_format color_format, depth_format; } ALIGN16_ATTRIB; /** - * Clear framebuffer tiles to given value/color. + * Clear framebuffer to the given value/color. */ -struct cell_command_clear_tiles +struct cell_command_clear_surface { + uint opcode; + uint surface; /**< Temporary: 0=color, 1=Z */ uint value; } ALIGN16_ATTRIB; -struct cell_command_triangle +#define CELL_MAX_VBUF_SIZE (16 * 1024) +#define CELL_MAX_VBUF_INDEXES 1024 +#define CELL_MAX_ATTRIBS 2 /* temporary! */ +struct cell_command_render { - float vert[3][4]; - float color[3][4]; + uint opcode; + uint prim_type; + uint num_verts, num_attribs; + uint num_indexes; + const void *vertex_data; + const ushort *index_data; + float xmin, ymin, xmax, ymax; } ALIGN16_ATTRIB; @@ -84,8 +110,8 @@ struct cell_command_triangle struct cell_command { struct cell_command_framebuffer fb; - struct cell_command_clear_tiles clear; - struct cell_command_triangle tri; + struct cell_command_clear_surface clear; + struct cell_command_render render; } ALIGN16_ATTRIB; @@ -95,9 +121,8 @@ struct cell_init_info unsigned id; unsigned num_spus; struct cell_command *cmd; + ubyte *batch_buffers[CELL_NUM_BATCH_BUFFERS]; } ALIGN16_ATTRIB; - - #endif /* CELL_COMMON_H */ diff --git a/src/mesa/pipe/cell/ppu/Makefile b/src/mesa/pipe/cell/ppu/Makefile index 2758e1b77f..6a1bd5982f 100644 --- a/src/mesa/pipe/cell/ppu/Makefile +++ b/src/mesa/pipe/cell/ppu/Makefile @@ -16,13 +16,14 @@ SPU_CODE_MODULE = ../spu/g3d_spu.a SOURCES = \ + cell_batch.c \ cell_context.c \ cell_draw_arrays.c \ cell_flush.c \ - cell_render.c \ cell_state_blend.c \ cell_state_clip.c \ cell_state_derived.c \ + cell_state_emit.c \ cell_state_fs.c \ cell_state_rasterizer.c \ cell_state_sampler.c \ @@ -30,6 +31,7 @@ SOURCES = \ cell_state_vertex.c \ cell_spu.c \ cell_surface.c \ + cell_vbuf.c \ cell_winsys.c diff --git a/src/mesa/pipe/cell/ppu/cell_batch.c b/src/mesa/pipe/cell/ppu/cell_batch.c new file mode 100644 index 0000000000..45f62ac3ad --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_batch.c @@ -0,0 +1,122 @@ +/************************************************************************** + * + * 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 "cell_context.h" +#include "cell_batch.h" +#include "cell_spu.h" + + +void +cell_batch_flush(struct cell_context *cell) +{ + const uint batch = cell->cur_batch; + const uint size = cell->batch_buffer_size[batch]; + uint i, cmd_word; + + if (size == 0) + return; + + assert(batch < CELL_NUM_BATCH_BUFFERS); + + /* + printf("cell_batch_dispatch: buf %u at %p, size %u\n", + batch, &cell->batch_buffer[batch][0], size); + */ + + cmd_word = CELL_CMD_BATCH | (batch << 8) | (size << 16); + + for (i = 0; i < cell->num_spus; i++) { + send_mbox_message(cell_global.spe_contexts[i], cmd_word); + } + + /* XXX wait for the DMX xfer to finish. + * Using mailboxes here is temporary. + * Ideally, we want to use a PPE-side DMA status check function... + */ + for (i = 0; i < cell->num_spus; i++) { + uint k = wait_mbox_message(cell_global.spe_contexts[i]); + assert(k == CELL_BATCH_FINISHED); + } + + /* next buffer */ + cell->cur_batch = (batch + 1) % CELL_NUM_BATCH_BUFFERS; + + cell->batch_buffer_size[cell->cur_batch] = 0; /* empty */ +} + + +/** + * \param cmd command to append + * \param length command size in bytes + */ +void +cell_batch_append(struct cell_context *cell, const void *cmd, uint length) +{ + uint size; + + assert(length % 4 == 0); + assert(cell->cur_batch >= 0); + + size = cell->batch_buffer_size[cell->cur_batch]; + + if (size + length > CELL_BATCH_BUFFER_SIZE) { + cell_batch_flush(cell); + size = 0; + } + + assert(size + length <= CELL_BATCH_BUFFER_SIZE); + + memcpy(cell->batch_buffer[cell->cur_batch] + size, cmd, length); + + cell->batch_buffer_size[cell->cur_batch] = size + length; +} + + +void * +cell_batch_alloc(struct cell_context *cell, uint bytes) +{ + void *pos; + uint size; + + assert(cell->cur_batch >= 0); + + size = cell->batch_buffer_size[cell->cur_batch]; + + if (size + bytes > CELL_BATCH_BUFFER_SIZE) { + cell_batch_flush(cell); + size = 0; + } + + assert(size + bytes <= CELL_BATCH_BUFFER_SIZE); + + pos = (void *) (cell->batch_buffer[cell->cur_batch] + size); + + cell->batch_buffer_size[cell->cur_batch] = size + bytes; + + return pos; +} diff --git a/src/mesa/pipe/cell/spu/tri.h b/src/mesa/pipe/cell/ppu/cell_batch.h index dc66ad0f47..7a5c6392d7 100644 --- a/src/mesa/pipe/cell/spu/tri.h +++ b/src/mesa/pipe/cell/ppu/cell_batch.h @@ -26,27 +26,21 @@ **************************************************************************/ -#ifndef TRI_H -#define TRI_H +#ifndef CELL_BATCH_H +#define CELL_BATCH_H -/** - * Simplified types taken from other parts of Gallium - */ +struct cell_context; -struct vertex_header { - float data[2][4]; /* pos and color */ -}; - - -struct prim_header { - struct vertex_header v[3]; - uint color; -}; +extern void +cell_batch_flush(struct cell_context *cell); extern void -draw_triangle(struct prim_header *tri, uint tx, uint ty); +cell_batch_append(struct cell_context *cell, const void *cmd, uint length); + +extern void * +cell_batch_alloc(struct cell_context *cell, uint bytes); -#endif /* TRI_H */ +#endif /* CELL_BATCH_H */ diff --git a/src/mesa/pipe/cell/ppu/cell_context.c b/src/mesa/pipe/cell/ppu/cell_context.c index 82b69ac33e..6ba3b0d413 100644 --- a/src/mesa/pipe/cell/ppu/cell_context.c +++ b/src/mesa/pipe/cell/ppu/cell_context.c @@ -46,6 +46,7 @@ #include "cell_state.h" #include "cell_surface.h" #include "cell_spu.h" +#include "cell_vbuf.h" @@ -148,9 +149,8 @@ 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); + align_free(cell); } @@ -160,11 +160,15 @@ struct pipe_context * cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws) { struct cell_context *cell; + uint i; - cell = CALLOC_STRUCT(cell_context); + /* some fields need to be 16-byte aligned, so align the whole object */ + cell = (struct cell_context*) align_malloc(sizeof(struct cell_context), 16); if (!cell) return NULL; + memset(cell, 0, sizeof(*cell)); + cell->winsys = cws; cell->pipe.winsys = winsys; cell->pipe.destroy = cell_destroy_context; @@ -234,20 +238,22 @@ cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws) cell->draw = draw_create(); - cell->render_stage = cell_draw_render_stage(cell); - draw_set_rasterize_stage(cell->draw, cell->render_stage); - + cell_init_vbuf(cell); + draw_set_rasterize_stage(cell->draw, cell->vbuf); /* * SPU stuff */ - cell->num_spus = 6; /* XXX >6 seems to fail */ + cell->num_spus = 6; - cell_start_spus(cell->num_spus); + cell_start_spus(cell); + + for (i = 0; i < CELL_NUM_BATCH_BUFFERS; i++) { + cell->batch_buffer_size[i] = 0; + } #if 0 test_spus(cell); - wait_spus(); #endif return &cell->pipe; diff --git a/src/mesa/pipe/cell/ppu/cell_context.h b/src/mesa/pipe/cell/ppu/cell_context.h index 5f6f987d8f..43e32a8abb 100644 --- a/src/mesa/pipe/cell/ppu/cell_context.h +++ b/src/mesa/pipe/cell/ppu/cell_context.h @@ -33,9 +33,13 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/draw/draw_vertex.h" +#include "pipe/draw/draw_vbuf.h" #include "cell_winsys.h" +#include "pipe/cell/common.h" +struct cell_vbuf_render; + struct cell_vertex_shader_state { struct pipe_shader_state shader; @@ -74,12 +78,17 @@ struct cell_context struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; + ubyte *cbuf_map[PIPE_MAX_COLOR_BUFS]; + ubyte *zbuf_map; uint dirty; /** The primitive drawing context */ struct draw_context *draw; struct draw_stage *render_stage; + + /** For post-transformed vertex buffering: */ + struct cell_vbuf_render *vbuf_render; struct draw_stage *vbuf; struct vertex_info vertex_info; @@ -89,7 +98,10 @@ struct cell_context uint num_spus; - + + ubyte batch_buffer_size[CELL_NUM_BATCH_BUFFERS]; + ubyte batch_buffer[CELL_NUM_BATCH_BUFFERS][CELL_BATCH_BUFFER_SIZE] ALIGN16_ATTRIB; + int cur_batch; /**< which batch buffer is being filled */ }; diff --git a/src/mesa/pipe/cell/ppu/cell_draw_arrays.c b/src/mesa/pipe/cell/ppu/cell_draw_arrays.c index c014f5b29d..537cec8785 100644 --- a/src/mesa/pipe/cell/ppu/cell_draw_arrays.c +++ b/src/mesa/pipe/cell/ppu/cell_draw_arrays.c @@ -121,18 +121,17 @@ cell_draw_elements(struct pipe_context *pipe, */ for (i = 0; i < PIPE_ATTRIB_MAX; i++) { if (sp->vertex_buffer[i].buffer) { - void *buf - = pipe->winsys->buffer_map(pipe->winsys, - sp->vertex_buffer[i].buffer, - PIPE_BUFFER_FLAG_READ); + void *buf = pipe->winsys->buffer_map(pipe->winsys, + sp->vertex_buffer[i].buffer, + PIPE_BUFFER_FLAG_READ); draw_set_mapped_vertex_buffer(draw, i, buf); } } /* Map index buffer, if present */ if (indexBuffer) { - void *mapped_indexes - = pipe->winsys->buffer_map(pipe->winsys, indexBuffer, - PIPE_BUFFER_FLAG_READ); + void *mapped_indexes = pipe->winsys->buffer_map(pipe->winsys, + indexBuffer, + PIPE_BUFFER_FLAG_READ); draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes); } else { @@ -161,7 +160,6 @@ cell_draw_elements(struct pipe_context *pipe, draw_set_mapped_element_buffer(draw, 0, NULL); } - /* Note: leave drawing surfaces mapped */ cell_unmap_constant_buffers(sp); diff --git a/src/mesa/pipe/cell/ppu/cell_flush.c b/src/mesa/pipe/cell/ppu/cell_flush.c index b1ff0e51cd..33cbe2a085 100644 --- a/src/mesa/pipe/cell/ppu/cell_flush.c +++ b/src/mesa/pipe/cell/ppu/cell_flush.c @@ -29,6 +29,7 @@ #include "cell_context.h" #include "cell_flush.h" #include "cell_spu.h" +#include "cell_render.h" void @@ -37,16 +38,25 @@ cell_flush(struct pipe_context *pipe, unsigned flags) struct cell_context *cell = cell_context(pipe); uint i; - printf("%s\n", __FUNCTION__); + if (flags & PIPE_FLUSH_WAIT) { + uint *cmd = (uint *) cell_batch_alloc(cell, sizeof(uint)); + *cmd = CELL_CMD_FINISH; + } + + cell_batch_flush(cell); +#if 0 /* Send CMD_FINISH to all SPUs */ for (i = 0; i < cell->num_spus; i++) { send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FINISH); } +#endif - /* Wait for ack */ - for (i = 0; i < cell->num_spus; i++) { - uint k = wait_mbox_message(cell_global.spe_contexts[i]); - assert(k == CELL_CMD_FINISH); + if (flags & PIPE_FLUSH_WAIT) { + /* Wait for ack */ + for (i = 0; i < cell->num_spus; i++) { + uint k = wait_mbox_message(cell_global.spe_contexts[i]); + assert(k == CELL_CMD_FINISH); + } } } diff --git a/src/mesa/pipe/cell/ppu/cell_render.c b/src/mesa/pipe/cell/ppu/cell_render.c index c7f0cf6be6..ecdd47e28b 100644 --- a/src/mesa/pipe/cell/ppu/cell_render.c +++ b/src/mesa/pipe/cell/ppu/cell_render.c @@ -32,6 +32,7 @@ #include "cell_context.h" #include "cell_render.h" +#include "cell_spu.h" #include "pipe/p_util.h" #include "pipe/draw/draw_private.h" @@ -89,13 +90,93 @@ render_line(struct draw_stage *stage, struct prim_header *prim) } +/** Write a vertex into the prim buffer */ +static void +save_vertex(struct cell_prim_buffer *buf, uint pos, + const struct vertex_header *vert) +{ + uint attr, j; + + for (attr = 0; attr < 2; attr++) { + for (j = 0; j < 4; j++) { + buf->vertex[pos][attr][j] = vert->data[attr][j]; + } + } + + /* update bounding box */ + if (vert->data[0][0] < buf->xmin) + buf->xmin = vert->data[0][0]; + if (vert->data[0][0] > buf->xmax) + buf->xmax = vert->data[0][0]; + if (vert->data[0][1] < buf->ymin) + buf->ymin = vert->data[0][1]; + if (vert->data[0][1] > buf->ymax) + buf->ymax = vert->data[0][1]; +} + + static void render_tri(struct draw_stage *stage, struct prim_header *prim) { - printf("Cell render tri\n"); + struct render_stage *rs = render_stage(stage); + struct cell_context *cell = rs->cell; + struct cell_prim_buffer *buf = &cell->prim_buffer; + uint i; + + if (buf->num_verts + 3 > CELL_MAX_VERTS) { + cell_flush_prim_buffer(cell); + } + + i = buf->num_verts; + assert(i+2 <= CELL_MAX_VERTS); + save_vertex(buf, i+0, prim->v[0]); + save_vertex(buf, i+1, prim->v[1]); + save_vertex(buf, i+2, prim->v[2]); + buf->num_verts += 3; +} + + +/** + * Send the a RENDER command to all SPUs to have them render the prims + * in the current prim_buffer. + */ +void +cell_flush_prim_buffer(struct cell_context *cell) +{ + uint i; + + if (cell->prim_buffer.num_verts == 0) + return; + + for (i = 0; i < cell->num_spus; i++) { + struct cell_command_render *render = &cell_global.command[i].render; + render->prim_type = PIPE_PRIM_TRIANGLES; + render->num_verts = cell->prim_buffer.num_verts; + render->num_attribs = CELL_MAX_ATTRIBS; + render->xmin = cell->prim_buffer.xmin; + render->ymin = cell->prim_buffer.ymin; + render->xmax = cell->prim_buffer.xmax; + render->ymax = cell->prim_buffer.ymax; + render->vertex_data = &cell->prim_buffer.vertex; + ASSERT_ALIGN16(render->vertex_data); + send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_RENDER); + } + + cell->prim_buffer.num_verts = 0; + + cell->prim_buffer.xmin = 1e100; + cell->prim_buffer.ymin = 1e100; + cell->prim_buffer.xmax = -1e100; + cell->prim_buffer.ymax = -1e100; + + /* XXX temporary, need to double-buffer the prim buffer until we get + * a real command buffer/list system. + */ + cell_flush(&cell->pipe, 0x0); } + static void render_destroy( struct draw_stage *stage ) { FREE( stage ); diff --git a/src/mesa/pipe/cell/ppu/cell_render.h b/src/mesa/pipe/cell/ppu/cell_render.h index d66e1bdb79..826dcbafeb 100644 --- a/src/mesa/pipe/cell/ppu/cell_render.h +++ b/src/mesa/pipe/cell/ppu/cell_render.h @@ -31,6 +31,9 @@ struct cell_context; struct draw_stage; +extern void +cell_flush_prim_buffer(struct cell_context *cell); + extern struct draw_stage *cell_draw_render_stage( struct cell_context *cell ); #endif /* CELL_RENDER_H */ diff --git a/src/mesa/pipe/cell/ppu/cell_spu.c b/src/mesa/pipe/cell/ppu/cell_spu.c index 55a0d5038b..77ddd9ccbf 100644 --- a/src/mesa/pipe/cell/ppu/cell_spu.c +++ b/src/mesa/pipe/cell/ppu/cell_spu.c @@ -95,11 +95,11 @@ static void *cell_thread_function(void *arg) * Create the SPU threads */ void -cell_start_spus(uint num_spus) +cell_start_spus(struct cell_context *cell) { - uint i; + uint i, j; - assert(num_spus <= MAX_SPUS); + assert(cell->num_spus <= MAX_SPUS); ASSERT_ALIGN16(&cell_global.command[0]); ASSERT_ALIGN16(&cell_global.command[1]); @@ -107,10 +107,13 @@ cell_start_spus(uint num_spus) ASSERT_ALIGN16(&cell_global.inits[0]); ASSERT_ALIGN16(&cell_global.inits[1]); - for (i = 0; i < num_spus; i++) { + for (i = 0; i < cell->num_spus; i++) { cell_global.inits[i].id = i; - cell_global.inits[i].num_spus = num_spus; + cell_global.inits[i].num_spus = cell->num_spus; cell_global.inits[i].cmd = &cell_global.command[i]; + for (j = 0; j < CELL_NUM_BATCH_BUFFERS; j++) { + cell_global.inits[i].batch_buffers[j] = cell->batch_buffer[j]; + } cell_global.spe_contexts[i] = spe_context_create(0, NULL); if (!cell_global.spe_contexts[i]) { @@ -158,28 +161,32 @@ void test_spus(struct cell_context *cell) { uint i; - struct pipe_surface *surf = cell->framebuffer.cbufs[0]; + struct pipe_surface *csurf = cell->framebuffer.cbufs[0]; + struct pipe_surface *zsurf = cell->framebuffer.zbuf; printf("PPU: sleep(2)\n\n\n"); sleep(2); for (i = 0; i < cell->num_spus; i++) { - cell_global.command[i].fb.start = surf->map; - cell_global.command[i].fb.width = surf->width; - cell_global.command[i].fb.height = surf->height; - cell_global.command[i].fb.format = PIPE_FORMAT_A8R8G8B8_UNORM; + cell_global.command[i].fb.color_start = cell->cbuf_map[0]; + cell_global.command[i].fb.depth_start = cell->zbuf_map; + cell_global.command[i].fb.width = csurf->width; + cell_global.command[i].fb.height = csurf->height; + cell_global.command[i].fb.color_format = PIPE_FORMAT_A8R8G8B8_UNORM; + cell_global.command[i].fb.depth_format = PIPE_FORMAT_Z32_UNORM; send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FRAMEBUFFER); } for (i = 0; i < cell->num_spus; i++) { cell_global.command[i].clear.value = 0xff880044; /* XXX */ - send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_CLEAR_TILES); + cell_global.command[i].clear.surface = 0; + send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_CLEAR_SURFACE); } finish_all(cell->num_spus); { - uint *b = (uint*) surf->map; + uint *b = (uint*) cell->cbuf_map[0]; printf("PPU: Clear results: 0x%x 0x%x 0x%x 0x%x\n", b[0], b[1000], b[2000], b[3000]); } @@ -191,31 +198,22 @@ test_spus(struct cell_context *cell) /** - * Wait for all SPUs to exit/return. - */ -void -wait_spus(uint num_spus) -{ - uint i; - void *value; - - for (i = 0; i < num_spus; i++) { - pthread_join(cell_global.spe_threads[i], &value); - } -} - - -/** * Tell all the SPUs to stop/exit. */ void cell_spu_exit(struct cell_context *cell) { - unsigned i; + uint i; for (i = 0; i < cell->num_spus; i++) { send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_EXIT); } - wait_spus(cell->num_spus); + /* wait for threads to exit */ + for (i = 0; i < cell->num_spus; i++) { + void *value; + pthread_join(cell_global.spe_threads[i], &value); + cell_global.spe_threads[i] = 0; + cell_global.spe_contexts[i] = 0; + } } diff --git a/src/mesa/pipe/cell/ppu/cell_spu.h b/src/mesa/pipe/cell/ppu/cell_spu.h index 612cb45c59..b4bfbced80 100644 --- a/src/mesa/pipe/cell/ppu/cell_spu.h +++ b/src/mesa/pipe/cell/ppu/cell_spu.h @@ -71,21 +71,18 @@ extern uint wait_mbox_message(spe_context_ptr_t ctx); -void -cell_start_spus(uint num_spus); +extern void +cell_start_spus(struct cell_context *cell); -void +extern void finish_all(uint num_spus); -void +extern void test_spus(struct cell_context *cell); -void -wait_spus(uint num_spus); - -void +extern void cell_spu_exit(struct cell_context *cell); diff --git a/src/mesa/pipe/cell/ppu/cell_state_blend.c b/src/mesa/pipe/cell/ppu/cell_state_blend.c index da3fcfd3a5..34ae0128ea 100644 --- a/src/mesa/pipe/cell/ppu/cell_state_blend.c +++ b/src/mesa/pipe/cell/ppu/cell_state_blend.c @@ -32,17 +32,20 @@ #include "cell_context.h" #include "cell_state.h" + + void * cell_create_blend_state(struct pipe_context *pipe, - const struct pipe_blend_state *blend) + const struct pipe_blend_state *blend) { - struct pipe_blend_state *state = MALLOC( sizeof(struct pipe_blend_state) ); + 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 ) + +void +cell_bind_blend_state(struct pipe_context *pipe, void *blend) { struct cell_context *cell = cell_context(pipe); @@ -51,15 +54,17 @@ void cell_bind_blend_state( struct pipe_context *pipe, cell->dirty |= CELL_NEW_BLEND; } -void cell_delete_blend_state(struct pipe_context *pipe, - void *blend) + +void +cell_delete_blend_state(struct pipe_context *pipe, void *blend) { - FREE( blend ); + FREE(blend); } -void cell_set_blend_color( struct pipe_context *pipe, - const struct pipe_blend_color *blend_color ) +void +cell_set_blend_color(struct pipe_context *pipe, + const struct pipe_blend_color *blend_color) { struct cell_context *cell = cell_context(pipe); @@ -70,29 +75,33 @@ void cell_set_blend_color( struct pipe_context *pipe, + void * cell_create_depth_stencil_alpha_state(struct pipe_context *pipe, - const struct pipe_depth_stencil_alpha_state *depth_stencil) + const struct pipe_depth_stencil_alpha_state *depth_stencil) { struct pipe_depth_stencil_alpha_state *state = - MALLOC( sizeof(struct pipe_depth_stencil_alpha_state) ); + MALLOC(sizeof(struct pipe_depth_stencil_alpha_state)); memcpy(state, depth_stencil, sizeof(struct pipe_depth_stencil_alpha_state)); return state; } + void cell_bind_depth_stencil_alpha_state(struct pipe_context *pipe, void *depth_stencil) { struct cell_context *cell = cell_context(pipe); - cell->depth_stencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil; + cell->depth_stencil + = (const struct pipe_depth_stencil_alpha_state *) depth_stencil; cell->dirty |= CELL_NEW_DEPTH_STENCIL; } + void cell_delete_depth_stencil_alpha_state(struct pipe_context *pipe, void *depth) { - FREE( depth ); + FREE(depth); } diff --git a/src/mesa/pipe/cell/ppu/cell_state_derived.c b/src/mesa/pipe/cell/ppu/cell_state_derived.c index ee7c0204b8..c654990325 100644 --- a/src/mesa/pipe/cell/ppu/cell_state_derived.c +++ b/src/mesa/pipe/cell/ppu/cell_state_derived.c @@ -159,7 +159,8 @@ static void calculate_vertex_layout( struct cell_context *cell ) if (1/*vinfo->attr_mask != cell->attr_mask*/) { /*cell->attr_mask = vinfo->attr_mask;*/ - draw_set_vertex_info( cell->draw, vinfo); + draw_compute_vertex_size(vinfo); + draw_set_vertex_info(cell->draw, vinfo); #if 0 draw_set_twoside_attributes(cell->draw, @@ -218,5 +219,7 @@ void cell_update_derived( struct cell_context *cell ) compute_cliprect(cell); #endif + //cell_emit_state(cell); + cell->dirty = 0; } diff --git a/src/mesa/pipe/cell/spu/main.h b/src/mesa/pipe/cell/ppu/cell_state_emit.c index 8c2796387f..e1a1458f39 100644 --- a/src/mesa/pipe/cell/spu/main.h +++ b/src/mesa/pipe/cell/ppu/cell_state_emit.c @@ -25,37 +25,21 @@ * **************************************************************************/ -#ifndef MAIN_H -#define MAIN_H +#include "pipe/p_util.h" +#include "cell_context.h" +#include "cell_state.h" +#include "cell_state_emit.h" +#include "cell_batch.h" -#include <libmisc.h> -#include <spu_mfcio.h> -#include "pipe/cell/common.h" - - -extern volatile struct cell_init_info init; - -struct framebuffer { - void *start; - uint width, height; - uint width_tiles, height_tiles; /**< width and height in tiles */ -}; - -extern struct framebuffer fb; - - -extern int DefaultTag; - void -wait_on_mask(unsigned tag); - -void -get_tile(const struct framebuffer *fb, uint tx, uint ty, uint *tile); - -void -put_tile(const struct framebuffer *fb, uint tx, uint ty, const uint *tile); - - -#endif /* MAIN_H */ +cell_emit_state(struct cell_context *cell) +{ + if (cell->dirty & CELL_NEW_DEPTH_STENCIL) { + uint cmd = CELL_CMD_STATE_DEPTH_STENCIL; + cell_batch_append(cell, &cmd, 4); + cell_batch_append(cell, cell->depth_stencil, + sizeof(struct pipe_depth_stencil_alpha_state)); + } +} diff --git a/src/mesa/pipe/cell/ppu/cell_state_emit.h b/src/mesa/pipe/cell/ppu/cell_state_emit.h new file mode 100644 index 0000000000..59f8affe8d --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_state_emit.h @@ -0,0 +1,36 @@ +/************************************************************************** + * + * 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_STATE_EMIT_H +#define CELL_STATE_EMIT_H + + +extern void +cell_emit_state(struct cell_context *cell); + + +#endif /* CELL_STATE_EMIT_H */ diff --git a/src/mesa/pipe/cell/ppu/cell_state_rasterizer.c b/src/mesa/pipe/cell/ppu/cell_state_rasterizer.c index 11e7de7309..d8128ece54 100644 --- a/src/mesa/pipe/cell/ppu/cell_state_rasterizer.c +++ b/src/mesa/pipe/cell/ppu/cell_state_rasterizer.c @@ -32,12 +32,54 @@ #include "cell_state.h" + +struct spu_rasterizer_state +{ + unsigned flatshade:1; +#if 0 + unsigned light_twoside:1; + unsigned front_winding:2; /**< PIPE_WINDING_x */ + unsigned cull_mode:2; /**< PIPE_WINDING_x */ + unsigned fill_cw:2; /**< PIPE_POLYGON_MODE_x */ + unsigned fill_ccw:2; /**< PIPE_POLYGON_MODE_x */ + unsigned offset_cw:1; + unsigned offset_ccw:1; +#endif + unsigned scissor:1; + unsigned poly_smooth:1; + unsigned poly_stipple_enable:1; + unsigned point_smooth:1; +#if 0 + unsigned point_sprite:1; + unsigned point_size_per_vertex:1; /**< size computed in vertex shader */ +#endif + unsigned multisample:1; /* XXX maybe more ms state in future */ + unsigned line_smooth:1; + unsigned line_stipple_enable:1; + unsigned line_stipple_factor:8; /**< [1..256] actually */ + unsigned line_stipple_pattern:16; +#if 0 + unsigned bypass_clipping:1; +#endif + unsigned origin_lower_left:1; /**< Is (0,0) the lower-left corner? */ + + float line_width; + float point_size; /**< used when no per-vertex size */ +#if 0 + float offset_units; + float offset_scale; + ubyte sprite_coord_mode[PIPE_MAX_SHADER_OUTPUTS]; /**< PIPE_SPRITE_COORD_ */ +#endif +}; + + + 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) ); + struct pipe_rasterizer_state *state + = MALLOC(sizeof(struct pipe_rasterizer_state)); memcpy(state, setup, sizeof(struct pipe_rasterizer_state)); return state; } @@ -56,10 +98,9 @@ cell_bind_rasterizer_state(struct pipe_context *pipe, void *setup) cell->dirty |= CELL_NEW_RASTERIZER; } + void cell_delete_rasterizer_state(struct pipe_context *pipe, void *rasterizer) { - FREE( rasterizer ); + FREE(rasterizer); } - - diff --git a/src/mesa/pipe/cell/ppu/cell_state_surface.c b/src/mesa/pipe/cell/ppu/cell_state_surface.c index f7330caf5e..9bf3c339d2 100644 --- a/src/mesa/pipe/cell/ppu/cell_state_surface.c +++ b/src/mesa/pipe/cell/ppu/cell_state_surface.c @@ -1,7 +1,37 @@ - - +/************************************************************************** + * + * 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_inlines.h" +#include "cell_batch.h" #include "cell_context.h" #include "cell_state.h" +#include "cell_spu.h" + void cell_set_framebuffer_state(struct pipe_context *pipe, @@ -9,9 +39,67 @@ cell_set_framebuffer_state(struct pipe_context *pipe, { struct cell_context *cell = cell_context(pipe); - cell->framebuffer = *fb; + /* XXX revisit this memcmp! */ + if (memcmp(&cell->framebuffer, fb, sizeof(*fb))) { + struct pipe_surface *csurf = fb->cbufs[0]; + struct pipe_surface *zsurf = fb->zbuf; + uint i; + + /* change in fb state */ + + /* unmap old surfaces */ + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (cell->framebuffer.cbufs[i] && cell->cbuf_map[i]) { + pipe_surface_unmap(cell->framebuffer.cbufs[i]); + cell->cbuf_map[i] = NULL; + } + } + + if (cell->framebuffer.zbuf && cell->zbuf_map) { + pipe_surface_unmap(cell->framebuffer.zbuf); + cell->zbuf_map = NULL; + } + + /* update my state */ + cell->framebuffer = *fb; - cell->dirty |= CELL_NEW_FRAMEBUFFER; + /* map new surfaces */ + if (csurf) + cell->cbuf_map[0] = pipe_surface_map(csurf); + + if (zsurf) + cell->zbuf_map = pipe_surface_map(zsurf); + +#if 0 + for (i = 0; i < cell->num_spus; i++) { + struct cell_command_framebuffer *fb = &cell_global.command[i].fb; + fb->opcode = CELL_CMD_FRAMEBUFFER; + fb->color_start = csurf->map; + fb->color_format = csurf->format; + fb->depth_start = zsurf ? zsurf->map : NULL; + fb->depth_format = zsurf ? zsurf->format : PIPE_FORMAT_NONE; + fb->width = csurf->width; + fb->height = csurf->height; + send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FRAMEBUFFER); + } +#endif +#if 1 + { + struct cell_command_framebuffer *fb + = cell_batch_alloc(cell, sizeof(*fb)); + fb->opcode = CELL_CMD_FRAMEBUFFER; + fb->color_start = cell->cbuf_map[0]; + fb->color_format = csurf->format; + fb->depth_start = cell->zbuf_map; + fb->depth_format = zsurf ? zsurf->format : PIPE_FORMAT_NONE; + fb->width = csurf->width; + fb->height = csurf->height; + /*cell_batch_flush(cell);*/ + /*cell_flush(&cell->pipe, 0x0);*/ + } +#endif + cell->dirty |= CELL_NEW_FRAMEBUFFER; + } #if 0 struct pipe_surface *ps; diff --git a/src/mesa/pipe/cell/ppu/cell_surface.c b/src/mesa/pipe/cell/ppu/cell_surface.c index 185eeb26e8..53c5325ddd 100644 --- a/src/mesa/pipe/cell/ppu/cell_surface.c +++ b/src/mesa/pipe/cell/ppu/cell_surface.c @@ -37,6 +37,7 @@ #include "pipe/p_util.h" #include "pipe/cell/common.h" #include "cell_context.h" +#include "cell_batch.h" #include "cell_surface.h" #include "cell_spu.h" @@ -47,55 +48,52 @@ cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps, { struct cell_context *cell = cell_context(pipe); uint i; + uint surfIndex; - if (!ps->map) - pipe_surface_map(ps); + if (!cell->cbuf_map[0]) + cell->cbuf_map[0] = pipe_surface_map(ps); - for (i = 0; i < cell->num_spus; i++) { - struct cell_command_framebuffer *fb = &cell_global.command[i].fb; - fb->start = ps->map; - fb->width = ps->width; - fb->height = ps->height; - fb->format = ps->format; - send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FRAMEBUFFER); + if (ps == cell->framebuffer.zbuf) { + surfIndex = 1; } - - for (i = 0; i < cell->num_spus; i++) { - /* XXX clear color varies per-SPU for debugging */ - cell_global.command[i].clear.value = clearValue | (i << 21); - send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_CLEAR_TILES); + else { + surfIndex = 0; } -#if 1 - /* XXX Draw a test triangle over the cleared surface */ +#if 0 for (i = 0; i < cell->num_spus; i++) { - /* Same triangle data for all SPUs */ - struct cell_command_triangle *tri = &cell_global.command[i].tri; - tri->vert[0][0] = 20.0; - tri->vert[0][1] = ps->height - 20; - - tri->vert[1][0] = ps->width - 20.0; - tri->vert[1][1] = ps->height - 20; - - tri->vert[2][0] = ps->width / 2; - tri->vert[2][1] = 20.0; - - tri->color[0][0] = 1.0; - tri->color[0][1] = 0.0; - tri->color[0][2] = 0.0; - tri->color[0][3] = 0.0; - - tri->color[1][0] = 0.0; - tri->color[1][1] = 1.0; - tri->color[1][2] = 0.0; - tri->color[1][3] = 0.0; - - tri->color[2][0] = 0.0; - tri->color[2][1] = 0.0; - tri->color[2][2] = 1.0; - tri->color[2][3] = 0.0; - - send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_TRIANGLE); +#if 1 + uint clr = clearValue; + if (surfIndex == 0) { + /* XXX debug: clear color varied per-SPU to visualize tiles */ + if ((clr & 0xff) == 0) + clr |= 64 + i * 8; + if ((clr & 0xff00) == 0) + clr |= (64 + i * 8) << 8; + if ((clr & 0xff0000) == 0) + clr |= (64 + i * 8) << 16; + if ((clr & 0xff000000) == 0) + clr |= (64 + i * 8) << 24; + } + cell_global.command[i].clear.value = clr; +#else + cell_global.command[i].clear.value = clearValue; +#endif + cell_global.command[i].clear.surface = surfIndex; + send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_CLEAR_SURFACE); + } +#else + { + struct cell_command_clear_surface *clr + = (struct cell_command_clear_surface *) + cell_batch_alloc(cell, sizeof(*clr)); + clr->opcode = CELL_CMD_CLEAR_SURFACE; + clr->surface = surfIndex; + clr->value = clearValue; } #endif + + /* XXX temporary */ + cell_flush(&cell->pipe, 0x0); + } diff --git a/src/mesa/pipe/cell/ppu/cell_vbuf.c b/src/mesa/pipe/cell/ppu/cell_vbuf.c new file mode 100644 index 0000000000..d27d718dae --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_vbuf.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. + * + **************************************************************************/ + +/** + * Authors + * Brian Paul + */ + + +#include "cell_context.h" +#include "cell_spu.h" +#include "cell_vbuf.h" +#include "pipe/draw/draw_vbuf.h" + + +/** + * Subclass of vbuf_render because we need a cell_context pointer in + * a few places. + */ +struct cell_vbuf_render +{ + struct vbuf_render base; + struct cell_context *cell; + uint prim; +}; + + +/** cast wrapper */ +static struct cell_vbuf_render * +cell_vbuf_render(struct vbuf_render *vbr) +{ + return (struct cell_vbuf_render *) vbr; +} + + + +static const struct vertex_info * +cell_vbuf_get_vertex_info(struct vbuf_render *vbr) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + return &cvbr->cell->vertex_info; +} + + +static void * +cell_vbuf_allocate_vertices(struct vbuf_render *vbr, + ushort vertex_size, ushort nr_vertices) +{ + /*printf("Alloc verts %u * %u\n", vertex_size, nr_vertices);*/ + return align_malloc(vertex_size * nr_vertices, 16); +} + + +static void +cell_vbuf_set_primitive(struct vbuf_render *vbr, unsigned prim) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + cvbr->prim = prim; + /*printf("cell_set_prim %u\n", prim);*/ +} + + +static void +cell_vbuf_draw(struct vbuf_render *vbr, + uint prim, + const ushort *indices, + uint nr_indices, + const void *vertices, + uint nr_vertices, + uint vertex_size) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + struct cell_context *cell = cvbr->cell; + float xmin, ymin, xmax, ymax; + uint i; + +#if 0 + printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u\n", + nr_indices, nr_vertices); + printf(" "); + for (i = 0; i < nr_indices; i += 3) { + printf("%u %u %u, ", indices[i+0], indices[i+1], indices[i+2]); + } + printf("\n"); +#elif 0 + printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u indexes = [%u %u %u ...]\n", + nr_indices, nr_vertices, + indices[0], indices[1], indices[2]); +#endif + + /* compute x/y bounding box */ + xmin = ymin = 1e50; + xmax = ymax = -1e50; + for (i = 0; i < nr_vertices; i++) { + const float *v = (float *) ((ubyte *) vertices + i * vertex_size); + if (v[0] < xmin) + xmin = v[0]; + if (v[0] > xmax) + xmax = v[0]; + if (v[1] < ymin) + ymin = v[1]; + if (v[1] > ymax) + ymax = v[1]; + } + + if (prim != PIPE_PRIM_TRIANGLES) + return; /* only render tris for now */ + +#if 0 + for (i = 0; i < cell->num_spus; i++) { + struct cell_command_render *render = &cell_global.command[i].render; + render->opcode = CELL_CMD_RENDER; + render->prim_type = prim; + render->num_verts = nr_vertices; + render->num_attribs = CELL_MAX_ATTRIBS; /* XXX fix */ + render->vertex_data = vertices; + render->index_data = indices; + render->num_indexes = nr_indices; + render->xmin = xmin; + render->ymin = ymin; + render->xmax = xmax; + render->ymax = ymax; + + ASSERT_ALIGN16(render->vertex_data); + ASSERT_ALIGN16(render->index_data); + send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_RENDER); + } +#else + { + struct cell_command_render *render + = (struct cell_command_render *) + cell_batch_alloc(cell, sizeof(*render)); + render->opcode = CELL_CMD_RENDER; + render->prim_type = prim; + render->num_verts = nr_vertices; + render->num_attribs = CELL_MAX_ATTRIBS; /* XXX fix */ + render->vertex_data = vertices; + render->index_data = indices; + render->num_indexes = nr_indices; + render->xmin = xmin; + render->ymin = ymin; + render->xmax = xmax; + render->ymax = ymax; + + ASSERT_ALIGN16(render->vertex_data); + ASSERT_ALIGN16(render->index_data); + } +#endif + +#if 01 + /* XXX this is temporary */ + cell_flush(&cell->pipe, PIPE_FLUSH_WAIT); +#endif +} + + +static void +cell_vbuf_release_vertices(struct vbuf_render *vbr, void *vertices, + unsigned vertex_size, unsigned vertices_used) +{ + /*printf("Free verts %u * %u\n", vertex_size, vertices_used);*/ + align_free(vertices); +} + + +static void +cell_vbuf_destroy(struct vbuf_render *vbr) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + cvbr->cell->vbuf_render = NULL; + FREE(cvbr); +} + + +/** + * Initialize the post-transform vertex buffer information for the given + * context. + */ +void +cell_init_vbuf(struct cell_context *cell) +{ + assert(cell->draw); + + cell->vbuf_render = CALLOC_STRUCT(cell_vbuf_render); + + cell->vbuf_render->base.max_indices = CELL_MAX_VBUF_INDEXES; + cell->vbuf_render->base.max_vertex_buffer_bytes = CELL_MAX_VBUF_SIZE; + + cell->vbuf_render->base.get_vertex_info = cell_vbuf_get_vertex_info; + cell->vbuf_render->base.allocate_vertices = cell_vbuf_allocate_vertices; + cell->vbuf_render->base.set_primitive = cell_vbuf_set_primitive; + cell->vbuf_render->base.draw = cell_vbuf_draw; + cell->vbuf_render->base.release_vertices = cell_vbuf_release_vertices; + cell->vbuf_render->base.destroy = cell_vbuf_destroy; + + cell->vbuf_render->cell = cell; + + cell->vbuf = draw_vbuf_stage(cell->draw, &cell->vbuf_render->base); +} diff --git a/src/mesa/pipe/cell/ppu/cell_vbuf.h b/src/mesa/pipe/cell/ppu/cell_vbuf.h new file mode 100644 index 0000000000..d265cbf770 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_vbuf.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * 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_VBUF_H +#define CELL_VBUF_H + + +struct cell_context; + +extern void +cell_init_vbuf(struct cell_context *cell); + + +#endif /* CELL_VBUF_H */ diff --git a/src/mesa/pipe/cell/spu/Makefile b/src/mesa/pipe/cell/spu/Makefile index 8e606dd1a2..b92a756cd5 100644 --- a/src/mesa/pipe/cell/spu/Makefile +++ b/src/mesa/pipe/cell/spu/Makefile @@ -16,14 +16,19 @@ PROG_SPU_EMBED_O = $(PROG)_spu-embed.o SOURCES = \ - main.c \ - tri.c + spu_main.c \ + spu_tile.c \ + spu_tri.c SPU_OBJECTS = $(SOURCES:.c=.o) \ INCLUDE_DIRS = -I$(TOP)/src/mesa +.c.o: + $(SPU_CC) $(SPU_CFLAGS) -c $< + + # The .a file will be linked into the main/PPU executable default: $(PROG_SPU_A) @@ -37,12 +42,6 @@ $(PROG_SPU): $(SPU_OBJECTS) $(SPU_CC) -o $(PROG_SPU) $(SPU_OBJECTS) $(SPU_LFLAGS) -main.o: main.c - $(SPU_CC) $(SPU_CFLAGS) -c main.c - -tri.o: tri.c - $(SPU_CC) $(SPU_CFLAGS) -c tri.c - clean: rm -f *~ *.o *.a *.d $(PROG_SPU) diff --git a/src/mesa/pipe/cell/spu/main.c b/src/mesa/pipe/cell/spu/main.c deleted file mode 100644 index cc5eddb0f5..0000000000 --- a/src/mesa/pipe/cell/spu/main.c +++ /dev/null @@ -1,265 +0,0 @@ -/************************************************************************** - * - * 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 "main.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 -*/ - -volatile struct cell_init_info init; - -struct framebuffer fb; - -int DefaultTag; - - - -void -wait_on_mask(unsigned tag) -{ - mfc_write_tag_mask( tag ); - mfc_read_tag_status_any(); -} - - - -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 */); -} - -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_ATTRIB; - - 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); - } -} - - -static void -triangle(const struct cell_command_triangle *tri) -{ - uint num_tiles = fb.width_tiles * fb.height_tiles; - struct prim_header prim; - uint i; - - COPY_4V(prim.v[0].data[0], tri->vert[0]); - COPY_4V(prim.v[1].data[0], tri->vert[1]); - COPY_4V(prim.v[2].data[0], tri->vert[2]); - - COPY_4V(prim.v[0].data[1], tri->color[0]); - COPY_4V(prim.v[1].data[1], tri->color[1]); - COPY_4V(prim.v[2].data[1], tri->color[2]); - - for (i = init.id; i < num_tiles; i += init.num_spus) { - uint tx = i % fb.width_tiles; - uint ty = i / fb.width_tiles; - draw_triangle(&prim, tx, ty); - } -} - - - -/** - * Temporary/simple main loop for SPEs: Get a command, execute it, repeat. - */ -static void -main_loop(void) -{ - struct cell_command cmd; - 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 - 1) / TILE_SIZE; - fb.height_tiles = (fb.height + TILE_SIZE - 1) / TILE_SIZE; - printf("SPU %u: %u x %u tiles\n", - init.id, fb.width_tiles, fb.height_tiles); - 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_TRIANGLE: - printf("SPU %u: TRIANGLE\n", init.id); - triangle(&cmd.tri); - 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); -} - - - -/** - * SPE entrypoint. - * Note: example programs declare params as 'unsigned long long' but - * that doesn't work. - */ -int -main(unsigned long speid, unsigned long argp) -{ - int tag = 0; - - (void) speid; - - DefaultTag = 1; - - printf("SPU: main() speid=%lu\n", speid); - - mfc_get(&init, /* dest */ - (unsigned int) argp, /* src */ - sizeof(struct cell_init_info), /* bytes */ - tag, - 0, /* tid */ - 0 /* rid */); - wait_on_mask( 1 << tag ); - - - main_loop(); - - return 0; -} diff --git a/src/mesa/pipe/cell/spu/spu_main.c b/src/mesa/pipe/cell/spu/spu_main.c new file mode 100644 index 0000000000..2727b03756 --- /dev/null +++ b/src/mesa/pipe/cell/spu/spu_main.c @@ -0,0 +1,590 @@ +/************************************************************************** + * + * 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 <libmisc.h> +#include <spu_mfcio.h> + +#include "spu_main.h" +#include "spu_tri.h" +#include "spu_tile.h" +#include "pipe/cell/common.h" +#include "pipe/p_defines.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 boolean Debug = FALSE; + +struct spu_global spu; + + +void +wait_on_mask(unsigned tagMask) +{ + mfc_write_tag_mask( tagMask ); + /* wait for completion of _any_ DMAs specified by tagMask */ + mfc_read_tag_status_any(); +} + + +static void +wait_on_mask_all(unsigned tagMask) +{ + mfc_write_tag_mask( tagMask ); + /* wait for completion of _any_ DMAs specified by tagMask */ + mfc_read_tag_status_all(); +} + + + +/** + * For tiles whose status is TILE_STATUS_CLEAR, write solid-filled + * tiles back to the main framebuffer. + */ +static void +really_clear_tiles(uint surfaceIndex) +{ + const uint num_tiles = spu.fb.width_tiles * spu.fb.height_tiles; + uint i, j; + + if (surfaceIndex == 0) { + for (i = 0; i < TILE_SIZE; i++) + for (j = 0; j < TILE_SIZE; j++) + ctile[i][j] = spu.fb.color_clear_value; /*0xff00ff;*/ + + for (i = spu.init.id; i < num_tiles; i += spu.init.num_spus) { + uint tx = i % spu.fb.width_tiles; + uint ty = i / spu.fb.width_tiles; + if (tile_status[ty][tx] == TILE_STATUS_CLEAR) { + put_tile(tx, ty, (uint *) ctile, TAG_SURFACE_CLEAR, 0); + } + } + } + else { + for (i = 0; i < TILE_SIZE; i++) + for (j = 0; j < TILE_SIZE; j++) + ztile[i][j] = spu.fb.depth_clear_value; + + for (i = spu.init.id; i < num_tiles; i += spu.init.num_spus) { + uint tx = i % spu.fb.width_tiles; + uint ty = i / spu.fb.width_tiles; + if (tile_status_z[ty][tx] == TILE_STATUS_CLEAR) + put_tile(tx, ty, (uint *) ctile, TAG_SURFACE_CLEAR, 1); + } + } + +#if 0 + wait_on_mask(1 << TAG_SURFACE_CLEAR); +#endif +} + + +static void +cmd_clear_surface(const struct cell_command_clear_surface *clear) +{ + const uint num_tiles = spu.fb.width_tiles * spu.fb.height_tiles; + uint i, j; + + if (Debug) + printf("SPU %u: CLEAR SURF %u to 0x%08x\n", spu.init.id, + clear->surface, clear->value); + +#define CLEAR_OPT 1 +#if CLEAR_OPT + /* set all tile's status to CLEAR */ + if (clear->surface == 0) { + memset(tile_status, TILE_STATUS_CLEAR, sizeof(tile_status)); + spu.fb.color_clear_value = clear->value; + } + else { + memset(tile_status_z, TILE_STATUS_CLEAR, sizeof(tile_status_z)); + spu.fb.depth_clear_value = clear->value; + } + return; +#endif + + if (clear->surface == 0) { + for (i = 0; i < TILE_SIZE; i++) + for (j = 0; j < TILE_SIZE; j++) + ctile[i][j] = clear->value; + } + else { + for (i = 0; i < TILE_SIZE; i++) + for (j = 0; j < TILE_SIZE; j++) + ztile[i][j] = clear->value; + } + + /* + printf("SPU: %s num=%d w=%d h=%d\n", + __FUNCTION__, num_tiles, spu.fb.width_tiles, spu.fb.height_tiles); + */ + + for (i = spu.init.id; i < num_tiles; i += spu.init.num_spus) { + uint tx = i % spu.fb.width_tiles; + uint ty = i / spu.fb.width_tiles; + if (clear->surface == 0) + put_tile(tx, ty, (uint *) ctile, TAG_SURFACE_CLEAR, 0); + else + put_tile(tx, ty, (uint *) ztile, TAG_SURFACE_CLEAR, 1); + /* XXX we don't want this here, but it fixes bad tile results */ + } + +#if 0 + wait_on_mask(1 << TAG_SURFACE_CLEAR); +#endif + + if (Debug) + printf("SPU %u: CLEAR SURF done\n", spu.init.id); +} + + +/** + * Given a rendering command's bounding box (in pixels) compute the + * location of the corresponding screen tile bounding box. + */ +static INLINE void +tile_bounding_box(const struct cell_command_render *render, + uint *txmin, uint *tymin, + uint *box_num_tiles, uint *box_width_tiles) +{ +#if 1 + /* Debug: full-window bounding box */ + uint txmax = spu.fb.width_tiles - 1; + uint tymax = spu.fb.height_tiles - 1; + *txmin = 0; + *tymin = 0; + *box_num_tiles = spu.fb.width_tiles * spu.fb.height_tiles; + *box_width_tiles = spu.fb.width_tiles; + (void) render; + (void) txmax; + (void) tymax; +#else + uint txmax, tymax, box_height_tiles; + + *txmin = (uint) render->xmin / TILE_SIZE; + *tymin = (uint) render->ymin / TILE_SIZE; + txmax = (uint) render->xmax / TILE_SIZE; + tymax = (uint) render->ymax / TILE_SIZE; + *box_width_tiles = txmax - *txmin + 1; + box_height_tiles = tymax - *tymin + 1; + *box_num_tiles = *box_width_tiles * box_height_tiles; +#endif +#if 0 + printf("Render bounds: %g, %g ... %g, %g\n", + render->xmin, render->ymin, render->xmax, render->ymax); + printf("Render tiles: %u, %u .. %u, %u\n", *txmin, *tymin, txmax, tymax); +#endif +} + + +static void +cmd_render(const struct cell_command_render *render) +{ + /* we'll DMA into these buffers */ + ubyte vertex_data[CELL_MAX_VBUF_SIZE] ALIGN16_ATTRIB; + ushort indexes[CELL_MAX_VBUF_INDEXES] ALIGN16_ATTRIB; + + uint i, j, vertex_size, vertex_bytes, index_bytes; + + if (Debug) { + printf("SPU %u: RENDER prim %u, indices: %u, nr_vert: %u\n", + spu.init.id, + render->prim_type, + render->num_verts, + render->num_indexes); + /* + printf(" bound: %g, %g .. %g, %g\n", + render->xmin, render->ymin, render->xmax, render->ymax); + */ + } + + ASSERT_ALIGN16(render->vertex_data); + ASSERT_ALIGN16(render->index_data); + + vertex_size = render->num_attribs * 4 * sizeof(float); + + /* how much vertex data */ + vertex_bytes = render->num_verts * vertex_size; + index_bytes = render->num_indexes * sizeof(ushort); + if (index_bytes < 8) + index_bytes = 8; + else + index_bytes = (index_bytes + 15) & ~0xf; /* multiple of 16 */ + + /* + printf("VBUF: indices at %p, vertices at %p vertex_bytes %u ind_bytes %u\n", + render->index_data, render->vertex_data, vertex_bytes, index_bytes); + */ + + ASSERT(vertex_bytes % 16 == 0); + /* get vertex data from main memory */ + mfc_get(vertex_data, /* dest */ + (unsigned int) render->vertex_data, /* src */ + vertex_bytes, /* size */ + TAG_VERTEX_BUFFER, + 0, /* tid */ + 0 /* rid */); + + ASSERT(index_bytes % 16 == 0); + + /* get index data from main memory */ + mfc_get(indexes, /* dest */ + (unsigned int) render->index_data, /* src */ + index_bytes, + TAG_INDEX_BUFFER, + 0, /* tid */ + 0 /* rid */); + + wait_on_mask_all((1 << TAG_VERTEX_BUFFER) | + (1 << TAG_INDEX_BUFFER)); + + /* find tiles which intersect the prim bounding box */ + uint txmin, tymin, box_width_tiles, box_num_tiles; +#if 0 + tile_bounding_box(render, &txmin, &tymin, + &box_num_tiles, &box_width_tiles); +#else + txmin = 0; + tymin = 0; + box_num_tiles = spu.fb.width_tiles * spu.fb.height_tiles; + box_width_tiles = spu.fb.width_tiles; +#endif + + /* make sure any pending clears have completed */ + wait_on_mask(1 << TAG_SURFACE_CLEAR); + + /* loop over tiles */ + for (i = spu.init.id; i < box_num_tiles; i += spu.init.num_spus) { + const uint tx = txmin + i % box_width_tiles; + const uint ty = tymin + i / box_width_tiles; + + ASSERT(tx < spu.fb.width_tiles); + ASSERT(ty < spu.fb.height_tiles); + + /* Start fetching color/z tiles. We'll wait for completion when + * we need read/write to them later in triangle rasterization. + */ + if (spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM) { + if (tile_status_z[ty][tx] != TILE_STATUS_CLEAR) { + get_tile(tx, ty, (uint *) ztile, TAG_READ_TILE_Z, 1); + } + } + + if (tile_status[ty][tx] != TILE_STATUS_CLEAR) { + get_tile(tx, ty, (uint *) ctile, TAG_READ_TILE_COLOR, 0); + } + + ASSERT(render->prim_type == PIPE_PRIM_TRIANGLES); + + /* loop over tris */ + for (j = 0; j < render->num_indexes; j += 3) { + const float *v0, *v1, *v2; + + v0 = (const float *) (vertex_data + indexes[j+0] * vertex_size); + v1 = (const float *) (vertex_data + indexes[j+1] * vertex_size); + v2 = (const float *) (vertex_data + indexes[j+2] * vertex_size); + + tri_draw(v0, v1, v2, tx, ty); + } + + /* write color/z tiles back to main framebuffer, if dirtied */ + if (tile_status[ty][tx] == TILE_STATUS_DIRTY) { + put_tile(tx, ty, (uint *) ctile, TAG_WRITE_TILE_COLOR, 0); + tile_status[ty][tx] = TILE_STATUS_DEFINED; + } + if (spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM) { + if (tile_status_z[ty][tx] == TILE_STATUS_DIRTY) { + put_tile(tx, ty, (uint *) ztile, TAG_WRITE_TILE_Z, 1); + tile_status_z[ty][tx] = TILE_STATUS_DEFINED; + } + } + + /* XXX move these... */ + wait_on_mask(1 << TAG_WRITE_TILE_COLOR); + if (spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM) { + wait_on_mask(1 << TAG_WRITE_TILE_Z); + } + } + + if (Debug) + printf("SPU %u: RENDER done\n", + spu.init.id); +} + + +static void +cmd_framebuffer(const struct cell_command_framebuffer *cmd) +{ + if (Debug) + printf("SPU %u: FRAMEBUFFER: %d x %d at %p, cformat 0x%x zformat 0x%x\n", + spu.init.id, + cmd->width, + cmd->height, + cmd->color_start, + cmd->color_format, + cmd->depth_format); + + spu.fb.color_start = cmd->color_start; + spu.fb.depth_start = cmd->depth_start; + spu.fb.color_format = cmd->color_format; + spu.fb.depth_format = cmd->depth_format; + spu.fb.width = cmd->width; + spu.fb.height = cmd->height; + spu.fb.width_tiles = (spu.fb.width + TILE_SIZE - 1) / TILE_SIZE; + spu.fb.height_tiles = (spu.fb.height + TILE_SIZE - 1) / TILE_SIZE; +} + + +static void +cmd_state_depth_stencil(const struct pipe_depth_stencil_alpha_state *state) +{ + if (Debug) + printf("SPU %u: DEPTH_STENCIL: ztest %d\n", + spu.init.id, + state->depth.enabled); + /* + memcpy(&spu.depth_stencil, state, sizeof(*state)); + */ +} + + +static void +cmd_finish(void) +{ + if (Debug) + printf("SPU %u: FINISH\n", spu.init.id); + really_clear_tiles(0); + /* 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); +} + + +/** + * Execute a batch of commands + * The opcode param encodes the location of the buffer and its size. + */ +static void +cmd_batch(uint opcode) +{ + const uint buf = (opcode >> 8) & 0xff; + uint size = (opcode >> 16); + uint buffer[CELL_BATCH_BUFFER_SIZE / 4] ALIGN16_ATTRIB; + const uint usize = size / sizeof(uint); + uint pos; + + if (Debug) + printf("SPU %u: BATCH buffer %u, len %u, from %p\n", + spu.init.id, buf, size, spu.init.batch_buffers[buf]); + + ASSERT((opcode & CELL_CMD_OPCODE_MASK) == CELL_CMD_BATCH); + + ASSERT_ALIGN16(spu.init.batch_buffers[buf]); + + size = (size + 0xf) & ~0xf; + + ASSERT(size % 16 == 0); + ASSERT((unsigned int) spu.init.batch_buffers[buf] % 16 == 0); + + mfc_get(buffer, /* dest */ + (unsigned int) spu.init.batch_buffers[buf], /* src */ + size, + TAG_BATCH_BUFFER, + 0, /* tid */ + 0 /* rid */); + wait_on_mask(1 << TAG_BATCH_BUFFER); + + /* send mbox message to indicate DMA completed */ + /* XXX temporary */ + spu_write_out_mbox(CELL_BATCH_FINISHED); + + for (pos = 0; pos < usize; /* no incr */) { + switch (buffer[pos]) { + case CELL_CMD_FRAMEBUFFER: + { + struct cell_command_framebuffer *fb + = (struct cell_command_framebuffer *) &buffer[pos]; + cmd_framebuffer(fb); + pos += sizeof(*fb) / 4; + } + break; + case CELL_CMD_CLEAR_SURFACE: + { + struct cell_command_clear_surface *clr + = (struct cell_command_clear_surface *) &buffer[pos]; + cmd_clear_surface(clr); + pos += sizeof(*clr) / 4; + } + break; + case CELL_CMD_RENDER: + { + struct cell_command_render *render + = (struct cell_command_render *) &buffer[pos]; + cmd_render(render); + pos += sizeof(*render) / 4; + } + break; + case CELL_CMD_FINISH: + cmd_finish(); + pos += 1; + break; + case CELL_CMD_STATE_DEPTH_STENCIL: + cmd_state_depth_stencil((struct pipe_depth_stencil_alpha_state *) + &buffer[pos+1]); + pos += (1 + sizeof(struct pipe_depth_stencil_alpha_state) / 4); + break; + default: + printf("SPU %u: bad opcode: 0x%x\n", spu.init.id, buffer[pos]); + ASSERT(0); + break; + } + } + + if (Debug) + printf("SPU %u: BATCH complete\n", spu.init.id); +} + + +/** + * Temporary/simple main loop for SPEs: Get a command, execute it, repeat. + */ +static void +main_loop(void) +{ + struct cell_command cmd; + int exitFlag = 0; + + if (Debug) + printf("SPU %u: Enter main loop\n", spu.init.id); + + ASSERT((sizeof(struct cell_command) & 0xf) == 0); + ASSERT_ALIGN16(&cmd); + + while (!exitFlag) { + unsigned opcode; + int tag = 0; + + if (Debug) + printf("SPU %u: Wait for cmd...\n", spu.init.id); + + /* read/wait from mailbox */ + opcode = (unsigned int) spu_read_in_mbox(); + + if (Debug) + printf("SPU %u: got cmd 0x%x\n", spu.init.id, opcode); + + /* command payload */ + mfc_get(&cmd, /* dest */ + (unsigned int) spu.init.cmd, /* src */ + sizeof(struct cell_command), /* bytes */ + tag, + 0, /* tid */ + 0 /* rid */); + wait_on_mask( 1 << tag ); + + switch (opcode & CELL_CMD_OPCODE_MASK) { + case CELL_CMD_EXIT: + if (Debug) + printf("SPU %u: EXIT\n", spu.init.id); + exitFlag = 1; + break; + case CELL_CMD_FRAMEBUFFER: + cmd_framebuffer(&cmd.fb); + break; + case CELL_CMD_CLEAR_SURFACE: + cmd_clear_surface(&cmd.clear); + break; + case CELL_CMD_RENDER: + cmd_render(&cmd.render); + break; + case CELL_CMD_BATCH: + cmd_batch(opcode); + break; + case CELL_CMD_FINISH: + cmd_finish(); + break; + default: + printf("Bad opcode!\n"); + } + + } + + if (Debug) + printf("SPU %u: Exit main loop\n", spu.init.id); +} + + + +static void +one_time_init(void) +{ + memset(tile_status, TILE_STATUS_DEFINED, sizeof(tile_status)); + memset(tile_status_z, TILE_STATUS_DEFINED, sizeof(tile_status_z)); +} + + +/** + * SPE entrypoint. + * Note: example programs declare params as 'unsigned long long' but + * that doesn't work. + */ +int +main(unsigned long speid, unsigned long argp) +{ + int tag = 0; + + (void) speid; + + one_time_init(); + + if (Debug) + printf("SPU: main() speid=%lu\n", speid); + + mfc_get(&spu.init, /* dest */ + (unsigned int) argp, /* src */ + sizeof(struct cell_init_info), /* bytes */ + tag, + 0, /* tid */ + 0 /* rid */); + wait_on_mask( 1 << tag ); + + + main_loop(); + + return 0; +} diff --git a/src/mesa/pipe/cell/spu/spu_main.h b/src/mesa/pipe/cell/spu/spu_main.h new file mode 100644 index 0000000000..75fb5b388b --- /dev/null +++ b/src/mesa/pipe/cell/spu/spu_main.h @@ -0,0 +1,93 @@ +/************************************************************************** + * + * 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 SPU_MAIN_H +#define SPU_MAIN_H + + +#include "pipe/cell/common.h" +#include "pipe/p_state.h" + + +struct spu_framebuffer { + void *color_start; /**< addr of color surface in main memory */ + void *depth_start; /**< addr of depth surface in main memory */ + enum pipe_format color_format; + enum pipe_format depth_format; + uint width, height; /**< size in pixels */ + uint width_tiles, height_tiles; /**< width and height in tiles */ + + uint color_clear_value; + uint depth_clear_value; +} ALIGN16_ATTRIB; + + +/** + * All SPU global/context state will be in singleton object of this type: + */ +struct spu_global +{ + struct cell_init_info init; + + struct spu_framebuffer fb; + struct pipe_depth_stencil_alpha_state depth_stencil; + struct pipe_blend_state blend; + /* XXX more state to come */ + +} ALIGN16_ATTRIB; + + +extern struct spu_global spu; + + + + +/* DMA TAGS */ + +#define TAG_SURFACE_CLEAR 10 +#define TAG_VERTEX_BUFFER 11 +#define TAG_READ_TILE_COLOR 12 +#define TAG_READ_TILE_Z 13 +#define TAG_WRITE_TILE_COLOR 14 +#define TAG_WRITE_TILE_Z 15 +#define TAG_INDEX_BUFFER 16 +#define TAG_BATCH_BUFFER 17 + +/** The standard assert macro doesn't seem to work on SPUs */ +#define ASSERT(x) \ + if (!(x)) { \ + fprintf(stderr, "SPU %d: %s:%d: %s(): assertion %s failed.\n", \ + spu.init.id, __FILE__, __LINE__, __FUNCTION__, #x); \ + exit(1); \ + } + + +void +wait_on_mask(unsigned tag); + + +#endif /* SPU_MAIN_H */ diff --git a/src/mesa/pipe/cell/spu/spu_tile.c b/src/mesa/pipe/cell/spu/spu_tile.c new file mode 100644 index 0000000000..1505cb322b --- /dev/null +++ b/src/mesa/pipe/cell/spu/spu_tile.c @@ -0,0 +1,115 @@ +/************************************************************************** + * + * 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 "spu_tile.h" + + + +uint ctile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB; +ushort ztile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB; + +ubyte tile_status[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB; +ubyte tile_status_z[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB; + + + +void +get_tile(uint tx, uint ty, uint *tile, int tag, int zBuf) +{ + const uint offset = ty * spu.fb.width_tiles + tx; + const uint bytesPerTile = TILE_SIZE * TILE_SIZE * (zBuf ? 2 : 4); + const ubyte *src = zBuf ? spu.fb.depth_start : spu.fb.color_start; + + src += offset * bytesPerTile; + + ASSERT(tx < spu.fb.width_tiles); + ASSERT(ty < spu.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 */); +} + + +void +put_tile(uint tx, uint ty, const uint *tile, int tag, int zBuf) +{ + const uint offset = ty * spu.fb.width_tiles + tx; + const uint bytesPerTile = TILE_SIZE * TILE_SIZE * (zBuf ? 2 : 4); + ubyte *dst = zBuf ? spu.fb.depth_start : spu.fb.color_start; + + dst += offset * bytesPerTile; + + ASSERT(tx < spu.fb.width_tiles); + ASSERT(ty < spu.fb.height_tiles); + ASSERT_ALIGN16(tile); + /* + printf("SPU %u: put_tile: src: %p dst: 0x%x size: %d\n", + spu.init.id, + tile, (unsigned int) dst, bytesPerTile); + */ + + mfc_put((void *) tile, /* src in local memory */ + (unsigned int) dst, /* dst in main memory */ + bytesPerTile, + tag, + 0, /* tid */ + 0 /* rid */); +} + + +void +clear_tile(uint tile[TILE_SIZE][TILE_SIZE], uint value) +{ + uint i, j; + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile[i][j] = value; + } + } +} + +void +clear_tile_z(ushort tile[TILE_SIZE][TILE_SIZE], uint value) +{ + uint i, j; + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile[i][j] = value; + } + } +} + diff --git a/src/mesa/pipe/cell/spu/spu_tile.h b/src/mesa/pipe/cell/spu/spu_tile.h new file mode 100644 index 0000000000..637923764b --- /dev/null +++ b/src/mesa/pipe/cell/spu/spu_tile.h @@ -0,0 +1,67 @@ +/************************************************************************** + * + * 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 SPU_TILE_H +#define SPU_TILE_H + + +#include <libmisc.h> +#include <spu_mfcio.h> +#include "spu_main.h" +#include "pipe/cell/common.h" + + +#define MAX_WIDTH 1024 +#define MAX_HEIGHT 1024 + + +extern uint ctile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB; +extern ushort ztile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB; + + +#define TILE_STATUS_CLEAR 1 +#define TILE_STATUS_DEFINED 2 /**< defined pixel data */ +#define TILE_STATUS_DIRTY 3 /**< modified, but not put back yet */ + +extern ubyte tile_status[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB; +extern ubyte tile_status_z[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB; + + +void +get_tile(uint tx, uint ty, uint *tile, int tag, int zBuf); + +void +put_tile(uint tx, uint ty, const uint *tile, int tag, int zBuf); + +void +clear_tile(uint tile[TILE_SIZE][TILE_SIZE], uint value); + +void +clear_tile_z(ushort tile[TILE_SIZE][TILE_SIZE], uint value); + + +#endif /* SPU_TILE_H */ diff --git a/src/mesa/pipe/cell/spu/tri.c b/src/mesa/pipe/cell/spu/spu_tri.c index cd648db360..ddd5e662d2 100644 --- a/src/mesa/pipe/cell/spu/tri.c +++ b/src/mesa/pipe/cell/spu/spu_tri.c @@ -29,31 +29,26 @@ * Triangle rendering within a tile. */ - -#if 0 -#include "sp_context.h" -#include "sp_headers.h" -#include "sp_quad.h" -#include "sp_prim_setup.h" -#include "pipe/draw/draw_private.h" -#include "pipe/draw/draw_vertex.h" -#include "pipe/p_util.h" -#endif - - #include "pipe/p_compiler.h" #include "pipe/p_format.h" #include "pipe/p_util.h" -#include "main.h" -#include "tri.h" +#include "spu_main.h" +#include "spu_tile.h" +#include "spu_tri.h" + -/* -#include <vmx2spu.h> -#include <spu_internals.h> -*/ +/** + * Simplified types taken from other parts of Gallium + */ +struct vertex_header { + float data[2][4]; /* pos and color */ +}; + +struct prim_header { + struct vertex_header *v[3]; +}; -#if 1 /* XXX fix this */ #undef CEILF @@ -70,14 +65,6 @@ #define MASK_BOTTOM_RIGHT (1 << QUAD_BOTTOM_RIGHT) #define MASK_ALL 0xf -#define PIPE_MAX_SHADER_INPUTS 8 /* XXX temp */ - -static int cliprect_minx, cliprect_maxx, cliprect_miny, cliprect_maxy; - -static uint tile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB; - -#endif - #define DEBUG_VERTS 0 @@ -100,16 +87,12 @@ struct interp_coef float dady[4]; }; + /** * Triangle setup info (derived from draw_stage). * Also used for line drawing (taking some liberties). */ struct setup_stage { -#if 0 - struct draw_stage stage; /**< This must be first (base class) */ - - struct softpipe_context *softpipe; -#endif /* Vertices are just an array of floats making up each attribute in * turn. Currently fixed at 4 floats, but should change in time. @@ -126,6 +109,10 @@ struct setup_stage { float oneoverarea; + uint tx, ty; + + int cliprect_minx, cliprect_maxx, cliprect_miny, cliprect_maxy; + #if 0 struct tgsi_interp_coef coef[PIPE_MAX_SHADER_INPUTS]; #else @@ -135,9 +122,6 @@ struct setup_stage { #if 0 struct quad_header quad; #endif -#if 1 - uint color; -#endif struct { int left[2]; /**< [0] = row0, [1] = row1 */ @@ -229,6 +213,22 @@ eval_coeff( struct setup_stage *setup, uint slot, } +static INLINE void +eval_z( struct setup_stage *setup, + float x, float y, float result[4]) +{ + uint slot = 0; + uint i = 2; + const float *dadx = setup->coef[slot].dadx; + const float *dady = setup->coef[slot].dady; + + result[QUAD_TOP_LEFT] = setup->coef[slot].a0[i] + x * dadx[i] + y * dady[i]; + result[QUAD_TOP_RIGHT] = result[0] + dadx[i]; + result[QUAD_BOTTOM_LEFT] = result[0] + dady[i]; + result[QUAD_BOTTOM_RIGHT] = result[0] + dadx[i] + dady[i]; +} + + static INLINE uint pack_color(const float color[4]) { @@ -236,14 +236,17 @@ pack_color(const float color[4]) uint g = (uint) (color[1] * 255.0); uint b = (uint) (color[2] * 255.0); uint a = (uint) (color[3] * 255.0); - const enum pipe_format format = PIPE_FORMAT_A8R8G8B8_UNORM; /* XXX temp */ - switch (format) { + r = MIN2(r, 255); + g = MIN2(g, 255); + b = MIN2(b, 255); + a = MIN2(a, 255); + switch (spu.fb.color_format) { case PIPE_FORMAT_A8R8G8B8_UNORM: return (a << 24) | (r << 16) | (g << 8) | b; case PIPE_FORMAT_B8G8R8A8_UNORM: return (b << 24) | (g << 16) | (r << 8) | a; default: - assert(0); + ASSERT(0); return 0; } } @@ -263,20 +266,80 @@ emit_quad( struct setup_stage *setup, int x, int y, unsigned mask ) sp->quad.first->run(sp->quad.first, &setup->quad); #else /* Cell: "write" quad fragments to the tile by setting prim color */ - int ix = x - cliprect_minx; - int iy = y - cliprect_miny; + int ix = x - setup->cliprect_minx; + int iy = y - setup->cliprect_miny; float colors[4][4]; + uint z; eval_coeff(setup, 1, (float) x, (float) y, colors); - if (mask & MASK_TOP_LEFT) - tile[iy][ix] = pack_color(colors[QUAD_TOP_LEFT]); - if (mask & MASK_TOP_RIGHT) - tile[iy][ix+1] = pack_color(colors[QUAD_TOP_RIGHT]); - if (mask & MASK_BOTTOM_LEFT) - tile[iy+1][ix] = pack_color(colors[QUAD_BOTTOM_LEFT]); - if (mask & MASK_BOTTOM_RIGHT) - tile[iy+1][ix+1] = pack_color(colors[QUAD_BOTTOM_RIGHT]); + if (spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM) { + float zvals[4]; + eval_z(setup, (float) x, (float) y, zvals); + + if (tile_status_z[setup->ty][setup->tx] == TILE_STATUS_CLEAR) { + /* now, _really_ clear the tile */ + clear_tile_z(ztile, spu.fb.depth_clear_value); + } + else { + /* make sure we've got the tile from main mem */ + wait_on_mask(1 << TAG_READ_TILE_Z); + } + tile_status_z[setup->ty][setup->tx] = TILE_STATUS_DIRTY; + + if (mask & MASK_TOP_LEFT) { + z = (uint) (zvals[0] * 65535.0); + if (z < ztile[iy][ix]) + ztile[iy][ix] = z; + else + mask &= ~MASK_TOP_LEFT; + } + + if (mask & MASK_TOP_RIGHT) { + z = (uint) (zvals[1] * 65535.0); + if (z < ztile[iy][ix+1]) + ztile[iy][ix+1] = z; + else + mask &= ~MASK_TOP_RIGHT; + } + + if (mask & MASK_BOTTOM_LEFT) { + z = (uint) (zvals[2] * 65535.0); + if (z < ztile[iy+1][ix]) + ztile[iy+1][ix] = z; + else + mask &= ~MASK_BOTTOM_LEFT; + } + + if (mask & MASK_BOTTOM_RIGHT) { + z = (uint) (zvals[3] * 65535.0); + if (z < ztile[iy+1][ix+1]) + ztile[iy+1][ix+1] = z; + else + mask &= ~MASK_BOTTOM_RIGHT; + } + } + + if (mask) { + if (tile_status[setup->ty][setup->tx] == TILE_STATUS_CLEAR) { + /* now, _really_ clear the tile */ + clear_tile(ctile, spu.fb.color_clear_value); + } + else { + /* make sure we've got the tile from main mem */ + wait_on_mask(1 << TAG_READ_TILE_COLOR); + } + tile_status[setup->ty][setup->tx] = TILE_STATUS_DIRTY; + + if (mask & MASK_TOP_LEFT) + ctile[iy][ix] = pack_color(colors[QUAD_TOP_LEFT]); + if (mask & MASK_TOP_RIGHT) + ctile[iy][ix+1] = pack_color(colors[QUAD_TOP_RIGHT]); + if (mask & MASK_BOTTOM_LEFT) + ctile[iy+1][ix] = pack_color(colors[QUAD_BOTTOM_LEFT]); + if (mask & MASK_BOTTOM_RIGHT) + ctile[iy+1][ix+1] = pack_color(colors[QUAD_BOTTOM_RIGHT]); + } #endif } @@ -379,15 +442,9 @@ static void print_vertex(const struct setup_stage *setup, static boolean setup_sort_vertices( struct setup_stage *setup, const struct prim_header *prim ) { -#if 0 const struct vertex_header *v0 = prim->v[0]; const struct vertex_header *v1 = prim->v[1]; const struct vertex_header *v2 = prim->v[2]; -#else - const struct vertex_header *v0 = &prim->v[0]; - const struct vertex_header *v1 = &prim->v[1]; - const struct vertex_header *v2 = &prim->v[2]; -#endif #if DEBUG_VERTS fprintf(stderr, "Triangle:\n"); @@ -445,6 +502,20 @@ static boolean setup_sort_vertices( struct setup_stage *setup, } } + /* Check if triangle is completely outside the tile bounds */ + if (setup->vmin->data[0][1] > setup->cliprect_maxy) + return FALSE; + if (setup->vmax->data[0][1] < setup->cliprect_miny) + return FALSE; + if (setup->vmin->data[0][0] < setup->cliprect_minx && + setup->vmid->data[0][0] < setup->cliprect_minx && + setup->vmax->data[0][0] < setup->cliprect_minx) + return FALSE; + if (setup->vmin->data[0][0] > setup->cliprect_maxx && + setup->vmid->data[0][0] > setup->cliprect_maxx && + setup->vmax->data[0][0] > setup->cliprect_maxx) + return FALSE; + setup->ebot.dx = setup->vmid->data[0][0] - setup->vmin->data[0][0]; setup->ebot.dy = setup->vmid->data[0][1] - setup->vmin->data[0][1]; setup->emaj.dx = setup->vmax->data[0][0] - setup->vmin->data[0][0]; @@ -515,16 +586,16 @@ static void const_coeff( struct setup_stage *setup, * for a triangle. */ static void tri_linear_coeff( struct setup_stage *setup, - unsigned slot ) + uint slot, uint firstComp, uint lastComp ) { uint i; - for (i = 0; i < 4; i++) { + for (i = firstComp; i < lastComp; i++) { float botda = setup->vmid->data[slot][i] - setup->vmin->data[slot][i]; float majda = setup->vmax->data[slot][i] - setup->vmin->data[slot][i]; float a = setup->ebot.dy * majda - botda * setup->emaj.dy; float b = setup->emaj.dx * botda - majda * setup->ebot.dx; - assert(slot < PIPE_MAX_SHADER_INPUTS); + ASSERT(slot < PIPE_MAX_SHADER_INPUTS); setup->coef[slot].dadx[i] = a * setup->oneoverarea; setup->coef[slot].dady[i] = b * setup->oneoverarea; @@ -640,7 +711,8 @@ static void setup_tri_coefficients( struct setup_stage *setup ) } } #else - tri_linear_coeff(setup, 1); /* slot 1 = color */ + tri_linear_coeff(setup, 0, 2, 3); /* slot 0, z */ + tri_linear_coeff(setup, 1, 0, 4); /* slot 1, color */ #endif } @@ -680,22 +752,14 @@ static void subtriangle( struct setup_stage *setup, struct edge *eright, unsigned lines ) { -#if 0 - const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect; - const int minx = (int) cliprect->minx; - const int maxx = (int) cliprect->maxx; - const int miny = (int) cliprect->miny; - const int maxy = (int) cliprect->maxy; -#else - const int minx = cliprect_minx; - const int maxx = cliprect_maxx; - const int miny = cliprect_miny; - const int maxy = cliprect_maxy; -#endif + const int minx = setup->cliprect_minx; + const int maxx = setup->cliprect_maxx; + const int miny = setup->cliprect_miny; + const int maxy = setup->cliprect_maxy; int y, start_y, finish_y; int sy = (int)eleft->sy; - assert((int)eleft->sy == (int) eright->sy); + ASSERT((int)eleft->sy == (int) eright->sy); /* clip top/bottom */ start_y = sy; @@ -757,25 +821,13 @@ static void subtriangle( struct setup_stage *setup, /** * Do setup for triangle rasterization, then render the triangle. */ -static void setup_tri( -#if 0 - struct draw_stage *stage, -#endif - struct prim_header *prim ) +static void +setup_tri(struct setup_stage *setup, struct prim_header *prim) { -#if 0 - struct setup_stage *setup = setup_stage( stage ); -#else - struct setup_stage ss; - struct setup_stage *setup = &ss; - ss.color = prim->color; -#endif - - /* - _mesa_printf("%s\n", __FUNCTION__ ); - */ + if (!setup_sort_vertices( setup, prim )) { + return; /* totally clipped */ + } - setup_sort_vertices( setup, prim ); setup_tri_coefficients( setup ); setup_tri_edges( setup ); @@ -809,81 +861,28 @@ static void setup_tri( - -#if 0 -static void setup_begin( struct draw_stage *stage ) -{ - struct setup_stage *setup = setup_stage(stage); - struct softpipe_context *sp = setup->softpipe; - - setup->quad.nr_attrs = setup->softpipe->nr_frag_attrs; - - sp->quad.first->begin(sp->quad.first); -} -#endif - -#if 0 -static void setup_end( struct draw_stage *stage ) -{ -} -#endif - - -#if 0 -static void reset_stipple_counter( struct draw_stage *stage ) -{ - struct setup_stage *setup = setup_stage(stage); - setup->softpipe->line_stipple_counter = 0; -} -#endif - -#if 0 -static void render_destroy( struct draw_stage *stage ) -{ - FREE( stage ); -} -#endif - - -#if 0 /** - * Create a new primitive setup/render stage. + * Draw triangle into tile at (tx, ty) (tile coords) + * The tile data should have already been fetched. */ -struct draw_stage *sp_draw_render_stage( struct softpipe_context *softpipe ) +void +tri_draw(const float *v0, const float *v1, const float *v2, uint tx, uint ty) { - struct setup_stage *setup = CALLOC_STRUCT(setup_stage); + struct prim_header tri; + struct setup_stage setup; - setup->softpipe = softpipe; - setup->stage.draw = softpipe->draw; - setup->stage.begin = setup_begin; - setup->stage.point = setup_point; - setup->stage.line = setup_line; - setup->stage.tri = setup_tri; - setup->stage.end = setup_end; - setup->stage.reset_stipple_counter = reset_stipple_counter; - setup->stage.destroy = render_destroy; + tri.v[0] = (struct vertex_header *) v0; + tri.v[1] = (struct vertex_header *) v1; + tri.v[2] = (struct vertex_header *) v2; - setup->quad.coef = setup->coef; + setup.tx = tx; + setup.ty = ty; - return &setup->stage; -} -#endif - - -void -draw_triangle(struct prim_header *tri, uint tx, uint ty) -{ /* set clipping bounds to tile bounds */ - cliprect_minx = tx * TILE_SIZE; - cliprect_miny = ty * TILE_SIZE; - cliprect_maxx = (tx + 1) * TILE_SIZE; - cliprect_maxy = (ty + 1) * TILE_SIZE; - - get_tile(&fb, tx, ty, (uint *) tile); - wait_on_mask(1 << DefaultTag); - - setup_tri(tri); + setup.cliprect_minx = tx * TILE_SIZE; + setup.cliprect_miny = ty * TILE_SIZE; + setup.cliprect_maxx = (tx + 1) * TILE_SIZE; + setup.cliprect_maxy = (ty + 1) * TILE_SIZE; - put_tile(&fb, tx, ty, (uint *) tile); - wait_on_mask(1 << DefaultTag); + setup_tri(&setup, &tri); } diff --git a/src/mesa/pipe/cell/spu/spu_tri.h b/src/mesa/pipe/cell/spu/spu_tri.h new file mode 100644 index 0000000000..86c42b6339 --- /dev/null +++ b/src/mesa/pipe/cell/spu/spu_tri.h @@ -0,0 +1,37 @@ +/************************************************************************** + * + * 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 SPU_TRI_H +#define SPU_TRI_H + + +extern void +tri_draw(const float *v0, const float *v1, const float *v2, uint tx, uint ty); + + +#endif /* SPU_TRI_H */ diff --git a/src/mesa/pipe/draw/draw_context.c b/src/mesa/pipe/draw/draw_context.c index a9ff54404f..d134b05717 100644 --- a/src/mesa/pipe/draw/draw_context.c +++ b/src/mesa/pipe/draw/draw_context.c @@ -69,7 +69,7 @@ struct draw_context *draw_create( void ) /* Statically allocate maximum sized vertices for the cache - could be cleverer... */ { - int i; + uint i; char *tmp = MALLOC( Elements(draw->vcache.vertex) * MAX_VERTEX_SIZE ); for (i = 0; i < Elements(draw->vcache.vertex); i++) diff --git a/src/mesa/pipe/draw/draw_context.h b/src/mesa/pipe/draw/draw_context.h index 6dc6e4ce82..60be3e194d 100644 --- a/src/mesa/pipe/draw/draw_context.h +++ b/src/mesa/pipe/draw/draw_context.h @@ -45,6 +45,7 @@ struct vertex_buffer; struct vertex_info; struct draw_context; struct draw_stage; +struct draw_vertex_shader; /** @@ -89,12 +90,13 @@ void draw_set_rasterize_stage( struct draw_context *draw, struct draw_stage *stage ); -void * draw_create_vertex_shader(struct draw_context *draw, - const struct pipe_shader_state *shader); +struct draw_vertex_shader * +draw_create_vertex_shader(struct draw_context *draw, + const struct pipe_shader_state *shader); void draw_bind_vertex_shader(struct draw_context *draw, - void *vcso); + struct draw_vertex_shader *dvs); void draw_delete_vertex_shader(struct draw_context *draw, - void *vcso); + struct draw_vertex_shader *dvs); boolean draw_use_sse(struct draw_context *draw); diff --git a/src/mesa/pipe/draw/draw_vbuf.c b/src/mesa/pipe/draw/draw_vbuf.c index d010aaba07..4f59b1b25d 100644 --- a/src/mesa/pipe/draw/draw_vbuf.c +++ b/src/mesa/pipe/draw/draw_vbuf.c @@ -275,7 +275,7 @@ vbuf_flush_indices( struct draw_stage *stage ) if(!vbuf->nr_indices) return; - assert(vbuf->vertex_ptr - vbuf->vertices == + assert((uint) (vbuf->vertex_ptr - vbuf->vertices) == vbuf->nr_vertices * vbuf->vertex_size / sizeof(unsigned)); switch(vbuf->prim) { @@ -291,8 +291,14 @@ vbuf_flush_indices( struct draw_stage *stage ) assert(0); } - vbuf->render->draw(vbuf->render, vbuf->indices, vbuf->nr_indices); - + vbuf->render->draw( vbuf->render, + vbuf->prim, + vbuf->indices, + vbuf->nr_indices, + vbuf->vertices, + vbuf->nr_vertices, + vbuf->vertex_size ); + vbuf->nr_indices = 0; } @@ -354,8 +360,14 @@ vbuf_begin( struct draw_stage *stage ) static void vbuf_end( struct draw_stage *stage ) { +#if 0 /* XXX: Overkill */ vbuf_flush_indices( stage ); +#else + /* By flushing vertices we avoid having the vertex buffer grow and grow */ + struct vbuf_stage *vbuf = vbuf_stage(stage); + vbuf_flush_vertices( stage, vbuf->vertex_size ); +#endif stage->point = vbuf_first_point; stage->line = vbuf_first_line; @@ -373,7 +385,7 @@ static void vbuf_destroy( struct draw_stage *stage ) { struct vbuf_stage *vbuf = vbuf_stage( stage ); - FREE( vbuf->indices ); + align_free( vbuf->indices ); FREE( stage ); } @@ -399,7 +411,8 @@ struct draw_stage *draw_vbuf_stage( struct draw_context *draw, assert(render->max_indices < UNDEFINED_VERTEX_ID); vbuf->max_indices = render->max_indices; - vbuf->indices = MALLOC( vbuf->max_indices ); + vbuf->indices + = align_malloc( vbuf->max_indices * sizeof(vbuf->indices[0]), 16 ); vbuf->vertices = NULL; vbuf->vertex_ptr = vbuf->vertices; diff --git a/src/mesa/pipe/draw/draw_vbuf.h b/src/mesa/pipe/draw/draw_vbuf.h index 43aa740f64..be4c4ab77b 100644 --- a/src/mesa/pipe/draw/draw_vbuf.h +++ b/src/mesa/pipe/draw/draw_vbuf.h @@ -82,8 +82,12 @@ struct vbuf_render { * DrawElements, note indices are ushort: */ void (*draw)( struct vbuf_render *, + uint prim, const ushort *indices, - unsigned nr_indices ); + uint nr_indices, + const void *vertices, + uint nr_vertices, + uint vertex_bytes); /** * Called when vbuf is done with this set of vertices: diff --git a/src/mesa/pipe/draw/draw_vertex_shader.c b/src/mesa/pipe/draw/draw_vertex_shader.c index d34d923018..c2e038453e 100644 --- a/src/mesa/pipe/draw/draw_vertex_shader.c +++ b/src/mesa/pipe/draw/draw_vertex_shader.c @@ -117,7 +117,11 @@ run_vertex_program(struct draw_context *draw, #if defined(__i386__) || defined(__386__) if (draw->use_sse) { /* SSE */ - codegen_function func = (codegen_function) x86_get_func( &draw->vertex_shader->sse2_program ); + /* cast away const */ + struct draw_vertex_shader *shader + = (struct draw_vertex_shader *)draw->vertex_shader; + codegen_function func + = (codegen_function) x86_get_func( &shader->sse2_program ); func( machine->Inputs, machine->Outputs, @@ -193,7 +197,8 @@ run_vertex_program(struct draw_context *draw, * Run the vertex shader on all vertices in the vertex queue. * Called by the draw module when the vertx cache needs to be flushed. */ -void draw_vertex_shader_queue_flush( struct draw_context *draw ) +void +draw_vertex_shader_queue_flush(struct draw_context *draw) { unsigned i, j; @@ -227,7 +232,7 @@ void draw_vertex_shader_queue_flush( struct draw_context *draw ) } -void * +struct draw_vertex_shader * draw_create_vertex_shader(struct draw_context *draw, const struct pipe_shader_state *shader) { @@ -240,33 +245,35 @@ draw_create_vertex_shader(struct draw_context *draw, vs->state = shader; -#if defined(__i386__) || defined(__386__) - if (draw->use_sse) { - /* cast-away const */ - struct pipe_shader_state *sh = (struct pipe_shader_state *) shader; - - x86_init_func( &vs->sse2_program ); - tgsi_emit_sse2( sh->tokens, &vs->sse2_program ); - } -#endif #ifdef MESA_LLVM vs->llvm_prog = gallivm_from_tgsi(shader->tokens, GALLIVM_VS); draw->engine = gallivm_global_cpu_engine(); if (!draw->engine) { draw->engine = gallivm_cpu_engine_create(vs->llvm_prog); } - else + else { gallivm_cpu_jit_compile(draw->engine, vs->llvm_prog); + } +#elif defined(__i386__) || defined(__386__) + if (draw->use_sse) { + /* cast-away const */ + struct pipe_shader_state *sh = (struct pipe_shader_state *) shader; + + x86_init_func( &vs->sse2_program ); + tgsi_emit_sse2( (struct tgsi_token *) sh->tokens, &vs->sse2_program ); + } #endif return vs; } -void draw_bind_vertex_shader(struct draw_context *draw, - void *vcso) + +void +draw_bind_vertex_shader(struct draw_context *draw, + struct draw_vertex_shader *dvs) { draw_flush(draw); - draw->vertex_shader = (struct draw_vertex_shader*)(vcso); + draw->vertex_shader = dvs; /* specify the fragment program to interpret/execute */ tgsi_exec_machine_init(&draw->machine, @@ -275,16 +282,14 @@ void draw_bind_vertex_shader(struct draw_context *draw, NULL /*samplers*/ ); } -void draw_delete_vertex_shader(struct draw_context *draw, - void *vcso) -{ - struct draw_vertex_shader *vs; - - vs = (struct draw_vertex_shader *) vcso; +void +draw_delete_vertex_shader(struct draw_context *draw, + struct draw_vertex_shader *dvs) +{ #if defined(__i386__) || defined(__386__) - x86_release_func( (struct x86_function *) &vs->sse2_program ); + x86_release_func( (struct x86_function *) &dvs->sse2_program ); #endif - FREE( vs ); + FREE( dvs ); } diff --git a/src/mesa/pipe/i915simple/i915_prim_vbuf.c b/src/mesa/pipe/i915simple/i915_prim_vbuf.c index 571ad40595..bdcc027ed7 100644 --- a/src/mesa/pipe/i915simple/i915_prim_vbuf.c +++ b/src/mesa/pipe/i915simple/i915_prim_vbuf.c @@ -136,8 +136,12 @@ i915_vbuf_render_set_primitive( struct vbuf_render *render, static void i915_vbuf_render_draw( struct vbuf_render *render, + uint prim, const ushort *indices, - unsigned nr_indices ) + uint nr_indices, + const void *vertices, + uint nr_vertices, + uint vertex_bytes) { struct i915_vbuf_render *i915_render = i915_vbuf_render(render); struct i915_context *i915 = i915_render->i915; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index f8332aab37..1190e05699 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -438,12 +438,12 @@ i915_create_vs_state(struct pipe_context *pipe, return draw_create_vertex_shader(i915->draw, templ); } -static void i915_bind_vs_state(struct pipe_context *pipe, void *vs) +static void i915_bind_vs_state(struct pipe_context *pipe, void *shader) { struct i915_context *i915 = i915_context(pipe); /* just pass-through to draw module */ - draw_bind_vertex_shader(i915->draw, vs); + draw_bind_vertex_shader(i915->draw, (struct draw_vertex_shader *) shader); } static void i915_delete_vs_state(struct pipe_context *pipe, void *shader) @@ -451,7 +451,7 @@ static void i915_delete_vs_state(struct pipe_context *pipe, void *shader) struct i915_context *i915 = i915_context(pipe); /* just pass-through to draw module */ - draw_delete_vertex_shader(i915->draw, shader); + draw_delete_vertex_shader(i915->draw, (struct draw_vertex_shader *) shader); } static void i915_set_constant_buffer(struct pipe_context *pipe, diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index 79e74e1143..e3c3cdd2e4 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -171,10 +171,10 @@ i915_surface_copy(struct pipe_context *pipe, /* Fill a rectangular sub-region. Need better logic about when to * push buffers into AGP - will currently do so whenever possible. */ -static ubyte * -get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +static void * +get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) { - return dst->map + (y * dst->pitch + x) * dst->cpp; + return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; } @@ -186,12 +186,11 @@ i915_surface_fill(struct pipe_context *pipe, { if (0) { unsigned i, j; - - (void)pipe_surface_map(dst); + void *dst_map = pipe_surface_map(dst); switch (dst->cpp) { case 1: { - ubyte *row = get_pointer(dst, dstx, dsty); + ubyte *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { memset(row, value, width); row += dst->pitch; @@ -199,7 +198,7 @@ i915_surface_fill(struct pipe_context *pipe, } break; case 2: { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = (ushort) value; @@ -208,7 +207,7 @@ i915_surface_fill(struct pipe_context *pipe, } break; case 4: { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + unsigned *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = value; @@ -220,6 +219,8 @@ i915_surface_fill(struct pipe_context *pipe, assert(0); break; } + + pipe_surface_unmap( dst ); } else { i915_fill_blit( i915_context(pipe), @@ -239,8 +240,6 @@ i915_init_surface_functions(struct i915_context *i915) i915->pipe.get_tex_surface = i915_get_tex_surface; i915->pipe.get_tile = pipe_get_tile_raw; i915->pipe.put_tile = pipe_put_tile_raw; - i915->pipe.get_tile_rgba = pipe_get_tile_rgba; - i915->pipe.put_tile_rgba = pipe_put_tile_rgba; i915->pipe.surface_data = i915_surface_data; i915->pipe.surface_copy = i915_surface_copy; diff --git a/src/mesa/pipe/i965simple/brw_sf.c b/src/mesa/pipe/i965simple/brw_sf.c index 7b6fd3fff6..b89b2e4087 100644 --- a/src/mesa/pipe/i965simple/brw_sf.c +++ b/src/mesa/pipe/i965simple/brw_sf.c @@ -58,7 +58,7 @@ static void compile_sf_prog( struct brw_context *brw, c.nr_attrs = c.key.vp_output_count; c.nr_attr_regs = (c.nr_attrs+1)/2; - c.nr_setup_attrs = c.key.fp_input_count; + c.nr_setup_attrs = c.key.fp_input_count + 1; /* +1 for position */ c.nr_setup_regs = (c.nr_setup_attrs+1)/2; c.prog_data.urb_read_length = c.nr_attr_regs; @@ -119,7 +119,11 @@ static boolean search_cache( struct brw_context *brw, */ static void upload_sf_prog( struct brw_context *brw ) { + const struct brw_fragment_program *fs = brw->attribs.FragmentProgram; struct brw_sf_prog_key key; + struct tgsi_parse_context parse; + int i, done = 0; + memset(&key, 0, sizeof(key)); @@ -149,6 +153,71 @@ static void upload_sf_prog( struct brw_context *brw ) } + + /* Scan fp inputs to figure out what interpolation modes are + * required for each incoming vp output. There is an assumption + * that the state tracker makes sure there is a 1:1 linkage between + * these sets of attributes (XXX: position??) + */ + tgsi_parse_init( &parse, fs->program.tokens ); + while( !done && + !tgsi_parse_end_of_tokens( &parse ) ) + { + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + if (parse.FullToken.FullDeclaration.Declaration.File == TGSI_FILE_INPUT) + { + int first = parse.FullToken.FullDeclaration.u.DeclarationRange.First; + int last = parse.FullToken.FullDeclaration.u.DeclarationRange.Last; + int interp_mode = parse.FullToken.FullDeclaration.Interpolation.Interpolate; + //int semantic = parse.FullToken.FullDeclaration.Semantic.SemanticName; + //int semantic_index = parse.FullToken.FullDeclaration.Semantic.SemanticIndex; + + fprintf(stderr, "fs input %d..%d interp mode %d\n", first, last, interp_mode); + + switch (interp_mode) { + case TGSI_INTERPOLATE_CONSTANT: + for (i = first; i <= last; i++) + key.const_mask |= (1 << i); + break; + case TGSI_INTERPOLATE_LINEAR: + for (i = first; i <= last; i++) + key.linear_mask |= (1 << i); + break; + case TGSI_INTERPOLATE_PERSPECTIVE: + for (i = first; i <= last; i++) + key.persp_mask |= (1 << i); + break; + default: + break; + } + + /* Also need stuff for flat shading, twosided color. + */ + + } + break; + default: + done = 1; + break; + } + } + + /* Hack: Adjust for position. Optimize away when not required (ie + * for perspective interpolation). + */ + key.persp_mask <<= 1; + key.linear_mask <<= 1; + key.linear_mask |= 1; + key.const_mask <<= 1; + + fprintf(stderr, "key.persp_mask: %x\n", key.persp_mask); + fprintf(stderr, "key.linear_mask: %x\n", key.linear_mask); + fprintf(stderr, "key.const_mask: %x\n", key.const_mask); + + // key.do_point_sprite = brw->attribs.Point->PointSprite; // key.SpriteOrigin = brw->attribs.Point->SpriteOrigin; @@ -176,6 +245,8 @@ const struct brw_tracked_state brw_sf_prog = { }; + +#if 0 /* Build a struct like the one we'd like the state tracker to pass to * us. */ @@ -202,43 +273,6 @@ static void update_sf_linkage( struct brw_context *brw ) - /* First scan fp inputs - */ - tgsi_parse_init( &parse, fs->program.tokens ); - while( !done && - !tgsi_parse_end_of_tokens( &parse ) ) - { - tgsi_parse_token( &parse ); - - switch( parse.FullToken.Token.Type ) { - case TGSI_TOKEN_TYPE_DECLARATION: - if (parse.FullToken.FullDeclaration.Declaration.File == TGSI_FILE_INPUT) - { - int first = parse.FullToken.FullDeclaration.u.DeclarationRange.First; - int last = parse.FullToken.FullDeclaration.u.DeclarationRange.Last; - - for (i = first; i < last; i++) { - state.fp_input[i].vp_output = ~0; - state.fp_input[i].bf_vp_output = ~0; - state.fp_input[i].interp_mode = - parse.FullToken.FullDeclaration.Interpolation.Interpolate; - - fp_semantic[i].semantic = - parse.FullToken.FullDeclaration.Semantic.SemanticName; - fp_semantic[i].semantic_index = - parse.FullToken.FullDeclaration.Semantic.SemanticIndex; - - } - - assert(last > state.fp_input_count); - state.fp_input_count = last; - } - break; - default: - done = 1; - break; - } - } assert(state.fp_input_count == fs->program.num_inputs); @@ -313,3 +347,5 @@ const struct brw_tracked_state brw_sf_linkage = { .update = update_sf_linkage }; + +#endif diff --git a/src/mesa/pipe/i965simple/brw_sf_emit.c b/src/mesa/pipe/i965simple/brw_sf_emit.c index 0fa61f14b6..6ff5254ff7 100644 --- a/src/mesa/pipe/i965simple/brw_sf_emit.c +++ b/src/mesa/pipe/i965simple/brw_sf_emit.c @@ -134,30 +134,39 @@ static boolean calculate_masks( struct brw_sf_compile *c, ushort *pc_linear) { boolean is_last_attr = (reg == c->nr_setup_regs - 1); + unsigned persp_mask = c->key.persp_mask; + unsigned linear_mask = c->key.linear_mask; + fprintf(stderr, "persp_mask: %x\n", persp_mask); + fprintf(stderr, "linear_mask: %x\n", linear_mask); *pc_persp = 0; *pc_linear = 0; *pc = 0xf; -// if (persp_mask & (1 << c->idx_to_attr[reg*2])) -// *pc_persp = 0xf; + if (persp_mask & (1 << (reg*2))) + *pc_persp = 0xf; -// if (linear_mask & (1 << c->idx_to_attr[reg*2])) + if (linear_mask & (1 << (reg*2))) *pc_linear = 0xf; /* Maybe only processs one attribute on the final round: */ - if (1 || reg*2+1 < c->nr_setup_attrs) { + if (reg*2+1 < c->nr_setup_attrs) { *pc |= 0xf0; -// if (persp_mask & (1 << c->idx_to_attr[reg*2+1])) -// *pc_persp |= 0xf0; + if (persp_mask & (1 << (reg*2+1))) + *pc_persp |= 0xf0; -// if (linear_mask & (1 << c->idx_to_attr[reg*2+1])) + if (linear_mask & (1 << (reg*2+1))) *pc_linear |= 0xf0; } + fprintf(stderr, "pc: %x\n", *pc); + fprintf(stderr, "pc_persp: %x\n", *pc_persp); + fprintf(stderr, "pc_linear: %x\n", *pc_linear); + + return is_last_attr; } @@ -168,6 +177,8 @@ void brw_emit_tri_setup( struct brw_sf_compile *c ) struct brw_compile *p = &c->func; unsigned i; + fprintf(stderr, "%s START ==============\n", __FUNCTION__); + c->nr_verts = 3; alloc_regs(c); invert_det(c); @@ -181,7 +192,7 @@ void brw_emit_tri_setup( struct brw_sf_compile *c ) struct brw_reg a0 = offset(c->vert[0], i); struct brw_reg a1 = offset(c->vert[1], i); struct brw_reg a2 = offset(c->vert[2], i); - ushort pc, pc_persp, pc_linear; + ushort pc = 0, pc_persp = 0, pc_linear = 0; boolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear); if (pc_persp) @@ -238,6 +249,9 @@ void brw_emit_tri_setup( struct brw_sf_compile *c ) BRW_URB_SWIZZLE_TRANSPOSE); /* XXX: Swizzle control "SF to windower" */ } } + + fprintf(stderr, "%s DONE ==============\n", __FUNCTION__); + } diff --git a/src/mesa/pipe/i965simple/brw_surface.c b/src/mesa/pipe/i965simple/brw_surface.c index d0e7229d5c..4eacbdf82b 100644 --- a/src/mesa/pipe/i965simple/brw_surface.c +++ b/src/mesa/pipe/i965simple/brw_surface.c @@ -171,10 +171,10 @@ brw_surface_copy(struct pipe_context *pipe, /* Fill a rectangular sub-region. Need better logic about when to * push buffers into AGP - will currently do so whenever possible. */ -static ubyte * -get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +static void * +get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) { - return dst->map + (y * dst->pitch + x) * dst->cpp; + return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; } @@ -186,12 +186,11 @@ brw_surface_fill(struct pipe_context *pipe, { if (0) { unsigned i, j; - - (void)pipe_surface_map(dst); + void *dst_map = pipe_surface_map(dst); switch (dst->cpp) { case 1: { - ubyte *row = get_pointer(dst, dstx, dsty); + ubyte *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { memset(row, value, width); row += dst->pitch; @@ -199,7 +198,7 @@ brw_surface_fill(struct pipe_context *pipe, } break; case 2: { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = (ushort) value; @@ -208,7 +207,7 @@ brw_surface_fill(struct pipe_context *pipe, } break; case 4: { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + unsigned *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = value; @@ -220,6 +219,8 @@ brw_surface_fill(struct pipe_context *pipe, assert(0); break; } + + pipe_surface_unmap( dst ); } else { brw_fill_blit(brw_context(pipe), @@ -238,8 +239,6 @@ brw_init_surface_functions(struct brw_context *brw) brw->pipe.get_tex_surface = brw_get_tex_surface; brw->pipe.get_tile = pipe_get_tile_raw; brw->pipe.put_tile = pipe_put_tile_raw; - brw->pipe.get_tile_rgba = pipe_get_tile_rgba; - brw->pipe.put_tile_rgba = pipe_put_tile_rgba; brw->pipe.surface_data = brw_surface_data; brw->pipe.surface_copy = brw_surface_copy; diff --git a/src/mesa/pipe/i965simple/brw_tex_layout.c b/src/mesa/pipe/i965simple/brw_tex_layout.c index 7d6e2851b1..2b2bf16f1b 100644 --- a/src/mesa/pipe/i965simple/brw_tex_layout.c +++ b/src/mesa/pipe/i965simple/brw_tex_layout.c @@ -237,7 +237,7 @@ static boolean brw_miptree_layout(struct pipe_context *pipe, struct brw_texture unsigned nr_images = pt->target == PIPE_TEXTURE_3D ? depth : 6; int x = 0; int y = 0; - int q, j; + uint q, j; intel_miptree_set_level_info(tex, level, nr_images, 0, tex->total_height, diff --git a/src/mesa/pipe/i965simple/brw_vs_emit.c b/src/mesa/pipe/i965simple/brw_vs_emit.c index 0cc0a437b0..5f212bd055 100644 --- a/src/mesa/pipe/i965simple/brw_vs_emit.c +++ b/src/mesa/pipe/i965simple/brw_vs_emit.c @@ -630,8 +630,8 @@ static struct brw_reg get_reg( struct brw_vs_compile *c, assert(c->regs[file][index].nr != 0); return c->regs[file][index]; case TGSI_FILE_CONSTANT: - assert(c->regs[TGSI_FILE_CONSTANT][index + c->prog_data.num_consts].nr != 0); - return c->regs[TGSI_FILE_CONSTANT][index + c->prog_data.num_consts]; + assert(c->regs[TGSI_FILE_CONSTANT][index + c->prog_data.num_imm].nr != 0); + return c->regs[TGSI_FILE_CONSTANT][index + c->prog_data.num_imm]; case TGSI_FILE_IMMEDIATE: assert(c->regs[TGSI_FILE_CONSTANT][index].nr != 0); return c->regs[TGSI_FILE_CONSTANT][index]; diff --git a/src/mesa/pipe/i965simple/brw_winsys.h b/src/mesa/pipe/i965simple/brw_winsys.h index 49a12a1c27..253599896c 100644 --- a/src/mesa/pipe/i965simple/brw_winsys.h +++ b/src/mesa/pipe/i965simple/brw_winsys.h @@ -190,7 +190,7 @@ static inline boolean brw_batchbuffer_data(struct brw_winsys *winsys, unsigned bytes) { static const unsigned incr = sizeof(unsigned); - int i; + uint i; const unsigned *udata = (const unsigned*)(data); unsigned size = bytes/incr; for (i = 0; i < size; ++i) { diff --git a/src/mesa/pipe/i965simple/brw_wm_decl.c b/src/mesa/pipe/i965simple/brw_wm_decl.c index 5b1abb9d48..b45a333a2e 100644 --- a/src/mesa/pipe/i965simple/brw_wm_decl.c +++ b/src/mesa/pipe/i965simple/brw_wm_decl.c @@ -273,6 +273,12 @@ static void prealloc_reg(struct brw_wm_compile *c) c->reg_index += nr_curbe_regs; } + /* Adjust for parameter coefficients for position, which are + * currently always provided. + */ +// c->position_coef[i] = brw_vec8_grf(c->reg_index, 0); + c->reg_index += 2; + /* Next we receive the plane coefficients for parameter * interpolation: */ @@ -282,7 +288,7 @@ static void prealloc_reg(struct brw_wm_compile *c) } c->prog_data.first_curbe_grf = c->key.nr_depth_regs * 2; - c->prog_data.urb_read_length = c->fp->program.num_inputs * 2; + c->prog_data.urb_read_length = (c->fp->program.num_inputs + 1) * 2; c->prog_data.curb_read_length = nr_curbe_regs; /* That's the end of the payload, now we can start allocating registers. diff --git a/src/mesa/pipe/i965simple/brw_wm_surface_state.c b/src/mesa/pipe/i965simple/brw_wm_surface_state.c index 5c7dee5790..fc40e0438c 100644 --- a/src/mesa/pipe/i965simple/brw_wm_surface_state.c +++ b/src/mesa/pipe/i965simple/brw_wm_surface_state.c @@ -33,7 +33,7 @@ #include "brw_state.h" #include "brw_defines.h" -static unsigned translate_tex_target( int target ) +static unsigned translate_tex_target( enum pipe_texture_target target ) { switch (target) { case PIPE_TEXTURE_1D: @@ -54,9 +54,9 @@ static unsigned translate_tex_target( int target ) } } -static unsigned translate_tex_format( unsigned mesa_format ) +static unsigned translate_tex_format( enum pipe_format pipe_format ) { - switch( mesa_format ) { + switch( pipe_format ) { case PIPE_FORMAT_U_L8: return BRW_SURFACEFORMAT_L8_UNORM; diff --git a/src/mesa/pipe/llvm/Makefile b/src/mesa/pipe/llvm/Makefile new file mode 100644 index 0000000000..b1463f67cf --- /dev/null +++ b/src/mesa/pipe/llvm/Makefile @@ -0,0 +1,80 @@ +# -*-makefile-*- +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = gallivm + + +GALLIVM_SOURCES = \ + gallivm.cpp \ + instructions.cpp \ + storage.cpp + +INC_SOURCES = gallivm_builtins.cpp llvm_base_shader.cpp + +CPP_SOURCES = \ + $(GALLIVM_SOURCES) + +C_SOURCES = +ASM_SOURCES = + +OBJECTS = $(C_SOURCES:.c=.o) \ + $(CPP_SOURCES:.cpp=.o) \ + $(ASM_SOURCES:.S=.o) + +### Include directories +INCLUDES = \ + -I. \ + -I$(TOP)/src/mesa/pipe \ + -I$(TOP)/src/mesa \ + -I$(TOP)/include + + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(LLVM_CFLAGS) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.cpp.o: + $(CXX) -c $(INCLUDES) $(LLVM_CXXFLAGS) $(CXXFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.S.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +##### TARGETS ##### + +default:: depend symlinks $(LIBNAME) + + +$(LIBNAME): $(OBJECTS) Makefile + $(TOP)/bin/mklib -o $@ -static $(OBJECTS) + + +depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(INC_SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) \ + $(ASM_SOURCES) $(INC_SOURCES) 2> /dev/null + + +gallivm_builtins.cpp: llvm_builtins.c + clang --emit-llvm $< |llvm-as|opt -std-compile-opts|llvm2cpp -gen-contents -o=$@ -f -for=shader -funcname=createGallivmBuiltins + +llvm_base_shader.cpp: llvm_entry.c + clang --emit-llvm $< |llvm-as |opt -std-compile-opts |llvm2cpp -for=Shader -gen-module -o=$@ -funcname=createBaseShader + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find ../include` + + +# Remove .o and backup files +clean: + -rm -f *.o */*.o *~ *.so *~ server/*.o + -rm -f depend depend.bak + -rm -f gallivm_builtins.cpp llvm_base_shader.cpp + +symlinks: + + +include depend diff --git a/src/mesa/pipe/llvm/gallivm_builtins.cpp b/src/mesa/pipe/llvm/gallivm_builtins.cpp index 48693ca2ed..1796f0a177 100644 --- a/src/mesa/pipe/llvm/gallivm_builtins.cpp +++ b/src/mesa/pipe/llvm/gallivm_builtins.cpp @@ -8,144 +8,170 @@ mod->setModuleIdentifier("shader"); // Type Definitions ArrayType* ArrayTy_0 = ArrayType::get(IntegerType::get(8), 25); -PointerType* PointerTy_1 = PointerType::get(ArrayTy_0); +PointerType* PointerTy_1 = PointerType::get(ArrayTy_0, 0); std::vector<const Type*>FuncTy_2_args; FuncTy_2_args.push_back(Type::FloatTy); FuncTy_2_args.push_back(Type::FloatTy); -ParamAttrsList *FuncTy_2_PAL = 0; FunctionType* FuncTy_2 = FunctionType::get( /*Result=*/Type::FloatTy, /*Params=*/FuncTy_2_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_2_PAL); + /*isVarArg=*/false); -PointerType* PointerTy_3 = PointerType::get(FuncTy_2); +PointerType* PointerTy_3 = PointerType::get(FuncTy_2, 0); VectorType* VectorTy_4 = VectorType::get(Type::FloatTy, 4); std::vector<const Type*>FuncTy_5_args; FuncTy_5_args.push_back(VectorTy_4); -ParamAttrsList *FuncTy_5_PAL = 0; FunctionType* FuncTy_5 = FunctionType::get( /*Result=*/VectorTy_4, /*Params=*/FuncTy_5_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_5_PAL); + /*isVarArg=*/false); std::vector<const Type*>FuncTy_6_args; FuncTy_6_args.push_back(VectorTy_4); FuncTy_6_args.push_back(VectorTy_4); FuncTy_6_args.push_back(VectorTy_4); -ParamAttrsList *FuncTy_6_PAL = 0; FunctionType* FuncTy_6 = FunctionType::get( /*Result=*/VectorTy_4, /*Params=*/FuncTy_6_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_6_PAL); + /*isVarArg=*/false); VectorType* VectorTy_7 = VectorType::get(IntegerType::get(32), 4); std::vector<const Type*>FuncTy_9_args; -ParamAttrsList *FuncTy_9_PAL = 0; FunctionType* FuncTy_9 = FunctionType::get( /*Result=*/IntegerType::get(32), /*Params=*/FuncTy_9_args, - /*isVarArg=*/true, - /*ParamAttrs=*/FuncTy_9_PAL); + /*isVarArg=*/true); -PointerType* PointerTy_8 = PointerType::get(FuncTy_9); +PointerType* PointerTy_8 = PointerType::get(FuncTy_9, 0); -PointerType* PointerTy_10 = PointerType::get(IntegerType::get(8)); +PointerType* PointerTy_10 = PointerType::get(IntegerType::get(8), 0); std::vector<const Type*>FuncTy_12_args; FuncTy_12_args.push_back(Type::FloatTy); -ParamAttrsList *FuncTy_12_PAL = 0; FunctionType* FuncTy_12 = FunctionType::get( /*Result=*/Type::FloatTy, /*Params=*/FuncTy_12_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_12_PAL); + /*isVarArg=*/false); -PointerType* PointerTy_11 = PointerType::get(FuncTy_12); +PointerType* PointerTy_11 = PointerType::get(FuncTy_12, 0); std::vector<const Type*>FuncTy_13_args; FuncTy_13_args.push_back(VectorTy_4); -ParamAttrsList *FuncTy_13_PAL = 0; FunctionType* FuncTy_13 = FunctionType::get( /*Result=*/IntegerType::get(32), /*Params=*/FuncTy_13_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_13_PAL); + /*isVarArg=*/false); // Function Declarations Function* func_approx = new Function( /*Type=*/FuncTy_2, - /*Linkage=*/GlobalValue::ExternalLinkage, + /*Linkage=*/GlobalValue::WeakLinkage, /*Name=*/"approx", mod); func_approx->setCallingConv(CallingConv::C); +const ParamAttrsList *func_approx_PAL = 0; +func_approx->setParamAttrs(func_approx_PAL); Function* func_powf = new Function( /*Type=*/FuncTy_2, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"powf", mod); // (external, no body) func_powf->setCallingConv(CallingConv::C); +const ParamAttrsList *func_powf_PAL = 0; +func_powf->setParamAttrs(func_powf_PAL); Function* func_lit = new Function( /*Type=*/FuncTy_5, - /*Linkage=*/GlobalValue::ExternalLinkage, + /*Linkage=*/GlobalValue::WeakLinkage, /*Name=*/"lit", mod); func_lit->setCallingConv(CallingConv::C); +const ParamAttrsList *func_lit_PAL = 0; +func_lit->setParamAttrs(func_lit_PAL); Function* func_cmp = new Function( /*Type=*/FuncTy_6, - /*Linkage=*/GlobalValue::ExternalLinkage, + /*Linkage=*/GlobalValue::WeakLinkage, /*Name=*/"cmp", mod); func_cmp->setCallingConv(CallingConv::C); +const ParamAttrsList *func_cmp_PAL = 0; +{ + ParamAttrsVector Attrs; + ParamAttrsWithIndex PAWI; + PAWI.index = 0; PAWI.attrs = 0 | ParamAttr::NoUnwind; + Attrs.push_back(PAWI); + func_cmp_PAL = ParamAttrsList::get(Attrs); + +} +func_cmp->setParamAttrs(func_cmp_PAL); Function* func_vcos = new Function( /*Type=*/FuncTy_5, - /*Linkage=*/GlobalValue::ExternalLinkage, + /*Linkage=*/GlobalValue::WeakLinkage, /*Name=*/"vcos", mod); func_vcos->setCallingConv(CallingConv::C); +const ParamAttrsList *func_vcos_PAL = 0; +func_vcos->setParamAttrs(func_vcos_PAL); Function* func_printf = new Function( /*Type=*/FuncTy_9, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"printf", mod); // (external, no body) func_printf->setCallingConv(CallingConv::C); +const ParamAttrsList *func_printf_PAL = 0; +func_printf->setParamAttrs(func_printf_PAL); Function* func_cosf = new Function( /*Type=*/FuncTy_12, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"cosf", mod); // (external, no body) func_cosf->setCallingConv(CallingConv::C); +const ParamAttrsList *func_cosf_PAL = 0; +func_cosf->setParamAttrs(func_cosf_PAL); Function* func_scs = new Function( /*Type=*/FuncTy_5, - /*Linkage=*/GlobalValue::ExternalLinkage, + /*Linkage=*/GlobalValue::WeakLinkage, /*Name=*/"scs", mod); func_scs->setCallingConv(CallingConv::C); +const ParamAttrsList *func_scs_PAL = 0; +func_scs->setParamAttrs(func_scs_PAL); Function* func_sinf = new Function( /*Type=*/FuncTy_12, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"sinf", mod); // (external, no body) func_sinf->setCallingConv(CallingConv::C); +const ParamAttrsList *func_sinf_PAL = 0; +func_sinf->setParamAttrs(func_sinf_PAL); Function* func_vsin = new Function( /*Type=*/FuncTy_5, - /*Linkage=*/GlobalValue::ExternalLinkage, + /*Linkage=*/GlobalValue::WeakLinkage, /*Name=*/"vsin", mod); func_vsin->setCallingConv(CallingConv::C); +const ParamAttrsList *func_vsin_PAL = 0; +func_vsin->setParamAttrs(func_vsin_PAL); Function* func_kilp = new Function( /*Type=*/FuncTy_13, - /*Linkage=*/GlobalValue::ExternalLinkage, + /*Linkage=*/GlobalValue::WeakLinkage, /*Name=*/"kilp", mod); func_kilp->setCallingConv(CallingConv::C); +const ParamAttrsList *func_kilp_PAL = 0; +{ + ParamAttrsVector Attrs; + ParamAttrsWithIndex PAWI; + PAWI.index = 0; PAWI.attrs = 0 | ParamAttr::NoUnwind; + Attrs.push_back(PAWI); + func_kilp_PAL = ParamAttrsList::get(Attrs); + +} +func_kilp->setParamAttrs(func_kilp_PAL); // Global Variable Declarations @@ -250,7 +276,9 @@ gvar_array__str1->setInitializer(const_array_15); float_call_params.push_back(float_b_addr_1); CallInst* float_call = new CallInst(func_powf, float_call_params.begin(), float_call_params.end(), "call", label_entry); float_call->setCallingConv(CallingConv::C); - float_call->setTailCall(true); + float_call->setTailCall(true);const ParamAttrsList *float_call_PAL = 0; + float_call->setParamAttrs(float_call_PAL); + new ReturnInst(float_call, label_entry); } @@ -266,28 +294,24 @@ gvar_array__str1->setInitializer(const_array_15); BasicBlock* label_UnifiedReturnBlock = new BasicBlock("UnifiedReturnBlock",func_lit,0); // Block entry (label_entry_38) - ExtractElementInst* float_tmp7 = new ExtractElementInst(packed_tmp, const_int32_19, "tmp7", label_entry_38); - FCmpInst* int1_cmp_39 = new FCmpInst(FCmpInst::FCMP_OGT, float_tmp7, const_float_18, "cmp", label_entry_38); + ExtractElementInst* float_tmp6 = new ExtractElementInst(packed_tmp, const_int32_19, "tmp6", label_entry_38); + FCmpInst* int1_cmp_39 = new FCmpInst(FCmpInst::FCMP_OGT, float_tmp6, const_float_18, "cmp", label_entry_38); new BranchInst(label_ifthen, label_UnifiedReturnBlock, int1_cmp_39, label_entry_38); // Block ifthen (label_ifthen) - InsertElementInst* packed_tmp12 = new InsertElementInst(const_packed_20, float_tmp7, const_int32_23, "tmp12", label_ifthen); - ExtractElementInst* float_tmp14 = new ExtractElementInst(packed_tmp, const_int32_23, "tmp14", label_ifthen); - ExtractElementInst* float_tmp16 = new ExtractElementInst(packed_tmp, const_int32_24, "tmp16", label_ifthen); - FCmpInst* int1_cmp_i = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp16, const_float_16, "cmp.i", label_ifthen); - SelectInst* float_b_addr_0_i = new SelectInst(int1_cmp_i, const_float_16, float_tmp16, "b.addr.0.i", label_ifthen); - FCmpInst* int1_cmp3_i = new FCmpInst(FCmpInst::FCMP_OGT, float_b_addr_0_i, const_float_17, "cmp3.i", label_ifthen); - SelectInst* float_b_addr_1_i = new SelectInst(int1_cmp3_i, const_float_17, float_b_addr_0_i, "b.addr.1.i", label_ifthen); - FCmpInst* int1_cmp7_i = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp14, const_float_18, "cmp7.i", label_ifthen); - SelectInst* float_a_addr_0_i = new SelectInst(int1_cmp7_i, const_float_18, float_tmp14, "a.addr.0.i", label_ifthen); - std::vector<Value*> float_call_i_params; - float_call_i_params.push_back(float_a_addr_0_i); - float_call_i_params.push_back(float_b_addr_1_i); - CallInst* float_call_i = new CallInst(func_powf, float_call_i_params.begin(), float_call_i_params.end(), "call.i", label_ifthen); - float_call_i->setCallingConv(CallingConv::C); - float_call_i->setTailCall(true); - InsertElementInst* packed_tmp18 = new InsertElementInst(packed_tmp12, float_call_i, const_int32_25, "tmp18", label_ifthen); - new ReturnInst(packed_tmp18, label_ifthen); + InsertElementInst* packed_tmp10 = new InsertElementInst(const_packed_20, float_tmp6, const_int32_23, "tmp10", label_ifthen); + ExtractElementInst* float_tmp12 = new ExtractElementInst(packed_tmp, const_int32_23, "tmp12", label_ifthen); + ExtractElementInst* float_tmp14 = new ExtractElementInst(packed_tmp, const_int32_24, "tmp14", label_ifthen); + std::vector<Value*> float_call_41_params; + float_call_41_params.push_back(float_tmp12); + float_call_41_params.push_back(float_tmp14); + CallInst* float_call_41 = new CallInst(func_approx, float_call_41_params.begin(), float_call_41_params.end(), "call", label_ifthen); + float_call_41->setCallingConv(CallingConv::C); + float_call_41->setTailCall(true);const ParamAttrsList *float_call_41_PAL = 0; + float_call_41->setParamAttrs(float_call_41_PAL); + + InsertElementInst* packed_tmp16 = new InsertElementInst(packed_tmp10, float_call_41, const_int32_25, "tmp16", label_ifthen); + new ReturnInst(packed_tmp16, label_ifthen); // Block UnifiedReturnBlock (label_UnifiedReturnBlock) new ReturnInst(const_packed_26, label_UnifiedReturnBlock); @@ -304,7 +328,7 @@ gvar_array__str1->setInitializer(const_array_15); Value* packed_tmp2 = args++; packed_tmp2->setName("tmp2"); - BasicBlock* label_entry_43 = new BasicBlock("entry",func_cmp,0); + BasicBlock* label_entry_44 = new BasicBlock("entry",func_cmp,0); BasicBlock* label_cond__14 = new BasicBlock("cond.?14",func_cmp,0); BasicBlock* label_cond_cont20 = new BasicBlock("cond.cont20",func_cmp,0); BasicBlock* label_cond__28 = new BasicBlock("cond.?28",func_cmp,0); @@ -312,15 +336,15 @@ gvar_array__str1->setInitializer(const_array_15); BasicBlock* label_cond__42 = new BasicBlock("cond.?42",func_cmp,0); BasicBlock* label_cond_cont48 = new BasicBlock("cond.cont48",func_cmp,0); - // Block entry (label_entry_43) - ExtractElementInst* float_tmp3 = new ExtractElementInst(packed_tmp0, const_int32_19, "tmp3", label_entry_43); - CastInst* double_conv = new FPExtInst(float_tmp3, Type::DoubleTy, "conv", label_entry_43); - FCmpInst* int1_cmp_44 = new FCmpInst(FCmpInst::FCMP_OLT, double_conv, const_double_27, "cmp", label_entry_43); - ExtractElementInst* float_tmp11 = new ExtractElementInst(packed_tmp0, const_int32_23, "tmp11", label_entry_43); - CastInst* double_conv12 = new FPExtInst(float_tmp11, Type::DoubleTy, "conv12", label_entry_43); - FCmpInst* int1_cmp13 = new FCmpInst(FCmpInst::FCMP_OLT, double_conv12, const_double_27, "cmp13", label_entry_43); - SelectInst* packed_tmp1_tmp2 = new SelectInst(int1_cmp_44, packed_tmp1, packed_tmp2, "tmp1.tmp2", label_entry_43); - new BranchInst(label_cond__14, label_cond_cont20, int1_cmp13, label_entry_43); + // Block entry (label_entry_44) + ExtractElementInst* float_tmp3 = new ExtractElementInst(packed_tmp0, const_int32_19, "tmp3", label_entry_44); + CastInst* double_conv = new FPExtInst(float_tmp3, Type::DoubleTy, "conv", label_entry_44); + FCmpInst* int1_cmp_45 = new FCmpInst(FCmpInst::FCMP_OLT, double_conv, const_double_27, "cmp", label_entry_44); + ExtractElementInst* float_tmp11 = new ExtractElementInst(packed_tmp0, const_int32_23, "tmp11", label_entry_44); + CastInst* double_conv12 = new FPExtInst(float_tmp11, Type::DoubleTy, "conv12", label_entry_44); + FCmpInst* int1_cmp13 = new FCmpInst(FCmpInst::FCMP_OLT, double_conv12, const_double_27, "cmp13", label_entry_44); + SelectInst* packed_tmp1_tmp2 = new SelectInst(int1_cmp_45, packed_tmp1, packed_tmp2, "tmp1.tmp2", label_entry_44); + new BranchInst(label_cond__14, label_cond_cont20, int1_cmp13, label_entry_44); // Block cond.?14 (label_cond__14) ShuffleVectorInst* packed_tmp233 = new ShuffleVectorInst(packed_tmp1_tmp2, packed_tmp1, const_packed_28, "tmp233", label_cond__14); @@ -386,125 +410,155 @@ gvar_array__str1->setInitializer(const_array_15); Value* packed_val = args++; packed_val->setName("val"); - BasicBlock* label_entry_52 = new BasicBlock("entry",func_vcos,0); - - // Block entry (label_entry_52) - ExtractElementInst* float_tmp1 = new ExtractElementInst(packed_val, const_int32_19, "tmp1", label_entry_52); - CastInst* double_conv_53 = new FPExtInst(float_tmp1, Type::DoubleTy, "conv", label_entry_52); - ExtractElementInst* float_tmp3_54 = new ExtractElementInst(packed_val, const_int32_23, "tmp3", label_entry_52); - CastInst* double_conv4 = new FPExtInst(float_tmp3_54, Type::DoubleTy, "conv4", label_entry_52); - ExtractElementInst* float_tmp6 = new ExtractElementInst(packed_val, const_int32_25, "tmp6", label_entry_52); - CastInst* double_conv7 = new FPExtInst(float_tmp6, Type::DoubleTy, "conv7", label_entry_52); - ExtractElementInst* float_tmp9 = new ExtractElementInst(packed_val, const_int32_24, "tmp9", label_entry_52); - CastInst* double_conv10 = new FPExtInst(float_tmp9, Type::DoubleTy, "conv10", label_entry_52); + BasicBlock* label_entry_53 = new BasicBlock("entry",func_vcos,0); + + // Block entry (label_entry_53) + ExtractElementInst* float_tmp1 = new ExtractElementInst(packed_val, const_int32_19, "tmp1", label_entry_53); + CastInst* double_conv_54 = new FPExtInst(float_tmp1, Type::DoubleTy, "conv", label_entry_53); + ExtractElementInst* float_tmp3_55 = new ExtractElementInst(packed_val, const_int32_23, "tmp3", label_entry_53); + CastInst* double_conv4 = new FPExtInst(float_tmp3_55, Type::DoubleTy, "conv4", label_entry_53); + ExtractElementInst* float_tmp6_56 = new ExtractElementInst(packed_val, const_int32_25, "tmp6", label_entry_53); + CastInst* double_conv7 = new FPExtInst(float_tmp6_56, Type::DoubleTy, "conv7", label_entry_53); + ExtractElementInst* float_tmp9 = new ExtractElementInst(packed_val, const_int32_24, "tmp9", label_entry_53); + CastInst* double_conv10 = new FPExtInst(float_tmp9, Type::DoubleTy, "conv10", label_entry_53); std::vector<Value*> int32_call_params; int32_call_params.push_back(const_ptr_34); - int32_call_params.push_back(double_conv_53); + int32_call_params.push_back(double_conv_54); int32_call_params.push_back(double_conv4); int32_call_params.push_back(double_conv7); int32_call_params.push_back(double_conv10); - CallInst* int32_call = new CallInst(func_printf, int32_call_params.begin(), int32_call_params.end(), "call", label_entry_52); + CallInst* int32_call = new CallInst(func_printf, int32_call_params.begin(), int32_call_params.end(), "call", label_entry_53); int32_call->setCallingConv(CallingConv::C); - int32_call->setTailCall(true); - CallInst* float_call13 = new CallInst(func_cosf, float_tmp1, "call13", label_entry_52); + int32_call->setTailCall(true);const ParamAttrsList *int32_call_PAL = 0; + int32_call->setParamAttrs(int32_call_PAL); + + CallInst* float_call13 = new CallInst(func_cosf, float_tmp1, "call13", label_entry_53); float_call13->setCallingConv(CallingConv::C); - float_call13->setTailCall(true); - InsertElementInst* packed_tmp15 = new InsertElementInst(const_packed_35, float_call13, const_int32_19, "tmp15", label_entry_52); - InsertElementInst* packed_tmp20 = new InsertElementInst(packed_tmp15, float_call13, const_int32_23, "tmp20", label_entry_52); - InsertElementInst* packed_tmp25 = new InsertElementInst(packed_tmp20, float_call13, const_int32_25, "tmp25", label_entry_52); - InsertElementInst* packed_tmp30 = new InsertElementInst(packed_tmp25, float_call13, const_int32_24, "tmp30", label_entry_52); - CastInst* double_conv33 = new FPExtInst(float_call13, Type::DoubleTy, "conv33", label_entry_52); + float_call13->setTailCall(true);const ParamAttrsList *float_call13_PAL = 0; + float_call13->setParamAttrs(float_call13_PAL); + + InsertElementInst* packed_tmp15 = new InsertElementInst(const_packed_35, float_call13, const_int32_19, "tmp15", label_entry_53); + CallInst* float_call18 = new CallInst(func_cosf, float_tmp1, "call18", label_entry_53); + float_call18->setCallingConv(CallingConv::C); + float_call18->setTailCall(true);const ParamAttrsList *float_call18_PAL = 0; + float_call18->setParamAttrs(float_call18_PAL); + + InsertElementInst* packed_tmp20 = new InsertElementInst(packed_tmp15, float_call18, const_int32_23, "tmp20", label_entry_53); + CallInst* float_call23 = new CallInst(func_cosf, float_tmp1, "call23", label_entry_53); + float_call23->setCallingConv(CallingConv::C); + float_call23->setTailCall(true);const ParamAttrsList *float_call23_PAL = 0; + float_call23->setParamAttrs(float_call23_PAL); + + InsertElementInst* packed_tmp25 = new InsertElementInst(packed_tmp20, float_call23, const_int32_25, "tmp25", label_entry_53); + CallInst* float_call28 = new CallInst(func_cosf, float_tmp1, "call28", label_entry_53); + float_call28->setCallingConv(CallingConv::C); + float_call28->setTailCall(true);const ParamAttrsList *float_call28_PAL = 0; + float_call28->setParamAttrs(float_call28_PAL); + + InsertElementInst* packed_tmp30 = new InsertElementInst(packed_tmp25, float_call28, const_int32_24, "tmp30", label_entry_53); + CastInst* double_conv33 = new FPExtInst(float_call13, Type::DoubleTy, "conv33", label_entry_53); + CastInst* double_conv36 = new FPExtInst(float_call18, Type::DoubleTy, "conv36", label_entry_53); + CastInst* double_conv39 = new FPExtInst(float_call23, Type::DoubleTy, "conv39", label_entry_53); + CastInst* double_conv42 = new FPExtInst(float_call28, Type::DoubleTy, "conv42", label_entry_53); std::vector<Value*> int32_call43_params; int32_call43_params.push_back(const_ptr_36); int32_call43_params.push_back(double_conv33); - int32_call43_params.push_back(double_conv33); - int32_call43_params.push_back(double_conv33); - int32_call43_params.push_back(double_conv33); - CallInst* int32_call43 = new CallInst(func_printf, int32_call43_params.begin(), int32_call43_params.end(), "call43", label_entry_52); + int32_call43_params.push_back(double_conv36); + int32_call43_params.push_back(double_conv39); + int32_call43_params.push_back(double_conv42); + CallInst* int32_call43 = new CallInst(func_printf, int32_call43_params.begin(), int32_call43_params.end(), "call43", label_entry_53); int32_call43->setCallingConv(CallingConv::C); - int32_call43->setTailCall(true); - new ReturnInst(packed_tmp30, label_entry_52); + int32_call43->setTailCall(true);const ParamAttrsList *int32_call43_PAL = 0; + int32_call43->setParamAttrs(int32_call43_PAL); + + new ReturnInst(packed_tmp30, label_entry_53); } // Function: scs (func_scs) { Function::arg_iterator args = func_scs->arg_begin(); - Value* packed_val_56 = args++; - packed_val_56->setName("val"); - - BasicBlock* label_entry_57 = new BasicBlock("entry",func_scs,0); - - // Block entry (label_entry_57) - ExtractElementInst* float_tmp2 = new ExtractElementInst(packed_val_56, const_int32_19, "tmp2", label_entry_57); - CallInst* float_call_58 = new CallInst(func_cosf, float_tmp2, "call", label_entry_57); - float_call_58->setCallingConv(CallingConv::C); - float_call_58->setTailCall(true); - InsertElementInst* packed_tmp5 = new InsertElementInst(const_packed_35, float_call_58, const_int32_19, "tmp5", label_entry_57); - CallInst* float_call7 = new CallInst(func_sinf, float_tmp2, "call7", label_entry_57); + Value* packed_val_58 = args++; + packed_val_58->setName("val"); + + BasicBlock* label_entry_59 = new BasicBlock("entry",func_scs,0); + + // Block entry (label_entry_59) + ExtractElementInst* float_tmp2 = new ExtractElementInst(packed_val_58, const_int32_19, "tmp2", label_entry_59); + CallInst* float_call_60 = new CallInst(func_cosf, float_tmp2, "call", label_entry_59); + float_call_60->setCallingConv(CallingConv::C); + float_call_60->setTailCall(true);const ParamAttrsList *float_call_60_PAL = 0; + float_call_60->setParamAttrs(float_call_60_PAL); + + InsertElementInst* packed_tmp5 = new InsertElementInst(const_packed_35, float_call_60, const_int32_19, "tmp5", label_entry_59); + CallInst* float_call7 = new CallInst(func_sinf, float_tmp2, "call7", label_entry_59); float_call7->setCallingConv(CallingConv::C); - float_call7->setTailCall(true); - InsertElementInst* packed_tmp9 = new InsertElementInst(packed_tmp5, float_call7, const_int32_23, "tmp9", label_entry_57); - new ReturnInst(packed_tmp9, label_entry_57); + float_call7->setTailCall(true);const ParamAttrsList *float_call7_PAL = 0; + float_call7->setParamAttrs(float_call7_PAL); + + InsertElementInst* packed_tmp9 = new InsertElementInst(packed_tmp5, float_call7, const_int32_23, "tmp9", label_entry_59); + new ReturnInst(packed_tmp9, label_entry_59); } // Function: vsin (func_vsin) { Function::arg_iterator args = func_vsin->arg_begin(); - Value* packed_val_60 = args++; - packed_val_60->setName("val"); - - BasicBlock* label_entry_61 = new BasicBlock("entry",func_vsin,0); - - // Block entry (label_entry_61) - ExtractElementInst* float_tmp2_62 = new ExtractElementInst(packed_val_60, const_int32_19, "tmp2", label_entry_61); - CallInst* float_call_63 = new CallInst(func_sinf, float_tmp2_62, "call", label_entry_61); - float_call_63->setCallingConv(CallingConv::C); - float_call_63->setTailCall(true); - InsertElementInst* packed_tmp6 = new InsertElementInst(const_packed_35, float_call_63, const_int32_19, "tmp6", label_entry_61); - InsertElementInst* packed_tmp9_64 = new InsertElementInst(packed_tmp6, float_call_63, const_int32_23, "tmp9", label_entry_61); - InsertElementInst* packed_tmp12_65 = new InsertElementInst(packed_tmp9_64, float_call_63, const_int32_25, "tmp12", label_entry_61); - InsertElementInst* packed_tmp15_66 = new InsertElementInst(packed_tmp12_65, float_call_63, const_int32_24, "tmp15", label_entry_61); - new ReturnInst(packed_tmp15_66, label_entry_61); + Value* packed_val_62 = args++; + packed_val_62->setName("val"); + + BasicBlock* label_entry_63 = new BasicBlock("entry",func_vsin,0); + + // Block entry (label_entry_63) + ExtractElementInst* float_tmp2_64 = new ExtractElementInst(packed_val_62, const_int32_19, "tmp2", label_entry_63); + CallInst* float_call_65 = new CallInst(func_sinf, float_tmp2_64, "call", label_entry_63); + float_call_65->setCallingConv(CallingConv::C); + float_call_65->setTailCall(true);const ParamAttrsList *float_call_65_PAL = 0; + float_call_65->setParamAttrs(float_call_65_PAL); + + InsertElementInst* packed_tmp6 = new InsertElementInst(const_packed_35, float_call_65, const_int32_19, "tmp6", label_entry_63); + InsertElementInst* packed_tmp9_66 = new InsertElementInst(packed_tmp6, float_call_65, const_int32_23, "tmp9", label_entry_63); + InsertElementInst* packed_tmp12 = new InsertElementInst(packed_tmp9_66, float_call_65, const_int32_25, "tmp12", label_entry_63); + InsertElementInst* packed_tmp15_67 = new InsertElementInst(packed_tmp12, float_call_65, const_int32_24, "tmp15", label_entry_63); + new ReturnInst(packed_tmp15_67, label_entry_63); } // Function: kilp (func_kilp) { Function::arg_iterator args = func_kilp->arg_begin(); - Value* packed_val_68 = args++; - packed_val_68->setName("val"); + Value* packed_val_69 = args++; + packed_val_69->setName("val"); - BasicBlock* label_entry_69 = new BasicBlock("entry",func_kilp,0); + BasicBlock* label_entry_70 = new BasicBlock("entry",func_kilp,0); BasicBlock* label_lor_rhs = new BasicBlock("lor_rhs",func_kilp,0); - BasicBlock* label_lor_rhs6 = new BasicBlock("lor_rhs6",func_kilp,0); - BasicBlock* label_lor_rhs13 = new BasicBlock("lor_rhs13",func_kilp,0); - BasicBlock* label_UnifiedReturnBlock_70 = new BasicBlock("UnifiedReturnBlock",func_kilp,0); + BasicBlock* label_lor_rhs5 = new BasicBlock("lor_rhs5",func_kilp,0); + BasicBlock* label_lor_rhs11 = new BasicBlock("lor_rhs11",func_kilp,0); + BasicBlock* label_UnifiedReturnBlock_71 = new BasicBlock("UnifiedReturnBlock",func_kilp,0); - // Block entry (label_entry_69) - ExtractElementInst* float_tmp1_71 = new ExtractElementInst(packed_val_68, const_int32_19, "tmp1", label_entry_69); - FCmpInst* int1_cmp_72 = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp1_71, const_float_18, "cmp", label_entry_69); - new BranchInst(label_UnifiedReturnBlock_70, label_lor_rhs, int1_cmp_72, label_entry_69); + // Block entry (label_entry_70) + ExtractElementInst* float_tmp1_72 = new ExtractElementInst(packed_val_69, const_int32_19, "tmp1", label_entry_70); + FCmpInst* int1_cmp_73 = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp1_72, const_float_18, "cmp", label_entry_70); + new BranchInst(label_UnifiedReturnBlock_71, label_lor_rhs, int1_cmp_73, label_entry_70); // Block lor_rhs (label_lor_rhs) - ExtractElementInst* float_tmp3_74 = new ExtractElementInst(packed_val_68, const_int32_23, "tmp3", label_lor_rhs); - FCmpInst* int1_cmp5 = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp3_74, const_float_18, "cmp5", label_lor_rhs); - new BranchInst(label_UnifiedReturnBlock_70, label_lor_rhs6, int1_cmp5, label_lor_rhs); - - // Block lor_rhs6 (label_lor_rhs6) - ExtractElementInst* float_tmp8 = new ExtractElementInst(packed_val_68, const_int32_25, "tmp8", label_lor_rhs6); - FCmpInst* int1_cmp10 = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp8, const_float_18, "cmp10", label_lor_rhs6); - new BranchInst(label_UnifiedReturnBlock_70, label_lor_rhs13, int1_cmp10, label_lor_rhs6); - - // Block lor_rhs13 (label_lor_rhs13) - ExtractElementInst* float_tmp15 = new ExtractElementInst(packed_val_68, const_int32_24, "tmp15", label_lor_rhs13); - FCmpInst* int1_cmp17 = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp15, const_float_18, "cmp17", label_lor_rhs13); - CastInst* int32_retval = new ZExtInst(int1_cmp17, IntegerType::get(32), "retval", label_lor_rhs13); - new ReturnInst(int32_retval, label_lor_rhs13); - - // Block UnifiedReturnBlock (label_UnifiedReturnBlock_70) - new ReturnInst(const_int32_23, label_UnifiedReturnBlock_70); + ExtractElementInst* float_tmp3_75 = new ExtractElementInst(packed_val_69, const_int32_23, "tmp3", label_lor_rhs); + FCmpInst* int1_cmp4 = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp3_75, const_float_18, "cmp4", label_lor_rhs); + new BranchInst(label_UnifiedReturnBlock_71, label_lor_rhs5, int1_cmp4, label_lor_rhs); + + // Block lor_rhs5 (label_lor_rhs5) + ExtractElementInst* float_tmp7 = new ExtractElementInst(packed_val_69, const_int32_25, "tmp7", label_lor_rhs5); + FCmpInst* int1_cmp8 = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp7, const_float_18, "cmp8", label_lor_rhs5); + new BranchInst(label_UnifiedReturnBlock_71, label_lor_rhs11, int1_cmp8, label_lor_rhs5); + + // Block lor_rhs11 (label_lor_rhs11) + ExtractElementInst* float_tmp13 = new ExtractElementInst(packed_val_69, const_int32_24, "tmp13", label_lor_rhs11); + FCmpInst* int1_cmp14 = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp13, const_float_18, "cmp14", label_lor_rhs11); + CastInst* int32_retval = new ZExtInst(int1_cmp14, IntegerType::get(32), "retval", label_lor_rhs11); + new ReturnInst(int32_retval, label_lor_rhs11); + + // Block UnifiedReturnBlock (label_UnifiedReturnBlock_71) + new ReturnInst(const_int32_23, label_UnifiedReturnBlock_71); } diff --git a/src/mesa/pipe/llvm/instructions.cpp b/src/mesa/pipe/llvm/instructions.cpp index c8d1992587..55d39fa5f1 100644 --- a/src/mesa/pipe/llvm/instructions.cpp +++ b/src/mesa/pipe/llvm/instructions.cpp @@ -41,6 +41,7 @@ #include <llvm/Function.h> #include <llvm/InstrTypes.h> #include <llvm/Instructions.h> +#include <llvm/ParameterAttributes.h> #include <sstream> #include <fstream> @@ -103,13 +104,13 @@ const char * Instructions::name(const char *prefix) llvm::Value * Instructions::dp3(llvm::Value *in1, llvm::Value *in2) { Value *mulRes = mul(in1, in2); - ExtractElementInst *x = m_builder.CreateExtractElement(mulRes, + Value *x = m_builder.CreateExtractElement(mulRes, m_storage->constantInt(0), name("extractx")); - ExtractElementInst *y = m_builder.CreateExtractElement(mulRes, + Value *y = m_builder.CreateExtractElement(mulRes, m_storage->constantInt(1), name("extracty")); - ExtractElementInst *z = m_builder.CreateExtractElement(mulRes, + Value *z = m_builder.CreateExtractElement(mulRes, m_storage->constantInt(2), name("extractz")); Value *xy = m_builder.CreateAdd(x, y,name("xy")); @@ -127,13 +128,13 @@ llvm::Value *Instructions::callFSqrt(llvm::Value *val) FunctionType* fsqrtType = FunctionType::get( /*Result=*/Type::FloatTy, /*Params=*/fsqrtArgs, - /*isVarArg=*/false, - /*ParamAttrs=*/fsqrtPal); + /*isVarArg=*/false); m_llvmFSqrt = new Function( /*Type=*/fsqrtType, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"llvm.sqrt.f32", m_mod); m_llvmFSqrt->setCallingConv(CallingConv::C); + m_llvmFSqrt->setParamAttrs(fsqrtPal); } CallInst *call = m_builder.CreateCall(m_llvmFSqrt, val, name("sqrt")); @@ -144,9 +145,9 @@ llvm::Value *Instructions::callFSqrt(llvm::Value *val) llvm::Value * Instructions::rsq(llvm::Value *in1) { - ExtractElementInst *x = m_builder.CreateExtractElement(in1, - m_storage->constantInt(0), - name("extractx")); + Value *x = m_builder.CreateExtractElement(in1, + m_storage->constantInt(0), + name("extractx")); Value *abs = callFAbs(x); Value *sqrt = callFSqrt(abs); @@ -161,9 +162,9 @@ llvm::Value * Instructions::vectorFromVals(llvm::Value *x, llvm::Value *y, llvm::Value *z, llvm::Value *w) { Constant *const_vec = Constant::getNullValue(m_floatVecType); - InsertElementInst *res = m_builder.CreateInsertElement(const_vec, x, - m_storage->constantInt(0), - name("vecx")); + Value *res = m_builder.CreateInsertElement(const_vec, x, + m_storage->constantInt(0), + name("vecx")); res = m_builder.CreateInsertElement(res, y, m_storage->constantInt(1), name("vecxy")); res = m_builder.CreateInsertElement(res, z, m_storage->constantInt(2), @@ -184,13 +185,13 @@ llvm::Value *Instructions::callFAbs(llvm::Value *val) FunctionType* fabsType = FunctionType::get( /*Result=*/Type::FloatTy, /*Params=*/fabsArgs, - /*isVarArg=*/false, - /*ParamAttrs=*/fabsPal); + /*isVarArg=*/false); m_llvmFAbs = new Function( /*Type=*/fabsType, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"fabs", m_mod); m_llvmFAbs->setCallingConv(CallingConv::C); + m_llvmFAbs->setParamAttrs(fabsPal); } CallInst *call = m_builder.CreateCall(m_llvmFAbs, val, name("fabs")); @@ -227,13 +228,13 @@ llvm::Value * Instructions::callPow(llvm::Value *val1, llvm::Value *val2) FunctionType* powType = FunctionType::get( /*Result=*/Type::FloatTy, /*Params=*/powArgs, - /*isVarArg=*/false, - /*ParamAttrs=*/powPal); + /*isVarArg=*/false); m_llvmPow = new Function( /*Type=*/powType, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"llvm.pow.f32", m_mod); m_llvmPow->setCallingConv(CallingConv::C); + m_llvmPow->setParamAttrs(powPal); } std::vector<Value*> params; params.push_back(val1); @@ -247,21 +248,21 @@ llvm::Value * Instructions::callPow(llvm::Value *val1, llvm::Value *val2) llvm::Value * Instructions::pow(llvm::Value *in1, llvm::Value *in2) { - ExtractElementInst *x1 = m_builder.CreateExtractElement(in1, - m_storage->constantInt(0), - name("x1")); - ExtractElementInst *x2 = m_builder.CreateExtractElement(in2, - m_storage->constantInt(0), - name("x2")); + Value *x1 = m_builder.CreateExtractElement(in1, + m_storage->constantInt(0), + name("x1")); + Value *x2 = m_builder.CreateExtractElement(in2, + m_storage->constantInt(0), + name("x2")); llvm::Value *val = callPow(x1, x2); return vectorFromVals(val, val, val, val); } llvm::Value * Instructions::rcp(llvm::Value *in1) { - ExtractElementInst *x1 = m_builder.CreateExtractElement(in1, - m_storage->constantInt(0), - name("x1")); + Value *x1 = m_builder.CreateExtractElement(in1, + m_storage->constantInt(0), + name("x1")); Value *res = m_builder.CreateFDiv(ConstantFP::get(Type::FloatTy, APFloat(1.f)), x1, name("rcp")); @@ -290,18 +291,18 @@ llvm::Value * Instructions::dph(llvm::Value *in1, llvm::Value *in2) llvm::Value * Instructions::dst(llvm::Value *in1, llvm::Value *in2) { - ExtractElementInst *y1 = m_builder.CreateExtractElement(in1, - m_storage->constantInt(1), - name("y1")); - ExtractElementInst *z = m_builder.CreateExtractElement(in1, - m_storage->constantInt(2), - name("z")); - ExtractElementInst *y2 = m_builder.CreateExtractElement(in2, - m_storage->constantInt(1), - name("y2")); - ExtractElementInst *w = m_builder.CreateExtractElement(in2, - m_storage->constantInt(3), - name("w")); + Value *y1 = m_builder.CreateExtractElement(in1, + m_storage->constantInt(1), + name("y1")); + Value *z = m_builder.CreateExtractElement(in1, + m_storage->constantInt(2), + name("z")); + Value *y2 = m_builder.CreateExtractElement(in2, + m_storage->constantInt(1), + name("y2")); + Value *w = m_builder.CreateExtractElement(in2, + m_storage->constantInt(3), + name("w")); Value *ry = m_builder.CreateMul(y1, y2, name("tyuy")); return vectorFromVals(ConstantFP::get(Type::FloatTy, APFloat(1.f)), ry, z, w); @@ -326,13 +327,13 @@ llvm::Value * Instructions::callFloor(llvm::Value *val) FunctionType* floorType = FunctionType::get( /*Result=*/Type::FloatTy, /*Params=*/floorArgs, - /*isVarArg=*/false, - /*ParamAttrs=*/floorPal); + /*isVarArg=*/false); m_llvmFloor = new Function( /*Type=*/floorType, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"floorf", m_mod); m_llvmFloor->setCallingConv(CallingConv::C); + m_llvmFloor->setParamAttrs(floorPal); } CallInst *call = m_builder.CreateCall(m_llvmFloor, val, name("floorf")); @@ -369,13 +370,13 @@ llvm::Value * Instructions::callFLog(llvm::Value *val) FunctionType* flogType = FunctionType::get( /*Result=*/Type::FloatTy, /*Params=*/flogArgs, - /*isVarArg=*/false, - /*ParamAttrs=*/flogPal); + /*isVarArg=*/false); m_llvmFlog = new Function( /*Type=*/flogType, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"logf", m_mod); m_llvmFlog->setCallingConv(CallingConv::C); + m_llvmFlog->setParamAttrs(flogPal); } CallInst *call = m_builder.CreateCall(m_llvmFlog, val, name("logf")); @@ -399,20 +400,20 @@ llvm::Value * Instructions::min(llvm::Value *in1, llvm::Value *in2) std::vector<llvm::Value*> vec2 = extractVector(in2); Value *xcmp = m_builder.CreateFCmpOLT(vec1[0], vec2[0], name("xcmp")); - SelectInst *selx = m_builder.CreateSelect(xcmp, vec1[0], vec2[0], - name("selx")); + Value *selx = m_builder.CreateSelect(xcmp, vec1[0], vec2[0], + name("selx")); Value *ycmp = m_builder.CreateFCmpOLT(vec1[1], vec2[1], name("ycmp")); - SelectInst *sely = m_builder.CreateSelect(ycmp, vec1[1], vec2[1], - name("sely")); + Value *sely = m_builder.CreateSelect(ycmp, vec1[1], vec2[1], + name("sely")); Value *zcmp = m_builder.CreateFCmpOLT(vec1[2], vec2[2], name("zcmp")); - SelectInst *selz = m_builder.CreateSelect(zcmp, vec1[2], vec2[2], - name("selz")); + Value *selz = m_builder.CreateSelect(zcmp, vec1[2], vec2[2], + name("selz")); Value *wcmp = m_builder.CreateFCmpOLT(vec1[3], vec2[3], name("wcmp")); - SelectInst *selw = m_builder.CreateSelect(wcmp, vec1[3], vec2[3], - name("selw")); + Value *selw = m_builder.CreateSelect(wcmp, vec1[3], vec2[3], + name("selw")); return vectorFromVals(selx, sely, selz, selw); } @@ -423,24 +424,24 @@ llvm::Value * Instructions::max(llvm::Value *in1, llvm::Value *in2) std::vector<llvm::Value*> vec2 = extractVector(in2); Value *xcmp = m_builder.CreateFCmpOGT(vec1[0], vec2[0], - name("xcmp")); - SelectInst *selx = m_builder.CreateSelect(xcmp, vec1[0], vec2[0], - name("selx")); + name("xcmp")); + Value *selx = m_builder.CreateSelect(xcmp, vec1[0], vec2[0], + name("selx")); Value *ycmp = m_builder.CreateFCmpOGT(vec1[1], vec2[1], - name("ycmp")); - SelectInst *sely = m_builder.CreateSelect(ycmp, vec1[1], vec2[1], - name("sely")); + name("ycmp")); + Value *sely = m_builder.CreateSelect(ycmp, vec1[1], vec2[1], + name("sely")); Value *zcmp = m_builder.CreateFCmpOGT(vec1[2], vec2[2], - name("zcmp")); - SelectInst *selz = m_builder.CreateSelect(zcmp, vec1[2], vec2[2], - name("selz")); + name("zcmp")); + Value *selz = m_builder.CreateSelect(zcmp, vec1[2], vec2[2], + name("selz")); Value *wcmp = m_builder.CreateFCmpOGT(vec1[3], vec2[3], - name("wcmp")); - SelectInst *selw = m_builder.CreateSelect(wcmp, vec1[3], vec2[3], - name("selw")); + name("wcmp")); + Value *selw = m_builder.CreateSelect(wcmp, vec1[3], vec2[3], + name("selw")); return vectorFromVals(selx, sely, selz, selw); } @@ -474,17 +475,17 @@ void Instructions::printVector(llvm::Value *val) func_printf = declarePrintf(); assert(func_printf); std::vector<llvm::Value*> vec = extractVector(val); - CastInst *dx = m_builder.CreateFPExt(vec[0], Type::DoubleTy, name("dx")); - CastInst *dy = m_builder.CreateFPExt(vec[1], Type::DoubleTy, name("dy")); - CastInst *dz = m_builder.CreateFPExt(vec[2], Type::DoubleTy, name("dz")); - CastInst *dw = m_builder.CreateFPExt(vec[3], Type::DoubleTy, name("dw")); + Value *dx = m_builder.CreateFPExt(vec[0], Type::DoubleTy, name("dx")); + Value *dy = m_builder.CreateFPExt(vec[1], Type::DoubleTy, name("dy")); + Value *dz = m_builder.CreateFPExt(vec[2], Type::DoubleTy, name("dz")); + Value *dw = m_builder.CreateFPExt(vec[3], Type::DoubleTy, name("dw")); std::vector<Value*> params; params.push_back(m_fmtPtr); params.push_back(dx); params.push_back(dy); params.push_back(dz); params.push_back(dw); - CallInst* call = m_builder.CreateCall(func_printf, params.begin(), params.end(), + CallInst *call = m_builder.CreateCall(func_printf, params.begin(), params.end(), name("printf")); call->setCallingConv(CallingConv::C); call->setTailCall(true); @@ -497,13 +498,13 @@ llvm::Function * Instructions::declarePrintf() FunctionType* funcTy = FunctionType::get( /*Result=*/IntegerType::get(32), /*Params=*/args, - /*isVarArg=*/true, - /*ParamAttrs=*/params); + /*isVarArg=*/true); Function* func_printf = new Function( /*Type=*/funcTy, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"printf", m_mod); func_printf->setCallingConv(CallingConv::C); + func_printf->setParamAttrs(params); return func_printf; } @@ -516,16 +517,16 @@ llvm::Value * Instructions::sgt(llvm::Value *in1, llvm::Value *in2) std::vector<llvm::Value*> vec1 = extractVector(in1); std::vector<llvm::Value*> vec2 = extractVector(in2); Value *xcmp = m_builder.CreateFCmpOGT(vec1[0], vec2[0], name("xcmp")); - SelectInst *x = m_builder.CreateSelect(xcmp, const1f, const0f, name("xsel")); + Value *x = m_builder.CreateSelect(xcmp, const1f, const0f, name("xsel")); Value *ycmp = m_builder.CreateFCmpOGT(vec1[1], vec2[1], name("ycmp")); - SelectInst *y = m_builder.CreateSelect(ycmp, const1f, const0f, name("ysel")); + Value *y = m_builder.CreateSelect(ycmp, const1f, const0f, name("ysel")); Value *zcmp = m_builder.CreateFCmpOGT(vec1[2], vec2[2], name("zcmp")); - SelectInst *z = m_builder.CreateSelect(zcmp, const1f, const0f, name("zsel")); + Value *z = m_builder.CreateSelect(zcmp, const1f, const0f, name("zsel")); Value *wcmp = m_builder.CreateFCmpOGT(vec1[3], vec2[3], name("wcmp")); - SelectInst *w = m_builder.CreateSelect(wcmp, const1f, const0f, name("wsel")); + Value *w = m_builder.CreateSelect(wcmp, const1f, const0f, name("wsel")); return vectorFromVals(x, y, z, w); } @@ -538,16 +539,16 @@ llvm::Value * Instructions::sge(llvm::Value *in1, llvm::Value *in2) std::vector<llvm::Value*> vec2 = extractVector(in2); Value *xcmp = m_builder.CreateFCmpOGE(vec1[0], vec2[0], name("xcmp")); - SelectInst *x = m_builder.CreateSelect(xcmp, const1f, const0f, name("xsel")); + Value *x = m_builder.CreateSelect(xcmp, const1f, const0f, name("xsel")); Value *ycmp = m_builder.CreateFCmpOGE(vec1[1], vec2[1], name("ycmp")); - SelectInst *y = m_builder.CreateSelect(ycmp, const1f, const0f, name("ysel")); + Value *y = m_builder.CreateSelect(ycmp, const1f, const0f, name("ysel")); Value *zcmp = m_builder.CreateFCmpOGE(vec1[2], vec2[2], name("zcmp")); - SelectInst *z = m_builder.CreateSelect(zcmp, const1f, const0f, name("zsel")); + Value *z = m_builder.CreateSelect(zcmp, const1f, const0f, name("zsel")); Value *wcmp = m_builder.CreateFCmpOGE(vec1[3], vec2[3], name("wcmp")); - SelectInst *w = m_builder.CreateSelect(wcmp, const1f, const0f, name("wsel")); + Value *w = m_builder.CreateSelect(wcmp, const1f, const0f, name("wsel")); return vectorFromVals(x, y, z, w); } @@ -562,41 +563,41 @@ llvm::Value * Instructions::slt(llvm::Value *in1, llvm::Value *in2) std::vector<llvm::Value*> vec2 = extractVector(in2); Value *xcmp = m_builder.CreateFCmpOLT(vec1[0], vec2[0], name("xcmp")); - SelectInst *x = m_builder.CreateSelect(xcmp, const1f, const0f, name("xsel")); + Value *x = m_builder.CreateSelect(xcmp, const1f, const0f, name("xsel")); Value *ycmp = m_builder.CreateFCmpOLT(vec1[1], vec2[1], name("ycmp")); - SelectInst *y = m_builder.CreateSelect(ycmp, const1f, const0f, name("ysel")); + Value *y = m_builder.CreateSelect(ycmp, const1f, const0f, name("ysel")); Value *zcmp = m_builder.CreateFCmpOLT(vec1[2], vec2[2], name("zcmp")); - SelectInst *z = m_builder.CreateSelect(zcmp, const1f, const0f, name("zsel")); + Value *z = m_builder.CreateSelect(zcmp, const1f, const0f, name("zsel")); Value *wcmp = m_builder.CreateFCmpOLT(vec1[3], vec2[3], name("wcmp")); - SelectInst *w = m_builder.CreateSelect(wcmp, const1f, const0f, name("wsel")); + Value *w = m_builder.CreateSelect(wcmp, const1f, const0f, name("wsel")); return vectorFromVals(x, y, z, w); } llvm::Value * Instructions::cross(llvm::Value *in1, llvm::Value *in2) { - ExtractElementInst *x1 = m_builder.CreateExtractElement(in1, - m_storage->constantInt(0), - name("x1")); - ExtractElementInst *y1 = m_builder.CreateExtractElement(in1, - m_storage->constantInt(1), - name("y1")); - ExtractElementInst *z1 = m_builder.CreateExtractElement(in1, - m_storage->constantInt(2), - name("z1")); - - ExtractElementInst *x2 = m_builder.CreateExtractElement(in2, - m_storage->constantInt(0), - name("x2")); - ExtractElementInst *y2 = m_builder.CreateExtractElement(in2, - m_storage->constantInt(1), - name("y2")); - ExtractElementInst *z2 = m_builder.CreateExtractElement(in2, - m_storage->constantInt(2), - name("z2")); + Value *x1 = m_builder.CreateExtractElement(in1, + m_storage->constantInt(0), + name("x1")); + Value *y1 = m_builder.CreateExtractElement(in1, + m_storage->constantInt(1), + name("y1")); + Value *z1 = m_builder.CreateExtractElement(in1, + m_storage->constantInt(2), + name("z1")); + + Value *x2 = m_builder.CreateExtractElement(in2, + m_storage->constantInt(0), + name("x2")); + Value *y2 = m_builder.CreateExtractElement(in2, + m_storage->constantInt(1), + name("y2")); + Value *z2 = m_builder.CreateExtractElement(in2, + m_storage->constantInt(2), + name("z2")); Value *y1z2 = mul(y1, z2); Value *z1y2 = mul(z1, y2); @@ -631,8 +632,8 @@ void Instructions::ifop(llvm::Value *in) Constant *float0 = Constant::getNullValue(Type::FloatTy); - ExtractElementInst *x = m_builder.CreateExtractElement(in, m_storage->constantInt(0), - name("extractx")); + Value *x = m_builder.CreateExtractElement(in, m_storage->constantInt(0), + name("extractx")); Value *xcmp = m_builder.CreateFCmpUNE(x, float0, name("xcmp")); m_builder.CreateCondBr(xcmp, ifthen, ifend); //m_builder.SetInsertPoint(yblock); @@ -708,22 +709,22 @@ void Instructions::brk() llvm::Value * Instructions::trunc(llvm::Value *in) { std::vector<llvm::Value*> vec = extractVector(in); - CastInst *icastx = m_builder.CreateFPToSI(vec[0], IntegerType::get(32), - name("ftoix")); - CastInst *icasty = m_builder.CreateFPToSI(vec[1], IntegerType::get(32), - name("ftoiy")); - CastInst *icastz = m_builder.CreateFPToSI(vec[2], IntegerType::get(32), - name("ftoiz")); - CastInst *icastw = m_builder.CreateFPToSI(vec[3], IntegerType::get(32), - name("ftoiw")); - CastInst *fx = m_builder.CreateSIToFP(icastx, Type::FloatTy, - name("fx")); - CastInst *fy = m_builder.CreateSIToFP(icasty, Type::FloatTy, - name("fy")); - CastInst *fz = m_builder.CreateSIToFP(icastz, Type::FloatTy, - name("fz")); - CastInst *fw = m_builder.CreateSIToFP(icastw, Type::FloatTy, - name("fw")); + Value *icastx = m_builder.CreateFPToSI(vec[0], IntegerType::get(32), + name("ftoix")); + Value *icasty = m_builder.CreateFPToSI(vec[1], IntegerType::get(32), + name("ftoiy")); + Value *icastz = m_builder.CreateFPToSI(vec[2], IntegerType::get(32), + name("ftoiz")); + Value *icastw = m_builder.CreateFPToSI(vec[3], IntegerType::get(32), + name("ftoiw")); + Value *fx = m_builder.CreateSIToFP(icastx, Type::FloatTy, + name("fx")); + Value *fy = m_builder.CreateSIToFP(icasty, Type::FloatTy, + name("fy")); + Value *fz = m_builder.CreateSIToFP(icastz, Type::FloatTy, + name("fz")); + Value *fw = m_builder.CreateSIToFP(icastw, Type::FloatTy, + name("fw")); return vectorFromVals(fx, fy, fz, fw); } @@ -743,7 +744,7 @@ void Instructions::cal(int label, llvm::Value *input) llvm::Function * Instructions::declareFunc(int label) { - PointerType *vecPtr = PointerType::get(m_floatVecType); + PointerType *vecPtr = PointerType::getUnqual(m_floatVecType); std::vector<const Type*> args; args.push_back(vecPtr); args.push_back(vecPtr); @@ -753,14 +754,14 @@ llvm::Function * Instructions::declareFunc(int label) FunctionType *funcType = FunctionType::get( /*Result=*/Type::VoidTy, /*Params=*/args, - /*isVarArg=*/false, - /*ParamAttrs=*/params); + /*isVarArg=*/false); std::string name = createFuncName(label); Function *func = new Function( /*Type=*/funcType, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/name.c_str(), m_mod); func->setCallingConv(CallingConv::C); + func->setParamAttrs(params); return func; } diff --git a/src/mesa/pipe/llvm/llvm_base_shader.cpp b/src/mesa/pipe/llvm/llvm_base_shader.cpp index 85fa389d79..b574b550ae 100644 --- a/src/mesa/pipe/llvm/llvm_base_shader.cpp +++ b/src/mesa/pipe/llvm/llvm_base_shader.cpp @@ -4,14 +4,14 @@ Module* createBaseShader() { // Module Construction Module* mod = new Module("Shader"); - mod->setDataLayout(""); - mod->setTargetTriple("i686-apple-darwin9"); + mod->setDataLayout("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"); + mod->setTargetTriple("i686-pc-linux-gnu"); // Type Definitions std::vector<const Type*>StructTy_struct_ShaderInput_fields; VectorType* VectorTy_1 = VectorType::get(Type::FloatTy, 4); - PointerType* PointerTy_0 = PointerType::get(VectorTy_1); + PointerType* PointerTy_0 = PointerType::get(VectorTy_1, 0); StructTy_struct_ShaderInput_fields.push_back(PointerTy_0); StructTy_struct_ShaderInput_fields.push_back(PointerTy_0); @@ -21,9 +21,6 @@ Module* createBaseShader() { StructType* StructTy_struct_ShaderInput = StructType::get(StructTy_struct_ShaderInput_fields, /*isPacked=*/false); mod->addTypeName("struct.ShaderInput", StructTy_struct_ShaderInput); - OpaqueType* OpaqueTy_struct_pipe_mipmap_tree = OpaqueType::get(); - mod->addTypeName("struct.pipe_mipmap_tree", OpaqueTy_struct_pipe_mipmap_tree); - OpaqueType* OpaqueTy_struct_pipe_sampler_state = OpaqueType::get(); mod->addTypeName("struct.pipe_sampler_state", OpaqueTy_struct_pipe_sampler_state); @@ -31,199 +28,217 @@ Module* createBaseShader() { mod->addTypeName("struct.softpipe_tile_cache", OpaqueTy_struct_softpipe_tile_cache); std::vector<const Type*>StructTy_struct_tgsi_sampler_fields; - PointerType* PointerTy_2 = PointerType::get(OpaqueTy_struct_pipe_sampler_state); + PointerType* PointerTy_2 = PointerType::get(OpaqueTy_struct_pipe_sampler_state, 0); StructTy_struct_tgsi_sampler_fields.push_back(PointerTy_2); - PointerType* PointerTy_3 = PointerType::get(OpaqueTy_struct_pipe_mipmap_tree); - - StructTy_struct_tgsi_sampler_fields.push_back(PointerTy_3); - std::vector<const Type*>FuncTy_5_args; + std::vector<const Type*>FuncTy_4_args; PATypeHolder StructTy_struct_tgsi_sampler_fwd = OpaqueType::get(); - PointerType* PointerTy_6 = PointerType::get(StructTy_struct_tgsi_sampler_fwd); + PointerType* PointerTy_5 = PointerType::get(StructTy_struct_tgsi_sampler_fwd, 0); - FuncTy_5_args.push_back(PointerTy_6); - PointerType* PointerTy_7 = PointerType::get(Type::FloatTy); + FuncTy_4_args.push_back(PointerTy_5); + PointerType* PointerTy_6 = PointerType::get(Type::FloatTy, 0); - FuncTy_5_args.push_back(PointerTy_7); - FuncTy_5_args.push_back(PointerTy_7); - FuncTy_5_args.push_back(PointerTy_7); - FuncTy_5_args.push_back(Type::FloatTy); - ArrayType* ArrayTy_9 = ArrayType::get(Type::FloatTy, 4); + FuncTy_4_args.push_back(PointerTy_6); + FuncTy_4_args.push_back(PointerTy_6); + FuncTy_4_args.push_back(PointerTy_6); + FuncTy_4_args.push_back(Type::FloatTy); + ArrayType* ArrayTy_8 = ArrayType::get(Type::FloatTy, 4); - PointerType* PointerTy_8 = PointerType::get(ArrayTy_9); + PointerType* PointerTy_7 = PointerType::get(ArrayTy_8, 0); - FuncTy_5_args.push_back(PointerTy_8); - ParamAttrsList *FuncTy_5_PAL = 0; - FunctionType* FuncTy_5 = FunctionType::get( + FuncTy_4_args.push_back(PointerTy_7); + FunctionType* FuncTy_4 = FunctionType::get( /*Result=*/Type::VoidTy, - /*Params=*/FuncTy_5_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_5_PAL); + /*Params=*/FuncTy_4_args, + /*isVarArg=*/false); - PointerType* PointerTy_4 = PointerType::get(FuncTy_5); + PointerType* PointerTy_3 = PointerType::get(FuncTy_4, 0); - StructTy_struct_tgsi_sampler_fields.push_back(PointerTy_4); - PointerType* PointerTy_10 = PointerType::get(IntegerType::get(8)); + StructTy_struct_tgsi_sampler_fields.push_back(PointerTy_3); + PointerType* PointerTy_9 = PointerType::get(IntegerType::get(8), 0); - StructTy_struct_tgsi_sampler_fields.push_back(PointerTy_10); - PointerType* PointerTy_11 = PointerType::get(OpaqueTy_struct_softpipe_tile_cache); + StructTy_struct_tgsi_sampler_fields.push_back(PointerTy_9); + PointerType* PointerTy_10 = PointerType::get(OpaqueTy_struct_softpipe_tile_cache, 0); - StructTy_struct_tgsi_sampler_fields.push_back(PointerTy_11); + StructTy_struct_tgsi_sampler_fields.push_back(PointerTy_10); StructType* StructTy_struct_tgsi_sampler = StructType::get(StructTy_struct_tgsi_sampler_fields, /*isPacked=*/false); mod->addTypeName("struct.tgsi_sampler", StructTy_struct_tgsi_sampler); cast<OpaqueType>(StructTy_struct_tgsi_sampler_fwd.get())->refineAbstractTypeTo(StructTy_struct_tgsi_sampler); StructTy_struct_tgsi_sampler = cast<StructType>(StructTy_struct_tgsi_sampler_fwd.get()); - std::vector<const Type*>FuncTy_12_args; - ArrayType* ArrayTy_14 = ArrayType::get(VectorTy_1, 16); + std::vector<const Type*>FuncTy_11_args; + ArrayType* ArrayTy_13 = ArrayType::get(VectorTy_1, 16); - PointerType* PointerTy_13 = PointerType::get(ArrayTy_14); + PointerType* PointerTy_12 = PointerType::get(ArrayTy_13, 0); - FuncTy_12_args.push_back(PointerTy_13); - ArrayType* ArrayTy_16 = ArrayType::get(ArrayTy_9, 16); + FuncTy_11_args.push_back(PointerTy_12); + ArrayType* ArrayTy_15 = ArrayType::get(ArrayTy_8, 16); - PointerType* PointerTy_15 = PointerType::get(ArrayTy_16); + PointerType* PointerTy_14 = PointerType::get(ArrayTy_15, 0); - FuncTy_12_args.push_back(PointerTy_15); - FuncTy_12_args.push_back(IntegerType::get(32)); - FuncTy_12_args.push_back(IntegerType::get(32)); - ParamAttrsList *FuncTy_12_PAL = 0; - FunctionType* FuncTy_12 = FunctionType::get( + FuncTy_11_args.push_back(PointerTy_14); + FuncTy_11_args.push_back(IntegerType::get(32)); + FuncTy_11_args.push_back(IntegerType::get(32)); + FunctionType* FuncTy_11 = FunctionType::get( /*Result=*/Type::VoidTy, - /*Params=*/FuncTy_12_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_12_PAL); + /*Params=*/FuncTy_11_args, + /*isVarArg=*/false); + + std::vector<const Type*>FuncTy_16_args; + FuncTy_16_args.push_back(PointerTy_0); + FuncTy_16_args.push_back(PointerTy_7); + FuncTy_16_args.push_back(IntegerType::get(32)); + FunctionType* FuncTy_16 = FunctionType::get( + /*Result=*/Type::VoidTy, + /*Params=*/FuncTy_16_args, + /*isVarArg=*/false); std::vector<const Type*>FuncTy_17_args; + FuncTy_17_args.push_back(PointerTy_7); FuncTy_17_args.push_back(PointerTy_0); - FuncTy_17_args.push_back(PointerTy_8); FuncTy_17_args.push_back(IntegerType::get(32)); - ParamAttrsList *FuncTy_17_PAL = 0; FunctionType* FuncTy_17 = FunctionType::get( /*Result=*/Type::VoidTy, /*Params=*/FuncTy_17_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_17_PAL); + /*isVarArg=*/false); std::vector<const Type*>FuncTy_18_args; - FuncTy_18_args.push_back(PointerTy_8); - FuncTy_18_args.push_back(PointerTy_0); + FuncTy_18_args.push_back(PointerTy_12); + FuncTy_18_args.push_back(PointerTy_12); + FuncTy_18_args.push_back(PointerTy_7); + FuncTy_18_args.push_back(IntegerType::get(32)); + FuncTy_18_args.push_back(IntegerType::get(32)); + FuncTy_18_args.push_back(IntegerType::get(32)); FuncTy_18_args.push_back(IntegerType::get(32)); - ParamAttrsList *FuncTy_18_PAL = 0; FunctionType* FuncTy_18 = FunctionType::get( /*Result=*/Type::VoidTy, /*Params=*/FuncTy_18_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_18_PAL); - - std::vector<const Type*>FuncTy_19_args; - FuncTy_19_args.push_back(PointerTy_13); - FuncTy_19_args.push_back(PointerTy_13); - FuncTy_19_args.push_back(PointerTy_8); - FuncTy_19_args.push_back(IntegerType::get(32)); - FuncTy_19_args.push_back(IntegerType::get(32)); - FuncTy_19_args.push_back(IntegerType::get(32)); - FuncTy_19_args.push_back(IntegerType::get(32)); - ParamAttrsList *FuncTy_19_PAL = 0; - FunctionType* FuncTy_19 = FunctionType::get( - /*Result=*/Type::VoidTy, - /*Params=*/FuncTy_19_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_19_PAL); + /*isVarArg=*/false); - ArrayType* ArrayTy_21 = ArrayType::get(VectorTy_1, 32); + ArrayType* ArrayTy_20 = ArrayType::get(VectorTy_1, 32); - PointerType* PointerTy_20 = PointerType::get(ArrayTy_21); + PointerType* PointerTy_19 = PointerType::get(ArrayTy_20, 0); - ArrayType* ArrayTy_23 = ArrayType::get(VectorTy_1, 128); + ArrayType* ArrayTy_22 = ArrayType::get(VectorTy_1, 128); - PointerType* PointerTy_22 = PointerType::get(ArrayTy_23); + PointerType* PointerTy_21 = PointerType::get(ArrayTy_22, 0); - PointerType* PointerTy_24 = PointerType::get(StructTy_struct_ShaderInput); + PointerType* PointerTy_23 = PointerType::get(StructTy_struct_ShaderInput, 0); - PointerType* PointerTy_25 = PointerType::get(PointerTy_0); + PointerType* PointerTy_24 = PointerType::get(PointerTy_0, 0); + + std::vector<const Type*>FuncTy_26_args; + FuncTy_26_args.push_back(PointerTy_23); + FunctionType* FuncTy_26 = FunctionType::get( + /*Result=*/Type::VoidTy, + /*Params=*/FuncTy_26_args, + /*isVarArg=*/false); + + PointerType* PointerTy_25 = PointerType::get(FuncTy_26, 0); std::vector<const Type*>FuncTy_27_args; - FuncTy_27_args.push_back(PointerTy_24); - ParamAttrsList *FuncTy_27_PAL = 0; + FuncTy_27_args.push_back(Type::FloatTy); + FuncTy_27_args.push_back(Type::FloatTy); + FuncTy_27_args.push_back(PointerTy_12); + FuncTy_27_args.push_back(PointerTy_12); + FuncTy_27_args.push_back(IntegerType::get(32)); + FuncTy_27_args.push_back(PointerTy_7); + FuncTy_27_args.push_back(IntegerType::get(32)); + FuncTy_27_args.push_back(PointerTy_5); FunctionType* FuncTy_27 = FunctionType::get( - /*Result=*/Type::VoidTy, - /*Params=*/FuncTy_27_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_27_PAL); - - PointerType* PointerTy_26 = PointerType::get(FuncTy_27); - - std::vector<const Type*>FuncTy_28_args; - FuncTy_28_args.push_back(Type::FloatTy); - FuncTy_28_args.push_back(Type::FloatTy); - FuncTy_28_args.push_back(PointerTy_13); - FuncTy_28_args.push_back(PointerTy_13); - FuncTy_28_args.push_back(IntegerType::get(32)); - FuncTy_28_args.push_back(PointerTy_8); - FuncTy_28_args.push_back(IntegerType::get(32)); - FuncTy_28_args.push_back(PointerTy_6); - PointerType* PointerTy_29 = PointerType::get(IntegerType::get(32)); - - FuncTy_28_args.push_back(PointerTy_29); - ParamAttrsList *FuncTy_28_PAL = 0; - FunctionType* FuncTy_28 = FunctionType::get( /*Result=*/IntegerType::get(32), - /*Params=*/FuncTy_28_args, - /*isVarArg=*/false, - /*ParamAttrs=*/FuncTy_28_PAL); + /*Params=*/FuncTy_27_args, + /*isVarArg=*/false); + + PointerType* PointerTy_28 = PointerType::get(IntegerType::get(32), 0); // Function Declarations Function* func_from_array = new Function( - /*Type=*/FuncTy_12, + /*Type=*/FuncTy_11, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"from_array", mod); func_from_array->setCallingConv(CallingConv::C); + const ParamAttrsList *func_from_array_PAL = 0; + { + ParamAttrsVector Attrs; + ParamAttrsWithIndex PAWI; + PAWI.index = 0; PAWI.attrs = 0 | ParamAttr::NoUnwind; + Attrs.push_back(PAWI); + func_from_array_PAL = ParamAttrsList::get(Attrs); + + } + func_from_array->setParamAttrs(func_from_array_PAL); Function* func_from_consts = new Function( - /*Type=*/FuncTy_17, + /*Type=*/FuncTy_16, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"from_consts", mod); func_from_consts->setCallingConv(CallingConv::C); + const ParamAttrsList *func_from_consts_PAL = 0; + { + ParamAttrsVector Attrs; + ParamAttrsWithIndex PAWI; + PAWI.index = 0; PAWI.attrs = 0 | ParamAttr::NoUnwind; + Attrs.push_back(PAWI); + func_from_consts_PAL = ParamAttrsList::get(Attrs); + + } + func_from_consts->setParamAttrs(func_from_consts_PAL); Function* func_to_array = new Function( - /*Type=*/FuncTy_18, + /*Type=*/FuncTy_17, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"to_array", mod); func_to_array->setCallingConv(CallingConv::C); + const ParamAttrsList *func_to_array_PAL = 0; + { + ParamAttrsVector Attrs; + ParamAttrsWithIndex PAWI; + PAWI.index = 0; PAWI.attrs = 0 | ParamAttr::NoUnwind; + Attrs.push_back(PAWI); + func_to_array_PAL = ParamAttrsList::get(Attrs); + + } + func_to_array->setParamAttrs(func_to_array_PAL); Function* func_run_vertex_shader = new Function( - /*Type=*/FuncTy_19, + /*Type=*/FuncTy_18, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"run_vertex_shader", mod); func_run_vertex_shader->setCallingConv(CallingConv::C); + const ParamAttrsList *func_run_vertex_shader_PAL = 0; + func_run_vertex_shader->setParamAttrs(func_run_vertex_shader_PAL); Function* func_execute_shader = new Function( - /*Type=*/FuncTy_27, + /*Type=*/FuncTy_26, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"execute_shader", mod); // (external, no body) func_execute_shader->setCallingConv(CallingConv::C); + const ParamAttrsList *func_execute_shader_PAL = 0; + func_execute_shader->setParamAttrs(func_execute_shader_PAL); Function* func_run_fragment_shader = new Function( - /*Type=*/FuncTy_28, + /*Type=*/FuncTy_27, /*Linkage=*/GlobalValue::ExternalLinkage, /*Name=*/"run_fragment_shader", mod); func_run_fragment_shader->setCallingConv(CallingConv::C); + const ParamAttrsList *func_run_fragment_shader_PAL = 0; + func_run_fragment_shader->setParamAttrs(func_run_fragment_shader_PAL); // Global Variable Declarations // Constant Definitions - Constant* const_int32_30 = Constant::getNullValue(IntegerType::get(32)); - UndefValue* const_packed_31 = UndefValue::get(VectorTy_1); - ConstantInt* const_int32_32 = ConstantInt::get(APInt(32, "1", 10)); + Constant* const_int32_29 = Constant::getNullValue(IntegerType::get(32)); + ConstantInt* const_int32_30 = ConstantInt::get(APInt(32, "-1", 10)); + ConstantInt* const_int32_31 = ConstantInt::get(APInt(32, "1", 10)); + UndefValue* const_packed_32 = UndefValue::get(VectorTy_1); ConstantInt* const_int32_33 = ConstantInt::get(APInt(32, "2", 10)); ConstantInt* const_int32_34 = ConstantInt::get(APInt(32, "3", 10)); ConstantInt* const_int32_35 = ConstantInt::get(APInt(32, "4", 10)); - ConstantInt* const_int32_36 = ConstantInt::get(APInt(32, "-1", 10)); // Global Variable Definitions @@ -242,53 +257,68 @@ Module* createBaseShader() { int32_num_attribs->setName("num_attribs"); BasicBlock* label_entry = new BasicBlock("entry",func_from_array,0); + BasicBlock* label_forcond2_preheader_split = new BasicBlock("forcond2.preheader.split",func_from_array,0); + BasicBlock* label_forcond2 = new BasicBlock("forcond2",func_from_array,0); BasicBlock* label_forbody6 = new BasicBlock("forbody6",func_from_array,0); BasicBlock* label_forinc57 = new BasicBlock("forinc57",func_from_array,0); BasicBlock* label_afterfor60 = new BasicBlock("afterfor60",func_from_array,0); // Block entry (label_entry) - ICmpInst* int1_cmp = new ICmpInst(ICmpInst::ICMP_SGT, int32_count, const_int32_30, "cmp", label_entry); - ICmpInst* int1_cmp5 = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_attribs, const_int32_30, "cmp5", label_entry); + ICmpInst* int1_cmp = new ICmpInst(ICmpInst::ICMP_SGT, int32_count, const_int32_29, "cmp", label_entry); + ICmpInst* int1_cmp5 = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_attribs, const_int32_29, "cmp5", label_entry); BinaryOperator* int1_bothcond = BinaryOperator::create(Instruction::And, int1_cmp, int1_cmp5, "bothcond", label_entry); - new BranchInst(label_forbody6, label_afterfor60, int1_bothcond, label_entry); + new BranchInst(label_forcond2_preheader_split, label_afterfor60, int1_bothcond, label_entry); - // Block forbody6 (label_forbody6) + // Block forcond2.preheader.split (label_forcond2_preheader_split) + BinaryOperator* int32_tmp21 = BinaryOperator::create(Instruction::Add, int32_count, const_int32_30, "tmp21", label_forcond2_preheader_split); + ICmpInst* int1_tmp22 = new ICmpInst(ICmpInst::ICMP_SLT, int32_tmp21, const_int32_29, "tmp22", label_forcond2_preheader_split); + SelectInst* int32_tmp25 = new SelectInst(int1_tmp22, const_int32_31, int32_count, "tmp25", label_forcond2_preheader_split); + new BranchInst(label_forcond2, label_forcond2_preheader_split); + + // Block forcond2 (label_forcond2) Argument* fwdref_38 = new Argument(IntegerType::get(32)); - Argument* fwdref_39 = new Argument(IntegerType::get(32)); - PHINode* int32_i_0_reg2mem_0 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0", label_forbody6); - int32_i_0_reg2mem_0->reserveOperandSpace(3); - int32_i_0_reg2mem_0->addIncoming(const_int32_30, label_entry); + PHINode* int32_i_0_reg2mem_0 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0", label_forcond2); + int32_i_0_reg2mem_0->reserveOperandSpace(2); + int32_i_0_reg2mem_0->addIncoming(const_int32_29, label_forcond2_preheader_split); int32_i_0_reg2mem_0->addIncoming(fwdref_38, label_forinc57); - int32_i_0_reg2mem_0->addIncoming(fwdref_39, label_forbody6); - Argument* fwdref_40 = new Argument(IntegerType::get(32)); + Argument* fwdref_39 = new Argument(VectorTy_1); + PHINode* packed_vec_1_reg2mem_0 = new PHINode(VectorTy_1, "vec.1.reg2mem.0", label_forcond2); + packed_vec_1_reg2mem_0->reserveOperandSpace(2); + packed_vec_1_reg2mem_0->addIncoming(const_packed_32, label_forcond2_preheader_split); + packed_vec_1_reg2mem_0->addIncoming(fwdref_39, label_forinc57); + + BinaryOperator* int32_tmp = BinaryOperator::create(Instruction::Add, int32_num_attribs, const_int32_30, "tmp", label_forcond2); + ICmpInst* int1_tmp18 = new ICmpInst(ICmpInst::ICMP_SLT, int32_tmp, const_int32_29, "tmp18", label_forcond2); + SelectInst* int32_tmp19 = new SelectInst(int1_tmp18, const_int32_31, int32_num_attribs, "tmp19", label_forcond2); + new BranchInst(label_forbody6, label_forcond2); + + // Block forbody6 (label_forbody6) + Argument* fwdref_41 = new Argument(IntegerType::get(32)); PHINode* int32_j_0_reg2mem_0 = new PHINode(IntegerType::get(32), "j.0.reg2mem.0", label_forbody6); - int32_j_0_reg2mem_0->reserveOperandSpace(3); - int32_j_0_reg2mem_0->addIncoming(fwdref_40, label_forbody6); - int32_j_0_reg2mem_0->addIncoming(const_int32_30, label_forinc57); - int32_j_0_reg2mem_0->addIncoming(const_int32_30, label_entry); + int32_j_0_reg2mem_0->reserveOperandSpace(2); + int32_j_0_reg2mem_0->addIncoming(const_int32_29, label_forcond2); + int32_j_0_reg2mem_0->addIncoming(fwdref_41, label_forbody6); - Argument* fwdref_41 = new Argument(VectorTy_1); PHINode* packed_vec_0_reg2mem_0 = new PHINode(VectorTy_1, "vec.0.reg2mem.0", label_forbody6); - packed_vec_0_reg2mem_0->reserveOperandSpace(3); - packed_vec_0_reg2mem_0->addIncoming(fwdref_41, label_forbody6); - packed_vec_0_reg2mem_0->addIncoming(const_packed_31, label_entry); - packed_vec_0_reg2mem_0->addIncoming(fwdref_41, label_forinc57); + packed_vec_0_reg2mem_0->reserveOperandSpace(2); + packed_vec_0_reg2mem_0->addIncoming(packed_vec_1_reg2mem_0, label_forcond2); + packed_vec_0_reg2mem_0->addIncoming(fwdref_39, label_forbody6); std::vector<Value*> ptr_arraydecay11_indices; ptr_arraydecay11_indices.push_back(int32_i_0_reg2mem_0); ptr_arraydecay11_indices.push_back(int32_j_0_reg2mem_0); - ptr_arraydecay11_indices.push_back(const_int32_30); + ptr_arraydecay11_indices.push_back(const_int32_29); Instruction* ptr_arraydecay11 = new GetElementPtrInst(ptr_ainputs, ptr_arraydecay11_indices.begin(), ptr_arraydecay11_indices.end(), "arraydecay11", label_forbody6); LoadInst* float_tmp13 = new LoadInst(ptr_arraydecay11, "tmp13", false, label_forbody6); - InsertElementInst* packed_tmp15 = new InsertElementInst(packed_vec_0_reg2mem_0, float_tmp13, const_int32_30, "tmp15", label_forbody6); + InsertElementInst* packed_tmp15 = new InsertElementInst(packed_vec_0_reg2mem_0, float_tmp13, const_int32_29, "tmp15", label_forbody6); std::vector<Value*> ptr_arrayidx23_indices; ptr_arrayidx23_indices.push_back(int32_i_0_reg2mem_0); ptr_arrayidx23_indices.push_back(int32_j_0_reg2mem_0); - ptr_arrayidx23_indices.push_back(const_int32_32); + ptr_arrayidx23_indices.push_back(const_int32_31); Instruction* ptr_arrayidx23 = new GetElementPtrInst(ptr_ainputs, ptr_arrayidx23_indices.begin(), ptr_arrayidx23_indices.end(), "arrayidx23", label_forbody6); LoadInst* float_tmp24 = new LoadInst(ptr_arrayidx23, "tmp24", false, label_forbody6); - InsertElementInst* packed_tmp26 = new InsertElementInst(packed_tmp15, float_tmp24, const_int32_32, "tmp26", label_forbody6); + InsertElementInst* packed_tmp26 = new InsertElementInst(packed_tmp15, float_tmp24, const_int32_31, "tmp26", label_forbody6); std::vector<Value*> ptr_arrayidx34_indices; ptr_arrayidx34_indices.push_back(int32_i_0_reg2mem_0); ptr_arrayidx34_indices.push_back(int32_j_0_reg2mem_0); @@ -308,23 +338,22 @@ Module* createBaseShader() { ptr_arrayidx54_indices.push_back(int32_j_0_reg2mem_0); Instruction* ptr_arrayidx54 = new GetElementPtrInst(ptr_res, ptr_arrayidx54_indices.begin(), ptr_arrayidx54_indices.end(), "arrayidx54", label_forbody6); StoreInst* void_42 = new StoreInst(packed_tmp48, ptr_arrayidx54, false, label_forbody6); - BinaryOperator* int32_inc = BinaryOperator::create(Instruction::Add, int32_j_0_reg2mem_0, const_int32_32, "inc", label_forbody6); - ICmpInst* int1_cmp59 = new ICmpInst(ICmpInst::ICMP_SLT, int32_inc, int32_num_attribs, "cmp59", label_forbody6); - new BranchInst(label_forbody6, label_forinc57, int1_cmp59, label_forbody6); + BinaryOperator* int32_indvar_next = BinaryOperator::create(Instruction::Add, int32_j_0_reg2mem_0, const_int32_31, "indvar.next", label_forbody6); + ICmpInst* int1_exitcond = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next, int32_tmp19, "exitcond", label_forbody6); + new BranchInst(label_forinc57, label_forbody6, int1_exitcond, label_forbody6); // Block forinc57 (label_forinc57) - BinaryOperator* int32_inc59 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0, const_int32_32, "inc59", label_forinc57); - ICmpInst* int1_cmp17 = new ICmpInst(ICmpInst::ICMP_SLT, int32_inc59, int32_count, "cmp17", label_forinc57); - new BranchInst(label_forbody6, label_afterfor60, int1_cmp17, label_forinc57); + BinaryOperator* int32_indvar_next20 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0, const_int32_31, "indvar.next20", label_forinc57); + ICmpInst* int1_exitcond26 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next20, int32_tmp25, "exitcond26", label_forinc57); + new BranchInst(label_afterfor60, label_forcond2, int1_exitcond26, label_forinc57); // Block afterfor60 (label_afterfor60) new ReturnInst(label_afterfor60); // Resolve Forward References - fwdref_39->replaceAllUsesWith(int32_i_0_reg2mem_0); delete fwdref_39; - fwdref_41->replaceAllUsesWith(packed_tmp48); delete fwdref_41; - fwdref_40->replaceAllUsesWith(int32_inc); delete fwdref_40; - fwdref_38->replaceAllUsesWith(int32_inc59); delete fwdref_38; + fwdref_39->replaceAllUsesWith(packed_tmp48); delete fwdref_39; + fwdref_41->replaceAllUsesWith(int32_indvar_next); delete fwdref_41; + fwdref_38->replaceAllUsesWith(int32_indvar_next20); delete fwdref_38; } @@ -339,62 +368,69 @@ Module* createBaseShader() { int32_count_48->setName("count"); BasicBlock* label_entry_49 = new BasicBlock("entry",func_from_consts,0); + BasicBlock* label_forbody_preheader = new BasicBlock("forbody.preheader",func_from_consts,0); BasicBlock* label_forbody = new BasicBlock("forbody",func_from_consts,0); BasicBlock* label_afterfor = new BasicBlock("afterfor",func_from_consts,0); // Block entry (label_entry_49) - ICmpInst* int1_cmp_50 = new ICmpInst(ICmpInst::ICMP_SGT, int32_count_48, const_int32_30, "cmp", label_entry_49); - new BranchInst(label_forbody, label_afterfor, int1_cmp_50, label_entry_49); + ICmpInst* int1_cmp_50 = new ICmpInst(ICmpInst::ICMP_SGT, int32_count_48, const_int32_29, "cmp", label_entry_49); + new BranchInst(label_forbody_preheader, label_afterfor, int1_cmp_50, label_entry_49); + + // Block forbody.preheader (label_forbody_preheader) + BinaryOperator* int32_tmp_52 = BinaryOperator::create(Instruction::Add, int32_count_48, const_int32_30, "tmp", label_forbody_preheader); + ICmpInst* int1_tmp9 = new ICmpInst(ICmpInst::ICMP_SLT, int32_tmp_52, const_int32_29, "tmp9", label_forbody_preheader); + SelectInst* int32_tmp10 = new SelectInst(int1_tmp9, const_int32_31, int32_count_48, "tmp10", label_forbody_preheader); + new BranchInst(label_forbody, label_forbody_preheader); // Block forbody (label_forbody) - Argument* fwdref_53 = new Argument(IntegerType::get(32)); - PHINode* int32_i_0_reg2mem_0_52 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0", label_forbody); - int32_i_0_reg2mem_0_52->reserveOperandSpace(2); - int32_i_0_reg2mem_0_52->addIncoming(const_int32_30, label_entry_49); - int32_i_0_reg2mem_0_52->addIncoming(fwdref_53, label_forbody); - - Argument* fwdref_55 = new Argument(VectorTy_1); - PHINode* packed_vec_0_reg2mem_0_54 = new PHINode(VectorTy_1, "vec.0.reg2mem.0", label_forbody); - packed_vec_0_reg2mem_0_54->reserveOperandSpace(2); - packed_vec_0_reg2mem_0_54->addIncoming(const_packed_31, label_entry_49); - packed_vec_0_reg2mem_0_54->addIncoming(fwdref_55, label_forbody); + Argument* fwdref_55 = new Argument(IntegerType::get(32)); + PHINode* int32_i_0_reg2mem_0_54 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0", label_forbody); + int32_i_0_reg2mem_0_54->reserveOperandSpace(2); + int32_i_0_reg2mem_0_54->addIncoming(const_int32_29, label_forbody_preheader); + int32_i_0_reg2mem_0_54->addIncoming(fwdref_55, label_forbody); + + Argument* fwdref_57 = new Argument(VectorTy_1); + PHINode* packed_vec_0_reg2mem_0_56 = new PHINode(VectorTy_1, "vec.0.reg2mem.0", label_forbody); + packed_vec_0_reg2mem_0_56->reserveOperandSpace(2); + packed_vec_0_reg2mem_0_56->addIncoming(const_packed_32, label_forbody_preheader); + packed_vec_0_reg2mem_0_56->addIncoming(fwdref_57, label_forbody); std::vector<Value*> ptr_arraydecay_indices; - ptr_arraydecay_indices.push_back(int32_i_0_reg2mem_0_52); - ptr_arraydecay_indices.push_back(const_int32_30); + ptr_arraydecay_indices.push_back(int32_i_0_reg2mem_0_54); + ptr_arraydecay_indices.push_back(const_int32_29); Instruction* ptr_arraydecay = new GetElementPtrInst(ptr_ainputs_47, ptr_arraydecay_indices.begin(), ptr_arraydecay_indices.end(), "arraydecay", label_forbody); LoadInst* float_tmp5 = new LoadInst(ptr_arraydecay, "tmp5", false, label_forbody); - InsertElementInst* packed_tmp7 = new InsertElementInst(packed_vec_0_reg2mem_0_54, float_tmp5, const_int32_30, "tmp7", label_forbody); + InsertElementInst* packed_tmp7 = new InsertElementInst(packed_vec_0_reg2mem_0_56, float_tmp5, const_int32_29, "tmp7", label_forbody); std::vector<Value*> ptr_arrayidx12_indices; - ptr_arrayidx12_indices.push_back(int32_i_0_reg2mem_0_52); - ptr_arrayidx12_indices.push_back(const_int32_32); + ptr_arrayidx12_indices.push_back(int32_i_0_reg2mem_0_54); + ptr_arrayidx12_indices.push_back(const_int32_31); Instruction* ptr_arrayidx12 = new GetElementPtrInst(ptr_ainputs_47, ptr_arrayidx12_indices.begin(), ptr_arrayidx12_indices.end(), "arrayidx12", label_forbody); - LoadInst* float_tmp13_56 = new LoadInst(ptr_arrayidx12, "tmp13", false, label_forbody); - InsertElementInst* packed_tmp15_57 = new InsertElementInst(packed_tmp7, float_tmp13_56, const_int32_32, "tmp15", label_forbody); + LoadInst* float_tmp13_58 = new LoadInst(ptr_arrayidx12, "tmp13", false, label_forbody); + InsertElementInst* packed_tmp15_59 = new InsertElementInst(packed_tmp7, float_tmp13_58, const_int32_31, "tmp15", label_forbody); std::vector<Value*> ptr_arrayidx20_indices; - ptr_arrayidx20_indices.push_back(int32_i_0_reg2mem_0_52); + ptr_arrayidx20_indices.push_back(int32_i_0_reg2mem_0_54); ptr_arrayidx20_indices.push_back(const_int32_33); Instruction* ptr_arrayidx20 = new GetElementPtrInst(ptr_ainputs_47, ptr_arrayidx20_indices.begin(), ptr_arrayidx20_indices.end(), "arrayidx20", label_forbody); LoadInst* float_tmp21 = new LoadInst(ptr_arrayidx20, "tmp21", false, label_forbody); - InsertElementInst* packed_tmp23 = new InsertElementInst(packed_tmp15_57, float_tmp21, const_int32_33, "tmp23", label_forbody); + InsertElementInst* packed_tmp23 = new InsertElementInst(packed_tmp15_59, float_tmp21, const_int32_33, "tmp23", label_forbody); std::vector<Value*> ptr_arrayidx28_indices; - ptr_arrayidx28_indices.push_back(int32_i_0_reg2mem_0_52); + ptr_arrayidx28_indices.push_back(int32_i_0_reg2mem_0_54); ptr_arrayidx28_indices.push_back(const_int32_34); Instruction* ptr_arrayidx28 = new GetElementPtrInst(ptr_ainputs_47, ptr_arrayidx28_indices.begin(), ptr_arrayidx28_indices.end(), "arrayidx28", label_forbody); LoadInst* float_tmp29 = new LoadInst(ptr_arrayidx28, "tmp29", false, label_forbody); InsertElementInst* packed_tmp31 = new InsertElementInst(packed_tmp23, float_tmp29, const_int32_34, "tmp31", label_forbody); - GetElementPtrInst* ptr_arrayidx34_58 = new GetElementPtrInst(ptr_res_46, int32_i_0_reg2mem_0_52, "arrayidx34", label_forbody); - StoreInst* void_59 = new StoreInst(packed_tmp31, ptr_arrayidx34_58, false, label_forbody); - BinaryOperator* int32_indvar_next = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_52, const_int32_32, "indvar.next", label_forbody); - ICmpInst* int1_exitcond = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next, int32_count_48, "exitcond", label_forbody); - new BranchInst(label_afterfor, label_forbody, int1_exitcond, label_forbody); + GetElementPtrInst* ptr_arrayidx34_60 = new GetElementPtrInst(ptr_res_46, int32_i_0_reg2mem_0_54, "arrayidx34", label_forbody); + StoreInst* void_61 = new StoreInst(packed_tmp31, ptr_arrayidx34_60, false, label_forbody); + BinaryOperator* int32_indvar_next_62 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_54, const_int32_31, "indvar.next", label_forbody); + ICmpInst* int1_exitcond_63 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next_62, int32_tmp10, "exitcond", label_forbody); + new BranchInst(label_afterfor, label_forbody, int1_exitcond_63, label_forbody); // Block afterfor (label_afterfor) new ReturnInst(label_afterfor); // Resolve Forward References - fwdref_55->replaceAllUsesWith(packed_tmp31); delete fwdref_55; - fwdref_53->replaceAllUsesWith(int32_indvar_next); delete fwdref_53; + fwdref_57->replaceAllUsesWith(packed_tmp31); delete fwdref_57; + fwdref_55->replaceAllUsesWith(int32_indvar_next_62); delete fwdref_55; } @@ -405,59 +441,66 @@ Module* createBaseShader() { ptr_dests->setName("dests"); Value* ptr_in = args++; ptr_in->setName("in"); - Value* int32_num_attribs_62 = args++; - int32_num_attribs_62->setName("num_attribs"); - - BasicBlock* label_entry_63 = new BasicBlock("entry",func_to_array,0); - BasicBlock* label_forbody_64 = new BasicBlock("forbody",func_to_array,0); - BasicBlock* label_afterfor_65 = new BasicBlock("afterfor",func_to_array,0); - - // Block entry (label_entry_63) - ICmpInst* int1_cmp_66 = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_attribs_62, const_int32_30, "cmp", label_entry_63); - new BranchInst(label_forbody_64, label_afterfor_65, int1_cmp_66, label_entry_63); - - // Block forbody (label_forbody_64) - Argument* fwdref_69 = new Argument(IntegerType::get(32)); - PHINode* int32_i_0_reg2mem_0_68 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0", label_forbody_64); - int32_i_0_reg2mem_0_68->reserveOperandSpace(2); - int32_i_0_reg2mem_0_68->addIncoming(const_int32_30, label_entry_63); - int32_i_0_reg2mem_0_68->addIncoming(fwdref_69, label_forbody_64); - - std::vector<Value*> ptr_arraydecay_70_indices; - ptr_arraydecay_70_indices.push_back(int32_i_0_reg2mem_0_68); - ptr_arraydecay_70_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay_70 = new GetElementPtrInst(ptr_dests, ptr_arraydecay_70_indices.begin(), ptr_arraydecay_70_indices.end(), "arraydecay", label_forbody_64); - GetElementPtrInst* ptr_arrayidx6 = new GetElementPtrInst(ptr_in, int32_i_0_reg2mem_0_68, "arrayidx6", label_forbody_64); - LoadInst* packed_tmp7_71 = new LoadInst(ptr_arrayidx6, "tmp7", false, label_forbody_64); - ExtractElementInst* float_tmp11 = new ExtractElementInst(packed_tmp7_71, const_int32_30, "tmp11", label_forbody_64); - StoreInst* void_72 = new StoreInst(float_tmp11, ptr_arraydecay_70, false, label_forbody_64); + Value* int32_num_attribs_66 = args++; + int32_num_attribs_66->setName("num_attribs"); + + BasicBlock* label_entry_67 = new BasicBlock("entry",func_to_array,0); + BasicBlock* label_forbody_preheader_68 = new BasicBlock("forbody.preheader",func_to_array,0); + BasicBlock* label_forbody_69 = new BasicBlock("forbody",func_to_array,0); + BasicBlock* label_afterfor_70 = new BasicBlock("afterfor",func_to_array,0); + + // Block entry (label_entry_67) + ICmpInst* int1_cmp_71 = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_attribs_66, const_int32_29, "cmp", label_entry_67); + new BranchInst(label_forbody_preheader_68, label_afterfor_70, int1_cmp_71, label_entry_67); + + // Block forbody.preheader (label_forbody_preheader_68) + BinaryOperator* int32_tmp_73 = BinaryOperator::create(Instruction::Add, int32_num_attribs_66, const_int32_30, "tmp", label_forbody_preheader_68); + ICmpInst* int1_tmp9_74 = new ICmpInst(ICmpInst::ICMP_SLT, int32_tmp_73, const_int32_29, "tmp9", label_forbody_preheader_68); + SelectInst* int32_tmp10_75 = new SelectInst(int1_tmp9_74, const_int32_31, int32_num_attribs_66, "tmp10", label_forbody_preheader_68); + new BranchInst(label_forbody_69, label_forbody_preheader_68); + + // Block forbody (label_forbody_69) + Argument* fwdref_78 = new Argument(IntegerType::get(32)); + PHINode* int32_i_0_reg2mem_0_77 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0", label_forbody_69); + int32_i_0_reg2mem_0_77->reserveOperandSpace(2); + int32_i_0_reg2mem_0_77->addIncoming(const_int32_29, label_forbody_preheader_68); + int32_i_0_reg2mem_0_77->addIncoming(fwdref_78, label_forbody_69); + + std::vector<Value*> ptr_arraydecay_79_indices; + ptr_arraydecay_79_indices.push_back(int32_i_0_reg2mem_0_77); + ptr_arraydecay_79_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay_79 = new GetElementPtrInst(ptr_dests, ptr_arraydecay_79_indices.begin(), ptr_arraydecay_79_indices.end(), "arraydecay", label_forbody_69); + GetElementPtrInst* ptr_arrayidx6 = new GetElementPtrInst(ptr_in, int32_i_0_reg2mem_0_77, "arrayidx6", label_forbody_69); + LoadInst* packed_tmp7_80 = new LoadInst(ptr_arrayidx6, "tmp7", false, label_forbody_69); + ExtractElementInst* float_tmp11 = new ExtractElementInst(packed_tmp7_80, const_int32_29, "tmp11", label_forbody_69); + StoreInst* void_81 = new StoreInst(float_tmp11, ptr_arraydecay_79, false, label_forbody_69); std::vector<Value*> ptr_arrayidx13_indices; - ptr_arrayidx13_indices.push_back(int32_i_0_reg2mem_0_68); - ptr_arrayidx13_indices.push_back(const_int32_32); - Instruction* ptr_arrayidx13 = new GetElementPtrInst(ptr_dests, ptr_arrayidx13_indices.begin(), ptr_arrayidx13_indices.end(), "arrayidx13", label_forbody_64); - ExtractElementInst* float_tmp15 = new ExtractElementInst(packed_tmp7_71, const_int32_32, "tmp15", label_forbody_64); - StoreInst* void_73 = new StoreInst(float_tmp15, ptr_arrayidx13, false, label_forbody_64); + ptr_arrayidx13_indices.push_back(int32_i_0_reg2mem_0_77); + ptr_arrayidx13_indices.push_back(const_int32_31); + Instruction* ptr_arrayidx13 = new GetElementPtrInst(ptr_dests, ptr_arrayidx13_indices.begin(), ptr_arrayidx13_indices.end(), "arrayidx13", label_forbody_69); + ExtractElementInst* float_tmp15 = new ExtractElementInst(packed_tmp7_80, const_int32_31, "tmp15", label_forbody_69); + StoreInst* void_82 = new StoreInst(float_tmp15, ptr_arrayidx13, false, label_forbody_69); std::vector<Value*> ptr_arrayidx17_indices; - ptr_arrayidx17_indices.push_back(int32_i_0_reg2mem_0_68); + ptr_arrayidx17_indices.push_back(int32_i_0_reg2mem_0_77); ptr_arrayidx17_indices.push_back(const_int32_33); - Instruction* ptr_arrayidx17 = new GetElementPtrInst(ptr_dests, ptr_arrayidx17_indices.begin(), ptr_arrayidx17_indices.end(), "arrayidx17", label_forbody_64); - ExtractElementInst* float_tmp19 = new ExtractElementInst(packed_tmp7_71, const_int32_33, "tmp19", label_forbody_64); - StoreInst* void_74 = new StoreInst(float_tmp19, ptr_arrayidx17, false, label_forbody_64); + Instruction* ptr_arrayidx17 = new GetElementPtrInst(ptr_dests, ptr_arrayidx17_indices.begin(), ptr_arrayidx17_indices.end(), "arrayidx17", label_forbody_69); + ExtractElementInst* float_tmp19 = new ExtractElementInst(packed_tmp7_80, const_int32_33, "tmp19", label_forbody_69); + StoreInst* void_83 = new StoreInst(float_tmp19, ptr_arrayidx17, false, label_forbody_69); std::vector<Value*> ptr_arrayidx21_indices; - ptr_arrayidx21_indices.push_back(int32_i_0_reg2mem_0_68); + ptr_arrayidx21_indices.push_back(int32_i_0_reg2mem_0_77); ptr_arrayidx21_indices.push_back(const_int32_34); - Instruction* ptr_arrayidx21 = new GetElementPtrInst(ptr_dests, ptr_arrayidx21_indices.begin(), ptr_arrayidx21_indices.end(), "arrayidx21", label_forbody_64); - ExtractElementInst* float_tmp23 = new ExtractElementInst(packed_tmp7_71, const_int32_34, "tmp23", label_forbody_64); - StoreInst* void_75 = new StoreInst(float_tmp23, ptr_arrayidx21, false, label_forbody_64); - BinaryOperator* int32_indvar_next_76 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_68, const_int32_32, "indvar.next", label_forbody_64); - ICmpInst* int1_exitcond_77 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next_76, int32_num_attribs_62, "exitcond", label_forbody_64); - new BranchInst(label_afterfor_65, label_forbody_64, int1_exitcond_77, label_forbody_64); + Instruction* ptr_arrayidx21 = new GetElementPtrInst(ptr_dests, ptr_arrayidx21_indices.begin(), ptr_arrayidx21_indices.end(), "arrayidx21", label_forbody_69); + ExtractElementInst* float_tmp23 = new ExtractElementInst(packed_tmp7_80, const_int32_34, "tmp23", label_forbody_69); + StoreInst* void_84 = new StoreInst(float_tmp23, ptr_arrayidx21, false, label_forbody_69); + BinaryOperator* int32_indvar_next_85 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_77, const_int32_31, "indvar.next", label_forbody_69); + ICmpInst* int1_exitcond_86 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next_85, int32_tmp10_75, "exitcond", label_forbody_69); + new BranchInst(label_afterfor_70, label_forbody_69, int1_exitcond_86, label_forbody_69); - // Block afterfor (label_afterfor_65) - new ReturnInst(label_afterfor_65); + // Block afterfor (label_afterfor_70) + new ReturnInst(label_afterfor_70); // Resolve Forward References - fwdref_69->replaceAllUsesWith(int32_indvar_next_76); delete fwdref_69; + fwdref_78->replaceAllUsesWith(int32_indvar_next_85); delete fwdref_78; } @@ -474,50 +517,57 @@ Module* createBaseShader() { int32_num_vertices->setName("num_vertices"); Value* int32_num_inputs = args++; int32_num_inputs->setName("num_inputs"); - Value* int32_num_attribs_80 = args++; - int32_num_attribs_80->setName("num_attribs"); + Value* int32_num_attribs_89 = args++; + int32_num_attribs_89->setName("num_attribs"); Value* int32_num_consts = args++; int32_num_consts->setName("num_consts"); - BasicBlock* label_entry_81 = new BasicBlock("entry",func_run_vertex_shader,0); + BasicBlock* label_entry_90 = new BasicBlock("entry",func_run_vertex_shader,0); + BasicBlock* label_forbody_preheader_i = new BasicBlock("forbody.preheader.i",func_run_vertex_shader,0); BasicBlock* label_forbody_i = new BasicBlock("forbody.i",func_run_vertex_shader,0); BasicBlock* label_from_consts_exit = new BasicBlock("from_consts.exit",func_run_vertex_shader,0); - BasicBlock* label_forbody_preheader = new BasicBlock("forbody.preheader",func_run_vertex_shader,0); - BasicBlock* label_forbody_82 = new BasicBlock("forbody",func_run_vertex_shader,0); - BasicBlock* label_afterfor_83 = new BasicBlock("afterfor",func_run_vertex_shader,0); - - // Block entry (label_entry_81) - AllocaInst* ptr_consts = new AllocaInst(ArrayTy_21, "consts", label_entry_81); - AllocaInst* ptr_temps = new AllocaInst(ArrayTy_23, "temps", label_entry_81); - AllocaInst* ptr_args = new AllocaInst(StructTy_struct_ShaderInput, "args", label_entry_81); - ICmpInst* int1_cmp_i = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_consts, const_int32_30, "cmp.i", label_entry_81); - new BranchInst(label_forbody_i, label_from_consts_exit, int1_cmp_i, label_entry_81); + BasicBlock* label_forbody_preheader_91 = new BasicBlock("forbody.preheader",func_run_vertex_shader,0); + BasicBlock* label_forbody_92 = new BasicBlock("forbody",func_run_vertex_shader,0); + BasicBlock* label_afterfor_93 = new BasicBlock("afterfor",func_run_vertex_shader,0); + + // Block entry (label_entry_90) + AllocaInst* ptr_consts = new AllocaInst(ArrayTy_20, "consts", label_entry_90); + AllocaInst* ptr_temps = new AllocaInst(ArrayTy_22, "temps", label_entry_90); + AllocaInst* ptr_args = new AllocaInst(StructTy_struct_ShaderInput, "args", label_entry_90); + ICmpInst* int1_cmp_i = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_consts, const_int32_29, "cmp.i", label_entry_90); + new BranchInst(label_forbody_preheader_i, label_from_consts_exit, int1_cmp_i, label_entry_90); + + // Block forbody.preheader.i (label_forbody_preheader_i) + BinaryOperator* int32_tmp_i = BinaryOperator::create(Instruction::Add, int32_num_consts, const_int32_30, "tmp.i", label_forbody_preheader_i); + ICmpInst* int1_tmp9_i = new ICmpInst(ICmpInst::ICMP_SLT, int32_tmp_i, const_int32_29, "tmp9.i", label_forbody_preheader_i); + SelectInst* int32_tmp10_i = new SelectInst(int1_tmp9_i, const_int32_31, int32_num_consts, "tmp10.i", label_forbody_preheader_i); + new BranchInst(label_forbody_i, label_forbody_preheader_i); // Block forbody.i (label_forbody_i) - Argument* fwdref_85 = new Argument(IntegerType::get(32)); + Argument* fwdref_96 = new Argument(IntegerType::get(32)); PHINode* int32_i_0_reg2mem_0_i = new PHINode(IntegerType::get(32), "i.0.reg2mem.0.i", label_forbody_i); int32_i_0_reg2mem_0_i->reserveOperandSpace(2); - int32_i_0_reg2mem_0_i->addIncoming(const_int32_30, label_entry_81); - int32_i_0_reg2mem_0_i->addIncoming(fwdref_85, label_forbody_i); + int32_i_0_reg2mem_0_i->addIncoming(const_int32_29, label_forbody_preheader_i); + int32_i_0_reg2mem_0_i->addIncoming(fwdref_96, label_forbody_i); - Argument* fwdref_86 = new Argument(VectorTy_1); + Argument* fwdref_97 = new Argument(VectorTy_1); PHINode* packed_vec_0_reg2mem_0_i = new PHINode(VectorTy_1, "vec.0.reg2mem.0.i", label_forbody_i); packed_vec_0_reg2mem_0_i->reserveOperandSpace(2); - packed_vec_0_reg2mem_0_i->addIncoming(const_packed_31, label_entry_81); - packed_vec_0_reg2mem_0_i->addIncoming(fwdref_86, label_forbody_i); + packed_vec_0_reg2mem_0_i->addIncoming(const_packed_32, label_forbody_preheader_i); + packed_vec_0_reg2mem_0_i->addIncoming(fwdref_97, label_forbody_i); std::vector<Value*> ptr_arraydecay_i_indices; ptr_arraydecay_i_indices.push_back(int32_i_0_reg2mem_0_i); - ptr_arraydecay_i_indices.push_back(const_int32_30); + ptr_arraydecay_i_indices.push_back(const_int32_29); Instruction* ptr_arraydecay_i = new GetElementPtrInst(ptr_aconsts, ptr_arraydecay_i_indices.begin(), ptr_arraydecay_i_indices.end(), "arraydecay.i", label_forbody_i); LoadInst* float_tmp5_i = new LoadInst(ptr_arraydecay_i, "tmp5.i", false, label_forbody_i); - InsertElementInst* packed_tmp7_i = new InsertElementInst(packed_vec_0_reg2mem_0_i, float_tmp5_i, const_int32_30, "tmp7.i", label_forbody_i); + InsertElementInst* packed_tmp7_i = new InsertElementInst(packed_vec_0_reg2mem_0_i, float_tmp5_i, const_int32_29, "tmp7.i", label_forbody_i); std::vector<Value*> ptr_arrayidx12_i_indices; ptr_arrayidx12_i_indices.push_back(int32_i_0_reg2mem_0_i); - ptr_arrayidx12_i_indices.push_back(const_int32_32); + ptr_arrayidx12_i_indices.push_back(const_int32_31); Instruction* ptr_arrayidx12_i = new GetElementPtrInst(ptr_aconsts, ptr_arrayidx12_i_indices.begin(), ptr_arrayidx12_i_indices.end(), "arrayidx12.i", label_forbody_i); LoadInst* float_tmp13_i = new LoadInst(ptr_arrayidx12_i, "tmp13.i", false, label_forbody_i); - InsertElementInst* packed_tmp15_i = new InsertElementInst(packed_tmp7_i, float_tmp13_i, const_int32_32, "tmp15.i", label_forbody_i); + InsertElementInst* packed_tmp15_i = new InsertElementInst(packed_tmp7_i, float_tmp13_i, const_int32_31, "tmp15.i", label_forbody_i); std::vector<Value*> ptr_arrayidx20_i_indices; ptr_arrayidx20_i_indices.push_back(int32_i_0_reg2mem_0_i); ptr_arrayidx20_i_indices.push_back(const_int32_33); @@ -531,78 +581,83 @@ Module* createBaseShader() { LoadInst* float_tmp29_i = new LoadInst(ptr_arrayidx28_i, "tmp29.i", false, label_forbody_i); InsertElementInst* packed_tmp31_i = new InsertElementInst(packed_tmp23_i, float_tmp29_i, const_int32_34, "tmp31.i", label_forbody_i); std::vector<Value*> ptr_arrayidx34_i_indices; - ptr_arrayidx34_i_indices.push_back(const_int32_30); + ptr_arrayidx34_i_indices.push_back(const_int32_29); ptr_arrayidx34_i_indices.push_back(int32_i_0_reg2mem_0_i); Instruction* ptr_arrayidx34_i = new GetElementPtrInst(ptr_consts, ptr_arrayidx34_i_indices.begin(), ptr_arrayidx34_i_indices.end(), "arrayidx34.i", label_forbody_i); - StoreInst* void_87 = new StoreInst(packed_tmp31_i, ptr_arrayidx34_i, false, label_forbody_i); - BinaryOperator* int32_indvar_next6 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_i, const_int32_32, "indvar.next6", label_forbody_i); - ICmpInst* int1_exitcond7 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next6, int32_num_consts, "exitcond7", label_forbody_i); - new BranchInst(label_from_consts_exit, label_forbody_i, int1_exitcond7, label_forbody_i); + StoreInst* void_98 = new StoreInst(packed_tmp31_i, ptr_arrayidx34_i, false, label_forbody_i); + BinaryOperator* int32_indvar_next8 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_i, const_int32_31, "indvar.next8", label_forbody_i); + ICmpInst* int1_exitcond9 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next8, int32_tmp10_i, "exitcond9", label_forbody_i); + new BranchInst(label_from_consts_exit, label_forbody_i, int1_exitcond9, label_forbody_i); // Block from_consts.exit (label_from_consts_exit) std::vector<Value*> ptr_tmp2_indices; - ptr_tmp2_indices.push_back(const_int32_30); + ptr_tmp2_indices.push_back(const_int32_29); ptr_tmp2_indices.push_back(const_int32_34); Instruction* ptr_tmp2 = new GetElementPtrInst(ptr_args, ptr_tmp2_indices.begin(), ptr_tmp2_indices.end(), "tmp2", label_from_consts_exit); std::vector<Value*> ptr_arraydecay3_indices; - ptr_arraydecay3_indices.push_back(const_int32_30); - ptr_arraydecay3_indices.push_back(const_int32_30); + ptr_arraydecay3_indices.push_back(const_int32_29); + ptr_arraydecay3_indices.push_back(const_int32_29); Instruction* ptr_arraydecay3 = new GetElementPtrInst(ptr_consts, ptr_arraydecay3_indices.begin(), ptr_arraydecay3_indices.end(), "arraydecay3", label_from_consts_exit); - StoreInst* void_89 = new StoreInst(ptr_arraydecay3, ptr_tmp2, false, label_from_consts_exit); + StoreInst* void_100 = new StoreInst(ptr_arraydecay3, ptr_tmp2, false, label_from_consts_exit); std::vector<Value*> ptr_tmp4_indices; - ptr_tmp4_indices.push_back(const_int32_30); + ptr_tmp4_indices.push_back(const_int32_29); ptr_tmp4_indices.push_back(const_int32_33); Instruction* ptr_tmp4 = new GetElementPtrInst(ptr_args, ptr_tmp4_indices.begin(), ptr_tmp4_indices.end(), "tmp4", label_from_consts_exit); std::vector<Value*> ptr_arraydecay5_indices; - ptr_arraydecay5_indices.push_back(const_int32_30); - ptr_arraydecay5_indices.push_back(const_int32_30); + ptr_arraydecay5_indices.push_back(const_int32_29); + ptr_arraydecay5_indices.push_back(const_int32_29); Instruction* ptr_arraydecay5 = new GetElementPtrInst(ptr_temps, ptr_arraydecay5_indices.begin(), ptr_arraydecay5_indices.end(), "arraydecay5", label_from_consts_exit); - StoreInst* void_90 = new StoreInst(ptr_arraydecay5, ptr_tmp4, false, label_from_consts_exit); - ICmpInst* int1_cmp_91 = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_vertices, const_int32_30, "cmp", label_from_consts_exit); - new BranchInst(label_forbody_preheader, label_afterfor_83, int1_cmp_91, label_from_consts_exit); + StoreInst* void_101 = new StoreInst(ptr_arraydecay5, ptr_tmp4, false, label_from_consts_exit); + ICmpInst* int1_cmp_102 = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_vertices, const_int32_29, "cmp", label_from_consts_exit); + new BranchInst(label_forbody_preheader_91, label_afterfor_93, int1_cmp_102, label_from_consts_exit); - // Block forbody.preheader (label_forbody_preheader) + // Block forbody.preheader (label_forbody_preheader_91) std::vector<Value*> ptr_tmp8_indices; - ptr_tmp8_indices.push_back(const_int32_30); - ptr_tmp8_indices.push_back(const_int32_30); - Instruction* ptr_tmp8 = new GetElementPtrInst(ptr_args, ptr_tmp8_indices.begin(), ptr_tmp8_indices.end(), "tmp8", label_forbody_preheader); + ptr_tmp8_indices.push_back(const_int32_29); + ptr_tmp8_indices.push_back(const_int32_29); + Instruction* ptr_tmp8 = new GetElementPtrInst(ptr_args, ptr_tmp8_indices.begin(), ptr_tmp8_indices.end(), "tmp8", label_forbody_preheader_91); std::vector<Value*> ptr_tmp12_indices; - ptr_tmp12_indices.push_back(const_int32_30); - ptr_tmp12_indices.push_back(const_int32_32); - Instruction* ptr_tmp12 = new GetElementPtrInst(ptr_args, ptr_tmp12_indices.begin(), ptr_tmp12_indices.end(), "tmp12", label_forbody_preheader); - new BranchInst(label_forbody_82, label_forbody_preheader); - - // Block forbody (label_forbody_82) - Argument* fwdref_95 = new Argument(IntegerType::get(32)); - PHINode* int32_i_0_reg2mem_0_94 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0", label_forbody_82); - int32_i_0_reg2mem_0_94->reserveOperandSpace(2); - int32_i_0_reg2mem_0_94->addIncoming(const_int32_30, label_forbody_preheader); - int32_i_0_reg2mem_0_94->addIncoming(fwdref_95, label_forbody_82); - - std::vector<Value*> ptr_arraydecay11_96_indices; - ptr_arraydecay11_96_indices.push_back(int32_i_0_reg2mem_0_94); - ptr_arraydecay11_96_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay11_96 = new GetElementPtrInst(ptr_results, ptr_arraydecay11_96_indices.begin(), ptr_arraydecay11_96_indices.end(), "arraydecay11", label_forbody_82); - StoreInst* void_97 = new StoreInst(ptr_arraydecay11_96, ptr_tmp8, false, label_forbody_82); + ptr_tmp12_indices.push_back(const_int32_29); + ptr_tmp12_indices.push_back(const_int32_31); + Instruction* ptr_tmp12 = new GetElementPtrInst(ptr_args, ptr_tmp12_indices.begin(), ptr_tmp12_indices.end(), "tmp12", label_forbody_preheader_91); + BinaryOperator* int32_tmp_104 = BinaryOperator::create(Instruction::Add, int32_num_vertices, const_int32_30, "tmp", label_forbody_preheader_91); + ICmpInst* int1_tmp6 = new ICmpInst(ICmpInst::ICMP_SLT, int32_tmp_104, const_int32_29, "tmp6", label_forbody_preheader_91); + SelectInst* int32_tmp7 = new SelectInst(int1_tmp6, const_int32_31, int32_num_vertices, "tmp7", label_forbody_preheader_91); + new BranchInst(label_forbody_92, label_forbody_preheader_91); + + // Block forbody (label_forbody_92) + Argument* fwdref_107 = new Argument(IntegerType::get(32)); + PHINode* int32_i_0_reg2mem_0_106 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0", label_forbody_92); + int32_i_0_reg2mem_0_106->reserveOperandSpace(2); + int32_i_0_reg2mem_0_106->addIncoming(const_int32_29, label_forbody_preheader_91); + int32_i_0_reg2mem_0_106->addIncoming(fwdref_107, label_forbody_92); + + std::vector<Value*> ptr_arraydecay11_108_indices; + ptr_arraydecay11_108_indices.push_back(int32_i_0_reg2mem_0_106); + ptr_arraydecay11_108_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay11_108 = new GetElementPtrInst(ptr_results, ptr_arraydecay11_108_indices.begin(), ptr_arraydecay11_108_indices.end(), "arraydecay11", label_forbody_92); + StoreInst* void_109 = new StoreInst(ptr_arraydecay11_108, ptr_tmp8, false, label_forbody_92); std::vector<Value*> ptr_arraydecay16_indices; - ptr_arraydecay16_indices.push_back(int32_i_0_reg2mem_0_94); - ptr_arraydecay16_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay16 = new GetElementPtrInst(ptr_inputs, ptr_arraydecay16_indices.begin(), ptr_arraydecay16_indices.end(), "arraydecay16", label_forbody_82); - StoreInst* void_98 = new StoreInst(ptr_arraydecay16, ptr_tmp12, false, label_forbody_82); - CallInst* void_99 = new CallInst(func_execute_shader, ptr_args, "", label_forbody_82); - void_99->setCallingConv(CallingConv::C); - void_99->setTailCall(false); - BinaryOperator* int32_indvar_next_100 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_94, const_int32_32, "indvar.next", label_forbody_82); - ICmpInst* int1_exitcond_101 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next_100, int32_num_vertices, "exitcond", label_forbody_82); - new BranchInst(label_afterfor_83, label_forbody_82, int1_exitcond_101, label_forbody_82); - - // Block afterfor (label_afterfor_83) - new ReturnInst(label_afterfor_83); + ptr_arraydecay16_indices.push_back(int32_i_0_reg2mem_0_106); + ptr_arraydecay16_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay16 = new GetElementPtrInst(ptr_inputs, ptr_arraydecay16_indices.begin(), ptr_arraydecay16_indices.end(), "arraydecay16", label_forbody_92); + StoreInst* void_110 = new StoreInst(ptr_arraydecay16, ptr_tmp12, false, label_forbody_92); + CallInst* void_111 = new CallInst(func_execute_shader, ptr_args, "", label_forbody_92); + void_111->setCallingConv(CallingConv::C); + void_111->setTailCall(false);const ParamAttrsList *void_111_PAL = 0; + void_111->setParamAttrs(void_111_PAL); + + BinaryOperator* int32_indvar_next_112 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_106, const_int32_31, "indvar.next", label_forbody_92); + ICmpInst* int1_exitcond_113 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next_112, int32_tmp7, "exitcond", label_forbody_92); + new BranchInst(label_afterfor_93, label_forbody_92, int1_exitcond_113, label_forbody_92); + + // Block afterfor (label_afterfor_93) + new ReturnInst(label_afterfor_93); // Resolve Forward References - fwdref_86->replaceAllUsesWith(packed_tmp31_i); delete fwdref_86; - fwdref_85->replaceAllUsesWith(int32_indvar_next6); delete fwdref_85; - fwdref_95->replaceAllUsesWith(int32_indvar_next_100); delete fwdref_95; + fwdref_107->replaceAllUsesWith(int32_indvar_next_112); delete fwdref_107; + fwdref_97->replaceAllUsesWith(packed_tmp31_i); delete fwdref_97; + fwdref_96->replaceAllUsesWith(int32_indvar_next8); delete fwdref_96; } @@ -613,180 +668,195 @@ Module* createBaseShader() { float_x->setName("x"); Value* float_y = args++; float_y->setName("y"); - Value* ptr_results_104 = args++; - ptr_results_104->setName("results"); - Value* ptr_inputs_105 = args++; - ptr_inputs_105->setName("inputs"); - Value* int32_num_inputs_106 = args++; - int32_num_inputs_106->setName("num_inputs"); - Value* ptr_aconsts_107 = args++; - ptr_aconsts_107->setName("aconsts"); - Value* int32_num_consts_108 = args++; - int32_num_consts_108->setName("num_consts"); + Value* ptr_results_116 = args++; + ptr_results_116->setName("results"); + Value* ptr_inputs_117 = args++; + ptr_inputs_117->setName("inputs"); + Value* int32_num_inputs_118 = args++; + int32_num_inputs_118->setName("num_inputs"); + Value* ptr_aconsts_119 = args++; + ptr_aconsts_119->setName("aconsts"); + Value* int32_num_consts_120 = args++; + int32_num_consts_120->setName("num_consts"); Value* ptr_samplers = args++; ptr_samplers->setName("samplers"); - BasicBlock* label_entry_109 = new BasicBlock("entry",func_run_fragment_shader,0); - BasicBlock* label_forbody_i_110 = new BasicBlock("forbody.i",func_run_fragment_shader,0); - BasicBlock* label_from_consts_exit_111 = new BasicBlock("from_consts.exit",func_run_fragment_shader,0); + BasicBlock* label_entry_121 = new BasicBlock("entry",func_run_fragment_shader,0); + BasicBlock* label_forbody_preheader_i_122 = new BasicBlock("forbody.preheader.i",func_run_fragment_shader,0); + BasicBlock* label_forbody_i_123 = new BasicBlock("forbody.i",func_run_fragment_shader,0); + BasicBlock* label_from_consts_exit_124 = new BasicBlock("from_consts.exit",func_run_fragment_shader,0); - // Block entry (label_entry_109) - AllocaInst* ptr_consts_112 = new AllocaInst(ArrayTy_21, "consts", label_entry_109); - AllocaInst* ptr_temps_113 = new AllocaInst(ArrayTy_23, "temps", label_entry_109); - AllocaInst* ptr_args_114 = new AllocaInst(StructTy_struct_ShaderInput, "args", label_entry_109); + // Block entry (label_entry_121) + AllocaInst* ptr_consts_125 = new AllocaInst(ArrayTy_20, "consts", label_entry_121); + AllocaInst* ptr_temps_126 = new AllocaInst(ArrayTy_22, "temps", label_entry_121); + AllocaInst* ptr_args_127 = new AllocaInst(StructTy_struct_ShaderInput, "args", label_entry_121); std::vector<Value*> ptr_tmp_indices; - ptr_tmp_indices.push_back(const_int32_30); + ptr_tmp_indices.push_back(const_int32_29); ptr_tmp_indices.push_back(const_int32_35); - Instruction* ptr_tmp = new GetElementPtrInst(ptr_args_114, ptr_tmp_indices.begin(), ptr_tmp_indices.end(), "tmp", label_entry_109); - StoreInst* void_115 = new StoreInst(const_int32_30, ptr_tmp, false, label_entry_109); - ICmpInst* int1_cmp_i_116 = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_consts_108, const_int32_30, "cmp.i", label_entry_109); - new BranchInst(label_forbody_i_110, label_from_consts_exit_111, int1_cmp_i_116, label_entry_109); - - // Block forbody.i (label_forbody_i_110) - Argument* fwdref_119 = new Argument(IntegerType::get(32)); - PHINode* int32_i_0_reg2mem_0_i_118 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0.i", label_forbody_i_110); - int32_i_0_reg2mem_0_i_118->reserveOperandSpace(2); - int32_i_0_reg2mem_0_i_118->addIncoming(const_int32_30, label_entry_109); - int32_i_0_reg2mem_0_i_118->addIncoming(fwdref_119, label_forbody_i_110); - - Argument* fwdref_121 = new Argument(VectorTy_1); - PHINode* packed_vec_0_reg2mem_0_i_120 = new PHINode(VectorTy_1, "vec.0.reg2mem.0.i", label_forbody_i_110); - packed_vec_0_reg2mem_0_i_120->reserveOperandSpace(2); - packed_vec_0_reg2mem_0_i_120->addIncoming(const_packed_31, label_entry_109); - packed_vec_0_reg2mem_0_i_120->addIncoming(fwdref_121, label_forbody_i_110); - - std::vector<Value*> ptr_arraydecay_i_122_indices; - ptr_arraydecay_i_122_indices.push_back(int32_i_0_reg2mem_0_i_118); - ptr_arraydecay_i_122_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay_i_122 = new GetElementPtrInst(ptr_aconsts_107, ptr_arraydecay_i_122_indices.begin(), ptr_arraydecay_i_122_indices.end(), "arraydecay.i", label_forbody_i_110); - LoadInst* float_tmp5_i_123 = new LoadInst(ptr_arraydecay_i_122, "tmp5.i", false, label_forbody_i_110); - InsertElementInst* packed_tmp7_i_124 = new InsertElementInst(packed_vec_0_reg2mem_0_i_120, float_tmp5_i_123, const_int32_30, "tmp7.i", label_forbody_i_110); - std::vector<Value*> ptr_arrayidx12_i_125_indices; - ptr_arrayidx12_i_125_indices.push_back(int32_i_0_reg2mem_0_i_118); - ptr_arrayidx12_i_125_indices.push_back(const_int32_32); - Instruction* ptr_arrayidx12_i_125 = new GetElementPtrInst(ptr_aconsts_107, ptr_arrayidx12_i_125_indices.begin(), ptr_arrayidx12_i_125_indices.end(), "arrayidx12.i", label_forbody_i_110); - LoadInst* float_tmp13_i_126 = new LoadInst(ptr_arrayidx12_i_125, "tmp13.i", false, label_forbody_i_110); - InsertElementInst* packed_tmp15_i_127 = new InsertElementInst(packed_tmp7_i_124, float_tmp13_i_126, const_int32_32, "tmp15.i", label_forbody_i_110); - std::vector<Value*> ptr_arrayidx20_i_128_indices; - ptr_arrayidx20_i_128_indices.push_back(int32_i_0_reg2mem_0_i_118); - ptr_arrayidx20_i_128_indices.push_back(const_int32_33); - Instruction* ptr_arrayidx20_i_128 = new GetElementPtrInst(ptr_aconsts_107, ptr_arrayidx20_i_128_indices.begin(), ptr_arrayidx20_i_128_indices.end(), "arrayidx20.i", label_forbody_i_110); - LoadInst* float_tmp21_i_129 = new LoadInst(ptr_arrayidx20_i_128, "tmp21.i", false, label_forbody_i_110); - InsertElementInst* packed_tmp23_i_130 = new InsertElementInst(packed_tmp15_i_127, float_tmp21_i_129, const_int32_33, "tmp23.i", label_forbody_i_110); - std::vector<Value*> ptr_arrayidx28_i_131_indices; - ptr_arrayidx28_i_131_indices.push_back(int32_i_0_reg2mem_0_i_118); - ptr_arrayidx28_i_131_indices.push_back(const_int32_34); - Instruction* ptr_arrayidx28_i_131 = new GetElementPtrInst(ptr_aconsts_107, ptr_arrayidx28_i_131_indices.begin(), ptr_arrayidx28_i_131_indices.end(), "arrayidx28.i", label_forbody_i_110); - LoadInst* float_tmp29_i_132 = new LoadInst(ptr_arrayidx28_i_131, "tmp29.i", false, label_forbody_i_110); - InsertElementInst* packed_tmp31_i_133 = new InsertElementInst(packed_tmp23_i_130, float_tmp29_i_132, const_int32_34, "tmp31.i", label_forbody_i_110); - std::vector<Value*> ptr_arrayidx34_i_134_indices; - ptr_arrayidx34_i_134_indices.push_back(const_int32_30); - ptr_arrayidx34_i_134_indices.push_back(int32_i_0_reg2mem_0_i_118); - Instruction* ptr_arrayidx34_i_134 = new GetElementPtrInst(ptr_consts_112, ptr_arrayidx34_i_134_indices.begin(), ptr_arrayidx34_i_134_indices.end(), "arrayidx34.i", label_forbody_i_110); - StoreInst* void_135 = new StoreInst(packed_tmp31_i_133, ptr_arrayidx34_i_134, false, label_forbody_i_110); - BinaryOperator* int32_indvar_next7 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_i_118, const_int32_32, "indvar.next7", label_forbody_i_110); - ICmpInst* int1_exitcond8 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next7, int32_num_consts_108, "exitcond8", label_forbody_i_110); - new BranchInst(label_from_consts_exit_111, label_forbody_i_110, int1_exitcond8, label_forbody_i_110); - - // Block from_consts.exit (label_from_consts_exit_111) + Instruction* ptr_tmp = new GetElementPtrInst(ptr_args_127, ptr_tmp_indices.begin(), ptr_tmp_indices.end(), "tmp", label_entry_121); + StoreInst* void_128 = new StoreInst(const_int32_29, ptr_tmp, false, label_entry_121); + ICmpInst* int1_cmp_i_129 = new ICmpInst(ICmpInst::ICMP_SGT, int32_num_consts_120, const_int32_29, "cmp.i", label_entry_121); + new BranchInst(label_forbody_preheader_i_122, label_from_consts_exit_124, int1_cmp_i_129, label_entry_121); + + // Block forbody.preheader.i (label_forbody_preheader_i_122) + BinaryOperator* int32_tmp_i_131 = BinaryOperator::create(Instruction::Add, int32_num_consts_120, const_int32_30, "tmp.i", label_forbody_preheader_i_122); + ICmpInst* int1_tmp9_i_132 = new ICmpInst(ICmpInst::ICMP_SLT, int32_tmp_i_131, const_int32_29, "tmp9.i", label_forbody_preheader_i_122); + SelectInst* int32_tmp10_i_133 = new SelectInst(int1_tmp9_i_132, const_int32_31, int32_num_consts_120, "tmp10.i", label_forbody_preheader_i_122); + new BranchInst(label_forbody_i_123, label_forbody_preheader_i_122); + + // Block forbody.i (label_forbody_i_123) + Argument* fwdref_136 = new Argument(IntegerType::get(32)); + PHINode* int32_i_0_reg2mem_0_i_135 = new PHINode(IntegerType::get(32), "i.0.reg2mem.0.i", label_forbody_i_123); + int32_i_0_reg2mem_0_i_135->reserveOperandSpace(2); + int32_i_0_reg2mem_0_i_135->addIncoming(const_int32_29, label_forbody_preheader_i_122); + int32_i_0_reg2mem_0_i_135->addIncoming(fwdref_136, label_forbody_i_123); + + Argument* fwdref_138 = new Argument(VectorTy_1); + PHINode* packed_vec_0_reg2mem_0_i_137 = new PHINode(VectorTy_1, "vec.0.reg2mem.0.i", label_forbody_i_123); + packed_vec_0_reg2mem_0_i_137->reserveOperandSpace(2); + packed_vec_0_reg2mem_0_i_137->addIncoming(const_packed_32, label_forbody_preheader_i_122); + packed_vec_0_reg2mem_0_i_137->addIncoming(fwdref_138, label_forbody_i_123); + + std::vector<Value*> ptr_arraydecay_i_139_indices; + ptr_arraydecay_i_139_indices.push_back(int32_i_0_reg2mem_0_i_135); + ptr_arraydecay_i_139_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay_i_139 = new GetElementPtrInst(ptr_aconsts_119, ptr_arraydecay_i_139_indices.begin(), ptr_arraydecay_i_139_indices.end(), "arraydecay.i", label_forbody_i_123); + LoadInst* float_tmp5_i_140 = new LoadInst(ptr_arraydecay_i_139, "tmp5.i", false, label_forbody_i_123); + InsertElementInst* packed_tmp7_i_141 = new InsertElementInst(packed_vec_0_reg2mem_0_i_137, float_tmp5_i_140, const_int32_29, "tmp7.i", label_forbody_i_123); + std::vector<Value*> ptr_arrayidx12_i_142_indices; + ptr_arrayidx12_i_142_indices.push_back(int32_i_0_reg2mem_0_i_135); + ptr_arrayidx12_i_142_indices.push_back(const_int32_31); + Instruction* ptr_arrayidx12_i_142 = new GetElementPtrInst(ptr_aconsts_119, ptr_arrayidx12_i_142_indices.begin(), ptr_arrayidx12_i_142_indices.end(), "arrayidx12.i", label_forbody_i_123); + LoadInst* float_tmp13_i_143 = new LoadInst(ptr_arrayidx12_i_142, "tmp13.i", false, label_forbody_i_123); + InsertElementInst* packed_tmp15_i_144 = new InsertElementInst(packed_tmp7_i_141, float_tmp13_i_143, const_int32_31, "tmp15.i", label_forbody_i_123); + std::vector<Value*> ptr_arrayidx20_i_145_indices; + ptr_arrayidx20_i_145_indices.push_back(int32_i_0_reg2mem_0_i_135); + ptr_arrayidx20_i_145_indices.push_back(const_int32_33); + Instruction* ptr_arrayidx20_i_145 = new GetElementPtrInst(ptr_aconsts_119, ptr_arrayidx20_i_145_indices.begin(), ptr_arrayidx20_i_145_indices.end(), "arrayidx20.i", label_forbody_i_123); + LoadInst* float_tmp21_i_146 = new LoadInst(ptr_arrayidx20_i_145, "tmp21.i", false, label_forbody_i_123); + InsertElementInst* packed_tmp23_i_147 = new InsertElementInst(packed_tmp15_i_144, float_tmp21_i_146, const_int32_33, "tmp23.i", label_forbody_i_123); + std::vector<Value*> ptr_arrayidx28_i_148_indices; + ptr_arrayidx28_i_148_indices.push_back(int32_i_0_reg2mem_0_i_135); + ptr_arrayidx28_i_148_indices.push_back(const_int32_34); + Instruction* ptr_arrayidx28_i_148 = new GetElementPtrInst(ptr_aconsts_119, ptr_arrayidx28_i_148_indices.begin(), ptr_arrayidx28_i_148_indices.end(), "arrayidx28.i", label_forbody_i_123); + LoadInst* float_tmp29_i_149 = new LoadInst(ptr_arrayidx28_i_148, "tmp29.i", false, label_forbody_i_123); + InsertElementInst* packed_tmp31_i_150 = new InsertElementInst(packed_tmp23_i_147, float_tmp29_i_149, const_int32_34, "tmp31.i", label_forbody_i_123); + std::vector<Value*> ptr_arrayidx34_i_151_indices; + ptr_arrayidx34_i_151_indices.push_back(const_int32_29); + ptr_arrayidx34_i_151_indices.push_back(int32_i_0_reg2mem_0_i_135); + Instruction* ptr_arrayidx34_i_151 = new GetElementPtrInst(ptr_consts_125, ptr_arrayidx34_i_151_indices.begin(), ptr_arrayidx34_i_151_indices.end(), "arrayidx34.i", label_forbody_i_123); + StoreInst* void_152 = new StoreInst(packed_tmp31_i_150, ptr_arrayidx34_i_151, false, label_forbody_i_123); + BinaryOperator* int32_indvar_next7 = BinaryOperator::create(Instruction::Add, int32_i_0_reg2mem_0_i_135, const_int32_31, "indvar.next7", label_forbody_i_123); + ICmpInst* int1_exitcond8 = new ICmpInst(ICmpInst::ICMP_EQ, int32_indvar_next7, int32_tmp10_i_133, "exitcond8", label_forbody_i_123); + new BranchInst(label_from_consts_exit_124, label_forbody_i_123, int1_exitcond8, label_forbody_i_123); + + // Block from_consts.exit (label_from_consts_exit_124) std::vector<Value*> ptr_tmp3_indices; - ptr_tmp3_indices.push_back(const_int32_30); + ptr_tmp3_indices.push_back(const_int32_29); ptr_tmp3_indices.push_back(const_int32_34); - Instruction* ptr_tmp3 = new GetElementPtrInst(ptr_args_114, ptr_tmp3_indices.begin(), ptr_tmp3_indices.end(), "tmp3", label_from_consts_exit_111); + Instruction* ptr_tmp3 = new GetElementPtrInst(ptr_args_127, ptr_tmp3_indices.begin(), ptr_tmp3_indices.end(), "tmp3", label_from_consts_exit_124); std::vector<Value*> ptr_arraydecay4_indices; - ptr_arraydecay4_indices.push_back(const_int32_30); - ptr_arraydecay4_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay4 = new GetElementPtrInst(ptr_consts_112, ptr_arraydecay4_indices.begin(), ptr_arraydecay4_indices.end(), "arraydecay4", label_from_consts_exit_111); - StoreInst* void_137 = new StoreInst(ptr_arraydecay4, ptr_tmp3, false, label_from_consts_exit_111); + ptr_arraydecay4_indices.push_back(const_int32_29); + ptr_arraydecay4_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay4 = new GetElementPtrInst(ptr_consts_125, ptr_arraydecay4_indices.begin(), ptr_arraydecay4_indices.end(), "arraydecay4", label_from_consts_exit_124); + StoreInst* void_154 = new StoreInst(ptr_arraydecay4, ptr_tmp3, false, label_from_consts_exit_124); std::vector<Value*> ptr_tmp5_indices; - ptr_tmp5_indices.push_back(const_int32_30); + ptr_tmp5_indices.push_back(const_int32_29); ptr_tmp5_indices.push_back(const_int32_33); - Instruction* ptr_tmp5 = new GetElementPtrInst(ptr_args_114, ptr_tmp5_indices.begin(), ptr_tmp5_indices.end(), "tmp5", label_from_consts_exit_111); + Instruction* ptr_tmp5 = new GetElementPtrInst(ptr_args_127, ptr_tmp5_indices.begin(), ptr_tmp5_indices.end(), "tmp5", label_from_consts_exit_124); std::vector<Value*> ptr_arraydecay6_indices; - ptr_arraydecay6_indices.push_back(const_int32_30); - ptr_arraydecay6_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay6 = new GetElementPtrInst(ptr_temps_113, ptr_arraydecay6_indices.begin(), ptr_arraydecay6_indices.end(), "arraydecay6", label_from_consts_exit_111); - StoreInst* void_138 = new StoreInst(ptr_arraydecay6, ptr_tmp5, false, label_from_consts_exit_111); - std::vector<Value*> ptr_tmp8_139_indices; - ptr_tmp8_139_indices.push_back(const_int32_30); - ptr_tmp8_139_indices.push_back(const_int32_32); - Instruction* ptr_tmp8_139 = new GetElementPtrInst(ptr_args_114, ptr_tmp8_139_indices.begin(), ptr_tmp8_139_indices.end(), "tmp8", label_from_consts_exit_111); - std::vector<Value*> ptr_tmp12_140_indices; - ptr_tmp12_140_indices.push_back(const_int32_30); - ptr_tmp12_140_indices.push_back(const_int32_30); - Instruction* ptr_tmp12_140 = new GetElementPtrInst(ptr_args_114, ptr_tmp12_140_indices.begin(), ptr_tmp12_140_indices.end(), "tmp12", label_from_consts_exit_111); - std::vector<Value*> ptr_arraydecay11_141_indices; - ptr_arraydecay11_141_indices.push_back(const_int32_30); - ptr_arraydecay11_141_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay11_141 = new GetElementPtrInst(ptr_inputs_105, ptr_arraydecay11_141_indices.begin(), ptr_arraydecay11_141_indices.end(), "arraydecay11", label_from_consts_exit_111); - StoreInst* void_142 = new StoreInst(ptr_arraydecay11_141, ptr_tmp8_139, false, label_from_consts_exit_111); - std::vector<Value*> ptr_arraydecay16_143_indices; - ptr_arraydecay16_143_indices.push_back(const_int32_30); - ptr_arraydecay16_143_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay16_143 = new GetElementPtrInst(ptr_results_104, ptr_arraydecay16_143_indices.begin(), ptr_arraydecay16_143_indices.end(), "arraydecay16", label_from_consts_exit_111); - StoreInst* void_144 = new StoreInst(ptr_arraydecay16_143, ptr_tmp12_140, false, label_from_consts_exit_111); - StoreInst* void_145 = new StoreInst(const_int32_30, ptr_tmp, false, label_from_consts_exit_111); - CallInst* void_146 = new CallInst(func_execute_shader, ptr_args_114, "", label_from_consts_exit_111); - void_146->setCallingConv(CallingConv::C); - void_146->setTailCall(false); - LoadInst* int32_tmp23 = new LoadInst(ptr_tmp, "tmp23", false, label_from_consts_exit_111); + ptr_arraydecay6_indices.push_back(const_int32_29); + ptr_arraydecay6_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay6 = new GetElementPtrInst(ptr_temps_126, ptr_arraydecay6_indices.begin(), ptr_arraydecay6_indices.end(), "arraydecay6", label_from_consts_exit_124); + StoreInst* void_155 = new StoreInst(ptr_arraydecay6, ptr_tmp5, false, label_from_consts_exit_124); + std::vector<Value*> ptr_tmp8_156_indices; + ptr_tmp8_156_indices.push_back(const_int32_29); + ptr_tmp8_156_indices.push_back(const_int32_31); + Instruction* ptr_tmp8_156 = new GetElementPtrInst(ptr_args_127, ptr_tmp8_156_indices.begin(), ptr_tmp8_156_indices.end(), "tmp8", label_from_consts_exit_124); + std::vector<Value*> ptr_tmp12_157_indices; + ptr_tmp12_157_indices.push_back(const_int32_29); + ptr_tmp12_157_indices.push_back(const_int32_29); + Instruction* ptr_tmp12_157 = new GetElementPtrInst(ptr_args_127, ptr_tmp12_157_indices.begin(), ptr_tmp12_157_indices.end(), "tmp12", label_from_consts_exit_124); + std::vector<Value*> ptr_arraydecay11_158_indices; + ptr_arraydecay11_158_indices.push_back(const_int32_29); + ptr_arraydecay11_158_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay11_158 = new GetElementPtrInst(ptr_inputs_117, ptr_arraydecay11_158_indices.begin(), ptr_arraydecay11_158_indices.end(), "arraydecay11", label_from_consts_exit_124); + StoreInst* void_159 = new StoreInst(ptr_arraydecay11_158, ptr_tmp8_156, false, label_from_consts_exit_124); + std::vector<Value*> ptr_arraydecay16_160_indices; + ptr_arraydecay16_160_indices.push_back(const_int32_29); + ptr_arraydecay16_160_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay16_160 = new GetElementPtrInst(ptr_results_116, ptr_arraydecay16_160_indices.begin(), ptr_arraydecay16_160_indices.end(), "arraydecay16", label_from_consts_exit_124); + StoreInst* void_161 = new StoreInst(ptr_arraydecay16_160, ptr_tmp12_157, false, label_from_consts_exit_124); + StoreInst* void_162 = new StoreInst(const_int32_29, ptr_tmp, false, label_from_consts_exit_124); + CallInst* void_163 = new CallInst(func_execute_shader, ptr_args_127, "", label_from_consts_exit_124); + void_163->setCallingConv(CallingConv::C); + void_163->setTailCall(false);const ParamAttrsList *void_163_PAL = 0; + void_163->setParamAttrs(void_163_PAL); + + LoadInst* int32_tmp23 = new LoadInst(ptr_tmp, "tmp23", false, label_from_consts_exit_124); std::vector<Value*> ptr_arraydecay11_1_indices; - ptr_arraydecay11_1_indices.push_back(const_int32_32); - ptr_arraydecay11_1_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay11_1 = new GetElementPtrInst(ptr_inputs_105, ptr_arraydecay11_1_indices.begin(), ptr_arraydecay11_1_indices.end(), "arraydecay11.1", label_from_consts_exit_111); - StoreInst* void_147 = new StoreInst(ptr_arraydecay11_1, ptr_tmp8_139, false, label_from_consts_exit_111); + ptr_arraydecay11_1_indices.push_back(const_int32_31); + ptr_arraydecay11_1_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay11_1 = new GetElementPtrInst(ptr_inputs_117, ptr_arraydecay11_1_indices.begin(), ptr_arraydecay11_1_indices.end(), "arraydecay11.1", label_from_consts_exit_124); + StoreInst* void_164 = new StoreInst(ptr_arraydecay11_1, ptr_tmp8_156, false, label_from_consts_exit_124); std::vector<Value*> ptr_arraydecay16_1_indices; - ptr_arraydecay16_1_indices.push_back(const_int32_32); - ptr_arraydecay16_1_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay16_1 = new GetElementPtrInst(ptr_results_104, ptr_arraydecay16_1_indices.begin(), ptr_arraydecay16_1_indices.end(), "arraydecay16.1", label_from_consts_exit_111); - StoreInst* void_148 = new StoreInst(ptr_arraydecay16_1, ptr_tmp12_140, false, label_from_consts_exit_111); - StoreInst* void_149 = new StoreInst(const_int32_30, ptr_tmp, false, label_from_consts_exit_111); - CallInst* void_150 = new CallInst(func_execute_shader, ptr_args_114, "", label_from_consts_exit_111); - void_150->setCallingConv(CallingConv::C); - void_150->setTailCall(false); - LoadInst* int32_tmp23_1 = new LoadInst(ptr_tmp, "tmp23.1", false, label_from_consts_exit_111); - BinaryOperator* int32_shl_1 = BinaryOperator::create(Instruction::Shl, int32_tmp23_1, const_int32_32, "shl.1", label_from_consts_exit_111); - BinaryOperator* int32_or_1 = BinaryOperator::create(Instruction::Or, int32_shl_1, int32_tmp23, "or.1", label_from_consts_exit_111); + ptr_arraydecay16_1_indices.push_back(const_int32_31); + ptr_arraydecay16_1_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay16_1 = new GetElementPtrInst(ptr_results_116, ptr_arraydecay16_1_indices.begin(), ptr_arraydecay16_1_indices.end(), "arraydecay16.1", label_from_consts_exit_124); + StoreInst* void_165 = new StoreInst(ptr_arraydecay16_1, ptr_tmp12_157, false, label_from_consts_exit_124); + StoreInst* void_166 = new StoreInst(const_int32_29, ptr_tmp, false, label_from_consts_exit_124); + CallInst* void_167 = new CallInst(func_execute_shader, ptr_args_127, "", label_from_consts_exit_124); + void_167->setCallingConv(CallingConv::C); + void_167->setTailCall(false);const ParamAttrsList *void_167_PAL = 0; + void_167->setParamAttrs(void_167_PAL); + + LoadInst* int32_tmp23_1 = new LoadInst(ptr_tmp, "tmp23.1", false, label_from_consts_exit_124); + BinaryOperator* int32_shl_1 = BinaryOperator::create(Instruction::Shl, int32_tmp23_1, const_int32_31, "shl.1", label_from_consts_exit_124); + BinaryOperator* int32_or_1 = BinaryOperator::create(Instruction::Or, int32_shl_1, int32_tmp23, "or.1", label_from_consts_exit_124); std::vector<Value*> ptr_arraydecay11_2_indices; ptr_arraydecay11_2_indices.push_back(const_int32_33); - ptr_arraydecay11_2_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay11_2 = new GetElementPtrInst(ptr_inputs_105, ptr_arraydecay11_2_indices.begin(), ptr_arraydecay11_2_indices.end(), "arraydecay11.2", label_from_consts_exit_111); - StoreInst* void_151 = new StoreInst(ptr_arraydecay11_2, ptr_tmp8_139, false, label_from_consts_exit_111); + ptr_arraydecay11_2_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay11_2 = new GetElementPtrInst(ptr_inputs_117, ptr_arraydecay11_2_indices.begin(), ptr_arraydecay11_2_indices.end(), "arraydecay11.2", label_from_consts_exit_124); + StoreInst* void_168 = new StoreInst(ptr_arraydecay11_2, ptr_tmp8_156, false, label_from_consts_exit_124); std::vector<Value*> ptr_arraydecay16_2_indices; ptr_arraydecay16_2_indices.push_back(const_int32_33); - ptr_arraydecay16_2_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay16_2 = new GetElementPtrInst(ptr_results_104, ptr_arraydecay16_2_indices.begin(), ptr_arraydecay16_2_indices.end(), "arraydecay16.2", label_from_consts_exit_111); - StoreInst* void_152 = new StoreInst(ptr_arraydecay16_2, ptr_tmp12_140, false, label_from_consts_exit_111); - StoreInst* void_153 = new StoreInst(const_int32_30, ptr_tmp, false, label_from_consts_exit_111); - CallInst* void_154 = new CallInst(func_execute_shader, ptr_args_114, "", label_from_consts_exit_111); - void_154->setCallingConv(CallingConv::C); - void_154->setTailCall(false); - LoadInst* int32_tmp23_2 = new LoadInst(ptr_tmp, "tmp23.2", false, label_from_consts_exit_111); - BinaryOperator* int32_shl_2 = BinaryOperator::create(Instruction::Shl, int32_tmp23_2, const_int32_33, "shl.2", label_from_consts_exit_111); - BinaryOperator* int32_or_2 = BinaryOperator::create(Instruction::Or, int32_shl_2, int32_or_1, "or.2", label_from_consts_exit_111); + ptr_arraydecay16_2_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay16_2 = new GetElementPtrInst(ptr_results_116, ptr_arraydecay16_2_indices.begin(), ptr_arraydecay16_2_indices.end(), "arraydecay16.2", label_from_consts_exit_124); + StoreInst* void_169 = new StoreInst(ptr_arraydecay16_2, ptr_tmp12_157, false, label_from_consts_exit_124); + StoreInst* void_170 = new StoreInst(const_int32_29, ptr_tmp, false, label_from_consts_exit_124); + CallInst* void_171 = new CallInst(func_execute_shader, ptr_args_127, "", label_from_consts_exit_124); + void_171->setCallingConv(CallingConv::C); + void_171->setTailCall(false);const ParamAttrsList *void_171_PAL = 0; + void_171->setParamAttrs(void_171_PAL); + + LoadInst* int32_tmp23_2 = new LoadInst(ptr_tmp, "tmp23.2", false, label_from_consts_exit_124); + BinaryOperator* int32_shl_2 = BinaryOperator::create(Instruction::Shl, int32_tmp23_2, const_int32_33, "shl.2", label_from_consts_exit_124); + BinaryOperator* int32_or_2 = BinaryOperator::create(Instruction::Or, int32_shl_2, int32_or_1, "or.2", label_from_consts_exit_124); std::vector<Value*> ptr_arraydecay11_3_indices; ptr_arraydecay11_3_indices.push_back(const_int32_34); - ptr_arraydecay11_3_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay11_3 = new GetElementPtrInst(ptr_inputs_105, ptr_arraydecay11_3_indices.begin(), ptr_arraydecay11_3_indices.end(), "arraydecay11.3", label_from_consts_exit_111); - StoreInst* void_155 = new StoreInst(ptr_arraydecay11_3, ptr_tmp8_139, false, label_from_consts_exit_111); + ptr_arraydecay11_3_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay11_3 = new GetElementPtrInst(ptr_inputs_117, ptr_arraydecay11_3_indices.begin(), ptr_arraydecay11_3_indices.end(), "arraydecay11.3", label_from_consts_exit_124); + StoreInst* void_172 = new StoreInst(ptr_arraydecay11_3, ptr_tmp8_156, false, label_from_consts_exit_124); std::vector<Value*> ptr_arraydecay16_3_indices; ptr_arraydecay16_3_indices.push_back(const_int32_34); - ptr_arraydecay16_3_indices.push_back(const_int32_30); - Instruction* ptr_arraydecay16_3 = new GetElementPtrInst(ptr_results_104, ptr_arraydecay16_3_indices.begin(), ptr_arraydecay16_3_indices.end(), "arraydecay16.3", label_from_consts_exit_111); - StoreInst* void_156 = new StoreInst(ptr_arraydecay16_3, ptr_tmp12_140, false, label_from_consts_exit_111); - StoreInst* void_157 = new StoreInst(const_int32_30, ptr_tmp, false, label_from_consts_exit_111); - CallInst* void_158 = new CallInst(func_execute_shader, ptr_args_114, "", label_from_consts_exit_111); - void_158->setCallingConv(CallingConv::C); - void_158->setTailCall(false); - LoadInst* int32_tmp23_3 = new LoadInst(ptr_tmp, "tmp23.3", false, label_from_consts_exit_111); - BinaryOperator* int32_shl_3 = BinaryOperator::create(Instruction::Shl, int32_tmp23_3, const_int32_34, "shl.3", label_from_consts_exit_111); - BinaryOperator* int32_or_3 = BinaryOperator::create(Instruction::Or, int32_shl_3, int32_or_2, "or.3", label_from_consts_exit_111); - BinaryOperator* int32_neg = BinaryOperator::create(Instruction::Xor, int32_or_3, const_int32_36, "neg", label_from_consts_exit_111); - new ReturnInst(int32_neg, label_from_consts_exit_111); + ptr_arraydecay16_3_indices.push_back(const_int32_29); + Instruction* ptr_arraydecay16_3 = new GetElementPtrInst(ptr_results_116, ptr_arraydecay16_3_indices.begin(), ptr_arraydecay16_3_indices.end(), "arraydecay16.3", label_from_consts_exit_124); + StoreInst* void_173 = new StoreInst(ptr_arraydecay16_3, ptr_tmp12_157, false, label_from_consts_exit_124); + StoreInst* void_174 = new StoreInst(const_int32_29, ptr_tmp, false, label_from_consts_exit_124); + CallInst* void_175 = new CallInst(func_execute_shader, ptr_args_127, "", label_from_consts_exit_124); + void_175->setCallingConv(CallingConv::C); + void_175->setTailCall(false);const ParamAttrsList *void_175_PAL = 0; + void_175->setParamAttrs(void_175_PAL); + + LoadInst* int32_tmp23_3 = new LoadInst(ptr_tmp, "tmp23.3", false, label_from_consts_exit_124); + BinaryOperator* int32_shl_3 = BinaryOperator::create(Instruction::Shl, int32_tmp23_3, const_int32_34, "shl.3", label_from_consts_exit_124); + BinaryOperator* int32_or_3 = BinaryOperator::create(Instruction::Or, int32_shl_3, int32_or_2, "or.3", label_from_consts_exit_124); + BinaryOperator* int32_neg = BinaryOperator::create(Instruction::Xor, int32_or_3, const_int32_30, "neg", label_from_consts_exit_124); + new ReturnInst(int32_neg, label_from_consts_exit_124); // Resolve Forward References - fwdref_121->replaceAllUsesWith(packed_tmp31_i_133); delete fwdref_121; - fwdref_119->replaceAllUsesWith(int32_indvar_next7); delete fwdref_119; + fwdref_138->replaceAllUsesWith(packed_tmp31_i_150); delete fwdref_138; + fwdref_136->replaceAllUsesWith(int32_indvar_next7); delete fwdref_136; } diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 1afb38a868..7a18d48865 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -29,7 +29,7 @@ #define PIPE_CONTEXT_H #include "p_state.h" -#include <stdint.h> + struct pipe_state_cache; @@ -97,7 +97,7 @@ struct pipe_context { boolean (*get_query_result)(struct pipe_context *pipe, struct pipe_query *q, boolean wait, - uint64_t *result); + uint64 *result); /* * State functions @@ -192,11 +192,6 @@ struct pipe_context { struct pipe_surface *ps, uint x, uint y, uint w, uint h, const void *p, int src_stride); - /* XXX temporary here, move these to softpipe */ - void (*get_tile_rgba)(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, float *p); - void (*put_tile_rgba)(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, const float *p); /* diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index a67ed60547..50bea691e7 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -115,10 +115,12 @@ #define PIPE_STENCIL_OP_INVERT 7 /** Texture types */ -#define PIPE_TEXTURE_1D 0 -#define PIPE_TEXTURE_2D 1 -#define PIPE_TEXTURE_3D 2 -#define PIPE_TEXTURE_CUBE 3 +enum pipe_texture_target { + PIPE_TEXTURE_1D = 0, + PIPE_TEXTURE_2D = 1, + PIPE_TEXTURE_3D = 2, + PIPE_TEXTURE_CUBE = 3 +}; #define PIPE_TEX_FACE_POS_X 0 #define PIPE_TEX_FACE_NEG_X 1 @@ -168,6 +170,14 @@ /** + * Surface status + */ +#define PIPE_SURFACE_STATUS_UNDEFINED 0 +#define PIPE_SURFACE_STATUS_DEFINED 1 +#define PIPE_SURFACE_STATUS_CLEAR 2 + + +/** * Buffer access flags */ #define PIPE_BUFFER_FLAG_READ 0x1 diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index e7303c45c1..6976d087f9 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -33,35 +33,21 @@ #include "p_winsys.h" -static INLINE ubyte * +static INLINE void * pipe_surface_map(struct pipe_surface *surface) { - if (!surface->map_refcount++) { - surface->map - = (ubyte *) surface->winsys->buffer_map( surface->winsys, - surface->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ ) - + surface->offset; - } - - return surface->map; + return (char *)surface->winsys->buffer_map( surface->winsys, surface->buffer, + PIPE_BUFFER_FLAG_WRITE | + PIPE_BUFFER_FLAG_READ ) + + surface->offset; } static INLINE void pipe_surface_unmap(struct pipe_surface *surface) { - if (surface->map_refcount > 0) { - assert(surface->map); - if (!--surface->map_refcount) { - surface->winsys->buffer_unmap( surface->winsys, - surface->buffer ); - surface->map = NULL; - } - } + surface->winsys->buffer_unmap( surface->winsys, surface->buffer ); } - /** * Set 'ptr' to point to 'surf' and update reference counting. * The old thing pointed to, if any, will be unreferenced first. diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 16d50fdb82..46328d2a8f 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -39,6 +39,7 @@ #define PIPE_STATE_H #include "p_compiler.h" +#include "p_defines.h" #include "p_format.h" /** @@ -55,18 +56,13 @@ #define PIPE_MAX_SHADER_OUTPUTS 16 -/* fwd decl */ +/* fwd decls */ struct pipe_surface; +struct pipe_winsys; /* opaque type */ struct pipe_buffer_handle; -struct pipe_winsys; - - -/*** - *** State objects - ***/ /** @@ -114,6 +110,7 @@ struct pipe_viewport_state { float translate[4]; }; + struct pipe_scissor_state { unsigned minx:16; unsigned miny:16; @@ -121,6 +118,7 @@ struct pipe_scissor_state { unsigned maxy:16; }; + struct pipe_clip_state { float ucp[PIPE_MAX_CLIP_PLANES][4]; unsigned nr; @@ -147,13 +145,14 @@ struct pipe_shader_state { ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; }; + struct pipe_depth_stencil_alpha_state { struct { - unsigned enabled:1; /**< depth test enabled? */ - unsigned writemask:1; /**< allow depth buffer writes? */ - unsigned func:3; /**< depth test func (PIPE_FUNC_x) */ - unsigned occlusion_count:1; /**< XXX move this elsewhere? */ + unsigned enabled:1; /**< depth test enabled? */ + unsigned writemask:1; /**< allow depth buffer writes? */ + unsigned func:3; /**< depth test func (PIPE_FUNC_x) */ + unsigned occlusion_count:1; /**< do occlusion counting? */ } depth; struct { unsigned enabled:1; @@ -164,12 +163,11 @@ struct pipe_depth_stencil_alpha_state ubyte ref_value; ubyte value_mask; ubyte write_mask; - } stencil[2]; /**< [0] = front, [1] = back */ - + } stencil[2]; /**< [0] = front, [1] = back */ struct { unsigned enabled:1; - unsigned func:3; /**< PIPE_FUNC_x */ - float ref; /**< reference value */ + unsigned func:3; /**< PIPE_FUNC_x */ + float ref; /**< reference value */ } alpha; }; @@ -192,10 +190,12 @@ struct pipe_blend_state { unsigned dither:1; }; + struct pipe_blend_color { float color[4]; }; + struct pipe_framebuffer_state { /** multiple colorbuffers for multiple render targets */ @@ -242,9 +242,9 @@ struct pipe_sampler_state struct pipe_surface { struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ - ubyte *map; /**< only non-NULL when surface is actually mapped */ - unsigned map_refcount; /**< Reference count for mapping */ enum pipe_format format; /**< PIPE_FORMAT_x */ + unsigned status; /**< PIPE_SURFACE_STATUS_x */ + unsigned clear_value; /**< may be temporary */ unsigned cpp; /**< bytes per pixel */ unsigned width, height; unsigned pitch; /**< in pixels */ @@ -262,8 +262,8 @@ struct pipe_texture { /* Effectively the key: */ - unsigned target; /**< PIPE_TEXTURE_x */ - enum pipe_format format; /**< PIPE_FORMAT_x */ + enum pipe_texture_target target; /**< PIPE_TEXTURE_x */ + enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned first_level; unsigned last_level; @@ -313,5 +313,4 @@ struct pipe_vertex_element }; - #endif diff --git a/src/mesa/pipe/p_util.h b/src/mesa/pipe/p_util.h index 46edcf3075..69ec62e307 100644 --- a/src/mesa/pipe/p_util.h +++ b/src/mesa/pipe/p_util.h @@ -30,7 +30,6 @@ #include "p_compiler.h" #include <math.h> -#include <stdint.h> #ifdef WIN32 @@ -124,6 +123,7 @@ align_malloc(size_t bytes, uint alignment) (void) posix_memalign(& mem, alignment, bytes); return mem; #else + typedef unsigned long int uintptr_t; uintptr_t ptr, buf; assert( alignment > 0 ); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index c7af63cc2d..68c18e2d05 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -75,22 +75,15 @@ softpipe_is_format_supported( struct pipe_context *pipe, void softpipe_map_surfaces(struct softpipe_context *sp) { - struct pipe_surface *ps; unsigned i; for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - ps = sp->framebuffer.cbufs[i]; - if (ps->buffer) - pipe_surface_map(ps); + sp_tile_cache_map_surfaces(sp->cbuf_cache[i]); } - ps = sp->framebuffer.zbuf; - if (ps && ps->buffer) - pipe_surface_map(ps); + sp_tile_cache_map_surfaces(sp->zbuf_cache); - ps = sp->framebuffer.sbuf; - if (ps && ps->buffer) - pipe_surface_map(ps); + sp_tile_cache_map_surfaces(sp->sbuf_cache); } @@ -100,7 +93,6 @@ softpipe_map_surfaces(struct softpipe_context *sp) void softpipe_unmap_surfaces(struct softpipe_context *sp) { - struct pipe_surface *ps; uint i; for (i = 0; i < sp->framebuffer.num_cbufs; i++) @@ -109,18 +101,12 @@ softpipe_unmap_surfaces(struct softpipe_context *sp) sp_flush_tile_cache(sp, sp->sbuf_cache); for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - ps = sp->framebuffer.cbufs[i]; - if (ps->map) - pipe_surface_unmap(ps); + sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]); } - ps = sp->framebuffer.zbuf; - if (ps && ps->map) - pipe_surface_unmap(ps); + sp_tile_cache_unmap_surfaces(sp->zbuf_cache); - ps = sp->framebuffer.sbuf; - if (ps && ps->map) - pipe_surface_unmap(ps); + sp_tile_cache_unmap_surfaces(sp->sbuf_cache); } @@ -345,7 +331,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, if (GETENV( "SP_VBUF" ) != NULL) { softpipe->vbuf = sp_draw_vbuf_stage(softpipe->draw, &softpipe->pipe, - sp_vbuf_setup_draw); + sp_vbuf_render); draw_set_rasterize_stage(softpipe->draw, softpipe->vbuf); } diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 394baf0109..3537f86a61 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -76,7 +76,7 @@ struct softpipe_context { /* Counter for occlusion queries. Note this supports overlapping * queries. */ - uint64_t occlusion_count; + uint64 occlusion_count; /* * Mapped vertex buffers diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index de45529bf9..722cadc5c0 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -1286,18 +1286,20 @@ static void calc_det( struct prim_header *header ) -/* Test harness - feed vertex buffer back into prim pipeline. +/** + * Render buffer of points/lines/triangles. + * Called by vbuf code when the vertex or index buffer is filled. * * The big issue at this point is that reset_stipple doesn't make it * through the interface. Probably need to split primitives at reset * stipple, perhaps using the ~0 index marker. */ -void sp_vbuf_setup_draw( struct pipe_context *pipe, - unsigned primitive, - const ushort *elements, - unsigned nr_elements, - const void *vertex_buffer, - unsigned nr_vertices ) +void sp_vbuf_render( struct pipe_context *pipe, + unsigned primitive, + const ushort *elements, + unsigned nr_elements, + const void *vertex_buffer, + unsigned nr_vertices ) { struct softpipe_context *softpipe = softpipe_context( pipe ); struct setup_stage *setup = setup_stage( softpipe->setup ); diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.h b/src/mesa/pipe/softpipe/sp_prim_setup.h index 598394f73e..c16dc634b0 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.h +++ b/src/mesa/pipe/softpipe/sp_prim_setup.h @@ -1,33 +1,49 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5 - * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. - * +/************************************************************************** + * + * 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, sublicense, - * 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 shall be included - * in all copies or substantial portions of the Software. - * + * 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 NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL 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. - */ + * 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 SP_PRIM_SETUP_H #define SP_PRIM_SETUP_H -/* Vertices are just an array of floats, with all the attributes +/** + * vbuf is a special stage to gather the stream of triangles, lines, points + * together and reconstruct vertex buffers for hardware upload. + * + * First attempt, work in progress. + * + * TODO: + * - separate out vertex buffer building and primitive emit, ie >1 draw per vb. + * - tell vbuf stage how to build hw vertices directly + * - pass vbuf stage a buffer pointer for direct emit to agp/vram. + * + * + * + * Vertices are just an array of floats, with all the attributes * packed. We currently assume a layout like: * * attr[0][0..3] - window position @@ -37,23 +53,11 @@ * all the enabled attributes run contiguously. */ + struct draw_stage; struct softpipe_context; -extern struct draw_stage *sp_draw_render_stage( struct softpipe_context *softpipe ); - - -/* A special stage to gather the stream of triangles, lines, points - * together and reconstruct vertex buffers for hardware upload. - * - * First attempt, work in progress. - * - * TODO: - * - separate out vertex buffer building and primitive emit, ie >1 draw per vb. - * - tell vbuf stage how to build hw vertices directly - * - pass vbuf stage a buffer pointer for direct emit to agp/vram. - */ typedef void (*vbuf_draw_func)( struct pipe_context *pipe, unsigned prim, const ushort *elements, @@ -62,20 +66,23 @@ typedef void (*vbuf_draw_func)( struct pipe_context *pipe, unsigned nr_vertices ); -extern struct draw_stage *sp_draw_vbuf_stage( struct draw_context *draw_context, - struct pipe_context *pipe, - vbuf_draw_func draw ); +extern struct draw_stage * +sp_draw_render_stage( struct softpipe_context *softpipe ); +extern struct draw_stage * +sp_draw_vbuf_stage( struct draw_context *draw_context, + struct pipe_context *pipe, + vbuf_draw_func draw ); -/* Test harness - */ -void sp_vbuf_setup_draw( struct pipe_context *pipe, - unsigned prim, - const ushort *elements, - unsigned nr_elements, - const void *vertex_buffer, - unsigned nr_vertices ); + +extern void +sp_vbuf_render( struct pipe_context *pipe, + unsigned prim, + const ushort *elements, + unsigned nr_elements, + const void *vertex_buffer, + unsigned nr_vertices ); diff --git a/src/mesa/pipe/softpipe/sp_prim_vbuf.c b/src/mesa/pipe/softpipe/sp_prim_vbuf.c index 2cfdeb5809..055cb19f9a 100644 --- a/src/mesa/pipe/softpipe/sp_prim_vbuf.c +++ b/src/mesa/pipe/softpipe/sp_prim_vbuf.c @@ -120,6 +120,12 @@ static void emit_vertex( struct vbuf_stage *vbuf, vertex->vertex_id = vbuf->nr_vertices++; //vbuf->emit_vertex( vbuf->vertex_ptr, vertex ); + + /* Note: for softpipe, the vertex includes the vertex header info + * such as clip flags and clip coords. In the future when vbuf is + * always used, we could just copy the vertex attributes/data here. + * The sp_prim_setup.c code doesn't use any of the vertex header info. + */ memcpy(vbuf->vertex_ptr, vertex, vbuf->vertex_size); vbuf->vertex_ptr += vbuf->vertex_size; @@ -221,7 +227,9 @@ static void vbuf_flush_elements( struct draw_stage *stage ) struct vbuf_stage *vbuf = vbuf_stage( stage ); if (vbuf->nr_elements) { + /* fprintf(stderr, "%s (%d elts)\n", __FUNCTION__, vbuf->nr_elements); + */ /* Draw now or add to list of primitives??? */ diff --git a/src/mesa/pipe/softpipe/sp_query.c b/src/mesa/pipe/softpipe/sp_query.c index bf753dad98..6a8a43aeda 100644 --- a/src/mesa/pipe/softpipe/sp_query.c +++ b/src/mesa/pipe/softpipe/sp_query.c @@ -37,8 +37,8 @@ #include "sp_query.h" struct softpipe_query { - uint64_t start; - uint64_t end; + uint64 start; + uint64 end; }; @@ -87,7 +87,7 @@ static boolean softpipe_get_query_result(struct pipe_context *pipe, struct pipe_query *q, boolean wait, - uint64_t *result ) + uint64 *result ) { struct softpipe_query *sq = softpipe_query(q); *result = sq->end - sq->start; diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index c1f5555a86..bac7b0876f 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -75,7 +75,7 @@ struct sp_fragment_shader_state { /** Subclass of pipe_shader_state */ struct sp_vertex_shader_state { struct pipe_shader_state shader; - void *draw_data; + struct draw_vertex_shader *draw_data; }; diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index f72a91485f..945c93411f 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -38,8 +38,9 @@ #include "pipe/tgsi/exec/tgsi_sse2.h" -void * softpipe_create_fs_state(struct pipe_context *pipe, - const struct pipe_shader_state *templ) +void * +softpipe_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) { struct softpipe_context *softpipe = softpipe_context(pipe); struct sp_fragment_shader_state *state; @@ -58,13 +59,6 @@ void * softpipe_create_fs_state(struct pipe_context *pipe, tgsi_dump(state->shader.tokens, 0); } -#if defined(__i386__) || defined(__386__) - if (softpipe->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()) { @@ -72,13 +66,19 @@ void * softpipe_create_fs_state(struct pipe_context *pipe, } else gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state->llvm_prog); +#elif defined(__i386__) || defined(__386__) + if (softpipe->use_sse) { + x86_init_func( &state->sse2_program ); + tgsi_emit_sse2_fs( state->shader.tokens, &state->sse2_program ); + } #endif return state; } -void softpipe_bind_fs_state(struct pipe_context *pipe, void *fs) +void +softpipe_bind_fs_state(struct pipe_context *pipe, void *fs) { struct softpipe_context *softpipe = softpipe_context(pipe); @@ -88,10 +88,10 @@ void softpipe_bind_fs_state(struct pipe_context *pipe, void *fs) } -void softpipe_delete_fs_state(struct pipe_context *pipe, - void *shader) +void +softpipe_delete_fs_state(struct pipe_context *pipe, void *fs) { - struct sp_fragment_shader_state *state = shader; + struct sp_fragment_shader_state *state = fs; #if defined(__i386__) || defined(__386__) x86_release_func( &state->sse2_program ); @@ -101,8 +101,9 @@ void softpipe_delete_fs_state(struct pipe_context *pipe, } -void * softpipe_create_vs_state(struct pipe_context *pipe, - const struct pipe_shader_state *templ) +void * +softpipe_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) { struct softpipe_context *softpipe = softpipe_context(pipe); struct sp_vertex_shader_state *state; @@ -125,7 +126,8 @@ void * softpipe_create_vs_state(struct pipe_context *pipe, } -void softpipe_bind_vs_state(struct pipe_context *pipe, void *vs) +void +softpipe_bind_vs_state(struct pipe_context *pipe, void *vs) { struct softpipe_context *softpipe = softpipe_context(pipe); @@ -137,7 +139,8 @@ void softpipe_bind_vs_state(struct pipe_context *pipe, void *vs) } -void softpipe_delete_vs_state(struct pipe_context *pipe, void *vs) +void +softpipe_delete_vs_state(struct pipe_context *pipe, void *vs) { struct softpipe_context *softpipe = softpipe_context(pipe); @@ -149,9 +152,11 @@ void softpipe_delete_vs_state(struct pipe_context *pipe, void *vs) } -void softpipe_set_constant_buffer(struct pipe_context *pipe, - uint shader, uint index, - const struct pipe_constant_buffer *buf) + +void +softpipe_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + const struct pipe_constant_buffer *buf) { struct softpipe_context *softpipe = softpipe_context(pipe); struct pipe_winsys *ws = pipe->winsys; diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c index ee72aaf4c5..4a9a28cc4d 100644 --- a/src/mesa/pipe/softpipe/sp_state_surface.c +++ b/src/mesa/pipe/softpipe/sp_state_surface.c @@ -38,7 +38,7 @@ /** * XXX this might get moved someday * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer. - * Here, we map the surfaces and update the tile cache to point to the new + * Here, we flush the old surfaces and update the tile cache to point to the new * surfaces. */ void @@ -46,7 +46,6 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, const struct pipe_framebuffer_state *fb) { struct softpipe_context *sp = softpipe_context(pipe); - struct pipe_surface *ps; uint i; for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { @@ -54,19 +53,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, 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->cbuf_cache[i], ps); + sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]); } } @@ -76,23 +68,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, 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->zbuf_cache, ps); + sp_tile_cache_set_surface(sp->zbuf_cache, fb->zbuf); } /* XXX combined depth/stencil here */ @@ -101,14 +82,7 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, 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; @@ -116,12 +90,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, if (fb->sbuf != fb->zbuf) { /* separate stencil buf */ sp->sbuf_cache = sp->sbuf_cache_sep; - sp_tile_cache_set_surface(sp->sbuf_cache, ps); + sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf); } else { /* combined depth/stencil */ sp->sbuf_cache = sp->zbuf_cache; - sp_tile_cache_set_surface(sp->sbuf_cache, ps); + sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf); } } diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index 5259fbfd20..6c080d5b5c 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -46,20 +46,6 @@ softpipe_get_tex_surface(struct pipe_context *pipe, { struct softpipe_texture *spt = softpipe_texture(pt); struct pipe_surface *ps; - unsigned offset; /* in bytes */ - - offset = spt->level_offset[level]; - - if (pt->target == PIPE_TEXTURE_CUBE) { - offset += spt->image_offset[level][face] * pt->cpp; - } - else if (pt->target == PIPE_TEXTURE_3D) { - offset += spt->image_offset[level][zslice] * pt->cpp; - } - else { - assert(face == 0); - assert(zslice == 0); - } ps = pipe->winsys->surface_alloc(pipe->winsys); if (ps) { @@ -69,8 +55,17 @@ softpipe_get_tex_surface(struct pipe_context *pipe, ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; - ps->pitch = spt->pitch; - ps->offset = offset; + ps->pitch = ps->width; + ps->offset = spt->level_offset[level]; + + if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) { + ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) * + (pt->compressed ? ps->height/4 : ps->height) * + ps->width * ps->cpp; + } else { + assert(face == 0); + assert(zslice == 0); + } } return ps; } @@ -163,10 +158,10 @@ sp_surface_copy(struct pipe_context *pipe, } -static ubyte * -get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +static void * +get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) { - return dst->map + (y * dst->pitch + x) * dst->cpp; + return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; } @@ -184,16 +179,16 @@ sp_surface_fill(struct pipe_context *pipe, unsigned width, unsigned height, unsigned value) { unsigned i, j; + void *dst_map = pipe_surface_map(dst); assert(dst->pitch > 0); assert(width <= dst->pitch); - (void)pipe_surface_map(dst); switch (dst->cpp) { case 1: { - ubyte *row = get_pointer(dst, dstx, dsty); + ubyte *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { memset(row, value, width); row += dst->pitch; @@ -202,7 +197,7 @@ sp_surface_fill(struct pipe_context *pipe, break; case 2: { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = (ushort) value; @@ -212,7 +207,7 @@ sp_surface_fill(struct pipe_context *pipe, break; case 4: { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + unsigned *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = value; @@ -223,7 +218,7 @@ sp_surface_fill(struct pipe_context *pipe, case 8: { /* expand the 4-byte clear value to an 8-byte value */ - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort *row = (ushort *) get_pointer(dst, dst_map, dstx, dsty); ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff); ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff); ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff); @@ -257,8 +252,6 @@ sp_init_surface_functions(struct softpipe_context *sp) { sp->pipe.get_tile = pipe_get_tile_raw; sp->pipe.put_tile = pipe_put_tile_raw; - sp->pipe.get_tile_rgba = pipe_get_tile_rgba; - sp->pipe.put_tile_rgba = pipe_put_tile_rgba; sp->pipe.surface_data = sp_surface_data; sp->pipe.surface_copy = sp_surface_copy; diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c index 44512e4281..e5e6bfe01b 100644 --- a/src/mesa/pipe/softpipe/sp_texture.c +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -41,10 +41,7 @@ #include "sp_texture.h" -/* At the moment, just make softpipe use the same layout for its - * textures as the i945. Softpipe needs some sort of texture layout, - * this one was handy. May be worthwhile to simplify this code a - * little. +/* Simple, maximally packed layout. */ static unsigned minify( unsigned d ) @@ -53,319 +50,35 @@ static unsigned minify( unsigned d ) } - -static void -sp_miptree_set_level_info(struct softpipe_texture *spt, - unsigned level, - unsigned nr_images, - unsigned x, unsigned y, unsigned w, unsigned h, - unsigned d) -{ - struct pipe_texture *pt = &spt->base; - - assert(level < PIPE_MAX_TEXTURE_LEVELS); - - pt->width[level] = w; - pt->height[level] = h; - pt->depth[level] = d; - - spt->nr_images[level] = nr_images; - spt->level_offset[level] = (x + y * spt->pitch) * pt->cpp; - - /* - DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, - level, w, h, d, x, y, spt->level_offset[level]); - */ - - /* Not sure when this would happen, but anyway: - */ - if (spt->image_offset[level]) { - FREE( spt->image_offset[level] ); - spt->image_offset[level] = NULL; - } - - assert(nr_images); - assert(!spt->image_offset[level]); - - spt->image_offset[level] = (unsigned *) MALLOC( nr_images * sizeof(unsigned) ); - spt->image_offset[level][0] = 0; -} - - -static void -sp_miptree_set_image_offset(struct softpipe_texture *spt, - unsigned level, unsigned img, unsigned x, unsigned y) -{ - if (img == 0 && level == 0) - assert(x == 0 && y == 0); - - assert(img < spt->nr_images[level]); - - spt->image_offset[level][img] = (x + y * spt->pitch); - - /* - DBG("%s level %d img %d pos %d,%d image_offset %x\n", - __FUNCTION__, level, img, x, y, spt->image_offset[level][img]); - */ -} - - static void -sp_miptree_layout_2d( struct softpipe_texture *spt ) +softpipe_texture_layout(struct softpipe_texture * spt) { struct pipe_texture *pt = &spt->base; - int align_h = 2, align_w = 4; unsigned level; - unsigned x = 0; - unsigned y = 0; unsigned width = pt->width[0]; unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; - spt->pitch = pt->width[0]; - /* XXX FIX THIS: - * we use alignment=64 bytes in sp_region_alloc(). If we change - * that, change this too. - */ - if (spt->pitch < 16) - spt->pitch = 16; - - /* May need to adjust pitch to accomodate the placement of - * the 2nd mipmap. This occurs when the alignment - * constraints of mipmap placement push the right edge of the - * 2nd mipmap out past the width of its parent. - */ - if (pt->first_level != pt->last_level) { - unsigned mip1_width = align(minify(pt->width[0]), align_w) - + minify(minify(pt->width[0])); - - if (mip1_width > pt->width[0]) - spt->pitch = mip1_width; - } - - /* Pitch must be a whole number of dwords, even though we - * express it in texels. - */ - spt->pitch = align(spt->pitch * pt->cpp, 4) / pt->cpp; - spt->total_height = 0; + spt->buffer_size = 0; for ( level = pt->first_level ; level <= pt->last_level ; level++ ) { - unsigned img_height; - - sp_miptree_set_level_info(spt, level, 1, x, y, width, height, 1); - - if (pt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align(height, align_h); + pt->width[level] = width; + pt->height[level] = height; + pt->depth[level] = depth; + spt->level_offset[level] = spt->buffer_size; - /* Because the images are packed better, the final offset - * might not be the maximal one: - */ - spt->total_height = MAX2(spt->total_height, y + img_height); - - /* Layout_below: step right after second mipmap. - */ - if (level == pt->first_level + 1) { - x += align(width, align_w); - } - else { - y += img_height; - } + spt->buffer_size += ((pt->compressed) ? MAX2(1, height/4) : height) * + ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * + width * pt->cpp; width = minify(width); height = minify(height); + depth = minify(depth); } } -static const int initial_offsets[6][2] = { - {0, 0}, - {0, 2}, - {1, 0}, - {1, 2}, - {1, 1}, - {1, 3} -}; - -static const int step_offsets[6][2] = { - {0, 2}, - {0, 2}, - {-1, 2}, - {-1, 2}, - {-1, 1}, - {-1, 1} -}; - - - -static boolean -softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct softpipe_texture * spt) -{ - struct pipe_texture *pt = &spt->base; - unsigned level; - - switch (pt->target) { - case PIPE_TEXTURE_CUBE:{ - const unsigned dim = pt->width[0]; - unsigned face; - unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; - - assert(lvlWidth == lvlHeight); /* cubemap images are square */ - - /* Depending on the size of the largest images, pitch can be - * determined either by the old-style packing of cubemap faces, - * or the final row of 4x4, 2x2 and 1x1 faces below this. - */ - if (dim > 32) - spt->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; - else - spt->pitch = 14 * 8; - - spt->total_height = dim * 4 + 4; - - /* Set all the levels to effectively occupy the whole rectangular region. - */ - for (level = pt->first_level; level <= pt->last_level; level++) { - sp_miptree_set_level_info(spt, level, 6, - 0, 0, - lvlWidth, lvlHeight, 1); - lvlWidth /= 2; - lvlHeight /= 2; - } - - - for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; - - if (dim == 4 && face >= 4) { - y = spt->total_height - 4; - x = (face - 4) * 8; - } - else if (dim < 4 && (face > 0 || pt->first_level > 0)) { - y = spt->total_height - 4; - x = face * 8; - } - - for (level = pt->first_level; level <= pt->last_level; level++) { - sp_miptree_set_image_offset(spt, level, face, x, y); - - d >>= 1; - - switch (d) { - case 4: - switch (face) { - case PIPE_TEX_FACE_POS_X: - case PIPE_TEX_FACE_NEG_X: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - case PIPE_TEX_FACE_POS_Y: - case PIPE_TEX_FACE_NEG_Y: - y += 12; - x -= 8; - break; - case PIPE_TEX_FACE_POS_Z: - case PIPE_TEX_FACE_NEG_Z: - y = spt->total_height - 4; - x = (face - 4) * 8; - break; - } - - case 2: - y = spt->total_height - 4; - x = 16 + face * 8; - break; - - case 1: - x += 48; - break; - - default: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - } - } - } - break; - } - case PIPE_TEXTURE_3D:{ - unsigned width = pt->width[0]; - unsigned height = pt->height[0]; - unsigned depth = pt->depth[0]; - unsigned pack_x_pitch, pack_x_nr; - unsigned pack_y_pitch; - unsigned level; - - spt->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; - spt->total_height = 0; - - pack_y_pitch = MAX2(pt->height[0], 2); - pack_x_pitch = spt->pitch; - pack_x_nr = 1; - - for (level = pt->first_level; level <= pt->last_level; level++) { - unsigned nr_images = pt->target == PIPE_TEXTURE_3D ? depth : 6; - int x = 0; - int y = 0; - unsigned q, j; - - sp_miptree_set_level_info(spt, level, nr_images, - 0, spt->total_height, - width, height, depth); - - for (q = 0; q < nr_images;) { - for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { - sp_miptree_set_image_offset(spt, level, q, x, y); - x += pack_x_pitch; - } - - x = 0; - y += pack_y_pitch; - } - - - spt->total_height += y; - - if (pack_x_pitch > 4) { - pack_x_pitch >>= 1; - pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= spt->pitch); - } - - if (pack_y_pitch > 2) { - pack_y_pitch >>= 1; - } - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - break; - } - - case PIPE_TEXTURE_1D: - case PIPE_TEXTURE_2D: -// case PIPE_TEXTURE_RECTANGLE: - sp_miptree_layout_2d(spt); - break; - default: - assert(0); - break; - } - - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - spt->pitch, - spt->total_height, pt->cpp, spt->pitch * spt->total_height * pt->cpp); - */ - - return TRUE; -} - void softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) { @@ -376,15 +89,13 @@ softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) memset(&spt->base + 1, 0, sizeof(struct softpipe_texture) - sizeof(struct pipe_texture)); - if (softpipe_mipmap_tree_layout(pipe, spt)) { - spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0); + softpipe_texture_layout(spt); - if (spt->buffer) { - pipe->winsys->buffer_data(pipe->winsys, spt->buffer, - spt->pitch * spt->base.cpp * - spt->total_height, NULL, - PIPE_BUFFER_USAGE_PIXEL); - } + spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0); + + if (spt->buffer) { + pipe->winsys->buffer_data(pipe->winsys, spt->buffer, spt->buffer_size, + NULL, PIPE_BUFFER_USAGE_PIXEL); } if (!spt->buffer) { @@ -408,7 +119,6 @@ softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) */ if (--(*pt)->refcount <= 0) { struct softpipe_texture *spt = softpipe_texture(*pt); - uint i; /* DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); @@ -416,10 +126,6 @@ softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) pipe->winsys->buffer_reference(pipe->winsys, &spt->buffer, NULL); - for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) - if (spt->image_offset[i]) - free(spt->image_offset[i]); - free(spt); } *pt = NULL; diff --git a/src/mesa/pipe/softpipe/sp_texture.h b/src/mesa/pipe/softpipe/sp_texture.h index 732064d986..e1a5db2791 100644 --- a/src/mesa/pipe/softpipe/sp_texture.h +++ b/src/mesa/pipe/softpipe/sp_texture.h @@ -10,29 +10,12 @@ struct softpipe_texture { struct pipe_texture base; - /* Derived from the above: - */ - unsigned pitch; - unsigned depth_pitch; /* per-image on i945? */ - unsigned total_height; - - unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; - - /* Explicitly store the offset of each image for each cube face or - * depth value. Pretty much have to accept that hardware formats - * are going to be so diverse that there is no unified way to - * compute the offsets of depth/cube images within a mipmap level, - * so have to store them as a lookup table: - */ - unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ - - /* Includes image offset tables: - */ unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS]; /* The data is held here: */ struct pipe_buffer_handle *buffer; + unsigned long buffer_size; }; diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index 1dbcc5aadd..6515ce668c 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -34,6 +34,7 @@ #include "pipe/p_util.h" #include "pipe/p_inlines.h" +#include "pipe/util/p_tile.h" #include "sp_context.h" #include "sp_surface.h" #include "sp_tile_cache.h" @@ -49,6 +50,7 @@ struct softpipe_tile_cache { struct pipe_surface *surface; /**< the surface we're caching */ + void *surface_map; struct pipe_texture *texture; /**< if caching a texture */ struct softpipe_cached_tile entries[NUM_ENTRIES]; uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32]; @@ -57,6 +59,7 @@ struct softpipe_tile_cache boolean depth_stencil; /** Is the surface a depth/stencil format? */ struct pipe_surface *tex_surf; + void *tex_surf_map; int tex_face, tex_level, tex_z; struct softpipe_cached_tile tile; /**< scratch tile for clears */ @@ -150,7 +153,7 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, { assert(!tc->texture); - if (tc->surface && tc->surface->map) { + if (tc->surface_map) { /*assert(tc->surface != ps);*/ pipe_surface_unmap(tc->surface); } @@ -158,8 +161,8 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, pipe_surface_reference(&tc->surface, ps); if (ps) { - if (!ps->map) - pipe_surface_map(ps); + if (tc->surface_map) + tc->surface_map = pipe_surface_map(ps); tc->depth_stencil = (ps->format == PIPE_FORMAT_S8Z24_UNORM || ps->format == PIPE_FORMAT_Z16_UNORM || @@ -179,6 +182,32 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) } +void +sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc) +{ + if (tc->surface && !tc->surface_map) + tc->surface_map = pipe_surface_map(tc->surface); + + if (tc->tex_surf && !tc->tex_surf_map) + tc->tex_surf_map = pipe_surface_map(tc->tex_surf); +} + + +void +sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc) +{ + if (tc->surface_map) { + pipe_surface_unmap(tc->surface); + tc->surface_map = NULL; + } + + if (tc->tex_surf_map) { + pipe_surface_unmap(tc->tex_surf); + tc->tex_surf_map = NULL; + } +} + + /** * Specify the texture to cache. */ @@ -192,8 +221,10 @@ sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, tc->texture = texture; - if (tc->tex_surf && tc->tex_surf->map) + if (tc->tex_surf_map) { pipe_surface_unmap(tc->tex_surf); + tc->tex_surf_map = NULL; + } pipe_surface_reference(&tc->tex_surf, NULL); /* mark as entries as invalid/empty */ @@ -330,9 +361,6 @@ sp_flush_tile_cache(struct softpipe_context *softpipe, if (!ps || !ps->buffer) return; - if (!ps->map) - pipe_surface_map(ps); - for (pos = 0; pos < NUM_ENTRIES; pos++) { struct softpipe_cached_tile *tile = tc->entries + pos; if (tile->x >= 0) { @@ -342,9 +370,9 @@ sp_flush_tile_cache(struct softpipe_context *softpipe, tile->data.depth32, 0/*STRIDE*/); } else { - pipe->put_tile_rgba(pipe, ps, - tile->x, tile->y, TILE_SIZE, TILE_SIZE, - (float *) tile->data.color); + pipe_put_tile_rgba(pipe, ps, + tile->x, tile->y, TILE_SIZE, TILE_SIZE, + (float *) tile->data.color); } tile->x = tile->y = -1; /* mark as empty */ inuse++; @@ -391,9 +419,9 @@ sp_get_cached_tile(struct softpipe_context *softpipe, tile->data.depth32, 0/*STRIDE*/); } else { - pipe->put_tile_rgba(pipe, ps, - tile->x, tile->y, TILE_SIZE, TILE_SIZE, - (float *) tile->data.color); + pipe_put_tile_rgba(pipe, ps, + tile->x, tile->y, TILE_SIZE, TILE_SIZE, + (float *) tile->data.color); } } @@ -418,9 +446,9 @@ sp_get_cached_tile(struct softpipe_context *softpipe, tile->data.depth32, 0/*STRIDE*/); } else { - pipe->get_tile_rgba(pipe, ps, - tile->x, tile->y, TILE_SIZE, TILE_SIZE, - (float *) tile->data.color); + pipe_get_tile_rgba(pipe, ps, + tile->x, tile->y, TILE_SIZE, TILE_SIZE, + (float *) tile->data.color); } } } @@ -475,11 +503,11 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, tc->tex_z != z) { /* get new surface (view into texture) */ - if (tc->tex_surf && tc->tex_surf->map) + if (tc->tex_surf_map) pipe_surface_unmap(tc->tex_surf); tc->tex_surf = pipe->get_tex_surface(pipe, tc->texture, face, level, z); - pipe_surface_map(tc->tex_surf); + tc->tex_surf_map = pipe_surface_map(tc->tex_surf); tc->tex_face = face; tc->tex_level = level; @@ -487,9 +515,9 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, } /* get tile from the surface (view into texture) */ - pipe->get_tile_rgba(pipe, tc->tex_surf, - tile_x, tile_y, TILE_SIZE, TILE_SIZE, - (float *) tile->data.color); + pipe_get_tile_rgba(pipe, tc->tex_surf, + tile_x, tile_y, TILE_SIZE, TILE_SIZE, + (float *) tile->data.color); tile->x = tile_x; tile->y = tile_y; tile->z = z; diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h index 91fb2795a2..7fd1081286 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.h +++ b/src/mesa/pipe/softpipe/sp_tile_cache.h @@ -74,6 +74,12 @@ extern struct pipe_surface * sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); extern void +sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc); + +extern void +sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc); + +extern void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, struct pipe_texture *texture); diff --git a/src/mesa/pipe/util/p_tile.c b/src/mesa/pipe/util/p_tile.c index 8bc3c22c83..85a863db8a 100644 --- a/src/mesa/pipe/util/p_tile.c +++ b/src/mesa/pipe/util/p_tile.c @@ -56,8 +56,6 @@ pipe_get_tile_raw(struct pipe_context *pipe, ubyte *pDest; uint i; - assert(ps->map); - if (dst_stride == 0) { dst_stride = w * cpp; } @@ -65,7 +63,7 @@ pipe_get_tile_raw(struct pipe_context *pipe, if (pipe_clip_tile(x, y, &w, &h, ps)) return; - pSrc = ps->map + (y * ps->pitch + x) * cpp; + pSrc = (const ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { @@ -73,6 +71,8 @@ pipe_get_tile_raw(struct pipe_context *pipe, pDest += dst_stride; pSrc += src_stride; } + + pipe_surface_unmap(ps); } @@ -92,8 +92,6 @@ pipe_put_tile_raw(struct pipe_context *pipe, ubyte *pDest; uint i; - assert(ps->map); - if (src_stride == 0) { src_stride = w * cpp; } @@ -102,13 +100,15 @@ pipe_put_tile_raw(struct pipe_context *pipe, return; pSrc = (const ubyte *) p; - pDest = ps->map + (y * ps->pitch + x) * cpp; + pDest = (ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); pDest += dst_stride; pSrc += src_stride; } + + pipe_surface_unmap(ps); } @@ -125,66 +125,46 @@ pipe_put_tile_raw(struct pipe_context *pipe, /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/ static void -a8r8g8b8_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +a8r8g8b8_get_tile_rgba(unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const unsigned *src - = ((const unsigned *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_A8R8G8B8_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { - const unsigned pixel = src[j]; + for (j = 0; j < w; j++, pRow += 4) { + const unsigned pixel = *src++; pRow[0] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); pRow[1] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); pRow[2] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); - pRow += 4; } - src += ps->pitch; - p += w0 * 4; + p += dst_stride; } } static void -a8r8g8b8_put_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - const float *p) +a8r8g8b8_put_tile_rgba(unsigned *dst, + unsigned w, unsigned h, + const float *p, + unsigned src_stride) { - unsigned *dst - = ((unsigned *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_A8R8G8B8_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { const float *pRow = p; - for (j = 0; j < w; j++) { + for (j = 0; j < w; j++, pRow += 4) { unsigned r, g, b, a; UNCLAMPED_FLOAT_TO_UBYTE(r, pRow[0]); UNCLAMPED_FLOAT_TO_UBYTE(g, pRow[1]); UNCLAMPED_FLOAT_TO_UBYTE(b, pRow[2]); UNCLAMPED_FLOAT_TO_UBYTE(a, pRow[3]); - dst[j] = (a << 24) | (r << 16) | (g << 8) | b; - pRow += 4; + *dst++ = (a << 24) | (r << 16) | (g << 8) | b; } - dst += ps->pitch; - p += w0 * 4; + p += src_stride; } } @@ -192,66 +172,46 @@ a8r8g8b8_put_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_B8G8R8A8_UNORM ***/ static void -b8g8r8a8_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +b8g8r8a8_get_tile_rgba(unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const unsigned *src - = ((const unsigned *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_B8G8R8A8_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { - const unsigned pixel = src[j]; + for (j = 0; j < w; j++, pRow += 4) { + const unsigned pixel = *src++; pRow[0] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); pRow[1] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); pRow[2] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); pRow[3] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); - pRow += 4; } - src += ps->pitch; - p += w0 * 4; + p += dst_stride; } } static void -b8g8r8a8_put_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - const float *p) +b8g8r8a8_put_tile_rgba(unsigned *dst, + unsigned w, unsigned h, + const float *p, + unsigned src_stride) { - unsigned *dst - = ((unsigned *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_B8G8R8A8_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { const float *pRow = p; - for (j = 0; j < w; j++) { + for (j = 0; j < w; j++, pRow += 4) { unsigned r, g, b, a; UNCLAMPED_FLOAT_TO_UBYTE(r, pRow[0]); UNCLAMPED_FLOAT_TO_UBYTE(g, pRow[1]); UNCLAMPED_FLOAT_TO_UBYTE(b, pRow[2]); UNCLAMPED_FLOAT_TO_UBYTE(a, pRow[3]); - dst[j] = (b << 24) | (g << 16) | (r << 8) | a; - pRow += 4; + *dst++ = (b << 24) | (g << 16) | (r << 8) | a; } - dst += ps->pitch; - p += w0 * 4; + p += src_stride; } } @@ -259,27 +219,23 @@ b8g8r8a8_put_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_A1R5G5B5_UNORM ***/ static void -a1r5g5b5_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +a1r5g5b5_get_tile_rgba(ushort *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const ushort *src - = ((const ushort *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - assert(ps->format == PIPE_FORMAT_A1R5G5B5_UNORM); - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - const ushort pixel = src[j]; - p[0] = ((pixel >> 10) & 0x1f) * (1.0f / 31.0f); - p[1] = ((pixel >> 5) & 0x1f) * (1.0f / 31.0f); - p[2] = ((pixel ) & 0x1f) * (1.0f / 31.0f); - p[3] = ((pixel >> 15) ) * 1.0f; - p += 4; + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + const ushort pixel = *src++; + pRow[0] = ((pixel >> 10) & 0x1f) * (1.0f / 31.0f); + pRow[1] = ((pixel >> 5) & 0x1f) * (1.0f / 31.0f); + pRow[2] = ((pixel ) & 0x1f) * (1.0f / 31.0f); + pRow[3] = ((pixel >> 15) ) * 1.0f; } - src += ps->pitch; + p += dst_stride; } } @@ -287,27 +243,23 @@ a1r5g5b5_get_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_A4R4G4B4_UNORM ***/ static void -a4r4g4b4_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +a4r4g4b4_get_tile_rgba(ushort *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const ushort *src - = ((const ushort *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - assert(ps->format == PIPE_FORMAT_A4R4G4B4_UNORM); - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - const ushort pixel = src[j]; - p[0] = ((pixel >> 8) & 0xf) * (1.0f / 15.0f); - p[1] = ((pixel >> 4) & 0xf) * (1.0f / 15.0f); - p[2] = ((pixel ) & 0xf) * (1.0f / 15.0f); - p[3] = ((pixel >> 12) ) * (1.0f / 15.0f); - p += 4; + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + const ushort pixel = *src++; + pRow[0] = ((pixel >> 8) & 0xf) * (1.0f / 15.0f); + pRow[1] = ((pixel >> 4) & 0xf) * (1.0f / 15.0f); + pRow[2] = ((pixel ) & 0xf) * (1.0f / 15.0f); + pRow[3] = ((pixel >> 12) ) * (1.0f / 15.0f); } - src += ps->pitch; + p += dst_stride; } } @@ -315,58 +267,44 @@ a4r4g4b4_get_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_R5G6B5_UNORM ***/ static void -r5g6b5_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +r5g6b5_get_tile_rgba(ushort *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const ushort *src - = ((const ushort *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - assert(ps->format == PIPE_FORMAT_R5G6B5_UNORM); - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - const ushort pixel = src[j]; - p[0] = ((pixel >> 11) & 0x1f) * (1.0f / 31.0f); - p[1] = ((pixel >> 5) & 0x3f) * (1.0f / 63.0f); - p[2] = ((pixel ) & 0x1f) * (1.0f / 31.0f); - p[3] = 1.0f; - p += 4; + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + const ushort pixel = *src++; + pRow[0] = ((pixel >> 11) & 0x1f) * (1.0f / 31.0f); + pRow[1] = ((pixel >> 5) & 0x3f) * (1.0f / 63.0f); + pRow[2] = ((pixel ) & 0x1f) * (1.0f / 31.0f); + pRow[3] = 1.0f; } - src += ps->pitch; + p += dst_stride; } } static void -r5g5b5_put_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - const float *p) +r5g5b5_put_tile_rgba(ushort *dst, + unsigned w, unsigned h, + const float *p, + unsigned src_stride) { - ushort *dst - = ((ushort *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_R5G6B5_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { const float *pRow = p; - for (j = 0; j < w; j++) { + for (j = 0; j < w; j++, pRow += 4) { uint r = (uint) (CLAMP(pRow[0], 0.0, 1.0) * 31.0); uint g = (uint) (CLAMP(pRow[1], 0.0, 1.0) * 63.0); uint b = (uint) (CLAMP(pRow[2], 0.0, 1.0) * 31.0); - dst[j] = (r << 11) | (g << 5) | (b); - pRow += 4; + *dst++ = (r << 11) | (g << 5) | (b); } - dst += ps->pitch; - p += w0 * 4; + p += src_stride; } } @@ -378,32 +316,23 @@ r5g5b5_put_tile_rgba(struct pipe_surface *ps, * Return each Z value as four floats in [0,1]. */ static void -z16_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +z16_get_tile_rgba(ushort *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const ushort *src - = ((const ushort *) (ps->map)) - + y * ps->pitch + x; const float scale = 1.0f / 65535.0f; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_Z16_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { - pRow[j * 4 + 0] = - pRow[j * 4 + 1] = - pRow[j * 4 + 2] = - pRow[j * 4 + 3] = src[j] * scale; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = *src++ * scale; } - src += ps->pitch; - p += 4 * w0; + p += dst_stride; } } @@ -413,32 +342,22 @@ z16_get_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_U_L8 ***/ static void -l8_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +l8_get_tile_rgba(ubyte *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const ubyte *src - = ((const ubyte *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_U_L8); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { + for (j = 0; j < w; j++, src++, pRow += 4) { pRow[0] = pRow[1] = - pRow[2] = UBYTE_TO_FLOAT(src[j]); + pRow[2] = UBYTE_TO_FLOAT(*src); pRow[3] = 1.0; - pRow += 4; } - src += ps->pitch; - p += w0 * 4; + p += dst_stride; } } @@ -446,32 +365,22 @@ l8_get_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_U_A8 ***/ static void -a8_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +a8_get_tile_rgba(ubyte *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const ubyte *src - = ((const ubyte *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_U_A8); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { + for (j = 0; j < w; j++, src++, pRow += 4) { pRow[0] = pRow[1] = pRow[2] = 0.0; - pRow[3] = UBYTE_TO_FLOAT(src[j]); - pRow += 4; + pRow[3] = UBYTE_TO_FLOAT(*src); } - src += ps->pitch; - p += w0 * 4; + p += dst_stride; } } @@ -479,70 +388,43 @@ a8_get_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_R16G16B16A16_SNORM ***/ static void -r16g16b16a16_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +r16g16b16a16_get_tile_rgba(short *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const short *src - = ((const short *) (ps->map)) - + (y * ps->pitch + x) * 4; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_R16G16B16A16_SNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - const short *pixel = src; - for (j = 0; j < w; j++) { - pRow[0] = SHORT_TO_FLOAT(pixel[0]); - pRow[1] = SHORT_TO_FLOAT(pixel[1]); - pRow[2] = SHORT_TO_FLOAT(pixel[2]); - pRow[3] = SHORT_TO_FLOAT(pixel[3]); - pRow += 4; - pixel += 4; + for (j = 0; j < w; j++, src += 4, pRow += 4) { + pRow[0] = SHORT_TO_FLOAT(src[0]); + pRow[1] = SHORT_TO_FLOAT(src[1]); + pRow[2] = SHORT_TO_FLOAT(src[2]); + pRow[3] = SHORT_TO_FLOAT(src[3]); } - src += ps->pitch * 4; - p += w0 * 4; + p += dst_stride; } } static void -r16g16b16a16_put_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - const float *p) +r16g16b16a16_put_tile_rgba(short *dst, + unsigned w, unsigned h, + const float *p, + unsigned src_stride) { - short *dst - = ((short *) (ps->map)) - + (y * ps->pitch + x) * 4; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_R16G16B16A16_SNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { const float *pRow = p; - for (j = 0; j < w; j++) { - short r, g, b, a; - UNCLAMPED_FLOAT_TO_SHORT(r, pRow[0]); - UNCLAMPED_FLOAT_TO_SHORT(g, pRow[1]); - UNCLAMPED_FLOAT_TO_SHORT(b, pRow[2]); - UNCLAMPED_FLOAT_TO_SHORT(a, pRow[3]); - dst[j*4+0] = r; - dst[j*4+1] = g; - dst[j*4+2] = b; - dst[j*4+3] = a; - pRow += 4; + for (j = 0; j < w; j++, dst += 4, pRow += 4) { + UNCLAMPED_FLOAT_TO_SHORT(dst[0], pRow[0]); + UNCLAMPED_FLOAT_TO_SHORT(dst[1], pRow[1]); + UNCLAMPED_FLOAT_TO_SHORT(dst[2], pRow[2]); + UNCLAMPED_FLOAT_TO_SHORT(dst[3], pRow[3]); } - dst += ps->pitch * 4; - p += w0 * 4; + p += src_stride; } } @@ -551,32 +433,22 @@ r16g16b16a16_put_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_U_I8 ***/ static void -i8_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +i8_get_tile_rgba(ubyte *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const ubyte *src - = ((const ubyte *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_U_I8); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { + for (j = 0; j < w; j++, src++, pRow += 4) { pRow[0] = pRow[1] = pRow[2] = - pRow[3] = UBYTE_TO_FLOAT(src[j]); - pRow += 4; + pRow[3] = UBYTE_TO_FLOAT(*src); } - src += ps->pitch; - p += w0 * 4; + p += dst_stride; } } @@ -584,33 +456,23 @@ i8_get_tile_rgba(struct pipe_surface *ps, /*** PIPE_FORMAT_U_A8_L8 ***/ static void -a8_l8_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +a8_l8_get_tile_rgba(ushort *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const ushort *src - = ((const ushort *) (ps->map)) - + y * ps->pitch + x; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_U_A8_L8); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { - const ushort p = src[j]; + for (j = 0; j < w; j++, pRow += 4) { + ushort p = *src++; pRow[0] = pRow[1] = pRow[2] = UBYTE_TO_FLOAT(p & 0xff); pRow[3] = UBYTE_TO_FLOAT(p >> 8); - pRow += 4; } - src += ps->pitch; - p += w0 * 4; + p += dst_stride; } } @@ -623,32 +485,23 @@ a8_l8_get_tile_rgba(struct pipe_surface *ps, * Return each Z value as four floats in [0,1]. */ static void -z32_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +z32_get_tile_rgba(unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const uint *src - = ((const uint *) (ps->map)) - + y * ps->pitch + x; const double scale = 1.0 / (double) 0xffffffff; unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_Z16_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { - pRow[j * 4 + 0] = - pRow[j * 4 + 1] = - pRow[j * 4 + 2] = - pRow[j * 4 + 3] = (float) (scale * src[j]); + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float) (*src++ * scale); } - src += ps->pitch; - p += 4 * w0; + p += dst_stride; } } @@ -659,32 +512,23 @@ z32_get_tile_rgba(struct pipe_surface *ps, * Return Z component as four float in [0,1]. Stencil part ignored. */ static void -s8z24_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +s8z24_get_tile_rgba(unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const uint *src - = ((const uint *) (ps->map)) - + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_S8Z24_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { - pRow[j * 4 + 0] = - pRow[j * 4 + 1] = - pRow[j * 4 + 2] = - pRow[j * 4 + 3] = (float) (scale * (src[j] & 0xffffff)); + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float) (scale * (*src++ & 0xffffff)); } - src += ps->pitch; - p += 4 * w0; + p += dst_stride; } } @@ -695,32 +539,23 @@ s8z24_get_tile_rgba(struct pipe_surface *ps, * Return Z component as four float in [0,1]. Stencil part ignored. */ static void -z24s8_get_tile_rgba(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, - float *p) +z24s8_get_tile_rgba(unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) { - const uint *src - = ((const uint *) (ps->map)) - + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; - unsigned w0 = w; - - assert(ps->format == PIPE_FORMAT_Z24S8_UNORM); - - if (pipe_clip_tile(x, y, &w, &h, ps)) - return; for (i = 0; i < h; i++) { float *pRow = p; - for (j = 0; j < w; j++) { - pRow[j * 4 + 0] = - pRow[j * 4 + 1] = - pRow[j * 4 + 2] = - pRow[j * 4 + 3] = (float) (scale * (src[j] >> 8)); + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float) (scale * (*src++ >> 8)); } - src += ps->pitch; - p += 4 * w0; + p += dst_stride; } } @@ -731,52 +566,67 @@ pipe_get_tile_rgba(struct pipe_context *pipe, uint x, uint y, uint w, uint h, float *p) { + unsigned dst_stride = w * 4; + void *packed; + + if (pipe_clip_tile(x, y, &w, &h, ps)) + return; + + packed = MALLOC(h * w * ps->cpp); + + if (!packed) + return; + + pipe->get_tile(pipe, ps, x, y, w, h, packed, w * ps->cpp); + switch (ps->format) { case PIPE_FORMAT_A8R8G8B8_UNORM: - a8r8g8b8_get_tile_rgba(ps, x, y, w, h, p); + a8r8g8b8_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_B8G8R8A8_UNORM: - b8g8r8a8_get_tile_rgba(ps, x, y, w, h, p); + b8g8r8a8_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_A1R5G5B5_UNORM: - a1r5g5b5_get_tile_rgba(ps, x, y, w, h, p); + a1r5g5b5_get_tile_rgba((ushort *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_A4R4G4B4_UNORM: - a4r4g4b4_get_tile_rgba(ps, x, y, w, h, p); + a4r4g4b4_get_tile_rgba((ushort *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_R5G6B5_UNORM: - r5g6b5_get_tile_rgba(ps, x, y, w, h, p); + r5g6b5_get_tile_rgba((ushort *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_U_L8: - l8_get_tile_rgba(ps, x, y, w, h, p); + l8_get_tile_rgba((ubyte *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_U_A8: - a8_get_tile_rgba(ps, x, y, w, h, p); + a8_get_tile_rgba((ubyte *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_U_I8: - i8_get_tile_rgba(ps, x, y, w, h, p); + i8_get_tile_rgba((ubyte *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_U_A8_L8: - a8_l8_get_tile_rgba(ps, x, y, w, h, p); + a8_l8_get_tile_rgba((ushort *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_R16G16B16A16_SNORM: - r16g16b16a16_get_tile_rgba(ps, x, y, w, h, p); + r16g16b16a16_get_tile_rgba((short *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_Z16_UNORM: - z16_get_tile_rgba(ps, x, y, w, h, p); + z16_get_tile_rgba((ushort *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_Z32_UNORM: - z32_get_tile_rgba(ps, x, y, w, h, p); + z32_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_S8Z24_UNORM: - s8z24_get_tile_rgba(ps, x, y, w, h, p); + s8z24_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride); break; case PIPE_FORMAT_Z24S8_UNORM: - z24s8_get_tile_rgba(ps, x, y, w, h, p); + z24s8_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride); break; default: assert(0); } + + FREE(packed); } @@ -786,49 +636,64 @@ pipe_put_tile_rgba(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const float *p) { + unsigned src_stride = w * 4; + void *packed; + + if (pipe_clip_tile(x, y, &w, &h, ps)) + return; + + packed = MALLOC(h * w * ps->cpp); + + if (!packed) + return; + switch (ps->format) { case PIPE_FORMAT_A8R8G8B8_UNORM: - a8r8g8b8_put_tile_rgba(ps, x, y, w, h, p); + a8r8g8b8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; case PIPE_FORMAT_B8G8R8A8_UNORM: - b8g8r8a8_put_tile_rgba(ps, x, y, w, h, p); + b8g8r8a8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; case PIPE_FORMAT_A1R5G5B5_UNORM: - /*a1r5g5b5_put_tile_rgba(ps, x, y, w, h, p);*/ + /*a1r5g5b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/ break; case PIPE_FORMAT_R5G6B5_UNORM: - r5g5b5_put_tile_rgba(ps, x, y, w, h, p); + r5g5b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride); break; case PIPE_FORMAT_R8G8B8A8_UNORM: break; case PIPE_FORMAT_U_L8: - /*l8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*l8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/ break; case PIPE_FORMAT_U_A8: - /*a8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*a8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/ break; case PIPE_FORMAT_U_I8: - /*i8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*i8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/ break; case PIPE_FORMAT_U_A8_L8: - /*a8_l8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*a8_l8_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/ break; case PIPE_FORMAT_R16G16B16A16_SNORM: - r16g16b16a16_put_tile_rgba(ps, x, y, w, h, p); + r16g16b16a16_put_tile_rgba((short *) packed, w, h, p, src_stride); break; case PIPE_FORMAT_Z16_UNORM: - /*z16_put_tile_rgba(ps, x, y, w, h, p);*/ + /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/ break; case PIPE_FORMAT_Z32_UNORM: - /*z32_put_tile_rgba(ps, x, y, w, h, p);*/ + /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ break; case PIPE_FORMAT_S8Z24_UNORM: - /*s8z24_put_tile_rgba(ps, x, y, w, h, p);*/ + /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ break; case PIPE_FORMAT_Z24S8_UNORM: - /*z24s8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ break; default: assert(0); } + + pipe->put_tile(pipe, ps, x, y, w, h, packed, w * ps->cpp); + + FREE(packed); } diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index 168eba0784..03985eab5a 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -1247,22 +1247,11 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height, GLint *bytesPerValue, void **buffer ) { - struct pipe_surface *surf - = st_get_framebuffer_surface(b->stfb, ST_SURFACE_DEPTH); - if (surf) { - *width = surf->width; - *height = surf->pitch; - *bytesPerValue = surf->cpp; - *buffer = surf->map; - return GL_TRUE; - } - else { - *width = 0; - *height = 0; - *bytesPerValue = 0; - *buffer = 0; - return GL_FALSE; - } + *width = 0; + *height = 0; + *bytesPerValue = 0; + *buffer = 0; + return GL_FALSE; } diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 42c43387af..10dc09b13c 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -45,7 +45,10 @@ #ifdef GALLIUM_CELL #include "pipe/cell/ppu/cell_context.h" #include "pipe/cell/ppu/cell_winsys.h" +#else +#define TILE_SIZE 32 /* avoid compilation errors */ #endif + #include "xm_winsys_aub.h" @@ -214,7 +217,6 @@ 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; const uint tilesPerRow = (surf->width + TILE_SIZE - 1) / TILE_SIZE; uint x, y; @@ -234,6 +236,7 @@ xmesa_display_surface_tiled(XMesaBuffer b, const struct pipe_surface *surf) int tx = x / TILE_SIZE; int ty = y / TILE_SIZE; int offset = ty * tilesPerRow + tx; + offset *= 4 * TILE_SIZE * TILE_SIZE; ximage->data = (char *) xm_buf->data + offset; @@ -364,6 +367,10 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys, surf->cpp = pf_get_size(format); surf->pitch = round_up(width, alignment / surf->cpp); +#ifdef GALLIUM_CELL /* XXX a bit of a hack */ + height = round_up(height, TILE_SIZE); +#endif + assert(!surf->buffer); surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0); if(!surf->buffer) diff --git a/src/mesa/pipe/xlib/xm_winsys_aub.c b/src/mesa/pipe/xlib/xm_winsys_aub.c index b207638390..2be8f8793d 100644 --- a/src/mesa/pipe/xlib/xm_winsys_aub.c +++ b/src/mesa/pipe/xlib/xm_winsys_aub.c @@ -99,6 +99,8 @@ static void *aub_buffer_map(struct pipe_winsys *winsys, { struct aub_buffer *sbo = aub_bo(buf); + assert(sbo->data); + if (flags & PIPE_BUFFER_FLAG_WRITE) sbo->dump_on_unmap = 1; @@ -116,6 +118,9 @@ static void aub_buffer_unmap(struct pipe_winsys *winsys, if (sbo->map_count == 0 && sbo->dump_on_unmap) { + + sbo->dump_on_unmap = 0; + brw_aub_gtt_data( iws->aubfile, sbo->offset, sbo->data, @@ -132,6 +137,7 @@ aub_buffer_reference(struct pipe_winsys *winsys, struct pipe_buffer_handle *buf) { if (*ptr) { + assert(aub_bo(*ptr)->refcount != 0); if (--(aub_bo(*ptr)->refcount) == 0) free(*ptr); *ptr = NULL; @@ -273,7 +279,9 @@ aub_buffer_create(struct pipe_winsys *winsys, unsigned flags, unsigned hint) { - return pipe_bo(CALLOC_STRUCT(aub_buffer)); + struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer); + sbo->refcount = 1; + return pipe_bo(sbo); } @@ -282,6 +290,8 @@ aub_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned bytes) { struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer); + sbo->refcount = 1; + /* Lets hope this is meant for upload, not as a result! */ aub_buffer_data( winsys, diff --git a/src/mesa/sources b/src/mesa/sources index 56ea6dbce2..90ce9ce370 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -186,12 +186,6 @@ TGSIUTIL_SOURCES = \ pipe/tgsi/util/tgsi_parse.c \ pipe/tgsi/util/tgsi_util.c - -LLVMTGSI_SOURCES = \ - pipe/llvm/gallivm.cpp \ - pipe/llvm/storage.cpp \ - pipe/llvm/instructions.cpp - STATECACHE_SOURCES = \ pipe/cso_cache/cso_hash.c \ pipe/cso_cache/cso_cache.c @@ -370,7 +364,6 @@ FBDEV_DRIVER_SOURCES = \ ALL_SOURCES = \ $(GLAPI_SOURCES) \ $(SOLO_SOURCES) \ - $(LLVMTGSI_SOURCES) \ $(ASM_SOURCES) \ $(COMMON_DRIVER_SOURCES)\ $(X11_DRIVER_SOURCES) \ @@ -397,15 +390,13 @@ SOLO_SOURCES = \ CORE_SOURCES = \ $(GLAPI_SOURCES) \ - $(SOLO_SOURCES) \ - $(LLVMTGSI_SOURCES) + $(SOLO_SOURCES) ### Object files SOLO_OBJECTS = \ $(SOLO_SOURCES:.c=.o) \ - $(LLVMTGSI_SOURCES:.cpp=.o) \ $(ASM_SOURCES:.S=.o) GLAPI_OBJECTS = \ diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 2a182c7d9c..1ed9333556 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -43,6 +43,8 @@ #include "pipe/p_context.h" #include "pipe/p_shader_tokens.h" +#include "pipe/cso_cache/cso_cache.h" + #include "st_context.h" #include "st_cache.h" #include "st_atom.h" @@ -71,8 +73,8 @@ struct translated_vertex_program /** The program in TGSI format */ struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; - /** Pointer to the translated, cached vertex shader */ - const struct cso_vertex_shader *vs; + /** Pointer to the translated vertex program */ + struct st_vertex_program *vp; struct translated_vertex_program *next; /**< next in linked list */ }; @@ -257,12 +259,13 @@ find_translated_vp(struct st_context *st, assert(stvp->Base.Base.NumInstructions > 1); - xvp->vs = st_translate_vertex_program(st, stvp, - xvp->output_to_slot, - xvp->tokens, - ST_MAX_SHADER_TOKENS); - assert(xvp->vs); - stvp->vs = NULL; /* don't want to use this */ + st_translate_vertex_program(st, stvp, + xvp->output_to_slot, + xvp->tokens, + ST_MAX_SHADER_TOKENS); + + assert(stvp->cso); + xvp->vp = stvp; /* translated VP is up to date now */ xvp->serialNo = stvp->serialNo; @@ -291,8 +294,8 @@ update_linkage( struct st_context *st ) xvp = find_translated_vp(st, stvp, stfp); st->vp = stvp; - st->state.vs = xvp->vs; - st->pipe->bind_vs_state(st->pipe, st->state.vs->data); + st->state.vs = xvp->vp; + st->pipe->bind_vs_state(st->pipe, st->state.vs->cso->data); st->fp = stfp; st->state.fs = stfp->fs; diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index cf2e9db51c..3a3bf9016d 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -43,6 +43,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" +#include "pipe/util/p_tile.h" #define UNCLAMPED_FLOAT_TO_SHORT(us, f) \ @@ -59,6 +60,7 @@ void st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *acc_strb = st_renderbuffer(rb); struct pipe_surface *acc_ps = acc_strb->surface; const GLint xpos = ctx->DrawBuffer->_Xmin; @@ -69,102 +71,17 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) const GLfloat g = ctx->Accum.ClearColor[1]; const GLfloat b = ctx->Accum.ClearColor[2]; const GLfloat a = ctx->Accum.ClearColor[3]; + GLfloat *accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); + int i; - (void) pipe_surface_map(acc_ps); - - switch (acc_ps->format) { - case PIPE_FORMAT_R16G16B16A16_SNORM: - { - const short sr = (short) (32767 * r); - const short sg = (short) (32767 * g); - const short sb = (short) (32767 * b); - const short sa = (short) (32767 * a); - short *acc = ((short *) acc_ps->map) - + (ypos * acc_ps->pitch + xpos) * 4; - int i, j; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - acc[j*4+0] = sr; - acc[j*4+1] = sg; - acc[j*4+2] = sb; - acc[j*4+3] = sa; - } - acc += acc_ps->pitch * 4; - } - } - break; - default: - assert(0); + for (i = 0; i < width * height; i++) { + accBuf[i*4+0] = r; + accBuf[i*4+1] = g; + accBuf[i*4+2] = b; + accBuf[i*4+3] = a; } - pipe_surface_unmap(acc_ps); -} - - -/** Get block of values from accum buffer, converting to float */ -static void -get_accum_tile(struct pipe_context *pipe, - struct pipe_surface *acc_surf, - int xpos, int ypos, int width, int height, - float *buf) -{ - switch (acc_surf->format) { - case PIPE_FORMAT_R16G16B16A16_SNORM: - { - const short *acc = ((const short *) acc_surf->map) - + (ypos * acc_surf->pitch + xpos) * 4; - int i, j; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - buf[j*4+0] = SHORT_TO_FLOAT(acc[j*4+0]); - buf[j*4+1] = SHORT_TO_FLOAT(acc[j*4+1]); - buf[j*4+2] = SHORT_TO_FLOAT(acc[j*4+2]); - buf[j*4+3] = SHORT_TO_FLOAT(acc[j*4+3]); - } - acc += acc_surf->pitch * 4; - buf += width * 4; - } - } - break; - default: - assert(0); - } -} - - -/** Put block of values into accum buffer, converting from float */ -static void -put_accum_tile(struct pipe_context *pipe, - struct pipe_surface *acc_surf, - int xpos, int ypos, int width, int height, - const float *buf) -{ - switch (acc_surf->format) { - case PIPE_FORMAT_R16G16B16A16_SNORM: - { - short *acc = ((short *) acc_surf->map) - + (ypos * acc_surf->pitch + xpos) * 4; - int i, j; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - short r, g, b, a; - UNCLAMPED_FLOAT_TO_SHORT(r, buf[j*4+0]); - UNCLAMPED_FLOAT_TO_SHORT(g, buf[j*4+1]); - UNCLAMPED_FLOAT_TO_SHORT(b, buf[j*4+2]); - UNCLAMPED_FLOAT_TO_SHORT(a, buf[j*4+3]); - acc[j*4+0] = r; - acc[j*4+1] = g; - acc[j*4+2] = b; - acc[j*4+3] = a; - } - acc += acc_surf->pitch * 4; - buf += width * 4; - } - } - break; - default: - assert(0); - } + pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); } @@ -179,19 +96,15 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(acc_ps); - - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); for (i = 0; i < 4 * width * height; i++) { accBuf[i] = accBuf[i] * scale + bias; } - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); free(accBuf); - - pipe_surface_unmap(acc_ps); } @@ -201,30 +114,23 @@ accum_accum(struct pipe_context *pipe, GLfloat value, struct pipe_surface *acc_ps, struct pipe_surface *color_ps) { - ubyte *colorMap, *accMap; GLfloat *colorBuf, *accBuf; GLint i; colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - colorMap = pipe_surface_map(color_ps); - accMap = pipe_surface_map(acc_ps); - - pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); + pipe_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); for (i = 0; i < 4 * width * height; i++) { accBuf[i] = accBuf[i] + colorBuf[i] * value; } - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); free(colorBuf); free(accBuf); - - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); } @@ -239,21 +145,15 @@ accum_load(struct pipe_context *pipe, GLfloat value, buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(color_ps); - (void) pipe_surface_map(acc_ps); - - pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf); + pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf); for (i = 0; i < 4 * width * height; i++) { buf[i] = buf[i] * value; } - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, buf); + pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, buf); free(buf); - - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); } @@ -270,14 +170,11 @@ accum_return(GLcontext *ctx, GLfloat value, abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(color_ps); - (void) pipe_surface_map(acc_ps); - - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, abuf); + pipe_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf); if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) { cbuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, cbuf); + pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, cbuf); } for (i = 0; i < width * height; i++) { @@ -292,14 +189,11 @@ accum_return(GLcontext *ctx, GLfloat value, } } - pipe->put_tile_rgba(pipe, color_ps, xpos, ypos, width, height, abuf); + pipe_put_tile_rgba(pipe, color_ps, xpos, ypos, width, height, abuf); free(abuf); if (cbuf) free(cbuf); - - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 40319f4b4b..758d4a4086 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -208,7 +208,7 @@ make_vertex_shader(struct st_context *st) stvp = (struct st_vertex_program *) p; st_translate_vertex_program(st, stvp, NULL, stvp->tokens, ST_MAX_SHADER_TOKENS); - assert(stvp->vs); + assert(stvp->cso); return stvp; } @@ -350,7 +350,7 @@ clear_with_quad(GLcontext *ctx, if (!stvp) { stvp = make_vertex_shader(st); } - pipe->bind_vs_state(pipe, stvp->vs->data); + pipe->bind_vs_state(pipe, stvp->cso->data); } /* viewport state: viewport matching window dims */ @@ -376,7 +376,7 @@ clear_with_quad(GLcontext *ctx, pipe->bind_blend_state(pipe, st->state.blend->data); pipe->bind_depth_stencil_alpha_state(pipe, st->state.depth_stencil->data); pipe->bind_fs_state(pipe, st->state.fs->data); - pipe->bind_vs_state(pipe, st->state.vs->data); + pipe->bind_vs_state(pipe, st->state.vs->cso->data); pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); pipe->set_viewport_state(pipe, &st->state.viewport); /* OR: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 2db12c653b..f4d6b9362c 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -56,6 +56,7 @@ #include "pipe/p_defines.h" #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" +#include "pipe/util/p_tile.h" #include "shader/prog_instruction.h" @@ -661,7 +662,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->bind_fs_state(pipe, stfp->fs->data); /* vertex shader state: position + texcoord pass-through */ - pipe->bind_vs_state(pipe, stvp->vs->data); + pipe->bind_vs_state(pipe, stvp->cso->data); /* texture sampling state: */ { @@ -718,7 +719,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* restore GL state */ pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer->data); pipe->bind_fs_state(pipe, ctx->st->state.fs->data); - pipe->bind_vs_state(pipe, ctx->st->state.vs->data); + pipe->bind_vs_state(pipe, ctx->st->state.vs->cso->data); pipe->set_sampler_texture(pipe, unit, ctx->st->state.sampler_texture[unit]); pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]->data); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); @@ -1261,14 +1262,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, /* alternate path using get/put_tile() */ GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(psRead); - (void) pipe_surface_map(psTex); - - pipe->get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); - pipe->put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); - - pipe_surface_unmap(psRead); - pipe_surface_unmap(psTex); + pipe_get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); + pipe_put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); free(buf); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index bc0f26ffb0..2d6b3fc749 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -97,9 +97,6 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, return GL_FALSE; } - /* loop here since mapping is refcounted */ - while (strb->surface->map) - pipe_surface_unmap(strb->surface); if (strb->surface->buffer) pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index aed6b1ee97..f1f33fb0dd 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -39,6 +39,9 @@ #include "shader/programopt.h" #include "shader/shader_api.h" +#include "pipe/cso_cache/cso_cache.h" +#include "pipe/draw/draw_context.h" + #include "st_context.h" #include "st_program.h" #include "st_atom_shader.h" @@ -181,17 +184,22 @@ static void st_program_string_notify( GLcontext *ctx, stvp->serialNo++; - if (stvp->vs) { - /* free the TGSI code */ - // cso_delete(stfp->vs); - stvp->vs = NULL; + if (stvp->cso) { + /* free the CSO data */ + st->pipe->delete_vs_state(st->pipe, stvp->cso->data); + FREE((void *) stvp->cso); + stvp->cso = NULL; + } + + if (stvp->draw_shader) { + draw_delete_vertex_shader(st->draw, stvp->draw_shader); + stvp->draw_shader = NULL; } stvp->param_state = stvp->Base.Base.Parameters->StateFlags; if (st->vp == stvp) st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - } } diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index b0c9275c6f..a1bbb3a831 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -40,6 +40,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" +#include "pipe/util/p_tile.h" #include "st_context.h" #include "st_cb_readpixels.h" #include "st_cb_fbo.h" @@ -179,8 +180,6 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (!strb) return; - pipe_surface_map(strb->surface); - if (format == GL_RGBA && type == GL_FLOAT) { /* write tile(row) directly into user's buffer */ df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width, @@ -212,7 +211,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* Do a row at a time to flip image data vertically */ for (i = 0; i < height; i++) { - pipe->get_tile_rgba(pipe, strb->surface, x, y, width, 1, df); + pipe_get_tile_rgba(pipe, strb->surface, x, y, width, 1, df); y += yStep; df += dfStride; if (!dfStride) { @@ -229,8 +228,6 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } } - - pipe_surface_unmap(strb->surface); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index e813bdb47a..ba0950e295 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -45,6 +45,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" +#include "pipe/util/p_tile.h" #define DBG if (0) printf @@ -97,7 +98,7 @@ st_get_texobj_texture(struct gl_texture_object *texObj) } -static unsigned +static enum pipe_texture_target gl_target_to_pipe(GLenum target) { switch (target) { @@ -1063,15 +1064,12 @@ fallback_copy_texsubimage(GLcontext *ctx, dest_surf = pipe->get_tex_surface(pipe, pt, face, level, destZ); - (void) pipe_surface_map(dest_surf); - (void) pipe_surface_map(src_surf); - /* buffer for one row */ data = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); /* do copy row by row */ for (row = 0; row < height; row++) { - pipe->get_tile_rgba(pipe, src_surf, srcX, srcY + row, width, 1, data); + pipe_get_tile_rgba(pipe, src_surf, srcX, srcY + row, width, 1, data); /* XXX we're ignoring convolution for now */ if (ctx->_ImageTransferState) { @@ -1080,14 +1078,10 @@ fallback_copy_texsubimage(GLcontext *ctx, width, (GLfloat (*)[4])data); } - pipe->put_tile_rgba(pipe, dest_surf, destX, destY, width, 1, data); + pipe_put_tile_rgba(pipe, dest_surf, destX, destY, width, 1, data); destY += yStep; } - - (void) pipe_surface_unmap(dest_surf); - (void) pipe_surface_unmap(src_surf); - free(data); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 0f40f3ceee..5ae21c93f9 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -100,7 +100,7 @@ struct st_context const struct cso_depth_stencil_alpha *depth_stencil; const struct cso_rasterizer *rasterizer; const struct cso_fragment_shader *fs; - const struct cso_vertex_shader *vs; + struct st_vertex_program *vs; struct pipe_blend_color blend_color; struct pipe_clip_state clip; diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c index cffd66751d..57450e52bf 100644 --- a/src/mesa/state_tracker/st_debug.c +++ b/src/mesa/state_tracker/st_debug.c @@ -53,11 +53,11 @@ st_print_current(void) int i; printf("Vertex Transform Inputs:\n"); - for (i = 0; i < st->state.vs->state.num_inputs; i++) { + for (i = 0; i < st->state.vs->cso->state.num_inputs; i++) { printf(" Slot %d: VERT_ATTRIB_%d\n", i, st->vp->index_to_input[i]); } - tgsi_dump( st->state.vs->state.tokens, 0 ); + tgsi_dump( st->state.vs->cso->state.tokens, 0 ); if (st->vp->Base.Base.Parameters) _mesa_print_parameter_list(st->vp->Base.Base.Parameters); diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 96db9e3c03..94b3a9531a 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -241,7 +241,7 @@ st_draw_vbo(GLcontext *ctx, /* must get these after state validation! */ vp = ctx->st->vp; - vs = &ctx->st->state.vs->state; + vs = &ctx->st->state.vs->cso->state; /* loop over TGSI shader inputs to determine vertex buffer * and attribute info @@ -447,7 +447,7 @@ set_feedback_vertex_format(GLcontext *ctx) else { /* GL_FEEDBACK, or glRasterPos */ /* emit all attribs (pos, color, texcoord) as GLfloat[4] */ - vinfo.num_attribs = st->state.vs->state.num_outputs; + vinfo.num_attribs = st->state.vs->cso->state.num_outputs; for (i = 0; i < vinfo.num_attribs; i++) { vinfo.format[i] = FORMAT_4F; vinfo.interp_mode[i] = INTERP_LINEAR; @@ -491,7 +491,11 @@ st_feedback_draw_vbo(GLcontext *ctx, /* must get these after state validation! */ vp = ctx->st->vp; - vs = &ctx->st->state.vs->state; + vs = &ctx->st->state.vs->cso->state; + + if (!st->state.vs->draw_shader) { + st->state.vs->draw_shader = draw_create_vertex_shader(draw, vs); + } /* * Set up the draw module's state. @@ -503,7 +507,7 @@ st_feedback_draw_vbo(GLcontext *ctx, draw_set_viewport_state(draw, &st->state.viewport); draw_set_clip_state(draw, &st->state.clip); draw_set_rasterizer_state(draw, &st->state.rasterizer->state); - draw_bind_vertex_shader(draw, st->state.vs->data); + draw_bind_vertex_shader(draw, st->state.vs->draw_shader); set_feedback_vertex_format(ctx); /* loop over TGSI shader inputs to determine vertex buffer diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 1852228b29..1f1e6500e0 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -57,7 +57,7 @@ * \param tokensOut destination for TGSI tokens * \return pointer to cached pipe_shader object. */ -const struct cso_vertex_shader * +void st_translate_vertex_program(struct st_context *st, struct st_vertex_program *stvp, const GLuint outputMapping[], @@ -256,12 +256,10 @@ st_translate_vertex_program(struct st_context *st, vs.tokens = tokensOut; cso = st_cached_vs_state(st, &vs); - stvp->vs = cso; + stvp->cso = cso; if (TGSI_DEBUG) tgsi_dump( tokensOut, 0 ); - - return cso; } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 049f9f659f..de02c3185f 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -90,7 +90,10 @@ struct st_vertex_program struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; /** Pointer to the corresponding cached shader */ - const struct cso_vertex_shader *vs; + const struct cso_vertex_shader *cso; + + /** For using our private draw module (glRasterPos) */ + struct draw_vertex_shader *draw_shader; GLuint param_state; }; @@ -122,7 +125,7 @@ st_translate_fragment_program(struct st_context *st, GLuint maxTokens); -extern const struct cso_vertex_shader * +extern void st_translate_vertex_program(struct st_context *st, struct st_vertex_program *vp, const GLuint vert_output_to_slot[], diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index c7d28eeca2..a2bdf846ca 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -61,8 +61,8 @@ target_to_target(GLenum target) struct pipe_texture * st_texture_create(struct st_context *st, - unsigned target, - unsigned format, + enum pipe_texture_target target, + enum pipe_format format, GLuint first_level, GLuint last_level, GLuint width0, diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 7524c219e0..d8b1bcad9d 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -37,8 +37,8 @@ struct pipe_texture; extern struct pipe_texture * st_texture_create(struct st_context *st, - unsigned target, - unsigned format, + enum pipe_texture_target target, + enum pipe_format format, GLuint first_level, GLuint last_level, GLuint width0, diff --git a/src/mesa/x86/glapi_x86.S b/src/mesa/x86/glapi_x86.S index 1d04779d14..8b7204cdb7 100644 --- a/src/mesa/x86/glapi_x86.S +++ b/src/mesa/x86/glapi_x86.S @@ -27,7 +27,7 @@ */ #include "assyntax.h" -#include "glapioffsets.h" +#include "glapi/glapioffsets.h" #if defined(STDCALL_API) # if defined(USE_MGL_NAMESPACE) |