From: Ben Skeggs Date: Sun, 9 Dec 2007 11:32:09 +0000 (+1100) Subject: Merge branch 'nouveau-gallium-0.1' into darktama-gallium-0.1 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=88b56c454513f5097b7806ffaa5c313881861504;hp=fecb3ce5860caa498f531c28db043c3c2cb845a8;p=mesa.git Merge branch 'nouveau-gallium-0.1' into darktama-gallium-0.1 --- diff --git a/Makefile b/Makefile index c4ffea85a2b..6e92858ad50 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,7 @@ irix6-o32-static \ linux \ linux-alpha \ linux-alpha-static \ +linux-cell \ linux-debug \ linux-directfb \ linux-dri \ diff --git a/configs/default b/configs/default index a7de3f813d6..92fc743ab46 100644 --- a/configs/default +++ b/configs/default @@ -71,7 +71,7 @@ PROGRAM_DIRS = demos redbook samples glsl xdemos GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread OSMESA_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) $(EXTRA_LIB_PATH) -lX11 -lXmu -lXt -lXi -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) $(EXTRA_LIB_PATH) -lX11 -lXmu -lXi -lm GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(EXTRA_LIB_PATH) -lXt -lX11 APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm diff --git a/configs/linux-cell b/configs/linux-cell new file mode 100644 index 00000000000..f581b5a6fe3 --- /dev/null +++ b/configs/linux-cell @@ -0,0 +1,44 @@ +# linux-cell + +include $(TOP)/configs/default + +CONFIG_NAME = linux-cell + + +# Compiler and flags +CC = /usr/bin/ppu32-gcc +CXX = /usr/bin/ppu32-g++ + +# Cell SDK location +SDK = /opt/ibm/cell-sdk/prototype/sysroot/usr + + +CFLAGS = -g -W -Wall -Winline -fPIC -m32 -mabi=altivec -maltivec -I. -I/usr/include -I$(SDK)/include -include altivec.h + +CXXFLAGS = $(CFLAGS) + +# Omitting glw here: +SRC_DIRS = mesa glu glut/glx + + +MKDEP_OPTIONS = -fdepend -Y + + +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread \ + -L$(SDK)/lib -m32 -Wl,-m,elf32ppc -R$(SDK)/lib -lspe + + + +### SPU stuff + +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_LFLAGS = -L$(SDK)/spu/lib -Wl,-N -lmisc + +SPU_AR = /usr/bin/ar +SPU_AR_FLAGS = -qcs + +SPU_EMBED = /usr/bin/embedspu +SPU_EMBED_FLAGS = -m32 diff --git a/doxygen/gallium.doxy b/doxygen/gallium.doxy index 17a0dadbfc8..b9781973887 100644 --- a/doxygen/gallium.doxy +++ b/doxygen/gallium.doxy @@ -136,7 +136,7 @@ SHORT_NAMES = NO # comments will behave just like regular Qt-style comments # (thus requiring an explicit @brief command for a brief description.) -JAVADOC_AUTOBRIEF = NO +JAVADOC_AUTOBRIEF = YES # If the QT_AUTOBRIEF tag is set to YES then Doxygen will # interpret the first line (until the first dot) of a Qt-style @@ -144,7 +144,7 @@ JAVADOC_AUTOBRIEF = NO # will behave just like regular Qt-style comments (thus requiring # an explicit \brief command for a brief description.) -QT_AUTOBRIEF = NO +QT_AUTOBRIEF = YES # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// @@ -255,7 +255,7 @@ EXTRACT_STATIC = YES # defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. -EXTRACT_LOCAL_CLASSES = NO +EXTRACT_LOCAL_CLASSES = YES # This flag is only useful for Objective-C code. When set to YES local # methods, which are defined in the implementation section but not in @@ -477,7 +477,10 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = gallium.doc ../src/mesa/pipe +INPUT = gallium.doc \ + ../src/mesa/pipe \ + ../src/mesa/state_tracker \ + ../src/mesa/drivers/dri/intel_winsys # This tag can be used to specify the character encoding of the source files that # doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default @@ -1020,7 +1023,7 @@ ENABLE_PREPROCESSING = YES # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the @@ -1054,7 +1057,7 @@ INCLUDE_FILE_PATTERNS = # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = +PREDEFINED = INLINE=inline # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. diff --git a/src/mesa/Makefile b/src/mesa/Makefile index 521cbeb6064..6f090d9b3d6 100644 --- a/src/mesa/Makefile +++ b/src/mesa/Makefile @@ -13,6 +13,12 @@ GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) SOFTPIPE_LIB = $(TOP)/src/mesa/pipe/softpipe/libsoftpipe.a +ifeq ($(CONFIG_NAME), linux-cell) +CELL_LIB = $(TOP)/src/mesa/pipe/cell/ppu/libcell.a +CELL_LIB_SPU = $(TOP)/src/mesa/pipe/cell/spu/g3d_spu.a +endif + + .SUFFIXES : .cpp .c.o: @@ -112,12 +118,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) $(SOFTPIPE_LIB) +$(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(STAND_ALONE_OBJECTS) $(SOFTPIPE_LIB) $(CELL_LIB) $(CELL_LIB_SPU) @ $(TOP)/bin/mklib -o $(GL_LIB) \ -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \ -install $(TOP)/$(LIB_DIR) \ $(MKLIB_OPTIONS) $(STAND_ALONE_OBJECTS) \ - $(SOFTPIPE_LIB) $(GL_LIB_DEPS) + $(SOFTPIPE_LIB) $(CELL_LIB) $(CELL_LIB_SPU) $(GL_LIB_DEPS) # Make the OSMesa library $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_NAME): $(OSMESA_DRIVER_OBJECTS) $(OSMESA16_OBJECTS) diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c index 96e5037fa57..ea0cc51d4a9 100644 --- a/src/mesa/drivers/common/driverfuncs.c +++ b/src/mesa/drivers/common/driverfuncs.c @@ -259,43 +259,6 @@ _mesa_init_driver_functions(struct dd_function_table *driver) } -/** - * Plug in Mesa's GLSL functions. - */ -void -_mesa_init_glsl_driver_functions(struct dd_function_table *driver) -{ - driver->AttachShader = _mesa_attach_shader; - driver->BindAttribLocation = _mesa_bind_attrib_location; - driver->CompileShader = _mesa_compile_shader; - driver->CreateProgram = _mesa_create_program; - driver->CreateShader = _mesa_create_shader; - driver->DeleteProgram2 = _mesa_delete_program2; - driver->DeleteShader = _mesa_delete_shader; - driver->DetachShader = _mesa_detach_shader; - driver->GetActiveAttrib = _mesa_get_active_attrib; - driver->GetActiveUniform = _mesa_get_active_uniform; - driver->GetAttachedShaders = _mesa_get_attached_shaders; - driver->GetAttribLocation = _mesa_get_attrib_location; - driver->GetHandle = _mesa_get_handle; - driver->GetProgramiv = _mesa_get_programiv; - driver->GetProgramInfoLog = _mesa_get_program_info_log; - driver->GetShaderiv = _mesa_get_shaderiv; - driver->GetShaderInfoLog = _mesa_get_shader_info_log; - driver->GetShaderSource = _mesa_get_shader_source; - driver->GetUniformfv = _mesa_get_uniformfv; - driver->GetUniformLocation = _mesa_get_uniform_location; - driver->IsProgram = _mesa_is_program; - driver->IsShader = _mesa_is_shader; - driver->LinkProgram = _mesa_link_program; - driver->ShaderSource = _mesa_shader_source; - driver->Uniform = _mesa_uniform; - driver->UniformMatrix = _mesa_uniform_matrix; - driver->UseProgram = _mesa_use_program; - driver->ValidateProgram = _mesa_validate_program; -} - - /** * Call the ctx->Driver.* state functions with current values to initialize * driver state. diff --git a/src/mesa/drivers/common/driverfuncs.h b/src/mesa/drivers/common/driverfuncs.h index 6ed23c4520e..4c90ed12f60 100644 --- a/src/mesa/drivers/common/driverfuncs.h +++ b/src/mesa/drivers/common/driverfuncs.h @@ -30,10 +30,6 @@ extern void _mesa_init_driver_functions(struct dd_function_table *driver); -extern void -_mesa_init_glsl_driver_functions(struct dd_function_table *driver); - - extern void _mesa_init_driver_state(GLcontext *ctx); diff --git a/src/mesa/drivers/dri/Makefile.template b/src/mesa/drivers/dri/Makefile.template index 37bf0a49772..1d0b0726db1 100644 --- a/src/mesa/drivers/dri/Makefile.template +++ b/src/mesa/drivers/dri/Makefile.template @@ -3,7 +3,6 @@ MESA_MODULES = $(TOP)/src/mesa/libmesa.a COMMON_SOURCES = \ - ../../common/driverfuncs.c \ ../common/utils.c \ ../common/texmem.c \ ../common/vblank.c \ diff --git a/src/mesa/drivers/dri/intel_winsys/intel_batchbuffer.c b/src/mesa/drivers/dri/intel_winsys/intel_batchbuffer.c index ed223977e2c..49e04d81ec1 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_batchbuffer.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_batchbuffer.c @@ -307,6 +307,20 @@ intel_batchbuffer_flush(struct intel_batchbuffer *batch) } +void +intel_batchbuffer_finish(struct intel_batchbuffer *batch) +{ + struct _DriFenceObject *fence = intel_batchbuffer_flush(batch); + if (fence) { + driFenceReference(fence); + driFenceFinish(fence, + DRM_FENCE_TYPE_EXE | DRM_I915_FENCE_TYPE_RW, + GL_FALSE); + driFenceUnReference(fence); + } +} + + /* This is the only way buffers get added to the validate list. */ boolean diff --git a/src/mesa/drivers/dri/intel_winsys/intel_batchbuffer.h b/src/mesa/drivers/dri/intel_winsys/intel_batchbuffer.h index 2c943e68e5c..82feafa21f6 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_batchbuffer.h +++ b/src/mesa/drivers/dri/intel_winsys/intel_batchbuffer.h @@ -72,6 +72,8 @@ struct intel_batchbuffer *intel_batchbuffer_alloc(struct intel_context *intel); void intel_batchbuffer_free(struct intel_batchbuffer *batch); +void intel_batchbuffer_finish(struct intel_batchbuffer *batch); + struct _DriFenceObject *intel_batchbuffer_flush(struct intel_batchbuffer *batch); diff --git a/src/mesa/drivers/dri/intel_winsys/intel_screen.c b/src/mesa/drivers/dri/intel_winsys/intel_screen.c index 01460e5be3c..1b520f71353 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_screen.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_screen.c @@ -328,8 +328,8 @@ intelSetTexOffset(__DRIcontext *pDRICtx, int texname, if (!stObj) return; - if (stObj->mt) - st_miptree_release(intel->st->pipe, &stObj->mt); + if (stObj->pt) + st->pipe->texture_release(intel->st->pipe, &stObj->pt); stObj->imageOverride = GL_TRUE; stObj->depthOverride = depth; diff --git a/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c b/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c index 9fcb2dac273..454cd71f6c0 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c @@ -88,16 +88,15 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, const drm_clip_rect_t *pbox = dPriv->pClipRects; const int pitch = intelScreen->front.pitch / intelScreen->front.cpp; const int cpp = intelScreen->front.cpp; - const struct pipe_region *srcRegion = surf->region; - const int srcpitch = srcRegion->pitch; + const int srcpitch = surf->pitch; int BR13, CMD; int i; - ASSERT(srcRegion); - ASSERT(srcRegion->cpp == cpp); + ASSERT(surf->buffer); + ASSERT(surf->cpp == cpp); DBG(SWAP, "screen pitch %d src surface pitch %d\n", - pitch, srcRegion->pitch); + pitch, surf->pitch); if (cpp == 2) { BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24); @@ -159,7 +158,7 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, assert(box.x1 < box.x2); assert(box.y1 < box.y2); - /* XXX this could be done with pipe->region_copy() */ + /* XXX this could be done with pipe->surface_copy() */ BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS); OUT_BATCH(CMD); OUT_BATCH(BR13); @@ -171,7 +170,7 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, DRM_BO_MASK_MEM | DRM_BO_FLAG_WRITE, 0); OUT_BATCH((sbox.y1 << 16) | sbox.x1); OUT_BATCH((srcpitch * cpp) & 0xffff); - OUT_RELOC(dri_bo(srcRegion->buffer), + OUT_RELOC(dri_bo(surf->buffer), DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, DRM_BO_MASK_MEM | DRM_BO_FLAG_READ, 0); diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys.h b/src/mesa/drivers/dri/intel_winsys/intel_winsys.h index f944cd23c36..89e63e0a797 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys.h +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys.h @@ -32,9 +32,7 @@ struct intel_context; struct pipe_context; struct pipe_winsys; struct pipe_buffer_handle; -struct pipe_fence; struct _DriBufferObject; -struct _DriFenceObject; struct pipe_winsys * intel_create_pipe_winsys( int fd ); @@ -68,20 +66,5 @@ pipe_bo( struct _DriBufferObject *bo ) } -/* Turn the pipe opaque buffer pointer into a dri_bufmgr opaque - * buffer pointer... - */ -static INLINE struct _DriFenceObject * -dri_fo( struct pipe_fence *bo ) -{ - return (struct _DriFenceObject *)bo; -} - -static INLINE struct pipe_fence * -pipe_fo( struct _DriFenceObject *bo ) -{ - return (struct pipe_fence *)bo; -} - #endif diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c index d73b309fd42..8e0eea43922 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c @@ -111,62 +111,19 @@ static void intel_i915_batch_reloc( struct i915_winsys *sws, -static void -intel_i915_batch_flush( struct i915_winsys *sws, - struct pipe_fence **fence ) +static void intel_i915_batch_flush( struct i915_winsys *sws ) { struct intel_context *intel = intel_i915_winsys(sws)->intel; - struct pipe_fence *tmp_fence; - - tmp_fence = pipe_fo(intel_batchbuffer_flush( intel->batch )); - - /* this also increases the fence reference count, which is not done inside - * intel_batchbuffer_flush call above - */ - sws->fence_reference(sws, fence, tmp_fence); -} - -static void -intel_i915_fence_reference( struct i915_winsys *sws, - struct pipe_fence **dst_fence, - struct pipe_fence *src_fence ) -{ - struct _DriFenceObject **dri_dst_fence = (struct _DriFenceObject **)dst_fence; - struct _DriFenceObject *dri_src_fence = (struct _DriFenceObject *)src_fence; - - if(dri_src_fence) - driFenceReference(dri_src_fence); - - if(*dri_dst_fence) - driFenceUnReference(*dri_dst_fence); - - *dri_dst_fence = dri_src_fence; + intel_batchbuffer_flush( intel->batch ); +// if (0) intel_i915_batch_wait_idle( sws ); } -static int -intel_i915_fence_is_signalled( struct i915_winsys *sws, - struct pipe_fence *fence ) +static void intel_i915_batch_finish( struct i915_winsys *sws ) { - struct _DriFenceObject *dri_fence = dri_fo(fence); - if (fence) - return driFenceSignaled(dri_fence, - DRM_FENCE_TYPE_EXE | DRM_I915_FENCE_TYPE_RW); - return 1; -} - - -static int -intel_i915_fence_wait( struct i915_winsys *sws, - struct pipe_fence *fence ) -{ - struct _DriFenceObject *dri_fence = dri_fo(fence); - if (fence) - driFenceFinish(dri_fence, - DRM_FENCE_TYPE_EXE | DRM_I915_FENCE_TYPE_RW, - GL_FALSE); - return 1; + struct intel_context *intel = intel_i915_winsys(sws)->intel; + intel_batchbuffer_finish( intel->batch ); } @@ -186,10 +143,7 @@ intel_create_i915simple( struct intel_context *intel, iws->winsys.batch_dword = intel_i915_batch_dword; iws->winsys.batch_reloc = intel_i915_batch_reloc; iws->winsys.batch_flush = intel_i915_batch_flush; - iws->winsys.fence_reference = intel_i915_fence_reference; - iws->winsys.fence_is_signalled = intel_i915_fence_is_signalled; - iws->winsys.fence_wait = intel_i915_fence_wait; - + iws->winsys.batch_finish = intel_i915_batch_finish; iws->intel = intel; /* Create the i915simple context: diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index ae02f98a783..1799e9b901b 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -135,13 +135,12 @@ static void intel_buffer_get_subdata(struct pipe_winsys *winsys, * for all buffers. */ static struct pipe_buffer_handle * -intel_buffer_create(struct pipe_winsys *winsys, - unsigned alignment) +intel_buffer_create(struct pipe_winsys *winsys, unsigned flags) { struct _DriBufferObject *buffer; struct intel_pipe_winsys *iws = intel_pipe_winsys(winsys); driGenBuffers( iws->regionPool, - "pipe buffer", 1, &buffer, alignment, 0, 0 ); + "pipe buffer", 1, &buffer, 64, 0, 0 ); return pipe_bo(buffer); } @@ -173,14 +172,10 @@ intel_flush_frontbuffer( struct pipe_winsys *winsys, } -static struct pipe_region * -intel_i915_region_alloc(struct pipe_winsys *winsys, - unsigned cpp, unsigned width, - unsigned height, unsigned flags) +static unsigned +intel_i915_surface_pitch(struct pipe_winsys *winsys, + unsigned cpp, unsigned width, unsigned flags) { - struct pipe_region *region = calloc(sizeof(*region), 1); - const unsigned alignment = 64; - /* Choose a pitch to match hardware requirements - requires 64 byte * alignment of render targets. * @@ -188,52 +183,17 @@ intel_i915_region_alloc(struct pipe_winsys *winsys, * clearly want to be able to render to textures under some * circumstances, but maybe not always a requirement. */ - unsigned pitch; /* XXX is the pitch different for textures vs. drawables? */ if (flags & PIPE_SURFACE_FLAG_TEXTURE) /* or PIPE_SURFACE_FLAG_RENDER? */ - pitch = ((cpp * width + 63) & ~63) / cpp; + return ((cpp * width + 63) & ~63) / cpp; else - pitch = ((cpp * width + 63) & ~63) / cpp; - - region->cpp = cpp; - region->pitch = pitch; - region->height = height; /* needed? */ - region->refcount = 1; - - region->buffer = winsys->buffer_create( winsys, alignment ); - - winsys->buffer_data( winsys, - region->buffer, - pitch * cpp * height, - NULL, - PIPE_BUFFER_USAGE_PIXEL ); - - return region; -} - -static void -intel_i915_region_release(struct pipe_winsys *winsys, - struct pipe_region **region) -{ - if (!*region) - return; - - assert((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - - winsys->buffer_reference( winsys, &((*region)->buffer), NULL ); - free(*region); - } - *region = NULL; + return ((cpp * width + 63) & ~63) / cpp; } static struct pipe_surface * -intel_i915_surface_alloc(struct pipe_winsys *winsys, unsigned format) +intel_i915_surface_alloc(struct pipe_winsys *winsys, enum pipe_format format) { struct pipe_surface *surf = CALLOC_STRUCT(pipe_surface); if (surf) { @@ -251,8 +211,8 @@ intel_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) struct pipe_surface *surf = *s; surf->refcount--; if (surf->refcount == 0) { - if (surf->region) - winsys->region_release(winsys, &surf->region); + if (surf->buffer) + winsys->buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -299,8 +259,7 @@ intel_create_pipe_winsys( int fd ) iws->winsys.flush_frontbuffer = intel_flush_frontbuffer; iws->winsys.printf = intel_printf; iws->winsys.get_name = intel_get_name; - iws->winsys.region_alloc = intel_i915_region_alloc; - iws->winsys.region_release = intel_i915_region_release; + iws->winsys.surface_pitch = intel_i915_surface_pitch; iws->winsys.surface_alloc = intel_i915_surface_alloc; iws->winsys.surface_release = intel_i915_surface_release; diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_softpipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_softpipe.c index 7a93546bc22..f9ed6253f1d 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_softpipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_softpipe.c @@ -48,9 +48,9 @@ static boolean intel_is_format_supported(struct softpipe_winsys *sws, uint format) { switch(format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - case PIPE_FORMAT_U_R5_G6_B5: - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: return TRUE; default: return FALSE; diff --git a/src/mesa/drivers/dri/nouveau_winsys/Makefile b/src/mesa/drivers/dri/nouveau_winsys/Makefile index 97b861526f4..fe9a9668b11 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/Makefile +++ b/src/mesa/drivers/dri/nouveau_winsys/Makefile @@ -8,7 +8,8 @@ MINIGLX_SOURCES = PIPE_DRIVERS = \ $(TOP)/src/mesa/pipe/softpipe/libsoftpipe.a \ - $(TOP)/src/mesa/pipe/nv40/libnv40.a + $(TOP)/src/mesa/pipe/nv40/libnv40.a \ + $(TOP)/src/mesa/pipe/nv50/libnv50.a DRIVER_SOURCES = \ nouveau_bo.c \ @@ -16,16 +17,18 @@ DRIVER_SOURCES = \ nouveau_context.c \ nouveau_device.c \ nouveau_dma.c \ + nouveau_fence.c \ nouveau_grobj.c \ nouveau_lock.c \ nouveau_notifier.c \ + nouveau_pushbuf.c \ nouveau_screen.c \ nouveau_swapbuffers.c \ nouveau_winsys.c \ nouveau_winsys_pipe.c \ nouveau_winsys_softpipe.c \ - nv04_region.c \ - nv50_region.c + nv04_surface.c \ + nv50_surface.c C_SOURCES = \ $(COMMON_SOURCES) \ diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_bo.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_bo.c index 3b508cf92b3..d684ab4d7c4 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_bo.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_bo.c @@ -31,45 +31,12 @@ int nouveau_bo_init(struct nouveau_device *userdev) { - struct nouveau_device_priv *nv = nouveau_device(userdev); - struct nouveau_channel *chan; - int ret; - - if ((ret = nouveau_channel_alloc(userdev, 0x80000001, 0x80000002, - &nv->bufmgr.channel))) - return ret; - chan = nv->bufmgr.channel; - - if ((ret = nouveau_notifier_alloc(nv->bufmgr.channel, 0x80000003, 1, - &nv->bufmgr.notify))) - return ret; - - if ((ret = nouveau_grobj_alloc(nv->bufmgr.channel, 0x80000004, 0x39, - &nv->bufmgr.m2mf))) - return ret; - - nouveau_notifier_reset(nv->bufmgr.notify, 0); - BEGIN_RING_CH(chan, nv->bufmgr.m2mf, 0x180, 1); - OUT_RING_CH (chan, nv->bufmgr.notify->handle); - BEGIN_RING_CH(chan, nv->bufmgr.m2mf, 0x104, 1); - OUT_RING_CH (chan, 0); - BEGIN_RING_CH(chan, nv->bufmgr.m2mf, 0x100, 1); - OUT_RING_CH (chan, 0); - FIRE_RING_CH (chan); - if ((ret = nouveau_notifier_wait_status(nv->bufmgr.notify, 0, 0, 2000))) - return ret; - return 0; } void nouveau_bo_takedown(struct nouveau_device *userdev) { - struct nouveau_device_priv *nv = nouveau_device(userdev); - - nouveau_notifier_free(&nv->bufmgr.notify); - nouveau_grobj_free(&nv->bufmgr.m2mf); - nouveau_channel_free(&nv->bufmgr.channel); } static int @@ -238,6 +205,9 @@ nouveau_bo_del(struct nouveau_bo **userbo) if (--bo->refcount) return; + if (bo->fence) + nouveau_fence_wait(&bo->fence); + nouveau_bo_realloc_gpu(bo, 0, 0); if (bo->sysmem && !bo->user) free(bo->sysmem); @@ -265,83 +235,48 @@ nouveau_bo_unmap(struct nouveau_bo *userbo) userbo->map = NULL; } -void -nouveau_bo_emit_reloc(struct nouveau_channel *userchan, void *ptr, - struct nouveau_bo *userbo, uint32_t data, uint32_t flags, - uint32_t vor, uint32_t tor) -{ - struct nouveau_channel_priv *chan = nouveau_channel(userchan); - struct nouveau_bo_priv *bo = nouveau_bo(userbo); - struct nouveau_bo_reloc *r; - int i, on_list = 0; - - for (i = 0; i < chan->nr_buffers; i++) { - if (chan->buffers[i].bo == bo) { - on_list = 1; - break; - } - } - - if (i >= 128) - return; - - if (on_list) { - chan->buffers[i].flags &= (flags | NOUVEAU_BO_RDWR); - chan->buffers[i].flags |= (flags & NOUVEAU_BO_RDWR); - } else { - chan->buffers[i].bo = bo; - chan->buffers[i].flags = flags; - chan->nr_buffers++; - } - - if (chan->num_relocs >= chan->max_relocs) - FIRE_RING_CH(userchan); - r = &chan->relocs[chan->num_relocs++]; - - r->ptr = ptr; - r->bo = bo; - r->data = data; - r->flags = flags; - r->vor = vor; - r->tor = tor; -} - static int nouveau_bo_upload(struct nouveau_bo_priv *bo) { + if (bo->fence) + nouveau_fence_wait(&bo->fence); memcpy(bo->map, bo->sysmem, bo->drm.size); return 0; } -void -nouveau_bo_validate(struct nouveau_channel *userchan) +int +nouveau_bo_validate(struct nouveau_channel *chan, struct nouveau_bo *bo, + struct nouveau_fence *fence, uint32_t flags) { - struct nouveau_channel_priv *chan = nouveau_channel(userchan); - int i; - - for (i = 0; i < chan->nr_buffers; i++) { - struct nouveau_bo_priv *bo = chan->buffers[i].bo; - - if (!bo->drm.size) { - nouveau_bo_realloc_gpu(bo, chan->buffers[i].flags, - bo->base.size); - nouveau_bo_upload(bo); - } else - if (bo->user || bo->base.map) - nouveau_bo_upload(bo); - - if (!bo->user && !bo->base.map) { - free(bo->sysmem); - bo->sysmem = NULL; - } - + struct nouveau_bo_priv *nvbo = nouveau_bo(bo); + + if (!nvbo->drm.size) { + nouveau_bo_realloc_gpu(nvbo, flags, nvbo->base.size); + nouveau_bo_upload(nvbo); + } else + if (nvbo->user) { + nouveau_bo_upload(nvbo); + } else + if (nvbo->base.map) { + nouveau_bo_upload(nvbo); + nvbo->sync_hack = 1; + } - bo->base.offset = bo->drm.offset; - if (bo->drm.flags & NOUVEAU_MEM_AGP) - bo->base.flags = NOUVEAU_BO_GART; - else - bo->base.flags = NOUVEAU_BO_VRAM; + if (!nvbo->user && !nvbo->base.map) { + free(nvbo->sysmem); + nvbo->sysmem = NULL; } - chan->nr_buffers = 0; + + if (nvbo->fence) + nouveau_fence_del(&nvbo->fence); + nouveau_fence_ref(fence, &nvbo->fence); + + nvbo->base.offset = nvbo->drm.offset; + if (nvbo->drm.flags & NOUVEAU_MEM_AGP) + nvbo->base.flags = NOUVEAU_BO_GART; + else + nvbo->base.flags = NOUVEAU_BO_VRAM; + + return 0; } diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_channel.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_channel.c index ef41020b727..c4558e5573a 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_channel.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_channel.c @@ -85,12 +85,8 @@ nouveau_channel_alloc(struct nouveau_device *userdev, uint32_t fb_ctxdma, return ret; } - chan->max_relocs = chan->drm.cmdbuf_size / 4; - chan->num_relocs = 0; - chan->relocs = - malloc(sizeof(struct nouveau_bo_reloc) * chan->max_relocs); - nouveau_dma_channel_init(&chan->base); + nouveau_pushbuf_init(&chan->base); *userchan = &chan->base; return 0; @@ -114,9 +110,6 @@ nouveau_channel_free(struct nouveau_channel **userchan) FIRE_RING_CH(&chan->base); - if (chan->relocs) - free(chan->relocs); - nouveau_grobj_free(&chan->base.vram); nouveau_grobj_free(&chan->base.gart); diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_context.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_context.c index 67df43647aa..03f1816c323 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_context.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_context.c @@ -1,18 +1,8 @@ -#include "glheader.h" -#include "context.h" -#include "extensions.h" - -#include "tnl/tnl.h" -#include "tnl/t_pipeline.h" -#include "tnl/t_vertex.h" - -#include "drivers/common/driverfuncs.h" - -#include "drirenderbuffer.h" +#include "main/glheader.h" +#include "glapi/glthread.h" +#include #include "state_tracker/st_public.h" -#include "state_tracker/st_context.h" - #include "pipe/p_defines.h" #include "pipe/p_context.h" @@ -125,6 +115,36 @@ nouveau_context_create(const __GLcontextModes *glVis, debug_control); #endif + /*XXX: Hack up a fake region and buffer object for front buffer. + * This will go away with TTM, replaced with a simple reference + * of the front buffer handle passed to us by the DDX. + */ + { + struct pipe_surface *fb_surf; + struct nouveau_bo_priv *fb_bo; + + fb_bo = calloc(1, sizeof(struct nouveau_bo_priv)); + fb_bo->drm.offset = nv_screen->front_offset; + fb_bo->drm.flags = NOUVEAU_MEM_FB; + fb_bo->drm.size = nv_screen->front_pitch * + nv_screen->front_height; + fb_bo->refcount = 1; + fb_bo->base.flags = NOUVEAU_BO_PIN | NOUVEAU_BO_VRAM; + fb_bo->base.offset = fb_bo->drm.offset; + fb_bo->base.handle = (unsigned long)fb_bo; + fb_bo->base.size = fb_bo->drm.size; + fb_bo->base.device = nv_screen->device; + + fb_surf = calloc(1, sizeof(struct pipe_surface)); + fb_surf->cpp = nv_screen->front_cpp; + fb_surf->pitch = nv_screen->front_pitch / fb_surf->cpp; + fb_surf->height = nv_screen->front_height; + fb_surf->refcount = 1; + fb_surf->buffer = (void *)fb_bo; + + nv->frontbuffer = fb_surf; + } + if ((ret = nouveau_grobj_alloc(nv->channel, 0x00000000, 0x30, &nv->NvNull))) { NOUVEAU_ERR("Error creating NULL object: %d\n", ret); @@ -139,9 +159,9 @@ nouveau_context_create(const __GLcontextModes *glVis, } if (nv->chipset < 0x50) - ret = nouveau_region_init_nv04(nv); + ret = nouveau_surface_init_nv04(nv); else - ret = nouveau_region_init_nv50(nv); + ret = nouveau_surface_init_nv50(nv); if (ret) { return GL_FALSE; } diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_context.h b/src/mesa/drivers/dri/nouveau_winsys/nouveau_context.h index f2557af935d..cd59b7cc436 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_context.h +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_context.h @@ -1,9 +1,6 @@ #ifndef __NOUVEAU_CONTEXT_H__ #define __NOUVEAU_CONTEXT_H__ -#include "glheader.h" -#include "context.h" - #include "dri_util.h" #include "xmlconfig.h" @@ -31,6 +28,7 @@ struct nouveau_context { drmLock drm_lock; GLboolean locked; struct nouveau_screen *nv_screen; + struct pipe_surface *frontbuffer; /* Bufmgr */ struct { @@ -46,6 +44,7 @@ struct nouveau_context { struct nouveau_bo *reloc_head; /* Hardware context */ + uint32_t *pushbuf; struct nouveau_channel *channel; struct nouveau_notifier *sync_notifier; struct nouveau_grobj *NvNull; @@ -53,28 +52,26 @@ struct nouveau_context { struct nouveau_grobj *NvImageBlit; struct nouveau_grobj *NvGdiRect; struct nouveau_grobj *NvM2MF; + struct nouveau_grobj *Nv2D; uint32_t next_handle; uint32_t next_sequence; - /* pipe_region accel */ - int (*region_display)(void); - int (*region_copy)(struct nouveau_context *, struct pipe_region *, - unsigned, unsigned, unsigned, struct pipe_region *, - unsigned, unsigned, unsigned, unsigned, unsigned); - int (*region_fill)(struct nouveau_context *, struct pipe_region *, - unsigned, unsigned, unsigned, unsigned, unsigned, - unsigned); - int (*region_data)(struct nouveau_context *, struct pipe_region *, - unsigned, unsigned, unsigned, const void *, - unsigned, unsigned, unsigned, unsigned, unsigned); + /* pipe_surface accel */ + struct pipe_surface *surf_src, *surf_dst; + unsigned surf_src_offset, surf_dst_offset; + int (*surface_copy_prep)(struct nouveau_context *, + struct pipe_surface *dst, + struct pipe_surface *src); + void (*surface_copy)(struct nouveau_context *, unsigned dx, unsigned dy, + unsigned sx, unsigned sy, unsigned w, unsigned h); + void (*surface_copy_done)(struct nouveau_context *); + int (*surface_fill)(struct nouveau_context *, struct pipe_surface *, + unsigned, unsigned, unsigned, unsigned, unsigned); + int (*surface_data)(struct nouveau_context *, struct pipe_surface *, + unsigned, unsigned, const void *, unsigned, + unsigned, unsigned, unsigned, unsigned); }; -static INLINE struct nouveau_context * -nouveau_context(GLcontext *ctx) -{ - return (struct nouveau_context *)ctx; -} - extern GLboolean nouveau_context_create(const __GLcontextModes *, __DRIcontextPrivate *, void *); extern void nouveau_context_destroy(__DRIcontextPrivate *); @@ -99,7 +96,10 @@ extern int __nouveau_debug; extern void LOCK_HARDWARE(struct nouveau_context *); extern void UNLOCK_HARDWARE(struct nouveau_context *); -extern int nouveau_region_init_nv04(struct nouveau_context *); -extern int nouveau_region_init_nv50(struct nouveau_context *); +extern int nouveau_surface_init_nv04(struct nouveau_context *); +extern int nouveau_surface_init_nv50(struct nouveau_context *); + +extern uint32_t *nouveau_pipe_dma_beginp(struct nouveau_grobj *, int, int); +extern void nouveau_pipe_dma_kickoff(struct nouveau_channel *); #endif diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_dma.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_dma.c index d3239959034..6ec390ec769 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_dma.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_dma.c @@ -142,35 +142,6 @@ nouveau_dma_kickoff(struct nouveau_channel *userchan) if (chan->dma.cur == chan->dma.put) return; - if (chan->num_relocs) { - nouveau_bo_validate(userchan); - - for (i = 0; i < chan->num_relocs; i++) { - struct nouveau_bo_reloc *r = &chan->relocs[i]; - uint32_t push; - - if (r->flags & NOUVEAU_BO_LOW) { - push = r->bo->base.offset + r->data; - } else - if (r->flags & NOUVEAU_BO_HIGH) { - push = (r->bo->base.offset + r->data) >> 32; - } else { - push = r->data; - } - - if (r->flags & NOUVEAU_BO_OR) { - if (r->bo->base.flags & NOUVEAU_BO_VRAM) - push |= r->vor; - else - push |= r->tor; - } - - *r->ptr = push; - } - - chan->num_relocs = 0; - } - #ifdef NOUVEAU_DMA_DEBUG if (chan->dma.push_free) { NOUVEAU_ERR("Packet incomplete: %d left\n", chan->dma.push_free); @@ -179,8 +150,19 @@ nouveau_dma_kickoff(struct nouveau_channel *userchan) #endif #ifdef NOUVEAU_DMA_DUMP_POSTRELOC_PUSHBUF - for (i = chan->dma.put; i < chan->dma.cur; i++) - NOUVEAU_MSG("0x%08x\n", chan->pushbuf[i]); + for (i = chan->dma.put; i < chan->dma.cur; i++) { + NOUVEAU_MSG("0x%08x 0x%08x\n", (i<<2)+chan->dma.base, + chan->pushbuf[i]); + if ((chan->pushbuf[i] & 0xf0000000) == 0x20000000) { + int n = (((chan->pushbuf[i] & 0x0fffffff) - + chan->dma.base) / 4); + do { + NOUVEAU_MSG("\t0x%08x 0x%08x\n", + (n<<2)+chan->dma.base, + chan->pushbuf[n]); + } while ((chan->pushbuf[n++]&0xf0000000) != 0x20000000); + } + } #endif put_offset = (chan->dma.cur << 2) + chan->dma.base; diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h b/src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h index 1a21da69857..f176767f136 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_drmif.h @@ -32,6 +32,7 @@ #include "pipe/nouveau/nouveau_grobj.h" #include "pipe/nouveau/nouveau_notifier.h" #include "pipe/nouveau/nouveau_bo.h" +#include "pipe/nouveau/nouveau_resource.h" struct nouveau_device_priv { struct nouveau_device base; @@ -40,12 +41,6 @@ struct nouveau_device_priv { drm_context_t ctx; drmLock *lock; int needs_close; - - struct { - struct nouveau_channel *channel; - struct nouveau_notifier *notify; - struct nouveau_grobj *m2mf; - } bufmgr; }; #define nouveau_device(n) ((struct nouveau_device_priv *)(n)) @@ -65,6 +60,93 @@ nouveau_device_get_param(struct nouveau_device *, uint64_t param, uint64_t *v); extern int nouveau_device_set_param(struct nouveau_device *, uint64_t param, uint64_t val); +struct nouveau_fence { + struct nouveau_channel *channel; +}; + +struct nouveau_fence_priv { + struct nouveau_fence base; + int refcount; + + struct nouveau_fence *next; + + uint32_t sequence; + int emitted; + int signalled; +}; +#define nouveau_fence(n) ((struct nouveau_fence_priv *)(n)) + +extern int +nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **); + +extern int +nouveau_fence_ref(struct nouveau_fence *, struct nouveau_fence **); + +extern void +nouveau_fence_del(struct nouveau_fence **); + +extern void +nouveau_fence_emit(struct nouveau_fence *); + +extern int +nouveau_fence_wait(struct nouveau_fence **); + +extern void +nouveau_fence_flush(struct nouveau_channel *); + +struct nouveau_pushbuf_reloc { + uint64_t next; + uint64_t handle; + uint32_t *ptr; + uint32_t flags; + uint32_t data; + uint32_t vor; + uint32_t tor; +}; + +struct nouveau_pushbuf_bo { + uint64_t next; + uint64_t handle; + uint64_t flags; + uint64_t relocs; + int nr_relocs; +}; + +struct nouveau_pushbuf { + struct nouveau_channel *channel; + unsigned remaining; + uint32_t *cur; +}; + +struct nouveau_pushbuf_priv { + struct nouveau_pushbuf base; + struct nouveau_pushbuf *next; + + struct nouveau_resource *res; + struct nouveau_fence *fence; + + uint64_t buffers; + int nr_buffers; +}; +#define nouveau_pushbuf(n) ((struct nouveau_pushbuf_priv *)(n)) +#define pbbo_to_ptr(o) ((uint64_t)(unsigned long)(o)) +#define ptr_to_pbbo(h) ((struct nouveau_pushbuf_bo *)(unsigned long)(h)) +#define pbrel_to_ptr(o) ((uint64_t)(unsigned long)(o)) +#define ptr_to_pbrel(h) ((struct nouveau_pushbuf_reloc *)(unsigned long)(h)) +#define bo_to_ptr(o) ((uint64_t)(unsigned long)(o)) +#define ptr_to_bo(h) ((struct nouveau_bo_priv *)(unsigned long)(h)) + +extern int +nouveau_pushbuf_init(struct nouveau_channel *); + +extern int +nouveau_pushbuf_flush(struct nouveau_channel *); + +extern int +nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr, + struct nouveau_bo *, uint32_t data, uint32_t flags, + uint32_t vor, uint32_t tor); + struct nouveau_channel_priv { struct nouveau_channel base; @@ -92,15 +174,13 @@ struct nouveau_channel_priv { int push_free; } dma; - struct { - struct nouveau_bo_priv *bo; - uint32_t flags; - } buffers[128]; - int nr_buffers; + struct nouveau_fence *fence_head; + struct nouveau_fence *fence_tail; + uint32_t fence_sequence; - struct nouveau_bo_reloc *relocs; - int num_relocs; - int max_relocs; + struct nouveau_resource *pb_heap; + struct nouveau_pushbuf *pb_head; + struct nouveau_pushbuf *pb_tail; }; #define nouveau_channel(n) ((struct nouveau_channel_priv *)(n)) @@ -154,6 +234,8 @@ nouveau_notifier_wait_status(struct nouveau_notifier *, int id, int status, struct nouveau_bo_priv { struct nouveau_bo base; + struct nouveau_fence *fence; + struct drm_nouveau_mem_alloc drm; void *map; @@ -161,15 +243,8 @@ struct nouveau_bo_priv { int user; int refcount; + int sync_hack; }; - -struct nouveau_bo_reloc { - struct nouveau_bo_priv *bo; - uint32_t *ptr; - uint32_t flags; - uint32_t data, vor, tor; -}; - #define nouveau_bo(n) ((struct nouveau_bo_priv *)(n)) extern int @@ -201,12 +276,18 @@ nouveau_bo_map(struct nouveau_bo *, uint32_t flags); extern void nouveau_bo_unmap(struct nouveau_bo *); -extern void -nouveau_bo_emit_reloc(struct nouveau_channel *chan, void *ptr, - struct nouveau_bo *, uint32_t data, uint32_t flags, - uint32_t vor, uint32_t tor); +extern int +nouveau_bo_validate(struct nouveau_channel *, struct nouveau_bo *, + struct nouveau_fence *fence, uint32_t flags); + +extern int +nouveau_resource_init(struct nouveau_resource **heap, int size); + +extern int +nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv, + struct nouveau_resource **); extern void -nouveau_bo_validate(struct nouveau_channel *); +nouveau_resource_free(struct nouveau_resource **); #endif diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_fence.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_fence.c new file mode 100644 index 00000000000..842b38f913b --- /dev/null +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_fence.c @@ -0,0 +1,135 @@ +/* + * Copyright 2007 Nouveau Project + * + * 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. + * + * 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 + * THE AUTHORS 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 +#include + +#include "nouveau_drmif.h" +#include "nouveau_dma.h" +#include "nouveau_local.h" + +int +nouveau_fence_new(struct nouveau_channel *chan, struct nouveau_fence **fence) +{ + struct nouveau_fence_priv *nvfence; + + if (!chan || !fence || *fence) + return -EINVAL; + + nvfence = calloc(1, sizeof(struct nouveau_fence_priv)); + if (!nvfence) + return -ENOMEM; + nvfence->base.channel = chan; + nvfence->refcount = 1; + + *fence = &nvfence->base; + return 0; +} + +int +nouveau_fence_ref(struct nouveau_fence *ref, struct nouveau_fence **fence) +{ + struct nouveau_fence_priv *nvfence; + + if (!ref || !fence || *fence) + return -EINVAL; + nvfence = nouveau_fence(ref); + nvfence->refcount++; + + *fence = &nvfence->base; + return 0; +} + +void +nouveau_fence_del(struct nouveau_fence **fence) +{ + struct nouveau_fence_priv *nvfence; + + if (!fence || !*fence) + return; + nvfence = nouveau_fence(*fence); + *fence = NULL; + + if (--nvfence->refcount <= 0) { + if (nvfence->emitted && !nvfence->signalled) + nouveau_fence_wait((void *)&nvfence); + free(nvfence); + } +} + +void +nouveau_fence_emit(struct nouveau_fence *fence) +{ + struct nouveau_channel_priv *nvchan = nouveau_channel(fence->channel); + struct nouveau_fence_priv *nvfence = nouveau_fence(fence); + + nvfence->emitted = 1; + nvfence->sequence = ++nvchan->fence_sequence; + if (nvfence->sequence == 0xffffffff) + NOUVEAU_ERR("AII wrap unhandled\n"); + + BEGIN_RING_CH(&nvchan->base, nvchan->subchannel[0].grobj, 0x50, 1); + OUT_RING_CH (&nvchan->base, nvfence->sequence); + + if (nvchan->fence_tail) { + nouveau_fence(nvchan->fence_tail)->next = fence; + } else { + nvchan->fence_head = fence; + } + nvchan->fence_tail = fence; +} + +void +nouveau_fence_flush(struct nouveau_channel *chan) +{ + struct nouveau_channel_priv *nvchan = nouveau_channel(chan); + struct nouveau_fence_priv *nvfence = nouveau_fence(nvchan->fence_head); + uint32_t sequence = *nvchan->ref_cnt; + + while (nvchan->fence_head && nvfence->sequence <= sequence) { + nvfence->signalled = 1; + + nvchan->fence_head = nvfence->next; + if (nvchan->fence_head == NULL) + nvchan->fence_tail = NULL; + nvfence = nouveau_fence(nvchan->fence_head); + } +} + +int +nouveau_fence_wait(struct nouveau_fence **fence) +{ + struct nouveau_fence_priv *nvfence; + + if (!fence || !*fence) + return -EINVAL; + nvfence = nouveau_fence(*fence); + + if (nvfence->emitted) { + while (!nvfence->signalled) + nouveau_fence_flush(nvfence->base.channel); + } + nouveau_fence_del(fence); + + return 0; +} + diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_local.h b/src/mesa/drivers/dri/nouveau_winsys/nouveau_local.h index 4ada5d014bf..1978edea02d 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_local.h +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_local.h @@ -26,15 +26,16 @@ /* Push buffer access macros */ #define BEGIN_RING(obj,mthd,size) do { \ - BEGIN_RING_CH(nv->channel, nv->obj, (mthd), (size)); \ + nv->pushbuf = nouveau_pipe_dma_beginp(nv->obj, (mthd), (size)); \ } while(0) #define OUT_RING(data) do { \ - OUT_RING_CH(nv->channel, (data)); \ + (*nv->pushbuf++) = (data); \ } while(0) #define OUT_RINGp(src,size) do { \ - OUT_RINGp_CH(nv->channel, (src), (size)); \ + memcpy(nv->pushbuf, (src), (size)<<2); \ + nv->pushbuf += (size); \ } while(0) #define OUT_RINGf(data) do { \ @@ -43,18 +44,13 @@ OUT_RING(c.u); \ } while(0) -#define WAIT_RING(size) do { \ - WAIT_RING_CH(nv->channel, (size)); \ -} while(0) - #define FIRE_RING() do { \ - FIRE_RING_CH(nv->channel); \ + nouveau_pipe_dma_kickoff(nv->channel); \ } while(0) #define OUT_RELOC(bo,data,flags,vor,tor) do { \ - struct nouveau_channel_priv *chan = nouveau_channel(nv->channel); \ - nouveau_bo_emit_reloc(nv->channel, &chan->pushbuf[chan->dma.cur], \ - (void*)(bo), (data), (flags), (vor), (tor)); \ + nouveau_pushbuf_emit_reloc(nv->channel, nv->pushbuf, (void*)(bo), \ + (data), (flags), (vor), (tor)); \ OUT_RING(0); \ } while(0) diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_lock.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_lock.c index ffe7d01d667..9adb9ac8547 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_lock.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_lock.c @@ -25,18 +25,9 @@ * **************************************************************************/ - -#include "glheader.h" -#include "context.h" -#include "extensions.h" - -#include "state_tracker/st_public.h" -#include "state_tracker/st_context.h" - -#include "drirenderbuffer.h" -#include "vblank.h" -#include "utils.h" -#include "xmlpool.h" /* for symbolic values of enum-type options */ +#include "main/glheader.h" +#include "glapi/glthread.h" +#include #include "nouveau_context.h" #include "nouveau_screen.h" diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c new file mode 100644 index 00000000000..6cb06f8c37b --- /dev/null +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_pushbuf.c @@ -0,0 +1,257 @@ +/* + * Copyright 2007 Nouveau Project + * + * 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. + * + * 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 + * THE AUTHORS 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 +#include +#include + +#include "nouveau_drmif.h" +#include "nouveau_dma.h" + +int +nouveau_pushbuf_init(struct nouveau_channel *chan) +{ + struct nouveau_channel_priv *nvchan = nouveau_channel(chan); + + if (!nvchan) + return -EINVAL; + + /* Everything except first 4KiB of the push buffer is managed by us */ + if (nouveau_resource_init(&nvchan->pb_heap, + nvchan->drm.cmdbuf_size - 4096)) + return -EINVAL; + + /* Shrink master ring to 4KiB */ + assert(nvchan->dma.cur <= (4096/4)); + nvchan->dma.max = (4096 / 4) - 2; + nvchan->dma.free = nvchan->dma.max - nvchan->dma.cur; + + return 0; +} + +/* This would be our TTM "superioctl" */ +int +nouveau_pushbuf_flush(struct nouveau_channel *chan) +{ + struct nouveau_channel_priv *nvchan = nouveau_channel(chan); + struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(nvchan->pb_tail); + struct nouveau_pushbuf_bo *pbbo; + struct nouveau_fence *fence = NULL; + int sync_hack = 0; + int ret; + + if (!nvpb) + goto out_realloc; + + if (nvpb->base.remaining == nvpb->res->size / 4) + return 0; + + ret = nouveau_fence_new(chan, &fence); + if (ret) + return ret; + + /* Validate buffers + apply relocations */ + while ((pbbo = ptr_to_pbbo(nvpb->buffers))) { + struct nouveau_pushbuf_reloc *r; + struct nouveau_bo *bo = &ptr_to_bo(pbbo->handle)->base; + + ret = nouveau_bo_validate(chan, bo, fence, pbbo->flags); + assert (ret == 0); + + sync_hack |= nouveau_bo(bo)->sync_hack; + nouveau_bo(bo)->sync_hack = 0; + + while ((r = ptr_to_pbrel(pbbo->relocs))) { + uint32_t push; + + if (r->flags & NOUVEAU_BO_LOW) { + push = bo->offset + r->data; + } else + if (r->flags & NOUVEAU_BO_HIGH) { + push = (bo->offset + r->data) >> 32; + } else { + push = r->data; + } + + if (r->flags & NOUVEAU_BO_OR) { + if (bo->flags & NOUVEAU_BO_VRAM) + push |= r->vor; + else + push |= r->tor; + } + + *r->ptr = push; + pbbo->relocs = r->next; + free(r); + } + + nvpb->buffers = pbbo->next; + free(pbbo); + } + nvpb->nr_buffers = 0; + + /* Emit JMP to indirect pushbuf */ + if (nvchan->dma.free < 1) + WAIT_RING_CH(chan, 1); + nvchan->dma.free -= 1; +#ifdef NOUVEAU_DMA_DEBUG + nvchan->dma.push_free = 1; +#endif + OUT_RING_CH(chan, 0x20000000 | (nvpb->res->start + 4096)); + + /* Add JMP back to master pushbuf from indirect pushbuf */ + (*nvpb->base.cur++) = + 0x20000000 | ((nvchan->dma.cur << 2) + nvchan->dma.base); + + /* Fence */ + nvpb->fence = fence; + nouveau_fence_emit(nvpb->fence); + + /* Kickoff */ + FIRE_RING_CH(chan); + + /* Allocate space for next push buffer */ +out_realloc: + nvpb = calloc(1, sizeof(struct nouveau_pushbuf_priv)); + if (!nvpb) + return -ENOMEM; + + if (nouveau_resource_alloc(nvchan->pb_heap, 0x2000, NULL, &nvpb->res)) { + struct nouveau_pushbuf_priv *e; + int nr = 0; + + /* Update fences */ + nouveau_fence_flush(chan); + + /* Free any push buffers that have already been executed */ + e = nouveau_pushbuf(nvchan->pb_head); + while (e && e->fence) { + if (!e->fence || !nouveau_fence(e->fence)->signalled) + break; + nouveau_fence_del(&e->fence); + nouveau_resource_free(&e->res); + nr++; + + nvchan->pb_head = e->next; + if (nvchan->pb_head == NULL) + nvchan->pb_tail = NULL; + free(e); + e = nouveau_pushbuf(nvchan->pb_head); + } + + /* We didn't free any buffers above. As a last resort, busy + * wait on the oldest buffer becoming available. + */ + if (!nr) { + e = nouveau_pushbuf(nvchan->pb_head); + nouveau_fence_wait(&e->fence); + nouveau_resource_free(&e->res); + + nvchan->pb_head = e->next; + if (nvchan->pb_head == NULL) + nvchan->pb_tail = NULL; + free(e); + } + + if (nouveau_resource_alloc(nvchan->pb_heap, 0x2000, nvpb, + &nvpb->res)) + assert(0); + } + + nvpb->base.channel = chan; + nvpb->base.remaining = nvpb->res->size / 4; + nvpb->base.cur = &nvchan->pushbuf[(nvpb->res->start + 4096)/4]; + + if (nvchan->pb_tail) { + nouveau_pushbuf(nvchan->pb_tail)->next = &nvpb->base; + } else { + nvchan->pb_head = &nvpb->base; + } + nvchan->pb_tail = &nvpb->base; + + if (sync_hack) { + struct nouveau_fence *f = NULL; + nouveau_fence_ref(nvpb->fence, &f); + nouveau_fence_wait(&f); + } + + return 0; +} + +static struct nouveau_pushbuf_bo * +nouveau_pushbuf_emit_buffer(struct nouveau_channel *chan, struct nouveau_bo *bo) +{ + struct nouveau_channel_priv *nvchan = nouveau_channel(chan); + struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(nvchan->pb_tail); + struct nouveau_pushbuf_bo *pbbo = ptr_to_pbbo(nvpb->buffers); + + while (pbbo) { + if (pbbo->handle == bo->handle) + return pbbo; + pbbo = ptr_to_pbbo(pbbo->next); + } + + pbbo = malloc(sizeof(struct nouveau_pushbuf_bo)); + pbbo->next = nvpb->buffers; + nvpb->buffers = pbbo_to_ptr(pbbo); + nvpb->nr_buffers++; + + pbbo->handle = bo_to_ptr(bo); + pbbo->flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART; + pbbo->relocs = 0; + pbbo->nr_relocs = 0; + return pbbo; +} + +int +nouveau_pushbuf_emit_reloc(struct nouveau_channel *chan, void *ptr, + struct nouveau_bo *bo, uint32_t data, uint32_t flags, + uint32_t vor, uint32_t tor) +{ + struct nouveau_pushbuf_bo *pbbo; + struct nouveau_pushbuf_reloc *r; + + if (!chan) + return -EINVAL; + + pbbo = nouveau_pushbuf_emit_buffer(chan, bo); + if (!pbbo) + return -EFAULT; + + r = malloc(sizeof(struct nouveau_pushbuf_reloc)); + r->next = pbbo->relocs; + pbbo->relocs = pbrel_to_ptr(r); + pbbo->nr_relocs++; + + pbbo->flags |= (flags & NOUVEAU_BO_RDWR); + pbbo->flags &= (flags | NOUVEAU_BO_RDWR); + + r->handle = bo_to_ptr(r); + r->ptr = ptr; + r->flags = flags; + r->data = data; + r->vor = vor; + r->tor = tor; + + return 0; +} + diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_screen.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_screen.c index 16c4324164b..a1eed2e44aa 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_screen.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_screen.c @@ -1,9 +1,3 @@ -#include "glheader.h" -#include "context.h" -#include "framebuffer.h" -#include "matrix.h" -#include "renderbuffer.h" -#include "simple_list.h" #include "utils.h" #include "vblank.h" #include "xmlpool.h" @@ -61,6 +55,8 @@ nouveau_screen_create(__DRIscreenPrivate *driScrnPriv) nv_screen->front_offset = nv_dri->front_offset; nv_screen->front_pitch = nv_dri->front_pitch * (nv_dri->bpp / 8); + nv_screen->front_cpp = nv_dri->bpp / 8; + nv_screen->front_height = nv_dri->height; return GL_TRUE; } diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_screen.h b/src/mesa/drivers/dri/nouveau_winsys/nouveau_screen.h index e53cd873a7e..019823bd44d 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_screen.h +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_screen.h @@ -12,6 +12,8 @@ struct nouveau_screen { uint32_t front_offset; uint32_t front_pitch; + uint32_t front_cpp; + uint32_t front_height; }; #endif diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_swapbuffers.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_swapbuffers.c index 57598f9cab9..91bf243f424 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_swapbuffers.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_swapbuffers.c @@ -1,7 +1,10 @@ -#include "context.h" +#include "main/glheader.h" +#include "glapi/glthread.h" +#include #include "pipe/p_context.h" #include "state_tracker/st_public.h" +#include "state_tracker/st_context.h" #include "state_tracker/st_cb_fbo.h" #include "nouveau_context.h" @@ -14,8 +17,6 @@ nouveau_copy_buffer(__DRIdrawablePrivate *dPriv, struct pipe_surface *surf, const drm_clip_rect_t *rect) { struct nouveau_context *nv = dPriv->driContextPriv->driverPrivate; - struct nouveau_screen *nv_screen = nv->nv_screen; - struct pipe_region *p_region = surf->region; drm_clip_rect_t *pbox; int nbox, i; @@ -27,17 +28,7 @@ nouveau_copy_buffer(__DRIdrawablePrivate *dPriv, struct pipe_surface *surf, pbox = dPriv->pClipRects; nbox = dPriv->numClipRects; - BEGIN_RING(NvCtxSurf2D, 0x184, 2); - OUT_RELOCo(p_region->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); - OUT_RING (nv->channel->vram->handle); - - BEGIN_RING(NvCtxSurf2D, 0x300, 4); - OUT_RING ((p_region->cpp == 4) ? 6 : 4); - OUT_RING ((nv_screen->front_pitch << 16) | - (p_region->pitch * p_region->cpp)); - OUT_RELOCl(p_region->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); - OUT_RING (nv_screen->front_offset); - + nv->surface_copy_prep(nv, nv->frontbuffer, surf); for (i = 0; i < nbox; i++, pbox++) { int sx, sy, dx, dy, w, h; @@ -48,10 +39,7 @@ nouveau_copy_buffer(__DRIdrawablePrivate *dPriv, struct pipe_surface *surf, w = pbox->x2 - pbox->x1; h = pbox->y2 - pbox->y1; - BEGIN_RING(NvImageBlit, 0x300, 3); - OUT_RING ((sy << 16) | sx); - OUT_RING ((dy << 16) | dx); - OUT_RING (( h << 16) | w); + nv->surface_copy(nv, dx, dy, sx, sy, w, h); } FIRE_RING(); diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c index bdc89b95318..9919272ebe1 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys.c @@ -1,9 +1,11 @@ +#include "pipe/p_util.h" + #include "nouveau_context.h" #include "nouveau_winsys_pipe.h" #include "pipe/nouveau/nouveau_winsys.h" -static int +int nouveau_resource_init(struct nouveau_resource **heap, int size) { struct nouveau_resource *r; @@ -18,7 +20,7 @@ nouveau_resource_init(struct nouveau_resource **heap, int size) return 0; } -static int +int nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv, struct nouveau_resource **res) { @@ -56,7 +58,7 @@ nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv, return 1; } -static void +void nouveau_resource_free(struct nouveau_resource **res) { struct nouveau_resource *r; @@ -106,25 +108,68 @@ nouveau_pipe_grobj_alloc(struct nouveau_winsys *nvws, int grclass, grclass, grobj); } -static uint32_t * +uint32_t * nouveau_pipe_dma_beginp(struct nouveau_grobj *grobj, int mthd, int size) { - struct nouveau_channel_priv *chan = nouveau_channel(grobj->channel); + struct nouveau_channel_priv *nvchan = nouveau_channel(grobj->channel); uint32_t *pushbuf; - BEGIN_RING_CH(&chan->base, grobj, mthd, size); - pushbuf = &chan->pushbuf[chan->dma.cur]; - chan->dma.cur += size; -#ifdef NOUVEAU_DMA_DEBUG - chan->dma.push_free -= size; -#endif + if (!nvchan->pb_tail || nvchan->pb_tail->remaining < (size + 1)) + nouveau_pushbuf_flush(grobj->channel); + + if (grobj->bound == NOUVEAU_GROBJ_UNBOUND) + nouveau_dma_subc_bind(grobj); + nvchan->subchannel[grobj->subc].seq = nvchan->subc_sequence++; + + pushbuf = nvchan->pb_tail->cur; + nvchan->pb_tail->cur += (size + 1); + nvchan->pb_tail->remaining -= (size + 1); + + (*pushbuf++) = ((grobj->subc << 13) | (size << 18) | mthd); return pushbuf; } -static void -nouveau_pipe_dma_kickoff(struct nouveau_channel *userchan) +void +nouveau_pipe_dma_kickoff(struct nouveau_channel *chan) +{ + nouveau_pushbuf_flush(chan); +} + +static int +nouveau_pipe_surface_copy(struct nouveau_winsys *nvws, struct pipe_surface *dst, + unsigned dx, unsigned dy, struct pipe_surface *src, + unsigned sx, unsigned sy, unsigned w, unsigned h) +{ + struct nouveau_context *nv = nvws->nv; + + if (nv->surface_copy_prep(nv, dst, src)) + return 1; + nv->surface_copy(nv, dx, dy, sx, sy, w, h); + nv->surface_copy_done(nv); + + return 0; +} + +static int +nouveau_pipe_surface_fill(struct nouveau_winsys *nvws, struct pipe_surface *dst, + unsigned dx, unsigned dy, unsigned w, unsigned h, + unsigned value) +{ + if (nvws->nv->surface_fill(nvws->nv, dst, dx, dy, w, h, value)) + return 1; + return 0; +} + +static int +nouveau_pipe_surface_data(struct nouveau_winsys *nvws, struct pipe_surface *dst, + unsigned dx, unsigned dy, const void *src, + unsigned src_pitch, unsigned sx, unsigned sy, + unsigned w, unsigned h) { - FIRE_RING_CH(userchan); + if (nvws->nv->surface_data(nvws->nv, dst, dx, dy, src, src_pitch, sx, + sy, w, h)) + return 1; + return 0; } struct pipe_context * @@ -142,6 +187,10 @@ nouveau_pipe_create(struct nouveau_context *nv) case 0x40: hw_create = nv40_create; break; + case 0x50: + case 0x80: + hw_create = nv50_create; + break; default: NOUVEAU_ERR("Unknown chipset NV%02x\n", (int)nv->chipset); return NULL; @@ -155,7 +204,7 @@ nouveau_pipe_create(struct nouveau_context *nv) nvws->res_free = nouveau_resource_free; nvws->begin_ring = nouveau_pipe_dma_beginp; - nvws->out_reloc = nouveau_bo_emit_reloc; + nvws->out_reloc = nouveau_pushbuf_emit_reloc; nvws->fire_ring = nouveau_pipe_dma_kickoff; nvws->grobj_alloc = nouveau_pipe_grobj_alloc; @@ -168,9 +217,9 @@ nouveau_pipe_create(struct nouveau_context *nv) nvws->notifier_retval = nouveau_notifier_return_val; nvws->notifier_wait = nouveau_notifier_wait_status; - nvws->region_copy = nv->region_copy; - nvws->region_fill = nv->region_fill; - nvws->region_data = nv->region_data; + nvws->surface_copy = nouveau_pipe_surface_copy; + nvws->surface_fill = nouveau_pipe_surface_fill; + nvws->surface_data = nouveau_pipe_surface_data; return hw_create(nouveau_create_pipe_winsys(nv), nvws, nv->chipset); } diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys_pipe.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys_pipe.c index 0dd2cec2ca1..adbf6b28e8d 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys_pipe.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys_pipe.c @@ -1,5 +1,6 @@ #include "pipe/p_winsys.h" #include "pipe/p_defines.h" +#include "pipe/p_util.h" #include "nouveau_context.h" #include "nouveau_device.h" @@ -33,46 +34,18 @@ nouveau_get_name(struct pipe_winsys *pws) return "Nouveau/DRI"; } -static struct pipe_region * -nouveau_region_alloc(struct pipe_winsys *ws, unsigned cpp, - unsigned width, unsigned height, unsigned flags) +static unsigned +nouveau_surface_pitch(struct pipe_winsys *ws, unsigned cpp, unsigned width, + unsigned flags) { - struct pipe_region *region; - - region = calloc(sizeof(*region), 1); - region->cpp = cpp; - region->pitch = ((cpp * width + 63) & ~63) / cpp; - region->height = height; - region->refcount = 1; - region->buffer = ws->buffer_create(ws, 64); - - ws->buffer_data(ws, region->buffer, region->pitch * cpp * height, NULL, - PIPE_BUFFER_USAGE_PIXEL); - return region; -} - -static void -nouveau_region_release(struct pipe_winsys *pws, struct pipe_region **pregion) -{ - struct pipe_region *region; - - if (!pregion || !*pregion) - return; - region = *pregion; - *pregion = NULL; - - assert(region->refcount > 0); - region->refcount--; + unsigned pitch = width * cpp; - if (region->refcount == 0) { - assert(region->map_refcount == 0); - pws->buffer_reference(pws, ®ion->buffer, NULL); - free(region); - } + pitch = (pitch + 63) & ~63; + return pitch / cpp; } static struct pipe_surface * -nouveau_surface_alloc(struct pipe_winsys *pws, unsigned format) +nouveau_surface_alloc(struct pipe_winsys *ws, unsigned format) { struct pipe_surface *surf; @@ -82,19 +55,19 @@ nouveau_surface_alloc(struct pipe_winsys *pws, unsigned format) surf->format = format; surf->refcount = 1; - surf->winsys = pws; - + surf->winsys = ws; return surf; } static void -nouveau_surface_release(struct pipe_winsys *pws, struct pipe_surface **s) +nouveau_surface_release(struct pipe_winsys *ws, struct pipe_surface **s) { - struct pipe_surface *surf = *s; *s = NULL; + struct pipe_surface *surf = *s; - if (surf->refcount-- == 0) { - if (surf->region) - pws->region_release(pws, &surf->region); + *s = NULL; + if (--surf->refcount <= 0) { + if (surf->buffer) + ws->buffer_reference(ws, &surf->buffer, NULL); free(surf); } } @@ -229,9 +202,7 @@ nouveau_create_pipe_winsys(struct nouveau_context *nv) pws->flush_frontbuffer = nouveau_flush_frontbuffer; pws->printf = nouveau_printf; - pws->region_alloc = nouveau_region_alloc; - pws->region_release = nouveau_region_release; - + pws->surface_pitch = nouveau_surface_pitch; pws->surface_alloc = nouveau_surface_alloc; pws->surface_release = nouveau_surface_release; diff --git a/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys_softpipe.c b/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys_softpipe.c index c86575f1875..ebce4ddede1 100644 --- a/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys_softpipe.c +++ b/src/mesa/drivers/dri/nouveau_winsys/nouveau_winsys_softpipe.c @@ -49,9 +49,9 @@ static boolean nouveau_is_format_supported(struct softpipe_winsys *sws, uint format) { switch (format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - case PIPE_FORMAT_U_R5_G6_B5: - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: return TRUE; default: break; diff --git a/src/mesa/drivers/dri/nouveau_winsys/nv04_region.c b/src/mesa/drivers/dri/nouveau_winsys/nv04_region.c deleted file mode 100644 index 0fdb38e105c..00000000000 --- a/src/mesa/drivers/dri/nouveau_winsys/nv04_region.c +++ /dev/null @@ -1,247 +0,0 @@ -#include "pipe/p_context.h" - -#include "nouveau_context.h" - -static INLINE int -nv04_surface_format(int cpp) -{ - switch (cpp) { - case 1: return NV04_CONTEXT_SURFACES_2D_FORMAT_Y8; - case 2: return NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5; - case 4: return NV04_CONTEXT_SURFACES_2D_FORMAT_Y32; - default: - return -1; - } -} - -static INLINE int -nv04_rect_format(int cpp) -{ - switch (cpp) { - case 1: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; - case 2: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A16R5G6B5; - case 4: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; - default: - return -1; - } -} - -static int -nv04_region_display(void) -{ - NOUVEAU_ERR("unimplemented\n"); - return 0; -} - -static int -nv04_region_copy_m2mf(struct nouveau_context *nv, struct pipe_region *dst, - unsigned dst_offset, struct pipe_region *src, - unsigned src_offset, unsigned line_len, unsigned height) -{ - BEGIN_RING(NvM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_IN, 2); - OUT_RELOCo(src->buffer, NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | - NOUVEAU_BO_RD); - OUT_RELOCo(dst->buffer, NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | - NOUVEAU_BO_WR); - - while (height) { - int count = (height > 2047) ? 2047 : height; - - BEGIN_RING(NvM2MF, NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); - OUT_RELOCl(src->buffer, src_offset, NOUVEAU_BO_VRAM | - NOUVEAU_BO_GART | NOUVEAU_BO_RD); - OUT_RELOCl(dst->buffer, dst_offset, NOUVEAU_BO_VRAM | - NOUVEAU_BO_GART | NOUVEAU_BO_WR); - OUT_RING (src->pitch * src->cpp); - OUT_RING (dst->pitch * dst->cpp); - OUT_RING (line_len); - OUT_RING (count); - OUT_RING (0x0101); - OUT_RING (0); - - height -= count; - src_offset += src->pitch * count; - dst_offset += dst->pitch * count; - } - - nouveau_notifier_reset(nv->sync_notifier, 0); - BEGIN_RING(NvM2MF, 0x104, 1); - OUT_RING (0); - BEGIN_RING(NvM2MF, 0x100, 1); - OUT_RING (0); - FIRE_RING(); - nouveau_notifier_wait_status(nv->sync_notifier, 0, 0, 2000); - - return 0; -} - -static int -nv04_region_copy(struct nouveau_context *nv, struct pipe_region *dst, - unsigned dst_offset, unsigned dx, unsigned dy, - struct pipe_region *src, unsigned src_offset, - unsigned sx, unsigned sy, unsigned w, unsigned h) -{ - int format; - - if (src->cpp != dst->cpp) - return 1; - - /* NV_CONTEXT_SURFACES_2D has buffer alignment restrictions, fallback - * to NV_MEMORY_TO_MEMORY_FORMAT in this case. - */ - if ((src_offset & 63) || (dst_offset & 63)) { - dst_offset += (dy * dst->pitch + dx) * dst->cpp; - src_offset += (sy * src->pitch + sx) * src->cpp; - return nv04_region_copy_m2mf(nv, dst, dst_offset, src, - src_offset, w * src->cpp, h); - - } - - if ((format = nv04_surface_format(dst->cpp)) < 0) { - NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp); - return 1; - } - - BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); - OUT_RELOCo(src->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); - OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); - BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_FORMAT, 4); - OUT_RING (format); - OUT_RING (((dst->pitch * dst->cpp) << 16) | (src->pitch * src->cpp)); - OUT_RELOCl(src->buffer, src_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); - OUT_RELOCl(dst->buffer, dst_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); - - BEGIN_RING(NvImageBlit, 0x0300, 3); - OUT_RING ((sy << 16) | sx); - OUT_RING ((dy << 16) | dx); - OUT_RING (( h << 16) | w); - - nouveau_notifier_reset(nv->sync_notifier, 0); - BEGIN_RING(NvGdiRect, 0x104, 1); - OUT_RING (0); - BEGIN_RING(NvGdiRect, 0x100, 1); - OUT_RING (0); - FIRE_RING(); - nouveau_notifier_wait_status(nv->sync_notifier, 0, 0, 2000); - - return 0; -} - -static int -nv04_region_fill(struct nouveau_context *nv, - struct pipe_region *dst, unsigned dst_offset, - unsigned dx, unsigned dy, unsigned w, unsigned h, - unsigned value) -{ - int cs2d_format, gdirect_format; - - if ((cs2d_format = nv04_surface_format(dst->cpp)) < 0) { - NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp); - return 1; - } - - if ((gdirect_format = nv04_rect_format(dst->cpp)) < 0) { - NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp); - return 1; - } - - BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); - OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); - OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); - BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_FORMAT, 4); - OUT_RING (cs2d_format); - OUT_RING (((dst->pitch * dst->cpp) << 16) | (dst->pitch * dst->cpp)); - OUT_RELOCl(dst->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); - OUT_RELOCl(dst->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); - - BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT, 1); - OUT_RING (gdirect_format); - BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_COLOR1_A, 1); - OUT_RING (value); - BEGIN_RING(NvGdiRect, - NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT(0), 2); - OUT_RING ((dx << 16) | dy); - OUT_RING (( w << 16) | h); - - nouveau_notifier_reset(nv->sync_notifier, 0); - BEGIN_RING(NvGdiRect, 0x104, 1); - OUT_RING (0); - BEGIN_RING(NvGdiRect, 0x100, 1); - OUT_RING (0); - FIRE_RING(); - nouveau_notifier_wait_status(nv->sync_notifier, 0, 0, 2000); - - return 0; -} - -static int -nv04_region_data(struct nouveau_context *nv, struct pipe_region *dst, - unsigned dst_offset, unsigned dx, unsigned dy, - const void *src, unsigned src_pitch, - unsigned sx, unsigned sy, unsigned w, unsigned h) -{ - NOUVEAU_ERR("unimplemented!!\n"); - return 0; -} - -int -nouveau_region_init_nv04(struct nouveau_context *nv) -{ - unsigned class; - int ret; - - if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, 0x39, - &nv->NvM2MF))) { - NOUVEAU_ERR("Error creating m2mf object: %d\n", ret); - return 1; - } - BEGIN_RING(NvM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 1); - OUT_RING (nv->sync_notifier->handle); - - class = nv->chipset < 0x10 ? NV04_CONTEXT_SURFACES_2D : - NV10_CONTEXT_SURFACES_2D; - if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, class, - &nv->NvCtxSurf2D))) { - NOUVEAU_ERR("Error creating 2D surface object: %d\n", ret); - return 1; - } - BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); - OUT_RING (nv->channel->vram->handle); - OUT_RING (nv->channel->vram->handle); - - class = nv->chipset < 0x10 ? NV_IMAGE_BLIT : - NV12_IMAGE_BLIT; - if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, class, - &nv->NvImageBlit))) { - NOUVEAU_ERR("Error creating blit object: %d\n", ret); - return 1; - } - BEGIN_RING(NvImageBlit, NV_IMAGE_BLIT_DMA_NOTIFY, 1); - OUT_RING (nv->sync_notifier->handle); - BEGIN_RING(NvImageBlit, NV_IMAGE_BLIT_SURFACE, 1); - OUT_RING (nv->NvCtxSurf2D->handle); - BEGIN_RING(NvImageBlit, NV_IMAGE_BLIT_OPERATION, 1); - OUT_RING (NV_IMAGE_BLIT_OPERATION_SRCCOPY); - - class = NV04_GDI_RECTANGLE_TEXT; - if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, class, - &nv->NvGdiRect))) { - NOUVEAU_ERR("Error creating rect object: %d\n", ret); - return 1; - } - BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_DMA_NOTIFY, 1); - OUT_RING (nv->sync_notifier->handle); - BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_SURFACE, 1); - OUT_RING (nv->NvCtxSurf2D->handle); - BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_OPERATION, 1); - OUT_RING (NV04_GDI_RECTANGLE_TEXT_OPERATION_SRCCOPY); - BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT, 1); - OUT_RING (NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_LE); - - nv->region_display = nv04_region_display; - nv->region_copy = nv04_region_copy; - nv->region_fill = nv04_region_fill; - nv->region_data = nv04_region_data; - return 0; -} - diff --git a/src/mesa/drivers/dri/nouveau_winsys/nv04_surface.c b/src/mesa/drivers/dri/nouveau_winsys/nv04_surface.c new file mode 100644 index 00000000000..67e2514026b --- /dev/null +++ b/src/mesa/drivers/dri/nouveau_winsys/nv04_surface.c @@ -0,0 +1,231 @@ +#include "pipe/p_context.h" + +#include "nouveau_context.h" + +static INLINE int +nv04_surface_format(int cpp) +{ + switch (cpp) { + case 1: return NV04_CONTEXT_SURFACES_2D_FORMAT_Y8; + case 2: return NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5; + case 4: return NV04_CONTEXT_SURFACES_2D_FORMAT_Y32; + default: + return -1; + } +} + +static INLINE int +nv04_rect_format(int cpp) +{ + switch (cpp) { + case 1: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; + case 2: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A16R5G6B5; + case 4: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; + default: + return -1; + } +} + +static void +nv04_surface_copy_m2mf(struct nouveau_context *nv, unsigned dx, unsigned dy, + unsigned sx, unsigned sy, unsigned w, unsigned h) +{ + struct pipe_surface *dst = nv->surf_dst; + struct pipe_surface *src = nv->surf_dst; + unsigned dst_offset, src_offset; + + dst_offset = dst->offset + (dy * dst->pitch + dx) * dst->cpp; + src_offset = src->offset + (sy * src->pitch + sx) * src->cpp; + + while (h) { + int count = (h > 2047) ? 2047 : h; + + BEGIN_RING(NvM2MF, NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); + OUT_RELOCl(src->buffer, src_offset, NOUVEAU_BO_VRAM | + NOUVEAU_BO_GART | NOUVEAU_BO_RD); + OUT_RELOCl(dst->buffer, dst_offset, NOUVEAU_BO_VRAM | + NOUVEAU_BO_GART | NOUVEAU_BO_WR); + OUT_RING (src->pitch * src->cpp); + OUT_RING (dst->pitch * dst->cpp); + OUT_RING (w * src->cpp); + OUT_RING (count); + OUT_RING (0x0101); + OUT_RING (0); + + h -= count; + src_offset += src->pitch * count; + dst_offset += dst->pitch * count; + } +} + +static void +nv04_surface_copy_blit(struct nouveau_context *nv, unsigned dx, unsigned dy, + unsigned sx, unsigned sy, unsigned w, unsigned h) +{ + BEGIN_RING(NvImageBlit, 0x0300, 3); + OUT_RING ((sy << 16) | sx); + OUT_RING ((dy << 16) | dx); + OUT_RING (( h << 16) | w); +} + +static int +nv04_surface_copy_prep(struct nouveau_context *nv, struct pipe_surface *dst, + struct pipe_surface *src) +{ + int format; + + if (src->cpp != dst->cpp) + return 1; + + /* NV_CONTEXT_SURFACES_2D has buffer alignment restrictions, fallback + * to NV_MEMORY_TO_MEMORY_FORMAT in this case. + */ + if ((src->offset & 63) || (dst->offset & 63)) { + BEGIN_RING(NvM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_IN, 2); + OUT_RELOCo(src->buffer, NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | + NOUVEAU_BO_RD); + OUT_RELOCo(dst->buffer, NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | + NOUVEAU_BO_WR); + + nv->surface_copy = nv04_surface_copy_m2mf; + nv->surf_dst = dst; + nv->surf_src = src; + return 0; + + } + + if ((format = nv04_surface_format(dst->cpp)) < 0) { + NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp); + return 1; + } + nv->surface_copy = nv04_surface_copy_blit; + + BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); + OUT_RELOCo(src->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + + BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_FORMAT, 4); + OUT_RING (format); + OUT_RING (((dst->pitch * dst->cpp) << 16) | (src->pitch * src->cpp)); + OUT_RELOCl(src->buffer, src->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCl(dst->buffer, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + + return 0; +} + +static void +nv04_surface_copy_done(struct nouveau_context *nv) +{ + FIRE_RING(); +} + +static int +nv04_surface_fill(struct nouveau_context *nv, struct pipe_surface *dst, + unsigned dx, unsigned dy, unsigned w, unsigned h, + unsigned value) +{ + int cs2d_format, gdirect_format; + + if ((cs2d_format = nv04_surface_format(dst->cpp)) < 0) { + NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp); + return 1; + } + + if ((gdirect_format = nv04_rect_format(dst->cpp)) < 0) { + NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp); + return 1; + } + + BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); + OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_FORMAT, 4); + OUT_RING (cs2d_format); + OUT_RING (((dst->pitch * dst->cpp) << 16) | (dst->pitch * dst->cpp)); + OUT_RELOCl(dst->buffer, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(dst->buffer, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + + BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT, 1); + OUT_RING (gdirect_format); + BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_COLOR1_A, 1); + OUT_RING (value); + BEGIN_RING(NvGdiRect, + NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT(0), 2); + OUT_RING ((dx << 16) | dy); + OUT_RING (( w << 16) | h); + + FIRE_RING(); + return 0; +} + +static int +nv04_surface_data(struct nouveau_context *nv, struct pipe_surface *dst, + unsigned dx, unsigned dy, const void *src, unsigned src_pitch, + unsigned sx, unsigned sy, unsigned w, unsigned h) +{ + NOUVEAU_ERR("unimplemented!!\n"); + return 0; +} + +int +nouveau_surface_init_nv04(struct nouveau_context *nv) +{ + unsigned class; + int ret; + + if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, 0x39, + &nv->NvM2MF))) { + NOUVEAU_ERR("Error creating m2mf object: %d\n", ret); + return 1; + } + BEGIN_RING(NvM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 1); + OUT_RING (nv->sync_notifier->handle); + + class = nv->chipset < 0x10 ? NV04_CONTEXT_SURFACES_2D : + NV10_CONTEXT_SURFACES_2D; + if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, class, + &nv->NvCtxSurf2D))) { + NOUVEAU_ERR("Error creating 2D surface object: %d\n", ret); + return 1; + } + BEGIN_RING(NvCtxSurf2D, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); + OUT_RING (nv->channel->vram->handle); + OUT_RING (nv->channel->vram->handle); + + class = nv->chipset < 0x10 ? NV_IMAGE_BLIT : + NV12_IMAGE_BLIT; + if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, class, + &nv->NvImageBlit))) { + NOUVEAU_ERR("Error creating blit object: %d\n", ret); + return 1; + } + BEGIN_RING(NvImageBlit, NV_IMAGE_BLIT_DMA_NOTIFY, 1); + OUT_RING (nv->sync_notifier->handle); + BEGIN_RING(NvImageBlit, NV_IMAGE_BLIT_SURFACE, 1); + OUT_RING (nv->NvCtxSurf2D->handle); + BEGIN_RING(NvImageBlit, NV_IMAGE_BLIT_OPERATION, 1); + OUT_RING (NV_IMAGE_BLIT_OPERATION_SRCCOPY); + + class = NV04_GDI_RECTANGLE_TEXT; + if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, class, + &nv->NvGdiRect))) { + NOUVEAU_ERR("Error creating rect object: %d\n", ret); + return 1; + } + BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_DMA_NOTIFY, 1); + OUT_RING (nv->sync_notifier->handle); + BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_SURFACE, 1); + OUT_RING (nv->NvCtxSurf2D->handle); + BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_OPERATION, 1); + OUT_RING (NV04_GDI_RECTANGLE_TEXT_OPERATION_SRCCOPY); + BEGIN_RING(NvGdiRect, NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT, 1); + OUT_RING (NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_LE); + + nv->surface_copy_prep = nv04_surface_copy_prep; + nv->surface_copy = nv04_surface_copy_blit; + nv->surface_copy_done = nv04_surface_copy_done; + nv->surface_fill = nv04_surface_fill; + nv->surface_data = nv04_surface_data; + return 0; +} + diff --git a/src/mesa/drivers/dri/nouveau_winsys/nv50_region.c b/src/mesa/drivers/dri/nouveau_winsys/nv50_region.c deleted file mode 100644 index c7450c5c8d0..00000000000 --- a/src/mesa/drivers/dri/nouveau_winsys/nv50_region.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "pipe/p_context.h" - -#include "nouveau_context.h" - -static int -nv50_region_display(void) -{ - NOUVEAU_ERR("unimplemented\n"); - return 0; -} - -static int -nv50_region_copy(struct nouveau_context *nv, struct pipe_region *dst, - unsigned dst_offset, unsigned dx, unsigned dy, - struct pipe_region *src, unsigned src_offset, - unsigned sx, unsigned sy, unsigned w, unsigned h) -{ - NOUVEAU_ERR("unimplemented!!\n"); - return 0; -} - -static int -nv50_region_fill(struct nouveau_context *nv, - struct pipe_region *dst, unsigned dst_offset, - unsigned dx, unsigned dy, unsigned w, unsigned h, - unsigned value) -{ - NOUVEAU_ERR("unimplemented!!\n"); - return 0; -} - -static int -nv50_region_data(struct nouveau_context *nv, struct pipe_region *dst, - unsigned dst_offset, unsigned dx, unsigned dy, - const void *src, unsigned src_pitch, - unsigned sx, unsigned sy, unsigned w, unsigned h) -{ - NOUVEAU_ERR("unimplemented!!\n"); - return 0; -} - -int -nouveau_region_init_nv50(struct nouveau_context *nv) -{ - nv->region_display = nv50_region_display; - nv->region_copy = nv50_region_copy; - nv->region_fill = nv50_region_fill; - nv->region_data = nv50_region_data; - return 0; -} - diff --git a/src/mesa/drivers/dri/nouveau_winsys/nv50_surface.c b/src/mesa/drivers/dri/nouveau_winsys/nv50_surface.c new file mode 100644 index 00000000000..2a95b1fcd36 --- /dev/null +++ b/src/mesa/drivers/dri/nouveau_winsys/nv50_surface.c @@ -0,0 +1,170 @@ +#include "pipe/p_context.h" + +#include "nouveau_context.h" + +static INLINE int +nv50_format(int cpp) +{ + switch (cpp) { + case 4: return NV50_2D_DST_FORMAT_32BPP; + case 3: return NV50_2D_DST_FORMAT_24BPP; + case 2: return NV50_2D_DST_FORMAT_16BPP; + case 1: return NV50_2D_DST_FORMAT_8BPP; + default: + return -1; + } +} + +static int +nv50_surface_copy_prep(struct nouveau_context *nv, + struct pipe_surface *dst, struct pipe_surface *src) +{ + int surf_format; + + assert(src->cpp == dst->cpp); + + surf_format = nv50_format(dst->cpp); + assert(surf_format >= 0); + + BEGIN_RING(Nv2D, NV50_2D_DMA_IN_MEMORY0, 2); + OUT_RELOCo(src->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + + BEGIN_RING(Nv2D, NV50_2D_DST_FORMAT, 2); + OUT_RING (surf_format); + OUT_RING (1); + BEGIN_RING(Nv2D, NV50_2D_DST_PITCH, 5); + OUT_RING (dst->pitch * dst->cpp); + OUT_RING (dst->pitch); + OUT_RING (dst->height); + OUT_RELOCh(dst->buffer, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(dst->buffer, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + BEGIN_RING(Nv2D, NV50_2D_CLIP_X, 4); + OUT_RING (0); + OUT_RING (0); + OUT_RING (dst->pitch); + OUT_RING (dst->height); + + BEGIN_RING(Nv2D, NV50_2D_SRC_FORMAT, 2); + OUT_RING (surf_format); + OUT_RING (1); + BEGIN_RING(Nv2D, NV50_2D_SRC_PITCH, 5); + OUT_RING (src->pitch * src->cpp); + OUT_RING (src->pitch); + OUT_RING (src->height); + OUT_RELOCh(src->buffer, src->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCl(src->buffer, src->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + + return 0; +} + +static void +nv50_surface_copy(struct nouveau_context *nv, unsigned dx, unsigned dy, + unsigned sx, unsigned sy, unsigned w, unsigned h) +{ + BEGIN_RING(Nv2D, 0x0110, 1); + OUT_RING (0); + BEGIN_RING(Nv2D, NV50_2D_BLIT_DST_X, 12); + OUT_RING (dx); + OUT_RING (dy); + OUT_RING (w); + OUT_RING (h); + OUT_RING (0); + OUT_RING (1); + OUT_RING (0); + OUT_RING (1); + OUT_RING (0); + OUT_RING (sx); + OUT_RING (0); + OUT_RING (sy); +} + +static void +nv50_surface_copy_done(struct nouveau_context *nv) +{ + FIRE_RING(); +} + +static int +nv50_surface_fill(struct nouveau_context *nv, struct pipe_surface *dst, + unsigned dx, unsigned dy, unsigned w, unsigned h, + unsigned value) +{ + int surf_format, rect_format; + + surf_format = nv50_format(dst->cpp); + if (surf_format < 0) + return 1; + + rect_format = nv50_format(dst->cpp); + if (rect_format < 0) + return 1; + + BEGIN_RING(Nv2D, NV50_2D_DMA_IN_MEMORY1, 1); + OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + BEGIN_RING(Nv2D, NV50_2D_DST_FORMAT, 2); + OUT_RING (surf_format); + OUT_RING (1); + BEGIN_RING(Nv2D, NV50_2D_DST_PITCH, 5); + OUT_RING (dst->pitch * dst->cpp); + OUT_RING (dst->pitch); + OUT_RING (dst->height); + OUT_RELOCh(dst->buffer, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(dst->buffer, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + BEGIN_RING(Nv2D, NV50_2D_CLIP_X, 4); + OUT_RING (0); + OUT_RING (0); + OUT_RING (dst->pitch); + OUT_RING (dst->height); + + BEGIN_RING(Nv2D, 0x0580, 3); + OUT_RING (4); + OUT_RING (rect_format); + OUT_RING (value); + + BEGIN_RING(Nv2D, NV50_2D_RECT_X1, 4); + OUT_RING (dx); + OUT_RING (dy); + OUT_RING (dx + w); + OUT_RING (dy + h); + + FIRE_RING(); + + return 0; +} + +static int +nv50_surface_data(struct nouveau_context *nv, struct pipe_surface *dst, + unsigned dx, unsigned dy, const void *src, unsigned src_pitch, + unsigned sx, unsigned sy, unsigned w, unsigned h) +{ + NOUVEAU_ERR("unimplemented!!\n"); + return 0; +} + +int +nouveau_surface_init_nv50(struct nouveau_context *nv) +{ + int ret; + + ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, NV50_2D, + &nv->Nv2D); + if (ret) + return ret; + + BEGIN_RING(Nv2D, NV50_2D_DMA_NOTIFY, 1); + OUT_RING (nv->sync_notifier->handle); + BEGIN_RING(Nv2D, NV50_2D_DMA_IN_MEMORY0, 2); + OUT_RING (nv->channel->vram->handle); + OUT_RING (nv->channel->vram->handle); + BEGIN_RING(Nv2D, NV50_2D_OPERATION, 1); + OUT_RING (NV50_2D_OPERATION_SRCCOPY); + + nv->surface_copy_prep = nv50_surface_copy_prep; + nv->surface_copy = nv50_surface_copy; + nv->surface_copy_done = nv50_surface_copy_done; + nv->surface_fill = nv50_surface_fill; + nv->surface_data = nv50_surface_data; + return 0; +} + diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 3b5151ed171..30be65525e0 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.1 + * Version: 7.1 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 Brian Paul 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"), @@ -1443,7 +1443,6 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS) (baseInternalFormat == GL_RGBA || baseInternalFormat == GL_RGB) && srcType == GL_UNSIGNED_BYTE) { - int img, row, col; for (img = 0; img < srcDepth; img++) { const GLint srcRowStride = _mesa_image_row_stride(srcPacking, @@ -1455,11 +1454,12 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS) + dstYoffset * dstRowStride + dstXoffset * dstFormat->TexelBytes; for (row = 0; row < srcHeight; row++) { + GLuint *d4 = (GLuint *) dstRow; for (col = 0; col < srcWidth; col++) { - dstRow[col * 4 + 0] = srcRow[col * 3 + BCOMP]; - dstRow[col * 4 + 1] = srcRow[col * 3 + GCOMP]; - dstRow[col * 4 + 2] = srcRow[col * 3 + RCOMP]; - dstRow[col * 4 + 3] = 0xff; + d4[col] = ((0xff << 24) | + (srcRow[col * 3 + RCOMP] << 16) | + (srcRow[col * 3 + GCOMP] << 8) | + (srcRow[col * 3 + BCOMP] << 0)); } dstRow += dstRowStride; srcRow += srcRowStride; @@ -1471,7 +1471,9 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS) dstFormat == &_mesa_texformat_argb8888 && srcFormat == GL_RGBA && baseInternalFormat == GL_RGBA && - (srcType == GL_UNSIGNED_BYTE && littleEndian)) { + srcType == GL_UNSIGNED_BYTE && + littleEndian) { + /* same as above case, but src data has alpha too */ GLint img, row, col; /* For some reason, streaming copies to write-combined regions * are extremely sensitive to the characteristics of how the @@ -1488,13 +1490,13 @@ _mesa_texstore_argb8888(TEXSTORE_PARAMS) + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes + dstYoffset * dstRowStride + dstXoffset * dstFormat->TexelBytes; - for (row = 0; row < srcHeight; row++) { + GLuint *d4 = (GLuint *) dstRow; for (col = 0; col < srcWidth; col++) { - *(GLuint *)(dstRow + col * 4) = (srcRow[col * 4 + RCOMP] << 16 | - srcRow[col * 4 + GCOMP] << 8 | - srcRow[col * 4 + BCOMP] << 0 | - srcRow[col * 4 + ACOMP] << 24); + d4[col] = ((srcRow[col * 4 + ACOMP] << 24) | + (srcRow[col * 4 + RCOMP] << 16) | + (srcRow[col * 4 + GCOMP] << 8) | + (srcRow[col * 4 + BCOMP] << 0)); } dstRow += dstRowStride; srcRow += srcRowStride; diff --git a/src/mesa/pipe/Makefile b/src/mesa/pipe/Makefile index 135f1fd19d7..5099b65885e 100644 --- a/src/mesa/pipe/Makefile +++ b/src/mesa/pipe/Makefile @@ -1,8 +1,25 @@ -default: - cd softpipe ; make - cd i915simple ; make - cd failover ; make - cd nv40; make + +TOP = ../../.. +include $(TOP)/configs/current + + +ifeq ($(CONFIG_NAME), linux-cell) +CELL_DIR = cell +endif + +SUBDIRS = softpipe i915simple nv40 nv50 failover $(CELL_DIR) + + +default: subdirs + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + fi \ + done + clean: rm -f `find . -name \*.[oa]` diff --git a/src/mesa/pipe/cell/Makefile b/src/mesa/pipe/cell/Makefile new file mode 100644 index 00000000000..47aef7b05f6 --- /dev/null +++ b/src/mesa/pipe/cell/Makefile @@ -0,0 +1,12 @@ +# Cell Gallium driver Makefile + + +default: + ( cd spu ; make ) + ( cd ppu ; make ) + + + +clean: + ( cd spu ; make clean ) + ( cd ppu ; make clean ) diff --git a/src/mesa/pipe/cell/common.h b/src/mesa/pipe/cell/common.h new file mode 100644 index 00000000000..c4bad4194a1 --- /dev/null +++ b/src/mesa/pipe/cell/common.h @@ -0,0 +1,13 @@ + +#ifndef CELL_COMMON_H +#define CELL_COMMON_H + + +struct init_info +{ + int foo; + int bar; +}; + + +#endif /* CELL_COMMON_H */ diff --git a/src/mesa/pipe/cell/ppu/Makefile b/src/mesa/pipe/cell/ppu/Makefile new file mode 100644 index 00000000000..c987d54e02f --- /dev/null +++ b/src/mesa/pipe/cell/ppu/Makefile @@ -0,0 +1,57 @@ +# Gallium3D Cell driver: PPU code + +# This makefile builds the g3dcell.a library which gets pulled into +# the main libGL.so library + + +TOP = ../../../../.. +include $(TOP)/configs/linux-cell + + +#PROG = gl4 + +CELL_LIB = libcell.a + +SPU_CODE_MODULE = ../spu/g3d_spu.a + + +SOURCES = \ + cell_context.c \ + cell_surface.c + +OBJECTS = $(SOURCES:.c=.o) \ + +INCLUDE_DIRS = -I$(TOP)/src/mesa + + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + + +default: $(CELL_LIB) + + +$(CELL_LIB): $(OBJECTS) $(SPU_CODE_MODULE) +# ar -ru $(CELL_LIB) $(OBJECTS) $(SPU_CODE_MODULE) + ar -ru $(CELL_LIB) $(OBJECTS) + +#$(PROG): $(PPU_OBJECTS) +# $(CC) -o $(PROG) $(PPU_OBJECTS) $(SPU_CODE_MODULE) $(PPU_LFLAGS) + + + +clean: + rm -f *.o $(CELL_LIB) + + + +depend: $(SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDE_DIRS) $(SOURCES) 2> /dev/null + +include depend + + + diff --git a/src/mesa/pipe/cell/ppu/cell_context.c b/src/mesa/pipe/cell/ppu/cell_context.c new file mode 100644 index 00000000000..a8f6cba2fa9 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_context.c @@ -0,0 +1,76 @@ +/************************************************************************** + * + * 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 +#include +#include +#include "pipe/cell/ppu/cell_context.h" +#include "pipe/cell/common.h" + +#define NUM_SPUS 6 + + +extern spe_program_handle_t g3d_spu; + +static speid_t speid[NUM_SPUS]; +static struct init_info inits[NUM_SPUS]; + + +static void +start_spus(void) +{ + int i; + + for (i = 0; i < NUM_SPUS; i++) { + inits[i].foo = i; + inits[i].bar = i * 10; + + speid[i] = spe_create_thread(0, /* gid */ + &g3d_spu, /* spe program handle */ + &inits[i], /* argp */ + NULL, /* envp */ + -1, /* mask */ + 0 ); /* flags */ + } +} + + + +void cell_create_context(void) +{ + printf("cell_create_context\n"); + + start_spus(); + + /* TODO: do something with the SPUs! */ +} diff --git a/src/mesa/pipe/cell/ppu/cell_context.h b/src/mesa/pipe/cell/ppu/cell_context.h new file mode 100644 index 00000000000..b4d93d14141 --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_context.h @@ -0,0 +1,46 @@ +/************************************************************************** + * + * 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_CONTEXT_H +#define CELL_CONTEXT_H + + +#include "pipe/p_context.h" + + + +struct cell_context +{ + struct pipe_context pipe; + + int spu_info; +}; + + + +#endif /* CELL_CONTEXT_H */ diff --git a/src/mesa/pipe/cell/ppu/cell_surface.c b/src/mesa/pipe/cell/ppu/cell_surface.c new file mode 100644 index 00000000000..2c4b6e640bd --- /dev/null +++ b/src/mesa/pipe/cell/ppu/cell_surface.c @@ -0,0 +1,9 @@ + +#include + + +void cell_create_surface(void) +{ + printf("cell_create_surface\n"); + +} diff --git a/src/mesa/pipe/cell/spu/Makefile b/src/mesa/pipe/cell/spu/Makefile new file mode 100644 index 00000000000..700a6c61cdc --- /dev/null +++ b/src/mesa/pipe/cell/spu/Makefile @@ -0,0 +1,58 @@ +# Gallium3D Cell driver: SPU code + +# This makefile builds the g3d_spu.a file that's linked into the +# PPU code/library. + + +TOP = ../../../../.. +include $(TOP)/configs/linux-cell + + +PROG = g3d + +PROG_SPU = $(PROG)_spu +PROG_SPU_A = $(PROG)_spu.a +PROG_SPU_EMBED_O = $(PROG)_spu-embed.o + + +SOURCES = \ + main.c \ + tri.c + +SPU_OBJECTS = $(SOURCES:.c=.o) \ + +INCLUDE_DIRS = -I$(TOP)/src/mesa + + +# The .a file will be linked into the main/PPU executable +default: $(PROG_SPU_A) + +$(PROG_SPU_A): $(PROG_SPU_EMBED_O) + $(SPU_AR) $(SPU_AR_FLAGS) $(PROG_SPU_A) $(PROG_SPU_EMBED_O) + +$(PROG_SPU_EMBED_O): $(PROG_SPU) + $(SPU_EMBED) $(SPU_EMBED_FLAGS) $(PROG_SPU) $(PROG_SPU) $(PROG_SPU_EMBED_O) + +$(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) + + + +depend: $(SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDE_DIRS) $(SOURCES) 2> /dev/null + +include depend + diff --git a/src/mesa/pipe/cell/spu/main.c b/src/mesa/pipe/cell/spu/main.c new file mode 100644 index 00000000000..e8d5fdccbf7 --- /dev/null +++ b/src/mesa/pipe/cell/spu/main.c @@ -0,0 +1,29 @@ +/* main.c for cell SPU code */ + + +#include +#include +#include + +#include "tri.h" +#include "pipe/cell/common.h" + + +static struct init_info init; + + +int +main(unsigned long long speid, + unsigned long long argp, + unsigned long long envp) +{ + int tag = 0; + + mfc_get(&init, (unsigned int) argp, sizeof(struct init_info), tag, 0, 0); + + printf("Enter spu main(): init.foo=%d\n", init.foo); + + draw_triangle(0, 1, 2); + + return 0; +} diff --git a/src/mesa/pipe/cell/spu/tri.c b/src/mesa/pipe/cell/spu/tri.c new file mode 100644 index 00000000000..949c3b4c8e5 --- /dev/null +++ b/src/mesa/pipe/cell/spu/tri.c @@ -0,0 +1,9 @@ + +#include "tri.h" + +void +draw_triangle(int v1, int v2, int v3) +{ + + +} diff --git a/src/mesa/pipe/cell/spu/tri.h b/src/mesa/pipe/cell/spu/tri.h new file mode 100644 index 00000000000..6a915de60d5 --- /dev/null +++ b/src/mesa/pipe/cell/spu/tri.h @@ -0,0 +1,4 @@ + + +extern void +draw_triangle(int v1, int v2, int v3); diff --git a/src/mesa/pipe/draw/draw_clip.c b/src/mesa/pipe/draw/draw_clip.c index bc62d422a42..e4c257a0ee2 100644 --- a/src/mesa/pipe/draw/draw_clip.c +++ b/src/mesa/pipe/draw/draw_clip.c @@ -128,12 +128,8 @@ static void interp( const struct clipper *clip, /* Other attributes * Note: start at 1 to skip winpos (data[0]) since we just computed * it above. - * Subtract two from nr_attrs since the first two attribs (always - * VF_ATTRIB_VERTEX_HEADER and VF_ATTRIB_CLIP_POS, see - * draw_set_vertex_attributes()) are in the vertex_header struct, - * not in the data[] array. */ - for (j = 1; j < nr_attrs - 2; j++) { + for (j = 1; j < nr_attrs; j++) { interp_attr(dst->data[j], t, in->data[j], out->data[j]); } } @@ -352,12 +348,8 @@ do_clip_line( struct draw_stage *stage, static void clip_begin( struct draw_stage *stage ) { - /* sanity checks. If these fail, review the clip/interp code! */ - assert(stage->draw->vertex_info.num_attribs >= 3); -#if 0 - assert(stage->draw->vertex_info.slot_to_attrib[0] == TGSI_ATTRIB_VERTEX_HEADER); - assert(stage->draw->vertex_info.slot_to_attrib[1] == TGSI_ATTRIB_CLIP_POS); -#endif + /* should always have position, at least */ + assert(stage->draw->vertex_info.num_attribs >= 1); stage->next->begin( stage->next ); } diff --git a/src/mesa/pipe/draw/draw_flatshade.c b/src/mesa/pipe/draw/draw_flatshade.c index 3b22c01b34e..d46e53f2be2 100644 --- a/src/mesa/pipe/draw/draw_flatshade.c +++ b/src/mesa/pipe/draw/draw_flatshade.c @@ -60,8 +60,9 @@ static INLINE void copy_colors( struct draw_stage *stage, uint i; /* Look for constant/flat attribs and duplicate from src to dst vertex */ - for (i = 1; i < num_attribs - 2; i++) { - if (interp[i + 2] == INTERP_CONSTANT) { + /* skip attrib[0] which is vert pos */ + for (i = 1; i < num_attribs; i++) { + if (interp[i] == INTERP_CONSTANT) { copy_attr( i, dst, src ); } } diff --git a/src/mesa/pipe/draw/draw_prim.c b/src/mesa/pipe/draw/draw_prim.c index e4a65b9f243..f8fc23b5101 100644 --- a/src/mesa/pipe/draw/draw_prim.c +++ b/src/mesa/pipe/draw/draw_prim.c @@ -61,7 +61,7 @@ static void draw_prim_queue_flush( struct draw_context *draw ) unsigned i; if (0) - printf("Flushing with %d prims, %d verts\n", + fprintf(stdout,"Flushing with %d prims, %d verts\n", draw->pq.queue_nr, draw->vs.queue_nr); /* Make sure all vertices are available/shaded: diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h index 09acf69623b..53d74511131 100644 --- a/src/mesa/pipe/draw/draw_private.h +++ b/src/mesa/pipe/draw/draw_private.h @@ -47,7 +47,7 @@ #include "draw_vertex.h" #include "x86/rtasm/x86sse.h" -#include "pipe/tgsi/exec/tgsi_core.h" +#include "pipe/tgsi/exec/tgsi_exec.h" struct gallivm_prog; diff --git a/src/mesa/pipe/draw/draw_vbuf.c b/src/mesa/pipe/draw/draw_vbuf.c new file mode 100644 index 00000000000..d00cdec56c6 --- /dev/null +++ b/src/mesa/pipe/draw/draw_vbuf.c @@ -0,0 +1,399 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * \file + * Vertex buffer drawing stage. + * + * \author José Fonseca + * \author Keith Whitwell + */ + + +#include + +#include "pipe/draw/draw_vbuf.h" +#include "pipe/draw/draw_private.h" +#include "pipe/draw/draw_vertex.h" +#include "pipe/p_util.h" + + +/** + * Vertex buffer emit stage. + */ +struct vbuf_stage { + struct draw_stage stage; /**< This must be first (base class) */ + + struct vbuf_render *render; + + /** Vertex size in bytes */ + unsigned vertex_size; + + /* FIXME: we have no guarantee that 'unsigned' is 32bit */ + + /** Vertices in hardware format */ + unsigned *vertices; + unsigned *vertex_ptr; + unsigned max_vertices; + unsigned nr_vertices; + + /** Indices */ + ushort *indices; + unsigned max_indices; + unsigned nr_indices; + + /** Pipe primitive */ + unsigned prim; +}; + + +/** + * Basically a cast wrapper. + */ +static INLINE struct vbuf_stage * +vbuf_stage( struct draw_stage *stage ) +{ + assert(stage); + return (struct vbuf_stage *)stage; +} + + +static void vbuf_flush_indices( struct draw_stage *stage ); +static void vbuf_flush_vertices( struct draw_stage *stage, + unsigned new_vertex_size ); + + +static INLINE boolean +overflow( void *map, void *ptr, unsigned bytes, unsigned bufsz ) +{ + unsigned long used = (unsigned long) ((char *)ptr - (char *)map); + return (used + bytes) > bufsz; +} + + +static INLINE void +check_space( struct vbuf_stage *vbuf, unsigned nr ) +{ + if (vbuf->nr_vertices + nr > vbuf->max_vertices ) + vbuf_flush_vertices(&vbuf->stage, vbuf->vertex_size ); + + if (vbuf->nr_indices + nr > vbuf->max_indices ) + vbuf_flush_indices(&vbuf->stage); +} + + +/** + * Extract the needed fields from vertex_header and emit i915 dwords. + * Recall that the vertices are constructed by the 'draw' module and + * have a couple of slots at the beginning (1-dword header, 4-dword + * clip pos) that we ignore here. + */ +static INLINE void +emit_vertex( struct vbuf_stage *vbuf, + struct vertex_header *vertex ) +{ + const struct vertex_info *vinfo = vbuf->render->get_vertex_info(vbuf->render); + + uint i; + uint count = 0; /* for debug/sanity */ + +// fprintf(stderr, "emit vertex %d to %p\n", +// vbuf->nr_vertices, vbuf->vertex_ptr); + + if(vertex->vertex_id != UNDEFINED_VERTEX_ID) { + if(vertex->vertex_id < vbuf->nr_vertices) + return; + else + fprintf(stderr, "Bad vertex id 0x%04x (>= 0x%04x)\n", + vertex->vertex_id, vbuf->nr_vertices); + return; + } + + vertex->vertex_id = vbuf->nr_vertices++; + + for (i = 0; i < vinfo->num_attribs; i++) { + switch (vinfo->format[i]) { + case FORMAT_OMIT: + /* no-op */ + break; + case FORMAT_1F: + *vbuf->vertex_ptr++ = fui(vertex->data[i][0]); + count++; + break; + case FORMAT_2F: + *vbuf->vertex_ptr++ = fui(vertex->data[i][0]); + *vbuf->vertex_ptr++ = fui(vertex->data[i][1]); + count += 2; + break; + case FORMAT_3F: + *vbuf->vertex_ptr++ = fui(vertex->data[i][0]); + *vbuf->vertex_ptr++ = fui(vertex->data[i][1]); + *vbuf->vertex_ptr++ = fui(vertex->data[i][2]); + count += 3; + break; + case FORMAT_4F: + *vbuf->vertex_ptr++ = fui(vertex->data[i][0]); + *vbuf->vertex_ptr++ = fui(vertex->data[i][1]); + *vbuf->vertex_ptr++ = fui(vertex->data[i][2]); + *vbuf->vertex_ptr++ = fui(vertex->data[i][3]); + count += 4; + break; + case FORMAT_4UB: + *vbuf->vertex_ptr++ = pack_ub4(float_to_ubyte( vertex->data[i][2] ), + float_to_ubyte( vertex->data[i][1] ), + float_to_ubyte( vertex->data[i][0] ), + float_to_ubyte( vertex->data[i][3] )); + count += 1; + break; + default: + assert(0); + } + } + assert(count == vinfo->size); +} + + +static void +vbuf_tri( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + unsigned i; + + check_space( vbuf, 3 ); + + for (i = 0; i < 3; i++) { + emit_vertex( vbuf, prim->v[i] ); + + vbuf->indices[vbuf->nr_indices++] = (ushort) prim->v[i]->vertex_id; + } +} + + +static void +vbuf_line( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + unsigned i; + + check_space( vbuf, 2 ); + + for (i = 0; i < 2; i++) { + emit_vertex( vbuf, prim->v[i] ); + + vbuf->indices[vbuf->nr_indices++] = (ushort) prim->v[i]->vertex_id; + } +} + + +static void +vbuf_point( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + check_space( vbuf, 1 ); + + emit_vertex( vbuf, prim->v[0] ); + + vbuf->indices[vbuf->nr_indices++] = (ushort) prim->v[0]->vertex_id; +} + + +static void +vbuf_first_tri( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_indices( stage ); + stage->tri = vbuf_tri; + stage->tri( stage, prim ); + vbuf->prim = PIPE_PRIM_TRIANGLES; + vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_TRIANGLES); +} + + +static void +vbuf_first_line( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_indices( stage ); + stage->line = vbuf_line; + stage->line( stage, prim ); + vbuf->prim = PIPE_PRIM_LINES; + vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_LINES); +} + + +static void +vbuf_first_point( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_indices( stage ); + stage->point = vbuf_point; + stage->point( stage, prim ); + vbuf->prim = PIPE_PRIM_POINTS; + vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_POINTS); +} + + +static void +vbuf_flush_indices( struct draw_stage *stage ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + if(!vbuf->nr_indices) + return; + + assert(vbuf->vertex_ptr - vbuf->vertices == + vbuf->nr_vertices * vbuf->vertex_size / sizeof(unsigned)); + + switch(vbuf->prim) { + case PIPE_PRIM_POINTS: + break; + case PIPE_PRIM_LINES: + assert(vbuf->nr_indices % 2 == 0); + break; + case PIPE_PRIM_TRIANGLES: + assert(vbuf->nr_indices % 3 == 0); + break; + default: + assert(0); + } + + vbuf->render->draw(vbuf->render, vbuf->indices, vbuf->nr_indices); + + vbuf->nr_indices = 0; +} + + +/** + * Flush existing vertex buffer and allocate a new one. + * + * XXX: We separate flush-on-index-full and flush-on-vb-full, but may + * raise issues uploading vertices if the hardware wants to flush when + * we flush. + */ +static void +vbuf_flush_vertices( struct draw_stage *stage, + unsigned new_vertex_size ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + if(vbuf->vertices) { + vbuf_flush_indices(stage); + + /* Reset temporary vertices ids */ + if(vbuf->nr_vertices) + draw_reset_vertex_ids( vbuf->stage.draw ); + + /* Free the vertex buffer */ + vbuf->render->release_vertices(vbuf->render, + vbuf->vertices, + vbuf->vertex_size, + vbuf->nr_vertices); + vbuf->nr_vertices = 0; + vbuf->vertex_ptr = vbuf->vertices = NULL; + + } + + assert(!vbuf->nr_indices); + + /* Allocate a new vertex buffer */ + vbuf->vertex_size = new_vertex_size; + vbuf->max_vertices = vbuf->render->max_vertex_buffer_bytes / vbuf->vertex_size; + vbuf->vertices = vbuf->render->allocate_vertices(vbuf->render, + vbuf->vertex_size, + vbuf->max_vertices) ; + vbuf->vertex_ptr = vbuf->vertices; +} + + +static void +vbuf_begin( struct draw_stage *stage ) +{ + struct vbuf_stage *vbuf = vbuf_stage(stage); + const struct vertex_info *vinfo = vbuf->render->get_vertex_info(vbuf->render); + unsigned vertex_size = vinfo->size * sizeof(float); + + if(vbuf->vertex_size != vertex_size) + vbuf_flush_vertices(&vbuf->stage, vertex_size); +} + + +static void +vbuf_end( struct draw_stage *stage ) +{ + /* XXX: Overkill */ + vbuf_flush_indices( stage ); + + stage->point = vbuf_first_point; + stage->line = vbuf_first_line; + stage->tri = vbuf_first_tri; +} + + +static void +vbuf_reset_stipple_counter( struct draw_stage *stage ) +{ +} + + +/** + * Create a new primitive vbuf/render stage. + */ +struct draw_stage *draw_vbuf_stage( struct draw_context *draw, + struct vbuf_render *render ) +{ + struct vbuf_stage *vbuf = CALLOC_STRUCT(vbuf_stage); + + vbuf->stage.draw = draw; + vbuf->stage.begin = vbuf_begin; + vbuf->stage.point = vbuf_first_point; + vbuf->stage.line = vbuf_first_line; + vbuf->stage.tri = vbuf_first_tri; + vbuf->stage.end = vbuf_end; + vbuf->stage.reset_stipple_counter = vbuf_reset_stipple_counter; + + vbuf->render = render; + + assert(render->max_indices < UNDEFINED_VERTEX_ID); + vbuf->max_indices = render->max_indices; + /* FIXME: free this memory on takedown */ + vbuf->indices = MALLOC( vbuf->max_indices ); + + vbuf->vertices = NULL; + vbuf->vertex_ptr = vbuf->vertices; + + return &vbuf->stage; +} diff --git a/src/mesa/pipe/draw/draw_vbuf.h b/src/mesa/pipe/draw/draw_vbuf.h new file mode 100644 index 00000000000..43aa740f646 --- /dev/null +++ b/src/mesa/pipe/draw/draw_vbuf.h @@ -0,0 +1,106 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Vertex buffer drawing stage. + * + * \author Keith Whitwell + * \author José Fonseca + */ + +#ifndef DRAW_VBUF_H_ +#define DRAW_VBUF_H_ + + +#include "pipe/p_util.h" + + +struct draw_context; +struct vertex_info; + + +/** + * Interface for hardware vertex buffer rendering. + */ +struct vbuf_render { + + /** + * Driver limits. May be tuned lower to improve cache hits on + * index list. + */ + unsigned max_indices; + unsigned max_vertex_buffer_bytes; + + /** + * Get the hardware vertex format. + * + * XXX: have this in draw_context instead? + */ + const struct vertex_info *(*get_vertex_info)( struct vbuf_render * ); + + /** + * Request a destination for vertices. + * Hardware renderers will use ttm memory, others will just malloc + * something. + */ + void *(*allocate_vertices)( struct vbuf_render *, + ushort vertex_size, + ushort nr_vertices ); + + /** + * Notify the renderer of the current primitive when it changes. + * Prim is restricted to TRIANGLES, LINES and POINTS. + */ + void (*set_primitive)( struct vbuf_render *, unsigned prim ); + + /** + * DrawElements, note indices are ushort: + */ + void (*draw)( struct vbuf_render *, + const ushort *indices, + unsigned nr_indices ); + + /** + * Called when vbuf is done with this set of vertices: + */ + void (*release_vertices)( struct vbuf_render *, + void *vertices, + unsigned vertex_size, + unsigned vertices_used ); + + void (*destroy)( struct vbuf_render * ); +}; + + + +struct draw_stage * +draw_vbuf_stage( struct draw_context *draw, + struct vbuf_render *render ); + + +#endif /*DRAW_VBUF_H_*/ diff --git a/src/mesa/pipe/draw/draw_vertex.c b/src/mesa/pipe/draw/draw_vertex.c index dea26a3d0a1..a1926d951a5 100644 --- a/src/mesa/pipe/draw/draw_vertex.c +++ b/src/mesa/pipe/draw/draw_vertex.c @@ -75,7 +75,6 @@ draw_compute_vertex_size(struct vertex_info *vinfo) vinfo->size += 3; break; case FORMAT_4F: - case FORMAT_4F_VIEWPORT: vinfo->size += 4; break; default: @@ -88,38 +87,26 @@ draw_compute_vertex_size(struct vertex_info *vinfo) /** - * Tell the drawing module about the layout of post-transformation vertices + * Tell the drawing module about the contents of post-transformation vertices. + * Note that the vertex attribute format info isn't used by 'draw'; all + * attributes are handled as float[4]. But when the driver emits vertices + * it'll use that info. + * We _do_ care about the number of attributes and their interpolation modes. */ void -draw_set_vertex_attributes( struct draw_context *draw, - const uint *slot_to_vf_attr, - const enum interp_mode *interps, - unsigned nr_attrs ) +draw_set_vertex_info( struct draw_context *draw, + const struct vertex_info *info) { - struct vertex_info *vinfo = &draw->vertex_info; - unsigned i; + assert(info->interp_mode[0] == INTERP_LINEAR); /* should be vert pos */ + assert(info->num_attribs <= PIPE_MAX_SHADER_OUTPUTS); -#if 0 - assert(slot_to_vf_attr[0] == TGSI_ATTRIB_POS); -#endif + memcpy(&draw->vertex_info, info, sizeof(*info)); - memset(vinfo, 0, sizeof(*vinfo)); - - /* - * First three attribs are always the same: header, clip pos, winpos - */ - emit_vertex_attr(vinfo, FORMAT_1F, INTERP_NONE); - emit_vertex_attr(vinfo, FORMAT_4F, INTERP_LINEAR); - emit_vertex_attr(vinfo, FORMAT_4F_VIEWPORT, INTERP_LINEAR); - - /* - * Remaining attribs (color, texcoords, etc) + /* Need to know vertex size (in words) for vertex copying elsewhere. + * Four words per attribute, plus vertex header (uint) and clip + * position (float[4]). */ - for (i = 1; i < nr_attrs; i++) { - emit_vertex_attr(vinfo, FORMAT_4F, interps[i]); - } - - draw_compute_vertex_size(vinfo); + draw->vertex_info.size = draw->vertex_info.num_attribs * 4 + 5; } diff --git a/src/mesa/pipe/draw/draw_vertex.h b/src/mesa/pipe/draw/draw_vertex.h index a1fa7aae5a1..8bb328affa3 100644 --- a/src/mesa/pipe/draw/draw_vertex.h +++ b/src/mesa/pipe/draw/draw_vertex.h @@ -46,7 +46,6 @@ enum attrib_format { FORMAT_2F, FORMAT_3F, FORMAT_4F, - FORMAT_4F_VIEWPORT, FORMAT_4UB }; @@ -93,10 +92,8 @@ draw_emit_vertex_attr(struct vertex_info *vinfo, } -extern void draw_set_vertex_attributes( struct draw_context *draw, - const uint *attrs, - const enum interp_mode *interps, - unsigned nr_attrs ); +extern void draw_set_vertex_info( struct draw_context *draw, + const struct vertex_info *info); extern void draw_set_twoside_attributes(struct draw_context *draw, uint front0, uint back0, diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c index b510a4dbba2..e0759c2e9a9 100644 --- a/src/mesa/pipe/draw/draw_vertex_fetch.c +++ b/src/mesa/pipe/draw/draw_vertex_fetch.c @@ -31,12 +31,11 @@ */ #include "pipe/p_util.h" +#include "pipe/p_shader_tokens.h" #include "draw_private.h" #include "draw_context.h" #include "draw_vertex.h" -#include "pipe/tgsi/exec/tgsi_core.h" - #define DBG 0 @@ -47,7 +46,7 @@ * XXX this might be a temporary thing. */ static void -fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) +fetch_attrib4(const void *ptr, enum pipe_format format, float attrib[4]) { /* defaults */ attrib[1] = 0.0; @@ -80,6 +79,13 @@ fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) attrib[0] = (float) ((int *) ptr)[0]; break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + attrib[0] = (float) ((unsigned char *) ptr)[2] / 255.0f; + attrib[1] = (float) ((unsigned char *) ptr)[1] / 255.0f; + attrib[2] = (float) ((unsigned char *) ptr)[0] / 255.0f; + attrib[3] = (float) ((unsigned char *) ptr)[3] / 255.0f; + break; + default: assert(0); } diff --git a/src/mesa/pipe/draw/draw_vertex_shader.c b/src/mesa/pipe/draw/draw_vertex_shader.c index e8801addac3..eef71a7a4a3 100644 --- a/src/mesa/pipe/draw/draw_vertex_shader.c +++ b/src/mesa/pipe/draw/draw_vertex_shader.c @@ -32,13 +32,13 @@ */ #include "pipe/p_util.h" +#include "pipe/p_shader_tokens.h" #include "draw_private.h" #include "draw_context.h" #include "draw_vertex.h" #include "x86/rtasm/x86sse.h" -#include "pipe/tgsi/exec/tgsi_core.h" #include "pipe/llvm/gallivm.h" @@ -158,10 +158,8 @@ run_vertex_program(struct draw_context *draw, #endif /* Remaining attributes are packed into sequential post-transform * vertex attrib slots. - * Skip 0 since we just did it above. - * Subtract two because of the VERTEX_HEADER, CLIP_POS attribs. */ - for (slot = 1; slot < draw->vertex_info.num_attribs - 2; slot++) { + for (slot = 1; slot < draw->vertex_info.num_attribs; slot++) { vOut[j]->data[slot][0] = machine->Outputs[slot].xyzw[0].f[j]; vOut[j]->data[slot][1] = machine->Outputs[slot].xyzw[1].f[j]; vOut[j]->data[slot][2] = machine->Outputs[slot].xyzw[2].f[j]; diff --git a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c index 3e005a76f31..29de437595c 100644 --- a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c +++ b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c @@ -43,7 +43,7 @@ #define DBG 0 static INLINE void -fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) +fetch_attrib4(const void *ptr, enum pipe_format format, float attrib[4]) { /* defaults */ attrib[1] = 0.0; @@ -173,10 +173,8 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw) /* Remaining attributes are packed into sequential post-transform * vertex attrib slots. - * Skip 0 since we just did it above. - * Subtract two because of the VERTEX_HEADER, CLIP_POS attribs. */ - for (slot = 1; slot < draw->vertex_info.num_attribs - 2; slot++) { + for (slot = 1; slot < draw->vertex_info.num_attribs; slot++) { vOut->data[slot][0] = dests[slot][0]; vOut->data[slot][1] = dests[slot][1]; vOut->data[slot][2] = dests[slot][2]; diff --git a/src/mesa/pipe/draw/draw_wide_prims.c b/src/mesa/pipe/draw/draw_wide_prims.c index f3b4478f9a3..494a2bc6199 100644 --- a/src/mesa/pipe/draw/draw_wide_prims.c +++ b/src/mesa/pipe/draw/draw_wide_prims.c @@ -30,10 +30,10 @@ #include "pipe/p_util.h" #include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" #include "draw_private.h" - struct wide_stage { struct draw_stage stage; diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index c5fab73fb13..a1291f583b0 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -140,12 +140,11 @@ struct pipe_context *failover_create( struct pipe_context *hw, #endif failover->pipe.get_tex_surface = hw->get_tex_surface; - failover->pipe.region_map = hw->region_map; - failover->pipe.region_unmap = hw->region_unmap; - failover->pipe.region_data = hw->region_data; - failover->pipe.region_copy = hw->region_copy; - failover->pipe.region_fill = hw->region_fill; - failover->pipe.mipmap_tree_layout = hw->mipmap_tree_layout; + failover->pipe.surface_data = hw->surface_data; + failover->pipe.surface_copy = hw->surface_copy; + failover->pipe.surface_fill = hw->surface_fill; + failover->pipe.texture_create = hw->texture_create; + failover->pipe.texture_release = hw->texture_release; failover->pipe.flush = hw->flush; failover->dirty = 0; diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 759b53ccbe4..7cf18c9ec19 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -85,7 +85,7 @@ struct failover_context { struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; uint sampler_units[PIPE_MAX_SAMPLERS]; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 2cd1a50b203..fd6137ba662 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -402,7 +402,7 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) static void failover_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct failover_context *failover = failover_context(pipe); diff --git a/src/mesa/pipe/i915simple/Makefile b/src/mesa/pipe/i915simple/Makefile index 391a084915d..2f91de3afc6 100644 --- a/src/mesa/pipe/i915simple/Makefile +++ b/src/mesa/pipe/i915simple/Makefile @@ -12,7 +12,6 @@ DRIVER_SOURCES = \ i915_context.c \ i915_debug.c \ i915_debug_fp.c \ - i915_regions.c \ i915_state.c \ i915_state_immediate.c \ i915_state_dynamic.c \ @@ -22,7 +21,7 @@ DRIVER_SOURCES = \ i915_strings.c \ i915_prim_emit.c \ i915_prim_vbuf.c \ - i915_tex_layout.c \ + i915_texture.c \ i915_fpc_emit.c \ i915_fpc_translate.c \ i915_surface.c diff --git a/src/mesa/pipe/i915simple/i915_batch.h b/src/mesa/pipe/i915simple/i915_batch.h index 603d193f626..fb88cd6db0d 100644 --- a/src/mesa/pipe/i915simple/i915_batch.h +++ b/src/mesa/pipe/i915simple/i915_batch.h @@ -44,11 +44,11 @@ #define ADVANCE_BATCH() -#define FLUSH_BATCH() do { \ - if (0) i915_dump_batchbuffer( i915 ); \ - i915->winsys->batch_flush( i915->winsys, &i915->last_fence ); \ - i915->batch_start = NULL; \ - i915->hardware_dirty = ~0; \ +#define FLUSH_BATCH() do { \ + if (0) i915_dump_batchbuffer( i915 ); \ + i915->winsys->batch_flush( i915->winsys ); \ + i915->batch_start = NULL; \ + i915->hardware_dirty = ~0; \ } while (0) #endif diff --git a/src/mesa/pipe/i915simple/i915_blit.c b/src/mesa/pipe/i915simple/i915_blit.c index a1f953ebbeb..6e95313a0d2 100644 --- a/src/mesa/pipe/i915simple/i915_blit.c +++ b/src/mesa/pipe/i915simple/i915_blit.c @@ -47,7 +47,7 @@ i915_fill_blit(struct i915_context *i915, unsigned BR13, CMD; BATCH_LOCALS; - dst_pitch *= cpp; + dst_pitch *= (short) cpp; switch (cpp) { case 1: @@ -102,14 +102,14 @@ i915_copy_blit( struct i915_context *i915, BATCH_LOCALS; - DBG(i915, + I915_DBG(i915, "%s src:buf(%p)/%d+%d %d,%d dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n", __FUNCTION__, src_buffer, src_pitch, src_offset, src_x, src_y, dst_buffer, dst_pitch, dst_offset, dst_x, dst_y, w, h); - src_pitch *= cpp; - dst_pitch *= cpp; + src_pitch *= (short) cpp; + dst_pitch *= (short) cpp; switch (cpp) { case 1: diff --git a/src/mesa/pipe/i915simple/i915_clear.c b/src/mesa/pipe/i915simple/i915_clear.c index e8087df5a47..cde69daacc0 100644 --- a/src/mesa/pipe/i915simple/i915_clear.c +++ b/src/mesa/pipe/i915simple/i915_clear.c @@ -43,12 +43,5 @@ void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps, unsigned clearValue) { - int x, y, w, h; - - x = 0; - y = 0; - w = ps->width; - h = ps->height; - - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearValue); + pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue); } diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index f5d770ce0df..b915a677908 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -29,7 +29,7 @@ #include "i915_winsys.h" #include "i915_state.h" #include "i915_batch.h" -#include "i915_tex_layout.h" +#include "i915_texture.h" #include "i915_reg.h" #include "pipe/draw/draw_context.h" @@ -45,37 +45,37 @@ */ static boolean i915_is_format_supported( struct pipe_context *pipe, - uint format ) + enum pipe_format format ) { #if 0 /* XXX: This is broken -- rewrite if still needed. */ static const unsigned tex_supported[] = { - PIPE_FORMAT_U_R8_G8_B8_A8, - PIPE_FORMAT_U_A8_R8_G8_B8, - PIPE_FORMAT_U_R5_G6_B5, + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_R5G6B5_UNORM, PIPE_FORMAT_U_L8, PIPE_FORMAT_U_A8, PIPE_FORMAT_U_I8, PIPE_FORMAT_U_L8_A8, PIPE_FORMAT_YCBCR, PIPE_FORMAT_YCBCR_REV, - PIPE_FORMAT_S8_Z24, + PIPE_FORMAT_S8Z24_UNORM, }; /* Actually a lot more than this - add later: */ static const unsigned render_supported[] = { - PIPE_FORMAT_U_A8_R8_G8_B8, - PIPE_FORMAT_U_R5_G6_B5, + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_R5G6B5_UNORM, }; /* */ static const unsigned z_stencil_supported[] = { - PIPE_FORMAT_U_Z16, - PIPE_FORMAT_U_Z32, - PIPE_FORMAT_S8_Z24, + PIPE_FORMAT_Z16_UNORM, + PIPE_FORMAT_Z32_UNORM, + PIPE_FORMAT_S8Z24_UNORM, }; switch (type) { @@ -97,12 +97,13 @@ i915_is_format_supported( struct pipe_context *pipe, } #else switch( format ) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - case PIPE_FORMAT_U_R5_G6_B5: - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: return TRUE; + default: + return FALSE; }; - return FALSE; #endif } @@ -175,9 +176,7 @@ static void i915_destroy( struct pipe_context *pipe ) draw_destroy( i915->draw ); - i915->winsys->fence_reference( i915->winsys, &i915->last_fence, NULL ); - - free( i915 ); + FREE( i915 ); } @@ -343,14 +342,13 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, */ i915->draw = draw_create(); assert(i915->draw); - if (getenv("I915_VBUF")) { + if (GETENV("I915_VBUF")) { draw_set_rasterize_stage(i915->draw, i915_draw_vbuf_stage(i915)); } else { draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915)); } - i915_init_region_functions(i915); i915_init_surface_functions(i915); i915_init_state_functions(i915); i915_init_flush_functions(i915); @@ -359,11 +357,8 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, i915->pci_id = pci_id; i915->flags.is_i945 = is_i945; - if (i915->flags.is_i945) - i915->pipe.mipmap_tree_layout = i945_miptree_layout; - else - i915->pipe.mipmap_tree_layout = i915_miptree_layout; - + i915->pipe.texture_create = i915_texture_create; + i915->pipe.texture_release = i915_texture_release; i915->dirty = ~0; i915->hardware_dirty = ~0; diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 488682f852e..dbf0c885cc8 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -80,7 +80,6 @@ -struct pipe_fence; struct i915_cache_context; /* Use to calculate differences between state emitted to hardware and @@ -151,6 +150,34 @@ struct i915_alpha_test_state { unsigned LIS6; }; +struct i915_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 level_offset[PIPE_MAX_TEXTURE_LEVELS]; + + /* The data is held here: + */ + struct pipe_buffer_handle *buffer; +}; + struct i915_context { struct pipe_context pipe; @@ -175,7 +202,7 @@ struct i915_context struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; uint sampler_units[PIPE_MAX_SAMPLERS]; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct i915_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; @@ -185,8 +212,6 @@ struct i915_context unsigned dirty; unsigned *batch_start; - - struct pipe_fence *last_fence; /** Vertex buffer */ struct pipe_buffer_handle *vbo; @@ -264,10 +289,10 @@ void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps, /*********************************************************************** - * i915_region.c: + * i915_surface.c: */ -void i915_init_region_functions( struct i915_context *i915 ); void i915_init_surface_functions( struct i915_context *i915 ); + void i915_init_state_functions( struct i915_context *i915 ); void i915_init_flush_functions( struct i915_context *i915 ); void i915_init_string_functions( struct i915_context *i915 ); diff --git a/src/mesa/pipe/i915simple/i915_debug.c b/src/mesa/pipe/i915simple/i915_debug.c index d07d2f1fa95..94db44e1aaf 100644 --- a/src/mesa/pipe/i915simple/i915_debug.c +++ b/src/mesa/pipe/i915simple/i915_debug.c @@ -33,7 +33,21 @@ #include "i915_debug.h" #include "pipe/p_winsys.h" -#define PRINTF( ... ) (stream)->winsys->printf( (stream)->winsys, __VA_ARGS__ ) + +static void +PRINTF( + struct debug_stream *stream, + const char *fmt, + ... ) +{ + va_list args; + char buffer[256]; + + va_start( args, fmt ); + vsprintf( buffer, fmt, args ); + stream->winsys->printf( stream->winsys, buffer ); + va_end( args ); +} static boolean debug( struct debug_stream *stream, const char *name, unsigned len ) @@ -42,19 +56,19 @@ static boolean debug( struct debug_stream *stream, const char *name, unsigned le unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); if (len == 0) { - PRINTF("Error - zero length packet (0x%08x)\n", stream->ptr[0]); + PRINTF(stream, "Error - zero length packet (0x%08x)\n", stream->ptr[0]); assert(0); return FALSE; } if (stream->print_addresses) - PRINTF("%08x: ", stream->offset); + PRINTF(stream, "%08x: ", stream->offset); - PRINTF("%s (%d dwords):\n", name, len); + PRINTF(stream, "%s (%d dwords):\n", name, len); for (i = 0; i < len; i++) - PRINTF("\t0x%08x\n", ptr[i]); - PRINTF("\n"); + PRINTF(stream, "\t0x%08x\n", ptr[i]); + PRINTF(stream, "\n"); stream->offset += len * sizeof(unsigned); @@ -91,17 +105,17 @@ static boolean debug_prim( struct debug_stream *stream, const char *name, - PRINTF("%s %s (%d dwords):\n", name, prim, len); - PRINTF("\t0x%08x\n", ptr[0]); + PRINTF(stream, "%s %s (%d dwords):\n", name, prim, len); + PRINTF(stream, "\t0x%08x\n", ptr[0]); for (i = 1; i < len; i++) { if (dump_floats) - PRINTF("\t0x%08x // %f\n", ptr[i], *(float *)&ptr[i]); + PRINTF(stream, "\t0x%08x // %f\n", ptr[i], *(float *)&ptr[i]); else - PRINTF("\t0x%08x\n", ptr[i]); + PRINTF(stream, "\t0x%08x\n", ptr[i]); } - PRINTF("\n"); + PRINTF(stream, "\n"); stream->offset += len * sizeof(unsigned); @@ -116,15 +130,15 @@ static boolean debug_program( struct debug_stream *stream, const char *name, uns unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); if (len == 0) { - PRINTF("Error - zero length packet (0x%08x)\n", stream->ptr[0]); + PRINTF(stream, "Error - zero length packet (0x%08x)\n", stream->ptr[0]); assert(0); return FALSE; } if (stream->print_addresses) - PRINTF("%08x: ", stream->offset); + PRINTF(stream, "%08x: ", stream->offset); - PRINTF("%s (%d dwords):\n", name, len); + PRINTF(stream, "%s (%d dwords):\n", name, len); i915_disassemble_program( stream, ptr, len ); stream->offset += len * sizeof(unsigned); @@ -138,17 +152,17 @@ static boolean debug_chain( struct debug_stream *stream, const char *name, unsig unsigned old_offset = stream->offset + len * sizeof(unsigned); unsigned i; - PRINTF("%s (%d dwords):\n", name, len); + PRINTF(stream, "%s (%d dwords):\n", name, len); for (i = 0; i < len; i++) - PRINTF("\t0x%08x\n", ptr[i]); + PRINTF(stream, "\t0x%08x\n", ptr[i]); stream->offset = ptr[1] & ~0x3; if (stream->offset < old_offset) - PRINTF("\n... skipping backwards from 0x%x --> 0x%x ...\n\n", + PRINTF(stream, "\n... skipping backwards from 0x%x --> 0x%x ...\n\n", old_offset, stream->offset ); else - PRINTF("\n... skipping from 0x%x --> 0x%x ...\n\n", + PRINTF(stream, "\n... skipping from 0x%x --> 0x%x ...\n\n", old_offset, stream->offset ); @@ -168,23 +182,38 @@ static boolean debug_variable_length_prim( struct debug_stream *stream ) len = 1+(i+2)/2; - PRINTF("3DPRIM, %s variable length %d indicies (%d dwords):\n", prim, i, len); + PRINTF(stream, "3DPRIM, %s variable length %d indicies (%d dwords):\n", prim, i, len); for (i = 0; i < len; i++) - PRINTF("\t0x%08x\n", ptr[i]); - PRINTF("\n"); + PRINTF(stream, "\t0x%08x\n", ptr[i]); + PRINTF(stream, "\n"); stream->offset += len * sizeof(unsigned); return TRUE; } -#define BITS( dw, hi, lo, ... ) \ -do { \ - unsigned himask = ~0UL >> (31 - (hi)); \ - PRINTF("\t\t "); \ - PRINTF(__VA_ARGS__); \ - PRINTF(": 0x%x\n", ((dw) & himask) >> (lo)); \ -} while (0) +static void +BITS( + struct debug_stream *stream, + unsigned dw, + unsigned hi, + unsigned lo, + const char *fmt, + ... ) +{ + va_list args; + char buffer[256]; + unsigned himask = ~0UL >> (31 - (hi)); + + PRINTF(stream, "\t\t "); + + va_start( args, fmt ); + vsprintf( buffer, fmt, args ); + stream->winsys->printf( stream->winsys, buffer ); + va_end( args ); + + PRINTF(stream, ": 0x%x\n", ((dw) & himask) >> (lo)); +} #define MBZ( dw, hi, lo) do { \ unsigned x = (dw) >> (lo); \ @@ -194,14 +223,28 @@ do { \ assert ((x & himask & ~lomask) == 0); \ } while (0) -#define FLAG( dw, bit, ... ) \ -do { \ - if (((dw) >> (bit)) & 1) { \ - PRINTF("\t\t "); \ - PRINTF(__VA_ARGS__); \ - PRINTF("\n"); \ - } \ -} while (0) +static void +FLAG( + struct debug_stream *stream, + unsigned dw, + unsigned bit, + const char *fmt, + ... ) +{ + if (((dw) >> (bit)) & 1) { + va_list args; + char buffer[256]; + + PRINTF(stream, "\t\t "); + + va_start( args, fmt ); + vsprintf( buffer, fmt, args ); + stream->winsys->printf( stream->winsys, buffer ); + va_end( args ); + + PRINTF(stream, "\n"); + } +} static boolean debug_load_immediate( struct debug_stream *stream, const char *name, @@ -211,95 +254,95 @@ static boolean debug_load_immediate( struct debug_stream *stream, unsigned bits = (ptr[0] >> 4) & 0xff; unsigned j = 0; - PRINTF("%s (%d dwords, flags: %x):\n", name, len, bits); - PRINTF("\t0x%08x\n", ptr[j++]); + PRINTF(stream, "%s (%d dwords, flags: %x):\n", name, len, bits); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); if (bits & (1<<0)) { - PRINTF("\t LIS0: 0x%08x\n", ptr[j]); - PRINTF("\t vb address: 0x%08x\n", (ptr[j] & ~0x3)); - BITS(ptr[j], 0, 0, "vb invalidate disable"); + PRINTF(stream, "\t LIS0: 0x%08x\n", ptr[j]); + PRINTF(stream, "\t vb address: 0x%08x\n", (ptr[j] & ~0x3)); + BITS(stream, ptr[j], 0, 0, "vb invalidate disable"); j++; } if (bits & (1<<1)) { - PRINTF("\t LIS1: 0x%08x\n", ptr[j]); - BITS(ptr[j], 29, 24, "vb dword width"); - BITS(ptr[j], 21, 16, "vb dword pitch"); - BITS(ptr[j], 15, 0, "vb max index"); + PRINTF(stream, "\t LIS1: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 29, 24, "vb dword width"); + BITS(stream, ptr[j], 21, 16, "vb dword pitch"); + BITS(stream, ptr[j], 15, 0, "vb max index"); j++; } if (bits & (1<<2)) { int i; - PRINTF("\t LIS2: 0x%08x\n", ptr[j]); + PRINTF(stream, "\t LIS2: 0x%08x\n", ptr[j]); for (i = 0; i < 8; i++) { unsigned tc = (ptr[j] >> (i * 4)) & 0xf; if (tc != 0xf) - BITS(tc, 3, 0, "tex coord %d", i); + BITS(stream, tc, 3, 0, "tex coord %d", i); } j++; } if (bits & (1<<3)) { - PRINTF("\t LIS3: 0x%08x\n", ptr[j]); + PRINTF(stream, "\t LIS3: 0x%08x\n", ptr[j]); j++; } if (bits & (1<<4)) { - PRINTF("\t LIS4: 0x%08x\n", ptr[j]); - BITS(ptr[j], 31, 23, "point width"); - BITS(ptr[j], 22, 19, "line width"); - FLAG(ptr[j], 18, "alpha flatshade"); - FLAG(ptr[j], 17, "fog flatshade"); - FLAG(ptr[j], 16, "spec flatshade"); - FLAG(ptr[j], 15, "rgb flatshade"); - BITS(ptr[j], 14, 13, "cull mode"); - FLAG(ptr[j], 12, "vfmt: point width"); - FLAG(ptr[j], 11, "vfmt: specular/fog"); - FLAG(ptr[j], 10, "vfmt: rgba"); - FLAG(ptr[j], 9, "vfmt: depth offset"); - BITS(ptr[j], 8, 6, "vfmt: position (2==xyzw)"); - FLAG(ptr[j], 5, "force dflt diffuse"); - FLAG(ptr[j], 4, "force dflt specular"); - FLAG(ptr[j], 3, "local depth offset enable"); - FLAG(ptr[j], 2, "vfmt: fp32 fog coord"); - FLAG(ptr[j], 1, "sprite point"); - FLAG(ptr[j], 0, "antialiasing"); + PRINTF(stream, "\t LIS4: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 23, "point width"); + BITS(stream, ptr[j], 22, 19, "line width"); + FLAG(stream, ptr[j], 18, "alpha flatshade"); + FLAG(stream, ptr[j], 17, "fog flatshade"); + FLAG(stream, ptr[j], 16, "spec flatshade"); + FLAG(stream, ptr[j], 15, "rgb flatshade"); + BITS(stream, ptr[j], 14, 13, "cull mode"); + FLAG(stream, ptr[j], 12, "vfmt: point width"); + FLAG(stream, ptr[j], 11, "vfmt: specular/fog"); + FLAG(stream, ptr[j], 10, "vfmt: rgba"); + FLAG(stream, ptr[j], 9, "vfmt: depth offset"); + BITS(stream, ptr[j], 8, 6, "vfmt: position (2==xyzw)"); + FLAG(stream, ptr[j], 5, "force dflt diffuse"); + FLAG(stream, ptr[j], 4, "force dflt specular"); + FLAG(stream, ptr[j], 3, "local depth offset enable"); + FLAG(stream, ptr[j], 2, "vfmt: fp32 fog coord"); + FLAG(stream, ptr[j], 1, "sprite point"); + FLAG(stream, ptr[j], 0, "antialiasing"); j++; } if (bits & (1<<5)) { - PRINTF("\t LIS5: 0x%08x\n", ptr[j]); - BITS(ptr[j], 31, 28, "rgba write disables"); - FLAG(ptr[j], 27, "force dflt point width"); - FLAG(ptr[j], 26, "last pixel enable"); - FLAG(ptr[j], 25, "global z offset enable"); - FLAG(ptr[j], 24, "fog enable"); - BITS(ptr[j], 23, 16, "stencil ref"); - BITS(ptr[j], 15, 13, "stencil test"); - BITS(ptr[j], 12, 10, "stencil fail op"); - BITS(ptr[j], 9, 7, "stencil pass z fail op"); - BITS(ptr[j], 6, 4, "stencil pass z pass op"); - FLAG(ptr[j], 3, "stencil write enable"); - FLAG(ptr[j], 2, "stencil test enable"); - FLAG(ptr[j], 1, "color dither enable"); - FLAG(ptr[j], 0, "logiop enable"); + PRINTF(stream, "\t LIS5: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 28, "rgba write disables"); + FLAG(stream, ptr[j], 27, "force dflt point width"); + FLAG(stream, ptr[j], 26, "last pixel enable"); + FLAG(stream, ptr[j], 25, "global z offset enable"); + FLAG(stream, ptr[j], 24, "fog enable"); + BITS(stream, ptr[j], 23, 16, "stencil ref"); + BITS(stream, ptr[j], 15, 13, "stencil test"); + BITS(stream, ptr[j], 12, 10, "stencil fail op"); + BITS(stream, ptr[j], 9, 7, "stencil pass z fail op"); + BITS(stream, ptr[j], 6, 4, "stencil pass z pass op"); + FLAG(stream, ptr[j], 3, "stencil write enable"); + FLAG(stream, ptr[j], 2, "stencil test enable"); + FLAG(stream, ptr[j], 1, "color dither enable"); + FLAG(stream, ptr[j], 0, "logiop enable"); j++; } if (bits & (1<<6)) { - PRINTF("\t LIS6: 0x%08x\n", ptr[j]); - FLAG(ptr[j], 31, "alpha test enable"); - BITS(ptr[j], 30, 28, "alpha func"); - BITS(ptr[j], 27, 20, "alpha ref"); - FLAG(ptr[j], 19, "depth test enable"); - BITS(ptr[j], 18, 16, "depth func"); - FLAG(ptr[j], 15, "blend enable"); - BITS(ptr[j], 14, 12, "blend func"); - BITS(ptr[j], 11, 8, "blend src factor"); - BITS(ptr[j], 7, 4, "blend dst factor"); - FLAG(ptr[j], 3, "depth write enable"); - FLAG(ptr[j], 2, "color write enable"); - BITS(ptr[j], 1, 0, "provoking vertex"); + PRINTF(stream, "\t LIS6: 0x%08x\n", ptr[j]); + FLAG(stream, ptr[j], 31, "alpha test enable"); + BITS(stream, ptr[j], 30, 28, "alpha func"); + BITS(stream, ptr[j], 27, 20, "alpha ref"); + FLAG(stream, ptr[j], 19, "depth test enable"); + BITS(stream, ptr[j], 18, 16, "depth func"); + FLAG(stream, ptr[j], 15, "blend enable"); + BITS(stream, ptr[j], 14, 12, "blend func"); + BITS(stream, ptr[j], 11, 8, "blend src factor"); + BITS(stream, ptr[j], 7, 4, "blend dst factor"); + FLAG(stream, ptr[j], 3, "depth write enable"); + FLAG(stream, ptr[j], 2, "color write enable"); + BITS(stream, ptr[j], 1, 0, "provoking vertex"); j++; } - PRINTF("\n"); + PRINTF(stream, "\n"); assert(j == len); @@ -318,34 +361,34 @@ static boolean debug_load_indirect( struct debug_stream *stream, unsigned bits = (ptr[0] >> 8) & 0x3f; unsigned i, j = 0; - PRINTF("%s (%d dwords):\n", name, len); - PRINTF("\t0x%08x\n", ptr[j++]); + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); for (i = 0; i < 6; i++) { if (bits & (1<ptr + stream->offset); int j = 0; - PRINTF("%s (%d dwords):\n", name, len); - PRINTF("\t0x%08x\n", ptr[j++]); + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); BR13(stream, ptr[j++]); BR22(stream, ptr[j++]); @@ -458,8 +501,8 @@ static boolean debug_color_blit( struct debug_stream *stream, unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); int j = 0; - PRINTF("%s (%d dwords):\n", name, len); - PRINTF("\t0x%08x\n", ptr[j++]); + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); BR13(stream, ptr[j++]); BR22(stream, ptr[j++]); @@ -479,13 +522,13 @@ static boolean debug_modes4( struct debug_stream *stream, unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); int j = 0; - PRINTF("%s (%d dwords):\n", name, len); - PRINTF("\t0x%08x\n", ptr[j]); - BITS(ptr[j], 21, 18, "logicop func"); - FLAG(ptr[j], 17, "stencil test mask modify-enable"); - FLAG(ptr[j], 16, "stencil write mask modify-enable"); - BITS(ptr[j], 15, 8, "stencil test mask"); - BITS(ptr[j], 7, 0, "stencil write mask"); + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 21, 18, "logicop func"); + FLAG(stream, ptr[j], 17, "stencil test mask modify-enable"); + FLAG(stream, ptr[j], 16, "stencil write mask modify-enable"); + BITS(stream, ptr[j], 15, 8, "stencil test mask"); + BITS(stream, ptr[j], 7, 0, "stencil write mask"); j++; stream->offset += len * sizeof(unsigned); @@ -498,44 +541,44 @@ static boolean debug_map_state( struct debug_stream *stream, unsigned len ) { unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); - int j = 0; + unsigned j = 0; - PRINTF("%s (%d dwords):\n", name, len); - PRINTF("\t0x%08x\n", ptr[j++]); + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); { - PRINTF("\t0x%08x\n", ptr[j]); - BITS(ptr[j], 15, 0, "map mask"); + PRINTF(stream, "\t0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 15, 0, "map mask"); j++; } while (j < len) { { - PRINTF("\t TMn.0: 0x%08x\n", ptr[j]); - PRINTF("\t map address: 0x%08x\n", (ptr[j] & ~0x3)); - FLAG(ptr[j], 1, "vertical line stride"); - FLAG(ptr[j], 0, "vertical line stride offset"); + PRINTF(stream, "\t TMn.0: 0x%08x\n", ptr[j]); + PRINTF(stream, "\t map address: 0x%08x\n", (ptr[j] & ~0x3)); + FLAG(stream, ptr[j], 1, "vertical line stride"); + FLAG(stream, ptr[j], 0, "vertical line stride offset"); j++; } { - PRINTF("\t TMn.1: 0x%08x\n", ptr[j]); - BITS(ptr[j], 31, 21, "height"); - BITS(ptr[j], 20, 10, "width"); - BITS(ptr[j], 9, 7, "surface format"); - BITS(ptr[j], 6, 3, "texel format"); - FLAG(ptr[j], 2, "use fence regs"); - FLAG(ptr[j], 1, "tiled surface"); - FLAG(ptr[j], 0, "tile walk ymajor"); + PRINTF(stream, "\t TMn.1: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 21, "height"); + BITS(stream, ptr[j], 20, 10, "width"); + BITS(stream, ptr[j], 9, 7, "surface format"); + BITS(stream, ptr[j], 6, 3, "texel format"); + FLAG(stream, ptr[j], 2, "use fence regs"); + FLAG(stream, ptr[j], 1, "tiled surface"); + FLAG(stream, ptr[j], 0, "tile walk ymajor"); j++; } { - PRINTF("\t TMn.2: 0x%08x\n", ptr[j]); - BITS(ptr[j], 31, 21, "dword pitch"); - BITS(ptr[j], 20, 15, "cube face enables"); - BITS(ptr[j], 14, 9, "max lod"); - FLAG(ptr[j], 8, "mip layout right"); - BITS(ptr[j], 7, 0, "depth"); + PRINTF(stream, "\t TMn.2: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 21, "dword pitch"); + BITS(stream, ptr[j], 20, 15, "cube face enables"); + BITS(stream, ptr[j], 14, 9, "max lod"); + FLAG(stream, ptr[j], 8, "mip layout right"); + BITS(stream, ptr[j], 7, 0, "depth"); j++; } } @@ -550,52 +593,52 @@ static boolean debug_sampler_state( struct debug_stream *stream, unsigned len ) { unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); - int j = 0; + unsigned j = 0; - PRINTF("%s (%d dwords):\n", name, len); - PRINTF("\t0x%08x\n", ptr[j++]); + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); { - PRINTF("\t0x%08x\n", ptr[j]); - BITS(ptr[j], 15, 0, "sampler mask"); + PRINTF(stream, "\t0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 15, 0, "sampler mask"); j++; } while (j < len) { { - PRINTF("\t TSn.0: 0x%08x\n", ptr[j]); - FLAG(ptr[j], 31, "reverse gamma"); - FLAG(ptr[j], 30, "planar to packed"); - FLAG(ptr[j], 29, "yuv->rgb"); - BITS(ptr[j], 28, 27, "chromakey index"); - BITS(ptr[j], 26, 22, "base mip level"); - BITS(ptr[j], 21, 20, "mip mode filter"); - BITS(ptr[j], 19, 17, "mag mode filter"); - BITS(ptr[j], 16, 14, "min mode filter"); - BITS(ptr[j], 13, 5, "lod bias (s4.4)"); - FLAG(ptr[j], 4, "shadow enable"); - FLAG(ptr[j], 3, "max-aniso-4"); - BITS(ptr[j], 2, 0, "shadow func"); + PRINTF(stream, "\t TSn.0: 0x%08x\n", ptr[j]); + FLAG(stream, ptr[j], 31, "reverse gamma"); + FLAG(stream, ptr[j], 30, "planar to packed"); + FLAG(stream, ptr[j], 29, "yuv->rgb"); + BITS(stream, ptr[j], 28, 27, "chromakey index"); + BITS(stream, ptr[j], 26, 22, "base mip level"); + BITS(stream, ptr[j], 21, 20, "mip mode filter"); + BITS(stream, ptr[j], 19, 17, "mag mode filter"); + BITS(stream, ptr[j], 16, 14, "min mode filter"); + BITS(stream, ptr[j], 13, 5, "lod bias (s4.4)"); + FLAG(stream, ptr[j], 4, "shadow enable"); + FLAG(stream, ptr[j], 3, "max-aniso-4"); + BITS(stream, ptr[j], 2, 0, "shadow func"); j++; } { - PRINTF("\t TSn.1: 0x%08x\n", ptr[j]); - BITS(ptr[j], 31, 24, "min lod"); + PRINTF(stream, "\t TSn.1: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 24, "min lod"); MBZ( ptr[j], 23, 18 ); - FLAG(ptr[j], 17, "kill pixel enable"); - FLAG(ptr[j], 16, "keyed tex filter mode"); - FLAG(ptr[j], 15, "chromakey enable"); - BITS(ptr[j], 14, 12, "tcx wrap mode"); - BITS(ptr[j], 11, 9, "tcy wrap mode"); - BITS(ptr[j], 8, 6, "tcz wrap mode"); - FLAG(ptr[j], 5, "normalized coords"); - BITS(ptr[j], 4, 1, "map (surface) index"); - FLAG(ptr[j], 0, "EAST deinterlacer enable"); + FLAG(stream, ptr[j], 17, "kill pixel enable"); + FLAG(stream, ptr[j], 16, "keyed tex filter mode"); + FLAG(stream, ptr[j], 15, "chromakey enable"); + BITS(stream, ptr[j], 14, 12, "tcx wrap mode"); + BITS(stream, ptr[j], 11, 9, "tcy wrap mode"); + BITS(stream, ptr[j], 8, 6, "tcz wrap mode"); + FLAG(stream, ptr[j], 5, "normalized coords"); + BITS(stream, ptr[j], 4, 1, "map (surface) index"); + FLAG(stream, ptr[j], 0, "EAST deinterlacer enable"); j++; } { - PRINTF("\t TSn.2: 0x%08x (default color)\n", ptr[j]); + PRINTF(stream, "\t TSn.2: 0x%08x (default color)\n", ptr[j]); j++; } } @@ -612,26 +655,26 @@ static boolean debug_dest_vars( struct debug_stream *stream, unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); int j = 0; - PRINTF("%s (%d dwords):\n", name, len); - PRINTF("\t0x%08x\n", ptr[j++]); + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); { - PRINTF("\t0x%08x\n", ptr[j]); - FLAG(ptr[j], 31, "early classic ztest"); - FLAG(ptr[j], 30, "opengl tex default color"); - FLAG(ptr[j], 29, "bypass iz"); - FLAG(ptr[j], 28, "lod preclamp"); - BITS(ptr[j], 27, 26, "dither pattern"); - FLAG(ptr[j], 25, "linear gamma blend"); - FLAG(ptr[j], 24, "debug dither"); - BITS(ptr[j], 23, 20, "dstorg x"); - BITS(ptr[j], 19, 16, "dstorg y"); + PRINTF(stream, "\t0x%08x\n", ptr[j]); + FLAG(stream, ptr[j], 31, "early classic ztest"); + FLAG(stream, ptr[j], 30, "opengl tex default color"); + FLAG(stream, ptr[j], 29, "bypass iz"); + FLAG(stream, ptr[j], 28, "lod preclamp"); + BITS(stream, ptr[j], 27, 26, "dither pattern"); + FLAG(stream, ptr[j], 25, "linear gamma blend"); + FLAG(stream, ptr[j], 24, "debug dither"); + BITS(stream, ptr[j], 23, 20, "dstorg x"); + BITS(stream, ptr[j], 19, 16, "dstorg y"); MBZ (ptr[j], 15, 15 ); - BITS(ptr[j], 14, 12, "422 write select"); - BITS(ptr[j], 11, 8, "cbuf format"); - BITS(ptr[j], 3, 2, "zbuf format"); - FLAG(ptr[j], 1, "vert line stride"); - FLAG(ptr[j], 1, "vert line stride offset"); + BITS(stream, ptr[j], 14, 12, "422 write select"); + BITS(stream, ptr[j], 11, 8, "cbuf format"); + BITS(stream, ptr[j], 3, 2, "zbuf format"); + FLAG(stream, ptr[j], 1, "vert line stride"); + FLAG(stream, ptr[j], 1, "vert line stride offset"); j++; } @@ -647,23 +690,23 @@ static boolean debug_buf_info( struct debug_stream *stream, unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); int j = 0; - PRINTF("%s (%d dwords):\n", name, len); - PRINTF("\t0x%08x\n", ptr[j++]); + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); { - PRINTF("\t0x%08x\n", ptr[j]); - BITS(ptr[j], 28, 28, "aux buffer id"); - BITS(ptr[j], 27, 24, "buffer id (7=depth, 3=back)"); - FLAG(ptr[j], 23, "use fence regs"); - FLAG(ptr[j], 22, "tiled surface"); - FLAG(ptr[j], 21, "tile walk ymajor"); + PRINTF(stream, "\t0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 28, 28, "aux buffer id"); + BITS(stream, ptr[j], 27, 24, "buffer id (7=depth, 3=back)"); + FLAG(stream, ptr[j], 23, "use fence regs"); + FLAG(stream, ptr[j], 22, "tiled surface"); + FLAG(stream, ptr[j], 21, "tile walk ymajor"); MBZ (ptr[j], 20, 14); - BITS(ptr[j], 13, 2, "dword pitch"); + BITS(stream, ptr[j], 13, 2, "dword pitch"); MBZ (ptr[j], 2, 0); j++; } - PRINTF("\t0x%08x -- buffer base address\n", ptr[j++]); + PRINTF(stream, "\t0x%08x -- buffer base address\n", ptr[j++]); stream->offset += len * sizeof(unsigned); assert(j == len); @@ -827,7 +870,7 @@ i915_dump_batchbuffer( struct i915_context *i915 ) struct debug_stream stream; unsigned *start = i915->batch_start; unsigned *end = i915->winsys->batch_start( i915->winsys, 0, 0 ); - unsigned bytes = (end - start) * 4; + unsigned long bytes = (unsigned long) (end - start) * 4; boolean done = FALSE; stream.offset = 0; @@ -843,8 +886,7 @@ i915_dump_batchbuffer( struct i915_context *i915 ) stream.winsys->printf( stream.winsys, "\n\nBATCH: (%d)\n", bytes / 4); while (!done && - stream.offset < bytes && - stream.offset >= 0) + stream.offset < bytes) { if (!i915_debug_packet( &stream )) break; diff --git a/src/mesa/pipe/i915simple/i915_debug.h b/src/mesa/pipe/i915simple/i915_debug.h index 4c3aa64b421..13197f35951 100644 --- a/src/mesa/pipe/i915simple/i915_debug.h +++ b/src/mesa/pipe/i915simple/i915_debug.h @@ -31,6 +31,8 @@ #ifndef I915_DEBUG_H #define I915_DEBUG_H +#include + struct i915_context; struct debug_stream @@ -67,15 +69,39 @@ void i915_print_ureg(const char *msg, unsigned ureg); #define DEBUG_SURFACE 0x2000 #define DEBUG_WINSYS 0x4000 -#ifdef DEBUG +#if defined(DEBUG) && defined(FILE_DEBUG_FLAG) + #include "pipe/p_winsys.h" -#define DBG( i915, ... ) do { \ - if ((i915)->debug & FILE_DEBUG_FLAG) \ - (i915)->pipe.winsys->printf( (i915)->pipe.winsys, __VA_ARGS__ ); \ -} while(0) + +static void +I915_DBG( + struct i915_context *i915, + const char *fmt, + ... ) +{ + if ((i915)->debug & FILE_DEBUG_FLAG) { + va_list args; + char buffer[256]; + + va_start( args, fmt ); + vsprintf( buffer, fmt, args ); + i915->pipe.winsys->printf( i915->pipe.winsys, buffer ); + va_end( args ); + } +} + #else -#define DBG( i915, ... ) \ - (void)i915 + +static void +I915_DBG( + struct i915_context *i915, + const char *fmt, + ... ) +{ + (void) i915; + (void) fmt; +} + #endif diff --git a/src/mesa/pipe/i915simple/i915_debug_fp.c b/src/mesa/pipe/i915simple/i915_debug_fp.c index 87fc3b2f9ac..ebfdb3d93c5 100644 --- a/src/mesa/pipe/i915simple/i915_debug_fp.c +++ b/src/mesa/pipe/i915simple/i915_debug_fp.c @@ -32,11 +32,20 @@ #include "pipe/p_util.h" +static void +PRINTF( + struct debug_stream *stream, + const char *fmt, + ... ) +{ + va_list args; + char buffer[256]; - -#define PRINTF( ... ) (stream)->winsys->printf( (stream)->winsys, __VA_ARGS__ ) - - + va_start( args, fmt ); + vsprintf( buffer, fmt, args ); + stream->winsys->printf( stream->winsys, buffer ); + va_end( args ); +} static const char *opcodes[0x20] = { @@ -129,27 +138,27 @@ print_reg_type_nr(struct debug_stream *stream, unsigned type, unsigned nr) case REG_TYPE_T: switch (nr) { case T_DIFFUSE: - PRINTF("T_DIFFUSE"); + PRINTF(stream, "T_DIFFUSE"); return; case T_SPECULAR: - PRINTF("T_SPECULAR"); + PRINTF(stream, "T_SPECULAR"); return; case T_FOG_W: - PRINTF("T_FOG_W"); + PRINTF(stream, "T_FOG_W"); return; default: - PRINTF("T_TEX%d", nr); + PRINTF(stream, "T_TEX%d", nr); return; } case REG_TYPE_OC: if (nr == 0) { - PRINTF("oC"); + PRINTF(stream, "oC"); return; } break; case REG_TYPE_OD: if (nr == 0) { - PRINTF("oD"); + PRINTF(stream, "oD"); return; } break; @@ -157,7 +166,7 @@ print_reg_type_nr(struct debug_stream *stream, unsigned type, unsigned nr) break; } - PRINTF("%s[%d]", regname[type], nr); + PRINTF(stream, "%s[%d]", regname[type], nr); } #define REG_SWIZZLE_MASK 0x7777 @@ -178,33 +187,33 @@ print_reg_neg_swizzle(struct debug_stream *stream, unsigned reg) (reg & REG_NEGATE_MASK) == 0) return; - PRINTF("."); + PRINTF(stream, "."); for (i = 3; i >= 0; i--) { if (reg & (1 << ((i * 4) + 3))) - PRINTF("-"); + PRINTF(stream, "-"); switch ((reg >> (i * 4)) & 0x7) { case 0: - PRINTF("x"); + PRINTF(stream, "x"); break; case 1: - PRINTF("y"); + PRINTF(stream, "y"); break; case 2: - PRINTF("z"); + PRINTF(stream, "z"); break; case 3: - PRINTF("w"); + PRINTF(stream, "w"); break; case 4: - PRINTF("0"); + PRINTF(stream, "0"); break; case 5: - PRINTF("1"); + PRINTF(stream, "1"); break; default: - PRINTF("?"); + PRINTF(stream, "?"); break; } } @@ -229,15 +238,15 @@ print_dest_reg(struct debug_stream *stream, unsigned dword) print_reg_type_nr(stream, type, nr); if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL) return; - PRINTF("."); + PRINTF(stream, "."); if (dword & A0_DEST_CHANNEL_X) - PRINTF("x"); + PRINTF(stream, "x"); if (dword & A0_DEST_CHANNEL_Y) - PRINTF("y"); + PRINTF(stream, "y"); if (dword & A0_DEST_CHANNEL_Z) - PRINTF("z"); + PRINTF(stream, "z"); if (dword & A0_DEST_CHANNEL_W) - PRINTF("w"); + PRINTF(stream, "w"); } @@ -253,29 +262,29 @@ print_arith_op(struct debug_stream *stream, if (opcode != A0_NOP) { print_dest_reg(stream, program[0]); if (program[0] & A0_DEST_SATURATE) - PRINTF(" = SATURATE "); + PRINTF(stream, " = SATURATE "); else - PRINTF(" = "); + PRINTF(stream, " = "); } - PRINTF("%s ", opcodes[opcode]); + PRINTF(stream, "%s ", opcodes[opcode]); print_src_reg(stream, GET_SRC0_REG(program[0], program[1])); if (args[opcode] == 1) { - PRINTF("\n"); + PRINTF(stream, "\n"); return; } - PRINTF(", "); + PRINTF(stream, ", "); print_src_reg(stream, GET_SRC1_REG(program[1], program[2])); if (args[opcode] == 2) { - PRINTF("\n"); + PRINTF(stream, "\n"); return; } - PRINTF(", "); + PRINTF(stream, ", "); print_src_reg(stream, GET_SRC2_REG(program[2])); - PRINTF("\n"); + PRINTF(stream, "\n"); return; } @@ -285,40 +294,40 @@ print_tex_op(struct debug_stream *stream, unsigned opcode, const unsigned * program) { print_dest_reg(stream, program[0] | A0_DEST_CHANNEL_ALL); - PRINTF(" = "); + PRINTF(stream, " = "); - PRINTF("%s ", opcodes[opcode]); + PRINTF(stream, "%s ", opcodes[opcode]); - PRINTF("S[%d],", program[0] & T0_SAMPLER_NR_MASK); + PRINTF(stream, "S[%d],", program[0] & T0_SAMPLER_NR_MASK); print_reg_type_nr(stream, (program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) & REG_TYPE_MASK, (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK); - PRINTF("\n"); + PRINTF(stream, "\n"); } static void print_texkil_op(struct debug_stream *stream, unsigned opcode, const unsigned * program) { - PRINTF("TEXKIL "); + PRINTF(stream, "TEXKIL "); print_reg_type_nr(stream, (program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) & REG_TYPE_MASK, (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK); - PRINTF("\n"); + PRINTF(stream, "\n"); } static void print_dcl_op(struct debug_stream *stream, unsigned opcode, const unsigned * program) { - PRINTF("%s ", opcodes[opcode]); + PRINTF(stream, "%s ", opcodes[opcode]); print_dest_reg(stream, program[0] | A0_DEST_CHANNEL_ALL); - PRINTF("\n"); + PRINTF(stream, "\n"); } @@ -327,9 +336,9 @@ i915_disassemble_program(struct debug_stream *stream, const unsigned * program, unsigned sz) { unsigned size = program[0] & 0x1ff; - int i; + unsigned i; - PRINTF("\t\tBEGIN\n"); + PRINTF(stream, "\t\tBEGIN\n"); assert(size + 2 == sz); @@ -337,7 +346,7 @@ i915_disassemble_program(struct debug_stream *stream, for (i = 1; i < sz; i += 3, program += 3) { unsigned opcode = program[0] & (0x1f << 24); - PRINTF("\t\t"); + PRINTF(stream, "\t\t"); if ((int) opcode >= A0_NOP && opcode <= A0_SLT) print_arith_op(stream, opcode >> 24, program); @@ -348,10 +357,10 @@ i915_disassemble_program(struct debug_stream *stream, else if (opcode == D0_DCL) print_dcl_op(stream, opcode >> 24, program); else - PRINTF("Unknown opcode 0x%x\n", opcode); + PRINTF(stream, "Unknown opcode 0x%x\n", opcode); } - PRINTF("\t\tEND\n\n"); + PRINTF(stream, "\t\tEND\n\n"); } diff --git a/src/mesa/pipe/i915simple/i915_flush.c b/src/mesa/pipe/i915simple/i915_flush.c index 1044cb1bdbd..3c2069b8273 100644 --- a/src/mesa/pipe/i915simple/i915_flush.c +++ b/src/mesa/pipe/i915simple/i915_flush.c @@ -69,8 +69,7 @@ static void i915_flush( struct pipe_context *pipe, FLUSH_BATCH(); if (flags & PIPE_FLUSH_WAIT) { - if( i915->last_fence ) - i915->winsys->fence_wait(i915->winsys, i915->last_fence); + i915->winsys->batch_finish(i915->winsys); } } diff --git a/src/mesa/pipe/i915simple/i915_fpc_emit.c b/src/mesa/pipe/i915simple/i915_fpc_emit.c index c8d36435d99..74924ff0a1d 100644 --- a/src/mesa/pipe/i915simple/i915_fpc_emit.c +++ b/src/mesa/pipe/i915simple/i915_fpc_emit.c @@ -235,7 +235,7 @@ uint i915_emit_texld( struct i915_fp_compile *p, uint i915_emit_const1f(struct i915_fp_compile * p, float c0) { - int reg, idx; + unsigned reg, idx; if (c0 == 0.0) return swizzle(UREG(REG_TYPE_R, 0), ZERO, ZERO, ZERO, ZERO); @@ -264,7 +264,7 @@ i915_emit_const1f(struct i915_fp_compile * p, float c0) uint i915_emit_const2f(struct i915_fp_compile * p, float c0, float c1) { - int reg, idx; + unsigned reg, idx; if (c0 == 0.0) return swizzle(i915_emit_const1f(p, c1), ZERO, X, Z, W); @@ -302,7 +302,7 @@ uint i915_emit_const4f(struct i915_fp_compile * p, float c0, float c1, float c2, float c3) { - int reg; + unsigned reg; for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { if (p->constant_flags[reg] == 0xf && diff --git a/src/mesa/pipe/i915simple/i915_fpc_translate.c b/src/mesa/pipe/i915simple/i915_fpc_translate.c index d74da852161..1cd554250cc 100644 --- a/src/mesa/pipe/i915simple/i915_fpc_translate.c +++ b/src/mesa/pipe/i915simple/i915_fpc_translate.c @@ -32,8 +32,8 @@ #include "i915_context.h" #include "i915_fpc.h" -#include "pipe/tgsi/exec/tgsi_token.h" -#include "pipe/tgsi/exec/tgsi_parse.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/tgsi/util/tgsi_parse.h" #include "pipe/draw/draw_vertex.h" @@ -69,16 +69,16 @@ static unsigned passthrough[] = /* 1, -1/3!, 1/5!, -1/7! */ static const float sin_constants[4] = { 1.0, - -1.0 / (3 * 2 * 1), - 1.0 / (5 * 4 * 3 * 2 * 1), - -1.0 / (7 * 6 * 5 * 4 * 3 * 2 * 1) + -1.0f / (3 * 2 * 1), + 1.0f / (5 * 4 * 3 * 2 * 1), + -1.0f / (7 * 6 * 5 * 4 * 3 * 2 * 1) }; /* 1, -1/2!, 1/4!, -1/6! */ static const float cos_constants[4] = { 1.0, - -1.0 / (2 * 1), - 1.0 / (4 * 3 * 2 * 1), - -1.0 / (6 * 5 * 4 * 3 * 2 * 1) + -1.0f / (2 * 1), + 1.0f / (4 * 3 * 2 * 1), + -1.0f / (6 * 5 * 4 * 3 * 2 * 1) }; @@ -102,7 +102,7 @@ i915_use_passthrough_shader(struct i915_context *i915) { fprintf(stderr, "**** Using i915 pass-through fragment shader\n"); - i915->current.program = (uint *) malloc(sizeof(passthrough)); + i915->current.program = (uint *) MALLOC(sizeof(passthrough)); if (i915->current.program) { memcpy(i915->current.program, passthrough, sizeof(passthrough)); i915->current.program_len = Elements(passthrough); @@ -117,11 +117,13 @@ void i915_program_error(struct i915_fp_compile *p, const char *msg, ...) { va_list args; + char buffer[1024]; fprintf(stderr, "i915_program_error: "); va_start( args, msg ); - vfprintf( stderr, msg, args ); + vsprintf( buffer, msg, args ); va_end( args ); + fprintf(stderr, buffer); fprintf(stderr, "\n"); p->error = 1; @@ -167,7 +169,7 @@ src_vector(struct i915_fp_compile *p, switch (sem_name) { case TGSI_SEMANTIC_POSITION: - printf("SKIP SEM POS\n"); + fprintf(stderr, "SKIP SEM POS\n"); /* assert(p->wpos_tex != -1); src = i915_emit_decl(p, REG_TYPE_T, p->wpos_tex, D0_CHANNEL_ALL); @@ -381,6 +383,9 @@ emit_simple_arith(struct i915_fp_compile *p, arg3 ); } +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif /* * Translate TGSI instruction to i915 instruction. @@ -430,7 +435,7 @@ i915_translate_instruction(struct i915_fp_compile *p, i915_emit_arith(p, A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, - src0, i915_emit_const1f(p, 1.0 / (M_PI * 2)), 0); + src0, i915_emit_const1f(p, 1.0f / (float) (M_PI * 2.0)), 0); i915_emit_arith(p, A0_MOD, tmp, A0_DEST_CHANNEL_X, 0, tmp, 0, 0); @@ -439,7 +444,7 @@ i915_translate_instruction(struct i915_fp_compile *p, i915_emit_arith(p, A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, - tmp, i915_emit_const1f(p, (M_PI * 2)), 0); + tmp, i915_emit_const1f(p, (float) (M_PI * 2.0)), 0); /* * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1 @@ -772,7 +777,7 @@ i915_translate_instruction(struct i915_fp_compile *p, i915_emit_arith(p, A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, - src0, i915_emit_const1f(p, 1.0 / (M_PI * 2)), 0); + src0, i915_emit_const1f(p, 1.0f / (float) (M_PI * 2.0)), 0); i915_emit_arith(p, A0_MOD, tmp, A0_DEST_CHANNEL_X, 0, tmp, 0, 0); @@ -781,7 +786,7 @@ i915_translate_instruction(struct i915_fp_compile *p, i915_emit_arith(p, A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, - tmp, i915_emit_const1f(p, (M_PI * 2)), 0); + tmp, i915_emit_const1f(p, (float) (M_PI * 2.0)), 0); /* * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1 @@ -986,8 +991,8 @@ i915_init_compile(struct i915_context *i915, static void i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) { - uint program_size = p->csr - p->program; - uint decl_size = p->decl - p->declarations; + unsigned long program_size = (unsigned long) (p->csr - p->program); + unsigned long decl_size = (unsigned long) (p->decl - p->declarations); if (p->nr_tex_indirect > I915_MAX_TEX_INDIRECT) i915_program_error(p, "Exceeded max nr indirect texture lookups"); @@ -1003,7 +1008,7 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) /* free old program, if present */ if (i915->current.program) { - free(i915->current.program); + FREE(i915->current.program); i915->current.program_len = 0; } @@ -1028,7 +1033,7 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) /* Copy compilation results to fragment program struct: */ i915->current.program - = (uint *) malloc((program_size + decl_size) * sizeof(uint)); + = (uint *) MALLOC((program_size + decl_size) * sizeof(uint)); if (i915->current.program) { i915->current.program_len = program_size + decl_size; @@ -1049,7 +1054,7 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) /* Release the compilation struct: */ - free(p); + FREE(p); } diff --git a/src/mesa/pipe/i915simple/i915_prim_vbuf.c b/src/mesa/pipe/i915simple/i915_prim_vbuf.c index 35174c64a01..08ac5b672c3 100644 --- a/src/mesa/pipe/i915simple/i915_prim_vbuf.c +++ b/src/mesa/pipe/i915simple/i915_prim_vbuf.c @@ -38,16 +38,12 @@ */ -#include "pipe/draw/draw_private.h" -#include "pipe/draw/draw_vertex.h" +#include + +#include "pipe/draw/draw_vbuf.h" #include "pipe/p_util.h" #include "pipe/p_winsys.h" -#include "softpipe/sp_context.h" -#include "softpipe/sp_headers.h" -#include "softpipe/sp_quad.h" -#include "softpipe/sp_prim_setup.h" - #include "i915_context.h" #include "i915_reg.h" #include "i915_winsys.h" @@ -55,253 +51,99 @@ #include "i915_state.h" -static void vbuf_flush_elements( struct draw_stage *stage ); -static void vbuf_flush_vertices( struct draw_stage *stage ); - - -#define VBUF_SIZE (128*1024) -#define IBUF_SIZE (16*1024) - - /** - * Vertex buffer emit stage. + * Primitive renderer for i915. */ -struct vbuf_stage { - struct draw_stage stage; /**< This must be first (base class) */ +struct i915_vbuf_render { + struct vbuf_render base; + + struct i915_context *i915; /** Vertex size in bytes */ unsigned vertex_size; - /* FIXME: we have no guarantee that 'unsigned' is 32bit */ - - /** Vertices in hardware format */ - unsigned *vertex_map; - unsigned *vertex_ptr; - unsigned max_vertices; - unsigned nr_vertices; - - ushort *element_map; - unsigned nr_elements; - - unsigned prim; - - struct i915_context *i915; + /** Hardware primitive */ + unsigned hwprim; }; /** * Basically a cast wrapper. */ -static INLINE struct vbuf_stage *vbuf_stage( struct draw_stage *stage ) -{ - return (struct vbuf_stage *)stage; -} - - -static INLINE boolean -overflow( void *map, void *ptr, unsigned bytes, unsigned bufsz ) -{ - unsigned long used = (char *)ptr - (char *)map; - return (used + bytes) > bufsz; -} - - -static INLINE void -check_space( struct vbuf_stage *vbuf, unsigned nr ) -{ - if (overflow( vbuf->vertex_map, - vbuf->vertex_ptr, - nr*vbuf->vertex_size, - VBUF_SIZE )) - vbuf_flush_vertices(&vbuf->stage); - - if (vbuf->nr_elements + nr > IBUF_SIZE / sizeof(ushort) ) - vbuf_flush_elements(&vbuf->stage); -} - - -/** - * Extract the needed fields from vertex_header and emit i915 dwords. - * Recall that the vertices are constructed by the 'draw' module and - * have a couple of slots at the beginning (1-dword header, 4-dword - * clip pos) that we ignore here. - */ -static INLINE void -emit_vertex( struct vbuf_stage *vbuf, - struct vertex_header *vertex ) +static INLINE struct i915_vbuf_render * +i915_vbuf_render( struct vbuf_render *render ) { - struct i915_context *i915 = vbuf->i915; - const struct vertex_info *vinfo = &i915->current.vertex_info; - uint i; - uint count = 0; /* for debug/sanity */ - -// fprintf(stderr, "emit vertex %d to %p\n", -// vbuf->nr_vertices, vbuf->vertex_ptr); - - if(vertex->vertex_id != UNDEFINED_VERTEX_ID) { - if(vertex->vertex_id < vbuf->nr_vertices) - return; - else - fprintf(stderr, "Bad vertex id 0x%04x (>= 0x%04x)\n", - vertex->vertex_id, vbuf->nr_vertices); - return; - } - - vertex->vertex_id = vbuf->nr_vertices++; - - for (i = 0; i < vinfo->num_attribs; i++) { - switch (vinfo->format[i]) { - case FORMAT_OMIT: - /* no-op */ - break; - case FORMAT_1F: - *vbuf->vertex_ptr++ = fui(vertex->data[i][0]); - count++; - break; - case FORMAT_2F: - *vbuf->vertex_ptr++ = fui(vertex->data[i][0]); - *vbuf->vertex_ptr++ = fui(vertex->data[i][1]); - count += 2; - break; - case FORMAT_3F: - *vbuf->vertex_ptr++ = fui(vertex->data[i][0]); - *vbuf->vertex_ptr++ = fui(vertex->data[i][1]); - *vbuf->vertex_ptr++ = fui(vertex->data[i][2]); - count += 3; - break; - case FORMAT_4F: - *vbuf->vertex_ptr++ = fui(vertex->data[i][0]); - *vbuf->vertex_ptr++ = fui(vertex->data[i][1]); - *vbuf->vertex_ptr++ = fui(vertex->data[i][2]); - *vbuf->vertex_ptr++ = fui(vertex->data[i][3]); - count += 4; - break; - case FORMAT_4UB: - *vbuf->vertex_ptr++ = pack_ub4(float_to_ubyte( vertex->data[i][2] ), - float_to_ubyte( vertex->data[i][1] ), - float_to_ubyte( vertex->data[i][0] ), - float_to_ubyte( vertex->data[i][3] )); - count += 1; - break; - default: - assert(0); - } - } - assert(count == vinfo->size); + assert(render); + return (struct i915_vbuf_render *)render; } -static void vbuf_tri( struct draw_stage *stage, - struct prim_header *prim ) +static const struct vertex_info * +i915_vbuf_render_get_vertex_info( struct vbuf_render *render ) { - struct vbuf_stage *vbuf = vbuf_stage( stage ); - unsigned i; - - check_space( vbuf, 3 ); - - for (i = 0; i < 3; i++) { - emit_vertex( vbuf, prim->v[i] ); - - vbuf->element_map[vbuf->nr_elements++] = prim->v[i]->vertex_id; - } + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + return &i915->current.vertex_info; } -static void vbuf_line(struct draw_stage *stage, - struct prim_header *prim) +static void * +i915_vbuf_render_allocate_vertices( struct vbuf_render *render, + ushort vertex_size, + ushort nr_vertices ) { - struct vbuf_stage *vbuf = vbuf_stage( stage ); - unsigned i; - - check_space( vbuf, 2 ); - - for (i = 0; i < 2; i++) { - emit_vertex( vbuf, prim->v[i] ); - - vbuf->element_map[vbuf->nr_elements++] = prim->v[i]->vertex_id; - } -} - - -static void vbuf_point(struct draw_stage *stage, - struct prim_header *prim) -{ - struct vbuf_stage *vbuf = vbuf_stage( stage ); - - check_space( vbuf, 1 ); + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + struct pipe_winsys *winsys = i915->pipe.winsys; + size_t size = (size_t)vertex_size * (size_t)nr_vertices; - emit_vertex( vbuf, prim->v[0] ); + /* FIXME: handle failure */ + assert(!i915->vbo); + i915->vbo = winsys->buffer_create(winsys, 64); + winsys->buffer_data( winsys, i915->vbo, + size, NULL, + I915_BUFFER_USAGE_LIT_VERTEX ); - vbuf->element_map[vbuf->nr_elements++] = prim->v[0]->vertex_id; -} - - -static void vbuf_first_tri( struct draw_stage *stage, - struct prim_header *prim ) -{ - struct vbuf_stage *vbuf = vbuf_stage( stage ); - - vbuf_flush_elements( stage ); - stage->tri = vbuf_tri; - stage->tri( stage, prim ); - vbuf->prim = PIPE_PRIM_TRIANGLES; -} - - -static void vbuf_first_line( struct draw_stage *stage, - struct prim_header *prim ) -{ - struct vbuf_stage *vbuf = vbuf_stage( stage ); - - vbuf_flush_elements( stage ); - stage->line = vbuf_line; - stage->line( stage, prim ); - vbuf->prim = PIPE_PRIM_LINES; -} - - -static void vbuf_first_point( struct draw_stage *stage, - struct prim_header *prim ) -{ - struct vbuf_stage *vbuf = vbuf_stage( stage ); - - vbuf_flush_elements( stage ); - stage->point = vbuf_point; - stage->point( stage, prim ); - vbuf->prim = PIPE_PRIM_POINTS; + i915->dirty |= I915_NEW_VBO; + + return winsys->buffer_map(winsys, + i915->vbo, + PIPE_BUFFER_FLAG_WRITE ); } -static void vbuf_flush_elements( struct draw_stage *stage ) +static void +i915_vbuf_render_set_primitive( struct vbuf_render *render, + unsigned prim ) { - struct vbuf_stage *vbuf = vbuf_stage( stage ); - struct i915_context *i915 = vbuf->i915; - unsigned nr = vbuf->nr_elements; - unsigned vertex_size = i915->current.vertex_info.size * 4; /* in bytes */ - unsigned hwprim; - unsigned i; + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); - if(!nr) - return; - - switch(vbuf->prim) { + switch(prim) { case PIPE_PRIM_POINTS: - hwprim = PRIM3D_POINTLIST; + i915_render->hwprim = PRIM3D_POINTLIST; break; case PIPE_PRIM_LINES: - hwprim = PRIM3D_LINELIST; - assert(nr % 2 == 0); + i915_render->hwprim = PRIM3D_LINELIST; break; case PIPE_PRIM_TRIANGLES: - hwprim = PRIM3D_TRILIST; - assert(nr % 3 == 0); + i915_render->hwprim = PRIM3D_TRILIST; break; default: assert(0); - return; } - - assert(vbuf->vertex_ptr - vbuf->vertex_map == vbuf->nr_vertices * vertex_size / 4); +} + + +static void +i915_vbuf_render_draw( struct vbuf_render *render, + const ushort *indices, + unsigned nr_indices ) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + unsigned i; + + assert(nr_indices); assert((i915->dirty & ~I915_NEW_VBO) == 0); @@ -311,7 +153,7 @@ static void vbuf_flush_elements( struct draw_stage *stage ) if (i915->hardware_dirty) i915_emit_hardware_state( i915 ); - if (!BEGIN_BATCH( 1 + (nr + 1)/2, 1 )) { + if (!BEGIN_BATCH( 1 + (nr_indices + 1)/2, 1 )) { FLUSH_BATCH(); /* Make sure state is re-emitted after a flush: @@ -319,7 +161,7 @@ static void vbuf_flush_elements( struct draw_stage *stage ) i915_update_derived( i915 ); i915_emit_hardware_state( i915 ); - if (!BEGIN_BATCH( 1 + (nr + 1)/2, 1 )) { + if (!BEGIN_BATCH( 1 + (nr_indices + 1)/2, 1 )) { assert(0); return; } @@ -327,95 +169,68 @@ static void vbuf_flush_elements( struct draw_stage *stage ) OUT_BATCH( _3DPRIMITIVE | PRIM_INDIRECT | - hwprim | + i915_render->hwprim | PRIM_INDIRECT_ELTS | - nr ); - for (i = 0; i + 1 < nr; i += 2) { - OUT_BATCH( vbuf->element_map[i] | - (vbuf->element_map[i + 1] << 16) ); + nr_indices ); + for (i = 0; i + 1 < nr_indices; i += 2) { + OUT_BATCH( indices[i] | + (indices[i + 1] << 16) ); } - if (i < nr) { - OUT_BATCH( vbuf->element_map[i] ); + if (i < nr_indices) { + OUT_BATCH( indices[i] ); } - - vbuf->nr_elements = 0; } - -/** - * Flush vertex buffer. - */ -static void vbuf_flush_vertices( struct draw_stage *stage ) +static void +i915_vbuf_render_release_vertices( struct vbuf_render *render, + void *vertices, + unsigned vertex_size, + unsigned vertices_used ) { - struct vbuf_stage *vbuf = vbuf_stage( stage ); - struct i915_context *i915 = vbuf->i915; + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; struct pipe_winsys *winsys = i915->pipe.winsys; - if(vbuf->nr_vertices) { - - vbuf_flush_elements(stage); - - winsys->buffer_unmap(winsys, i915->vbo); - - vbuf->nr_vertices = 0; - - /** - * XXX: Reset vertex ids? Actually, want to not do that unless our - * vertex buffer is full. Would like separate - * flush-on-index-full and flush-on-vb-full, but may raise - * issues uploading vertices if the hardware wants to flush when - * we flush. - */ - draw_reset_vertex_ids( vbuf->i915->draw ); - } - - /* FIXME: handle failure */ - if(!i915->vbo) - i915->vbo = winsys->buffer_create(winsys, 64); - winsys->buffer_data( winsys, i915->vbo, - VBUF_SIZE, NULL, - I915_BUFFER_USAGE_LIT_VERTEX ); - - i915->dirty |= I915_NEW_VBO; - - vbuf->vertex_map = winsys->buffer_map(winsys, - i915->vbo, - PIPE_BUFFER_FLAG_WRITE ); - vbuf->vertex_ptr = vbuf->vertex_map; + assert(i915->vbo); + winsys->buffer_unmap(winsys, i915->vbo); + winsys->buffer_reference(winsys, &i915->vbo, NULL); } - -static void vbuf_begin( struct draw_stage *stage ) +static void +i915_vbuf_render_destroy( struct vbuf_render *render ) { - struct vbuf_stage *vbuf = vbuf_stage(stage); - struct i915_context *i915 = vbuf->i915; - unsigned vertex_size = i915->current.vertex_info.size * 4; - - assert(!i915->dirty); - - if(vbuf->vertex_size != vertex_size) - vbuf_flush_vertices(stage); - - vbuf->vertex_size = vertex_size; + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + free(i915_render); } -static void vbuf_end( struct draw_stage *stage ) +/** + * Create a new primitive render. + */ +static struct vbuf_render * +i915_vbuf_render_create( struct i915_context *i915 ) { - /* Overkill. + struct i915_vbuf_render *i915_render = CALLOC_STRUCT(i915_vbuf_render); + + i915_render->i915 = i915; + + i915_render->base.max_vertex_buffer_bytes = 128*1024; + + /* NOTE: it must be such that state and vertices indices fit in a single + * batch buffer. */ - vbuf_flush_elements( stage ); + i915_render->base.max_indices = 16*1024; - stage->point = vbuf_first_point; - stage->line = vbuf_first_line; - stage->tri = vbuf_first_tri; -} - - -static void reset_stipple_counter( struct draw_stage *stage ) -{ + i915_render->base.get_vertex_info = i915_vbuf_render_get_vertex_info; + i915_render->base.allocate_vertices = i915_vbuf_render_allocate_vertices; + i915_render->base.set_primitive = i915_vbuf_render_set_primitive; + i915_render->base.draw = i915_vbuf_render_draw; + i915_render->base.release_vertices = i915_vbuf_render_release_vertices; + i915_render->base.destroy = i915_vbuf_render_destroy; + + return &i915_render->base; } @@ -424,24 +239,18 @@ static void reset_stipple_counter( struct draw_stage *stage ) */ struct draw_stage *i915_draw_vbuf_stage( struct i915_context *i915 ) { - struct vbuf_stage *vbuf = CALLOC_STRUCT(vbuf_stage); - - vbuf->i915 = i915; - vbuf->stage.draw = i915->draw; - vbuf->stage.begin = vbuf_begin; - vbuf->stage.point = vbuf_first_point; - vbuf->stage.line = vbuf_first_line; - vbuf->stage.tri = vbuf_first_tri; - vbuf->stage.end = vbuf_end; - vbuf->stage.reset_stipple_counter = reset_stipple_counter; - - assert(IBUF_SIZE < UNDEFINED_VERTEX_ID); - - /* FIXME: free this memory on takedown */ - vbuf->element_map = malloc( IBUF_SIZE ); - vbuf->vertex_map = NULL; + struct vbuf_render *render; + struct draw_stage *stage; - vbuf->vertex_ptr = vbuf->vertex_map; + render = i915_vbuf_render_create(i915); + if(!render) + return NULL; - return &vbuf->stage; + stage = draw_vbuf_stage( i915->draw, render ); + if(!stage) { + render->destroy(render); + return NULL; + } + + return stage; } diff --git a/src/mesa/pipe/i915simple/i915_regions.c b/src/mesa/pipe/i915simple/i915_regions.c deleted file mode 100644 index 04104463263..00000000000 --- a/src/mesa/pipe/i915simple/i915_regions.c +++ /dev/null @@ -1,250 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 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. - * - **************************************************************************/ - -/* Provide additional functionality on top of bufmgr buffers: - * - 2d semantics and blit operations (XXX: remove/simplify blits??) - * - refcounting of buffers for multiple images in a buffer. - * - refcounting of buffer mappings. - */ - -#include "pipe/p_defines.h" -#include "pipe/p_winsys.h" -#include "i915_context.h" -#include "i915_blit.h" - - - - -static ubyte * -i915_region_map(struct pipe_context *pipe, struct pipe_region *region) -{ - struct i915_context *i915 = i915_context( pipe ); - - if (!region->map_refcount++) { - region->map = i915->pipe.winsys->buffer_map( i915->pipe.winsys, - region->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ); - } - - return region->map; -} - -static void -i915_region_unmap(struct pipe_context *pipe, struct pipe_region *region) -{ - struct i915_context *i915 = i915_context( pipe ); - - if (region->map_refcount > 0) { - assert(region->map); - if (!--region->map_refcount) { - i915->pipe.winsys->buffer_unmap( i915->pipe.winsys, - region->buffer ); - region->map = NULL; - } - } -} - - -/* - * XXX Move this into core Mesa? - */ -static void -_mesa_copy_rect(ubyte * dst, - unsigned cpp, - unsigned dst_pitch, - unsigned dst_x, - unsigned dst_y, - unsigned width, - unsigned height, - const ubyte * src, - unsigned src_pitch, - unsigned src_x, - unsigned src_y) -{ - unsigned i; - - dst_pitch *= cpp; - src_pitch *= cpp; - dst += dst_x * cpp; - src += src_x * cpp; - dst += dst_y * dst_pitch; - src += src_y * dst_pitch; - width *= cpp; - - if (width == dst_pitch && width == src_pitch) - memcpy(dst, src, height * width); - else { - for (i = 0; i < height; i++) { - memcpy(dst, src, width); - dst += dst_pitch; - src += src_pitch; - } - } -} - - -/* Upload data to a rectangular sub-region. Lots of choices how to do this: - * - * - memcpy by span to current destination - * - upload data as new buffer and blit - * - * Currently always memcpy. - */ -static void -i915_region_data(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - const void *src, unsigned src_pitch, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - _mesa_copy_rect(pipe->region_map(pipe, dst) + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, width, height, src, src_pitch, srcx, srcy); - - pipe->region_unmap(pipe, dst); -} - - -/* Assumes all values are within bounds -- no checking at this level - - * do it higher up if required. - */ -static void -i915_region_copy(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - struct pipe_region *src, - unsigned src_offset, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - assert( dst != src ); - assert( dst->cpp == src->cpp ); - - if (0) { - _mesa_copy_rect(pipe->region_map(pipe, dst) + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, - width, height, - pipe->region_map(pipe, src) + src_offset, - src->pitch, - srcx, srcy); - - pipe->region_unmap(pipe, src); - pipe->region_unmap(pipe, dst); - } - else { - i915_copy_blit( i915_context(pipe), - dst->cpp, - src->pitch, src->buffer, src_offset, - dst->pitch, dst->buffer, dst_offset, - srcx, srcy, dstx, dsty, width, height ); - } -} - -/* 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_region *dst, unsigned x, unsigned y) -{ - return dst->map + (y * dst->pitch + x) * dst->cpp; -} - - -static void -i915_region_fill(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, unsigned value) -{ - if (0) { - unsigned i, j; - - (void)pipe->region_map(pipe, dst); - - switch (dst->cpp) { - case 1: { - ubyte *row = get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - memset(row, value, width); - row += dst->pitch; - } - } - break; - case 2: { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = value; - row += dst->pitch; - } - } - break; - case 4: { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = value; - row += dst->pitch; - } - } - break; - default: - assert(0); - break; - } - } - else { - i915_fill_blit( i915_context(pipe), - dst->cpp, - dst->pitch, - dst->buffer, dst_offset, - dstx, dsty, - width, height, - value ); - } -} - - - - - -void -i915_init_region_functions(struct i915_context *i915) -{ - i915->pipe.region_map = i915_region_map; - i915->pipe.region_unmap = i915_region_unmap; - i915->pipe.region_data = i915_region_data; - i915->pipe.region_copy = i915_region_copy; - i915->pipe.region_fill = i915_region_fill; -} - diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 70b8195bf1d..038fd623ea1 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -97,7 +97,7 @@ static void * i915_create_blend_state(struct pipe_context *pipe, const struct pipe_blend_state *blend) { - struct i915_blend_state *cso_data = calloc(1, sizeof(struct i915_blend_state)); + struct i915_blend_state *cso_data = CALLOC_STRUCT( i915_blend_state ); { unsigned eqRGB = blend->rgb_func; @@ -182,7 +182,7 @@ static void i915_bind_blend_state(struct pipe_context *pipe, static void i915_delete_blend_state(struct pipe_context *pipe, void *blend) { - free(blend); + FREE(blend); } static void i915_set_blend_color( struct pipe_context *pipe, @@ -199,15 +199,15 @@ static void * i915_create_sampler_state(struct pipe_context *pipe, const struct pipe_sampler_state *sampler) { - struct i915_sampler_state *cso = calloc(1, sizeof(struct i915_sampler_state)); - cso->templ = sampler; - + struct i915_sampler_state *cso = CALLOC_STRUCT( i915_sampler_state ); const unsigned ws = sampler->wrap_s; const unsigned wt = sampler->wrap_t; const unsigned wr = sampler->wrap_r; unsigned minFilt, magFilt; unsigned mipFilt; + cso->templ = sampler; + mipFilt = translate_mip_filter(sampler->min_mip_filter); if (sampler->max_anisotropy > 1.0) { minFilt = FILTER_ANISOTROPIC; @@ -222,7 +222,7 @@ i915_create_sampler_state(struct pipe_context *pipe, } { - int b = sampler->lod_bias * 16.0; + int b = (int) (sampler->lod_bias * 16.0); b = CLAMP(b, -256, 255); cso->state[0] |= ((b << SS2_LOD_BIAS_SHIFT) & SS2_LOD_BIAS_MASK); } @@ -274,7 +274,7 @@ static void i915_bind_sampler_state(struct pipe_context *pipe, static void i915_delete_sampler_state(struct pipe_context *pipe, void *sampler) { - free(sampler); + FREE(sampler); } @@ -286,7 +286,7 @@ static void * i915_create_depth_stencil_state(struct pipe_context *pipe, const struct pipe_depth_stencil_state *depth_stencil) { - struct i915_depth_stencil_state *cso = calloc(1, sizeof(struct i915_depth_stencil_state)); + struct i915_depth_stencil_state *cso = CALLOC_STRUCT( i915_depth_stencil_state ); { int testmask = depth_stencil->stencil.value_mask[0] & 0xff; @@ -379,7 +379,7 @@ static void i915_bind_depth_stencil_state(struct pipe_context *pipe, static void i915_delete_depth_stencil_state(struct pipe_context *pipe, void *depth_stencil) { - free(depth_stencil); + FREE(depth_stencil); } @@ -387,7 +387,7 @@ static void * i915_create_alpha_test_state(struct pipe_context *pipe, const struct pipe_alpha_test_state *alpha_test) { - struct i915_alpha_test_state *cso = calloc(1, sizeof(struct i915_alpha_test_state)); + struct i915_alpha_test_state *cso = CALLOC_STRUCT( i915_alpha_test_state ); if (alpha_test->enabled) { int test = i915_translate_compare_func(alpha_test->func); @@ -413,7 +413,7 @@ static void i915_bind_alpha_test_state(struct pipe_context *pipe, static void i915_delete_alpha_test_state(struct pipe_context *pipe, void *alpha) { - free(alpha); + FREE(alpha); } static void i915_set_scissor_state( struct pipe_context *pipe, @@ -525,11 +525,11 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, static void i915_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct i915_context *i915 = i915_context(pipe); - i915->texture[unit] = texture; /* ptr, not struct */ + i915->texture[unit] = (struct i915_texture*)texture; /* ptr, not struct */ i915->dirty |= I915_NEW_TEXTURE; } @@ -619,7 +619,7 @@ static void * i915_create_rasterizer_state(struct pipe_context *pipe, const struct pipe_rasterizer_state *rasterizer) { - struct i915_rasterizer_state *cso = calloc(1, sizeof(struct i915_rasterizer_state)); + struct i915_rasterizer_state *cso = CALLOC_STRUCT( i915_rasterizer_state ); cso->templ = rasterizer; cso->color_interp = rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; @@ -671,7 +671,7 @@ i915_create_rasterizer_state(struct pipe_context *pipe, S4_FLATSHADE_SPECULAR); } - cso->LIS7 = rasterizer->offset_units; /* probably incorrect */ + cso->LIS7 = fui( rasterizer->offset_units ); return cso; @@ -693,7 +693,7 @@ static void i915_bind_rasterizer_state( struct pipe_context *pipe, static void i915_delete_rasterizer_state(struct pipe_context *pipe, void *setup) { - free(setup); + FREE(setup); } static void i915_set_vertex_buffer( struct pipe_context *pipe, diff --git a/src/mesa/pipe/i915simple/i915_state_derived.c b/src/mesa/pipe/i915simple/i915_state_derived.c index ed1521fcce2..be73769cf2f 100644 --- a/src/mesa/pipe/i915simple/i915_state_derived.c +++ b/src/mesa/pipe/i915simple/i915_state_derived.c @@ -33,7 +33,7 @@ #include "i915_state.h" #include "i915_reg.h" #include "i915_fpc.h" -#include "pipe/tgsi/exec/tgsi_token.h" +#include "pipe/p_shader_tokens.h" /** @@ -132,11 +132,8 @@ static void calculate_vertex_layout( struct i915_context *i915 ) /* If the attributes have changed, tell the draw module about the new * vertex layout. We'll also update the hardware vertex format info. */ - draw_set_vertex_attributes( i915->draw, - NULL,/*vinfo.slot_to_attrib,*/ - vinfo.interp_mode, - vinfo.num_attribs); - + draw_set_vertex_info( i915->draw, &vinfo); + draw_set_twoside_attributes(i915->draw, front0, back0, front1, back1); diff --git a/src/mesa/pipe/i915simple/i915_state_dynamic.c b/src/mesa/pipe/i915simple/i915_state_dynamic.c index 845873baa04..8cfbdddd19b 100644 --- a/src/mesa/pipe/i915simple/i915_state_dynamic.c +++ b/src/mesa/pipe/i915simple/i915_state_dynamic.c @@ -45,12 +45,12 @@ * (active) state every time a 4kb boundary is crossed. */ -static inline void set_dynamic_indirect( struct i915_context *i915, +static INLINE void set_dynamic_indirect( struct i915_context *i915, unsigned offset, const unsigned *src, unsigned dwords ) { - int i; + unsigned i; for (i = 0; i < dwords; i++) i915->current.dynamic[offset + i] = src[i]; @@ -80,8 +80,8 @@ static void upload_MODES4( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_MODES4 = { - .dirty = I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL, - .update = upload_MODES4 + I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL, + upload_MODES4 }; @@ -99,8 +99,8 @@ static void upload_BFO( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_BFO = { - .dirty = I915_NEW_DEPTH_STENCIL, - .update = upload_BFO + I915_NEW_DEPTH_STENCIL, + upload_BFO }; @@ -133,8 +133,8 @@ static void upload_BLENDCOLOR( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_BLENDCOLOR = { - .dirty = I915_NEW_BLEND, - .update = upload_BLENDCOLOR + I915_NEW_BLEND, + upload_BLENDCOLOR }; /*********************************************************************** @@ -153,8 +153,8 @@ static void upload_IAB( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_IAB = { - .dirty = I915_NEW_BLEND, - .update = upload_IAB + I915_NEW_BLEND, + upload_IAB }; @@ -172,8 +172,8 @@ static void upload_DEPTHSCALE( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_DEPTHSCALE = { - .dirty = I915_NEW_RASTERIZER, - .update = upload_DEPTHSCALE + I915_NEW_RASTERIZER, + upload_DEPTHSCALE }; @@ -230,8 +230,8 @@ static void upload_STIPPLE( struct i915_context *i915 ) const struct i915_tracked_state i915_upload_STIPPLE = { - .dirty = I915_NEW_RASTERIZER | I915_NEW_STIPPLE, - .update = upload_STIPPLE + I915_NEW_RASTERIZER | I915_NEW_STIPPLE, + upload_STIPPLE }; @@ -248,8 +248,8 @@ static void upload_SCISSOR_ENABLE( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_SCISSOR_ENABLE = { - .dirty = I915_NEW_RASTERIZER, - .update = upload_SCISSOR_ENABLE + I915_NEW_RASTERIZER, + upload_SCISSOR_ENABLE }; @@ -274,8 +274,8 @@ static void upload_SCISSOR_RECT( struct i915_context *i915 ) const struct i915_tracked_state i915_upload_SCISSOR_RECT = { - .dirty = I915_NEW_SCISSOR, - .update = upload_SCISSOR_RECT + I915_NEW_SCISSOR, + upload_SCISSOR_RECT }; diff --git a/src/mesa/pipe/i915simple/i915_state_emit.c b/src/mesa/pipe/i915simple/i915_state_emit.c index d793e92a14d..09bf1fa2d68 100644 --- a/src/mesa/pipe/i915simple/i915_state_emit.c +++ b/src/mesa/pipe/i915simple/i915_state_emit.c @@ -35,12 +35,12 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -static unsigned translate_format( unsigned format ) +static unsigned translate_format( enum pipe_format format ) { switch (format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: return COLOR_BUF_ARGB8888; - case PIPE_FORMAT_U_R5_G6_B5: + case PIPE_FORMAT_R5G6B5_UNORM: return COLOR_BUF_RGB565; default: assert(0); @@ -48,12 +48,12 @@ static unsigned translate_format( unsigned format ) } } -static unsigned translate_depth_format( unsigned zformat ) +static unsigned translate_depth_format( enum pipe_format zformat ) { switch (zformat) { - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: return DEPTH_FRMT_24_FIXED_8_OTHER; - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: return DEPTH_FRMT_16_FIXED; default: assert(0); @@ -208,10 +208,11 @@ i915_emit_hardware_state(struct i915_context *i915 ) /* 8 dwords, 2 relocs */ if (i915->hardware_dirty & I915_HW_STATIC) { - if (i915->framebuffer.cbufs[0]) { - struct pipe_region *cbuf_region = i915->framebuffer.cbufs[0]->region; - unsigned pitch = (cbuf_region->pitch * - cbuf_region->cpp); + struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0]; + struct pipe_surface *depth_surface = i915->framebuffer.zbuf; + + if (cbuf_surface) { + unsigned pitch = (cbuf_surface->pitch * cbuf_surface->cpp); OUT_BATCH(_3DSTATE_BUF_INFO_CMD); @@ -219,17 +220,15 @@ i915_emit_hardware_state(struct i915_context *i915 ) BUF_3D_PITCH(pitch) | /* pitch in bytes */ BUF_3D_USE_FENCE); - OUT_RELOC(cbuf_region->buffer, + OUT_RELOC(cbuf_surface->buffer, I915_BUFFER_ACCESS_WRITE, 0); } /* What happens if no zbuf?? */ - if (i915->framebuffer.zbuf) { - struct pipe_region *depth_region = i915->framebuffer.zbuf->region; - unsigned zpitch = (depth_region->pitch * - depth_region->cpp); + if (depth_surface) { + unsigned zpitch = (depth_surface->pitch * depth_surface->cpp); OUT_BATCH(_3DSTATE_BUF_INFO_CMD); @@ -237,7 +236,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) BUF_3D_PITCH(zpitch) | /* pitch in bytes */ BUF_3D_USE_FENCE); - OUT_RELOC(depth_region->buffer, + OUT_RELOC(depth_surface->buffer, I915_BUFFER_ACCESS_WRITE, 0); } @@ -245,13 +244,13 @@ i915_emit_hardware_state(struct i915_context *i915 ) { unsigned cformat, zformat = 0; - if (i915->framebuffer.cbufs[0]) - cformat = i915->framebuffer.cbufs[0]->format; + if (cbuf_surface) + cformat = cbuf_surface->format; else - cformat = PIPE_FORMAT_U_A8_R8_G8_B8; /* arbitrary */ + cformat = PIPE_FORMAT_A8R8G8B8_UNORM; /* arbitrary */ cformat = translate_format(cformat); - if (i915->framebuffer.zbuf) + if (depth_surface) zformat = translate_depth_format( i915->framebuffer.zbuf->format ); OUT_BATCH(_3DSTATE_DST_BUF_VARS_CMD); @@ -285,7 +284,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) for (unit = 0; unit < I915_TEX_UNITS; unit++) { if (enabled & (1 << unit)) { struct pipe_buffer_handle *buf = - i915->texture[unit]->region->buffer; + i915->texture[unit]->buffer; uint offset = 0; assert(buf); diff --git a/src/mesa/pipe/i915simple/i915_state_immediate.c b/src/mesa/pipe/i915simple/i915_state_immediate.c index d830bb78e8f..da2402c0188 100644 --- a/src/mesa/pipe/i915simple/i915_state_immediate.c +++ b/src/mesa/pipe/i915simple/i915_state_immediate.c @@ -78,8 +78,8 @@ static void upload_S0S1(struct i915_context *i915) } const struct i915_tracked_state i915_upload_S0S1 = { - .dirty = I915_NEW_VBO | I915_NEW_VERTEX_FORMAT, - .update = upload_S0S1 + I915_NEW_VBO | I915_NEW_VERTEX_FORMAT, + upload_S0S1 }; @@ -115,8 +115,8 @@ static void upload_S2S4(struct i915_context *i915) const struct i915_tracked_state i915_upload_S2S4 = { - .dirty = I915_NEW_RASTERIZER | I915_NEW_VERTEX_FORMAT, - .update = upload_S2S4 + I915_NEW_RASTERIZER | I915_NEW_VERTEX_FORMAT, + upload_S2S4 }; @@ -147,8 +147,8 @@ static void upload_S5( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_S5 = { - .dirty = (I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_RASTERIZER), - .update = upload_S5 + (I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_RASTERIZER), + upload_S5 }; @@ -178,8 +178,8 @@ static void upload_S6( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_S6 = { - .dirty = I915_NEW_ALPHA_TEST | I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL, - .update = upload_S6 + I915_NEW_ALPHA_TEST | I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL, + upload_S6 }; @@ -187,11 +187,11 @@ const struct i915_tracked_state i915_upload_S6 = { */ static void upload_S7( struct i915_context *i915 ) { - float LIS7; + unsigned LIS7; /* I915_NEW_RASTERIZER */ - LIS7 = i915->rasterizer->LIS7; /* probably incorrect */ + LIS7 = i915->rasterizer->LIS7; if (LIS7 != i915->current.immediate[I915_IMMEDIATE_S7]) { i915->current.immediate[I915_IMMEDIATE_S7] = LIS7; @@ -200,8 +200,8 @@ static void upload_S7( struct i915_context *i915 ) } const struct i915_tracked_state i915_upload_S7 = { - .dirty = I915_NEW_RASTERIZER, - .update = upload_S7 + I915_NEW_RASTERIZER, + upload_S7 }; diff --git a/src/mesa/pipe/i915simple/i915_state_sampler.c b/src/mesa/pipe/i915simple/i915_state_sampler.c index 0991e6ac0d1..59408b6ba06 100644 --- a/src/mesa/pipe/i915simple/i915_state_sampler.c +++ b/src/mesa/pipe/i915simple/i915_state_sampler.c @@ -46,9 +46,11 @@ static void update_sampler(struct i915_context *i915, uint unit, const struct i915_sampler_state *sampler, - const struct pipe_mipmap_tree *mt, + const struct i915_texture *tex, unsigned state[3] ) { + const struct pipe_texture *pt = &tex->base; + /* Need to do this after updating the maps, which call the * intel_finalize_mipmap_tree and hence can update firstLevel: */ @@ -56,8 +58,8 @@ static void update_sampler(struct i915_context *i915, state[1] = sampler->state[1]; state[2] = sampler->state[2]; - if (mt->format == PIPE_FORMAT_YCBCR || - mt->format == PIPE_FORMAT_YCBCR_REV) + if (pt->format == PIPE_FORMAT_YCBCR || + pt->format == PIPE_FORMAT_YCBCR_REV) state[0] |= SS2_COLORSPACE_CONVERSION; /* 3D textures don't seem to respect the border color. @@ -75,7 +77,7 @@ static void update_sampler(struct i915_context *i915, const unsigned ws = sampler->templ->wrap_s; const unsigned wt = sampler->templ->wrap_t; const unsigned wr = sampler->templ->wrap_r; - if (mt->target == PIPE_TEXTURE_3D && + if (pt->target == PIPE_TEXTURE_3D && (sampler->templ->min_img_filter != PIPE_TEX_FILTER_NEAREST || sampler->templ->mag_img_filter != PIPE_TEX_FILTER_NEAREST) && (ws == PIPE_TEX_WRAP_CLAMP || @@ -105,13 +107,13 @@ void i915_update_samplers( struct i915_context *i915 ) i915->current.sampler_enable_flags = 0x0; for (unit = 0; unit < I915_TEX_UNITS; unit++) { - /* determine unit enable/disable by looking for a bound mipmap tree */ + /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->texture[unit]) { update_sampler( i915, unit, i915->sampler[unit], /* sampler state */ - i915->texture[unit], /* mipmap tree */ + i915->texture[unit], /* texture */ i915->current.sampler[unit] /* the result */ ); @@ -125,7 +127,7 @@ void i915_update_samplers( struct i915_context *i915 ) static uint -translate_texture_format(uint pipeFormat) +translate_texture_format(enum pipe_format pipeFormat) { switch (pipeFormat) { case PIPE_FORMAT_U_L8: @@ -136,13 +138,13 @@ translate_texture_format(uint pipeFormat) return MAPSURF_8BIT | MT_8BIT_A8; case PIPE_FORMAT_U_A8_L8: return MAPSURF_16BIT | MT_16BIT_AY88; - case PIPE_FORMAT_U_R5_G6_B5: + case PIPE_FORMAT_R5G6B5_UNORM: return MAPSURF_16BIT | MT_16BIT_RGB565; - case PIPE_FORMAT_U_A1_R5_G5_B5: + case PIPE_FORMAT_A1R5G5B5_UNORM: return MAPSURF_16BIT | MT_16BIT_ARGB1555; - case PIPE_FORMAT_U_A4_R4_G4_B4: + case PIPE_FORMAT_A4R4G4B4_UNORM: return MAPSURF_16BIT | MT_16BIT_ARGB4444; - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: return MAPSURF_32BIT | MT_32BIT_ARGB8888; case PIPE_FORMAT_YCBCR_REV: return (MAPSURF_422 | MT_422_YCRCB_NORMAL); @@ -153,7 +155,7 @@ translate_texture_format(uint pipeFormat) case PIPE_FORMAT_RGBA_FXT1: return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1); #endif - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: return (MAPSURF_16BIT | MT_16BIT_L16); #if 0 case PIPE_FORMAT_RGBA_DXT1: @@ -164,7 +166,7 @@ translate_texture_format(uint pipeFormat) case PIPE_FORMAT_RGBA_DXT5: return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5); #endif - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: return (MAPSURF_32BIT | MT_32BIT_xL824); default: fprintf(stderr, "i915: translate_texture_format() bad image format %x\n", @@ -179,18 +181,19 @@ static void i915_update_texture(struct i915_context *i915, uint unit, uint state[6]) { - const struct pipe_mipmap_tree *mt = i915->texture[unit]; + const struct i915_texture *tex = i915->texture[unit]; + const struct pipe_texture *pt = &tex->base; uint format, pitch; - const uint width = mt->width0, height = mt->height0, depth = mt->depth0; - const uint num_levels = mt->last_level - mt->first_level; + const uint width = pt->width[0], height = pt->height[0], depth = pt->depth[0]; + const uint num_levels = pt->last_level - pt->first_level; - assert(mt); + assert(tex); assert(width); assert(height); assert(depth); - format = translate_texture_format(mt->format); - pitch = mt->pitch * mt->cpp; + format = translate_texture_format(pt->format); + pitch = tex->pitch * pt->cpp; assert(format); assert(pitch); @@ -217,7 +220,7 @@ i915_update_textures(struct i915_context *i915) uint unit; for (unit = 0; unit < I915_TEX_UNITS; unit++) { - /* determine unit enable/disable by looking for a bound mipmap tree */ + /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->texture[unit]) { i915_update_texture(i915, unit, i915->current.texbuffer[unit]); diff --git a/src/mesa/pipe/i915simple/i915_strings.c b/src/mesa/pipe/i915simple/i915_strings.c index a9b0bfc7c27..c713bf72086 100644 --- a/src/mesa/pipe/i915simple/i915_strings.c +++ b/src/mesa/pipe/i915simple/i915_strings.c @@ -70,7 +70,7 @@ static const char *i915_get_name( struct pipe_context *pipe ) break; } - snprintf(buffer, sizeof(buffer), "pipe/i915 (chipset: %s)", chipset); + sprintf(buffer, "pipe/i915 (chipset: %s)", chipset); return buffer; } diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index afe15fb525d..ea48c1bd8ae 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -26,8 +26,10 @@ **************************************************************************/ #include "i915_context.h" +#include "i915_blit.h" #include "i915_state.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" @@ -56,15 +58,15 @@ i915_get_tile_rgba(struct pipe_context *pipe, uint x, uint y, uint w, uint h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((const unsigned *) (ps->map)) + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; CLIP_TILE; switch (ps->format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: for (i = 0; i < h; i++) { float *pRow = p; for (j = 0; j < w; j++) { @@ -75,13 +77,13 @@ i915_get_tile_rgba(struct pipe_context *pipe, pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: { - const float scale = 1.0 / (float) 0xffffff; + const float scale = 1.0f / (float) 0xffffff; for (i = 0; i < h; i++) { float *pRow = p; for (j = 0; j < w; j++) { @@ -92,7 +94,7 @@ i915_get_tile_rgba(struct pipe_context *pipe, pRow[3] = (pixel & 0xffffff) * scale; pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -122,13 +124,13 @@ i915_get_tile(struct pipe_context *pipe, uint x, uint y, uint w, uint h, void *p, int dst_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const uint w0 = w; const ubyte *pSrc; ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); CLIP_TILE; @@ -136,13 +138,13 @@ i915_get_tile(struct pipe_context *pipe, dst_stride = w0 * cpp; } - pSrc = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pSrc = ps->map + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w0 * cpp); pDest += dst_stride; - pSrc += ps->region->pitch * cpp; + pSrc += ps->pitch * cpp; } } @@ -156,13 +158,13 @@ i915_put_tile(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const void *p, int src_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const uint w0 = w; const ubyte *pSrc; ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); CLIP_TILE; @@ -171,11 +173,11 @@ i915_put_tile(struct pipe_context *pipe, } pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pDest = ps->map + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w0 * cpp); - pDest += ps->region->pitch * cpp; + pDest += ps->pitch * cpp; pSrc += src_stride; } } @@ -186,38 +188,202 @@ i915_put_tile(struct pipe_context *pipe, */ static struct pipe_surface * i915_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice) { + struct i915_texture *tex = (struct i915_texture *)pt; struct pipe_surface *ps; unsigned offset; /* in bytes */ - offset = mt->level[level].level_offset; + offset = tex->level_offset[level]; - if (mt->target == PIPE_TEXTURE_CUBE) { - offset += mt->level[level].image_offset[face] * mt->cpp; + if (pt->target == PIPE_TEXTURE_CUBE) { + offset += tex->image_offset[level][face] * pt->cpp; } - else if (mt->target == PIPE_TEXTURE_3D) { - offset += mt->level[level].image_offset[zslice] * mt->cpp; + else if (pt->target == PIPE_TEXTURE_3D) { + offset += tex->image_offset[level][zslice] * pt->cpp; } else { assert(face == 0); assert(zslice == 0); } - ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format); if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, mt->region); - ps->width = mt->level[level].width; - ps->height = mt->level[level].height; + pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); + ps->cpp = pt->cpp; + ps->width = pt->width[level]; + ps->height = pt->height[level]; + ps->pitch = tex->pitch; ps->offset = offset; } return ps; } +/* + * XXX Move this into core Mesa? + */ +static void +_mesa_copy_rect(ubyte * dst, + unsigned cpp, + unsigned dst_pitch, + unsigned dst_x, + unsigned dst_y, + unsigned width, + unsigned height, + const ubyte * src, + unsigned src_pitch, + unsigned src_x, + unsigned src_y) +{ + unsigned i; + + dst_pitch *= cpp; + src_pitch *= cpp; + dst += dst_x * cpp; + src += src_x * cpp; + dst += dst_y * dst_pitch; + src += src_y * dst_pitch; + width *= cpp; + + if (width == dst_pitch && width == src_pitch) + memcpy(dst, src, height * width); + else { + for (i = 0; i < height; i++) { + memcpy(dst, src, width); + dst += dst_pitch; + src += src_pitch; + } + } +} + + +/* Upload data to a rectangular sub-region. Lots of choices how to do this: + * + * - memcpy by span to current destination + * - upload data as new buffer and blit + * + * Currently always memcpy. + */ +static void +i915_surface_data(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + const void *src, unsigned src_pitch, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + _mesa_copy_rect(pipe_surface_map(dst), + dst->cpp, + dst->pitch, + dstx, dsty, width, height, src, src_pitch, srcx, srcy); + + pipe_surface_unmap(dst); +} + + +/* Assumes all values are within bounds -- no checking at this level - + * do it higher up if required. + */ +static void +i915_surface_copy(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + struct pipe_surface *src, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + assert( dst != src ); + assert( dst->cpp == src->cpp ); + + if (0) { + _mesa_copy_rect(pipe_surface_map(dst), + dst->cpp, + dst->pitch, + dstx, dsty, + width, height, + pipe_surface_map(src), + src->pitch, + srcx, srcy); + + pipe_surface_unmap(src); + pipe_surface_unmap(dst); + } + else { + i915_copy_blit( i915_context(pipe), + dst->cpp, + (short) src->pitch, src->buffer, src->offset, + (short) dst->pitch, dst->buffer, dst->offset, + (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height ); + } +} + +/* 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) +{ + return dst->map + (y * dst->pitch + x) * dst->cpp; +} + + +static void +i915_surface_fill(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, unsigned value) +{ + if (0) { + unsigned i, j; + + (void)pipe_surface_map(dst); + + switch (dst->cpp) { + case 1: { + ubyte *row = get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + memset(row, value, width); + row += dst->pitch; + } + } + break; + case 2: { + ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) + row[j] = (ushort) value; + row += dst->pitch; + } + } + break; + case 4: { + unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) + row[j] = value; + row += dst->pitch; + } + } + break; + default: + assert(0); + break; + } + } + else { + i915_fill_blit( i915_context(pipe), + dst->cpp, + (short) dst->pitch, + dst->buffer, dst->offset, + (short) dstx, (short) dsty, + (short) width, (short) height, + value ); + } +} + + void i915_init_surface_functions(struct i915_context *i915) { @@ -226,4 +392,7 @@ i915_init_surface_functions(struct i915_context *i915) i915->pipe.put_tile = i915_put_tile; i915->pipe.get_tile_rgba = i915_get_tile_rgba; i915->pipe.put_tile_rgba = i915_put_tile_rgba; + i915->pipe.surface_data = i915_surface_data; + i915->pipe.surface_copy = i915_surface_copy; + i915->pipe.surface_fill = i915_surface_fill; } diff --git a/src/mesa/pipe/i915simple/i915_tex_layout.c b/src/mesa/pipe/i915simple/i915_tex_layout.c deleted file mode 100644 index 39c3cf2f71e..00000000000 --- a/src/mesa/pipe/i915simple/i915_tex_layout.c +++ /dev/null @@ -1,474 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - /* - * Authors: - * Keith Whitwell - * Michel Dänzer - */ - -#include "pipe/p_state.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_util.h" - -#include "i915_tex_layout.h" -#include "i915_debug.h" - - -static unsigned minify( unsigned d ) -{ - return MAX2(1, d>>1); -} - -static int align(int value, int alignment) -{ - return (value + alignment - 1) & ~(alignment - 1); -} - - -static void -i915_miptree_set_level_info(struct pipe_mipmap_tree *mt, - unsigned level, - unsigned nr_images, - unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) -{ - assert(level < PIPE_MAX_TEXTURE_LEVELS); - - mt->level[level].width = w; - mt->level[level].height = h; - mt->level[level].depth = d; - mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp; - mt->level[level].nr_images = nr_images; - - /* - DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, - level, w, h, d, x, y, mt->level[level].level_offset); - */ - - /* Not sure when this would happen, but anyway: - */ - if (mt->level[level].image_offset) { - free(mt->level[level].image_offset); - mt->level[level].image_offset = NULL; - } - - assert(nr_images); - assert(!mt->level[level].image_offset); - - mt->level[level].image_offset = (unsigned *) malloc(nr_images * sizeof(unsigned)); - mt->level[level].image_offset[0] = 0; -} - - -static void -i915_miptree_set_image_offset(struct pipe_mipmap_tree *mt, - unsigned level, unsigned img, unsigned x, unsigned y) -{ - if (img == 0 && level == 0) - assert(x == 0 && y == 0); - - assert(img < mt->level[level].nr_images); - - mt->level[level].image_offset[img] = (x + y * mt->pitch); - - /* - DBG("%s level %d img %d pos %d,%d image_offset %x\n", - __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]); - */ -} - - -static void -i945_miptree_layout_2d( struct pipe_mipmap_tree *mt ) -{ - int align_h = 2, align_w = 4; - unsigned level; - unsigned x = 0; - unsigned y = 0; - unsigned width = mt->width0; - unsigned height = mt->height0; - - mt->pitch = mt->width0; - - /* 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 (mt->first_level != mt->last_level) { - unsigned mip1_width = align(minify(mt->width0), align_w) - + minify(minify(mt->width0)); - - if (mip1_width > mt->width0) - mt->pitch = mip1_width; - } - - /* Pitch must be a whole number of dwords, even though we - * express it in texels. - */ - mt->pitch = align(mt->pitch * mt->cpp, 4) / mt->cpp; - mt->total_height = 0; - - for ( level = mt->first_level ; level <= mt->last_level ; level++ ) { - unsigned img_height; - - i915_miptree_set_level_info(mt, level, 1, x, y, width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align(height, align_h); - - - /* Because the images are packed better, the final offset - * might not be the maximal one: - */ - mt->total_height = MAX2(mt->total_height, y + img_height); - - /* Layout_below: step right after second mipmap. - */ - if (level == mt->first_level + 1) { - x += align(width, align_w); - } - else { - y += img_height; - } - - width = minify(width); - height = minify(height); - } -} - - -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} -}; - - -boolean -i915_miptree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - int level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE: { - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - assert(lvlWidth == lvlHeight); /* cubemap images are square */ - - /* double pitch for cube layouts */ - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - mt->total_height = dim * 4; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, level, 6, - 0, 0, - /*OLD: mt->pitch, mt->total_height,*/ - 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; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_image_offset(mt, level, face, x, y); - d >>= 1; - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - } - } - break; - } - case PIPE_TEXTURE_3D:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned stack_height = 0; - - /* Calculate the size of a single slice. - */ - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - - /* XXX: hardware expects/requires 9 levels at minimum. - */ - for (level = mt->first_level; level <= MAX2(8, mt->last_level); - level++) { - i915_miptree_set_level_info(mt, level, depth, 0, mt->total_height, - width, height, depth); - - - stack_height += MAX2(2, height); - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - - /* Fixup depth image_offsets: - */ - depth = mt->depth0; - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned i; - for (i = 0; i < depth; i++) - i915_miptree_set_image_offset(mt, level, i, - 0, i * stack_height); - - depth = minify(depth); - } - - - /* Multiply slice size by texture depth for total size. It's - * remarkable how wasteful of memory the i915 texture layouts - * are. They are largely fixed in the i945. - */ - mt->total_height = stack_height * mt->depth0; - break; - } - - default:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned img_height; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, level, 1, - 0, mt->total_height, - width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height / 4); - else - img_height = (MAX2(2, height) + 1) & ~1; - - mt->total_height += img_height; - - width = minify(width); - height = minify(height); - } - break; - } - } - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - - -boolean -i945_miptree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - int level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE:{ - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - 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) - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - else - mt->pitch = 14 * 8; - - mt->total_height = dim * 4 + 4; - - /* Set all the levels to effectively occupy the whole rectangular region. - */ - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, 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 = mt->total_height - 4; - x = (face - 4) * 8; - } - else if (dim < 4 && (face > 0 || mt->first_level > 0)) { - y = mt->total_height - 4; - x = face * 8; - } - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_image_offset(mt, 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 = mt->total_height - 4; - x = (face - 4) * 8; - break; - } - - case 2: - y = mt->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 = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned pack_x_pitch, pack_x_nr; - unsigned pack_y_pitch; - unsigned level; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - pack_y_pitch = MAX2(mt->height0, 2); - pack_x_pitch = mt->pitch; - pack_x_nr = 1; - - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned nr_images = mt->target == PIPE_TEXTURE_3D ? depth : 6; - int x = 0; - int y = 0; - int q, j; - - i915_miptree_set_level_info(mt, level, nr_images, - 0, mt->total_height, - width, height, depth); - - for (q = 0; q < nr_images;) { - for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { - i915_miptree_set_image_offset(mt, level, q, x, y); - x += pack_x_pitch; - } - - x = 0; - y += pack_y_pitch; - } - - - mt->total_height += y; - - if (pack_x_pitch > 4) { - pack_x_pitch >>= 1; - pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= mt->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: - i945_miptree_layout_2d(mt); - break; - default: - assert(0); - return FALSE; - } - - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - diff --git a/src/mesa/pipe/i915simple/i915_tex_layout.h b/src/mesa/pipe/i915simple/i915_tex_layout.h deleted file mode 100644 index e0337863815..00000000000 --- a/src/mesa/pipe/i915simple/i915_tex_layout.h +++ /dev/null @@ -1,16 +0,0 @@ - -#ifndef I915_TEX_LAYOUT_H -#define I915_TEX_LAYOUT_H - -struct pipe_context; -struct pipe_mipmap_tree; - - -extern boolean -i915_miptree_layout(struct pipe_context *, struct pipe_mipmap_tree *); - -extern boolean -i945_miptree_layout(struct pipe_context *, struct pipe_mipmap_tree *); - - -#endif /* I915_TEX_LAYOUT_H */ diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c new file mode 100644 index 00000000000..1ca2815dfb9 --- /dev/null +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -0,0 +1,544 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + */ + +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_inlines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" + +#include "i915_context.h" +#include "i915_texture.h" +#include "i915_debug.h" + + +static unsigned minify( unsigned d ) +{ + return MAX2(1, d>>1); +} + +static int align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + + +static void +i915_miptree_set_level_info(struct i915_texture *tex, + unsigned level, + unsigned nr_images, + unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) +{ + struct pipe_texture *pt = &tex->base; + + assert(level < PIPE_MAX_TEXTURE_LEVELS); + + pt->width[level] = w; + pt->height[level] = h; + pt->depth[level] = d; + + tex->level_offset[level] = (x + y * tex->pitch) * pt->cpp; + tex->nr_images[level] = nr_images; + + /* + DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, + level, w, h, d, x, y, tex->level_offset[level]); + */ + + /* Not sure when this would happen, but anyway: + */ + if (tex->image_offset[level]) { + FREE(tex->image_offset[level]); + tex->image_offset[level] = NULL; + } + + assert(nr_images); + assert(!tex->image_offset[level]); + + tex->image_offset[level] = (unsigned *) MALLOC(nr_images * sizeof(unsigned)); + tex->image_offset[level][0] = 0; +} + + +static void +i915_miptree_set_image_offset(struct i915_texture *tex, + unsigned level, unsigned img, unsigned x, unsigned y) +{ + if (img == 0 && level == 0) + assert(x == 0 && y == 0); + + assert(img < tex->nr_images[level]); + + tex->image_offset[level][img] = (x + y * tex->pitch); + + /* + DBG("%s level %d img %d pos %d,%d image_offset %x\n", + __FUNCTION__, level, img, x, y, tex->image_offset[level][img]); + */ +} + + +static void +i945_miptree_layout_2d( struct i915_texture *tex ) +{ + struct pipe_texture *pt = &tex->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]; + + tex->pitch = pt->width[0]; + + /* 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]) + tex->pitch = mip1_width; + } + + /* Pitch must be a whole number of dwords, even though we + * express it in texels. + */ + tex->pitch = align(tex->pitch * pt->cpp, 4) / pt->cpp; + tex->total_height = 0; + + for ( level = pt->first_level ; level <= pt->last_level ; level++ ) { + unsigned img_height; + + i915_miptree_set_level_info(tex, level, 1, x, y, width, height, 1); + + if (pt->compressed) + img_height = MAX2(1, height/4); + else + img_height = align(height, align_h); + + + /* Because the images are packed better, the final offset + * might not be the maximal one: + */ + tex->total_height = MAX2(tex->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; + } + + width = minify(width); + height = minify(height); + } +} + + +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 +i915_miptree_layout(struct pipe_context *pipe, struct i915_texture * tex) +{ + struct pipe_texture *pt = &tex->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 */ + + /* double pitch for cube layouts */ + tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + tex->total_height = dim * 4; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_level_info(tex, level, 6, + 0, 0, + /*OLD: tex->pitch, tex->total_height,*/ + 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; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_image_offset(tex, level, face, x, y); + d >>= 1; + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + } + } + break; + } + case PIPE_TEXTURE_3D:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; + unsigned stack_height = 0; + + /* Calculate the size of a single slice. + */ + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + + /* XXX: hardware expects/requires 9 levels at minimum. + */ + for (level = pt->first_level; level <= MAX2(8, pt->last_level); + level++) { + i915_miptree_set_level_info(tex, level, depth, 0, tex->total_height, + width, height, depth); + + + stack_height += MAX2(2, height); + + width = minify(width); + height = minify(height); + depth = minify(depth); + } + + /* Fixup depth image_offsets: + */ + depth = pt->depth[0]; + for (level = pt->first_level; level <= pt->last_level; level++) { + unsigned i; + for (i = 0; i < depth; i++) + i915_miptree_set_image_offset(tex, level, i, + 0, i * stack_height); + + depth = minify(depth); + } + + + /* Multiply slice size by texture depth for total size. It's + * remarkable how wasteful of memory the i915 texture layouts + * are. They are largely fixed in the i945. + */ + tex->total_height = stack_height * pt->depth[0]; + break; + } + + default:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned img_height; + + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + tex->total_height = 0; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_level_info(tex, level, 1, + 0, tex->total_height, + width, height, 1); + + if (pt->compressed) + img_height = MAX2(1, height / 4); + else + img_height = (MAX2(2, height) + 1) & ~1; + + tex->total_height += img_height; + + width = minify(width); + height = minify(height); + } + break; + } + } + /* + DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + tex->pitch, + tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp); + */ + + return TRUE; +} + + +static boolean +i945_miptree_layout(struct pipe_context *pipe, struct i915_texture * tex) +{ + struct pipe_texture *pt = &tex->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) + tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + else + tex->pitch = 14 * 8; + + tex->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++) { + i915_miptree_set_level_info(tex, 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 = tex->total_height - 4; + x = (face - 4) * 8; + } + else if (dim < 4 && (face > 0 || pt->first_level > 0)) { + y = tex->total_height - 4; + x = face * 8; + } + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_image_offset(tex, 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 = tex->total_height - 4; + x = (face - 4) * 8; + break; + } + + case 2: + y = tex->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; + + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + tex->total_height = 0; + + pack_y_pitch = MAX2(pt->height[0], 2); + pack_x_pitch = tex->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; + + i915_miptree_set_level_info(tex, level, nr_images, + 0, tex->total_height, + width, height, depth); + + for (q = 0; q < nr_images;) { + for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { + i915_miptree_set_image_offset(tex, level, q, x, y); + x += pack_x_pitch; + } + + x = 0; + y += pack_y_pitch; + } + + + tex->total_height += y; + + if (pack_x_pitch > 4) { + pack_x_pitch >>= 1; + pack_x_nr <<= 1; + assert(pack_x_pitch * pack_x_nr <= tex->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: + i945_miptree_layout_2d(tex); + break; + default: + assert(0); + return FALSE; + } + + /* + DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + tex->pitch, + tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp); + */ + + return TRUE; +} + +void +i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) +{ + struct i915_texture *tex = REALLOC(*pt, sizeof(struct pipe_texture), + sizeof(struct i915_texture)); + + if (tex) { + struct i915_context *i915 = i915_context(pipe); + + memset(&tex->base + 1, 0, + sizeof(struct i915_texture) - sizeof(struct pipe_texture)); + + if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) : + i915_miptree_layout(pipe, tex)) { + tex->buffer = pipe->winsys->buffer_create(pipe->winsys, + PIPE_SURFACE_FLAG_TEXTURE); + + if (tex->buffer) + pipe->winsys->buffer_data(pipe->winsys, tex->buffer, + tex->pitch * tex->base.cpp * + tex->total_height, NULL, + PIPE_BUFFER_USAGE_PIXEL); + } + + if (!tex->buffer) { + FREE(tex); + tex = NULL; + } + } + + *pt = &tex->base; +} + +void +i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) +{ + if (!*pt) + return; + + /* + DBG("%s %p refcount will be %d\n", + __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + */ + if (--(*pt)->refcount <= 0) { + struct i915_texture *tex = (struct i915_texture *)*pt; + uint i; + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); + */ + + pipe->winsys->buffer_reference(pipe->winsys, &tex->buffer, NULL); + + for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) + if (tex->image_offset[i]) + free(tex->image_offset[i]); + + free(tex); + } + *pt = NULL; +} diff --git a/src/mesa/pipe/i915simple/i915_texture.h b/src/mesa/pipe/i915simple/i915_texture.h new file mode 100644 index 00000000000..84a0502e81a --- /dev/null +++ b/src/mesa/pipe/i915simple/i915_texture.h @@ -0,0 +1,16 @@ + +#ifndef I915_TEXTURE_H +#define I915_TEXTURE_H + +struct pipe_context; +struct pipe_texture; + + +extern void +i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt); + +extern void +i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt); + + +#endif /* I915_TEXTURE_H */ diff --git a/src/mesa/pipe/i915simple/i915_winsys.h b/src/mesa/pipe/i915simple/i915_winsys.h index 386ed745d37..2c0f335d346 100644 --- a/src/mesa/pipe/i915simple/i915_winsys.h +++ b/src/mesa/pipe/i915simple/i915_winsys.h @@ -52,7 +52,6 @@ struct pipe_buffer_handle; struct pipe_winsys; -struct pipe_fence; /** @@ -98,28 +97,8 @@ struct i915_winsys { unsigned access_flags, unsigned delta ); - /** - * Flush the batch buffer. - * - * Fence argument must point to NULL or to a previous fence, and the caller - * must call fence_reference when done with the fence. - */ - void (*batch_flush)( struct i915_winsys *sws, - struct pipe_fence **fence ); - - - /* Fence - */ - void (*fence_reference)( struct i915_winsys *sws, - struct pipe_fence **dst_fence, - struct pipe_fence *src_fence ); - - int (*fence_is_signalled)( struct i915_winsys *sws, - struct pipe_fence *fence ); - - int (*fence_wait)( struct i915_winsys *sws, - struct pipe_fence *fence ); - + void (*batch_flush)( struct i915_winsys *sws ); + void (*batch_finish)( struct i915_winsys *sws ); }; #define I915_BUFFER_ACCESS_WRITE 0x1 diff --git a/src/mesa/pipe/llvm/llvm_entry.c b/src/mesa/pipe/llvm/llvm_entry.c index 2459d14cb82..fe32e7810dc 100644 --- a/src/mesa/pipe/llvm/llvm_entry.c +++ b/src/mesa/pipe/llvm/llvm_entry.c @@ -194,7 +194,6 @@ void run_vertex_shader(float (*ainputs)[16][4], struct pipe_sampler_state; -struct pipe_mipmap_tree; struct softpipe_tile_cache; #define NUM_CHANNELS 4 /* R,G,B,A */ @@ -203,7 +202,6 @@ struct softpipe_tile_cache; struct tgsi_sampler { const struct pipe_sampler_state *state; - struct pipe_mipmap_tree *texture; /** Get samples for four fragments in a quad */ void (*get_samples)(struct tgsi_sampler *sampler, const float s[QUAD_SIZE], diff --git a/src/mesa/pipe/nouveau/nouveau_gldefs.h b/src/mesa/pipe/nouveau/nouveau_gldefs.h new file mode 100644 index 00000000000..15ff318023d --- /dev/null +++ b/src/mesa/pipe/nouveau/nouveau_gldefs.h @@ -0,0 +1,198 @@ +#ifndef __NVGL_PIPE_H__ +#define __NVGL_PIPE_H__ + +#include + +static INLINE unsigned +nvgl_blend_func(unsigned factor) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ONE: + return GL_ONE; + case PIPE_BLENDFACTOR_SRC_COLOR: + return GL_SRC_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return GL_SRC_ALPHA; + case PIPE_BLENDFACTOR_DST_ALPHA: + return GL_DST_ALPHA; + case PIPE_BLENDFACTOR_DST_COLOR: + return GL_DST_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return GL_SRC_ALPHA_SATURATE; + case PIPE_BLENDFACTOR_CONST_COLOR: + return GL_CONSTANT_COLOR; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return GL_CONSTANT_ALPHA; + case PIPE_BLENDFACTOR_ZERO: + return GL_ZERO; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return GL_ONE_MINUS_SRC_COLOR; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return GL_ONE_MINUS_SRC_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return GL_ONE_MINUS_DST_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return GL_ONE_MINUS_DST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return GL_ONE_MINUS_CONSTANT_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return GL_ONE_MINUS_CONSTANT_ALPHA; + default: + return GL_ONE; + } +} + +static INLINE unsigned +nvgl_blend_eqn(unsigned func) +{ + switch (func) { + case PIPE_BLEND_ADD: + return GL_FUNC_ADD; + case PIPE_BLEND_SUBTRACT: + return GL_FUNC_SUBTRACT; + case PIPE_BLEND_REVERSE_SUBTRACT: + return GL_FUNC_REVERSE_SUBTRACT; + case PIPE_BLEND_MIN: + return GL_MIN; + case PIPE_BLEND_MAX: + return GL_MAX; + default: + return GL_FUNC_ADD; + } +} + +static INLINE unsigned +nvgl_logicop_func(unsigned func) +{ + switch (func) { + case PIPE_LOGICOP_CLEAR: + return GL_CLEAR; + case PIPE_LOGICOP_NOR: + return GL_NOR; + case PIPE_LOGICOP_AND_INVERTED: + return GL_AND_INVERTED; + case PIPE_LOGICOP_COPY_INVERTED: + return GL_COPY_INVERTED; + case PIPE_LOGICOP_AND_REVERSE: + return GL_AND_REVERSE; + case PIPE_LOGICOP_INVERT: + return GL_INVERT; + case PIPE_LOGICOP_XOR: + return GL_XOR; + case PIPE_LOGICOP_NAND: + return GL_NAND; + case PIPE_LOGICOP_AND: + return GL_AND; + case PIPE_LOGICOP_EQUIV: + return GL_EQUIV; + case PIPE_LOGICOP_NOOP: + return GL_NOOP; + case PIPE_LOGICOP_OR_INVERTED: + return GL_OR_INVERTED; + case PIPE_LOGICOP_COPY: + return GL_COPY; + case PIPE_LOGICOP_OR_REVERSE: + return GL_OR_REVERSE; + case PIPE_LOGICOP_OR: + return GL_OR; + case PIPE_LOGICOP_SET: + return GL_SET; + default: + return GL_CLEAR; + } +} + +static INLINE unsigned +nvgl_comparison_op(unsigned op) +{ + switch (op) { + case PIPE_FUNC_NEVER: + return GL_NEVER; + case PIPE_FUNC_LESS: + return GL_LESS; + case PIPE_FUNC_EQUAL: + return GL_EQUAL; + case PIPE_FUNC_LEQUAL: + return GL_LEQUAL; + case PIPE_FUNC_GREATER: + return GL_GREATER; + case PIPE_FUNC_NOTEQUAL: + return GL_NOTEQUAL; + case PIPE_FUNC_GEQUAL: + return GL_GEQUAL; + case PIPE_FUNC_ALWAYS: + return GL_ALWAYS; + default: + return GL_NEVER; + } +} + +static INLINE unsigned +nvgl_polygon_mode(unsigned mode) +{ + switch (mode) { + case PIPE_POLYGON_MODE_FILL: + return GL_FILL; + case PIPE_POLYGON_MODE_LINE: + return GL_LINE; + case PIPE_POLYGON_MODE_POINT: + return GL_POINT; + default: + return GL_FILL; + } +} + +static INLINE unsigned +nvgl_stencil_op(unsigned op) +{ + switch (op) { + case PIPE_STENCIL_OP_KEEP: + return GL_KEEP; + case PIPE_STENCIL_OP_ZERO: + return GL_ZERO; + case PIPE_STENCIL_OP_REPLACE: + return GL_REPLACE; + case PIPE_STENCIL_OP_INCR: + return GL_INCR; + case PIPE_STENCIL_OP_DECR: + return GL_DECR; + case PIPE_STENCIL_OP_INCR_WRAP: + return GL_INCR_WRAP; + case PIPE_STENCIL_OP_DECR_WRAP: + return GL_DECR_WRAP; + case PIPE_STENCIL_OP_INVERT: + return GL_INVERT; + default: + return GL_KEEP; + } +} + +static INLINE unsigned +nvgl_primitive(unsigned prim) { + switch (prim) { + case PIPE_PRIM_POINTS: + return GL_POINTS + 1; + case PIPE_PRIM_LINES: + return GL_LINES + 1; + case PIPE_PRIM_LINE_LOOP: + return GL_LINE_LOOP + 1; + case PIPE_PRIM_LINE_STRIP: + return GL_LINE_STRIP + 1; + case PIPE_PRIM_TRIANGLES: + return GL_TRIANGLES + 1; + case PIPE_PRIM_TRIANGLE_STRIP: + return GL_TRIANGLE_STRIP + 1; + case PIPE_PRIM_TRIANGLE_FAN: + return GL_TRIANGLE_FAN + 1; + case PIPE_PRIM_QUADS: + return GL_QUADS + 1; + case PIPE_PRIM_QUAD_STRIP: + return GL_QUAD_STRIP + 1; + case PIPE_PRIM_POLYGON: + return GL_POLYGON + 1; + default: + return GL_POINTS + 1; + } +} + +#endif diff --git a/src/mesa/pipe/nouveau/nouveau_resource.h b/src/mesa/pipe/nouveau/nouveau_resource.h new file mode 100644 index 00000000000..1af7961d301 --- /dev/null +++ b/src/mesa/pipe/nouveau/nouveau_resource.h @@ -0,0 +1,37 @@ +/* + * Copyright 2007 Nouveau Project + * + * 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. + * + * 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 + * THE AUTHORS 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 __NOUVEAU_RESOURCE_H__ +#define __NOUVEAU_RESOURCE_H__ + +struct nouveau_resource { + struct nouveau_resource *prev; + struct nouveau_resource *next; + + int in_use; + void *priv; + + unsigned int start; + unsigned int size; +}; + +#endif diff --git a/src/mesa/pipe/nouveau/nouveau_winsys.h b/src/mesa/pipe/nouveau/nouveau_winsys.h index 28f17cdc8fa..4525f7113c2 100644 --- a/src/mesa/pipe/nouveau/nouveau_winsys.h +++ b/src/mesa/pipe/nouveau/nouveau_winsys.h @@ -10,17 +10,7 @@ #include "pipe/nouveau/nouveau_class.h" #include "pipe/nouveau/nouveau_grobj.h" #include "pipe/nouveau/nouveau_notifier.h" - -struct nouveau_resource { - struct nouveau_resource *prev; - struct nouveau_resource *next; - - boolean in_use; - void *priv; - - uint start; - uint size; -}; +#include "pipe/nouveau/nouveau_resource.h" struct nouveau_winsys { struct nouveau_context *nv; @@ -35,7 +25,7 @@ struct nouveau_winsys { /*XXX: this is crappy, and bound to be slow.. however, it's nice and * simple, it'll do for the moment*/ uint32_t *(*begin_ring)(struct nouveau_grobj *, int mthd, int size); - void (*out_reloc)(struct nouveau_channel *, void *ptr, + int (*out_reloc)(struct nouveau_channel *, void *ptr, struct nouveau_bo *, uint32_t data, uint32_t flags, uint32_t vor, uint32_t tor); void (*fire_ring)(struct nouveau_channel *); @@ -53,18 +43,20 @@ struct nouveau_winsys { int (*notifier_wait)(struct nouveau_notifier *, int id, int status, int timeout); - int (*region_copy)(struct nouveau_context *, struct pipe_region *, - unsigned, unsigned, unsigned, struct pipe_region *, - unsigned, unsigned, unsigned, unsigned, unsigned); - int (*region_fill)(struct nouveau_context *, struct pipe_region *, - unsigned, unsigned, unsigned, unsigned, unsigned, - unsigned); - int (*region_data)(struct nouveau_context *, struct pipe_region *, - unsigned, unsigned, unsigned, const void *, - unsigned, unsigned, unsigned, unsigned, unsigned); + int (*surface_copy)(struct nouveau_winsys *, struct pipe_surface *, + unsigned, unsigned, struct pipe_surface *, + unsigned, unsigned, unsigned, unsigned); + int (*surface_fill)(struct nouveau_winsys *, struct pipe_surface *, + unsigned, unsigned, unsigned, unsigned, unsigned); + int (*surface_data)(struct nouveau_winsys *, struct pipe_surface *, + unsigned, unsigned, const void *, unsigned, + unsigned, unsigned, unsigned, unsigned); }; extern struct pipe_context * nv40_create(struct pipe_winsys *, struct nouveau_winsys *, unsigned chipset); +extern struct pipe_context * +nv50_create(struct pipe_winsys *, struct nouveau_winsys *, unsigned chipset); + #endif diff --git a/src/mesa/pipe/nv40/Makefile b/src/mesa/pipe/nv40/Makefile index 90c8542da45..9818889ee32 100644 --- a/src/mesa/pipe/nv40/Makefile +++ b/src/mesa/pipe/nv40/Makefile @@ -10,7 +10,6 @@ DRIVER_SOURCES = \ nv40_fragprog.c \ nv40_miptree.c \ nv40_query.c \ - nv40_region.c \ nv40_state.c \ nv40_state_emit.c \ nv40_state_tex.c \ diff --git a/src/mesa/pipe/nv40/nv40_clear.c b/src/mesa/pipe/nv40/nv40_clear.c index 7890107c957..380a2a642fc 100644 --- a/src/mesa/pipe/nv40/nv40_clear.c +++ b/src/mesa/pipe/nv40/nv40_clear.c @@ -10,6 +10,5 @@ void nv40_clear(struct pipe_context *pipe, struct pipe_surface *ps, unsigned clearValue) { - pipe->region_fill(pipe, ps->region, 0, 0, 0, ps->width, ps->height, - clearValue); + pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue); } diff --git a/src/mesa/pipe/nv40/nv40_context.c b/src/mesa/pipe/nv40/nv40_context.c index 8706ed1c07c..7b77c70e81d 100644 --- a/src/mesa/pipe/nv40/nv40_context.c +++ b/src/mesa/pipe/nv40/nv40_context.c @@ -10,9 +10,9 @@ static boolean nv40_is_format_supported(struct pipe_context *pipe, uint format) { switch (format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - case PIPE_FORMAT_U_R5_G6_B5: - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: return TRUE; default: break; @@ -267,17 +267,12 @@ nv40_create(struct pipe_winsys *pipe_winsys, struct nouveau_winsys *nvws, nv40->pipe.draw_elements = nv40_draw_elements; nv40->pipe.clear = nv40_clear; - nv40->pipe.begin_query = nv40_query_begin; - nv40->pipe.end_query = nv40_query_end; - nv40->pipe.wait_query = nv40_query_wait; - - nv40->pipe.mipmap_tree_layout = nv40_miptree_layout; - nv40->pipe.flush = nv40_flush; - nv40_init_region_functions(nv40); + nv40_init_query_functions(nv40); nv40_init_surface_functions(nv40); nv40_init_state_functions(nv40); + nv40_init_miptree_functions(nv40); nv40->draw = draw_create(); assert(nv40->draw); diff --git a/src/mesa/pipe/nv40/nv40_context.h b/src/mesa/pipe/nv40/nv40_context.h index ec07a883706..3a1d3f076c6 100644 --- a/src/mesa/pipe/nv40/nv40_context.h +++ b/src/mesa/pipe/nv40/nv40_context.h @@ -8,6 +8,7 @@ #include "pipe/draw/draw_vertex.h" #include "pipe/nouveau/nouveau_winsys.h" +#include "pipe/nouveau/nouveau_gldefs.h" #include "nv40_state.h" @@ -40,7 +41,7 @@ struct nv40_context { uint32_t dirty; struct nv40_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS]; - struct pipe_mipmap_tree *tex_miptree[PIPE_MAX_SAMPLERS]; + struct pipe_texture *tex_miptree[PIPE_MAX_SAMPLERS]; uint32_t tex_dirty; struct { @@ -65,17 +66,14 @@ struct nv40_context { }; -extern void nv40_init_region_functions(struct nv40_context *nv40); -extern void nv40_init_surface_functions(struct nv40_context *nv40); extern void nv40_init_state_functions(struct nv40_context *nv40); +extern void nv40_init_surface_functions(struct nv40_context *nv40); +extern void nv40_init_miptree_functions(struct nv40_context *nv40); +extern void nv40_init_query_functions(struct nv40_context *nv40); /* nv40_draw.c */ extern struct draw_stage *nv40_draw_render_stage(struct nv40_context *nv40); -/* nv40_miptree.c */ -extern boolean nv40_miptree_layout(struct pipe_context *, - struct pipe_mipmap_tree *); - /* nv40_vertprog.c */ extern void nv40_vertprog_translate(struct nv40_context *, struct nv40_vertex_program *); @@ -106,9 +104,4 @@ extern void nv40_vbo_arrays_update(struct nv40_context *nv40); extern void nv40_clear(struct pipe_context *pipe, struct pipe_surface *ps, unsigned clearValue); -/* nv40_query.c */ -extern void nv40_query_begin(struct pipe_context *, struct pipe_query_object *); -extern void nv40_query_end(struct pipe_context *, struct pipe_query_object *); -extern void nv40_query_wait(struct pipe_context *, struct pipe_query_object *); - #endif diff --git a/src/mesa/pipe/nv40/nv40_fragprog.c b/src/mesa/pipe/nv40/nv40_fragprog.c index e6fee2bf5ae..8f3eeb1f481 100644 --- a/src/mesa/pipe/nv40/nv40_fragprog.c +++ b/src/mesa/pipe/nv40/nv40_fragprog.c @@ -2,9 +2,9 @@ #include "pipe/p_defines.h" #include "pipe/p_state.h" -#include "pipe/tgsi/exec/tgsi_token.h" -#include "pipe/tgsi/exec/tgsi_parse.h" -#include "pipe/tgsi/exec/tgsi_util.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/tgsi/util/tgsi_parse.h" +#include "pipe/tgsi/util/tgsi_util.h" #include "nv40_context.h" #include "nv40_dma.h" @@ -620,7 +620,6 @@ nv40_fragprog_translate(struct nv40_context *nv40, { struct tgsi_parse_context parse; struct nv40_fpc *fpc = NULL; - int i; fpc = calloc(1, sizeof(struct nv40_fpc)); if (!fpc) diff --git a/src/mesa/pipe/nv40/nv40_miptree.c b/src/mesa/pipe/nv40/nv40_miptree.c index 15639f01e90..45711f064d6 100644 --- a/src/mesa/pipe/nv40/nv40_miptree.c +++ b/src/mesa/pipe/nv40/nv40_miptree.c @@ -4,64 +4,105 @@ #include "nv40_context.h" -boolean -nv40_miptree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree *mt) +static void +nv40_miptree_layout(struct nv40_miptree *nv40mt) { - struct nv40_context *nv40 = (struct nv40_context *)pipe; + struct pipe_texture *pt = &nv40mt->base; boolean swizzled = FALSE; - uint width = mt->width0, height = mt->height0, depth = mt->depth0; - uint offset; + uint width = pt->width[0], height = pt->height[0], depth = pt->depth[0]; + uint offset = 0; int nr_faces, l, f; - mt->pitch = mt->width0; - mt->total_height = 0; - - if (mt->target == PIPE_TEXTURE_CUBE) { + if (pt->target == PIPE_TEXTURE_CUBE) { nr_faces = 6; } else - if (mt->target == PIPE_TEXTURE_3D) { - nr_faces = mt->depth0; + if (pt->target == PIPE_TEXTURE_3D) { + nr_faces = pt->depth[0]; } else { nr_faces = 1; } + + for (l = pt->first_level; l <= pt->last_level; l++) { + pt->width[l] = width; + pt->height[l] = height; + pt->depth[l] = depth; - for (l = mt->first_level; l <= mt->last_level; l++) { - mt->level[l].width = width; - mt->level[l].height = height; - mt->level[l].depth = depth; - mt->level[l].level_offset = 0; + if (swizzled) + nv40mt->level[l].pitch = pt->width[l] * pt->cpp; + else + nv40mt->level[l].pitch = pt->width[0] * pt->cpp; + nv40mt->level[l].pitch = (nv40mt->level[l].pitch + 63) & ~63; - mt->level[l].nr_images = nr_faces; - mt->level[l].image_offset = malloc(nr_faces * sizeof(unsigned)); - for (f = 0; f < nr_faces; f++) - mt->total_height += height; + nv40mt->level[l].image_offset = + calloc(nr_faces, sizeof(unsigned)); width = MAX2(1, width >> 1); height = MAX2(1, height >> 1); depth = MAX2(1, depth >> 1); + } - offset = 0; for (f = 0; f < nr_faces; f++) { - for (l = mt->first_level; l <= mt->last_level; l++) { - if (f == 0) { - mt->level[l].level_offset = offset; - } - - uint pitch; - - if (swizzled) - pitch = mt->level[l].width * mt->cpp; - else - pitch = mt->width0 * mt->cpp; - pitch = (pitch + 63) & ~63; - - mt->level[l].image_offset[f] = - (offset - mt->level[l].level_offset) / mt->cpp; - offset += pitch * mt->level[l].height; + for (l = pt->first_level; l <= pt->last_level; l++) { + nv40mt->level[l].image_offset[f] = offset; + offset += nv40mt->level[l].pitch * pt->height[l]; + } + } + + nv40mt->total_size = offset; +} + +static void +nv40_miptree_create(struct pipe_context *pipe, struct pipe_texture **pt) +{ + struct pipe_texture *mt = *pt; + struct pipe_winsys *ws = pipe->winsys; + struct nv40_miptree *nv40mt; + + *pt = NULL; + + nv40mt = calloc(1, sizeof(struct nv40_miptree)); + if (!nv40mt) + return; + + memcpy(&nv40mt->base, mt, sizeof(struct pipe_texture)); + nv40_miptree_layout(nv40mt); + + nv40mt->buffer = ws->buffer_create(ws, PIPE_SURFACE_FLAG_TEXTURE); + if (!nv40mt->buffer) { + free(nv40mt); + return; + } + + ws->buffer_data(ws, nv40mt->buffer, nv40mt->total_size, NULL, + PIPE_BUFFER_USAGE_PIXEL); + *pt = &nv40mt->base; +} + +static void +nv40_miptree_release(struct pipe_context *pipe, struct pipe_texture **pt) +{ + struct pipe_winsys *ws = pipe->winsys; + struct pipe_texture *mt = *pt; + + *pt = NULL; + if (--mt->refcount <= 0) { + struct nv40_miptree *nv40mt = (struct nv40_miptree *)mt; + int l; + + ws->buffer_reference(ws, &nv40mt->buffer, NULL); + for (l = 0; l < PIPE_MAX_TEXTURE_LEVELS; l++) { + if (nv40mt->level[l].image_offset) + free(nv40mt->level[l].image_offset); } + free(nv40mt); } +} - return TRUE; +void +nv40_init_miptree_functions(struct nv40_context *nv40) +{ + nv40->pipe.texture_create = nv40_miptree_create; + nv40->pipe.texture_release = nv40_miptree_release; } diff --git a/src/mesa/pipe/nv40/nv40_query.c b/src/mesa/pipe/nv40/nv40_query.c index efd81e66408..bcd6fe0cf49 100644 --- a/src/mesa/pipe/nv40/nv40_query.c +++ b/src/mesa/pipe/nv40/nv40_query.c @@ -16,7 +16,7 @@ nv40_query_object_find(struct nv40_context *nv40, struct pipe_query_object *q) return -1; } -void +static void nv40_query_begin(struct pipe_context *pipe, struct pipe_query_object *q) { struct nv40_context *nv40 = (struct nv40_context *)pipe; @@ -53,7 +53,24 @@ nv40_query_update(struct pipe_context *pipe, struct pipe_query_object *q) } } -void +static void +nv40_query_wait(struct pipe_context *pipe, struct pipe_query_object *q) +{ + nv40_query_update(pipe, q); + if (!q->ready) { + struct nv40_context *nv40 = (struct nv40_context *)pipe; + int id; + + id = nv40_query_object_find(nv40, q); + assert(id >= 0); + + nv40->nvws->notifier_wait(nv40->query, id, 0, 0); + nv40_query_update(pipe, q); + assert(q->ready); + } +} + +static void nv40_query_end(struct pipe_context *pipe, struct pipe_query_object *q) { struct nv40_context *nv40 = (struct nv40_context *)pipe; @@ -80,19 +97,9 @@ nv40_query_end(struct pipe_context *pipe, struct pipe_query_object *q) } void -nv40_query_wait(struct pipe_context *pipe, struct pipe_query_object *q) +nv40_init_query_functions(struct nv40_context *nv40) { - nv40_query_update(pipe, q); - if (!q->ready) { - struct nv40_context *nv40 = (struct nv40_context *)pipe; - int id; - - id = nv40_query_object_find(nv40, q); - assert(id >= 0); - - nv40->nvws->notifier_wait(nv40->query, id, 0, 0); - nv40_query_update(pipe, q); - assert(q->ready); - } + nv40->pipe.begin_query = nv40_query_begin; + nv40->pipe.end_query = nv40_query_end; + nv40->pipe.wait_query = nv40_query_wait; } - diff --git a/src/mesa/pipe/nv40/nv40_region.c b/src/mesa/pipe/nv40/nv40_region.c deleted file mode 100644 index f62bf89d183..00000000000 --- a/src/mesa/pipe/nv40/nv40_region.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "pipe/p_defines.h" -#include "pipe/p_winsys.h" - -#include "nv40_context.h" -#include "nv40_dma.h" - -static ubyte * -nv40_region_map(struct pipe_context *pipe, struct pipe_region *region) -{ - struct nv40_context *nv40 = (struct nv40_context *)pipe; - struct pipe_winsys *ws = nv40->pipe.winsys; - - if (!region->map_refcount++) { - region->map = ws->buffer_map(ws, region->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ); - } - - return region->map; -} - -static void -nv40_region_unmap(struct pipe_context *pipe, struct pipe_region *region) -{ - struct nv40_context *nv40 = (struct nv40_context *)pipe; - struct pipe_winsys *ws = nv40->pipe.winsys; - - if (!--region->map_refcount) { - ws->buffer_unmap(ws, region->buffer); - region->map = NULL; - } -} - -static void -nv40_region_data(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - const void *src, unsigned src_pitch, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - struct nv40_context *nv40 = (struct nv40_context *)pipe; - struct nouveau_winsys *nvws = nv40->nvws; - - nvws->region_data(nvws->nv, dst, dst_offset, dstx, dsty, - src, src_pitch, srcx, srcy, width, height); -} - - -static void -nv40_region_copy(struct pipe_context *pipe, struct pipe_region *dst, - unsigned dst_offset, unsigned dstx, unsigned dsty, - struct pipe_region *src, unsigned src_offset, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - struct nv40_context *nv40 = (struct nv40_context *)pipe; - struct nouveau_winsys *nvws = nv40->nvws; - - nvws->region_copy(nvws->nv, dst, dst_offset, dstx, dsty, - src, src_offset, srcx, srcy, width, height); -} - -static void -nv40_region_fill(struct pipe_context *pipe, - struct pipe_region *dst, unsigned dst_offset, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, unsigned value) -{ - struct nv40_context *nv40 = (struct nv40_context *)pipe; - struct nouveau_winsys *nvws = nv40->nvws; - - nvws->region_fill(nvws->nv, dst, dst_offset, dstx, dsty, - width, height, value); -} - -void -nv40_init_region_functions(struct nv40_context *nv40) -{ - nv40->pipe.region_map = nv40_region_map; - nv40->pipe.region_unmap = nv40_region_unmap; - nv40->pipe.region_data = nv40_region_data; - nv40->pipe.region_copy = nv40_region_copy; - nv40->pipe.region_fill = nv40_region_fill; -} - diff --git a/src/mesa/pipe/nv40/nv40_state.c b/src/mesa/pipe/nv40/nv40_state.c index 1e7513c0bbc..e4915794830 100644 --- a/src/mesa/pipe/nv40/nv40_state.c +++ b/src/mesa/pipe/nv40/nv40_state.c @@ -6,8 +6,6 @@ #include "nv40_dma.h" #include "nv40_state.h" -#include "nvgl_pipe.h" - static void * nv40_alpha_test_state_create(struct pipe_context *pipe, const struct pipe_alpha_test_state *cso) @@ -551,7 +549,7 @@ nv40_set_framebuffer_state(struct pipe_context *pipe, const struct pipe_framebuffer_state *fb) { struct nv40_context *nv40 = (struct nv40_context *)pipe; - struct pipe_region *region[4], *zregion; + struct pipe_surface *rt[4], *zeta; uint32_t rt_enable, rt_format, w, h; int i, colour_format = 0, zeta_format = 0; @@ -569,7 +567,7 @@ nv40_set_framebuffer_state(struct pipe_context *pipe, h = fb->cbufs[i]->height; colour_format = fb->cbufs[i]->format; rt_enable |= (NV40TCL_RT_ENABLE_COLOR0 << i); - region[i] = fb->cbufs[i]->region; + rt[i] = fb->cbufs[i]; } } @@ -587,7 +585,7 @@ nv40_set_framebuffer_state(struct pipe_context *pipe, } zeta_format = fb->zbuf->format; - zregion = fb->zbuf->region; + zeta = fb->zbuf; } if (fb->sbuf) { @@ -601,21 +599,21 @@ nv40_set_framebuffer_state(struct pipe_context *pipe, if (zeta_format) { assert(fb->sbuf->format == zeta_format); - assert(fb->sbuf->region == zregion); + assert(fb->sbuf == zeta); } else { zeta_format = fb->sbuf->format; - zregion = fb->sbuf->region; + zeta = fb->sbuf; } } rt_format = NV40TCL_RT_FORMAT_TYPE_LINEAR; switch (colour_format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: case 0: rt_format |= NV40TCL_RT_FORMAT_COLOR_A8R8G8B8; break; - case PIPE_FORMAT_U_R5_G6_B5: + case PIPE_FORMAT_R5G6B5_UNORM: rt_format |= NV40TCL_RT_FORMAT_COLOR_R5G6B5; break; default: @@ -623,13 +621,12 @@ nv40_set_framebuffer_state(struct pipe_context *pipe, } switch (zeta_format) { - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: rt_format |= NV40TCL_RT_FORMAT_ZETA_Z16; break; - case PIPE_FORMAT_Z24_S8: - rt_format |= NV40TCL_RT_FORMAT_ZETA_Z24S8; - break; + case PIPE_FORMAT_Z24S8_UNORM: case 0: + rt_format |= NV40TCL_RT_FORMAT_ZETA_Z24S8; break; default: assert(0); @@ -637,51 +634,47 @@ nv40_set_framebuffer_state(struct pipe_context *pipe, if (rt_enable & NV40TCL_RT_ENABLE_COLOR0) { BEGIN_RING(curie, NV40TCL_DMA_COLOR0, 1); - OUT_RELOCo(region[0]->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCo(rt[0]->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); BEGIN_RING(curie, NV40TCL_COLOR0_PITCH, 2); - OUT_RING (region[0]->pitch * region[0]->cpp); - OUT_RELOCl(region[0]->buffer, 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RING (rt[0]->pitch * rt[0]->cpp); + OUT_RELOCl(rt[0]->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); } if (rt_enable & NV40TCL_RT_ENABLE_COLOR1) { BEGIN_RING(curie, NV40TCL_DMA_COLOR1, 1); - OUT_RELOCo(region[1]->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCo(rt[1]->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); BEGIN_RING(curie, NV40TCL_COLOR1_OFFSET, 2); - OUT_RELOCl(region[1]->buffer, 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); - OUT_RING (region[1]->pitch * region[1]->cpp); + OUT_RELOCl(rt[1]->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RING (rt[1]->pitch * rt[1]->cpp); } if (rt_enable & NV40TCL_RT_ENABLE_COLOR2) { BEGIN_RING(curie, NV40TCL_DMA_COLOR2, 1); - OUT_RELOCo(region[2]->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCo(rt[2]->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); BEGIN_RING(curie, NV40TCL_COLOR2_OFFSET, 1); - OUT_RELOCl(region[2]->buffer, 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(rt[2]->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); BEGIN_RING(curie, NV40TCL_COLOR2_PITCH, 1); - OUT_RING (region[2]->pitch * region[2]->cpp); + OUT_RING (rt[2]->pitch * rt[2]->cpp); } if (rt_enable & NV40TCL_RT_ENABLE_COLOR3) { BEGIN_RING(curie, NV40TCL_DMA_COLOR3, 1); - OUT_RELOCo(region[3]->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCo(rt[3]->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); BEGIN_RING(curie, NV40TCL_COLOR3_OFFSET, 1); - OUT_RELOCl(region[3]->buffer, 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(rt[3]->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); BEGIN_RING(curie, NV40TCL_COLOR3_PITCH, 1); - OUT_RING (region[3]->pitch * region[3]->cpp); + OUT_RING (rt[3]->pitch * rt[3]->cpp); } if (zeta_format) { BEGIN_RING(curie, NV40TCL_DMA_ZETA, 1); - OUT_RELOCo(zregion->buffer, + OUT_RELOCo(zeta->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR | NOUVEAU_BO_RD); BEGIN_RING(curie, NV40TCL_ZETA_OFFSET, 1); - OUT_RELOCl(zregion->buffer, 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_WR | NOUVEAU_BO_RD); + OUT_RELOCl(zeta->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR | + NOUVEAU_BO_RD); BEGIN_RING(curie, NV40TCL_ZETA_PITCH, 1); - OUT_RING (zregion->pitch * zregion->cpp); + OUT_RING (zeta->pitch * zeta->cpp); } BEGIN_RING(curie, NV40TCL_RT_ENABLE, 1); @@ -727,7 +720,7 @@ nv40_set_scissor_state(struct pipe_context *pipe, static void nv40_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *miptree) + struct pipe_texture *miptree) { struct nv40_context *nv40 = (struct nv40_context *)pipe; diff --git a/src/mesa/pipe/nv40/nv40_state.h b/src/mesa/pipe/nv40/nv40_state.h index c6d22ceaa86..80c76cd25b6 100644 --- a/src/mesa/pipe/nv40/nv40_state.h +++ b/src/mesa/pipe/nv40/nv40_state.h @@ -124,4 +124,16 @@ struct nv40_depth_stencil_state { } stencil; }; +struct nv40_miptree { + struct pipe_texture base; + + struct pipe_buffer_handle *buffer; + uint total_size; + + struct { + uint pitch; + uint *image_offset; + } level[PIPE_MAX_TEXTURE_LEVELS]; +}; + #endif diff --git a/src/mesa/pipe/nv40/nv40_state_tex.c b/src/mesa/pipe/nv40/nv40_state_tex.c index bd779df9b36..30462a2a3d6 100644 --- a/src/mesa/pipe/nv40/nv40_state_tex.c +++ b/src/mesa/pipe/nv40/nv40_state_tex.c @@ -21,18 +21,18 @@ struct nv40_texture_format { static struct nv40_texture_format nv40_texture_formats[] = { - _(U_A8_R8_G8_B8, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W), - _(U_A1_R5_G5_B5, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W), - _(U_A4_R4_G4_B4, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W), - _(U_R5_G6_B5 , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W), - _(U_L8 , L8 , S1, S1, S1, ONE, X, X, X, X), - _(U_A8 , L8 , ZERO, ZERO, ZERO, S1, X, X, X, X), - _(U_I8 , L8 , S1, S1, S1, S1, X, X, X, X), - _(U_A8_L8 , A8L8 , S1, S1, S1, S1, Z, W, X, Y), -// _(RGB_DXT1 , 0x86, S1, S1, S1, ONE, X, Y, Z, W, 0x00, 0x00), -// _(RGBA_DXT1 , 0x86, S1, S1, S1, S1, X, Y, Z, W, 0x00, 0x00), -// _(RGBA_DXT3 , 0x87, S1, S1, S1, S1, X, Y, Z, W, 0x00, 0x00), -// _(RGBA_DXT5 , 0x88, S1, S1, S1, S1, X, Y, Z, W, 0x00, 0x00), + _(A8R8G8B8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W), + _(A1R5G5B5_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W), + _(A4R4G4B4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W), + _(R5G6B5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W), + _(U_L8 , L8 , S1, S1, S1, ONE, X, X, X, X), + _(U_A8 , L8 , ZERO, ZERO, ZERO, S1, X, X, X, X), + _(U_I8 , L8 , S1, S1, S1, S1, X, X, X, X), + _(U_A8_L8 , A8L8 , S1, S1, S1, S1, Z, W, X, Y), +// _(RGB_DXT1 , 0x86, S1, S1, S1, ONE, X, Y, Z, W, 0x00, 0x00), +// _(RGBA_DXT1 , 0x86, S1, S1, S1, S1, X, Y, Z, W, 0x00, 0x00), +// _(RGBA_DXT3 , 0x87, S1, S1, S1, S1, X, Y, Z, W, 0x00, 0x00), +// _(RGBA_DXT5 , 0x88, S1, S1, S1, S1, X, Y, Z, W, 0x00, 0x00), {}, }; @@ -50,31 +50,32 @@ nv40_tex_format(uint pipe_format) return NULL; } + static void nv40_tex_unit_enable(struct nv40_context *nv40, int unit) { - struct nouveau_winsys *nvws = nv40->nvws; struct nv40_sampler_state *ps = nv40->tex_sampler[unit]; - struct pipe_mipmap_tree *mt = nv40->tex_miptree[unit]; + struct pipe_texture *pt = nv40->tex_miptree[unit]; + struct nv40_miptree *nv40mt = (struct nv40_miptree *)pt; struct nv40_texture_format *tf; uint32_t txf, txs, txp; int swizzled = 0; /*XXX: implement in region code? */ - tf = nv40_tex_format(mt->format); + tf = nv40_tex_format(pt->format); if (!tf || !tf->defined) { - NOUVEAU_ERR("Unsupported texture format: 0x%x\n", mt->format); + NOUVEAU_ERR("Unsupported texture format: 0x%x\n", pt->format); return; } txf = ps->fmt; txf |= tf->format | 0x8000; - txf |= ((mt->last_level - mt->first_level + 1) << + txf |= ((pt->last_level - pt->first_level + 1) << NV40TCL_TEX_FORMAT_MIPMAP_COUNT_SHIFT); if (1) /* XXX */ txf |= NV40TCL_TEX_FORMAT_NO_BORDER; - switch (mt->target) { + switch (pt->target) { case PIPE_TEXTURE_CUBE: txf |= NV40TCL_TEX_FORMAT_CUBIC; /* fall-through */ @@ -88,25 +89,25 @@ nv40_tex_unit_enable(struct nv40_context *nv40, int unit) txf |= NV40TCL_TEX_FORMAT_DIMS_1D; break; default: - NOUVEAU_ERR("Unknown target %d\n", mt->target); + NOUVEAU_ERR("Unknown target %d\n", pt->target); return; } if (swizzled) { txp = 0; } else { - txp = mt->pitch * mt->cpp; + txp = nv40mt->level[0].pitch; txf |= NV40TCL_TEX_FORMAT_LINEAR; } txs = tf->swizzle; - if (mt->format == PIPE_FORMAT_U_A8_L8) + if (pt->format == PIPE_FORMAT_U_A8_L8) txs |= (1<<16); /*nfi*/ BEGIN_RING(curie, NV40TCL_TEX_OFFSET(unit), 8); - OUT_RELOCl(mt->region->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | + OUT_RELOCl(nv40mt->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD); - OUT_RELOCd(mt->region->buffer, txf, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | + OUT_RELOCd(nv40mt->buffer, txf, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_OR | NOUVEAU_BO_RD, NV40TCL_TEX_FORMAT_DMA0, NV40TCL_TEX_FORMAT_DMA1); OUT_RING (ps->wrap); @@ -114,10 +115,10 @@ nv40_tex_unit_enable(struct nv40_context *nv40, int unit) (0x00078000) /* mipmap related? */); OUT_RING (txs); OUT_RING (ps->filt | 0x3fd6 /*voodoo*/); - OUT_RING ((mt->width0 << NV40TCL_TEX_SIZE0_W_SHIFT) | mt->height0); + OUT_RING ((pt->width[0] << NV40TCL_TEX_SIZE0_W_SHIFT) | pt->height[0]); OUT_RING (ps->bcol); BEGIN_RING(curie, NV40TCL_TEX_SIZE1(unit), 1); - OUT_RING ((mt->depth0 << NV40TCL_TEX_SIZE1_DEPTH_SHIFT) | txp); + OUT_RING ((pt->depth[0] << NV40TCL_TEX_SIZE1_DEPTH_SHIFT) | txp); } void diff --git a/src/mesa/pipe/nv40/nv40_surface.c b/src/mesa/pipe/nv40/nv40_surface.c index 5292b5171ff..b4562f26e65 100644 --- a/src/mesa/pipe/nv40/nv40_surface.c +++ b/src/mesa/pipe/nv40/nv40_surface.c @@ -56,15 +56,15 @@ nv40_get_tile_rgba(struct pipe_context *pipe, uint x, uint y, uint w, uint h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((const unsigned *) (ps->map + ps->offset)) + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; CLIP_TILE; switch (ps->format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: for (i = 0; i < h; i++) { float *pRow = p; for (j = 0; j < w; j++) { @@ -75,11 +75,11 @@ nv40_get_tile_rgba(struct pipe_context *pipe, pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: { const float scale = 1.0 / (float) 0xffffff; for (i = 0; i < h; i++) { @@ -92,7 +92,7 @@ nv40_get_tile_rgba(struct pipe_context *pipe, pRow[3] = ((pixel & 0xffffff) >> 8) * scale; pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -122,13 +122,13 @@ nv40_get_tile(struct pipe_context *pipe, uint x, uint y, uint w, uint h, void *p, int dst_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const uint w0 = w; const ubyte *pSrc; ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); CLIP_TILE; @@ -136,13 +136,13 @@ nv40_get_tile(struct pipe_context *pipe, dst_stride = w0 * cpp; } - pSrc = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pSrc = ps->map + ps->offset + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w0 * cpp); pDest += dst_stride; - pSrc += ps->region->pitch * cpp; + pSrc += ps->pitch * cpp; } } @@ -156,13 +156,13 @@ nv40_put_tile(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const void *p, int src_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const uint w0 = w; const ubyte *pSrc; ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); CLIP_TILE; @@ -171,52 +171,81 @@ nv40_put_tile(struct pipe_context *pipe, } pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pDest = ps->map + ps->offset + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w0 * cpp); - pDest += ps->region->pitch * cpp; + pDest += ps->pitch * cpp; pSrc += src_stride; } } -/* - * XXX note: same as code in sp_surface.c - */ static struct pipe_surface * nv40_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice) { - struct pipe_surface *ps; - unsigned offset; /* in bytes */ + struct pipe_winsys *ws = pipe->winsys; + struct nv40_miptree *nv40mt = (struct nv40_miptree *)pt; + struct pipe_surface *ps; - offset = mt->level[level].level_offset; + ps = ws->surface_alloc(ws, pt->format); + if (!ps) + return NULL; + ws->buffer_reference(ws, &ps->buffer, nv40mt->buffer); + ps->cpp = pt->cpp; + ps->width = pt->width[level]; + ps->height = pt->height[level]; + ps->pitch = nv40mt->level[level].pitch / ps->cpp; - if (mt->target == PIPE_TEXTURE_CUBE) { - offset += mt->level[level].image_offset[face] * mt->cpp; - } - else if (mt->target == PIPE_TEXTURE_3D) { - offset += mt->level[level].image_offset[zslice] * mt->cpp; - } - else { - assert(face == 0); - assert(zslice == 0); - } + if (pt->target == PIPE_TEXTURE_CUBE) { + ps->offset = nv40mt->level[level].image_offset[face]; + } else + if (pt->target == PIPE_TEXTURE_3D) { + ps->offset = nv40mt->level[level].image_offset[zslice]; + } else { + ps->offset = nv40mt->level[level].image_offset[0]; + } - ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); - if (ps) { - assert(ps->format); - assert(ps->refcount); - pipe_region_reference(&ps->region, mt->region); - ps->width = mt->level[level].width; - ps->height = mt->level[level].height; - ps->offset = offset; - } - return ps; + return ps; } +static void +nv40_surface_data(struct pipe_context *pipe, struct pipe_surface *dest, + unsigned destx, unsigned desty, const void *src, + unsigned src_stride, unsigned srcx, unsigned srcy, + unsigned width, unsigned height) +{ + struct nv40_context *nv40 = (struct nv40_context *)pipe; + struct nouveau_winsys *nvws = nv40->nvws; + + nvws->surface_data(nvws, dest, destx, desty, src, src_stride, + srcx, srcy, width, height); +} + +static void +nv40_surface_copy(struct pipe_context *pipe, struct pipe_surface *dest, + unsigned destx, unsigned desty, struct pipe_surface *src, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + struct nv40_context *nv40 = (struct nv40_context *)pipe; + struct nouveau_winsys *nvws = nv40->nvws; + + nvws->surface_copy(nvws, dest, destx, desty, src, srcx, srcy, + width, height); +} + +static void +nv40_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest, + unsigned destx, unsigned desty, unsigned width, + unsigned height, unsigned value) +{ + struct nv40_context *nv40 = (struct nv40_context *)pipe; + struct nouveau_winsys *nvws = nv40->nvws; + + nvws->surface_fill(nvws, dest, destx, desty, width, height, value); +} void nv40_init_surface_functions(struct nv40_context *nv40) @@ -226,4 +255,7 @@ nv40_init_surface_functions(struct nv40_context *nv40) nv40->pipe.put_tile = nv40_put_tile; nv40->pipe.get_tile_rgba = nv40_get_tile_rgba; nv40->pipe.put_tile_rgba = nv40_put_tile_rgba; + nv40->pipe.surface_data = nv40_surface_data; + nv40->pipe.surface_copy = nv40_surface_copy; + nv40->pipe.surface_fill = nv40_surface_fill; } diff --git a/src/mesa/pipe/nv40/nv40_vbo.c b/src/mesa/pipe/nv40/nv40_vbo.c index 2da0001b288..8491f2a3ec8 100644 --- a/src/mesa/pipe/nv40/nv40_vbo.c +++ b/src/mesa/pipe/nv40/nv40_vbo.c @@ -5,7 +5,6 @@ #include "nv40_context.h" #include "nv40_dma.h" #include "nv40_state.h" -#include "nvgl_pipe.h" boolean nv40_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, @@ -42,7 +41,7 @@ nv40_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, BEGIN_RING(curie, NV40TCL_BEGIN_END, 1); OUT_RING (0); - pipe->flush(pipe, PIPE_FLUSH_WAIT); + pipe->flush(pipe, 0); return TRUE; } @@ -154,7 +153,7 @@ nv40_draw_elements(struct pipe_context *pipe, OUT_RING (0); pipe->winsys->buffer_unmap(pipe->winsys, ib); - pipe->flush(pipe, PIPE_FLUSH_WAIT); + pipe->flush(pipe, 0); return TRUE; } @@ -175,7 +174,6 @@ nv40_vbo_format_to_ncomp(uint format) void nv40_vbo_arrays_update(struct nv40_context *nv40) { - struct nouveau_winsys *nvws = nv40->nvws; struct nv40_vertex_program *vp = nv40->vertprog.active; uint32_t inputs, vtxfmt[16]; int hw, num_hw; diff --git a/src/mesa/pipe/nv40/nv40_vertprog.c b/src/mesa/pipe/nv40/nv40_vertprog.c index 04bdaacc98a..66722bafa58 100644 --- a/src/mesa/pipe/nv40/nv40_vertprog.c +++ b/src/mesa/pipe/nv40/nv40_vertprog.c @@ -2,8 +2,8 @@ #include "pipe/p_defines.h" #include "pipe/p_state.h" -#include "pipe/tgsi/exec/tgsi_token.h" -#include "pipe/tgsi/exec/tgsi_parse.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/tgsi/util/tgsi_parse.h" #include "nv40_context.h" #include "nv40_dma.h" diff --git a/src/mesa/pipe/nv40/nvgl_pipe.h b/src/mesa/pipe/nv40/nvgl_pipe.h deleted file mode 100644 index 15ff318023d..00000000000 --- a/src/mesa/pipe/nv40/nvgl_pipe.h +++ /dev/null @@ -1,198 +0,0 @@ -#ifndef __NVGL_PIPE_H__ -#define __NVGL_PIPE_H__ - -#include - -static INLINE unsigned -nvgl_blend_func(unsigned factor) -{ - switch (factor) { - case PIPE_BLENDFACTOR_ONE: - return GL_ONE; - case PIPE_BLENDFACTOR_SRC_COLOR: - return GL_SRC_COLOR; - case PIPE_BLENDFACTOR_SRC_ALPHA: - return GL_SRC_ALPHA; - case PIPE_BLENDFACTOR_DST_ALPHA: - return GL_DST_ALPHA; - case PIPE_BLENDFACTOR_DST_COLOR: - return GL_DST_COLOR; - case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: - return GL_SRC_ALPHA_SATURATE; - case PIPE_BLENDFACTOR_CONST_COLOR: - return GL_CONSTANT_COLOR; - case PIPE_BLENDFACTOR_CONST_ALPHA: - return GL_CONSTANT_ALPHA; - case PIPE_BLENDFACTOR_ZERO: - return GL_ZERO; - case PIPE_BLENDFACTOR_INV_SRC_COLOR: - return GL_ONE_MINUS_SRC_COLOR; - case PIPE_BLENDFACTOR_INV_SRC_ALPHA: - return GL_ONE_MINUS_SRC_ALPHA; - case PIPE_BLENDFACTOR_INV_DST_ALPHA: - return GL_ONE_MINUS_DST_ALPHA; - case PIPE_BLENDFACTOR_INV_DST_COLOR: - return GL_ONE_MINUS_DST_COLOR; - case PIPE_BLENDFACTOR_INV_CONST_COLOR: - return GL_ONE_MINUS_CONSTANT_COLOR; - case PIPE_BLENDFACTOR_INV_CONST_ALPHA: - return GL_ONE_MINUS_CONSTANT_ALPHA; - default: - return GL_ONE; - } -} - -static INLINE unsigned -nvgl_blend_eqn(unsigned func) -{ - switch (func) { - case PIPE_BLEND_ADD: - return GL_FUNC_ADD; - case PIPE_BLEND_SUBTRACT: - return GL_FUNC_SUBTRACT; - case PIPE_BLEND_REVERSE_SUBTRACT: - return GL_FUNC_REVERSE_SUBTRACT; - case PIPE_BLEND_MIN: - return GL_MIN; - case PIPE_BLEND_MAX: - return GL_MAX; - default: - return GL_FUNC_ADD; - } -} - -static INLINE unsigned -nvgl_logicop_func(unsigned func) -{ - switch (func) { - case PIPE_LOGICOP_CLEAR: - return GL_CLEAR; - case PIPE_LOGICOP_NOR: - return GL_NOR; - case PIPE_LOGICOP_AND_INVERTED: - return GL_AND_INVERTED; - case PIPE_LOGICOP_COPY_INVERTED: - return GL_COPY_INVERTED; - case PIPE_LOGICOP_AND_REVERSE: - return GL_AND_REVERSE; - case PIPE_LOGICOP_INVERT: - return GL_INVERT; - case PIPE_LOGICOP_XOR: - return GL_XOR; - case PIPE_LOGICOP_NAND: - return GL_NAND; - case PIPE_LOGICOP_AND: - return GL_AND; - case PIPE_LOGICOP_EQUIV: - return GL_EQUIV; - case PIPE_LOGICOP_NOOP: - return GL_NOOP; - case PIPE_LOGICOP_OR_INVERTED: - return GL_OR_INVERTED; - case PIPE_LOGICOP_COPY: - return GL_COPY; - case PIPE_LOGICOP_OR_REVERSE: - return GL_OR_REVERSE; - case PIPE_LOGICOP_OR: - return GL_OR; - case PIPE_LOGICOP_SET: - return GL_SET; - default: - return GL_CLEAR; - } -} - -static INLINE unsigned -nvgl_comparison_op(unsigned op) -{ - switch (op) { - case PIPE_FUNC_NEVER: - return GL_NEVER; - case PIPE_FUNC_LESS: - return GL_LESS; - case PIPE_FUNC_EQUAL: - return GL_EQUAL; - case PIPE_FUNC_LEQUAL: - return GL_LEQUAL; - case PIPE_FUNC_GREATER: - return GL_GREATER; - case PIPE_FUNC_NOTEQUAL: - return GL_NOTEQUAL; - case PIPE_FUNC_GEQUAL: - return GL_GEQUAL; - case PIPE_FUNC_ALWAYS: - return GL_ALWAYS; - default: - return GL_NEVER; - } -} - -static INLINE unsigned -nvgl_polygon_mode(unsigned mode) -{ - switch (mode) { - case PIPE_POLYGON_MODE_FILL: - return GL_FILL; - case PIPE_POLYGON_MODE_LINE: - return GL_LINE; - case PIPE_POLYGON_MODE_POINT: - return GL_POINT; - default: - return GL_FILL; - } -} - -static INLINE unsigned -nvgl_stencil_op(unsigned op) -{ - switch (op) { - case PIPE_STENCIL_OP_KEEP: - return GL_KEEP; - case PIPE_STENCIL_OP_ZERO: - return GL_ZERO; - case PIPE_STENCIL_OP_REPLACE: - return GL_REPLACE; - case PIPE_STENCIL_OP_INCR: - return GL_INCR; - case PIPE_STENCIL_OP_DECR: - return GL_DECR; - case PIPE_STENCIL_OP_INCR_WRAP: - return GL_INCR_WRAP; - case PIPE_STENCIL_OP_DECR_WRAP: - return GL_DECR_WRAP; - case PIPE_STENCIL_OP_INVERT: - return GL_INVERT; - default: - return GL_KEEP; - } -} - -static INLINE unsigned -nvgl_primitive(unsigned prim) { - switch (prim) { - case PIPE_PRIM_POINTS: - return GL_POINTS + 1; - case PIPE_PRIM_LINES: - return GL_LINES + 1; - case PIPE_PRIM_LINE_LOOP: - return GL_LINE_LOOP + 1; - case PIPE_PRIM_LINE_STRIP: - return GL_LINE_STRIP + 1; - case PIPE_PRIM_TRIANGLES: - return GL_TRIANGLES + 1; - case PIPE_PRIM_TRIANGLE_STRIP: - return GL_TRIANGLE_STRIP + 1; - case PIPE_PRIM_TRIANGLE_FAN: - return GL_TRIANGLE_FAN + 1; - case PIPE_PRIM_QUADS: - return GL_QUADS + 1; - case PIPE_PRIM_QUAD_STRIP: - return GL_QUAD_STRIP + 1; - case PIPE_PRIM_POLYGON: - return GL_POLYGON + 1; - default: - return GL_POINTS + 1; - } -} - -#endif diff --git a/src/mesa/pipe/nv50/Makefile b/src/mesa/pipe/nv50/Makefile new file mode 100644 index 00000000000..d3d011b14b7 --- /dev/null +++ b/src/mesa/pipe/nv50/Makefile @@ -0,0 +1,25 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = nv50 + +DRIVER_SOURCES = \ + nv50_clear.c \ + nv50_context.c \ + nv50_draw.c \ + nv50_miptree.c \ + nv50_query.c \ + nv50_state.c \ + nv50_surface.c \ + nv50_vbo.c + +C_SOURCES = \ + $(COMMON_SOURCES) \ + $(DRIVER_SOURCES) + +ASM_SOURCES = + +include ../Makefile.template + +symlinks: + diff --git a/src/mesa/pipe/nv50/nv50_clear.c b/src/mesa/pipe/nv50/nv50_clear.c new file mode 100644 index 00000000000..2b453a49d15 --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_clear.c @@ -0,0 +1,14 @@ +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + +#include "nv50_context.h" +#include "nv50_dma.h" + + +void +nv50_clear(struct pipe_context *pipe, struct pipe_surface *ps, + unsigned clearValue) +{ + pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue); +} diff --git a/src/mesa/pipe/nv50/nv50_context.c b/src/mesa/pipe/nv50/nv50_context.c new file mode 100644 index 00000000000..25ead1b5646 --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_context.c @@ -0,0 +1,210 @@ +#include "pipe/draw/draw_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_winsys.h" +#include "pipe/p_util.h" + +#include "nv50_context.h" +#include "nv50_dma.h" + +static boolean +nv50_is_format_supported(struct pipe_context *pipe, uint format) +{ + switch (format) { + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: + return TRUE; + default: + break; + }; + + return FALSE; +} + +static const char * +nv50_get_name(struct pipe_context *pipe) +{ + struct nv50_context *nv50 = (struct nv50_context *)pipe; + static char buffer[128]; + + snprintf(buffer, sizeof(buffer), "NV%02X", nv50->chipset); + return buffer; +} + +static const char * +nv50_get_vendor(struct pipe_context *pipe) +{ + return "nouveau"; +} + +static int +nv50_get_param(struct pipe_context *pipe, int param) +{ + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return 32; + case PIPE_CAP_NPOT_TEXTURES: + return 0; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return 0; + case PIPE_CAP_S3TC: + return 0; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 0; + case PIPE_CAP_POINT_SPRITE: + return 0; + case PIPE_CAP_MAX_RENDER_TARGETS: + return 8; + case PIPE_CAP_OCCLUSION_QUERY: + return 0; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 0; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return 13; + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return 10; + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return 13; + default: + NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param); + return 0; + } +} + +static float +nv50_get_paramf(struct pipe_context *pipe, int param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 10.0; + case PIPE_CAP_MAX_POINT_WIDTH: + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 64.0; + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 16.0; + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 4.0; + default: + NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param); + return 0.0; + } +} + +static void +nv50_flush(struct pipe_context *pipe, unsigned flags) +{ + struct nv50_context *nv50 = (struct nv50_context *)pipe; + struct nouveau_winsys *nvws = nv50->nvws; + + if (flags & PIPE_FLUSH_WAIT) { + nvws->notifier_reset(nv50->sync, 0); + BEGIN_RING(tesla, 0x104, 1); + OUT_RING (0); + BEGIN_RING(tesla, 0x100, 1); + OUT_RING (0); + } + + FIRE_RING(); + + if (flags & PIPE_FLUSH_WAIT) + nvws->notifier_wait(nv50->sync, 0, 0, 2000); +} + +static void +nv50_destroy(struct pipe_context *pipe) +{ + struct nv50_context *nv50 = (struct nv50_context *)pipe; + + draw_destroy(nv50->draw); + free(nv50); +} + +static boolean +nv50_init_hwctx(struct nv50_context *nv50, int tesla_class) +{ + struct nouveau_winsys *nvws = nv50->nvws; + int ret; + + if ((ret = nvws->grobj_alloc(nvws, tesla_class, &nv50->tesla))) { + NOUVEAU_ERR("Error creating 3D object: %d\n", ret); + return FALSE; + } + + BEGIN_RING(tesla, NV50TCL_DMA_NOTIFY, 1); + OUT_RING (nv50->sync->handle); + + FIRE_RING (); + return TRUE; +} + +#define GRCLASS5097_CHIPSETS 0x00000000 +#define GRCLASS8297_CHIPSETS 0x00000010 +struct pipe_context * +nv50_create(struct pipe_winsys *pipe_winsys, struct nouveau_winsys *nvws, + unsigned chipset) +{ + struct nv50_context *nv50; + int tesla_class, ret; + + if ((chipset & 0xf0) != 0x50 && (chipset & 0xf0) != 0x80) { + NOUVEAU_ERR("Not a G8x chipset\n"); + return NULL; + } + + if (GRCLASS5097_CHIPSETS & (1 << (chipset & 0x0f))) { + tesla_class = 0x5097; + } else + if (GRCLASS8297_CHIPSETS & (1 << (chipset & 0x0f))) { + tesla_class = 0x8297; + } else { + NOUVEAU_ERR("Unknown G8x chipset: NV%02x\n", chipset); + return NULL; + } + + nv50 = CALLOC_STRUCT(nv50_context); + if (!nv50) + return NULL; + nv50->chipset = chipset; + nv50->nvws = nvws; + + if ((ret = nvws->notifier_alloc(nvws, 1, &nv50->sync))) { + NOUVEAU_ERR("Error creating notifier object: %d\n", ret); + free(nv50); + return NULL; + } + + if (!nv50_init_hwctx(nv50, tesla_class)) { + free(nv50); + return NULL; + } + + nv50->pipe.winsys = pipe_winsys; + + nv50->pipe.destroy = nv50_destroy; + nv50->pipe.is_format_supported = nv50_is_format_supported; + nv50->pipe.get_name = nv50_get_name; + nv50->pipe.get_vendor = nv50_get_vendor; + nv50->pipe.get_param = nv50_get_param; + nv50->pipe.get_paramf = nv50_get_paramf; + + nv50->pipe.draw_arrays = nv50_draw_arrays; + nv50->pipe.draw_elements = nv50_draw_elements; + nv50->pipe.clear = nv50_clear; + + nv50->pipe.flush = nv50_flush; + + nv50_init_miptree_functions(nv50); + nv50_init_surface_functions(nv50); + nv50_init_state_functions(nv50); + nv50_init_query_functions(nv50); + + nv50->draw = draw_create(); + assert(nv50->draw); + draw_set_rasterize_stage(nv50->draw, nv50_draw_render_stage(nv50)); + + return &nv50->pipe; +} + + diff --git a/src/mesa/pipe/nv50/nv50_context.h b/src/mesa/pipe/nv50/nv50_context.h new file mode 100644 index 00000000000..5be4e5cb1be --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_context.h @@ -0,0 +1,54 @@ +#ifndef __NV50_CONTEXT_H__ +#define __NV50_CONTEXT_H__ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + +#include "pipe/draw/draw_vertex.h" + +#include "pipe/nouveau/nouveau_winsys.h" +#include "pipe/nouveau/nouveau_gldefs.h" + +#include "nv50_state.h" + +#define NOUVEAU_ERR(fmt, args...) \ + fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args); +#define NOUVEAU_MSG(fmt, args...) \ + fprintf(stderr, "nouveau: "fmt, ##args); + +struct nv50_context { + struct pipe_context pipe; + struct nouveau_winsys *nvws; + + struct draw_context *draw; + + int chipset; + struct nouveau_grobj *tesla; + struct nouveau_notifier *sync; + uint32_t *pushbuf; +}; + + +extern void nv50_init_miptree_functions(struct nv50_context *nv50); +extern void nv50_init_surface_functions(struct nv50_context *nv50); +extern void nv50_init_state_functions(struct nv50_context *nv50); +extern void nv50_init_query_functions(struct nv50_context *nv50); + +/* nv50_draw.c */ +extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50); + +/* nv50_vbo.c */ +extern boolean nv50_draw_arrays(struct pipe_context *, unsigned mode, + unsigned start, unsigned count); +extern boolean nv50_draw_elements(struct pipe_context *pipe, + struct pipe_buffer_handle *indexBuffer, + unsigned indexSize, + unsigned mode, unsigned start, + unsigned count); + +/* nv50_clear.c */ +extern void nv50_clear(struct pipe_context *pipe, struct pipe_surface *ps, + unsigned clearValue); + +#endif diff --git a/src/mesa/pipe/nv50/nv50_dma.h b/src/mesa/pipe/nv50/nv50_dma.h new file mode 100644 index 00000000000..f8121b61cc6 --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_dma.h @@ -0,0 +1,62 @@ +#ifndef __NV50_DMA_H__ +#define __NV50_DMA_H__ + +#include "pipe/nouveau/nouveau_winsys.h" + +#define BEGIN_RING(obj,mthd,size) do { \ + nv50->pushbuf = nv50->nvws->begin_ring(nv50->obj, (mthd), (size)); \ +} while(0) + +#define BEGIN_RING_NI(obj,mthd,size) do { \ + BEGIN_RING(obj, (mthd) | 0x40000000, (size)); \ +} while(0) + +#define OUT_RING(data) do { \ + (*nv50->pushbuf++) = (data); \ +} while(0) + +#define OUT_RINGp(src,size) do { \ + memcpy(nv50->pushbuf, (src), (size) * 4); \ + nv50->pushbuf += (size); \ +} while(0) + +#define OUT_RINGf(data) do { \ + union { float v; uint32_t u; } c; \ + c.v = (data); \ + OUT_RING(c.u); \ +} while(0) + +#define FIRE_RING() do { \ + nv50->nvws->fire_ring(nv50->nvws->channel); \ +} while(0) + +#define OUT_RELOC(bo,data,flags,vor,tor) do { \ + nv50->nvws->out_reloc(nv50->nvws->channel, nv50->pushbuf, \ + (struct nouveau_bo *)(bo), \ + (data), (flags), (vor), (tor)); \ + OUT_RING(0); \ +} while(0) + +/* Raw data + flags depending on FB/TT buffer */ +#define OUT_RELOCd(bo,data,flags,vor,tor) do { \ + OUT_RELOC((bo), (data), (flags) | NOUVEAU_BO_OR, (vor), (tor)); \ +} while(0) + +/* FB/TT object handle */ +#define OUT_RELOCo(bo,flags) do { \ + OUT_RELOC((bo), 0, (flags) | NOUVEAU_BO_OR, \ + nv50->nvws->channel->vram->handle, \ + nv50->nvws->channel->gart->handle); \ +} while(0) + +/* Low 32-bits of offset */ +#define OUT_RELOCl(bo,delta,flags) do { \ + OUT_RELOC((bo), (delta), (flags) | NOUVEAU_BO_LOW, 0, 0); \ +} while(0) + +/* High 32-bits of offset */ +#define OUT_RELOCh(bo,delta,flags) do { \ + OUT_RELOC((bo), (delta), (flags) | NOUVEAU_BO_HIGH, 0, 0); \ +} while(0) + +#endif diff --git a/src/mesa/pipe/nv50/nv50_draw.c b/src/mesa/pipe/nv50/nv50_draw.c new file mode 100644 index 00000000000..97088920284 --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_draw.c @@ -0,0 +1,63 @@ +#include "pipe/draw/draw_private.h" +#include "pipe/p_util.h" + +#include "nv50_context.h" + +struct nv50_draw_stage { + struct draw_stage draw; + struct nv50_context *nv50; +}; + +static void +nv50_draw_begin(struct draw_stage *draw) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_draw_end(struct draw_stage *draw) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_draw_point(struct draw_stage *draw, struct prim_header *prim) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_draw_line(struct draw_stage *draw, struct prim_header *prim) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_draw_tri(struct draw_stage *draw, struct prim_header *prim) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_draw_reset_stipple_counter(struct draw_stage *draw) +{ + NOUVEAU_ERR("\n"); +} + +struct draw_stage * +nv50_draw_render_stage(struct nv50_context *nv50) +{ + struct nv50_draw_stage *nv50draw = CALLOC_STRUCT(nv50_draw_stage); + + nv50draw->nv50 = nv50; + nv50draw->draw.draw = nv50->draw; + nv50draw->draw.begin = nv50_draw_begin; + nv50draw->draw.point = nv50_draw_point; + nv50draw->draw.line = nv50_draw_line; + nv50draw->draw.tri = nv50_draw_tri; + nv50draw->draw.end = nv50_draw_end; + nv50draw->draw.reset_stipple_counter = nv50_draw_reset_stipple_counter; + + return &nv50draw->draw; +} + diff --git a/src/mesa/pipe/nv50/nv50_miptree.c b/src/mesa/pipe/nv50/nv50_miptree.c new file mode 100644 index 00000000000..51442d64f3e --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_miptree.c @@ -0,0 +1,24 @@ +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" + +#include "nv50_context.h" + +static void +nv50_miptree_create(struct pipe_context *pipe, struct pipe_texture **pt) +{ + NOUVEAU_ERR("unimplemented\n"); +} + +static void +nv50_miptree_release(struct pipe_context *pipe, struct pipe_texture **pt) +{ + NOUVEAU_ERR("unimplemented\n"); +} + +void +nv50_init_miptree_functions(struct nv50_context *nv50) +{ + nv50->pipe.texture_create = nv50_miptree_create; + nv50->pipe.texture_release = nv50_miptree_release; +} diff --git a/src/mesa/pipe/nv50/nv50_query.c b/src/mesa/pipe/nv50/nv50_query.c new file mode 100644 index 00000000000..51cf6804d7c --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_query.c @@ -0,0 +1,30 @@ +#include "pipe/p_context.h" + +#include "nv50_context.h" +#include "nv50_dma.h" + +static void +nv50_query_begin(struct pipe_context *pipe, struct pipe_query_object *q) +{ + NOUVEAU_ERR("unimplemented\n"); +} + +static void +nv50_query_end(struct pipe_context *pipe, struct pipe_query_object *q) +{ + NOUVEAU_ERR("unimplemented\n"); +} + +static void +nv50_query_wait(struct pipe_context *pipe, struct pipe_query_object *q) +{ + NOUVEAU_ERR("unimplemented\n"); +} + +void +nv50_init_query_functions(struct nv50_context *nv50) +{ + nv50->pipe.begin_query = nv50_query_begin; + nv50->pipe.end_query = nv50_query_end; + nv50->pipe.wait_query = nv50_query_wait; +} diff --git a/src/mesa/pipe/nv50/nv50_state.c b/src/mesa/pipe/nv50/nv50_state.c new file mode 100644 index 00000000000..778b9f5c9ac --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_state.c @@ -0,0 +1,242 @@ +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" + +#include "nv50_context.h" +#include "nv50_dma.h" +#include "nv50_state.h" + +static void * +nv50_alpha_test_state_create(struct pipe_context *pipe, + const struct pipe_alpha_test_state *cso) +{ +} + +static void +nv50_alpha_test_state_bind(struct pipe_context *pipe, void *hwcso) +{ +} + +static void +nv50_alpha_test_state_delete(struct pipe_context *pipe, void *hwcso) +{ +} + +static void * +nv50_blend_state_create(struct pipe_context *pipe, + const struct pipe_blend_state *cso) +{ +} + +static void +nv50_blend_state_bind(struct pipe_context *pipe, void *hwcso) +{ +} + +static void +nv50_blend_state_delete(struct pipe_context *pipe, void *hwcso) +{ +} + +static void * +nv50_sampler_state_create(struct pipe_context *pipe, + const struct pipe_sampler_state *cso) +{ +} + +static void +nv50_sampler_state_bind(struct pipe_context *pipe, unsigned unit, + void *hwcso) +{ +} + +static void +nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso) +{ +} + +static void * +nv50_rasterizer_state_create(struct pipe_context *pipe, + const struct pipe_rasterizer_state *cso) +{ +} + +static void +nv50_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso) +{ +} + +static void +nv50_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso) +{ +} + +static void * +nv50_depth_stencil_state_create(struct pipe_context *pipe, + const struct pipe_depth_stencil_state *cso) +{ +} + +static void +nv50_depth_stencil_state_bind(struct pipe_context *pipe, void *hwcso) +{ +} + +static void +nv50_depth_stencil_state_delete(struct pipe_context *pipe, void *hwcso) +{ +} + +static void * +nv50_vp_state_create(struct pipe_context *pipe, + const struct pipe_shader_state *cso) +{ +} + +static void +nv50_vp_state_bind(struct pipe_context *pipe, void *hwcso) +{ +} + +static void +nv50_vp_state_delete(struct pipe_context *pipe, void *hwcso) +{ +} + +static void * +nv50_fp_state_create(struct pipe_context *pipe, + const struct pipe_shader_state *cso) +{ +} + +static void +nv50_fp_state_bind(struct pipe_context *pipe, void *hwcso) +{ +} + +static void +nv50_fp_state_delete(struct pipe_context *pipe, void *hwcso) +{ +} + +static void +nv50_set_blend_color(struct pipe_context *pipe, + const struct pipe_blend_color *bcol) +{ +} + +static void +nv50_set_clip_state(struct pipe_context *pipe, + const struct pipe_clip_state *clip) +{ +} + +static void +nv50_set_clear_color_state(struct pipe_context *pipe, + const struct pipe_clear_color_state *ccol) +{ +} + +static void +nv50_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, + const struct pipe_constant_buffer *buf ) +{ +} + +static void +nv50_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ +} + +static void +nv50_set_polygon_stipple(struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple) +{ +} + +static void +nv50_set_sampler_units(struct pipe_context *pipe, + uint num_samplers, const uint *units) +{ +} + +static void +nv50_set_scissor_state(struct pipe_context *pipe, + const struct pipe_scissor_state *s) +{ +} + +static void +nv50_set_texture_state(struct pipe_context *pipe, unsigned unit, + struct pipe_texture *pt) +{ +} + +static void +nv50_set_viewport_state(struct pipe_context *pipe, + const struct pipe_viewport_state *vpt) +{ +} + +static void +nv50_set_vertex_buffer(struct pipe_context *pipe, unsigned index, + const struct pipe_vertex_buffer *vb) +{ +} + +static void +nv50_set_vertex_element(struct pipe_context *pipe, unsigned index, + const struct pipe_vertex_element *ve) +{ +} + +void +nv50_init_state_functions(struct nv50_context *nv50) +{ + nv50->pipe.create_alpha_test_state = nv50_alpha_test_state_create; + nv50->pipe.bind_alpha_test_state = nv50_alpha_test_state_bind; + nv50->pipe.delete_alpha_test_state = nv50_alpha_test_state_delete; + + nv50->pipe.create_blend_state = nv50_blend_state_create; + nv50->pipe.bind_blend_state = nv50_blend_state_bind; + nv50->pipe.delete_blend_state = nv50_blend_state_delete; + + nv50->pipe.create_sampler_state = nv50_sampler_state_create; + nv50->pipe.bind_sampler_state = nv50_sampler_state_bind; + nv50->pipe.delete_sampler_state = nv50_sampler_state_delete; + + nv50->pipe.create_rasterizer_state = nv50_rasterizer_state_create; + nv50->pipe.bind_rasterizer_state = nv50_rasterizer_state_bind; + nv50->pipe.delete_rasterizer_state = nv50_rasterizer_state_delete; + + nv50->pipe.create_depth_stencil_state = nv50_depth_stencil_state_create; + nv50->pipe.bind_depth_stencil_state = nv50_depth_stencil_state_bind; + nv50->pipe.delete_depth_stencil_state = nv50_depth_stencil_state_delete; + + nv50->pipe.create_vs_state = nv50_vp_state_create; + nv50->pipe.bind_vs_state = nv50_vp_state_bind; + nv50->pipe.delete_vs_state = nv50_vp_state_delete; + + nv50->pipe.create_fs_state = nv50_fp_state_create; + nv50->pipe.bind_fs_state = nv50_fp_state_bind; + nv50->pipe.delete_fs_state = nv50_fp_state_delete; + + nv50->pipe.set_blend_color = nv50_set_blend_color; + nv50->pipe.set_clip_state = nv50_set_clip_state; + nv50->pipe.set_clear_color_state = nv50_set_clear_color_state; + nv50->pipe.set_constant_buffer = nv50_set_constant_buffer; + nv50->pipe.set_framebuffer_state = nv50_set_framebuffer_state; + nv50->pipe.set_polygon_stipple = nv50_set_polygon_stipple; + nv50->pipe.set_sampler_units = nv50_set_sampler_units; + nv50->pipe.set_scissor_state = nv50_set_scissor_state; + nv50->pipe.set_texture_state = nv50_set_texture_state; + nv50->pipe.set_viewport_state = nv50_set_viewport_state; + + nv50->pipe.set_vertex_buffer = nv50_set_vertex_buffer; + nv50->pipe.set_vertex_element = nv50_set_vertex_element; + +// nv50->pipe.set_feedback_state = nv50_set_feedback_state; +// nv50->pipe.set_feedback_buffer = nv50_set_feedback_buffer; +} + diff --git a/src/mesa/pipe/nv50/nv50_state.h b/src/mesa/pipe/nv50/nv50_state.h new file mode 100644 index 00000000000..a3b781d4c61 --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_state.h @@ -0,0 +1,7 @@ +#ifndef __NV50_STATE_H__ +#define __NV50_STATE_H__ + +#include "pipe/p_state.h" + + +#endif diff --git a/src/mesa/pipe/nv50/nv50_surface.c b/src/mesa/pipe/nv50/nv50_surface.c new file mode 100644 index 00000000000..7e294cdfdfc --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_surface.c @@ -0,0 +1,240 @@ + +/************************************************************************** + * + * Copyright 2003 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 "nv50_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" +#include "pipe/p_inlines.h" + + +#define CLIP_TILE \ + do { \ + if (x >= ps->width) \ + return; \ + if (y >= ps->height) \ + return; \ + if (x + w > ps->width) \ + w = ps->width - x; \ + if (y + h > ps->height) \ + h = ps->height -y; \ + } while(0) + + +/** + * Note: this is exactly like a8r8g8b8_get_tile() in sp_surface.c + * Share it someday. + */ +static void +nv50_get_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, float *p) +{ + const unsigned *src + = ((const unsigned *) (ps->map + ps->offset)) + + y * ps->pitch + x; + unsigned i, j; + unsigned w0 = w; + + CLIP_TILE; + + switch (ps->format) { + case PIPE_FORMAT_A8R8G8B8_UNORM: + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++) { + const unsigned pixel = src[j]; + 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; + } + break; + case PIPE_FORMAT_Z24S8_UNORM: + { + const float scale = 1.0 / (float) 0xffffff; + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++) { + const unsigned pixel = src[j]; + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = ((pixel & 0xffffff) >> 8) * scale; + pRow += 4; + } + src += ps->pitch; + p += w0 * 4; + } + } + break; + default: + assert(0); + } +} + + +static void +nv50_put_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, const float *p) +{ + /* TODO */ + assert(0); +} + + +/* + * XXX note: same as code in sp_surface.c + */ +static void +nv50_get_tile(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + void *p, int dst_stride) +{ + const uint cpp = ps->cpp; + const uint w0 = w; + const ubyte *pSrc; + ubyte *pDest; + uint i; + + assert(ps->map); + + CLIP_TILE; + + if (dst_stride == 0) { + dst_stride = w0 * cpp; + } + + pSrc = ps->map + ps->offset + (y * ps->pitch + x) * cpp; + pDest = (ubyte *) p; + + for (i = 0; i < h; i++) { + memcpy(pDest, pSrc, w0 * cpp); + pDest += dst_stride; + pSrc += ps->pitch * cpp; + } +} + + +/* + * XXX note: same as code in sp_surface.c + */ +static void +nv50_put_tile(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + const void *p, int src_stride) +{ + const uint cpp = ps->cpp; + const uint w0 = w; + const ubyte *pSrc; + ubyte *pDest; + uint i; + + assert(ps->map); + + CLIP_TILE; + + if (src_stride == 0) { + src_stride = w0 * cpp; + } + + pSrc = (const ubyte *) p; + pDest = ps->map + ps->offset + (y * ps->pitch + x) * cpp; + + for (i = 0; i < h; i++) { + memcpy(pDest, pSrc, w0 * cpp); + pDest += ps->pitch * cpp; + pSrc += src_stride; + } +} + + +static struct pipe_surface * +nv50_get_tex_surface(struct pipe_context *pipe, + struct pipe_texture *pt, + unsigned face, unsigned level, unsigned zslice) +{ + NOUVEAU_ERR("unimplemented\n"); + return NULL; +} + +static void +nv50_surface_data(struct pipe_context *pipe, struct pipe_surface *dest, + unsigned destx, unsigned desty, const void *src, + unsigned src_stride, unsigned srcx, unsigned srcy, + unsigned width, unsigned height) +{ + struct nv50_context *nv50 = (struct nv50_context *)pipe; + struct nouveau_winsys *nvws = nv50->nvws; + + nvws->surface_data(nvws, dest, destx, desty, src, src_stride, + srcx, srcy, width, height); +} + +static void +nv50_surface_copy(struct pipe_context *pipe, struct pipe_surface *dest, + unsigned destx, unsigned desty, struct pipe_surface *src, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + struct nv50_context *nv50 = (struct nv50_context *)pipe; + struct nouveau_winsys *nvws = nv50->nvws; + + nvws->surface_copy(nvws, dest, destx, desty, src, srcx, srcy, + width, height); +} + +static void +nv50_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest, + unsigned destx, unsigned desty, unsigned width, + unsigned height, unsigned value) +{ + struct nv50_context *nv50 = (struct nv50_context *)pipe; + struct nouveau_winsys *nvws = nv50->nvws; + + nvws->surface_fill(nvws, dest, destx, desty, width, height, value); +} + +void +nv50_init_surface_functions(struct nv50_context *nv50) +{ + nv50->pipe.get_tex_surface = nv50_get_tex_surface; + nv50->pipe.get_tile = nv50_get_tile; + nv50->pipe.put_tile = nv50_put_tile; + nv50->pipe.get_tile_rgba = nv50_get_tile_rgba; + nv50->pipe.put_tile_rgba = nv50_put_tile_rgba; + nv50->pipe.surface_data = nv50_surface_data; + nv50->pipe.surface_copy = nv50_surface_copy; + nv50->pipe.surface_fill = nv50_surface_fill; +} diff --git a/src/mesa/pipe/nv50/nv50_vbo.c b/src/mesa/pipe/nv50/nv50_vbo.c new file mode 100644 index 00000000000..faae08f6014 --- /dev/null +++ b/src/mesa/pipe/nv50/nv50_vbo.c @@ -0,0 +1,25 @@ +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_util.h" + +#include "nv50_context.h" +#include "nv50_dma.h" +#include "nv50_state.h" + +boolean +nv50_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, + unsigned count) +{ + NOUVEAU_ERR("unimplemented\n"); + return TRUE; +} + +boolean +nv50_draw_elements(struct pipe_context *pipe, + struct pipe_buffer_handle *indexBuffer, unsigned indexSize, + unsigned mode, unsigned start, unsigned count) +{ + NOUVEAU_ERR("unimplemented\n"); + return TRUE; +} + diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 8bed958feb3..b3a2122ade9 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -37,7 +37,7 @@ struct pipe_state_cache; * Gallium rendering context. Basically: * - state setting functions * - VBO drawing functions - * - memory region function + * - surface functions * - device queries */ struct pipe_context { @@ -51,7 +51,7 @@ struct pipe_context { * Queries */ boolean (*is_format_supported)( struct pipe_context *pipe, - uint format ); + enum pipe_format format ); const char *(*get_name)( struct pipe_context *pipe ); @@ -155,7 +155,7 @@ struct pipe_context { void (*set_texture_state)( struct pipe_context *, unsigned unit, - struct pipe_mipmap_tree * ); + struct pipe_texture * ); void (*set_viewport_state)( struct pipe_context *, const struct pipe_viewport_state * ); @@ -180,7 +180,7 @@ struct pipe_context { /** Get a surface which is a "view" into a texture */ struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe, - struct pipe_mipmap_tree *texture, + struct pipe_texture *texture, unsigned face, unsigned level, unsigned zslice); @@ -202,43 +202,38 @@ struct pipe_context { /* - * Memory region functions + * Surface functions */ - ubyte *(*region_map)(struct pipe_context *pipe, struct pipe_region *r); - - void (*region_unmap)(struct pipe_context *pipe, struct pipe_region *r); - - void (*region_data)(struct pipe_context *pipe, - struct pipe_region *dest, - unsigned dest_offset, - unsigned destx, unsigned desty, - const void *src, unsigned src_stride, - unsigned srcx, unsigned srcy, - unsigned width, unsigned height); - - void (*region_copy)(struct pipe_context *pipe, - struct pipe_region *dest, - unsigned dest_offset, - unsigned destx, unsigned desty, - struct pipe_region *src, /* don't make this const - - need to map/unmap */ - unsigned src_offset, - unsigned srcx, unsigned srcy, - unsigned width, unsigned height); - - void (*region_fill)(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, - unsigned value); + void (*surface_data)(struct pipe_context *pipe, + struct pipe_surface *dest, + unsigned destx, unsigned desty, + const void *src, unsigned src_stride, + unsigned srcx, unsigned srcy, + unsigned width, unsigned height); + + void (*surface_copy)(struct pipe_context *pipe, + struct pipe_surface *dest, + unsigned destx, unsigned desty, + struct pipe_surface *src, /* don't make this const - + need to map/unmap */ + unsigned srcx, unsigned srcy, + unsigned width, unsigned height); + + void (*surface_fill)(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, + unsigned value); /* * Texture functions */ - boolean (*mipmap_tree_layout)( struct pipe_context *pipe, - struct pipe_mipmap_tree *mt ); + void (*texture_create)(struct pipe_context *pipe, + struct pipe_texture **pt); + + void (*texture_release)(struct pipe_context *pipe, + struct pipe_texture **pt); /* Flush rendering: diff --git a/src/mesa/pipe/p_format.h b/src/mesa/pipe/p_format.h index f42f987c4e3..8f11bfab76b 100644 --- a/src/mesa/pipe/p_format.h +++ b/src/mesa/pipe/p_format.h @@ -97,16 +97,18 @@ static INLINE uint pf_get(pipe_format_rgbazs_t f, uint shift, uint mask) return (f >> shift) & mask; } -#define pf_swizzle_x(f) pf_get(f, 2, 0x7) /**< PIPE_FORMAT_COMP_ */ -#define pf_swizzle_y(f) pf_get(f, 5, 0x7) /**< PIPE_FORMAT_COMP_ */ -#define pf_swizzle_z(f) pf_get(f, 8, 0x7) /**< PIPE_FORMAT_COMP_ */ -#define pf_swizzle_w(f) pf_get(f, 11, 0x7) /**< PIPE_FORMAT_COMP_ */ -#define pf_size_x(f) pf_get(f, 14, 0x7) /**< Size of X - 1 */ -#define pf_size_y(f) pf_get(f, 17, 0x7) /**< Size of Y - 1 */ -#define pf_size_z(f) pf_get(f, 20, 0x7) /**< Size of Z - 1 */ -#define pf_size_w(f) pf_get(f, 23, 0x7) /**< Size of W - 1 */ -#define pf_exp8(f) pf_get(f, 26, 0x3) /**< Scale size by 8 ^ exp8 */ -#define pf_type(f) pf_get(f, 28, 0xf) /**< PIPE_FORMAT_TYPE_ */ +#define pf_swizzle_x(f) pf_get(f, 2, 0x7) /**< PIPE_FORMAT_COMP_ */ +#define pf_swizzle_y(f) pf_get(f, 5, 0x7) /**< PIPE_FORMAT_COMP_ */ +#define pf_swizzle_z(f) pf_get(f, 8, 0x7) /**< PIPE_FORMAT_COMP_ */ +#define pf_swizzle_w(f) pf_get(f, 11, 0x7) /**< PIPE_FORMAT_COMP_ */ +#define pf_swizzle_xyzw(f,i) pf_get(f, 2+((i)*3), 0x7) +#define pf_size_x(f) pf_get(f, 14, 0x7) /**< Size of X */ +#define pf_size_y(f) pf_get(f, 17, 0x7) /**< Size of Y */ +#define pf_size_z(f) pf_get(f, 20, 0x7) /**< Size of Z */ +#define pf_size_w(f) pf_get(f, 23, 0x7) /**< Size of W */ +#define pf_size_xyzw(f,i) pf_get(f, 14+((i)*3), 0x7) +#define pf_exp8(f) pf_get(f, 26, 0x3) /**< Scale size by 8 ^ exp8 */ +#define pf_type(f) pf_get(f, 28, 0xf) /**< PIPE_FORMAT_TYPE_ */ /** * Helper macro to encode the above structure into a 32-bit value. @@ -127,31 +129,19 @@ static INLINE uint pf_get(pipe_format_rgbazs_t f, uint shift, uint mask) #define _PIPE_FORMAT_SWZ( SWZX, SWZY, SWZZ, SWZW ) (((SWZX) << 0) | ((SWZY) << 3) | ((SWZZ) << 6) | ((SWZW) << 9)) /** - * Shorthand macro for RGBAZS layout with uniform component sizes in 1-bit units. + * Shorthand macro for RGBAZS layout with component sizes in 1-bit units. */ -#define _PIPE_FORMAT_RGBAZS_1U( SWZ, SIZE, TYPE )\ - _PIPE_FORMAT_RGBAZS( SWZ, SIZE, SIZE, SIZE, SIZE, 0, TYPE ) - -/** - * Shorthand macro for RGBAZS layout with non-uniform component sizes in 1-bit units. - */ -#define _PIPE_FORMAT_RGBAZS_1N( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ +#define _PIPE_FORMAT_RGBAZS_1( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 0, TYPE ) /** - * Shorthand macro for RGBAZS layout with uniform component sizes in 8-bit units. + * Shorthand macro for RGBAZS layout with component sizes in 8-bit units. */ -#define _PIPE_FORMAT_RGBAZS_8U( SWZ, SIZE, TYPE )\ - _PIPE_FORMAT_RGBAZS( SWZ, SIZE, SIZE, SIZE, SIZE, 1, TYPE ) - -/** - * Shorthand macro for RGBAZS layout with non-uniform component sizes in 8-bit units. - */ -#define _PIPE_FORMAT_RGBAZS_8N( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ +#define _PIPE_FORMAT_RGBAZS_8( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 1, TYPE ) /** - * Shorthand macro for RGBAZS layout with non-uniform component sizes in 64-bit units. + * Shorthand macro for RGBAZS layout with component sizes in 64-bit units. */ #define _PIPE_FORMAT_RGBAZS_64( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 2, TYPE ) @@ -164,6 +154,7 @@ static INLINE uint pf_get(pipe_format_rgbazs_t f, uint shift, uint mask) #define _PIPE_FORMAT_RGB0 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_A ) #define _PIPE_FORMAT_RGBA _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_A ) #define _PIPE_FORMAT_ARGB _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_A, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B ) +#define _PIPE_FORMAT_BGRA _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_A ) #define _PIPE_FORMAT_0000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) #define _PIPE_FORMAT_000R _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_R ) #define _PIPE_FORMAT_RRR1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_1 ) @@ -207,83 +198,172 @@ static INLINE uint pf_rev(pipe_format_ycbcr_t f) * z24s8, compressed textures, ycbcr, etc that won't fit that model. */ -#define PIPE_FORMAT_NONE _PIPE_FORMAT_RGBAZS_1U( _PIPE_FORMAT_0000, 0, PIPE_FORMAT_TYPE_UNKNOWN ) /**< unstructured */ -#define PIPE_FORMAT_U_A8_R8_G8_B8 _PIPE_FORMAT_RGBAZS_8U( _PIPE_FORMAT_ARGB, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte[4] ARGB */ -#define PIPE_FORMAT_U_A1_R5_G5_B5 _PIPE_FORMAT_RGBAZS_1N( _PIPE_FORMAT_ARGB, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ) /**< 16-bit packed RGBA */ -#define PIPE_FORMAT_U_A4_R4_G4_B4 _PIPE_FORMAT_RGBAZS_1U( _PIPE_FORMAT_ARGB, 4, PIPE_FORMAT_TYPE_UNORM ) /**< 16-bit packed RGBA */ -#define PIPE_FORMAT_U_R5_G6_B5 _PIPE_FORMAT_RGBAZS_1N( _PIPE_FORMAT_RGB0, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ) /**< 16-bit packed RGB */ -#define PIPE_FORMAT_U_L8 _PIPE_FORMAT_RGBAZS_8U( _PIPE_FORMAT_RRR1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte luminance */ -#define PIPE_FORMAT_U_A8 _PIPE_FORMAT_RGBAZS_8U( _PIPE_FORMAT_000R, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte alpha */ -#define PIPE_FORMAT_U_I8 _PIPE_FORMAT_RGBAZS_8U( _PIPE_FORMAT_RRRR, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte intensity */ -#define PIPE_FORMAT_U_A8_L8 _PIPE_FORMAT_RGBAZS_8U( _PIPE_FORMAT_RRRG, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte alpha, luminance */ -#define PIPE_FORMAT_S_R16_G16_B16_A16 _PIPE_FORMAT_RGBAZS_8U( _PIPE_FORMAT_RGBA, 2, PIPE_FORMAT_TYPE_SNORM ) /**< signed 16-bit RGBA (accum) */ -#define PIPE_FORMAT_YCBCR _PIPE_FORMAT_YCBCR( 0 ) -#define PIPE_FORMAT_YCBCR_REV _PIPE_FORMAT_YCBCR( 1 ) -#define PIPE_FORMAT_U_Z16 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_Z000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< ushort Z/depth */ -#define PIPE_FORMAT_U_Z32 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< uint Z/depth */ -#define PIPE_FORMAT_F_Z32 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) /**< float Z/depth */ -#define PIPE_FORMAT_S8_Z24 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< 8-bit stencil + 24-bit Z */ -#define PIPE_FORMAT_Z24_S8 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< 24-bit Z + 8-bit stencil */ -#define PIPE_FORMAT_U_S8 _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) /**< 8-bit stencil */ -#define PIPE_FORMAT_R64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64B64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64B64A64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32_FLOAT _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32_FLOAT _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32B32_FLOAT _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32B32A32_FLOAT _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32B32_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32B32A32_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32B32_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32B32A32_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32B32_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32B32A32_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32B32_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32B32A32_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16B16_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16B16A16_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16B16_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16B16A16_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16B16_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16B16A16_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16B16_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16B16A16_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8B8_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8B8A8_UNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8B8_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8B8A8_USCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8B8_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8B8A8_SNORM _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8B8_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8B8A8_SSCALED _PIPE_FORMAT_RGBAZS_8N( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ) - -/* Duplicated formats: +enum pipe_format { + PIPE_FORMAT_NONE = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_0000, 0, 0, 0, 0, PIPE_FORMAT_TYPE_UNKNOWN ), + PIPE_FORMAT_A8R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ARGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_B8G8R8A8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_A1R5G5B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_A4R4G4B4_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R5G6B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB0, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_U_L8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte luminance */ + PIPE_FORMAT_U_A8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_000R, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha */ + PIPE_FORMAT_U_I8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRR, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte intensity */ + PIPE_FORMAT_U_A8_L8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha, luminance */ + PIPE_FORMAT_YCBCR = _PIPE_FORMAT_YCBCR( 0 ), + PIPE_FORMAT_YCBCR_REV = _PIPE_FORMAT_YCBCR( 1 ), + PIPE_FORMAT_Z16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_S8Z24_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z24S8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_S8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte stencil */ + PIPE_FORMAT_R64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64B64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64B64A64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32B32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32B32A32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32B32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32B32A32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32B32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32B32A32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32B32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32B32A32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32B32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32B32A32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16B16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16B16A16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16B16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16B16A16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16B16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16B16A16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16B16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16B16A16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8B8A8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8B8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8B8A8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8B8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8B8A8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8A8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ) +}; + + +/** + * XXX should remove this, but S8_UNORM is a poor name + */ +#define PIPE_FORMAT_U_S8 PIPE_FORMAT_S8_UNORM + + +/** + * Builds pipe format name from format token. */ -#define PIPE_FORMAT_U_R8_G8_B8_A8 PIPE_FORMAT_R8G8B8A8_UNORM +static INLINE char *pf_sprint_name( char *str, uint format ) +{ + strcpy( str, "PIPE_FORMAT_" ); + switch (pf_layout( format )) { + case PIPE_FORMAT_LAYOUT_RGBAZS: { + pipe_format_rgbazs_t rgbazs = (pipe_format_rgbazs_t) format; + uint i; + uint scale = 1 << (pf_exp8( rgbazs ) * 3); + + for (i = 0; i < 4; i++) { + uint size = pf_size_xyzw( rgbazs, i ); + + if (size == 0) { + break; + } + switch (pf_swizzle_xyzw( rgbazs, i )) { + case PIPE_FORMAT_COMP_R: + strcat( str, "R" ); + break; + case PIPE_FORMAT_COMP_G: + strcat( str, "G" ); + break; + case PIPE_FORMAT_COMP_B: + strcat( str, "B" ); + break; + case PIPE_FORMAT_COMP_A: + strcat( str, "A" ); + break; + case PIPE_FORMAT_COMP_0: + strcat( str, "0" ); + break; + case PIPE_FORMAT_COMP_1: + strcat( str, "1" ); + break; + case PIPE_FORMAT_COMP_Z: + strcat( str, "Z" ); + break; + case PIPE_FORMAT_COMP_S: + strcat( str, "S" ); + break; + } + sprintf( &str[strlen( str )], "%u", size * scale ); + } + if (i != 0) { + strcat( str, "_" ); + } + switch (pf_type( rgbazs )) { + case PIPE_FORMAT_TYPE_UNKNOWN: + strcat( str, "NONE" ); + break; + case PIPE_FORMAT_TYPE_FLOAT: + strcat( str, "FLOAT" ); + break; + case PIPE_FORMAT_TYPE_UNORM: + strcat( str, "UNORM" ); + break; + case PIPE_FORMAT_TYPE_SNORM: + strcat( str, "SNORM" ); + break; + case PIPE_FORMAT_TYPE_USCALED: + strcat( str, "USCALED" ); + break; + case PIPE_FORMAT_TYPE_SSCALED: + strcat( str, "SSCALED" ); + break; + } + } + break; + case PIPE_FORMAT_LAYOUT_YCBCR: { + pipe_format_ycbcr_t ycbcr = (pipe_format_ycbcr_t) format; + + strcat( str, "YCBCR" ); + if (pf_rev( ycbcr )) { + strcat( str, "_REV" ); + } + } + break; + } + return str; +} #endif diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index 2418d016e15..e7303c45c1b 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -29,40 +29,43 @@ #define P_INLINES_H #include "p_context.h" +#include "p_defines.h" #include "p_winsys.h" -/** - * Set 'ptr' to point to 'region' and update reference counting. - * The old thing pointed to, if any, will be unreferenced first. - * 'region' may be NULL. - */ +static INLINE ubyte * +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; +} + static INLINE void -pipe_region_reference(struct pipe_region **ptr, struct pipe_region *region) +pipe_surface_unmap(struct pipe_surface *surface) { - assert(ptr); - if (*ptr) { - /* unreference the old thing */ - struct pipe_region *oldReg = *ptr; - assert(oldReg->refcount > 0); - oldReg->refcount--; - if (oldReg->refcount == 0) { - /* free the old region */ - assert(oldReg->map_refcount == 0); - /* XXX dereference the region->buffer */ - FREE( oldReg ); + if (surface->map_refcount > 0) { + assert(surface->map); + if (!--surface->map_refcount) { + surface->winsys->buffer_unmap( surface->winsys, + surface->buffer ); + surface->map = NULL; } - *ptr = NULL; - } - if (region) { - /* reference the new thing */ - region->refcount++; - *ptr = region; } } + /** - * \sa pipe_region_reference + * Set 'ptr' to point to 'surf' and update reference counting. + * The old thing pointed to, if any, will be unreferenced first. + * 'surf' may be NULL. */ static INLINE void pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) @@ -80,4 +83,25 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) } } + +/** + * \sa pipe_surface_reference + */ +static INLINE void +pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr, + struct pipe_texture *pt) +{ + assert(ptr); + if (*ptr) { + pipe->texture_release(pipe, ptr); + assert(!*ptr); + } + if (pt) { + /* reference the new thing */ + pt->refcount++; + *ptr = pt; + } +} + + #endif /* P_INLINES_H */ diff --git a/src/mesa/pipe/p_shader_tokens.h b/src/mesa/pipe/p_shader_tokens.h new file mode 100644 index 00000000000..e5922b439f6 --- /dev/null +++ b/src/mesa/pipe/p_shader_tokens.h @@ -0,0 +1,805 @@ +#if !defined TGSI_TOKEN_H +#define TGSI_TOKEN_H + +#if defined __cplusplus +extern "C" { +#endif // defined __cplusplus + +struct tgsi_version +{ + unsigned MajorVersion : 8; + unsigned MinorVersion : 8; + unsigned Padding : 16; +}; + +struct tgsi_header +{ + unsigned HeaderSize : 8; + unsigned BodySize : 24; +}; + +#define TGSI_PROCESSOR_FRAGMENT 0 +#define TGSI_PROCESSOR_VERTEX 1 +#define TGSI_PROCESSOR_GEOMETRY 2 + +struct tgsi_processor +{ + unsigned Processor : 4; /* TGSI_PROCESSOR_ */ + unsigned Padding : 28; +}; + +#define TGSI_TOKEN_TYPE_DECLARATION 0 +#define TGSI_TOKEN_TYPE_IMMEDIATE 1 +#define TGSI_TOKEN_TYPE_INSTRUCTION 2 + +struct tgsi_token +{ + unsigned Type : 4; /* TGSI_TOKEN_TYPE_ */ + unsigned Size : 8; /* UINT */ + unsigned Padding : 19; + unsigned Extended : 1; /* BOOL */ +}; + +#define TGSI_FILE_NULL 0 +#define TGSI_FILE_CONSTANT 1 +#define TGSI_FILE_INPUT 2 +#define TGSI_FILE_OUTPUT 3 +#define TGSI_FILE_TEMPORARY 4 +#define TGSI_FILE_SAMPLER 5 +#define TGSI_FILE_ADDRESS 6 +#define TGSI_FILE_IMMEDIATE 7 + +#define TGSI_DECLARE_RANGE 0 +#define TGSI_DECLARE_MASK 1 + +#define TGSI_WRITEMASK_NONE 0x00 +#define TGSI_WRITEMASK_X 0x01 +#define TGSI_WRITEMASK_Y 0x02 +#define TGSI_WRITEMASK_XY 0x03 +#define TGSI_WRITEMASK_Z 0x04 +#define TGSI_WRITEMASK_XZ 0x05 +#define TGSI_WRITEMASK_YZ 0x06 +#define TGSI_WRITEMASK_XYZ 0x07 +#define TGSI_WRITEMASK_W 0x08 +#define TGSI_WRITEMASK_XW 0x09 +#define TGSI_WRITEMASK_YW 0x0A +#define TGSI_WRITEMASK_XYW 0x0B +#define TGSI_WRITEMASK_ZW 0x0C +#define TGSI_WRITEMASK_XZW 0x0D +#define TGSI_WRITEMASK_YZW 0x0E +#define TGSI_WRITEMASK_XYZW 0x0F + +struct tgsi_declaration +{ + unsigned Type : 4; /* TGSI_TOKEN_TYPE_DECLARATION */ + unsigned Size : 8; /* UINT */ + unsigned File : 4; /* one of TGSI_FILE_x */ + unsigned Declare : 4; /* one of TGSI_DECLARE_x */ + unsigned UsageMask : 4; /* bitmask of TGSI_WRITEMASK_x flags */ + unsigned Interpolate : 1; /* BOOL, any interpolation info? */ + unsigned Semantic : 1; /* BOOL, any semantic info? */ + unsigned Padding : 5; + unsigned Extended : 1; /* BOOL */ +}; + +struct tgsi_declaration_range +{ + unsigned First : 16; /* UINT */ + unsigned Last : 16; /* UINT */ +}; + +struct tgsi_declaration_mask +{ + unsigned Mask : 32; /* UINT */ +}; + +#define TGSI_INTERPOLATE_CONSTANT 0 +#define TGSI_INTERPOLATE_LINEAR 1 +#define TGSI_INTERPOLATE_PERSPECTIVE 2 + +struct tgsi_declaration_interpolation +{ + unsigned Interpolate : 4; /* TGSI_INTERPOLATE_ */ + unsigned Padding : 28; +}; + +#define TGSI_SEMANTIC_POSITION 0 +#define TGSI_SEMANTIC_COLOR 1 +#define TGSI_SEMANTIC_BCOLOR 2 /**< back-face color */ +#define TGSI_SEMANTIC_FOG 3 +#define TGSI_SEMANTIC_PSIZE 4 +#define TGSI_SEMANTIC_GENERIC 5 +#define TGSI_SEMANTIC_COUNT 6 /**< number of semantic values */ + +struct tgsi_declaration_semantic +{ + unsigned SemanticName : 8; /* one of TGSI_SEMANTIC_ */ + unsigned SemanticIndex : 16; /* UINT */ + unsigned Padding : 8; +}; + +#define TGSI_IMM_FLOAT32 0 + +struct tgsi_immediate +{ + unsigned Type : 4; /* TGSI_TOKEN_TYPE_IMMEDIATE */ + unsigned Size : 8; /* UINT */ + unsigned DataType : 4; /* TGSI_IMM_ */ + unsigned Padding : 15; + unsigned Extended : 1; /* BOOL */ +}; + +struct tgsi_immediate_float32 +{ + float Float; +}; + +/* + * GL_NV_vertex_program + */ +#define TGSI_OPCODE_ARL 0 +#define TGSI_OPCODE_MOV 1 +#define TGSI_OPCODE_LIT 2 +#define TGSI_OPCODE_RCP 3 +#define TGSI_OPCODE_RSQ 4 +#define TGSI_OPCODE_EXP 5 +#define TGSI_OPCODE_LOG 6 +#define TGSI_OPCODE_MUL 7 +#define TGSI_OPCODE_ADD 8 +#define TGSI_OPCODE_DP3 9 +#define TGSI_OPCODE_DP4 10 +#define TGSI_OPCODE_DST 11 +#define TGSI_OPCODE_MIN 12 +#define TGSI_OPCODE_MAX 13 +#define TGSI_OPCODE_SLT 14 +#define TGSI_OPCODE_SGE 15 +#define TGSI_OPCODE_MAD 16 + +/* + * GL_ATI_fragment_shader + */ +#define TGSI_OPCODE_SUB 17 +#define TGSI_OPCODE_DOT3 TGSI_OPCODE_DP3 +#define TGSI_OPCODE_DOT4 TGSI_OPCODE_DP4 +#define TGSI_OPCODE_LERP 18 +#define TGSI_OPCODE_CND 19 +#define TGSI_OPCODE_CND0 20 +#define TGSI_OPCODE_DOT2ADD 21 + +/* + * GL_EXT_vertex_shader + */ +#define TGSI_OPCODE_INDEX 22 +#define TGSI_OPCODE_NEGATE 23 +#define TGSI_OPCODE_MADD TGSI_OPCODE_MAD +#define TGSI_OPCODE_FRAC 24 +#define TGSI_OPCODE_SETGE TGSI_OPCODE_SGE +#define TGSI_OPCODE_SETLT TGSI_OPCODE_SLT +#define TGSI_OPCODE_CLAMP 25 +#define TGSI_OPCODE_FLOOR 26 +#define TGSI_OPCODE_ROUND 27 +#define TGSI_OPCODE_EXPBASE2 28 +#define TGSI_OPCODE_LOGBASE2 29 +#define TGSI_OPCODE_POWER 30 +#define TGSI_OPCODE_RECIP TGSI_OPCODE_RCP +#define TGSI_OPCODE_RECIPSQRT TGSI_OPCODE_RSQ +#define TGSI_OPCODE_CROSSPRODUCT 31 +#define TGSI_OPCODE_MULTIPLYMATRIX 32 + +/* + * GL_NV_vertex_program1_1 + */ +#define TGSI_OPCODE_ABS 33 +#define TGSI_OPCODE_RCC 34 +#define TGSI_OPCODE_DPH 35 + +/* + * GL_NV_fragment_program + */ +#define TGSI_OPCODE_COS 36 +#define TGSI_OPCODE_DDX 37 +#define TGSI_OPCODE_DDY 38 +#define TGSI_OPCODE_EX2 TGSI_OPCODE_EXPBASE2 +#define TGSI_OPCODE_FLR TGSI_OPCODE_FLOOR +#define TGSI_OPCODE_FRC TGSI_OPCODE_FRAC +#define TGSI_OPCODE_KILP 39 /* predicated kill */ +#define TGSI_OPCODE_LG2 TGSI_OPCODE_LOGBASE2 +#define TGSI_OPCODE_LRP TGSI_OPCODE_LERP +#define TGSI_OPCODE_PK2H 40 +#define TGSI_OPCODE_PK2US 41 +#define TGSI_OPCODE_PK4B 42 +#define TGSI_OPCODE_PK4UB 43 +#define TGSI_OPCODE_POW TGSI_OPCODE_POWER +#define TGSI_OPCODE_RFL 44 +#define TGSI_OPCODE_SEQ 45 +#define TGSI_OPCODE_SFL 46 +#define TGSI_OPCODE_SGT 47 +#define TGSI_OPCODE_SIN 48 +#define TGSI_OPCODE_SLE 49 +#define TGSI_OPCODE_SNE 50 +#define TGSI_OPCODE_STR 51 +#define TGSI_OPCODE_TEX 52 +#define TGSI_OPCODE_TXD 53 +#define TGSI_OPCODE_UP2H 54 +#define TGSI_OPCODE_UP2US 55 +#define TGSI_OPCODE_UP4B 56 +#define TGSI_OPCODE_UP4UB 57 +#define TGSI_OPCODE_X2D 58 + +/* + * GL_NV_vertex_program2 + */ +#define TGSI_OPCODE_ARA 59 +#define TGSI_OPCODE_ARR 60 +#define TGSI_OPCODE_BRA 61 +#define TGSI_OPCODE_CAL 62 +#define TGSI_OPCODE_RET 63 +#define TGSI_OPCODE_SSG 64 + +/* + * GL_ARB_vertex_program + */ +#define TGSI_OPCODE_SWZ TGSI_OPCODE_MOV +#define TGSI_OPCODE_XPD TGSI_OPCODE_CROSSPRODUCT + +/* + * GL_ARB_fragment_program + */ +#define TGSI_OPCODE_CMP 65 +#define TGSI_OPCODE_SCS 66 +#define TGSI_OPCODE_TXB 67 + +/* + * GL_NV_fragment_program_option + */ +/* No new opcode */ + +/* + * GL_NV_fragment_program2 + */ +#define TGSI_OPCODE_NRM 68 +#define TGSI_OPCODE_DIV 69 +#define TGSI_OPCODE_DP2 70 +#define TGSI_OPCODE_DP2A TGSI_OPCODE_DOT2ADD +#define TGSI_OPCODE_TXL 71 +#define TGSI_OPCODE_BRK 72 +#define TGSI_OPCODE_IF 73 +#define TGSI_OPCODE_LOOP 74 +#define TGSI_OPCODE_REP 75 +#define TGSI_OPCODE_ELSE 76 +#define TGSI_OPCODE_ENDIF 77 +#define TGSI_OPCODE_ENDLOOP 78 +#define TGSI_OPCODE_ENDREP 79 + +/* + * GL_NV_vertex_program2_option + */ + +/* + * GL_NV_vertex_program3 + */ +#define TGSI_OPCODE_PUSHA 80 +#define TGSI_OPCODE_POPA 81 + +/* + * GL_NV_gpu_program4 + */ +#define TGSI_OPCODE_CEIL 82 +#define TGSI_OPCODE_I2F 83 +#define TGSI_OPCODE_NOT 84 +#define TGSI_OPCODE_TRUNC 85 +#define TGSI_OPCODE_SHL 86 +#define TGSI_OPCODE_SHR 87 +#define TGSI_OPCODE_AND 88 +#define TGSI_OPCODE_OR 89 +#define TGSI_OPCODE_MOD 90 +#define TGSI_OPCODE_XOR 91 +#define TGSI_OPCODE_SAD 92 +#define TGSI_OPCODE_TXF 93 +#define TGSI_OPCODE_TXQ 94 +#define TGSI_OPCODE_CONT 95 + +/* + * GL_NV_vertex_program4 + */ +/* Same as GL_NV_gpu_program4 */ + +/* + * GL_NV_fragment_program4 + */ +/* Same as GL_NV_gpu_program4 */ + +/* + * GL_NV_geometry_program4 + */ +/* Same as GL_NV_gpu_program4 */ +#define TGSI_OPCODE_EMIT 96 +#define TGSI_OPCODE_ENDPRIM 97 + +/* + * GLSL + */ +#define TGSI_OPCODE_BGNLOOP2 98 +#define TGSI_OPCODE_BGNSUB 99 +#define TGSI_OPCODE_ENDLOOP2 100 +#define TGSI_OPCODE_ENDSUB 101 +#define TGSI_OPCODE_INT TGSI_OPCODE_TRUNC +#define TGSI_OPCODE_NOISE1 102 +#define TGSI_OPCODE_NOISE2 103 +#define TGSI_OPCODE_NOISE3 104 +#define TGSI_OPCODE_NOISE4 105 +#define TGSI_OPCODE_NOP 106 + +/* + * ps_1_1 + */ +#define TGSI_OPCODE_TEXCOORD TGSI_OPCODE_NOP +#define TGSI_OPCODE_TEXKILL TGSI_OPCODE_KIL +#define TGSI_OPCODE_TEXBEM 107 +#define TGSI_OPCODE_TEXBEML 108 +#define TGSI_OPCODE_TEXREG2AR 109 +#define TGSI_OPCODE_TEXM3X2PAD 110 +#define TGSI_OPCODE_TEXM3X2TEX 111 +#define TGSI_OPCODE_TEXM3X3PAD 112 +#define TGSI_OPCODE_TEXM3X3TEX 113 +#define TGSI_OPCODE_TEXM3X3SPEC 114 +#define TGSI_OPCODE_TEXM3X3VSPEC 115 + +/* + * ps_1_2 + */ +#define TGSI_OPCODE_TEXREG2GB 116 +#define TGSI_OPCODE_TEXREG2RGB 117 +#define TGSI_OPCODE_TEXDP3TEX 118 +#define TGSI_OPCODE_TEXDP3 119 +#define TGSI_OPCODE_TEXM3X3 120 +/* CMP - use TGSI_OPCODE_CND0 */ + +/* + * ps_1_3 + */ +#define TGSI_OPCODE_TEXM3X2DEPTH 121 +/* CMP - use TGSI_OPCODE_CND0 */ + +/* + * ps_1_4 + */ +#define TGSI_OPCODE_TEXCRD TGSI_OPCODE_TEXCOORD +#define TGSI_OPCODE_TEXLD TGSI_OPCODE_TEX +#define TGSI_OPCODE_TEXDEPTH 122 +#define TGSI_OPCODE_BEM 123 + +/* + * ps_2_0 + */ +#define TGSI_OPCODE_M4X4 TGSI_OPCODE_MULTIPLYMATRIX +#define TGSI_OPCODE_M4X3 124 +#define TGSI_OPCODE_M3X4 125 +#define TGSI_OPCODE_M3X3 126 +#define TGSI_OPCODE_M3X2 127 +#define TGSI_OPCODE_CRS TGSI_OPCODE_XPD +#define TGSI_OPCODE_NRM4 128 +#define TGSI_OPCODE_SINCOS TGSI_OPCODE_SCS +#define TGSI_OPCODE_TEXLDB TGSI_OPCODE_TXB +#define TGSI_OPCODE_DP2ADD TGSI_OPCODE_DP2A + +/* + * ps_2_x + */ +#define TGSI_OPCODE_CALL TGSI_OPCODE_CAL +#define TGSI_OPCODE_CALLNZ 129 +#define TGSI_OPCODE_IFC 130 +#define TGSI_OPCODE_BREAK TGSI_OPCODE_BRK +#define TGSI_OPCODE_BREAKC 131 +#define TGSI_OPCODE_DSX TGSI_OPCODE_DDX +#define TGSI_OPCODE_DSY TGSI_OPCODE_DDY +#define TGSI_OPCODE_TEXLDD TGSI_OPCODE_TXD + +/* + * vs_1_1 + */ +#define TGSI_OPCODE_EXPP TGSI_OPCODE_EXP +#define TGSI_OPCODE_LOGP TGSI_OPCODE_LG2 + +/* + * vs_2_0 + */ +#define TGSI_OPCODE_SGN TGSI_OPCODE_SSG +#define TGSI_OPCODE_MOVA TGSI_OPCODE_ARR + +/* + * vs_2_x + */ + +#define TGSI_OPCODE_KIL 132 /* unpredicated kill */ +#define TGSI_OPCODE_END 133 /* aka HALT */ + +#define TGSI_OPCODE_LAST 134 + +#define TGSI_SAT_NONE 0 /* do not saturate */ +#define TGSI_SAT_ZERO_ONE 1 /* clamp to [0,1] */ +#define TGSI_SAT_MINUS_PLUS_ONE 2 /* clamp to [-1,1] */ + +/* + * Opcode is the operation code to execute. A given operation defines the + * semantics how the source registers (if any) are interpreted and what is + * written to the destination registers (if any) as a result of execution. + * + * NumDstRegs and NumSrcRegs is the number of destination and source registers, + * respectively. For a given operation code, those numbers are fixed and are + * present here only for convenience. + * + * If Extended is TRUE, it is now executed. + * + * Saturate controls how are final results in destination registers modified. + */ + +struct tgsi_instruction +{ + unsigned Type : 4; /* TGSI_TOKEN_TYPE_INSTRUCTION */ + unsigned Size : 8; /* UINT */ + unsigned Opcode : 8; /* TGSI_OPCODE_ */ + unsigned Saturate : 2; /* TGSI_SAT_ */ + unsigned NumDstRegs : 2; /* UINT */ + unsigned NumSrcRegs : 4; /* UINT */ + unsigned Padding : 3; + unsigned Extended : 1; /* BOOL */ +}; + +/* + * If tgsi_instruction::Extended is TRUE, tgsi_instruction_ext follows. + * + * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow. + * + * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow. + * + * tgsi_instruction::Size contains the total number of words that make the + * instruction, including the instruction word. + */ + +#define TGSI_INSTRUCTION_EXT_TYPE_NV 0 +#define TGSI_INSTRUCTION_EXT_TYPE_LABEL 1 +#define TGSI_INSTRUCTION_EXT_TYPE_TEXTURE 2 +#define TGSI_INSTRUCTION_EXT_TYPE_PREDICATE 3 + +struct tgsi_instruction_ext +{ + unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_ */ + unsigned Padding : 27; + unsigned Extended : 1; /* BOOL */ +}; + +/* + * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_NV, it should + * be cast to tgsi_instruction_ext_nv. + * + * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_LABEL, it + * should be cast to tgsi_instruction_ext_label. + * + * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_TEXTURE, it + * should be cast to tgsi_instruction_ext_texture. + * + * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_PREDICATE, it + * should be cast to tgsi_instruction_ext_predicate. + * + * If tgsi_instruction_ext::Extended is TRUE, another tgsi_instruction_ext + * follows. + */ + +#define TGSI_PRECISION_DEFAULT 0 +#define TGSI_PRECISION_FLOAT32 1 +#define TGSI_PRECISION_FLOAT16 2 +#define TGSI_PRECISION_FIXED12 3 + +#define TGSI_CC_GT 0 +#define TGSI_CC_EQ 1 +#define TGSI_CC_LT 2 +#define TGSI_CC_UN 3 +#define TGSI_CC_GE 4 +#define TGSI_CC_LE 5 +#define TGSI_CC_NE 6 +#define TGSI_CC_TR 7 +#define TGSI_CC_FL 8 + +#define TGSI_SWIZZLE_X 0 +#define TGSI_SWIZZLE_Y 1 +#define TGSI_SWIZZLE_Z 2 +#define TGSI_SWIZZLE_W 3 + +/* + * Precision controls the precision at which the operation should be executed. + * + * CondDstUpdate enables condition code register writes. When this field is + * TRUE, CondDstIndex specifies the index of the condition code register to + * update. + * + * CondFlowEnable enables conditional execution of the operation. When this + * field is TRUE, CondFlowIndex specifies the index of the condition code + * register to test against CondMask with component swizzle controled by + * CondSwizzleX, CondSwizzleY, CondSwizzleZ and CondSwizzleW. If the test fails, + * the operation is not executed. + */ + +struct tgsi_instruction_ext_nv +{ + unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_NV */ + unsigned Precision : 4; /* TGSI_PRECISION_ */ + unsigned CondDstIndex : 4; /* UINT */ + unsigned CondFlowIndex : 4; /* UINT */ + unsigned CondMask : 4; /* TGSI_CC_ */ + unsigned CondSwizzleX : 2; /* TGSI_SWIZZLE_ */ + unsigned CondSwizzleY : 2; /* TGSI_SWIZZLE_ */ + unsigned CondSwizzleZ : 2; /* TGSI_SWIZZLE_ */ + unsigned CondSwizzleW : 2; /* TGSI_SWIZZLE_ */ + unsigned CondDstUpdate : 1; /* BOOL */ + unsigned CondFlowEnable : 1; /* BOOL */ + unsigned Padding : 1; + unsigned Extended : 1; /* BOOL */ +}; + +struct tgsi_instruction_ext_label +{ + unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_LABEL */ + unsigned Label : 24; /* UINT */ + unsigned Padding : 3; + unsigned Extended : 1; /* BOOL */ +}; + +#define TGSI_TEXTURE_UNKNOWN 0 +#define TGSI_TEXTURE_1D 1 +#define TGSI_TEXTURE_2D 2 +#define TGSI_TEXTURE_3D 3 +#define TGSI_TEXTURE_CUBE 4 +#define TGSI_TEXTURE_RECT 5 +#define TGSI_TEXTURE_SHADOW1D 6 +#define TGSI_TEXTURE_SHADOW2D 7 +#define TGSI_TEXTURE_SHADOWRECT 8 + +struct tgsi_instruction_ext_texture +{ + unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_TEXTURE */ + unsigned Texture : 8; /* TGSI_TEXTURE_ */ + unsigned Padding : 19; + unsigned Extended : 1; /* BOOL */ +}; + +struct tgsi_instruction_ext_predicate +{ + unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_PREDICATE */ + unsigned PredDstIndex : 4; /* UINT */ + unsigned PredWriteMask : 4; /* TGSI_WRITEMASK_ */ + unsigned Padding : 19; + unsigned Extended : 1; /* BOOL */ +}; + +/* + * File specifies the register array to access. + * + * Index specifies the element number of a register in the register file. + * + * If Indirect is TRUE, Index should be offset by the X component of a source + * register that follows. The register can be now fetched into local storage + * for further processing. + * + * If Negate is TRUE, all components of the fetched register are negated. + * + * The fetched register components are swizzled according to SwizzleX, SwizzleY, + * SwizzleZ and SwizzleW. + * + * If Extended is TRUE, any further modifications to the source register are + * made to this temporary storage. + */ + +struct tgsi_src_register +{ + unsigned File : 4; /* TGSI_FILE_ */ + unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */ + unsigned Negate : 1; /* BOOL */ + unsigned Indirect : 1; /* BOOL */ + unsigned Dimension : 1; /* BOOL */ + int Index : 16; /* SINT */ + unsigned Extended : 1; /* BOOL */ +}; + +/* + * If tgsi_src_register::Extended is TRUE, tgsi_src_register_ext follows. + * + * Then, if tgsi_src_register::Indirect is TRUE, another tgsi_src_register + * follows. + * + * Then, if tgsi_src_register::Dimension is TRUE, tgsi_dimension follows. + */ + +#define TGSI_SRC_REGISTER_EXT_TYPE_SWZ 0 +#define TGSI_SRC_REGISTER_EXT_TYPE_MOD 1 + +struct tgsi_src_register_ext +{ + unsigned Type : 4; /* TGSI_SRC_REGISTER_EXT_TYPE_ */ + unsigned Padding : 27; + unsigned Extended : 1; /* BOOL */ +}; + +/* + * If tgsi_src_register_ext::Type is TGSI_SRC_REGISTER_EXT_TYPE_SWZ, + * it should be cast to tgsi_src_register_ext_extswz. + * + * If tgsi_src_register_ext::Type is TGSI_SRC_REGISTER_EXT_TYPE_MOD, + * it should be cast to tgsi_src_register_ext_mod. + * + * If tgsi_dst_register_ext::Extended is TRUE, another tgsi_dst_register_ext + * follows. + */ + +#define TGSI_EXTSWIZZLE_X TGSI_SWIZZLE_X +#define TGSI_EXTSWIZZLE_Y TGSI_SWIZZLE_Y +#define TGSI_EXTSWIZZLE_Z TGSI_SWIZZLE_Z +#define TGSI_EXTSWIZZLE_W TGSI_SWIZZLE_W +#define TGSI_EXTSWIZZLE_ZERO 4 +#define TGSI_EXTSWIZZLE_ONE 5 + +/* + * ExtSwizzleX, ExtSwizzleY, ExtSwizzleZ and ExtSwizzleW swizzle the source + * register in an extended manner. + * + * NegateX, NegateY, NegateZ and NegateW negate individual components of the + * source register. + * + * ExtDivide specifies which component is used to divide all components of the + * source register. + */ + +struct tgsi_src_register_ext_swz +{ + unsigned Type : 4; /* TGSI_SRC_REGISTER_EXT_TYPE_SWZ */ + unsigned ExtSwizzleX : 4; /* TGSI_EXTSWIZZLE_ */ + unsigned ExtSwizzleY : 4; /* TGSI_EXTSWIZZLE_ */ + unsigned ExtSwizzleZ : 4; /* TGSI_EXTSWIZZLE_ */ + unsigned ExtSwizzleW : 4; /* TGSI_EXTSWIZZLE_ */ + unsigned NegateX : 1; /* BOOL */ + unsigned NegateY : 1; /* BOOL */ + unsigned NegateZ : 1; /* BOOL */ + unsigned NegateW : 1; /* BOOL */ + unsigned ExtDivide : 4; /* TGSI_EXTSWIZZLE_ */ + unsigned Padding : 3; + unsigned Extended : 1; /* BOOL */ +}; + +/** + * Extra src register modifiers + * + * If Complement is TRUE, the source register is modified by subtracting it + * from 1.0. + * + * If Bias is TRUE, the source register is modified by subtracting 0.5 from it. + * + * If Scale2X is TRUE, the source register is modified by multiplying it by 2.0. + * + * If Absolute is TRUE, the source register is modified by removing the sign. + * + * If Negate is TRUE, the source register is modified by negating it. + */ + +struct tgsi_src_register_ext_mod +{ + unsigned Type : 4; /* TGSI_SRC_REGISTER_EXT_TYPE_MOD */ + unsigned Complement : 1; /* BOOL */ + unsigned Bias : 1; /* BOOL */ + unsigned Scale2X : 1; /* BOOL */ + unsigned Absolute : 1; /* BOOL */ + unsigned Negate : 1; /* BOOL */ + unsigned Padding : 22; + unsigned Extended : 1; /* BOOL */ +}; + +struct tgsi_dimension +{ + unsigned Indirect : 1; /* BOOL */ + unsigned Dimension : 1; /* BOOL */ + unsigned Padding : 13; + int Index : 16; /* SINT */ + unsigned Extended : 1; /* BOOL */ +}; + +struct tgsi_dst_register +{ + unsigned File : 4; /* TGSI_FILE_ */ + unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */ + unsigned Indirect : 1; /* BOOL */ + unsigned Dimension : 1; /* BOOL */ + int Index : 16; /* SINT */ + unsigned Padding : 5; + unsigned Extended : 1; /* BOOL */ +}; + +/* + * If tgsi_dst_register::Extended is TRUE, tgsi_dst_register_ext follows. + * + * Then, if tgsi_dst_register::Indirect is TRUE, tgsi_src_register follows. + */ + +#define TGSI_DST_REGISTER_EXT_TYPE_CONDCODE 0 +#define TGSI_DST_REGISTER_EXT_TYPE_MODULATE 1 +#define TGSI_DST_REGISTER_EXT_TYPE_PREDICATE 2 + +struct tgsi_dst_register_ext +{ + unsigned Type : 4; /* TGSI_DST_REGISTER_EXT_TYPE_ */ + unsigned Padding : 27; + unsigned Extended : 1; /* BOOL */ +}; + +/** + * Extra destination register modifiers + * + * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_CONDCODE, + * it should be cast to tgsi_dst_register_ext_condcode. + * + * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_MODULATE, + * it should be cast to tgsi_dst_register_ext_modulate. + * + * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_PREDICATE, + * it should be cast to tgsi_dst_register_ext_predicate. + * + * If tgsi_dst_register_ext::Extended is TRUE, another tgsi_dst_register_ext + * follows. + */ +struct tgsi_dst_register_ext_concode +{ + unsigned Type : 4; /* TGSI_DST_REGISTER_EXT_TYPE_CONDCODE */ + unsigned CondMask : 4; /* TGSI_CC_ */ + unsigned CondSwizzleX : 2; /* TGSI_SWIZZLE_ */ + unsigned CondSwizzleY : 2; /* TGSI_SWIZZLE_ */ + unsigned CondSwizzleZ : 2; /* TGSI_SWIZZLE_ */ + unsigned CondSwizzleW : 2; /* TGSI_SWIZZLE_ */ + unsigned CondSrcIndex : 4; /* UINT */ + unsigned Padding : 11; + unsigned Extended : 1; /* BOOL */ +}; + +#define TGSI_MODULATE_1X 0 +#define TGSI_MODULATE_2X 1 +#define TGSI_MODULATE_4X 2 +#define TGSI_MODULATE_8X 3 +#define TGSI_MODULATE_HALF 4 +#define TGSI_MODULATE_QUARTER 5 +#define TGSI_MODULATE_EIGHTH 6 + +struct tgsi_dst_register_ext_modulate +{ + unsigned Type : 4; /* TGSI_DST_REGISTER_EXT_TYPE_MODULATE */ + unsigned Modulate : 4; /* TGSI_MODULATE_ */ + unsigned Padding : 23; + unsigned Extended : 1; /* BOOL */ +}; + +/* + * Currently, the following constraints apply. + * + * - PredSwizzleXYZW is either set to identity or replicate. + * - PredSrcIndex is 0. + */ + +struct tgsi_dst_register_ext_predicate +{ + unsigned Type : 4; /* TGSI_DST_REGISTER_EXT_TYPE_PREDICATE */ + unsigned PredSwizzleX : 2; /* TGSI_SWIZZLE_ */ + unsigned PredSwizzleY : 2; /* TGSI_SWIZZLE_ */ + unsigned PredSwizzleZ : 2; /* TGSI_SWIZZLE_ */ + unsigned PredSwizzleW : 2; /* TGSI_SWIZZLE_ */ + unsigned PredSrcIndex : 4; /* UINT */ + unsigned Negate : 1; /* BOOL */ + unsigned Padding : 14; + unsigned Extended : 1; /* BOOL */ +}; + + +#if defined __cplusplus +} // extern "C" +#endif // defined __cplusplus + +#endif // !defined TGSI_TOKEN_H + diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 570f44e24ed..6db9bbc9534 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_format.h" /** * Implementation limits @@ -256,88 +257,47 @@ struct pipe_sampler_state }; -/*** - *** Resource Objects - ***/ - -struct pipe_region -{ - struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ - - unsigned refcount; /**< Reference count for region */ - unsigned cpp; /**< bytes per pixel */ - unsigned pitch; /**< in pixels */ - unsigned height; /**< in pixels */ - ubyte *map; /**< only non-NULL when region is actually mapped */ - unsigned map_refcount; /**< Reference count for mapping */ -}; - - /** - * 2D surface. This is basically a view into a pipe_region (memory buffer). + * 2D surface. This is basically a view into a memory buffer. * May be a renderbuffer, texture mipmap level, etc. */ struct pipe_surface { - struct pipe_region *region; - unsigned format; /**< PIPE_FORMAT_x */ + 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 cpp; /**< bytes per pixel */ unsigned width, height; - unsigned offset; /**< offset from start of region, in bytes */ + unsigned pitch; /**< in pixels */ + unsigned offset; /**< offset from start of buffer, in bytes */ unsigned refcount; struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ }; /** - * Describes the location of each texture image within a texture region. + * Texture. Represents one or several texture images on one or several mipmap + * levels. */ -struct pipe_mipmap_level -{ - unsigned level_offset; - unsigned width; - unsigned height; - unsigned depth; - unsigned nr_images; - - /* 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; /**< array [depth] of offsets */ -}; - -struct pipe_mipmap_tree -{ +struct pipe_texture +{ /* Effectively the key: */ unsigned target; /* XXX convert to PIPE_TEXTURE_x */ unsigned internal_format; /* XXX convert to PIPE_FORMAT_x */ - unsigned format; /**< PIPE_FORMAT_x */ + enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned first_level; unsigned last_level; - unsigned width0, height0, depth0; /**< Level zero image dimensions */ + unsigned width[PIPE_MAX_TEXTURE_LEVELS]; + unsigned height[PIPE_MAX_TEXTURE_LEVELS]; + unsigned depth[PIPE_MAX_TEXTURE_LEVELS]; unsigned cpp; unsigned compressed:1; - /* Derived from the above: - */ - unsigned pitch; - unsigned depth_pitch; /* per-image on i945? */ - unsigned total_height; - - /* Includes image offset tables: - */ - struct pipe_mipmap_level level[PIPE_MAX_TEXTURE_LEVELS]; - - /* The data is held here: - */ - struct pipe_region *region; - /* These are also refcounted: */ unsigned refcount; @@ -372,7 +332,7 @@ struct pipe_vertex_element unsigned vertex_buffer_index:5; unsigned dst_offset:8; - unsigned src_format; /**< PIPE_FORMAT_* */ + enum pipe_format src_format; /**< PIPE_FORMAT_* */ }; diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 41d522e11ea..438e8bdb63b 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -29,6 +29,8 @@ #define P_WINSYS_H +#include "p_format.h" + /** * \file * This is the interface that Gallium3D requires any window system @@ -80,15 +82,17 @@ struct pipe_winsys * flags is bitmask of PIPE_SURFACE_FLAG_RENDER, PIPE_SURFACE_FLAG_TEXTURE */ struct pipe_region *(*region_alloc)(struct pipe_winsys *ws, - unsigned cpp, unsigned width, - unsigned height, unsigned flags); + unsigned size, unsigned flags); void (*region_release)(struct pipe_winsys *ws, struct pipe_region **r); + unsigned (*surface_pitch)(struct pipe_winsys *ws, unsigned cpp, + unsigned with, unsigned flags); + /** allocate a new surface (no context dependency) */ struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, - unsigned format); + enum pipe_format format); void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile index 59628531cc8..647cc05373b 100644 --- a/src/mesa/pipe/softpipe/Makefile +++ b/src/mesa/pipe/softpipe/Makefile @@ -24,7 +24,6 @@ DRIVER_SOURCES = \ sp_quad_output.c \ sp_quad_stencil.c \ sp_quad_stipple.c \ - sp_region.c \ sp_state_blend.c \ sp_state_clip.c \ sp_state_derived.c \ @@ -34,7 +33,7 @@ DRIVER_SOURCES = \ sp_state_rasterizer.c \ sp_state_surface.c \ sp_state_vertex.c \ - sp_tex_layout.c \ + sp_texture.c \ sp_tex_sample.c \ sp_tile_cache.c \ sp_surface.c diff --git a/src/mesa/pipe/softpipe/sp_clear.c b/src/mesa/pipe/softpipe/sp_clear.c index 87f850b6fd9..5b3857145d6 100644 --- a/src/mesa/pipe/softpipe/sp_clear.c +++ b/src/mesa/pipe/softpipe/sp_clear.c @@ -47,39 +47,28 @@ softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps, unsigned clearValue) { struct softpipe_context *softpipe = softpipe_context(pipe); - unsigned x, y, w, h; + uint i; +#if 0 softpipe_update_derived(softpipe); /* not needed?? */ +#endif - /* Use the X coord to trick region_fill() into filling at an offset - * from the start of the region. Perhaps pipe_region should have the - * 'offset' field, not pipe_surface??? - */ - assert(ps->offset % ps->region->cpp == 0); - x = ps->offset / ps->region->cpp; - y = 0; - w = ps->width; - h = ps->height; - - assert(w <= ps->region->pitch); - assert(h <= ps->region->height); - +#if TILE_CLEAR_OPTIMIZATION if (ps == sp_tile_cache_get_surface(softpipe->zbuf_cache)) { - float clear[4]; - clear[0] = 1.0; /* XXX hack */ - sp_tile_cache_clear(softpipe->zbuf_cache, clear); - } - else if (ps == sp_tile_cache_get_surface(softpipe->cbuf_cache[0])) { - float clear[4]; - clear[0] = 0.2f; /* XXX hack */ - clear[1] = 0.2f; /* XXX hack */ - clear[2] = 0.2f; /* XXX hack */ - clear[3] = 0.2f; /* XXX hack */ - sp_tile_cache_clear(softpipe->cbuf_cache[0], clear); + sp_tile_cache_clear(softpipe->zbuf_cache, clearValue); + return; } - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearValue); + for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) { + if (ps == sp_tile_cache_get_surface(softpipe->cbuf_cache[i])) { + sp_tile_cache_clear(softpipe->cbuf_cache[i], clearValue); + return; + } + } +#endif + /* non-cached surface */ + pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue); #if 0 sp_clear_tile_cache(ps, clearValue); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index d5e68c189de..df4e0cbd5ae 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -31,16 +31,16 @@ #include "pipe/draw/draw_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "sp_clear.h" #include "sp_context.h" #include "sp_flush.h" #include "sp_prim_setup.h" -#include "sp_region.h" #include "sp_state.h" #include "sp_surface.h" #include "sp_tile_cache.h" -#include "sp_tex_layout.h" +#include "sp_texture.h" #include "sp_winsys.h" @@ -51,7 +51,8 @@ * parameter or another function. */ static boolean -softpipe_is_format_supported( struct pipe_context *pipe, uint format ) +softpipe_is_format_supported( struct pipe_context *pipe, + enum pipe_format format ) { struct softpipe_context *softpipe = softpipe_context( pipe ); /* ask winsys if the format is supported */ @@ -65,44 +66,22 @@ softpipe_is_format_supported( struct pipe_context *pipe, uint format ) void softpipe_map_surfaces(struct softpipe_context *sp) { - struct pipe_context *pipe = &sp->pipe; + struct pipe_surface *ps; unsigned i; for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - struct pipe_surface *ps = sp->framebuffer.cbufs[i]; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } + ps = sp->framebuffer.cbufs[i]; + if (ps->buffer) + pipe_surface_map(ps); } - if (sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.zbuf; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } - } - - if (sp->framebuffer.sbuf) { - struct pipe_surface *ps = sp->framebuffer.sbuf; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } - } -} - - -void -softpipe_map_texture_surfaces(struct softpipe_context *sp) -{ - struct pipe_context *pipe = &sp->pipe; - uint i; + ps = sp->framebuffer.zbuf; + if (ps && ps->buffer) + pipe_surface_map(ps); - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_mipmap_tree *mt = sp->texture[i]; - if (mt) { - pipe->region_map(pipe, mt->region); - } - } + ps = sp->framebuffer.sbuf; + if (ps && ps->buffer) + pipe_surface_map(ps); } @@ -112,45 +91,27 @@ softpipe_map_texture_surfaces(struct softpipe_context *sp) void softpipe_unmap_surfaces(struct softpipe_context *sp) { - struct pipe_context *pipe = &sp->pipe; + struct pipe_surface *ps; uint i; - for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + for (i = 0; i < sp->framebuffer.num_cbufs; i++) sp_flush_tile_cache(sp, sp->cbuf_cache[i]); sp_flush_tile_cache(sp, sp->zbuf_cache); sp_flush_tile_cache(sp, sp->sbuf_cache); for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - struct pipe_surface *ps = sp->framebuffer.cbufs[i]; - if (ps->region) - pipe->region_unmap(pipe, ps->region); - } - - if (sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.zbuf; - if (ps->region) - pipe->region_unmap(pipe, ps->region); - } - - if (sp->framebuffer.sbuf && sp->framebuffer.sbuf != sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.sbuf; - if (ps->region) - pipe->region_unmap(pipe, ps->region); + ps = sp->framebuffer.cbufs[i]; + if (ps->map) + pipe_surface_unmap(ps); } -} + ps = sp->framebuffer.zbuf; + if (ps && ps->map) + pipe_surface_unmap(ps); -void -softpipe_unmap_texture_surfaces(struct softpipe_context *sp) -{ - struct pipe_context *pipe = &sp->pipe; - uint i; - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_mipmap_tree *mt = sp->texture[i]; - if (mt) { - pipe->region_unmap(pipe, mt->region); - } - } + ps = sp->framebuffer.sbuf; + if (ps && ps->map) + pipe_surface_unmap(ps); } @@ -295,6 +256,8 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, /* queries */ softpipe->pipe.is_format_supported = softpipe_is_format_supported; + softpipe->pipe.get_name = softpipe_get_name; + softpipe->pipe.get_vendor = softpipe_get_vendor; softpipe->pipe.get_param = softpipe_get_param; softpipe->pipe.get_paramf = softpipe_get_paramf; @@ -302,21 +265,27 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.create_alpha_test_state = softpipe_create_alpha_test_state; softpipe->pipe.bind_alpha_test_state = softpipe_bind_alpha_test_state; softpipe->pipe.delete_alpha_test_state = softpipe_delete_alpha_test_state; + softpipe->pipe.create_blend_state = softpipe_create_blend_state; softpipe->pipe.bind_blend_state = softpipe_bind_blend_state; softpipe->pipe.delete_blend_state = softpipe_delete_blend_state; + softpipe->pipe.create_sampler_state = softpipe_create_sampler_state; softpipe->pipe.bind_sampler_state = softpipe_bind_sampler_state; softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_state; + softpipe->pipe.create_depth_stencil_state = softpipe_create_depth_stencil_state; softpipe->pipe.bind_depth_stencil_state = softpipe_bind_depth_stencil_state; softpipe->pipe.delete_depth_stencil_state = softpipe_delete_depth_stencil_state; + softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state; softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state; softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state; + softpipe->pipe.create_fs_state = softpipe_create_fs_state; softpipe->pipe.bind_fs_state = softpipe_bind_fs_state; softpipe->pipe.delete_fs_state = softpipe_delete_fs_state; + softpipe->pipe.create_vs_state = softpipe_create_vs_state; softpipe->pipe.bind_vs_state = softpipe_bind_vs_state; softpipe->pipe.delete_vs_state = softpipe_delete_vs_state; @@ -347,11 +316,9 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.end_query = softpipe_end_query; softpipe->pipe.wait_query = softpipe_wait_query; - softpipe->pipe.get_name = softpipe_get_name; - softpipe->pipe.get_vendor = softpipe_get_vendor; - /* textures */ - softpipe->pipe.mipmap_tree_layout = softpipe_mipmap_tree_layout; + softpipe->pipe.texture_create = softpipe_texture_create; + softpipe->pipe.texture_release = softpipe_texture_release; softpipe->pipe.get_tex_surface = softpipe_get_tex_surface; /* @@ -402,8 +369,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, draw_set_rasterize_stage(softpipe->draw, softpipe->setup); } - - sp_init_region_functions(softpipe); sp_init_surface_functions(softpipe); return &softpipe->pipe; diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 872766101d5..d4763a98c66 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -89,7 +89,7 @@ struct softpipe_context { struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct softpipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index 8a82cdfe1a9..93eb68405db 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -112,7 +112,6 @@ softpipe_draw_elements(struct pipe_context *pipe, softpipe_update_derived( sp ); softpipe_map_surfaces(sp); - softpipe_map_texture_surfaces(sp); softpipe_map_constant_buffers(sp); /* @@ -184,7 +183,6 @@ softpipe_draw_elements(struct pipe_context *pipe, /* Note: leave drawing surfaces mapped */ - softpipe_unmap_texture_surfaces(sp); softpipe_unmap_constant_buffers(sp); return TRUE; diff --git a/src/mesa/pipe/softpipe/sp_flush.c b/src/mesa/pipe/softpipe/sp_flush.c index 1010924bf61..47b11803ce1 100644 --- a/src/mesa/pipe/softpipe/sp_flush.c +++ b/src/mesa/pipe/softpipe/sp_flush.c @@ -55,7 +55,7 @@ softpipe_flush( struct pipe_context *pipe, * - flush the render cache */ - for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) if (softpipe->cbuf_cache[i]) sp_flush_tile_cache(softpipe, softpipe->cbuf_cache[i]); diff --git a/src/mesa/pipe/softpipe/sp_headers.h b/src/mesa/pipe/softpipe/sp_headers.h index e23742f8034..b9f2b2205a8 100644 --- a/src/mesa/pipe/softpipe/sp_headers.h +++ b/src/mesa/pipe/softpipe/sp_headers.h @@ -31,7 +31,7 @@ #ifndef SP_HEADERS_H #define SP_HEADERS_H -#include "../tgsi/exec/tgsi_core.h" +#include "pipe/tgsi/exec/tgsi_exec.h" #define PRIM_POINT 1 #define PRIM_LINE 2 diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c index 5a0df6de9d3..e0327c4cf9c 100644 --- a/src/mesa/pipe/softpipe/sp_quad.c +++ b/src/mesa/pipe/softpipe/sp_quad.c @@ -27,9 +27,8 @@ #include "sp_context.h" - #include "sp_state.h" -#include "pipe/tgsi/exec/tgsi_token.h" +#include "pipe/p_shader_tokens.h" static void sp_push_quad_first( diff --git a/src/mesa/pipe/softpipe/sp_quad_depth_test.c b/src/mesa/pipe/softpipe/sp_quad_depth_test.c index 33181896218..93ea1196f99 100644 --- a/src/mesa/pipe/softpipe/sp_quad_depth_test.c +++ b/src/mesa/pipe/softpipe/sp_quad_depth_test.c @@ -54,7 +54,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) { struct softpipe_context *softpipe = qs->softpipe; struct pipe_surface *ps = softpipe->framebuffer.zbuf; - const uint format = ps->format; + const enum pipe_format format = ps->format; unsigned bzzzz[QUAD_SIZE]; /**< Z values fetched from depth buffer */ unsigned qzzzz[QUAD_SIZE]; /**< Z values from the quad */ unsigned zmask = 0; @@ -74,7 +74,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) * Also, get the zbuffer values (bzzzz) from the cached tile. */ switch (format) { - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: { float scale = 65535.0; @@ -89,7 +89,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) } } break; - case PIPE_FORMAT_U_Z32: + case PIPE_FORMAT_Z32_UNORM: { double scale = (double) (uint) ~0UL; @@ -104,7 +104,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) } } break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: { float scale = (float) ((1 << 24) - 1); @@ -119,7 +119,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) } } break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: { float scale = (float) ((1 << 24) - 1); @@ -202,21 +202,21 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) /* put updated Z values back into cached tile */ switch (format) { - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); int y = quad->y0 % TILE_SIZE + (j >> 1); tile->data.depth16[y][x] = (ushort) bzzzz[j]; } break; - case PIPE_FORMAT_U_Z32: + case PIPE_FORMAT_Z32_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); int y = quad->y0 % TILE_SIZE + (j >> 1); tile->data.depth32[y][x] = bzzzz[j]; } break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); int y = quad->y0 % TILE_SIZE + (j >> 1); @@ -225,7 +225,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) tile->data.depth32[y][x] = s8z24; } break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); int y = quad->y0 % TILE_SIZE + (j >> 1); diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index ed14dac18e4..1aba54d12aa 100644 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -37,6 +37,7 @@ #include "pipe/p_util.h" #include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" #include "x86/rtasm/x86sse.h" @@ -48,6 +49,7 @@ #include "sp_state.h" #include "sp_headers.h" #include "sp_quad.h" +#include "sp_texture.h" #include "sp_tex_sample.h" @@ -276,7 +278,7 @@ static void shade_begin(struct quad_stage *qs) /* set TGSI sampler state that varies */ for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { qss->samplers[i].state = softpipe->sampler[i]; - qss->samplers[i].texture = softpipe->texture[i]; + qss->samplers[i].texture = &softpipe->texture[i]->base; } #ifdef MESA_LLVM diff --git a/src/mesa/pipe/softpipe/sp_quad_stencil.c b/src/mesa/pipe/softpipe/sp_quad_stencil.c index 0149b20f48f..b8c199204df 100644 --- a/src/mesa/pipe/softpipe/sp_quad_stencil.c +++ b/src/mesa/pipe/softpipe/sp_quad_stencil.c @@ -234,14 +234,14 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) /* get stencil values from cached tile */ switch (ps->format) { - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); int y = quad->y0 % TILE_SIZE + (j >> 1); stencilVals[j] = tile->data.depth32[y][x] >> 24; } break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); int y = quad->y0 % TILE_SIZE + (j >> 1); @@ -298,7 +298,7 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) /* put new stencil values into cached tile */ switch (ps->format) { - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); int y = quad->y0 % TILE_SIZE + (j >> 1); @@ -307,7 +307,7 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) tile->data.depth32[y][x] = s8z24; } break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); int y = quad->y0 % TILE_SIZE + (j >> 1); diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c deleted file mode 100644 index fef63ef2f6d..00000000000 --- a/src/mesa/pipe/softpipe/sp_region.c +++ /dev/null @@ -1,265 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 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. - * - **************************************************************************/ - -/* Provide additional functionality on top of bufmgr buffers: - * - 2d semantics and blit operations (XXX: remove/simplify blits??) - * - refcounting of buffers for multiple images in a buffer. - * - refcounting of buffer mappings. - */ - -#include "sp_context.h" -#include "sp_region.h" -#include "pipe/p_util.h" -#include "pipe/p_winsys.h" -#include "pipe/p_defines.h" - - - -static ubyte * -sp_region_map(struct pipe_context *pipe, struct pipe_region *region) -{ - struct softpipe_context *sp = softpipe_context( pipe ); - - if (!region->map_refcount++) { - region->map = sp->pipe.winsys->buffer_map( sp->pipe.winsys, - region->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ); - } - - return region->map; -} - -static void -sp_region_unmap(struct pipe_context *pipe, struct pipe_region *region) -{ - struct softpipe_context *sp = softpipe_context( pipe ); - - if (region->map_refcount > 0) { - assert(region->map); - if (!--region->map_refcount) { - sp->pipe.winsys->buffer_unmap( sp->pipe.winsys, - region->buffer ); - region->map = NULL; - } - } -} - - - -/** - * Copy 2D rect from one place to another. - * Position and sizes are in pixels. - */ -static void -copy_rect(ubyte * dst, - unsigned cpp, - unsigned dst_pitch, - unsigned dst_x, - unsigned dst_y, - unsigned width, - unsigned height, - const ubyte * src, - unsigned src_pitch, - unsigned src_x, - unsigned src_y) -{ - unsigned i; - - dst_pitch *= cpp; - src_pitch *= cpp; - dst += dst_x * cpp; - src += src_x * cpp; - dst += dst_y * dst_pitch; - src += src_y * src_pitch; - width *= cpp; - - if (width == dst_pitch && width == src_pitch) - memcpy(dst, src, height * width); - else { - for (i = 0; i < height; i++) { - memcpy(dst, src, width); - dst += dst_pitch; - src += src_pitch; - } - } -} - - -/* Upload data to a rectangular sub-region. Lots of choices how to do this: - * - * - memcpy by span to current destination - * - upload data as new buffer and blit - * - * Currently always memcpy. - */ -static void -sp_region_data(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - const void *src, unsigned src_pitch, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - copy_rect(pipe->region_map(pipe, dst) + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, width, height, src, src_pitch, srcx, srcy); - - pipe->region_unmap(pipe, dst); -} - -/* Assumes all values are within bounds -- no checking at this level - - * do it higher up if required. - */ -static void -sp_region_copy(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - struct pipe_region *src, - unsigned src_offset, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - ubyte *src_map, *dst_map; - assert( dst->cpp == src->cpp ); - - dst_map = pipe->region_map(pipe, dst); - src_map = pipe->region_map(pipe, src); - copy_rect(dst_map + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, - width, height, - src_map + src_offset, - src->pitch, - srcx, srcy); - - pipe->region_unmap(pipe, src); - pipe->region_unmap(pipe, dst); -} - - -static ubyte * -get_pointer(struct pipe_region *dst, unsigned x, unsigned y) -{ - return dst->map + (y * dst->pitch + x) * dst->cpp; -} - - -#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8)) - - -/** - * Fill a rectangular sub-region. Need better logic about when to - * push buffers into AGP - will currently do so whenever possible. - */ -static void -sp_region_fill(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, unsigned value) -{ - unsigned i, j; - - assert(dst->pitch > 0); - assert(width <= dst->pitch); - - (void)pipe->region_map(pipe, dst); - - switch (dst->cpp) { - case 1: - { - ubyte *row = get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - memset(row, value, width); - row += dst->pitch; - } - } - break; - case 2: - { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = (ushort) value; - row += dst->pitch; - } - } - break; - case 4: - { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = value; - row += dst->pitch; - } - } - break; - case 8: - { - /* expand the 4-byte clear value to an 8-byte value */ - ushort *row = (ushort *) get_pointer(dst, 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); - ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - row[j*4+0] = val0; - row[j*4+1] = val1; - row[j*4+2] = val2; - row[j*4+3] = val3; - } - row += dst->pitch * 4; - } - } - break; - default: - assert(0); - break; - } - - pipe->region_unmap( pipe, dst ); -} - - - - - -void -sp_init_region_functions(struct softpipe_context *sp) -{ - sp->pipe.region_map = sp_region_map; - sp->pipe.region_unmap = sp_region_unmap; - sp->pipe.region_data = sp_region_data; - sp->pipe.region_copy = sp_region_copy; - sp->pipe.region_fill = sp_region_fill; -} - diff --git a/src/mesa/pipe/softpipe/sp_region.h b/src/mesa/pipe/softpipe/sp_region.h deleted file mode 100644 index 432746b27f1..00000000000 --- a/src/mesa/pipe/softpipe/sp_region.h +++ /dev/null @@ -1,40 +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. - * - **************************************************************************/ - - -#ifndef SP_REGION_H -#define SP_REGION_H - - -struct softpipe_context; - - -extern void -sp_init_region_functions(struct softpipe_context *sp); - - -#endif /* SP_REGION_H */ diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 2f096a9cc97..ea9d2e62be6 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -125,7 +125,7 @@ void softpipe_set_scissor_state( struct pipe_context *, void softpipe_set_texture_state( struct pipe_context *, unsigned unit, - struct pipe_mipmap_tree * ); + struct pipe_texture * ); void softpipe_set_viewport_state( struct pipe_context *, const struct pipe_viewport_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 81f70f0f244..c4f1a0a01a9 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -26,15 +26,12 @@ **************************************************************************/ #include "pipe/p_util.h" - +#include "pipe/p_shader_tokens.h" #include "pipe/draw/draw_context.h" #include "pipe/draw/draw_vertex.h" - #include "sp_context.h" #include "sp_state.h" -#include "pipe/tgsi/exec/tgsi_token.h" - /** * Determine which post-transform / pre-rasterization vertex attributes @@ -156,10 +153,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe ) if (1/*vinfo->attr_mask != softpipe->attr_mask*/) { /*softpipe->attr_mask = vinfo->attr_mask;*/ - draw_set_vertex_attributes( softpipe->draw, - NULL,/*vinfo->slot_to_attrib,*/ - vinfo->interp_mode, - vinfo->num_attribs); + draw_set_vertex_info( softpipe->draw, vinfo); draw_set_twoside_attributes(softpipe->draw, front0, back0, front1, back1); diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index ba564b16e66..a360b4f02b0 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -32,8 +32,10 @@ #include "pipe/p_util.h" #include "pipe/p_winsys.h" #include "pipe/draw/draw_context.h" -#include "pipe/tgsi/exec/tgsi_core.h" +#include "pipe/p_shader_tokens.h" #include "pipe/llvm/gallivm.h" +#include "pipe/tgsi/util/tgsi_dump.h" +#include "pipe/tgsi/exec/tgsi_sse2.h" void * softpipe_create_fs_state(struct pipe_context *pipe, diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c index 246a7d6eda7..173901f04e6 100644 --- a/src/mesa/pipe/softpipe/sp_state_sampler.c +++ b/src/mesa/pipe/softpipe/sp_state_sampler.c @@ -32,6 +32,7 @@ #include "pipe/p_util.h" #include "sp_context.h" #include "sp_state.h" +#include "sp_texture.h" #include "sp_tile_cache.h" @@ -68,12 +69,12 @@ softpipe_delete_sampler_state(struct pipe_context *pipe, void softpipe_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct softpipe_context *softpipe = softpipe_context(pipe); assert(unit < PIPE_MAX_SAMPLERS); - softpipe->texture[unit] = texture; /* ptr, not struct */ + softpipe->texture[unit] = softpipe_texture(texture); /* ptr, not struct */ sp_tile_cache_set_texture(softpipe->tex_cache[unit], texture); diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c index d4e0bd1e157..30bedc74bc0 100644 --- a/src/mesa/pipe/softpipe/sp_state_surface.c +++ b/src/mesa/pipe/softpipe/sp_state_surface.c @@ -27,6 +27,8 @@ /* Authors: Keith Whitwell */ +#include "p_inlines.h" + #include "sp_context.h" #include "sp_state.h" #include "sp_surface.h" @@ -54,12 +56,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->cbuf_cache[i]); /* unmap old */ ps = sp->framebuffer.cbufs[i]; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); /* map new */ ps = fb->cbufs[i]; if (ps) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.cbufs[i] = fb->cbufs[i]; @@ -76,8 +78,8 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->zbuf_cache); /* unmap old */ ps = sp->framebuffer.zbuf; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); if (sp->framebuffer.sbuf == sp->framebuffer.zbuf) { /* combined z/stencil */ sp->framebuffer.sbuf = NULL; @@ -85,7 +87,7 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, /* map new */ ps = fb->zbuf; if (ps) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.zbuf = fb->zbuf; @@ -101,12 +103,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->sbuf_cache_sep); /* unmap old */ ps = sp->framebuffer.sbuf; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); /* map new */ ps = fb->sbuf; if (ps && fb->sbuf != fb->zbuf) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.sbuf = fb->sbuf; diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index b7c9d4f0045..55b8b85ef2b 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -30,9 +30,9 @@ #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "sp_context.h" -#include "sp_state.h" #include "sp_surface.h" -#include "sp_tile_cache.h" +#include "sp_texture.h" + /** * Softpipe surface functions. @@ -47,14 +47,6 @@ -#if 0 -#define CLIP_TILE \ - do { \ - assert(x + w <= ps->width); \ - assert(y + h <= ps->height); \ - } while(0) - -#else #define CLIP_TILE \ do { \ if (x >= ps->width) \ @@ -64,24 +56,23 @@ if (x + w > ps->width) \ w = ps->width - x; \ if (y + h > ps->height) \ - h = ps->height -y; \ + h = ps->height - y; \ } while(0) -#endif -/*** PIPE_FORMAT_U_A8_R8_G8_B8 ***/ +/*** PIPE_FORMAT_A8R8G8B8_UNORM ***/ static void a8r8g8b8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((const unsigned *) (ps->map)) + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; - assert(ps->format == PIPE_FORMAT_U_A8_R8_G8_B8); + assert(ps->format == PIPE_FORMAT_A8R8G8B8_UNORM); CLIP_TILE; @@ -95,7 +86,7 @@ a8r8g8b8_get_tile(struct pipe_surface *ps, pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -107,12 +98,12 @@ a8r8g8b8_put_tile(struct pipe_surface *ps, const float *p) { unsigned *dst - = ((unsigned *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((unsigned *) (ps->map)) + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; - assert(ps->format == PIPE_FORMAT_U_A8_R8_G8_B8); + assert(ps->format == PIPE_FORMAT_A8R8G8B8_UNORM); CLIP_TILE; @@ -127,24 +118,88 @@ a8r8g8b8_put_tile(struct pipe_surface *ps, dst[j] = (a << 24) | (r << 16) | (g << 8) | b; pRow += 4; } - dst += ps->region->pitch; + dst += ps->pitch; p += w0 * 4; } } -/*** PIPE_FORMAT_U_A1_R5_G5_B5 ***/ +/*** PIPE_FORMAT_B8G8R8A8_UNORM ***/ + +static void +b8g8r8a8_get_tile(struct pipe_surface *ps, + unsigned x, unsigned y, unsigned w, unsigned h, float *p) +{ + const unsigned *src + = ((const unsigned *) (ps->map)) + + y * ps->pitch + x; + unsigned i, j; + unsigned w0 = w; + + assert(ps->format == PIPE_FORMAT_B8G8R8A8_UNORM); + + CLIP_TILE; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++) { + const unsigned pixel = src[j]; + 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; + } +} + + +static void +b8g8r8a8_put_tile(struct pipe_surface *ps, + unsigned x, unsigned y, unsigned w, unsigned h, + const float *p) +{ + unsigned *dst + = ((unsigned *) (ps->map)) + + y * ps->pitch + x; + unsigned i, j; + unsigned w0 = w; + + assert(ps->format == PIPE_FORMAT_B8G8R8A8_UNORM); + + CLIP_TILE; + + for (i = 0; i < h; i++) { + const float *pRow = p; + for (j = 0; j < w; j++) { + 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 += ps->pitch; + p += w0 * 4; + } +} + + +/*** PIPE_FORMAT_A1R5G5B5_UNORM ***/ static void a1r5g5b5_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((const ushort *) (ps->map)) + + y * ps->pitch + x; unsigned i, j; - assert(ps->format == PIPE_FORMAT_U_A1_R5_G5_B5); + assert(ps->format == PIPE_FORMAT_A1R5G5B5_UNORM); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { @@ -155,13 +210,13 @@ a1r5g5b5_get_tile(struct pipe_surface *ps, p[3] = ((pixel >> 15) ) * 1.0f; p += 4; } - src += ps->region->pitch; + src += ps->pitch; } } -/*** PIPE_FORMAT_U_Z16 ***/ +/*** PIPE_FORMAT_Z16_UNORM ***/ /** * Return each Z value as four floats in [0,1]. @@ -171,13 +226,13 @@ z16_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((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_U_Z16); + assert(ps->format == PIPE_FORMAT_Z16_UNORM); CLIP_TILE; @@ -189,7 +244,7 @@ z16_get_tile(struct pipe_surface *ps, pRow[j * 4 + 2] = pRow[j * 4 + 3] = src[j] * scale; } - src += ps->region->pitch; + src += ps->pitch; p += 4 * w0; } } @@ -204,8 +259,8 @@ l8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((const ubyte *) (ps->map)) + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -222,7 +277,7 @@ l8_get_tile(struct pipe_surface *ps, pRow[3] = 1.0; pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -235,8 +290,8 @@ a8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((const ubyte *) (ps->map)) + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -253,25 +308,25 @@ a8_get_tile(struct pipe_surface *ps, pRow[3] = UBYTE_TO_FLOAT(src[j]); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } -/*** PIPE_FORMAT_S_R16_G16_B16_A16 ***/ +/*** PIPE_FORMAT_R16G16B16A16_SNORM ***/ static void r16g16b16a16_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const short *src - = ((const short *) (ps->region->map + ps->offset)) - + (y * ps->region->pitch + x) * 4; + = ((const short *) (ps->map)) + + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; - assert(ps->format == PIPE_FORMAT_S_R16_G16_B16_A16); + assert(ps->format == PIPE_FORMAT_R16G16B16A16_SNORM); CLIP_TILE; @@ -286,7 +341,7 @@ r16g16b16a16_get_tile(struct pipe_surface *ps, pRow += 4; pixel += 4; } - src += ps->region->pitch * 4; + src += ps->pitch * 4; p += w0 * 4; } } @@ -298,12 +353,12 @@ r16g16b16a16_put_tile(struct pipe_surface *ps, const float *p) { short *dst - = ((short *) (ps->region->map + ps->offset)) - + (y * ps->region->pitch + x) * 4; + = ((short *) (ps->map)) + + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; - assert(ps->format == PIPE_FORMAT_S_R16_G16_B16_A16); + assert(ps->format == PIPE_FORMAT_R16G16B16A16_SNORM); CLIP_TILE; @@ -321,7 +376,7 @@ r16g16b16a16_put_tile(struct pipe_surface *ps, dst[j*4+3] = a; pRow += 4; } - dst += ps->region->pitch * 4; + dst += ps->pitch * 4; p += w0 * 4; } } @@ -335,8 +390,8 @@ i8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((const ubyte *) (ps->map)) + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -353,7 +408,7 @@ i8_get_tile(struct pipe_surface *ps, pRow[3] = UBYTE_TO_FLOAT(src[j]); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -366,8 +421,8 @@ a8_l8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((const ushort *) (ps->map)) + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -385,7 +440,7 @@ a8_l8_get_tile(struct pipe_surface *ps, pRow[3] = UBYTE_TO_FLOAT(p >> 8); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -393,7 +448,7 @@ a8_l8_get_tile(struct pipe_surface *ps, -/*** PIPE_FORMAT_U_Z32 ***/ +/*** PIPE_FORMAT_Z32_UNORM ***/ /** * Return each Z value as four floats in [0,1]. @@ -403,13 +458,13 @@ z32_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((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_U_Z16); + assert(ps->format == PIPE_FORMAT_Z16_UNORM); CLIP_TILE; @@ -421,13 +476,13 @@ z32_get_tile(struct pipe_surface *ps, pRow[j * 4 + 2] = pRow[j * 4 + 3] = (float) (scale * src[j]); } - src += ps->region->pitch; + src += ps->pitch; p += 4 * w0; } } -/*** PIPE_FORMAT_S8_Z24 ***/ +/*** PIPE_FORMAT_S8Z24_UNORM ***/ /** * Return Z component as four float in [0,1]. Stencil part ignored. @@ -437,13 +492,13 @@ s8z24_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((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_S8_Z24); + assert(ps->format == PIPE_FORMAT_S8Z24_UNORM); CLIP_TILE; @@ -455,13 +510,13 @@ s8z24_get_tile(struct pipe_surface *ps, pRow[j * 4 + 2] = pRow[j * 4 + 3] = (float) (scale * (src[j] & 0xffffff)); } - src += ps->region->pitch; + src += ps->pitch; p += 4 * w0; } } -/*** PIPE_FORMAT_Z24_S8 ***/ +/*** PIPE_FORMAT_Z24S8_UNORM ***/ /** * Return Z component as four float in [0,1]. Stencil part ignored. @@ -471,13 +526,13 @@ z24s8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + = ((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_Z24_S8); + assert(ps->format == PIPE_FORMAT_Z24S8_UNORM); CLIP_TILE; @@ -489,7 +544,7 @@ z24s8_get_tile(struct pipe_surface *ps, pRow[j * 4 + 2] = pRow[j * 4 + 3] = (float) (scale * (src[j] >> 8)); } - src += ps->region->pitch; + src += ps->pitch; p += 4 * w0; } } @@ -501,32 +556,35 @@ z24s8_get_tile(struct pipe_surface *ps, */ struct pipe_surface * softpipe_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice) { + struct softpipe_texture *spt = softpipe_texture(pt); struct pipe_surface *ps; unsigned offset; /* in bytes */ - offset = mt->level[level].level_offset; + offset = spt->level_offset[level]; - if (mt->target == PIPE_TEXTURE_CUBE) { - offset += mt->level[level].image_offset[face] * mt->cpp; + if (pt->target == PIPE_TEXTURE_CUBE) { + offset += spt->image_offset[level][face] * pt->cpp; } - else if (mt->target == PIPE_TEXTURE_3D) { - offset += mt->level[level].image_offset[zslice] * mt->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, mt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format); if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, mt->region); - ps->width = mt->level[level].width; - ps->height = mt->level[level].height; + pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, spt->buffer); + ps->cpp = pt->cpp; + ps->width = pt->width[level]; + ps->height = pt->height[level]; + ps->pitch = spt->pitch; ps->offset = offset; } return ps; @@ -541,12 +599,13 @@ softpipe_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, void *p, int dst_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const ubyte *pSrc; + const uint src_stride = ps->pitch * cpp; ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); if (dst_stride == 0) { dst_stride = w * cpp; @@ -554,13 +613,13 @@ softpipe_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, CLIP_TILE; - pSrc = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pSrc = ps->map + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); pDest += dst_stride; - pSrc += ps->region->pitch * cpp; + pSrc += src_stride; } } @@ -573,12 +632,13 @@ softpipe_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, const void *p, int src_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const ubyte *pSrc; + const uint dst_stride = ps->pitch * cpp; ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); if (src_stride == 0) { src_stride = w * cpp; @@ -587,11 +647,11 @@ softpipe_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, CLIP_TILE; pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pDest = ps->map + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); - pDest += ps->region->pitch * cpp; + pDest += dst_stride; pSrc += src_stride; } } @@ -605,10 +665,13 @@ softpipe_get_tile_rgba(struct pipe_context *pipe, float *p) { switch (ps->format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: a8r8g8b8_get_tile(ps, x, y, w, h, p); break; - case PIPE_FORMAT_U_A1_R5_G5_B5: + case PIPE_FORMAT_B8G8R8A8_UNORM: + b8g8r8a8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_A1R5G5B5_UNORM: a1r5g5b5_get_tile(ps, x, y, w, h, p); break; case PIPE_FORMAT_U_L8: @@ -623,19 +686,19 @@ softpipe_get_tile_rgba(struct pipe_context *pipe, case PIPE_FORMAT_U_A8_L8: a8_l8_get_tile(ps, x, y, w, h, p); break; - case PIPE_FORMAT_S_R16_G16_B16_A16: + case PIPE_FORMAT_R16G16B16A16_SNORM: r16g16b16a16_get_tile(ps, x, y, w, h, p); break; - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: z16_get_tile(ps, x, y, w, h, p); break; - case PIPE_FORMAT_U_Z32: + case PIPE_FORMAT_Z32_UNORM: z32_get_tile(ps, x, y, w, h, p); break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: s8z24_get_tile(ps, x, y, w, h, p); break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: z24s8_get_tile(ps, x, y, w, h, p); break; default: @@ -652,10 +715,13 @@ softpipe_put_tile_rgba(struct pipe_context *pipe, const float *p) { switch (ps->format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: a8r8g8b8_put_tile(ps, x, y, w, h, p); break; - case PIPE_FORMAT_U_A1_R5_G5_B5: + case PIPE_FORMAT_B8G8R8A8_UNORM: + b8g8r8a8_put_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_A1R5G5B5_UNORM: /*a1r5g5b5_put_tile(ps, x, y, w, h, p);*/ break; case PIPE_FORMAT_U_L8: @@ -670,19 +736,19 @@ softpipe_put_tile_rgba(struct pipe_context *pipe, case PIPE_FORMAT_U_A8_L8: /*a8_l8_put_tile(ps, x, y, w, h, p);*/ break; - case PIPE_FORMAT_S_R16_G16_B16_A16: + case PIPE_FORMAT_R16G16B16A16_SNORM: r16g16b16a16_put_tile(ps, x, y, w, h, p); break; - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: /*z16_put_tile(ps, x, y, w, h, p);*/ break; - case PIPE_FORMAT_U_Z32: + case PIPE_FORMAT_Z32_UNORM: /*z32_put_tile(ps, x, y, w, h, p);*/ break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: /*s8z24_put_tile(ps, x, y, w, h, p);*/ break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: /*z24s8_put_tile(ps, x, y, w, h, p);*/ break; default: @@ -691,6 +757,177 @@ softpipe_put_tile_rgba(struct pipe_context *pipe, } +/** + * Copy 2D rect from one place to another. + * Position and sizes are in pixels. + */ +static void +copy_rect(ubyte * dst, + unsigned cpp, + unsigned dst_pitch, + unsigned dst_x, + unsigned dst_y, + unsigned width, + unsigned height, + const ubyte * src, + unsigned src_pitch, + unsigned src_x, + unsigned src_y) +{ + unsigned i; + + dst_pitch *= cpp; + src_pitch *= cpp; + dst += dst_x * cpp; + src += src_x * cpp; + dst += dst_y * dst_pitch; + src += src_y * src_pitch; + width *= cpp; + + if (width == dst_pitch && width == src_pitch) + memcpy(dst, src, height * width); + else { + for (i = 0; i < height; i++) { + memcpy(dst, src, width); + dst += dst_pitch; + src += src_pitch; + } + } +} + + +/* Upload data to a rectangular sub-region. Lots of choices how to do this: + * + * - memcpy by span to current destination + * - upload data as new buffer and blit + * + * Currently always memcpy. + */ +static void +sp_surface_data(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + const void *src, unsigned src_pitch, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + copy_rect(pipe_surface_map(dst), + dst->cpp, + dst->pitch, + dstx, dsty, width, height, src, src_pitch, srcx, srcy); + + pipe_surface_unmap(dst); +} + +/* Assumes all values are within bounds -- no checking at this level - + * do it higher up if required. + */ +static void +sp_surface_copy(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + struct pipe_surface *src, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + assert( dst->cpp == src->cpp ); + + copy_rect(pipe_surface_map(dst), + dst->cpp, + dst->pitch, + dstx, dsty, + width, height, + pipe_surface_map(src), + src->pitch, + srcx, srcy); + + pipe_surface_unmap(src); + pipe_surface_unmap(dst); +} + + +static ubyte * +get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +{ + return dst->map + (y * dst->pitch + x) * dst->cpp; +} + + +#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8)) + + +/** + * Fill a rectangular sub-region. Need better logic about when to + * push buffers into AGP - will currently do so whenever possible. + */ +static void +sp_surface_fill(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, unsigned value) +{ + unsigned i, j; + + 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); + for (i = 0; i < height; i++) { + memset(row, value, width); + row += dst->pitch; + } + } + break; + case 2: + { + ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) + row[j] = (ushort) value; + row += dst->pitch; + } + } + break; + case 4: + { + unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) + row[j] = value; + row += dst->pitch; + } + } + break; + case 8: + { + /* expand the 4-byte clear value to an 8-byte value */ + ushort *row = (ushort *) get_pointer(dst, 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); + ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + row[j*4+0] = val0; + row[j*4+1] = val1; + row[j*4+2] = val2; + row[j*4+3] = val3; + } + row += dst->pitch * 4; + } + } + break; + default: + assert(0); + break; + } + + pipe_surface_unmap( dst ); +} + void sp_init_surface_functions(struct softpipe_context *sp) @@ -700,4 +937,8 @@ sp_init_surface_functions(struct softpipe_context *sp) sp->pipe.get_tile_rgba = softpipe_get_tile_rgba; sp->pipe.put_tile_rgba = softpipe_put_tile_rgba; + + sp->pipe.surface_data = sp_surface_data; + sp->pipe.surface_copy = sp_surface_copy; + sp->pipe.surface_fill = sp_surface_fill; } diff --git a/src/mesa/pipe/softpipe/sp_surface.h b/src/mesa/pipe/softpipe/sp_surface.h index cf87e1a92ce..b652e7598e8 100644 --- a/src/mesa/pipe/softpipe/sp_surface.h +++ b/src/mesa/pipe/softpipe/sp_surface.h @@ -41,7 +41,7 @@ struct softpipe_tile_cache; extern struct pipe_surface * softpipe_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice); diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.c b/src/mesa/pipe/softpipe/sp_tex_layout.c deleted file mode 100644 index 8156b00301f..00000000000 --- a/src/mesa/pipe/softpipe/sp_tex_layout.c +++ /dev/null @@ -1,361 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - /* - * Authors: - * Keith Whitwell - * Michel Dänzer - */ - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_util.h" -#include "sp_tex_layout.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. - */ - -static unsigned minify( unsigned d ) -{ - return MAX2(1, d>>1); -} - -static int align(int value, int alignment) -{ - return (value + alignment - 1) & ~(alignment - 1); -} - - -static void -sp_miptree_set_level_info(struct pipe_mipmap_tree *mt, - unsigned level, - unsigned nr_images, - unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) -{ - assert(level < PIPE_MAX_TEXTURE_LEVELS); - - mt->level[level].width = w; - mt->level[level].height = h; - mt->level[level].depth = d; - mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp; - mt->level[level].nr_images = nr_images; - - /* - DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, - level, w, h, d, x, y, mt->level[level].level_offset); - */ - - /* Not sure when this would happen, but anyway: - */ - if (mt->level[level].image_offset) { - FREE( mt->level[level].image_offset ); - mt->level[level].image_offset = NULL; - } - - assert(nr_images); - assert(!mt->level[level].image_offset); - - mt->level[level].image_offset = (unsigned *) MALLOC( nr_images * sizeof(unsigned) ); - mt->level[level].image_offset[0] = 0; -} - - -static void -sp_miptree_set_image_offset(struct pipe_mipmap_tree *mt, - unsigned level, unsigned img, unsigned x, unsigned y) -{ - if (img == 0 && level == 0) - assert(x == 0 && y == 0); - - assert(img < mt->level[level].nr_images); - - mt->level[level].image_offset[img] = (x + y * mt->pitch); - - /* - DBG("%s level %d img %d pos %d,%d image_offset %x\n", - __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]); - */ -} - - -static void -sp_miptree_layout_2d( struct pipe_mipmap_tree *mt ) -{ - int align_h = 2, align_w = 4; - unsigned level; - unsigned x = 0; - unsigned y = 0; - unsigned width = mt->width0; - unsigned height = mt->height0; - - mt->pitch = mt->width0; - /* XXX FIX THIS: - * we use alignment=64 bytes in sp_region_alloc(). If we change - * that, change this too. - */ - if (mt->pitch < 16) - mt->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 (mt->first_level != mt->last_level) { - unsigned mip1_width = align(minify(mt->width0), align_w) - + minify(minify(mt->width0)); - - if (mip1_width > mt->width0) - mt->pitch = mip1_width; - } - - /* Pitch must be a whole number of dwords, even though we - * express it in texels. - */ - mt->pitch = align(mt->pitch * mt->cpp, 4) / mt->cpp; - mt->total_height = 0; - - for ( level = mt->first_level ; level <= mt->last_level ; level++ ) { - unsigned img_height; - - sp_miptree_set_level_info(mt, level, 1, x, y, width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align(height, align_h); - - - /* Because the images are packed better, the final offset - * might not be the maximal one: - */ - mt->total_height = MAX2(mt->total_height, y + img_height); - - /* Layout_below: step right after second mipmap. - */ - if (level == mt->first_level + 1) { - x += align(width, align_w); - } - else { - y += img_height; - } - - width = minify(width); - height = minify(height); - } -} - - -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} -}; - - - -boolean -softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - unsigned level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE:{ - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - 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) - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - else - mt->pitch = 14 * 8; - - mt->total_height = dim * 4 + 4; - - /* Set all the levels to effectively occupy the whole rectangular region. - */ - for (level = mt->first_level; level <= mt->last_level; level++) { - sp_miptree_set_level_info(mt, 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 = mt->total_height - 4; - x = (face - 4) * 8; - } - else if (dim < 4 && (face > 0 || mt->first_level > 0)) { - y = mt->total_height - 4; - x = face * 8; - } - - for (level = mt->first_level; level <= mt->last_level; level++) { - sp_miptree_set_image_offset(mt, 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 = mt->total_height - 4; - x = (face - 4) * 8; - break; - } - - case 2: - y = mt->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 = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned pack_x_pitch, pack_x_nr; - unsigned pack_y_pitch; - unsigned level; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - pack_y_pitch = MAX2(mt->height0, 2); - pack_x_pitch = mt->pitch; - pack_x_nr = 1; - - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned nr_images = mt->target == PIPE_TEXTURE_3D ? depth : 6; - int x = 0; - int y = 0; - unsigned q, j; - - sp_miptree_set_level_info(mt, level, nr_images, - 0, mt->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(mt, level, q, x, y); - x += pack_x_pitch; - } - - x = 0; - y += pack_y_pitch; - } - - - mt->total_height += y; - - if (pack_x_pitch > 4) { - pack_x_pitch >>= 1; - pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= mt->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(mt); - break; - default: - assert(0); - break; - } - - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.h b/src/mesa/pipe/softpipe/sp_tex_layout.h deleted file mode 100644 index ea19c13b23f..00000000000 --- a/src/mesa/pipe/softpipe/sp_tex_layout.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SP_TEX_LAYOUT_H -#define SP_TEX_LAYOUT_H - - -struct pipe_context; -struct pipe_mipmap_tree; - - -extern boolean -softpipe_mipmap_tree_layout(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt); - - -#endif /* SP_TEX_LAYOUT_H */ - - diff --git a/src/mesa/pipe/softpipe/sp_tex_sample.c b/src/mesa/pipe/softpipe/sp_tex_sample.c index 92958400fc5..9e48ed0cd2c 100644 --- a/src/mesa/pipe/softpipe/sp_tex_sample.c +++ b/src/mesa/pipe/softpipe/sp_tex_sample.c @@ -422,7 +422,7 @@ compute_lambda(struct tgsi_sampler *sampler, dsdy = FABSF(dsdy); rho = MAX2(dsdx, dsdy); if (sampler->state->normalized_coords) - rho *= sampler->texture->width0; + rho *= sampler->texture->width[0]; } if (t) { float dtdx = t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]; @@ -432,7 +432,7 @@ compute_lambda(struct tgsi_sampler *sampler, dtdy = FABSF(dtdy); max = MAX2(dtdx, dtdy); if (sampler->state->normalized_coords) - max *= sampler->texture->height0; + max *= sampler->texture->height[0]; rho = MAX2(rho, max); } if (p) { @@ -443,7 +443,7 @@ compute_lambda(struct tgsi_sampler *sampler, dpdy = FABSF(dpdy); max = MAX2(dpdx, dpdy); if (sampler->state->normalized_coords) - max *= sampler->texture->depth0; + max *= sampler->texture->depth[0]; rho = MAX2(rho, max); } @@ -620,8 +620,8 @@ sp_get_samples_2d_common(struct tgsi_sampler *sampler, &level0, &level1, &levelBlend, &imgFilter); if (sampler->state->normalized_coords) { - width = sampler->texture->level[level0].width; - height = sampler->texture->level[level0].height; + width = sampler->texture->width[level0]; + height = sampler->texture->height[level0]; } else { width = height = 1; @@ -757,9 +757,9 @@ sp_get_samples_3d(struct tgsi_sampler *sampler, &level0, &level1, &levelBlend, &imgFilter); if (sampler->state->normalized_coords) { - width = sampler->texture->level[level0].width; - height = sampler->texture->level[level0].height; - depth = sampler->texture->level[level0].depth; + width = sampler->texture->width[level0]; + height = sampler->texture->height[level0]; + depth = sampler->texture->depth[level0]; } else { width = height = depth = 1; @@ -883,7 +883,7 @@ sp_get_samples_cube(struct tgsi_sampler *sampler, /** * Called via tgsi_sampler::get_samples() * Use the sampler's state setting to get a filtered RGBA value - * from the sampler's texture (mipmap tree). + * from the sampler's texture. * * XXX we can implement many versions of this function, each * tightly coded for a specific combination of sampler state diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c new file mode 100644 index 00000000000..2288c343bf1 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -0,0 +1,431 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_inlines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" + +#include "sp_context.h" +#include "sp_state.h" +#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. + */ + +static unsigned minify( unsigned d ) +{ + return MAX2(1, d>>1); +} + +static int align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + + +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 ) +{ + 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]; + + 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; + + 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); + + + /* 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; + } + + width = minify(width); + height = minify(height); + } +} + + +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) +{ + struct softpipe_texture *spt = REALLOC(*pt, sizeof(struct pipe_texture), + sizeof(struct softpipe_texture)); + + if (spt) { + 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, + PIPE_SURFACE_FLAG_TEXTURE); + + if (spt->buffer) { + pipe->winsys->buffer_data(pipe->winsys, spt->buffer, + spt->pitch * spt->base.cpp * + spt->total_height, NULL, + PIPE_BUFFER_USAGE_PIXEL); + } + } + + if (!spt->buffer) { + FREE(spt); + spt = NULL; + } + } + + *pt = &spt->base; +} + +void +softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) +{ + if (!*pt) + return; + + /* + DBG("%s %p refcount will be %d\n", + __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + */ + if (--(*pt)->refcount <= 0) { + struct softpipe_texture *spt = softpipe_texture(*pt); + uint i; + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); + */ + + 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 new file mode 100644 index 00000000000..732064d9867 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_texture.h @@ -0,0 +1,57 @@ +#ifndef SP_TEXTURE_H +#define SP_TEXTURE_H + + +struct pipe_context; +struct pipe_texture; + + +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; +}; + + +/** cast wrapper */ +static INLINE struct softpipe_texture * +softpipe_texture(struct pipe_texture *pt) +{ + return (struct softpipe_texture *) pt; +} + + + +extern void +softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt); + +extern void +softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt); + + +#endif /* SP_TEXTURE */ + + diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index ea0c8b8f91d..fadd169f5df 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -38,9 +38,7 @@ #include "sp_surface.h" #include "sp_tile_cache.h" -#define CLEAR_OPTIMIZATION 0 - -#define NUM_ENTRIES 20 +#define NUM_ENTRIES 30 /** XXX move these */ @@ -51,10 +49,15 @@ struct softpipe_tile_cache { struct pipe_surface *surface; /**< the surface we're caching */ - struct pipe_mipmap_tree *texture; /**< if caching a texture */ + 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]; - float clear_value[4]; + float clear_color[4]; + uint clear_val; + boolean depth_stencil; /** Is the surface a depth/stencil format? */ + + struct pipe_surface *tex_surf; + int tex_face, tex_level, tex_z; }; @@ -69,7 +72,10 @@ struct softpipe_tile_cache -static uint +/** + * Is the tile at (x,y) in cleared state? + */ +static INLINE uint is_clear_flag_set(const uint *bitvec, int x, int y) { int pos, bit; @@ -82,7 +88,10 @@ is_clear_flag_set(const uint *bitvec, int x, int y) } -static void +/** + * Mark the tile at (x,y) as not cleared. + */ +static INLINE void clear_clear_flag(uint *bitvec, int x, int y) { int pos; @@ -122,14 +131,37 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc) } +/** + * Specify the surface to cache. + */ void sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, struct pipe_surface *ps) { + assert(!tc->texture); + + if (tc->surface && tc->surface->map) { + assert(tc->surface != ps); + pipe_surface_unmap(tc->surface); + } + pipe_surface_reference(&tc->surface, ps); + + if (!ps->map) + pipe_surface_map(ps); + + if (ps) { + tc->depth_stencil = (ps->format == PIPE_FORMAT_S8Z24_UNORM || + ps->format == PIPE_FORMAT_Z16_UNORM || + ps->format == PIPE_FORMAT_Z32_UNORM || + ps->format == PIPE_FORMAT_U_S8); + } } +/** + * Return the surface being cached. + */ struct pipe_surface * sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) { @@ -137,44 +169,165 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) } +/** + * Specify the texture to cache. + */ void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { uint i; + assert(!tc->surface); + tc->texture = texture; + if (tc->tex_surf && tc->tex_surf->map) + pipe_surface_unmap(tc->tex_surf); + pipe_surface_reference(&tc->tex_surf, NULL); + /* mark as entries as invalid/empty */ /* XXX we should try to avoid this when the teximage hasn't changed */ for (i = 0; i < NUM_ENTRIES; i++) { tc->entries[i].x = -1; } + + tc->tex_face = -1; /* any invalid value here */ +} + + +/** + * Set pixels in a tile to the given clear color/value, float. + */ +static void +clear_tile_rgba(struct softpipe_cached_tile *tile, + enum pipe_format format, + const float clear_value[4]) +{ + if (clear_value[0] == 0.0 && + clear_value[1] == 0.0 && + clear_value[2] == 0.0 && + clear_value[3] == 0.0) { + memset(tile->data.color, 0, sizeof(tile->data.color)); + } + else { + uint i, j; + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile->data.color[i][j][0] = clear_value[0]; + tile->data.color[i][j][1] = clear_value[1]; + tile->data.color[i][j][2] = clear_value[2]; + tile->data.color[i][j][3] = clear_value[3]; + } + } + } +} + + +/** + * Set a tile to a solid value/color. + */ +static void +clear_tile(struct softpipe_cached_tile *tile, + enum pipe_format format, + uint clear_value) +{ + uint i, j; + + switch (format) { + case PIPE_FORMAT_U_S8: + /* 8 bpp */ + memset(tile->data.any, 0, TILE_SIZE * TILE_SIZE); + break; + case PIPE_FORMAT_Z16_UNORM: + /* 16 bpp */ + if (clear_value == 0) { + memset(tile->data.any, 0, 2 * TILE_SIZE * TILE_SIZE); + } + else { + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile->data.depth16[i][j] = clear_value; + } + } + } + break; + default: + /* 32 bpp */ + if (clear_value == 0) { + memset(tile->data.any, 0, 4 * TILE_SIZE * TILE_SIZE); + } + else { + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile->data.color32[i][j] = clear_value; + } + } + } + } +} + + +/** + * Actually clear the tiles which were flagged as being in a clear state. + */ +static void +sp_tile_cache_flush_clear(struct pipe_context *pipe, + struct softpipe_tile_cache *tc) +{ + struct pipe_surface *ps = tc->surface; + const uint w = tc->surface->width; + const uint h = tc->surface->height; + uint x, y; + struct softpipe_cached_tile tile; + uint numCleared = 0; + + /* clear one tile to the clear value */ + clear_tile(&tile, ps->format, tc->clear_val); + + /* push the tile to all positions marked as clear */ + for (y = 0; y < h; y += TILE_SIZE) { + for (x = 0; x < w; x += TILE_SIZE) { + if (is_clear_flag_set(tc->clear_flags, x, y)) { + pipe->put_tile(pipe, ps, + x, y, TILE_SIZE, TILE_SIZE, + tile.data.color32, 0/*STRIDE*/); + + /* do this? */ + clear_clear_flag(tc->clear_flags, x, y); + + numCleared++; + } + } + } +#if 0 + printf("num cleared: %u\n", numCleared); +#endif } +/** + * Flush the tile cache: write all dirty tiles back to the surface. + * any tiles "flagged" as cleared will be "really" cleared. + */ void sp_flush_tile_cache(struct softpipe_context *softpipe, struct softpipe_tile_cache *tc) { struct pipe_context *pipe = &softpipe->pipe; struct pipe_surface *ps = tc->surface; - boolean is_depth_stencil; int inuse = 0, pos; - if (!ps || !ps->region || !ps->region->map) + if (!ps || !ps->buffer) return; - is_depth_stencil = (ps->format == PIPE_FORMAT_S8_Z24 || - ps->format == PIPE_FORMAT_Z24_S8 || - ps->format == PIPE_FORMAT_U_Z16 || - ps->format == PIPE_FORMAT_U_Z32 || - ps->format == PIPE_FORMAT_U_S8); + 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) { - if (is_depth_stencil) { + if (tc->depth_stencil) { pipe->put_tile(pipe, ps, tile->x, tile->y, TILE_SIZE, TILE_SIZE, tile->data.depth32, 0/*STRIDE*/); @@ -184,30 +337,31 @@ sp_flush_tile_cache(struct softpipe_context *softpipe, tile->x, tile->y, TILE_SIZE, TILE_SIZE, (float *) tile->data.color); } - tile->x = tile->y = -1; /* mark as empty */ inuse++; } } - /* +#if TILE_CLEAR_OPTIMIZATION + sp_tile_cache_flush_clear(&softpipe->pipe, tc); +#endif + +#if 0 printf("flushed tiles in use: %d\n", inuse); - */ +#endif } +/** + * Get a tile from the cache. + * \param x, y position of tile, in pixels + */ struct softpipe_cached_tile * sp_get_cached_tile(struct softpipe_context *softpipe, struct softpipe_tile_cache *tc, int x, int y) { struct pipe_context *pipe = &softpipe->pipe; struct pipe_surface *ps = tc->surface; - boolean is_depth_stencil - = (ps->format == PIPE_FORMAT_S8_Z24 || - ps->format == PIPE_FORMAT_Z24_S8 || - ps->format == PIPE_FORMAT_U_Z16 || - ps->format == PIPE_FORMAT_U_Z32 || - ps->format == PIPE_FORMAT_U_S8); /* tile pos in framebuffer: */ const int tile_x = x & ~(TILE_SIZE - 1); @@ -222,10 +376,10 @@ sp_get_cached_tile(struct softpipe_context *softpipe, if (tile->x != -1) { /* put dirty tile back in framebuffer */ - if (is_depth_stencil) { + if (tc->depth_stencil) { pipe->put_tile(pipe, ps, tile->x, tile->y, TILE_SIZE, TILE_SIZE, - tile->data.depth32, 0 /*STRIDE*/); + tile->data.depth32, 0/*STRIDE*/); } else { pipe->put_tile_rgba(pipe, ps, @@ -234,92 +388,32 @@ sp_get_cached_tile(struct softpipe_context *softpipe, } } + tile->x = tile_x; + tile->y = tile_y; + if (is_clear_flag_set(tc->clear_flags, x, y)) { /* don't get tile from framebuffer, just clear it */ - uint i, j; - /* XXX these loops could be optimized */ - switch (ps->format) { - case PIPE_FORMAT_U_Z16: - { - ushort clear_val = (ushort) (tc->clear_value[0] * 0xffff); - for (i = 0; i < TILE_SIZE; i++) { - for (j = 0; j < TILE_SIZE; j++) { - tile->data.depth16[i][j] = clear_val; - } - } - } - break; - case PIPE_FORMAT_U_Z32: - { - uint clear_val = (uint) (tc->clear_value[0] * 0xffffffff); - for (i = 0; i < TILE_SIZE; i++) { - for (j = 0; j < TILE_SIZE; j++) { - tile->data.depth32[i][j] = clear_val; - } - } - } - break; - case PIPE_FORMAT_S8_Z24: - { - uint clear_val = (uint) (tc->clear_value[0] * 0xffffff); - clear_val |= ((uint) tc->clear_value[1]) << 24; - for (i = 0; i < TILE_SIZE; i++) { - for (j = 0; j < TILE_SIZE; j++) { - tile->data.depth32[i][j] = clear_val; - } - } - } - break; - case PIPE_FORMAT_Z24_S8: - { - uint clear_val = ((uint) (tc->clear_value[0] * 0xffffff)) << 8; - clear_val |= ((uint) tc->clear_value[1]) & 0xff; - for (i = 0; i < TILE_SIZE; i++) { - for (j = 0; j < TILE_SIZE; j++) { - tile->data.depth32[i][j] = clear_val; - } - } - } - break; - case PIPE_FORMAT_U_S8: - { - ubyte clear_val = (uint) tc->clear_value[0]; - for (i = 0; i < TILE_SIZE; i++) { - for (j = 0; j < TILE_SIZE; j++) { - tile->data.stencil8[i][j] = clear_val; - } - } - } - break; - default: - /* color */ - for (i = 0; i < TILE_SIZE; i++) { - for (j = 0; j < TILE_SIZE; j++) { - tile->data.color[i][j][0] = tc->clear_value[0]; - tile->data.color[i][j][1] = tc->clear_value[1]; - tile->data.color[i][j][2] = tc->clear_value[2]; - tile->data.color[i][j][3] = tc->clear_value[3]; - } - } + if (tc->depth_stencil) { + clear_tile(tile, ps->format, tc->clear_val); + } + else { + clear_tile_rgba(tile, ps->format, tc->clear_color); } clear_clear_flag(tc->clear_flags, x, y); } else { - /* get new tile from framebuffer */ - if (is_depth_stencil) { + /* get new tile data from surface */ + if (tc->depth_stencil) { pipe->get_tile(pipe, ps, - tile_x, tile_y, TILE_SIZE, TILE_SIZE, + tile->x, tile->y, TILE_SIZE, TILE_SIZE, tile->data.depth32, 0/*STRIDE*/); } else { pipe->get_tile_rgba(pipe, ps, - tile_x, tile_y, TILE_SIZE, TILE_SIZE, + tile->x, tile->y, TILE_SIZE, TILE_SIZE, (float *) tile->data.color); } } - - tile->x = tile_x; - tile->y = tile_y; } return tile; @@ -363,16 +457,33 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, z != tile->z || face != tile->face || level != tile->level) { - /* XXX this call is a bit heavier than we'd like: */ - struct pipe_surface *ps - = pipe->get_tex_surface(pipe, tc->texture, face, level, z); + /* cache miss */ - pipe->get_tile_rgba(pipe, ps, - tile_x, tile_y, TILE_SIZE, TILE_SIZE, - (float *) tile->data.color); + /* check if we need to get a new surface */ + if (!tc->tex_surf || + tc->tex_face != face || + tc->tex_level != level || + tc->tex_z != z) { + /* get new surface (view into texture) */ + struct pipe_surface *ps; + + if (tc->tex_surf && tc->tex_surf->map) + pipe_surface_unmap(tc->tex_surf); + + ps = pipe->get_tex_surface(pipe, tc->texture, face, level, z); + pipe_surface_reference(&tc->tex_surf, ps); - pipe_surface_reference(&ps, NULL); + pipe_surface_map(ps); + tc->tex_face = face; + tc->tex_level = level; + tc->tex_z = z; + } + + /* 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); tile->x = tile_x; tile->y = tile_y; tile->z = z; @@ -390,16 +501,45 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, * Save the color and set a 'clearflag' for each tile of the screen. */ void -sp_tile_cache_clear(struct softpipe_tile_cache *tc, const float value[4]) +sp_tile_cache_clear(struct softpipe_tile_cache *tc, uint clearValue) { - tc->clear_value[0] = value[0]; - tc->clear_value[1] = value[1]; - tc->clear_value[2] = value[2]; - tc->clear_value[3] = value[3]; + uint r, g, b, a; + + tc->clear_val = clearValue; + + switch (tc->surface->format) { + case PIPE_FORMAT_R8G8B8A8_UNORM: + r = (clearValue >> 24) & 0xff; + g = (clearValue >> 16) & 0xff; + b = (clearValue >> 8) & 0xff; + a = (clearValue ) & 0xff; + break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + r = (clearValue >> 16) & 0xff; + g = (clearValue >> 8) & 0xff; + b = (clearValue ) & 0xff; + a = (clearValue >> 24) & 0xff; + break; + case PIPE_FORMAT_B8G8R8A8_UNORM: + r = (clearValue >> 8) & 0xff; + g = (clearValue >> 16) & 0xff; + b = (clearValue >> 24) & 0xff; + a = (clearValue ) & 0xff; + break; + default: + r = g = b = a = 0; + } + + tc->clear_color[0] = r / 255.0; + tc->clear_color[1] = g / 255.0; + tc->clear_color[2] = b / 255.0; + tc->clear_color[3] = a / 255.0; -#if CLEAR_OPTIMIZATION +#if TILE_CLEAR_OPTIMIZATION + /* set flags to indicate all the tiles are cleared */ memset(tc->clear_flags, 255, sizeof(tc->clear_flags)); #else + /* disable the optimization */ memset(tc->clear_flags, 0, sizeof(tc->clear_flags)); #endif } diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h index e66fec2e208..91fb2795a26 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.h +++ b/src/mesa/pipe/softpipe/sp_tile_cache.h @@ -28,6 +28,8 @@ #ifndef SP_TILE_CACHE_H #define SP_TILE_CACHE_H +#define TILE_CLEAR_OPTIMIZATION 1 + #include "pipe/p_compiler.h" @@ -49,9 +51,11 @@ struct softpipe_cached_tile int z, face, level; /**< Extra texture indexes */ union { float color[TILE_SIZE][TILE_SIZE][4]; + uint color32[TILE_SIZE][TILE_SIZE]; uint depth32[TILE_SIZE][TILE_SIZE]; ushort depth16[TILE_SIZE][TILE_SIZE]; ubyte stencil8[TILE_SIZE][TILE_SIZE]; + ubyte any[1]; } data; }; @@ -71,14 +75,14 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); extern void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, - struct pipe_mipmap_tree *texture); + struct pipe_texture *texture); extern void sp_flush_tile_cache(struct softpipe_context *softpipe, struct softpipe_tile_cache *tc); extern void -sp_tile_cache_clear(struct softpipe_tile_cache *tc, const float value[4]); +sp_tile_cache_clear(struct softpipe_tile_cache *tc, uint clearValue); extern struct softpipe_cached_tile * sp_get_cached_tile(struct softpipe_context *softpipe, diff --git a/src/mesa/pipe/tgsi/deco/Makefile b/src/mesa/pipe/tgsi/deco/Makefile deleted file mode 100644 index eb8b14e0e89..00000000000 --- a/src/mesa/pipe/tgsi/deco/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -default: - cd ../../.. ; make - diff --git a/src/mesa/pipe/tgsi/deco/deco_caps.c b/src/mesa/pipe/tgsi/deco/deco_caps.c deleted file mode 100644 index 66df05a14b8..00000000000 --- a/src/mesa/pipe/tgsi/deco/deco_caps.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "tgsi_platform.h" -#include "tgsi_deco.h" - -void -tgsi_deco_caps_init( - struct tgsi_deco_caps *caps ) -{ - memset( caps, 0, sizeof( *caps ) ); -} - diff --git a/src/mesa/pipe/tgsi/deco/deco_caps.h b/src/mesa/pipe/tgsi/deco/deco_caps.h deleted file mode 100644 index 40ca1c96f37..00000000000 --- a/src/mesa/pipe/tgsi/deco/deco_caps.h +++ /dev/null @@ -1,112 +0,0 @@ -#if !defined DECO_CAPS_H -#define DECO_CAPS_H - -#if defined __cplusplus -extern "C" { -#endif // defined __cplusplus - -struct tgsi_deco_caps -{ - /* - * Predicates (D3D9-specific). - * - * Constraints: - * 1. Token tgsi_dst_register_ext_predicate must not be used. - * 2. Token tgsi_instruction_ext_predicate must not be used. - */ - unsigned Predicates : 1; - - /* - * Destination register post-modulate. - * - * Constraints: - * 1. Field tgsi_dst_register_ext_modulate::Modulate - * must be set to TGSI_MODULATE_1X. - */ - unsigned DstModulate : 1; - - /* - * Condition codes (NVIDIA-specific). - * - * Constraints: - * 1. Token tgsi_dst_register_ext_concode must not be used. - * 2. Field tgsi_instruction_ext_nv::CondDstUpdate must be set to FALSE. - * 3. Field tgsi_instruction_ext_nv::CondFlowEnable must be set to FALSE. - */ - unsigned ConCodes : 1; - - /* - * Source register invert. - * - * Constraints: - * 1. Field tgsi_src_register_ext_mod::Complement must be set to FALSE. - */ - unsigned SrcInvert : 1; - - /* - * Source register bias. - * - * Constraints: - * 1. Field tgsi_src_register_ext_mod::Bias must be set to FALSE. - */ - unsigned SrcBias : 1; - - /* - * Source register scale by 2. - * - * Constraints: - * 1. Field tgsi_src_register_ext_mod::Scale2X must be set to FALSE. - */ - unsigned SrcScale : 1; - - /* - * Source register absolute. - * - * Constraints: - * 1. Field tgsi_src_register_ext_mod::Absolute must be set to FALSE. - */ - unsigned SrcAbsolute : 1; - - /* - * Source register force sign. - * - * Constraints: - * 1. Fields tgsi_src_register_ext_mod::Absolute and - * tgsi_src_register_ext_mod::Negate must not be both set to TRUE - * at the same time. - */ - unsigned SrcForceSign : 1; - - /* - * Source register divide. - * - * Constraints: - * 1. Field tgsi_src_register_ext_swz::ExtDivide - * must be set to TGSI_EXTSWIZZLE_ONE. - */ - unsigned SrcDivide : 1; - - /* - * Source register extended swizzle. - * - * Constraints: - * 1. Field tgsi_src_register_ext_swz::ExtSwizzleX/Y/Z/W - * must be set to TGSI_EXTSWIZZLE_X/Y/Z/W. - * 2. Fields tgsi_src_register_ext_swz::NegateX/Y/Z/W - * must all be set to the same value. - */ - unsigned SrcExtSwizzle : 1; - - unsigned Padding : 22; -}; - -void -tgsi_deco_caps_init( - struct tgsi_deco_caps *caps ); - -#if defined __cplusplus -} // extern "C" -#endif // defined __cplusplus - -#endif // !defined DECO_CAPS_H - diff --git a/src/mesa/pipe/tgsi/deco/tgsi_deco.h b/src/mesa/pipe/tgsi/deco/tgsi_deco.h deleted file mode 100644 index 3560e455f3b..00000000000 --- a/src/mesa/pipe/tgsi/deco/tgsi_deco.h +++ /dev/null @@ -1,8 +0,0 @@ -#if !defined TGSI_DECO_H -#define TGSI_DECO_H - -#include "../exec/tgsi_core.h" -#include "deco_caps.h" - -#endif // !defined TGSI_DECO_H - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_build.c b/src/mesa/pipe/tgsi/exec/tgsi_build.c deleted file mode 100644 index 78f648aae25..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_build.c +++ /dev/null @@ -1,1368 +0,0 @@ -#include "tgsi_platform.h" -#include "tgsi_core.h" - -/* - * version - */ - -struct tgsi_version -tgsi_build_version( void ) -{ - struct tgsi_version version; - - version.MajorVersion = 1; - version.MinorVersion = 1; - version.Padding = 0; - - return version; -} - -/* - * header - */ - -struct tgsi_header -tgsi_build_header( void ) -{ - struct tgsi_header header; - - header.HeaderSize = 1; - header.BodySize = 0; - - return header; -} - -static void -header_headersize_grow( struct tgsi_header *header ) -{ - assert( header->HeaderSize < 0xFF ); - assert( header->BodySize == 0 ); - - header->HeaderSize++; -} - -static void -header_bodysize_grow( struct tgsi_header *header ) -{ - assert( header->BodySize < 0xFFFFFF ); - - header->BodySize++; -} - -struct tgsi_processor -tgsi_default_processor( void ) -{ - struct tgsi_processor processor; - - processor.Processor = TGSI_PROCESSOR_FRAGMENT; - processor.Padding = 0; - - return processor; -} - -struct tgsi_processor -tgsi_build_processor( - unsigned type, - struct tgsi_header *header ) -{ - struct tgsi_processor processor; - - processor = tgsi_default_processor(); - processor.Processor = type; - - header_headersize_grow( header ); - - return processor; -} - -/* - * declaration - */ - -struct tgsi_declaration -tgsi_default_declaration( void ) -{ - struct tgsi_declaration declaration; - - declaration.Type = TGSI_TOKEN_TYPE_DECLARATION; - declaration.Size = 1; - declaration.File = TGSI_FILE_NULL; - declaration.Declare = TGSI_DECLARE_RANGE; - declaration.UsageMask = TGSI_WRITEMASK_XYZW; - declaration.Interpolate = 0; - declaration.Semantic = 0; - declaration.Padding = 0; - declaration.Extended = 0; - - return declaration; -} - -struct tgsi_declaration -tgsi_build_declaration( - unsigned file, - unsigned declare, - unsigned usage_mask, - unsigned interpolate, - unsigned semantic, - struct tgsi_header *header ) -{ - struct tgsi_declaration declaration; - - assert( file <= TGSI_FILE_IMMEDIATE ); - assert( declare <= TGSI_DECLARE_MASK ); - - declaration = tgsi_default_declaration(); - declaration.File = file; - declaration.Declare = declare; - declaration.UsageMask = usage_mask; - declaration.Interpolate = interpolate; - declaration.Semantic = semantic; - - header_bodysize_grow( header ); - - return declaration; -} - -static void -declaration_grow( - struct tgsi_declaration *declaration, - struct tgsi_header *header ) -{ - assert( declaration->Size < 0xFF ); - - declaration->Size++; - - header_bodysize_grow( header ); -} - -struct tgsi_full_declaration -tgsi_default_full_declaration( void ) -{ - struct tgsi_full_declaration full_declaration; - - full_declaration.Declaration = tgsi_default_declaration(); - full_declaration.Interpolation = tgsi_default_declaration_interpolation(); - full_declaration.Semantic = tgsi_default_declaration_semantic(); - - return full_declaration; -} - -unsigned -tgsi_build_full_declaration( - const struct tgsi_full_declaration *full_decl, - struct tgsi_token *tokens, - struct tgsi_header *header, - unsigned maxsize ) -{ - unsigned size = 0; - struct tgsi_declaration *declaration; - - if( maxsize <= size ) - return 0; - declaration = (struct tgsi_declaration *) &tokens[size]; - size++; - - *declaration = tgsi_build_declaration( - full_decl->Declaration.File, - full_decl->Declaration.Declare, - full_decl->Declaration.UsageMask, - full_decl->Declaration.Interpolate, - full_decl->Declaration.Semantic, - header ); - - switch( full_decl->Declaration.Declare ) { - case TGSI_DECLARE_RANGE: - { - struct tgsi_declaration_range *dr; - - if( maxsize <= size ) - return 0; - dr = (struct tgsi_declaration_range *) &tokens[size]; - size++; - - *dr = tgsi_build_declaration_range( - full_decl->u.DeclarationRange.First, - full_decl->u.DeclarationRange.Last, - declaration, - header ); - break; - } - - case TGSI_DECLARE_MASK: - { - struct tgsi_declaration_mask *dm; - - if( maxsize <= size ) - return 0; - dm = (struct tgsi_declaration_mask *) &tokens[size]; - size++; - - *dm = tgsi_build_declaration_mask( - full_decl->u.DeclarationMask.Mask, - declaration, - header ); - break; - } - - default: - assert( 0 ); - } - - if( full_decl->Declaration.Interpolate ) { - struct tgsi_declaration_interpolation *di; - - if( maxsize <= size ) - return 0; - di = (struct tgsi_declaration_interpolation *) &tokens[size]; - size++; - - *di = tgsi_build_declaration_interpolation( - full_decl->Interpolation.Interpolate, - declaration, - header ); - } - - if( full_decl->Declaration.Semantic ) { - struct tgsi_declaration_semantic *ds; - - if( maxsize <= size ) - return 0; - ds = (struct tgsi_declaration_semantic *) &tokens[size]; - size++; - - *ds = tgsi_build_declaration_semantic( - full_decl->Semantic.SemanticName, - full_decl->Semantic.SemanticIndex, - declaration, - header ); - } - - return size; -} - -struct tgsi_declaration_range -tgsi_build_declaration_range( - unsigned first, - unsigned last, - struct tgsi_declaration *declaration, - struct tgsi_header *header ) -{ - struct tgsi_declaration_range declaration_range; - - assert( last >= first ); - assert( last <= 0xFFFF ); - - declaration_range.First = first; - declaration_range.Last = last; - - declaration_grow( declaration, header ); - - return declaration_range; -} - -struct tgsi_declaration_mask -tgsi_build_declaration_mask( - unsigned mask, - struct tgsi_declaration *declaration, - struct tgsi_header *header ) -{ - struct tgsi_declaration_mask declaration_mask; - - declaration_mask.Mask = mask; - - declaration_grow( declaration, header ); - - return declaration_mask; -} - -struct tgsi_declaration_interpolation -tgsi_default_declaration_interpolation( void ) -{ - struct tgsi_declaration_interpolation di; - - di.Interpolate = TGSI_INTERPOLATE_CONSTANT; - di.Padding = 0; - - return di; -} - -struct tgsi_declaration_interpolation -tgsi_build_declaration_interpolation( - unsigned interpolate, - struct tgsi_declaration *declaration, - struct tgsi_header *header ) -{ - struct tgsi_declaration_interpolation di; - - assert( interpolate <= TGSI_INTERPOLATE_PERSPECTIVE ); - - di = tgsi_default_declaration_interpolation(); - di.Interpolate = interpolate; - - declaration_grow( declaration, header ); - - return di; -} - -struct tgsi_declaration_semantic -tgsi_default_declaration_semantic( void ) -{ - struct tgsi_declaration_semantic ds; - - ds.SemanticName = TGSI_SEMANTIC_POSITION; - ds.SemanticIndex = 0; - ds.Padding = 0; - - return ds; -} - -struct tgsi_declaration_semantic -tgsi_build_declaration_semantic( - unsigned semantic_name, - unsigned semantic_index, - struct tgsi_declaration *declaration, - struct tgsi_header *header ) -{ - struct tgsi_declaration_semantic ds; - - assert( semantic_name <= TGSI_SEMANTIC_COUNT ); - assert( semantic_index <= 0xFFFF ); - - ds = tgsi_default_declaration_semantic(); - ds.SemanticName = semantic_name; - ds.SemanticIndex = semantic_index; - - declaration_grow( declaration, header ); - - return ds; -} - -/* - * immediate - */ - -struct tgsi_immediate -tgsi_default_immediate( void ) -{ - struct tgsi_immediate immediate; - - immediate.Type = TGSI_TOKEN_TYPE_IMMEDIATE; - immediate.Size = 1; - immediate.DataType = TGSI_IMM_FLOAT32; - immediate.Padding = 0; - immediate.Extended = 0; - - return immediate; -} - -struct tgsi_immediate -tgsi_build_immediate( - struct tgsi_header *header ) -{ - struct tgsi_immediate immediate; - - immediate = tgsi_default_immediate(); - - header_bodysize_grow( header ); - - return immediate; -} - -struct tgsi_full_immediate -tgsi_default_full_immediate( void ) -{ - struct tgsi_full_immediate fullimm; - - fullimm.Immediate = tgsi_default_immediate(); - fullimm.u.Pointer = (void *) 0; - - return fullimm; -} - -static void -immediate_grow( - struct tgsi_immediate *immediate, - struct tgsi_header *header ) -{ - assert( immediate->Size < 0xFF ); - - immediate->Size++; - - header_bodysize_grow( header ); -} - -struct tgsi_immediate_float32 -tgsi_build_immediate_float32( - float value, - struct tgsi_immediate *immediate, - struct tgsi_header *header ) -{ - struct tgsi_immediate_float32 immediate_float32; - - immediate_float32.Float = value; - - immediate_grow( immediate, header ); - - return immediate_float32; -} - -unsigned -tgsi_build_full_immediate( - const struct tgsi_full_immediate *full_imm, - struct tgsi_token *tokens, - struct tgsi_header *header, - unsigned maxsize ) -{ - unsigned size = 0, i; - struct tgsi_immediate *immediate; - - if( maxsize <= size ) - return 0; - immediate = (struct tgsi_immediate *) &tokens[size]; - size++; - - *immediate = tgsi_build_immediate( header ); - - for( i = 0; i < full_imm->Immediate.Size - 1; i++ ) { - struct tgsi_immediate_float32 *if32; - - if( maxsize <= size ) - return 0; - if32 = (struct tgsi_immediate_float32 *) &tokens[size]; - size++; - - *if32 = tgsi_build_immediate_float32( - full_imm->u.ImmediateFloat32[i].Float, - immediate, - header ); - } - - return size; -} - -/* - * instruction - */ - -struct tgsi_instruction -tgsi_default_instruction( void ) -{ - struct tgsi_instruction instruction; - - instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION; - instruction.Size = 1; - instruction.Opcode = TGSI_OPCODE_MOV; - instruction.Saturate = TGSI_SAT_NONE; - instruction.NumDstRegs = 1; - instruction.NumSrcRegs = 1; - instruction.Padding = 0; - instruction.Extended = 0; - - return instruction; -} - -struct tgsi_instruction -tgsi_build_instruction( - unsigned opcode, - unsigned saturate, - unsigned num_dst_regs, - unsigned num_src_regs, - struct tgsi_header *header ) -{ - struct tgsi_instruction instruction; - - assert (opcode <= TGSI_OPCODE_LAST); - assert (saturate <= TGSI_SAT_MINUS_PLUS_ONE); - assert (num_dst_regs <= 3); - assert (num_src_regs <= 15); - - instruction = tgsi_default_instruction(); - instruction.Opcode = opcode; - instruction.Saturate = saturate; - instruction.NumDstRegs = num_dst_regs; - instruction.NumSrcRegs = num_src_regs; - - header_bodysize_grow( header ); - - return instruction; -} - -static void -instruction_grow( - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - assert (instruction->Size < 0xFF); - - instruction->Size++; - - header_bodysize_grow( header ); -} - -struct tgsi_full_instruction -tgsi_default_full_instruction( void ) -{ - struct tgsi_full_instruction full_instruction; - unsigned i; - - full_instruction.Instruction = tgsi_default_instruction(); - full_instruction.InstructionExtNv = tgsi_default_instruction_ext_nv(); - full_instruction.InstructionExtLabel = tgsi_default_instruction_ext_label(); - full_instruction.InstructionExtTexture = tgsi_default_instruction_ext_texture(); - for( i = 0; i < TGSI_FULL_MAX_DST_REGISTERS; i++ ) { - full_instruction.FullDstRegisters[i] = tgsi_default_full_dst_register(); - } - for( i = 0; i < TGSI_FULL_MAX_SRC_REGISTERS; i++ ) { - full_instruction.FullSrcRegisters[i] = tgsi_default_full_src_register(); - } - - return full_instruction; -} - -unsigned -tgsi_build_full_instruction( - const struct tgsi_full_instruction *full_inst, - struct tgsi_token *tokens, - struct tgsi_header *header, - unsigned maxsize ) -{ - unsigned size = 0; - unsigned i; - struct tgsi_instruction *instruction; - struct tgsi_token *prev_token; - - if( maxsize <= size ) - return 0; - instruction = (struct tgsi_instruction *) &tokens[size]; - size++; - - *instruction = tgsi_build_instruction( - full_inst->Instruction.Opcode, - full_inst->Instruction.Saturate, - full_inst->Instruction.NumDstRegs, - full_inst->Instruction.NumSrcRegs, - header ); - prev_token = (struct tgsi_token *) instruction; - - if( tgsi_compare_instruction_ext_nv( - full_inst->InstructionExtNv, - tgsi_default_instruction_ext_nv() ) ) { - struct tgsi_instruction_ext_nv *instruction_ext_nv; - - if( maxsize <= size ) - return 0; - instruction_ext_nv = - (struct tgsi_instruction_ext_nv *) &tokens[size]; - size++; - - *instruction_ext_nv = tgsi_build_instruction_ext_nv( - full_inst->InstructionExtNv.Precision, - full_inst->InstructionExtNv.CondDstIndex, - full_inst->InstructionExtNv.CondFlowIndex, - full_inst->InstructionExtNv.CondMask, - full_inst->InstructionExtNv.CondSwizzleX, - full_inst->InstructionExtNv.CondSwizzleY, - full_inst->InstructionExtNv.CondSwizzleZ, - full_inst->InstructionExtNv.CondSwizzleW, - full_inst->InstructionExtNv.CondDstUpdate, - full_inst->InstructionExtNv.CondFlowEnable, - prev_token, - instruction, - header ); - prev_token = (struct tgsi_token *) instruction_ext_nv; - } - - if( tgsi_compare_instruction_ext_label( - full_inst->InstructionExtLabel, - tgsi_default_instruction_ext_label() ) ) { - struct tgsi_instruction_ext_label *instruction_ext_label; - - if( maxsize <= size ) - return 0; - instruction_ext_label = - (struct tgsi_instruction_ext_label *) &tokens[size]; - size++; - - *instruction_ext_label = tgsi_build_instruction_ext_label( - full_inst->InstructionExtLabel.Label, - prev_token, - instruction, - header ); - prev_token = (struct tgsi_token *) instruction_ext_label; - } - - if( tgsi_compare_instruction_ext_texture( - full_inst->InstructionExtTexture, - tgsi_default_instruction_ext_texture() ) ) { - struct tgsi_instruction_ext_texture *instruction_ext_texture; - - if( maxsize <= size ) - return 0; - instruction_ext_texture = - (struct tgsi_instruction_ext_texture *) &tokens[size]; - size++; - - *instruction_ext_texture = tgsi_build_instruction_ext_texture( - full_inst->InstructionExtTexture.Texture, - prev_token, - instruction, - header ); - prev_token = (struct tgsi_token *) instruction_ext_texture; - } - - for( i = 0; i < full_inst->Instruction.NumDstRegs; i++ ) { - const struct tgsi_full_dst_register *reg = &full_inst->FullDstRegisters[i]; - struct tgsi_dst_register *dst_register; - struct tgsi_token *prev_token; - - if( maxsize <= size ) - return 0; - dst_register = (struct tgsi_dst_register *) &tokens[size]; - size++; - - *dst_register = tgsi_build_dst_register( - reg->DstRegister.File, - reg->DstRegister.WriteMask, - reg->DstRegister.Index, - instruction, - header ); - prev_token = (struct tgsi_token *) dst_register; - - if( tgsi_compare_dst_register_ext_concode( - reg->DstRegisterExtConcode, - tgsi_default_dst_register_ext_concode() ) ) { - struct tgsi_dst_register_ext_concode *dst_register_ext_concode; - - if( maxsize <= size ) - return 0; - dst_register_ext_concode = - (struct tgsi_dst_register_ext_concode *) &tokens[size]; - size++; - - *dst_register_ext_concode = tgsi_build_dst_register_ext_concode( - reg->DstRegisterExtConcode.CondMask, - reg->DstRegisterExtConcode.CondSwizzleX, - reg->DstRegisterExtConcode.CondSwizzleY, - reg->DstRegisterExtConcode.CondSwizzleZ, - reg->DstRegisterExtConcode.CondSwizzleW, - reg->DstRegisterExtConcode.CondSrcIndex, - prev_token, - instruction, - header ); - prev_token = (struct tgsi_token *) dst_register_ext_concode; - } - - if( tgsi_compare_dst_register_ext_modulate( - reg->DstRegisterExtModulate, - tgsi_default_dst_register_ext_modulate() ) ) { - struct tgsi_dst_register_ext_modulate *dst_register_ext_modulate; - - if( maxsize <= size ) - return 0; - dst_register_ext_modulate = - (struct tgsi_dst_register_ext_modulate *) &tokens[size]; - size++; - - *dst_register_ext_modulate = tgsi_build_dst_register_ext_modulate( - reg->DstRegisterExtModulate.Modulate, - prev_token, - instruction, - header ); - prev_token = (struct tgsi_token *) dst_register_ext_modulate; - } - } - - for( i = 0; i < full_inst->Instruction.NumSrcRegs; i++ ) { - const struct tgsi_full_src_register *reg = &full_inst->FullSrcRegisters[i]; - struct tgsi_src_register *src_register; - struct tgsi_token *prev_token; - - if( maxsize <= size ) - return 0; - src_register = (struct tgsi_src_register *) &tokens[size]; - size++; - - *src_register = tgsi_build_src_register( - reg->SrcRegister.File, - reg->SrcRegister.SwizzleX, - reg->SrcRegister.SwizzleY, - reg->SrcRegister.SwizzleZ, - reg->SrcRegister.SwizzleW, - reg->SrcRegister.Negate, - reg->SrcRegister.Indirect, - reg->SrcRegister.Dimension, - reg->SrcRegister.Index, - instruction, - header ); - prev_token = (struct tgsi_token *) src_register; - - if( tgsi_compare_src_register_ext_swz( - reg->SrcRegisterExtSwz, - tgsi_default_src_register_ext_swz() ) ) { - struct tgsi_src_register_ext_swz *src_register_ext_swz; - - if( maxsize <= size ) - return 0; - src_register_ext_swz = - (struct tgsi_src_register_ext_swz *) &tokens[size]; - size++; - - *src_register_ext_swz = tgsi_build_src_register_ext_swz( - reg->SrcRegisterExtSwz.ExtSwizzleX, - reg->SrcRegisterExtSwz.ExtSwizzleY, - reg->SrcRegisterExtSwz.ExtSwizzleZ, - reg->SrcRegisterExtSwz.ExtSwizzleW, - reg->SrcRegisterExtSwz.NegateX, - reg->SrcRegisterExtSwz.NegateY, - reg->SrcRegisterExtSwz.NegateZ, - reg->SrcRegisterExtSwz.NegateW, - reg->SrcRegisterExtSwz.ExtDivide, - prev_token, - instruction, - header ); - prev_token = (struct tgsi_token *) src_register_ext_swz; - } - - if( tgsi_compare_src_register_ext_mod( - reg->SrcRegisterExtMod, - tgsi_default_src_register_ext_mod() ) ) { - struct tgsi_src_register_ext_mod *src_register_ext_mod; - - if( maxsize <= size ) - return 0; - src_register_ext_mod = - (struct tgsi_src_register_ext_mod *) &tokens[size]; - size++; - - *src_register_ext_mod = tgsi_build_src_register_ext_mod( - reg->SrcRegisterExtMod.Complement, - reg->SrcRegisterExtMod.Bias, - reg->SrcRegisterExtMod.Scale2X, - reg->SrcRegisterExtMod.Absolute, - reg->SrcRegisterExtMod.Negate, - prev_token, - instruction, - header ); - prev_token = (struct tgsi_token *) src_register_ext_mod; - } - - if( reg->SrcRegister.Indirect ) { - struct tgsi_src_register *ind; - - if( maxsize <= size ) - return 0; - ind = (struct tgsi_src_register *) &tokens[size]; - size++; - - *ind = tgsi_build_src_register( - reg->SrcRegisterInd.File, - reg->SrcRegisterInd.SwizzleX, - reg->SrcRegisterInd.SwizzleY, - reg->SrcRegisterInd.SwizzleZ, - reg->SrcRegisterInd.SwizzleW, - reg->SrcRegisterInd.Negate, - reg->SrcRegisterInd.Indirect, - reg->SrcRegisterInd.Dimension, - reg->SrcRegisterInd.Index, - instruction, - header ); - } - - if( reg->SrcRegister.Dimension ) { - struct tgsi_dimension *dim; - - assert( !reg->SrcRegisterDim.Dimension ); - - if( maxsize <= size ) - return 0; - dim = (struct tgsi_dimension *) &tokens[size]; - size++; - - *dim = tgsi_build_dimension( - reg->SrcRegisterDim.Indirect, - reg->SrcRegisterDim.Index, - instruction, - header ); - - if( reg->SrcRegisterDim.Indirect ) { - struct tgsi_src_register *ind; - - if( maxsize <= size ) - return 0; - ind = (struct tgsi_src_register *) &tokens[size]; - size++; - - *ind = tgsi_build_src_register( - reg->SrcRegisterDimInd.File, - reg->SrcRegisterDimInd.SwizzleX, - reg->SrcRegisterDimInd.SwizzleY, - reg->SrcRegisterDimInd.SwizzleZ, - reg->SrcRegisterDimInd.SwizzleW, - reg->SrcRegisterDimInd.Negate, - reg->SrcRegisterDimInd.Indirect, - reg->SrcRegisterDimInd.Dimension, - reg->SrcRegisterDimInd.Index, - instruction, - header ); - } - } - } - - return size; -} - -struct tgsi_instruction_ext_nv -tgsi_default_instruction_ext_nv( void ) -{ - struct tgsi_instruction_ext_nv instruction_ext_nv; - - instruction_ext_nv.Type = TGSI_INSTRUCTION_EXT_TYPE_NV; - instruction_ext_nv.Precision = TGSI_PRECISION_DEFAULT; - instruction_ext_nv.CondDstIndex = 0; - instruction_ext_nv.CondFlowIndex = 0; - instruction_ext_nv.CondMask = TGSI_CC_TR; - instruction_ext_nv.CondSwizzleX = TGSI_SWIZZLE_X; - instruction_ext_nv.CondSwizzleY = TGSI_SWIZZLE_Y; - instruction_ext_nv.CondSwizzleZ = TGSI_SWIZZLE_Z; - instruction_ext_nv.CondSwizzleW = TGSI_SWIZZLE_W; - instruction_ext_nv.CondDstUpdate = 0; - instruction_ext_nv.CondFlowEnable = 0; - instruction_ext_nv.Padding = 0; - instruction_ext_nv.Extended = 0; - - return instruction_ext_nv; -} - -union token_u32 -{ - unsigned u32; -}; - -unsigned -tgsi_compare_instruction_ext_nv( - struct tgsi_instruction_ext_nv a, - struct tgsi_instruction_ext_nv b ) -{ - a.Padding = b.Padding = 0; - a.Extended = b.Extended = 0; - return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; -} - -struct tgsi_instruction_ext_nv -tgsi_build_instruction_ext_nv( - unsigned precision, - unsigned cond_dst_index, - unsigned cond_flow_index, - unsigned cond_mask, - unsigned cond_swizzle_x, - unsigned cond_swizzle_y, - unsigned cond_swizzle_z, - unsigned cond_swizzle_w, - unsigned cond_dst_update, - unsigned cond_flow_update, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_instruction_ext_nv instruction_ext_nv; - - instruction_ext_nv = tgsi_default_instruction_ext_nv(); - instruction_ext_nv.Precision = precision; - instruction_ext_nv.CondDstIndex = cond_dst_index; - instruction_ext_nv.CondFlowIndex = cond_flow_index; - instruction_ext_nv.CondMask = cond_mask; - instruction_ext_nv.CondSwizzleX = cond_swizzle_x; - instruction_ext_nv.CondSwizzleY = cond_swizzle_y; - instruction_ext_nv.CondSwizzleZ = cond_swizzle_z; - instruction_ext_nv.CondSwizzleW = cond_swizzle_w; - instruction_ext_nv.CondDstUpdate = cond_dst_update; - instruction_ext_nv.CondFlowEnable = cond_flow_update; - - prev_token->Extended = 1; - instruction_grow( instruction, header ); - - return instruction_ext_nv; -} - -struct tgsi_instruction_ext_label -tgsi_default_instruction_ext_label( void ) -{ - struct tgsi_instruction_ext_label instruction_ext_label; - - instruction_ext_label.Type = TGSI_INSTRUCTION_EXT_TYPE_LABEL; - instruction_ext_label.Label = 0; - instruction_ext_label.Padding = 0; - instruction_ext_label.Extended = 0; - - return instruction_ext_label; -} - -unsigned -tgsi_compare_instruction_ext_label( - struct tgsi_instruction_ext_label a, - struct tgsi_instruction_ext_label b ) -{ - a.Padding = b.Padding = 0; - a.Extended = b.Extended = 0; - return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; -} - -struct tgsi_instruction_ext_label -tgsi_build_instruction_ext_label( - unsigned label, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_instruction_ext_label instruction_ext_label; - - instruction_ext_label = tgsi_default_instruction_ext_label(); - instruction_ext_label.Label = label; - - prev_token->Extended = 1; - instruction_grow( instruction, header ); - - return instruction_ext_label; -} - -struct tgsi_instruction_ext_texture -tgsi_default_instruction_ext_texture( void ) -{ - struct tgsi_instruction_ext_texture instruction_ext_texture; - - instruction_ext_texture.Type = TGSI_INSTRUCTION_EXT_TYPE_TEXTURE; - instruction_ext_texture.Texture = TGSI_TEXTURE_UNKNOWN; - instruction_ext_texture.Padding = 0; - instruction_ext_texture.Extended = 0; - - return instruction_ext_texture; -} - -unsigned -tgsi_compare_instruction_ext_texture( - struct tgsi_instruction_ext_texture a, - struct tgsi_instruction_ext_texture b ) -{ - a.Padding = b.Padding = 0; - a.Extended = b.Extended = 0; - return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; -} - -struct tgsi_instruction_ext_texture -tgsi_build_instruction_ext_texture( - unsigned texture, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_instruction_ext_texture instruction_ext_texture; - - instruction_ext_texture = tgsi_default_instruction_ext_texture(); - instruction_ext_texture.Texture = texture; - - prev_token->Extended = 1; - instruction_grow( instruction, header ); - - return instruction_ext_texture; -} - -struct tgsi_src_register -tgsi_default_src_register( void ) -{ - struct tgsi_src_register src_register; - - src_register.File = TGSI_FILE_NULL; - src_register.SwizzleX = TGSI_SWIZZLE_X; - src_register.SwizzleY = TGSI_SWIZZLE_Y; - src_register.SwizzleZ = TGSI_SWIZZLE_Z; - src_register.SwizzleW = TGSI_SWIZZLE_W; - src_register.Negate = 0; - src_register.Indirect = 0; - src_register.Dimension = 0; - src_register.Index = 0; - src_register.Extended = 0; - - return src_register; -} - -struct tgsi_src_register -tgsi_build_src_register( - unsigned file, - unsigned swizzle_x, - unsigned swizzle_y, - unsigned swizzle_z, - unsigned swizzle_w, - unsigned negate, - unsigned indirect, - unsigned dimension, - int index, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_src_register src_register; - - assert( file <= TGSI_FILE_IMMEDIATE ); - assert( swizzle_x <= TGSI_SWIZZLE_W ); - assert( swizzle_y <= TGSI_SWIZZLE_W ); - assert( swizzle_z <= TGSI_SWIZZLE_W ); - assert( swizzle_w <= TGSI_SWIZZLE_W ); - assert( negate <= 1 ); - assert( index >= -0x8000 && index <= 0x7FFF ); - - src_register = tgsi_default_src_register(); - src_register.File = file; - src_register.SwizzleX = swizzle_x; - src_register.SwizzleY = swizzle_y; - src_register.SwizzleZ = swizzle_z; - src_register.SwizzleW = swizzle_w; - src_register.Negate = negate; - src_register.Indirect = indirect; - src_register.Dimension = dimension; - src_register.Index = index; - - instruction_grow( instruction, header ); - - return src_register; -} - -struct tgsi_full_src_register -tgsi_default_full_src_register( void ) -{ - struct tgsi_full_src_register full_src_register; - - full_src_register.SrcRegister = tgsi_default_src_register(); - full_src_register.SrcRegisterExtSwz = tgsi_default_src_register_ext_swz(); - full_src_register.SrcRegisterExtMod = tgsi_default_src_register_ext_mod(); - full_src_register.SrcRegisterInd = tgsi_default_src_register(); - full_src_register.SrcRegisterDim = tgsi_default_dimension(); - full_src_register.SrcRegisterDimInd = tgsi_default_src_register(); - - return full_src_register; -} - -struct tgsi_src_register_ext_swz -tgsi_default_src_register_ext_swz( void ) -{ - struct tgsi_src_register_ext_swz src_register_ext_swz; - - src_register_ext_swz.Type = TGSI_SRC_REGISTER_EXT_TYPE_SWZ; - src_register_ext_swz.ExtSwizzleX = TGSI_EXTSWIZZLE_X; - src_register_ext_swz.ExtSwizzleY = TGSI_EXTSWIZZLE_Y; - src_register_ext_swz.ExtSwizzleZ = TGSI_EXTSWIZZLE_Z; - src_register_ext_swz.ExtSwizzleW = TGSI_EXTSWIZZLE_W; - src_register_ext_swz.NegateX = 0; - src_register_ext_swz.NegateY = 0; - src_register_ext_swz.NegateZ = 0; - src_register_ext_swz.NegateW = 0; - src_register_ext_swz.ExtDivide = TGSI_EXTSWIZZLE_ONE; - src_register_ext_swz.Padding = 0; - src_register_ext_swz.Extended = 0; - - return src_register_ext_swz; -} - -unsigned -tgsi_compare_src_register_ext_swz( - struct tgsi_src_register_ext_swz a, - struct tgsi_src_register_ext_swz b ) -{ - a.Padding = b.Padding = 0; - a.Extended = b.Extended = 0; - return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; -} - -struct tgsi_src_register_ext_swz -tgsi_build_src_register_ext_swz( - unsigned ext_swizzle_x, - unsigned ext_swizzle_y, - unsigned ext_swizzle_z, - unsigned ext_swizzle_w, - unsigned negate_x, - unsigned negate_y, - unsigned negate_z, - unsigned negate_w, - unsigned ext_divide, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_src_register_ext_swz src_register_ext_swz; - - assert( ext_swizzle_x <= TGSI_EXTSWIZZLE_ONE ); - assert( ext_swizzle_y <= TGSI_EXTSWIZZLE_ONE ); - assert( ext_swizzle_z <= TGSI_EXTSWIZZLE_ONE ); - assert( ext_swizzle_w <= TGSI_EXTSWIZZLE_ONE ); - assert( negate_x <= 1 ); - assert( negate_y <= 1 ); - assert( negate_z <= 1 ); - assert( negate_w <= 1 ); - assert( ext_divide <= TGSI_EXTSWIZZLE_ONE ); - - src_register_ext_swz = tgsi_default_src_register_ext_swz(); - src_register_ext_swz.ExtSwizzleX = ext_swizzle_x; - src_register_ext_swz.ExtSwizzleY = ext_swizzle_y; - src_register_ext_swz.ExtSwizzleZ = ext_swizzle_z; - src_register_ext_swz.ExtSwizzleW = ext_swizzle_w; - src_register_ext_swz.NegateX = negate_x; - src_register_ext_swz.NegateY = negate_y; - src_register_ext_swz.NegateZ = negate_z; - src_register_ext_swz.NegateW = negate_w; - src_register_ext_swz.ExtDivide = ext_divide; - - prev_token->Extended = 1; - instruction_grow( instruction, header ); - - return src_register_ext_swz; -} - -struct tgsi_src_register_ext_mod -tgsi_default_src_register_ext_mod( void ) -{ - struct tgsi_src_register_ext_mod src_register_ext_mod; - - src_register_ext_mod.Type = TGSI_SRC_REGISTER_EXT_TYPE_MOD; - src_register_ext_mod.Complement = 0; - src_register_ext_mod.Bias = 0; - src_register_ext_mod.Scale2X = 0; - src_register_ext_mod.Absolute = 0; - src_register_ext_mod.Negate = 0; - src_register_ext_mod.Padding = 0; - src_register_ext_mod.Extended = 0; - - return src_register_ext_mod; -} - -unsigned -tgsi_compare_src_register_ext_mod( - struct tgsi_src_register_ext_mod a, - struct tgsi_src_register_ext_mod b ) -{ - a.Padding = b.Padding = 0; - a.Extended = b.Extended = 0; - return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; -} - -struct tgsi_src_register_ext_mod -tgsi_build_src_register_ext_mod( - unsigned complement, - unsigned bias, - unsigned scale_2x, - unsigned absolute, - unsigned negate, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_src_register_ext_mod src_register_ext_mod; - - assert( complement <= 1 ); - assert( bias <= 1 ); - assert( scale_2x <= 1 ); - assert( absolute <= 1 ); - assert( negate <= 1 ); - - src_register_ext_mod = tgsi_default_src_register_ext_mod(); - src_register_ext_mod.Complement = complement; - src_register_ext_mod.Bias = bias; - src_register_ext_mod.Scale2X = scale_2x; - src_register_ext_mod.Absolute = absolute; - src_register_ext_mod.Negate = negate; - - prev_token->Extended = 1; - instruction_grow( instruction, header ); - - return src_register_ext_mod; -} - -struct tgsi_dimension -tgsi_default_dimension( void ) -{ - struct tgsi_dimension dimension; - - dimension.Indirect = 0; - dimension.Dimension = 0; - dimension.Padding = 0; - dimension.Index = 0; - dimension.Extended = 0; - - return dimension; -} - -struct tgsi_dimension -tgsi_build_dimension( - unsigned indirect, - unsigned index, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_dimension dimension; - - dimension = tgsi_default_dimension(); - dimension.Indirect = indirect; - dimension.Index = index; - - instruction_grow( instruction, header ); - - return dimension; -} - -struct tgsi_dst_register -tgsi_default_dst_register( void ) -{ - struct tgsi_dst_register dst_register; - - dst_register.File = TGSI_FILE_NULL; - dst_register.WriteMask = TGSI_WRITEMASK_XYZW; - dst_register.Indirect = 0; - dst_register.Dimension = 0; - dst_register.Index = 0; - dst_register.Padding = 0; - dst_register.Extended = 0; - - return dst_register; -} - -struct tgsi_dst_register -tgsi_build_dst_register( - unsigned file, - unsigned mask, - int index, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_dst_register dst_register; - - assert( file <= TGSI_FILE_IMMEDIATE ); - assert( mask <= TGSI_WRITEMASK_XYZW ); - assert( index >= -32768 && index <= 32767 ); - - dst_register = tgsi_default_dst_register(); - dst_register.File = file; - dst_register.WriteMask = mask; - dst_register.Index = index; - - instruction_grow( instruction, header ); - - return dst_register; -} - -struct tgsi_full_dst_register -tgsi_default_full_dst_register( void ) -{ - struct tgsi_full_dst_register full_dst_register; - - full_dst_register.DstRegister = tgsi_default_dst_register(); - full_dst_register.DstRegisterExtConcode = - tgsi_default_dst_register_ext_concode(); - full_dst_register.DstRegisterExtModulate = - tgsi_default_dst_register_ext_modulate(); - - return full_dst_register; -} - -struct tgsi_dst_register_ext_concode -tgsi_default_dst_register_ext_concode( void ) -{ - struct tgsi_dst_register_ext_concode dst_register_ext_concode; - - dst_register_ext_concode.Type = TGSI_DST_REGISTER_EXT_TYPE_CONDCODE; - dst_register_ext_concode.CondMask = TGSI_CC_TR; - dst_register_ext_concode.CondSwizzleX = TGSI_SWIZZLE_X; - dst_register_ext_concode.CondSwizzleY = TGSI_SWIZZLE_Y; - dst_register_ext_concode.CondSwizzleZ = TGSI_SWIZZLE_Z; - dst_register_ext_concode.CondSwizzleW = TGSI_SWIZZLE_W; - dst_register_ext_concode.CondSrcIndex = 0; - dst_register_ext_concode.Padding = 0; - dst_register_ext_concode.Extended = 0; - - return dst_register_ext_concode; -} - -unsigned -tgsi_compare_dst_register_ext_concode( - struct tgsi_dst_register_ext_concode a, - struct tgsi_dst_register_ext_concode b ) -{ - a.Padding = b.Padding = 0; - a.Extended = b.Extended = 0; - return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; -} - -struct tgsi_dst_register_ext_concode -tgsi_build_dst_register_ext_concode( - unsigned cc, - unsigned swizzle_x, - unsigned swizzle_y, - unsigned swizzle_z, - unsigned swizzle_w, - int index, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_dst_register_ext_concode dst_register_ext_concode; - - assert( cc <= TGSI_CC_FL ); - assert( swizzle_x <= TGSI_SWIZZLE_W ); - assert( swizzle_y <= TGSI_SWIZZLE_W ); - assert( swizzle_z <= TGSI_SWIZZLE_W ); - assert( swizzle_w <= TGSI_SWIZZLE_W ); - assert( index >= -32768 && index <= 32767 ); - - dst_register_ext_concode = tgsi_default_dst_register_ext_concode(); - dst_register_ext_concode.CondMask = cc; - dst_register_ext_concode.CondSwizzleX = swizzle_x; - dst_register_ext_concode.CondSwizzleY = swizzle_y; - dst_register_ext_concode.CondSwizzleZ = swizzle_z; - dst_register_ext_concode.CondSwizzleW = swizzle_w; - dst_register_ext_concode.CondSrcIndex = index; - - prev_token->Extended = 1; - instruction_grow( instruction, header ); - - return dst_register_ext_concode; -} - -struct tgsi_dst_register_ext_modulate -tgsi_default_dst_register_ext_modulate( void ) -{ - struct tgsi_dst_register_ext_modulate dst_register_ext_modulate; - - dst_register_ext_modulate.Type = TGSI_DST_REGISTER_EXT_TYPE_MODULATE; - dst_register_ext_modulate.Modulate = TGSI_MODULATE_1X; - dst_register_ext_modulate.Padding = 0; - dst_register_ext_modulate.Extended = 0; - - return dst_register_ext_modulate; -} - -unsigned -tgsi_compare_dst_register_ext_modulate( - struct tgsi_dst_register_ext_modulate a, - struct tgsi_dst_register_ext_modulate b ) -{ - a.Padding = b.Padding = 0; - a.Extended = b.Extended = 0; - return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; -} - -struct tgsi_dst_register_ext_modulate -tgsi_build_dst_register_ext_modulate( - unsigned modulate, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ) -{ - struct tgsi_dst_register_ext_modulate dst_register_ext_modulate; - - assert( modulate <= TGSI_MODULATE_EIGHTH ); - - dst_register_ext_modulate = tgsi_default_dst_register_ext_modulate(); - dst_register_ext_modulate.Modulate = modulate; - - prev_token->Extended = 1; - instruction_grow( instruction, header ); - - return dst_register_ext_modulate; -} - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_build.h b/src/mesa/pipe/tgsi/exec/tgsi_build.h deleted file mode 100644 index 116c78abf34..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_build.h +++ /dev/null @@ -1,320 +0,0 @@ -#if !defined TGSI_BUILD_H -#define TGSI_BUILD_H - -#if defined __cplusplus -extern "C" { -#endif // defined __cplusplus - -/* - * version - */ - -struct tgsi_version -tgsi_build_version( void ); - -/* - * header - */ - -struct tgsi_header -tgsi_build_header( void ); - -struct tgsi_processor -tgsi_default_processor( void ); - -struct tgsi_processor -tgsi_build_processor( - unsigned processor, - struct tgsi_header *header ); - -/* - * declaration - */ - -struct tgsi_declaration -tgsi_default_declaration( void ); - -struct tgsi_declaration -tgsi_build_declaration( - unsigned file, - unsigned declare, - unsigned usage_mask, - unsigned interpolate, - unsigned semantic, - struct tgsi_header *header ); - -struct tgsi_full_declaration -tgsi_default_full_declaration( void ); - -unsigned -tgsi_build_full_declaration( - const struct tgsi_full_declaration *full_decl, - struct tgsi_token *tokens, - struct tgsi_header *header, - unsigned maxsize ); - -struct tgsi_declaration_range -tgsi_build_declaration_range( - unsigned first, - unsigned last, - struct tgsi_declaration *declaration, - struct tgsi_header *header ); - -struct tgsi_declaration_mask -tgsi_build_declaration_mask( - unsigned mask, - struct tgsi_declaration *declaration, - struct tgsi_header *header ); - -struct tgsi_declaration_interpolation -tgsi_default_declaration_interpolation( void ); - -struct tgsi_declaration_interpolation -tgsi_build_declaration_interpolation( - unsigned interpolate, - struct tgsi_declaration *declaration, - struct tgsi_header *header ); - -struct tgsi_declaration_semantic -tgsi_default_declaration_semantic( void ); - -struct tgsi_declaration_semantic -tgsi_build_declaration_semantic( - unsigned semantic_name, - unsigned semantic_index, - struct tgsi_declaration *declaration, - struct tgsi_header *header ); - -/* - * immediate - */ - -struct tgsi_immediate -tgsi_default_immediate( void ); - -struct tgsi_immediate -tgsi_build_immediate( - struct tgsi_header *header ); - -struct tgsi_full_immediate -tgsi_default_full_immediate( void ); - -struct tgsi_immediate_float32 -tgsi_build_immediate_float32( - float value, - struct tgsi_immediate *immediate, - struct tgsi_header *header ); - -unsigned -tgsi_build_full_immediate( - const struct tgsi_full_immediate *full_imm, - struct tgsi_token *tokens, - struct tgsi_header *header, - unsigned maxsize ); - -/* - * instruction - */ - -struct tgsi_instruction -tgsi_default_instruction( void ); - -struct tgsi_instruction -tgsi_build_instruction( - unsigned opcode, - unsigned saturate, - unsigned num_dst_regs, - unsigned num_src_regs, - struct tgsi_header *header ); - -struct tgsi_full_instruction -tgsi_default_full_instruction( void ); - -unsigned -tgsi_build_full_instruction( - const struct tgsi_full_instruction *full_inst, - struct tgsi_token *tokens, - struct tgsi_header *header, - unsigned maxsize ); - -struct tgsi_instruction_ext_nv -tgsi_default_instruction_ext_nv( void ); - -unsigned -tgsi_compare_instruction_ext_nv( - struct tgsi_instruction_ext_nv a, - struct tgsi_instruction_ext_nv b ); - -struct tgsi_instruction_ext_nv -tgsi_build_instruction_ext_nv( - unsigned precision, - unsigned cond_dst_index, - unsigned cond_flow_index, - unsigned cond_mask, - unsigned cond_swizzle_x, - unsigned cond_swizzle_y, - unsigned cond_swizzle_z, - unsigned cond_swizzle_w, - unsigned cond_dst_update, - unsigned cond_flow_update, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_instruction_ext_label -tgsi_default_instruction_ext_label( void ); - -unsigned -tgsi_compare_instruction_ext_label( - struct tgsi_instruction_ext_label a, - struct tgsi_instruction_ext_label b ); - -struct tgsi_instruction_ext_label -tgsi_build_instruction_ext_label( - unsigned label, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_instruction_ext_texture -tgsi_default_instruction_ext_texture( void ); - -unsigned -tgsi_compare_instruction_ext_texture( - struct tgsi_instruction_ext_texture a, - struct tgsi_instruction_ext_texture b ); - -struct tgsi_instruction_ext_texture -tgsi_build_instruction_ext_texture( - unsigned texture, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_src_register -tgsi_default_src_register( void ); - -struct tgsi_src_register -tgsi_build_src_register( - unsigned file, - unsigned swizzle_x, - unsigned swizzle_y, - unsigned swizzle_z, - unsigned swizzle_w, - unsigned negate, - unsigned indirect, - unsigned dimension, - int index, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_full_src_register -tgsi_default_full_src_register( void ); - -struct tgsi_src_register_ext_swz -tgsi_default_src_register_ext_swz( void ); - -unsigned -tgsi_compare_src_register_ext_swz( - struct tgsi_src_register_ext_swz a, - struct tgsi_src_register_ext_swz b ); - -struct tgsi_src_register_ext_swz -tgsi_build_src_register_ext_swz( - unsigned ext_swizzle_x, - unsigned ext_swizzle_y, - unsigned ext_swizzle_z, - unsigned ext_swizzle_w, - unsigned negate_x, - unsigned negate_y, - unsigned negate_z, - unsigned negate_w, - unsigned ext_divide, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_src_register_ext_mod -tgsi_default_src_register_ext_mod( void ); - -unsigned -tgsi_compare_src_register_ext_mod( - struct tgsi_src_register_ext_mod a, - struct tgsi_src_register_ext_mod b ); - -struct tgsi_src_register_ext_mod -tgsi_build_src_register_ext_mod( - unsigned complement, - unsigned bias, - unsigned scale_2x, - unsigned absolute, - unsigned negate, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_dimension -tgsi_default_dimension( void ); - -struct tgsi_dimension -tgsi_build_dimension( - unsigned indirect, - unsigned index, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_dst_register -tgsi_default_dst_register( void ); - -struct tgsi_dst_register -tgsi_build_dst_register( - unsigned file, - unsigned mask, - int index, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_full_dst_register -tgsi_default_full_dst_register( void ); - -struct tgsi_dst_register_ext_concode -tgsi_default_dst_register_ext_concode( void ); - -unsigned -tgsi_compare_dst_register_ext_concode( - struct tgsi_dst_register_ext_concode a, - struct tgsi_dst_register_ext_concode b ); - -struct tgsi_dst_register_ext_concode -tgsi_build_dst_register_ext_concode( - unsigned cc, - unsigned swizzle_x, - unsigned swizzle_y, - unsigned swizzle_z, - unsigned swizzle_w, - int index, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -struct tgsi_dst_register_ext_modulate -tgsi_default_dst_register_ext_modulate( void ); - -unsigned -tgsi_compare_dst_register_ext_modulate( - struct tgsi_dst_register_ext_modulate a, - struct tgsi_dst_register_ext_modulate b ); - -struct tgsi_dst_register_ext_modulate -tgsi_build_dst_register_ext_modulate( - unsigned modulate, - struct tgsi_token *prev_token, - struct tgsi_instruction *instruction, - struct tgsi_header *header ); - -#if defined __cplusplus -} // extern "C" -#endif // defined __cplusplus - -#endif // !defined TGSI_BUILD_H - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_core.h b/src/mesa/pipe/tgsi/exec/tgsi_core.h deleted file mode 100644 index 30ad801b6eb..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_core.h +++ /dev/null @@ -1,13 +0,0 @@ -#if !defined TGSI_CORE_H -#define TGSI_CORE_H - -#include "tgsi_token.h" -#include "tgsi_parse.h" -#include "tgsi_build.h" -#include "tgsi_exec.h" -#include "tgsi_dump.h" -#include "tgsi_util.h" -#include "tgsi_sse2.h" - -#endif // !defined TGSI_CORE_H - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_dump.c b/src/mesa/pipe/tgsi/exec/tgsi_dump.c deleted file mode 100644 index 1df71efff71..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_dump.c +++ /dev/null @@ -1,1456 +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. - * - **************************************************************************/ - -#include "tgsi_platform.h" -#include "tgsi_core.h" - -struct text_dump -{ - FILE *file; - unsigned tabs; -}; - -static void -text_dump_str( - struct text_dump *dump, - const char *str ) -{ - unsigned i; - size_t len = strlen( str ); - - for( i = 0; i < len; i++ ) { - fprintf( dump->file, "%c", str[i] ); - - if( str[i] == '\n' ) { - unsigned i; - - for( i = 0; i < dump->tabs; i++ ) { - fprintf( dump->file, " " ); - } - } - } -} - -static void -text_dump_chr( - struct text_dump *dump, - const char chr ) -{ - char str[2]; - - str[0] = chr; - str[1] = '\0'; - text_dump_str( dump, str ); -} - -static void -text_dump_uix( - struct text_dump *dump, - const unsigned ui ) -{ - char str[36]; - - sprintf( str, "0x%x", ui ); - text_dump_str( dump, str ); -} - -static void -text_dump_uid( - struct text_dump *dump, - const unsigned ui ) -{ - char str[16]; - - sprintf( str, "%u", ui ); - text_dump_str( dump, str ); -} - -static void -text_dump_sid( - struct text_dump *dump, - const int si ) -{ - char str[16]; - - sprintf( str, "%d", si ); - text_dump_str( dump, str ); -} - -static void -text_dump_flt( - struct text_dump *dump, - const float f ) -{ - char str[48]; - - sprintf( str, "%10.4f", f ); - text_dump_str( dump, str ); -} - -static void -text_dump_enum( - struct text_dump *dump, - const unsigned e, - const char **enums, - const unsigned enums_count ) -{ - if( e >= enums_count ) { - text_dump_uid( dump, e ); - } - else { - text_dump_str( dump, enums[e] ); - } -} - -static void -text_dump_tab( - struct text_dump *dump ) -{ - dump->tabs++; -} - -static void -text_dump_untab( - struct text_dump *dump ) -{ - assert( dump->tabs > 0 ); - - --dump->tabs; -} - -#define TXT(S) text_dump_str( dump, S ) -#define CHR(C) text_dump_chr( dump, C ) -#define UIX(I) text_dump_uix( dump, I ) -#define UID(I) text_dump_uid( dump, I ) -#define SID(I) text_dump_sid( dump, I ) -#define FLT(F) text_dump_flt( dump, F ) -#define TAB() text_dump_tab( dump ) -#define UNT() text_dump_untab( dump ) -#define ENM(E,ENUMS) text_dump_enum( dump, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) ) - -static const char *TGSI_PROCESSOR_TYPES[] = -{ - "PROCESSOR_FRAGMENT", - "PROCESSOR_VERTEX", - "PROCESSOR_GEOMETRY" -}; - -static const char *TGSI_PROCESSOR_TYPES_SHORT[] = -{ - "FRAG", - "VERT", - "GEOM" -}; - -static const char *TGSI_TOKEN_TYPES[] = -{ - "TOKEN_TYPE_DECLARATION", - "TOKEN_TYPE_IMMEDIATE", - "TOKEN_TYPE_INSTRUCTION" -}; - -static const char *TGSI_FILES[] = -{ - "FILE_NULL", - "FILE_CONSTANT", - "FILE_INPUT", - "FILE_OUTPUT", - "FILE_TEMPORARY", - "FILE_SAMPLER", - "FILE_ADDRESS", - "FILE_IMMEDIATE" -}; - -static const char *TGSI_FILES_SHORT[] = -{ - "NULL", - "CONST", - "IN", - "OUT", - "TEMP", - "SAMP", - "ADDR", - "IMM" -}; - -static const char *TGSI_DECLARES[] = -{ - "DECLARE_RANGE", - "DECLARE_MASK" -}; - -static const char *TGSI_INTERPOLATES[] = -{ - "INTERPOLATE_CONSTANT", - "INTERPOLATE_LINEAR", - "INTERPOLATE_PERSPECTIVE", - "INTERPOLATE_ATTRIB" -}; - -static const char *TGSI_INTERPOLATES_SHORT[] = -{ - "CONSTANT", - "LINEAR", - "PERSPECTIVE", - "ATTRIB" -}; - -static const char *TGSI_SEMANTICS[] = -{ - "SEMANTIC_POSITION", - "SEMANTIC_COLOR", - "SEMANTIC_BCOLOR", - "SEMANTIC_FOG", - "SEMANTIC_PSIZE", - "SEMANTIC_GENERIC," -}; - -static const char *TGSI_SEMANTICS_SHORT[] = -{ - "POSITION", - "COLOR", - "BCOLOR", - "FOG", - "PSIZE", - "GENERIC", -}; - -static const char *TGSI_IMMS[] = -{ - "IMM_FLOAT32" -}; - -static const char *TGSI_IMMS_SHORT[] = -{ - "FLT32" -}; - -static const char *TGSI_OPCODES[] = -{ - "OPCODE_ARL", - "OPCODE_MOV", - "OPCODE_LIT", - "OPCODE_RCP", - "OPCODE_RSQ", - "OPCODE_EXP", - "OPCODE_LOG", - "OPCODE_MUL", - "OPCODE_ADD", - "OPCODE_DP3", - "OPCODE_DP4", - "OPCODE_DST", - "OPCODE_MIN", - "OPCODE_MAX", - "OPCODE_SLT", - "OPCODE_SGE", - "OPCODE_MAD", - "OPCODE_SUB", - "OPCODE_LERP", - "OPCODE_CND", - "OPCODE_CND0", - "OPCODE_DOT2ADD", - "OPCODE_INDEX", - "OPCODE_NEGATE", - "OPCODE_FRAC", - "OPCODE_CLAMP", - "OPCODE_FLOOR", - "OPCODE_ROUND", - "OPCODE_EXPBASE2", - "OPCODE_LOGBASE2", - "OPCODE_POWER", - "OPCODE_CROSSPRODUCT", - "OPCODE_MULTIPLYMATRIX", - "OPCODE_ABS", - "OPCODE_RCC", - "OPCODE_DPH", - "OPCODE_COS", - "OPCODE_DDX", - "OPCODE_DDY", - "OPCODE_KILP", - "OPCODE_PK2H", - "OPCODE_PK2US", - "OPCODE_PK4B", - "OPCODE_PK4UB", - "OPCODE_RFL", - "OPCODE_SEQ", - "OPCODE_SFL", - "OPCODE_SGT", - "OPCODE_SIN", - "OPCODE_SLE", - "OPCODE_SNE", - "OPCODE_STR", - "OPCODE_TEX", - "OPCODE_TXD", - "OPCODE_UP2H", - "OPCODE_UP2US", - "OPCODE_UP4B", - "OPCODE_UP4UB", - "OPCODE_X2D", - "OPCODE_ARA", - "OPCODE_ARR", - "OPCODE_BRA", - "OPCODE_CAL", - "OPCODE_RET", - "OPCODE_SSG", - "OPCODE_CMP", - "OPCODE_SCS", - "OPCODE_TXB", - "OPCODE_NRM", - "OPCODE_DIV", - "OPCODE_DP2", - "OPCODE_TXL", - "OPCODE_BRK", - "OPCODE_IF", - "OPCODE_LOOP", - "OPCODE_REP", - "OPCODE_ELSE", - "OPCODE_ENDIF", - "OPCODE_ENDLOOP", - "OPCODE_ENDREP", - "OPCODE_PUSHA", - "OPCODE_POPA", - "OPCODE_CEIL", - "OPCODE_I2F", - "OPCODE_NOT", - "OPCODE_TRUNC", - "OPCODE_SHL", - "OPCODE_SHR", - "OPCODE_AND", - "OPCODE_OR", - "OPCODE_MOD", - "OPCODE_XOR", - "OPCODE_SAD", - "OPCODE_TXF", - "OPCODE_TXQ", - "OPCODE_CONT", - "OPCODE_EMIT", - "OPCODE_ENDPRIM", - "OPCODE_BGNLOOP2", - "OPCODE_BGNSUB", - "OPCODE_ENDLOOP2", - "OPCODE_ENDSUB", - "OPCODE_NOISE1", - "OPCODE_NOISE2", - "OPCODE_NOISE3", - "OPCODE_NOISE4", - "OPCODE_NOP", - "OPCODE_TEXBEM", - "OPCODE_TEXBEML", - "OPCODE_TEXREG2AR", - "OPCODE_TEXM3X2PAD", - "OPCODE_TEXM3X2TEX", - "OPCODE_TEXM3X3PAD", - "OPCODE_TEXM3X3TEX", - "OPCODE_TEXM3X3SPEC", - "OPCODE_TEXM3X3VSPEC", - "OPCODE_TEXREG2GB", - "OPCODE_TEXREG2RGB", - "OPCODE_TEXDP3TEX", - "OPCODE_TEXDP3", - "OPCODE_TEXM3X3", - "OPCODE_TEXM3X2DEPTH", - "OPCODE_TEXDEPTH", - "OPCODE_BEM", - "OPCODE_M4X3", - "OPCODE_M3X4", - "OPCODE_M3X3", - "OPCODE_M3X2", - "OPCODE_NRM4", - "OPCODE_CALLNZ", - "OPCODE_IFC", - "OPCODE_BREAKC", - "OPCODE_TXP", - "OPCODE_KIL", - "OPCODE_END" -}; - -static const char *TGSI_OPCODES_SHORT[] = -{ - "ARL", - "MOV", - "LIT", - "RCP", - "RSQ", - "EXP", - "LOG", - "MUL", - "ADD", - "DP3", - "DP4", - "DST", - "MIN", - "MAX", - "SLT", - "SGE", - "MAD", - "SUB", - "LERP", - "CND", - "CND0", - "DOT2ADD", - "INDEX", - "NEGATE", - "FRAC", - "CLAMP", - "FLOOR", - "ROUND", - "EXPBASE2", - "LOGBASE2", - "POWER", - "CROSSPRODUCT", - "MULTIPLYMATRIX", - "ABS", - "RCC", - "DPH", - "COS", - "DDX", - "DDY", - "KILP", - "PK2H", - "PK2US", - "PK4B", - "PK4UB", - "RFL", - "SEQ", - "SFL", - "SGT", - "SIN", - "SLE", - "SNE", - "STR", - "TEX", - "TXD", - "UP2H", - "UP2US", - "UP4B", - "UP4UB", - "X2D", - "ARA", - "ARR", - "BRA", - "CAL", - "RET", - "SSG", - "CMP", - "SCS", - "TXB", - "NRM", - "DIV", - "DP2", - "TXL", - "BRK", - "IF", - "LOOP", - "REP", - "ELSE", - "ENDIF", - "ENDLOOP", - "ENDREP", - "PUSHA", - "POPA", - "CEIL", - "I2F", - "NOT", - "TRUNC", - "SHL", - "SHR", - "AND", - "OR", - "MOD", - "XOR", - "SAD", - "TXF", - "TXQ", - "CONT", - "EMIT", - "ENDPRIM", - "BGNLOOP2", - "BGNSUB", - "ENDLOOP2", - "ENDSUB", - "NOISE1", - "NOISE2", - "NOISE3", - "NOISE4", - "NOP", - "TEXBEM", - "TEXBEML", - "TEXREG2AR", - "TEXM3X2PAD", - "TEXM3X2TEX", - "TEXM3X3PAD", - "TEXM3X3TEX", - "TEXM3X3SPEC", - "TEXM3X3VSPEC", - "TEXREG2GB", - "TEXREG2RGB", - "TEXDP3TEX", - "TEXDP3", - "TEXM3X3", - "TEXM3X2DEPTH", - "TEXDEPTH", - "BEM", - "M4X3", - "M3X4", - "M3X3", - "M3X2", - "NRM4", - "CALLNZ", - "IFC", - "BREAKC", - "TXP", - "KIL", - "END" -}; - -static const char *TGSI_SATS[] = -{ - "SAT_NONE", - "SAT_ZERO_ONE", - "SAT_MINUS_PLUS_ONE" -}; - -static const char *TGSI_INSTRUCTION_EXTS[] = -{ - "INSTRUCTION_EXT_TYPE_NV", - "INSTRUCTION_EXT_TYPE_LABEL", - "INSTRUCTION_EXT_TYPE_TEXTURE" -}; - -static const char *TGSI_PRECISIONS[] = -{ - "PRECISION_DEFAULT", - "TGSI_PRECISION_FLOAT32", - "TGSI_PRECISION_FLOAT16", - "TGSI_PRECISION_FIXED12" -}; - -static const char *TGSI_CCS[] = -{ - "CC_GT", - "CC_EQ", - "CC_LT", - "CC_UN", - "CC_GE", - "CC_LE", - "CC_NE", - "CC_TR", - "CC_FL" -}; - -static const char *TGSI_SWIZZLES[] = -{ - "SWIZZLE_X", - "SWIZZLE_Y", - "SWIZZLE_Z", - "SWIZZLE_W" -}; - -static const char *TGSI_SWIZZLES_SHORT[] = -{ - "x", - "y", - "z", - "w" -}; - -static const char *TGSI_TEXTURES[] = -{ - "TEXTURE_UNKNOWN", - "TEXTURE_1D", - "TEXTURE_2D", - "TEXTURE_3D", - "TEXTURE_CUBE", - "TEXTURE_RECT", - "TEXTURE_SHADOW1D", - "TEXTURE_SHADOW2D", - "TEXTURE_SHADOWRECT" -}; - -static const char *TGSI_SRC_REGISTER_EXTS[] = -{ - "SRC_REGISTER_EXT_TYPE_SWZ", - "SRC_REGISTER_EXT_TYPE_MOD" -}; - -static const char *TGSI_EXTSWIZZLES[] = -{ - "EXTSWIZZLE_X", - "EXTSWIZZLE_Y", - "EXTSWIZZLE_Z", - "EXTSWIZZLE_W", - "EXTSWIZZLE_ZERO", - "EXTSWIZZLE_ONE" -}; - -static const char *TGSI_EXTSWIZZLES_SHORT[] = -{ - "x", - "y", - "z", - "w", - "0", - "1" -}; - -static const char *TGSI_WRITEMASKS[] = -{ - "0", - "WRITEMASK_X", - "WRITEMASK_Y", - "WRITEMASK_XY", - "WRITEMASK_Z", - "WRITEMASK_XZ", - "WRITEMASK_YZ", - "WRITEMASK_XYZ", - "WRITEMASK_W", - "WRITEMASK_XW", - "WRITEMASK_YW", - "WRITEMASK_XYW", - "WRITEMASK_ZW", - "WRITEMASK_XZW", - "WRITEMASK_YZW", - "WRITEMASK_XYZW" -}; - -static const char *TGSI_DST_REGISTER_EXTS[] = -{ - "DST_REGISTER_EXT_TYPE_CONDCODE", - "DST_REGISTER_EXT_TYPE_MODULATE" -}; - -static const char *TGSI_MODULATES[] = -{ - "MODULATE_1X", - "MODULATE_2X", - "MODULATE_4X", - "MODULATE_8X", - "MODULATE_HALF", - "MODULATE_QUARTER", - "MODULATE_EIGHTH" -}; - -static void -dump_declaration_short( - struct text_dump *dump, - struct tgsi_full_declaration *decl ) -{ - TXT( "\nDCL " ); - ENM( decl->Declaration.File, TGSI_FILES_SHORT ); - - switch( decl->Declaration.Declare ) { - case TGSI_DECLARE_RANGE: - CHR( '[' ); - UID( decl->u.DeclarationRange.First ); - if( decl->u.DeclarationRange.First != decl->u.DeclarationRange.Last ) { - TXT( ".." ); - UID( decl->u.DeclarationRange.Last ); - } - CHR( ']' ); - break; - default: - assert( 0 ); - } - - if( decl->Declaration.UsageMask != TGSI_WRITEMASK_XYZW ) { - CHR( '.' ); - if( decl->Declaration.UsageMask & TGSI_WRITEMASK_X ) { - CHR( 'x' ); - } - if( decl->Declaration.UsageMask & TGSI_WRITEMASK_Y ) { - CHR( 'y' ); - } - if( decl->Declaration.UsageMask & TGSI_WRITEMASK_Z ) { - CHR( 'z' ); - } - if( decl->Declaration.UsageMask & TGSI_WRITEMASK_W ) { - CHR( 'w' ); - } - } - - if( decl->Declaration.Interpolate ) { - TXT( ", " ); - ENM( decl->Interpolation.Interpolate, TGSI_INTERPOLATES_SHORT ); - } - - if( decl->Declaration.Semantic ) { - TXT( ", " ); - ENM( decl->Semantic.SemanticName, TGSI_SEMANTICS_SHORT ); - CHR( '[' ); - UID( decl->Semantic.SemanticIndex ); - CHR( ']' ); - } -} - -static void -dump_declaration_verbose( - struct text_dump *dump, - struct tgsi_full_declaration *decl, - unsigned ignored, - unsigned deflt, - struct tgsi_full_declaration *fd ) -{ - TXT( "\nFile : " ); - ENM( decl->Declaration.File, TGSI_FILES ); - TXT( "\nDeclare : " ); - ENM( decl->Declaration.Declare, TGSI_DECLARES ); - if( deflt || fd->Declaration.UsageMask != decl->Declaration.UsageMask ) { - TXT( "\nUsageMask : " ); - if( decl->Declaration.UsageMask & TGSI_WRITEMASK_X ) { - CHR( 'X' ); - } - if( decl->Declaration.UsageMask & TGSI_WRITEMASK_Y ) { - CHR( 'Y' ); - } - if( decl->Declaration.UsageMask & TGSI_WRITEMASK_Z ) { - CHR( 'Z' ); - } - if( decl->Declaration.UsageMask & TGSI_WRITEMASK_W ) { - CHR( 'W' ); - } - } - if( deflt || fd->Declaration.Interpolate != decl->Declaration.Interpolate ) { - TXT( "\nInterpolate: " ); - UID( decl->Declaration.Interpolate ); - } - if( deflt || fd->Declaration.Semantic != decl->Declaration.Semantic ) { - TXT( "\nSemantic : " ); - UID( decl->Declaration.Semantic ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( decl->Declaration.Padding ); - } - - CHR( '\n' ); - switch( decl->Declaration.Declare ) { - case TGSI_DECLARE_RANGE: - TXT( "\nFirst: " ); - UID( decl->u.DeclarationRange.First ); - TXT( "\nLast : " ); - UID( decl->u.DeclarationRange.Last ); - break; - - case TGSI_DECLARE_MASK: - TXT( "\nMask: " ); - UIX( decl->u.DeclarationMask.Mask ); - break; - - default: - assert( 0 ); - } - - if( decl->Declaration.Interpolate ) { - CHR( '\n' ); - TXT( "\nInterpolate: " ); - ENM( decl->Interpolation.Interpolate, TGSI_INTERPOLATES ); - if( ignored ) { - TXT( "\nPadding : " ); - UIX( decl->Interpolation.Padding ); - } - } - - if( decl->Declaration.Semantic ) { - CHR( '\n' ); - TXT( "\nSemanticName : " ); - ENM( decl->Semantic.SemanticName, TGSI_SEMANTICS ); - TXT( "\nSemanticIndex: " ); - UID( decl->Semantic.SemanticIndex ); - if( ignored ) { - TXT( "\nPadding : " ); - UIX( decl->Semantic.Padding ); - } - } -} - -static void -dump_immediate_short( - struct text_dump *dump, - struct tgsi_full_immediate *imm ) -{ - unsigned i; - - TXT( "\nIMM " ); - ENM( imm->Immediate.DataType, TGSI_IMMS_SHORT ); - - TXT( " { " ); - for( i = 0; i < imm->Immediate.Size - 1; i++ ) { - switch( imm->Immediate.DataType ) { - case TGSI_IMM_FLOAT32: - FLT( imm->u.ImmediateFloat32[i].Float ); - break; - - default: - assert( 0 ); - } - - if( i < imm->Immediate.Size - 2 ) { - TXT( ", " ); - } - } - TXT( " }" ); -} - -static void -dump_immediate_verbose( - struct text_dump *dump, - struct tgsi_full_immediate *imm, - unsigned ignored ) -{ - unsigned i; - - TXT( "\nDataType : " ); - ENM( imm->Immediate.DataType, TGSI_IMMS ); - if( ignored ) { - TXT( "\nPadding : " ); - UIX( imm->Immediate.Padding ); - } - - for( i = 0; i < imm->Immediate.Size - 1; i++ ) { - CHR( '\n' ); - switch( imm->Immediate.DataType ) { - case TGSI_IMM_FLOAT32: - TXT( "\nFloat: " ); - FLT( imm->u.ImmediateFloat32[i].Float ); - break; - - default: - assert( 0 ); - } - } -} - -static void -dump_instruction_short( - struct text_dump *dump, - struct tgsi_full_instruction *inst, - unsigned instno ) -{ - unsigned i; - boolean first_reg = TRUE; - - CHR( '\n' ); - UID( instno ); - CHR( ':' ); - ENM( inst->Instruction.Opcode, TGSI_OPCODES_SHORT ); - - switch( inst->Instruction.Saturate ) { - case TGSI_SAT_NONE: - break; - case TGSI_SAT_ZERO_ONE: - TXT( "_SAT" ); - break; - case TGSI_SAT_MINUS_PLUS_ONE: - TXT( "_SAT[-1,1]" ); - break; - default: - assert( 0 ); - } - - for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) { - struct tgsi_full_dst_register *dst = &inst->FullDstRegisters[i]; - - if( !first_reg ) { - CHR( ',' ); - } - CHR( ' ' ); - - ENM( dst->DstRegister.File, TGSI_FILES_SHORT ); - - CHR( '[' ); - SID( dst->DstRegister.Index ); - CHR( ']' ); - - if( dst->DstRegister.WriteMask != TGSI_WRITEMASK_XYZW ) { - CHR( '.' ); - if( dst->DstRegister.WriteMask & TGSI_WRITEMASK_X ) { - CHR( 'x' ); - } - if( dst->DstRegister.WriteMask & TGSI_WRITEMASK_Y ) { - CHR( 'y' ); - } - if( dst->DstRegister.WriteMask & TGSI_WRITEMASK_Z ) { - CHR( 'z' ); - } - if( dst->DstRegister.WriteMask & TGSI_WRITEMASK_W ) { - CHR( 'w' ); - } - } - - first_reg = FALSE; - } - - for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) { - struct tgsi_full_src_register *src = &inst->FullSrcRegisters[i]; - - if( !first_reg ) { - CHR( ',' ); - } - CHR( ' ' ); - - if( src->SrcRegisterExtMod.Negate ) { - CHR( '-' ); - } - if( src->SrcRegisterExtMod.Absolute ) { - CHR( '|' ); - } - if( src->SrcRegister.Negate ) { - CHR( '-' ); - } - - ENM( src->SrcRegister.File, TGSI_FILES_SHORT ); - - CHR( '[' ); - SID( src->SrcRegister.Index ); - CHR( ']' ); - - if (src->SrcRegister.Extended) { - if (src->SrcRegisterExtSwz.ExtSwizzleX != TGSI_EXTSWIZZLE_X || - src->SrcRegisterExtSwz.ExtSwizzleY != TGSI_EXTSWIZZLE_Y || - src->SrcRegisterExtSwz.ExtSwizzleZ != TGSI_EXTSWIZZLE_Z || - src->SrcRegisterExtSwz.ExtSwizzleW != TGSI_EXTSWIZZLE_W) { - CHR( '.' ); - ENM( src->SrcRegisterExtSwz.ExtSwizzleX, TGSI_EXTSWIZZLES_SHORT ); - ENM( src->SrcRegisterExtSwz.ExtSwizzleY, TGSI_EXTSWIZZLES_SHORT ); - ENM( src->SrcRegisterExtSwz.ExtSwizzleZ, TGSI_EXTSWIZZLES_SHORT ); - ENM( src->SrcRegisterExtSwz.ExtSwizzleW, TGSI_EXTSWIZZLES_SHORT ); - } - } - else if( src->SrcRegister.SwizzleX != TGSI_SWIZZLE_X || - src->SrcRegister.SwizzleY != TGSI_SWIZZLE_Y || - src->SrcRegister.SwizzleZ != TGSI_SWIZZLE_Z || - src->SrcRegister.SwizzleW != TGSI_SWIZZLE_W ) { - CHR( '.' ); - ENM( src->SrcRegister.SwizzleX, TGSI_SWIZZLES_SHORT ); - ENM( src->SrcRegister.SwizzleY, TGSI_SWIZZLES_SHORT ); - ENM( src->SrcRegister.SwizzleZ, TGSI_SWIZZLES_SHORT ); - ENM( src->SrcRegister.SwizzleW, TGSI_SWIZZLES_SHORT ); - } - - if( src->SrcRegisterExtMod.Absolute ) { - CHR( '|' ); - } - - first_reg = FALSE; - } - - switch( inst->Instruction.Opcode ) { - case TGSI_OPCODE_IF: - case TGSI_OPCODE_ELSE: - case TGSI_OPCODE_BGNLOOP2: - case TGSI_OPCODE_ENDLOOP2: - case TGSI_OPCODE_CAL: - TXT( " :" ); - UID( inst->InstructionExtLabel.Label ); - break; - } -} - -static void -dump_instruction_verbose( - struct text_dump *dump, - struct tgsi_full_instruction *inst, - unsigned ignored, - unsigned deflt, - struct tgsi_full_instruction *fi ) -{ - unsigned i; - - TXT( "\nOpcode : " ); - ENM( inst->Instruction.Opcode, TGSI_OPCODES ); - if( deflt || fi->Instruction.Saturate != inst->Instruction.Saturate ) { - TXT( "\nSaturate : " ); - ENM( inst->Instruction.Saturate, TGSI_SATS ); - } - if( deflt || fi->Instruction.NumDstRegs != inst->Instruction.NumDstRegs ) { - TXT( "\nNumDstRegs : " ); - UID( inst->Instruction.NumDstRegs ); - } - if( deflt || fi->Instruction.NumSrcRegs != inst->Instruction.NumSrcRegs ) { - TXT( "\nNumSrcRegs : " ); - UID( inst->Instruction.NumSrcRegs ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( inst->Instruction.Padding ); - } - - if( deflt || tgsi_compare_instruction_ext_nv( inst->InstructionExtNv, fi->InstructionExtNv ) ) { - CHR( '\n' ); - TXT( "\nType : " ); - ENM( inst->InstructionExtNv.Type, TGSI_INSTRUCTION_EXTS ); - if( deflt || fi->InstructionExtNv.Precision != inst->InstructionExtNv.Precision ) { - TXT( "\nPrecision : " ); - ENM( inst->InstructionExtNv.Precision, TGSI_PRECISIONS ); - } - if( deflt || fi->InstructionExtNv.CondDstIndex != inst->InstructionExtNv.CondDstIndex ) { - TXT( "\nCondDstIndex : " ); - UID( inst->InstructionExtNv.CondDstIndex ); - } - if( deflt || fi->InstructionExtNv.CondFlowIndex != inst->InstructionExtNv.CondFlowIndex ) { - TXT( "\nCondFlowIndex : " ); - UID( inst->InstructionExtNv.CondFlowIndex ); - } - if( deflt || fi->InstructionExtNv.CondMask != inst->InstructionExtNv.CondMask ) { - TXT( "\nCondMask : " ); - ENM( inst->InstructionExtNv.CondMask, TGSI_CCS ); - } - if( deflt || fi->InstructionExtNv.CondSwizzleX != inst->InstructionExtNv.CondSwizzleX ) { - TXT( "\nCondSwizzleX : " ); - ENM( inst->InstructionExtNv.CondSwizzleX, TGSI_SWIZZLES ); - } - if( deflt || fi->InstructionExtNv.CondSwizzleY != inst->InstructionExtNv.CondSwizzleY ) { - TXT( "\nCondSwizzleY : " ); - ENM( inst->InstructionExtNv.CondSwizzleY, TGSI_SWIZZLES ); - } - if( deflt || fi->InstructionExtNv.CondSwizzleZ != inst->InstructionExtNv.CondSwizzleZ ) { - TXT( "\nCondSwizzleZ : " ); - ENM( inst->InstructionExtNv.CondSwizzleZ, TGSI_SWIZZLES ); - } - if( deflt || fi->InstructionExtNv.CondSwizzleW != inst->InstructionExtNv.CondSwizzleW ) { - TXT( "\nCondSwizzleW : " ); - ENM( inst->InstructionExtNv.CondSwizzleW, TGSI_SWIZZLES ); - } - if( deflt || fi->InstructionExtNv.CondDstUpdate != inst->InstructionExtNv.CondDstUpdate ) { - TXT( "\nCondDstUpdate : " ); - UID( inst->InstructionExtNv.CondDstUpdate ); - } - if( deflt || fi->InstructionExtNv.CondFlowEnable != inst->InstructionExtNv.CondFlowEnable ) { - TXT( "\nCondFlowEnable: " ); - UID( inst->InstructionExtNv.CondFlowEnable ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( inst->InstructionExtNv.Padding ); - if( deflt || fi->InstructionExtNv.Extended != inst->InstructionExtNv.Extended ) { - TXT( "\nExtended : " ); - UID( inst->InstructionExtNv.Extended ); - } - } - } - - if( deflt || tgsi_compare_instruction_ext_label( inst->InstructionExtLabel, fi->InstructionExtLabel ) ) { - CHR( '\n' ); - TXT( "\nType : " ); - ENM( inst->InstructionExtLabel.Type, TGSI_INSTRUCTION_EXTS ); - if( deflt || fi->InstructionExtLabel.Label != inst->InstructionExtLabel.Label ) { - TXT( "\nLabel : " ); - UID( inst->InstructionExtLabel.Label ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( inst->InstructionExtLabel.Padding ); - if( deflt || fi->InstructionExtLabel.Extended != inst->InstructionExtLabel.Extended ) { - TXT( "\nExtended: " ); - UID( inst->InstructionExtLabel.Extended ); - } - } - } - - if( deflt || tgsi_compare_instruction_ext_texture( inst->InstructionExtTexture, fi->InstructionExtTexture ) ) { - CHR( '\n' ); - TXT( "\nType : " ); - ENM( inst->InstructionExtTexture.Type, TGSI_INSTRUCTION_EXTS ); - if( deflt || fi->InstructionExtTexture.Texture != inst->InstructionExtTexture.Texture ) { - TXT( "\nTexture : " ); - ENM( inst->InstructionExtTexture.Texture, TGSI_TEXTURES ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( inst->InstructionExtTexture.Padding ); - if( deflt || fi->InstructionExtTexture.Extended != inst->InstructionExtTexture.Extended ) { - TXT( "\nExtended: " ); - UID( inst->InstructionExtTexture.Extended ); - } - } - } - - for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) { - struct tgsi_full_dst_register *dst = &inst->FullDstRegisters[i]; - struct tgsi_full_dst_register *fd = &fi->FullDstRegisters[i]; - - CHR( '\n' ); - TXT( "\nFile : " ); - ENM( dst->DstRegister.File, TGSI_FILES ); - if( deflt || fd->DstRegister.WriteMask != dst->DstRegister.WriteMask ) { - TXT( "\nWriteMask: " ); - ENM( dst->DstRegister.WriteMask, TGSI_WRITEMASKS ); - } - if( ignored ) { - if( deflt || fd->DstRegister.Indirect != dst->DstRegister.Indirect ) { - TXT( "\nIndirect : " ); - UID( dst->DstRegister.Indirect ); - } - if( deflt || fd->DstRegister.Dimension != dst->DstRegister.Dimension ) { - TXT( "\nDimension: " ); - UID( dst->DstRegister.Dimension ); - } - } - if( deflt || fd->DstRegister.Index != dst->DstRegister.Index ) { - TXT( "\nIndex : " ); - SID( dst->DstRegister.Index ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( dst->DstRegister.Padding ); - if( deflt || fd->DstRegister.Extended != dst->DstRegister.Extended ) { - TXT( "\nExtended : " ); - UID( dst->DstRegister.Extended ); - } - } - - if( deflt || tgsi_compare_dst_register_ext_concode( dst->DstRegisterExtConcode, fd->DstRegisterExtConcode ) ) { - CHR( '\n' ); - TXT( "\nType : " ); - ENM( dst->DstRegisterExtConcode.Type, TGSI_DST_REGISTER_EXTS ); - if( deflt || fd->DstRegisterExtConcode.CondMask != dst->DstRegisterExtConcode.CondMask ) { - TXT( "\nCondMask : " ); - ENM( dst->DstRegisterExtConcode.CondMask, TGSI_CCS ); - } - if( deflt || fd->DstRegisterExtConcode.CondSwizzleX != dst->DstRegisterExtConcode.CondSwizzleX ) { - TXT( "\nCondSwizzleX: " ); - ENM( dst->DstRegisterExtConcode.CondSwizzleX, TGSI_SWIZZLES ); - } - if( deflt || fd->DstRegisterExtConcode.CondSwizzleY != dst->DstRegisterExtConcode.CondSwizzleY ) { - TXT( "\nCondSwizzleY: " ); - ENM( dst->DstRegisterExtConcode.CondSwizzleY, TGSI_SWIZZLES ); - } - if( deflt || fd->DstRegisterExtConcode.CondSwizzleZ != dst->DstRegisterExtConcode.CondSwizzleZ ) { - TXT( "\nCondSwizzleZ: " ); - ENM( dst->DstRegisterExtConcode.CondSwizzleZ, TGSI_SWIZZLES ); - } - if( deflt || fd->DstRegisterExtConcode.CondSwizzleW != dst->DstRegisterExtConcode.CondSwizzleW ) { - TXT( "\nCondSwizzleW: " ); - ENM( dst->DstRegisterExtConcode.CondSwizzleW, TGSI_SWIZZLES ); - } - if( deflt || fd->DstRegisterExtConcode.CondSrcIndex != dst->DstRegisterExtConcode.CondSrcIndex ) { - TXT( "\nCondSrcIndex: " ); - UID( dst->DstRegisterExtConcode.CondSrcIndex ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( dst->DstRegisterExtConcode.Padding ); - if( deflt || fd->DstRegisterExtConcode.Extended != dst->DstRegisterExtConcode.Extended ) { - TXT( "\nExtended : " ); - UID( dst->DstRegisterExtConcode.Extended ); - } - } - } - - if( deflt || tgsi_compare_dst_register_ext_modulate( dst->DstRegisterExtModulate, fd->DstRegisterExtModulate ) ) { - CHR( '\n' ); - TXT( "\nType : " ); - ENM( dst->DstRegisterExtModulate.Type, TGSI_DST_REGISTER_EXTS ); - if( deflt || fd->DstRegisterExtModulate.Modulate != dst->DstRegisterExtModulate.Modulate ) { - TXT( "\nModulate: " ); - ENM( dst->DstRegisterExtModulate.Modulate, TGSI_MODULATES ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( dst->DstRegisterExtModulate.Padding ); - if( deflt || fd->DstRegisterExtModulate.Extended != dst->DstRegisterExtModulate.Extended ) { - TXT( "\nExtended: " ); - UID( dst->DstRegisterExtModulate.Extended ); - } - } - } - } - - for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) { - struct tgsi_full_src_register *src = &inst->FullSrcRegisters[i]; - struct tgsi_full_src_register *fs = &fi->FullSrcRegisters[i]; - - CHR( '\n' ); - TXT( "\nFile : "); - ENM( src->SrcRegister.File, TGSI_FILES ); - if( deflt || fs->SrcRegister.SwizzleX != src->SrcRegister.SwizzleX ) { - TXT( "\nSwizzleX : " ); - ENM( src->SrcRegister.SwizzleX, TGSI_SWIZZLES ); - } - if( deflt || fs->SrcRegister.SwizzleY != src->SrcRegister.SwizzleY ) { - TXT( "\nSwizzleY : " ); - ENM( src->SrcRegister.SwizzleY, TGSI_SWIZZLES ); - } - if( deflt || fs->SrcRegister.SwizzleZ != src->SrcRegister.SwizzleZ ) { - TXT( "\nSwizzleZ : " ); - ENM( src->SrcRegister.SwizzleZ, TGSI_SWIZZLES ); - } - if( deflt || fs->SrcRegister.SwizzleW != src->SrcRegister.SwizzleW ) { - TXT( "\nSwizzleW : " ); - ENM( src->SrcRegister.SwizzleW, TGSI_SWIZZLES ); - } - if( deflt || fs->SrcRegister.Negate != src->SrcRegister.Negate ) { - TXT( "\nNegate : " ); - UID( src->SrcRegister.Negate ); - } - if( ignored ) { - if( deflt || fs->SrcRegister.Indirect != src->SrcRegister.Indirect ) { - TXT( "\nIndirect : " ); - UID( src->SrcRegister.Indirect ); - } - if( deflt || fs->SrcRegister.Dimension != src->SrcRegister.Dimension ) { - TXT( "\nDimension: " ); - UID( src->SrcRegister.Dimension ); - } - } - if( deflt || fs->SrcRegister.Index != src->SrcRegister.Index ) { - TXT( "\nIndex : " ); - SID( src->SrcRegister.Index ); - } - if( ignored ) { - if( deflt || fs->SrcRegister.Extended != src->SrcRegister.Extended ) { - TXT( "\nExtended : " ); - UID( src->SrcRegister.Extended ); - } - } - - if( deflt || tgsi_compare_src_register_ext_swz( src->SrcRegisterExtSwz, fs->SrcRegisterExtSwz ) ) { - CHR( '\n' ); - TXT( "\nType : " ); - ENM( src->SrcRegisterExtSwz.Type, TGSI_SRC_REGISTER_EXTS ); - if( deflt || fs->SrcRegisterExtSwz.ExtSwizzleX != src->SrcRegisterExtSwz.ExtSwizzleX ) { - TXT( "\nExtSwizzleX: " ); - ENM( src->SrcRegisterExtSwz.ExtSwizzleX, TGSI_EXTSWIZZLES ); - } - if( deflt || fs->SrcRegisterExtSwz.ExtSwizzleY != src->SrcRegisterExtSwz.ExtSwizzleY ) { - TXT( "\nExtSwizzleY: " ); - ENM( src->SrcRegisterExtSwz.ExtSwizzleY, TGSI_EXTSWIZZLES ); - } - if( deflt || fs->SrcRegisterExtSwz.ExtSwizzleZ != src->SrcRegisterExtSwz.ExtSwizzleZ ) { - TXT( "\nExtSwizzleZ: " ); - ENM( src->SrcRegisterExtSwz.ExtSwizzleZ, TGSI_EXTSWIZZLES ); - } - if( deflt || fs->SrcRegisterExtSwz.ExtSwizzleW != src->SrcRegisterExtSwz.ExtSwizzleW ) { - TXT( "\nExtSwizzleW: " ); - ENM( src->SrcRegisterExtSwz.ExtSwizzleW, TGSI_EXTSWIZZLES ); - } - if( deflt || fs->SrcRegisterExtSwz.NegateX != src->SrcRegisterExtSwz.NegateX ) { - TXT( "\nNegateX : " ); - UID( src->SrcRegisterExtSwz.NegateX ); - } - if( deflt || fs->SrcRegisterExtSwz.NegateY != src->SrcRegisterExtSwz.NegateY ) { - TXT( "\nNegateY : " ); - UID( src->SrcRegisterExtSwz.NegateY ); - } - if( deflt || fs->SrcRegisterExtSwz.NegateZ != src->SrcRegisterExtSwz.NegateZ ) { - TXT( "\nNegateZ : " ); - UID( src->SrcRegisterExtSwz.NegateZ ); - } - if( deflt || fs->SrcRegisterExtSwz.NegateW != src->SrcRegisterExtSwz.NegateW ) { - TXT( "\nNegateW : " ); - UID( src->SrcRegisterExtSwz.NegateW ); - } - if( deflt || fs->SrcRegisterExtSwz.ExtDivide != src->SrcRegisterExtSwz.ExtDivide ) { - TXT( "\nExtDivide : " ); - ENM( src->SrcRegisterExtSwz.ExtDivide, TGSI_EXTSWIZZLES ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( src->SrcRegisterExtSwz.Padding ); - if( deflt || fs->SrcRegisterExtSwz.Extended != src->SrcRegisterExtSwz.Extended ) { - TXT( "\nExtended : " ); - UID( src->SrcRegisterExtSwz.Extended ); - } - } - } - - if( deflt || tgsi_compare_src_register_ext_mod( src->SrcRegisterExtMod, fs->SrcRegisterExtMod ) ) { - CHR( '\n' ); - TXT( "\nType : " ); - ENM( src->SrcRegisterExtMod.Type, TGSI_SRC_REGISTER_EXTS ); - if( deflt || fs->SrcRegisterExtMod.Complement != src->SrcRegisterExtMod.Complement ) { - TXT( "\nComplement: " ); - UID( src->SrcRegisterExtMod.Complement ); - } - if( deflt || fs->SrcRegisterExtMod.Bias != src->SrcRegisterExtMod.Bias ) { - TXT( "\nBias : " ); - UID( src->SrcRegisterExtMod.Bias ); - } - if( deflt || fs->SrcRegisterExtMod.Scale2X != src->SrcRegisterExtMod.Scale2X ) { - TXT( "\nScale2X : " ); - UID( src->SrcRegisterExtMod.Scale2X ); - } - if( deflt || fs->SrcRegisterExtMod.Absolute != src->SrcRegisterExtMod.Absolute ) { - TXT( "\nAbsolute : " ); - UID( src->SrcRegisterExtMod.Absolute ); - } - if( deflt || fs->SrcRegisterExtMod.Negate != src->SrcRegisterExtMod.Negate ) { - TXT( "\nNegate : " ); - UID( src->SrcRegisterExtMod.Negate ); - } - if( ignored ) { - TXT( "\nPadding : " ); - UIX( src->SrcRegisterExtMod.Padding ); - if( deflt || fs->SrcRegisterExtMod.Extended != src->SrcRegisterExtMod.Extended ) { - TXT( "\nExtended : " ); - UID( src->SrcRegisterExtMod.Extended ); - } - } - } - } -} - -void -tgsi_dump( - const struct tgsi_token *tokens, - unsigned flags ) -{ - struct text_dump _dump; - struct text_dump *dump = &_dump; - struct tgsi_parse_context parse; - struct tgsi_full_instruction fi; - struct tgsi_full_declaration fd; - unsigned verbose = flags & TGSI_DUMP_VERBOSE; - unsigned ignored = !(flags & TGSI_DUMP_NO_IGNORED); - unsigned deflt = !(flags & TGSI_DUMP_NO_DEFAULT); - unsigned instno = 0; - - { -#if 0 - static unsigned counter = 0; - char buffer[64]; - - sprintf( buffer, "tgsi-dump-%.4u.txt", counter++ ); - dump->file = fopen( buffer, "wt" ); -#else - dump->file = stderr; -#endif - dump->tabs = 0; - } - - /* sanity check */ - assert(strcmp(TGSI_OPCODES[TGSI_OPCODE_CONT], "OPCODE_CONT") == 0); - - tgsi_parse_init( &parse, tokens ); - - TXT( "tgsi-dump begin -----------------" ); - - CHR( '\n' ); - ENM( parse.FullHeader.Processor.Processor, TGSI_PROCESSOR_TYPES_SHORT ); - CHR( ' ' ); - UID( parse.FullVersion.Version.MajorVersion ); - CHR( '.' ); - UID( parse.FullVersion.Version.MinorVersion ); - - if( verbose ) { - TXT( "\nMajorVersion: " ); - UID( parse.FullVersion.Version.MajorVersion ); - TXT( "\nMinorVersion: " ); - UID( parse.FullVersion.Version.MinorVersion ); - CHR( '\n' ); - - TXT( "\nHeaderSize: " ); - UID( parse.FullHeader.Header.HeaderSize ); - TXT( "\nBodySize : " ); - UID( parse.FullHeader.Header.BodySize ); - TXT( "\nProcessor : " ); - ENM( parse.FullHeader.Processor.Processor, TGSI_PROCESSOR_TYPES ); - CHR( '\n' ); - } - - fi = tgsi_default_full_instruction(); - fd = tgsi_default_full_declaration(); - - while( !tgsi_parse_end_of_tokens( &parse ) ) { - tgsi_parse_token( &parse ); - - switch( parse.FullToken.Token.Type ) { - case TGSI_TOKEN_TYPE_DECLARATION: - dump_declaration_short( - dump, - &parse.FullToken.FullDeclaration ); - break; - - case TGSI_TOKEN_TYPE_IMMEDIATE: - dump_immediate_short( - dump, - &parse.FullToken.FullImmediate ); - break; - - case TGSI_TOKEN_TYPE_INSTRUCTION: - dump_instruction_short( - dump, - &parse.FullToken.FullInstruction, - instno ); - instno++; - break; - - default: - assert( 0 ); - } - - if( verbose ) { - TXT( "\nType : " ); - ENM( parse.FullToken.Token.Type, TGSI_TOKEN_TYPES ); - if( ignored ) { - TXT( "\nSize : " ); - UID( parse.FullToken.Token.Size ); - if( deflt || parse.FullToken.Token.Extended ) { - TXT( "\nExtended : " ); - UID( parse.FullToken.Token.Extended ); - } - } - - switch( parse.FullToken.Token.Type ) { - case TGSI_TOKEN_TYPE_DECLARATION: - dump_declaration_verbose( - dump, - &parse.FullToken.FullDeclaration, - ignored, - deflt, - &fd ); - break; - - case TGSI_TOKEN_TYPE_IMMEDIATE: - dump_immediate_verbose( - dump, - &parse.FullToken.FullImmediate, - ignored ); - break; - - case TGSI_TOKEN_TYPE_INSTRUCTION: - dump_instruction_verbose( - dump, - &parse.FullToken.FullInstruction, - ignored, - deflt, - &fi ); - break; - - default: - assert( 0 ); - } - - CHR( '\n' ); - } - } - - TXT( "\ntgsi-dump end -------------------\n" ); - - tgsi_parse_free( &parse ); -} - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_dump.h b/src/mesa/pipe/tgsi/exec/tgsi_dump.h deleted file mode 100644 index 70860c0885a..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_dump.h +++ /dev/null @@ -1,22 +0,0 @@ -#if !defined TGSI_DUMP_H -#define TGSI_DUMP_H - -#if defined __cplusplus -extern "C" { -#endif // defined __cplusplus - -#define TGSI_DUMP_VERBOSE 1 -#define TGSI_DUMP_NO_IGNORED 2 -#define TGSI_DUMP_NO_DEFAULT 4 - -void -tgsi_dump( - const struct tgsi_token *tokens, - unsigned flags ); - -#if defined __cplusplus -} // extern "C" -#endif // defined __cplusplus - -#endif // !defined TGSI_DUMP_H - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_exec.c b/src/mesa/pipe/tgsi/exec/tgsi_exec.c index ea6c5021b32..dd11dd58b78 100644 --- a/src/mesa/pipe/tgsi/exec/tgsi_exec.c +++ b/src/mesa/pipe/tgsi/exec/tgsi_exec.c @@ -46,14 +46,17 @@ * * * Authors: - * Michael Krol + * Michal Krol * Brian Paul */ #include "pipe/p_compiler.h" #include "pipe/p_state.h" #include "pipe/p_util.h" -#include "tgsi_core.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/tgsi/util/tgsi_parse.h" +#include "pipe/tgsi/util/tgsi_util.h" +#include "tgsi_exec.h" #define TILE_TOP_LEFT 0 #define TILE_TOP_RIGHT 1 diff --git a/src/mesa/pipe/tgsi/exec/tgsi_exec.h b/src/mesa/pipe/tgsi/exec/tgsi_exec.h index 1d497e97fb0..2c62b30f150 100644 --- a/src/mesa/pipe/tgsi/exec/tgsi_exec.h +++ b/src/mesa/pipe/tgsi/exec/tgsi_exec.h @@ -76,7 +76,7 @@ struct softpipe_tile_cache; /**< Opaque to TGSI */ struct tgsi_sampler { const struct pipe_sampler_state *state; - struct pipe_mipmap_tree *texture; + struct pipe_texture *texture; /** Get samples for four fragments in a quad */ void (*get_samples)(struct tgsi_sampler *sampler, const float s[QUAD_SIZE], diff --git a/src/mesa/pipe/tgsi/exec/tgsi_parse.c b/src/mesa/pipe/tgsi/exec/tgsi_parse.c deleted file mode 100644 index aee71decb38..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_parse.c +++ /dev/null @@ -1,316 +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. - * - **************************************************************************/ - -#include "tgsi_platform.h" -#include "tgsi_core.h" - -void -tgsi_full_token_init( - union tgsi_full_token *full_token ) -{ - full_token->Token.Type = TGSI_TOKEN_TYPE_DECLARATION; -} - -void -tgsi_full_token_free( - union tgsi_full_token *full_token ) -{ - if( full_token->Token.Type == TGSI_TOKEN_TYPE_IMMEDIATE ) { - FREE( full_token->FullImmediate.u.Pointer ); - } -} - -unsigned -tgsi_parse_init( - struct tgsi_parse_context *ctx, - const struct tgsi_token *tokens ) -{ - ctx->FullVersion.Version = *(struct tgsi_version *) &tokens[0]; - if( ctx->FullVersion.Version.MajorVersion > 1 ) { - return TGSI_PARSE_ERROR; - } - - ctx->FullHeader.Header = *(struct tgsi_header *) &tokens[1]; - if( ctx->FullHeader.Header.HeaderSize >= 2 ) { - ctx->FullHeader.Processor = *(struct tgsi_processor *) &tokens[2]; - } - else { - ctx->FullHeader.Processor = tgsi_default_processor(); - } - - ctx->Tokens = tokens; - ctx->Position = 1 + ctx->FullHeader.Header.HeaderSize; - - tgsi_full_token_init( &ctx->FullToken ); - - return TGSI_PARSE_OK; -} - -void -tgsi_parse_free( - struct tgsi_parse_context *ctx ) -{ - tgsi_full_token_free( &ctx->FullToken ); -} - -boolean -tgsi_parse_end_of_tokens( - struct tgsi_parse_context *ctx ) -{ - return ctx->Position >= - 1 + ctx->FullHeader.Header.HeaderSize + ctx->FullHeader.Header.BodySize; -} - -static void -next_token( - struct tgsi_parse_context *ctx, - void *token ) -{ - assert( !tgsi_parse_end_of_tokens( ctx ) ); - - *(struct tgsi_token *) token = ctx->Tokens[ctx->Position++]; -} - -void -tgsi_parse_token( - struct tgsi_parse_context *ctx ) -{ - struct tgsi_token token; - unsigned i; - - tgsi_full_token_free( &ctx->FullToken ); - tgsi_full_token_init( &ctx->FullToken ); - - next_token( ctx, &token ); - - switch( token.Type ) { - case TGSI_TOKEN_TYPE_DECLARATION: - { - struct tgsi_full_declaration *decl = &ctx->FullToken.FullDeclaration; - - *decl = tgsi_default_full_declaration(); - decl->Declaration = *(struct tgsi_declaration *) &token; - - switch( decl->Declaration.Type ) { - case TGSI_DECLARE_RANGE: - next_token( ctx, &decl->u.DeclarationRange ); - break; - - case TGSI_DECLARE_MASK: - next_token( ctx, &decl->u.DeclarationMask ); - break; - - default: - assert (0); - } - - if( decl->Declaration.Interpolate ) { - next_token( ctx, &decl->Interpolation ); - } - - if( decl->Declaration.Semantic ) { - next_token( ctx, &decl->Semantic ); - } - - break; - } - - case TGSI_TOKEN_TYPE_IMMEDIATE: - { - struct tgsi_full_immediate *imm = &ctx->FullToken.FullImmediate; - - *imm = tgsi_default_full_immediate(); - imm->Immediate = *(struct tgsi_immediate *) &token; - - assert( !imm->Immediate.Extended ); - - switch (imm->Immediate.DataType) { - case TGSI_IMM_FLOAT32: - imm->u.Pointer = MALLOC( - sizeof( struct tgsi_immediate_float32 ) * (imm->Immediate.Size - 1) ); - for( i = 0; i < imm->Immediate.Size - 1; i++ ) { - next_token( ctx, &imm->u.ImmediateFloat32[i] ); - } - break; - - default: - assert( 0 ); - } - - break; - } - - case TGSI_TOKEN_TYPE_INSTRUCTION: - { - struct tgsi_full_instruction *inst = &ctx->FullToken.FullInstruction; - unsigned extended; - - *inst = tgsi_default_full_instruction(); - inst->Instruction = *(struct tgsi_instruction *) &token; - - extended = inst->Instruction.Extended; - - while( extended ) { - struct tgsi_src_register_ext token; - - next_token( ctx, &token ); - - switch( token.Type ) { - case TGSI_INSTRUCTION_EXT_TYPE_NV: - inst->InstructionExtNv = - *(struct tgsi_instruction_ext_nv *) &token; - break; - - case TGSI_INSTRUCTION_EXT_TYPE_LABEL: - inst->InstructionExtLabel = - *(struct tgsi_instruction_ext_label *) &token; - break; - - case TGSI_INSTRUCTION_EXT_TYPE_TEXTURE: - inst->InstructionExtTexture = - *(struct tgsi_instruction_ext_texture *) &token; - break; - - default: - assert( 0 ); - } - - extended = token.Extended; - } - - assert( inst->Instruction.NumDstRegs <= TGSI_FULL_MAX_DST_REGISTERS ); - - for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) { - unsigned extended; - - next_token( ctx, &inst->FullDstRegisters[i].DstRegister ); - - /* - * No support for indirect or multi-dimensional addressing. - */ - assert( !inst->FullDstRegisters[i].DstRegister.Indirect ); - assert( !inst->FullDstRegisters[i].DstRegister.Dimension ); - - extended = inst->FullDstRegisters[i].DstRegister.Extended; - - while( extended ) { - struct tgsi_src_register_ext token; - - next_token( ctx, &token ); - - switch( token.Type ) { - case TGSI_DST_REGISTER_EXT_TYPE_CONDCODE: - inst->FullDstRegisters[i].DstRegisterExtConcode = - *(struct tgsi_dst_register_ext_concode *) &token; - break; - - case TGSI_DST_REGISTER_EXT_TYPE_MODULATE: - inst->FullDstRegisters[i].DstRegisterExtModulate = - *(struct tgsi_dst_register_ext_modulate *) &token; - break; - - default: - assert( 0 ); - } - - extended = token.Extended; - } - } - - assert( inst->Instruction.NumSrcRegs <= TGSI_FULL_MAX_SRC_REGISTERS ); - - for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) { - unsigned extended; - - next_token( ctx, &inst->FullSrcRegisters[i].SrcRegister ); - - extended = inst->FullSrcRegisters[i].SrcRegister.Extended; - - while( extended ) { - struct tgsi_src_register_ext token; - - next_token( ctx, &token ); - - switch( token.Type ) { - case TGSI_SRC_REGISTER_EXT_TYPE_SWZ: - inst->FullSrcRegisters[i].SrcRegisterExtSwz = - *(struct tgsi_src_register_ext_swz *) &token; - break; - - case TGSI_SRC_REGISTER_EXT_TYPE_MOD: - inst->FullSrcRegisters[i].SrcRegisterExtMod = - *(struct tgsi_src_register_ext_mod *) &token; - break; - - default: - assert( 0 ); - } - - extended = token.Extended; - } - - if( inst->FullSrcRegisters[i].SrcRegister.Indirect ) { - next_token( ctx, &inst->FullSrcRegisters[i].SrcRegisterInd ); - - /* - * No support for indirect or multi-dimensional addressing. - */ - assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Indirect ); - assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Dimension ); - assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Extended ); - } - - if( inst->FullSrcRegisters[i].SrcRegister.Dimension ) { - next_token( ctx, &inst->FullSrcRegisters[i].SrcRegisterDim ); - - /* - * No support for multi-dimensional addressing. - */ - assert( !inst->FullSrcRegisters[i].SrcRegisterDim.Dimension ); - assert( !inst->FullSrcRegisters[i].SrcRegisterDim.Extended ); - - if( inst->FullSrcRegisters[i].SrcRegisterDim.Indirect ) { - next_token( ctx, &inst->FullSrcRegisters[i].SrcRegisterDimInd ); - - /* - * No support for indirect or multi-dimensional addressing. - */ - assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Indirect ); - assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Dimension ); - assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Extended ); - } - } - } - - break; - } - - default: - assert( 0 ); - } -} - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_parse.h b/src/mesa/pipe/tgsi/exec/tgsi_parse.h deleted file mode 100644 index 9372da8d5d1..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_parse.h +++ /dev/null @@ -1,121 +0,0 @@ -#if !defined TGSI_PARSE_H -#define TGSI_PARSE_H - -#if defined __cplusplus -extern "C" { -#endif // defined __cplusplus - -struct tgsi_full_version -{ - struct tgsi_version Version; -}; - -struct tgsi_full_header -{ - struct tgsi_header Header; - struct tgsi_processor Processor; -}; - -struct tgsi_full_dst_register -{ - struct tgsi_dst_register DstRegister; - struct tgsi_dst_register_ext_concode DstRegisterExtConcode; - struct tgsi_dst_register_ext_modulate DstRegisterExtModulate; -}; - -struct tgsi_full_src_register -{ - struct tgsi_src_register SrcRegister; - struct tgsi_src_register_ext_swz SrcRegisterExtSwz; - struct tgsi_src_register_ext_mod SrcRegisterExtMod; - struct tgsi_src_register SrcRegisterInd; - struct tgsi_dimension SrcRegisterDim; - struct tgsi_src_register SrcRegisterDimInd; -}; - -struct tgsi_full_declaration -{ - struct tgsi_declaration Declaration; - union - { - struct tgsi_declaration_range DeclarationRange; - struct tgsi_declaration_mask DeclarationMask; - } u; - struct tgsi_declaration_interpolation Interpolation; - struct tgsi_declaration_semantic Semantic; -}; - -struct tgsi_full_immediate -{ - struct tgsi_immediate Immediate; - union - { - void *Pointer; - struct tgsi_immediate_float32 *ImmediateFloat32; - } u; -}; - -#define TGSI_FULL_MAX_DST_REGISTERS 2 -#define TGSI_FULL_MAX_SRC_REGISTERS 3 - -struct tgsi_full_instruction -{ - struct tgsi_instruction Instruction; - struct tgsi_instruction_ext_nv InstructionExtNv; - struct tgsi_instruction_ext_label InstructionExtLabel; - struct tgsi_instruction_ext_texture InstructionExtTexture; - struct tgsi_full_dst_register FullDstRegisters[TGSI_FULL_MAX_DST_REGISTERS]; - struct tgsi_full_src_register FullSrcRegisters[TGSI_FULL_MAX_SRC_REGISTERS]; -}; - -union tgsi_full_token -{ - struct tgsi_token Token; - struct tgsi_full_declaration FullDeclaration; - struct tgsi_full_immediate FullImmediate; - struct tgsi_full_instruction FullInstruction; -}; - -void -tgsi_full_token_init( - union tgsi_full_token *full_token ); - -void -tgsi_full_token_free( - union tgsi_full_token *full_token ); - -struct tgsi_parse_context -{ - const struct tgsi_token *Tokens; - unsigned Position; - struct tgsi_full_version FullVersion; - struct tgsi_full_header FullHeader; - union tgsi_full_token FullToken; -}; - -#define TGSI_PARSE_OK 0 -#define TGSI_PARSE_ERROR 1 - -unsigned -tgsi_parse_init( - struct tgsi_parse_context *ctx, - const struct tgsi_token *tokens ); - -void -tgsi_parse_free( - struct tgsi_parse_context *ctx ); - -boolean -tgsi_parse_end_of_tokens( - struct tgsi_parse_context *ctx ); - -void -tgsi_parse_token( - struct tgsi_parse_context *ctx ); - -#if defined __cplusplus -} // extern "C" -#endif // defined __cplusplus - -#endif // !defined TGSI_PARSE_H - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_sse2.c b/src/mesa/pipe/tgsi/exec/tgsi_sse2.c index 3a5c1da1800..e403cfaaf36 100755 --- a/src/mesa/pipe/tgsi/exec/tgsi_sse2.c +++ b/src/mesa/pipe/tgsi/exec/tgsi_sse2.c @@ -25,8 +25,13 @@ * **************************************************************************/ -#include "tgsi_platform.h" -#include "tgsi_core.h" +#include "pipe/p_util.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/tgsi/util/tgsi_parse.h" +#include "pipe/tgsi/util/tgsi_util.h" +#include "tgsi_exec.h" +#include "tgsi_sse2.h" + #include "x86/rtasm/x86sse.h" #if defined(__i386__) || defined(__386__) diff --git a/src/mesa/pipe/tgsi/exec/tgsi_token.h b/src/mesa/pipe/tgsi/exec/tgsi_token.h deleted file mode 100644 index 2b922c7aef0..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_token.h +++ /dev/null @@ -1,1494 +0,0 @@ -#if !defined TGSI_TOKEN_H -#define TGSI_TOKEN_H - -#if defined __cplusplus -extern "C" { -#endif // defined __cplusplus - -struct tgsi_version -{ - unsigned MajorVersion : 8; - unsigned MinorVersion : 8; - unsigned Padding : 16; -}; - -struct tgsi_header -{ - unsigned HeaderSize : 8; - unsigned BodySize : 24; -}; - -#define TGSI_PROCESSOR_FRAGMENT 0 -#define TGSI_PROCESSOR_VERTEX 1 -#define TGSI_PROCESSOR_GEOMETRY 2 - -struct tgsi_processor -{ - unsigned Processor : 4; /* TGSI_PROCESSOR_ */ - unsigned Padding : 28; -}; - -#define TGSI_TOKEN_TYPE_DECLARATION 0 -#define TGSI_TOKEN_TYPE_IMMEDIATE 1 -#define TGSI_TOKEN_TYPE_INSTRUCTION 2 - -struct tgsi_token -{ - unsigned Type : 4; /* TGSI_TOKEN_TYPE_ */ - unsigned Size : 8; /* UINT */ - unsigned Padding : 19; - unsigned Extended : 1; /* BOOL */ -}; - -#define TGSI_FILE_NULL 0 -#define TGSI_FILE_CONSTANT 1 -#define TGSI_FILE_INPUT 2 -#define TGSI_FILE_OUTPUT 3 -#define TGSI_FILE_TEMPORARY 4 -#define TGSI_FILE_SAMPLER 5 -#define TGSI_FILE_ADDRESS 6 -#define TGSI_FILE_IMMEDIATE 7 - -#define TGSI_DECLARE_RANGE 0 -#define TGSI_DECLARE_MASK 1 - -#define TGSI_WRITEMASK_NONE 0x00 -#define TGSI_WRITEMASK_X 0x01 -#define TGSI_WRITEMASK_Y 0x02 -#define TGSI_WRITEMASK_XY 0x03 -#define TGSI_WRITEMASK_Z 0x04 -#define TGSI_WRITEMASK_XZ 0x05 -#define TGSI_WRITEMASK_YZ 0x06 -#define TGSI_WRITEMASK_XYZ 0x07 -#define TGSI_WRITEMASK_W 0x08 -#define TGSI_WRITEMASK_XW 0x09 -#define TGSI_WRITEMASK_YW 0x0A -#define TGSI_WRITEMASK_XYW 0x0B -#define TGSI_WRITEMASK_ZW 0x0C -#define TGSI_WRITEMASK_XZW 0x0D -#define TGSI_WRITEMASK_YZW 0x0E -#define TGSI_WRITEMASK_XYZW 0x0F - -struct tgsi_declaration -{ - unsigned Type : 4; /* TGSI_TOKEN_TYPE_DECLARATION */ - unsigned Size : 8; /* UINT */ - unsigned File : 4; /* one of TGSI_FILE_x */ - unsigned Declare : 4; /* one of TGSI_DECLARE_x */ - unsigned UsageMask : 4; /* bitmask of TGSI_WRITEMASK_x flags */ - unsigned Interpolate : 1; /* BOOL, any interpolation info? */ - unsigned Semantic : 1; /* BOOL, any semantic info? */ - unsigned Padding : 5; - unsigned Extended : 1; /* BOOL */ -}; - -struct tgsi_declaration_range -{ - unsigned First : 16; /* UINT */ - unsigned Last : 16; /* UINT */ -}; - -struct tgsi_declaration_mask -{ - unsigned Mask : 32; /* UINT */ -}; - -#define TGSI_INTERPOLATE_CONSTANT 0 -#define TGSI_INTERPOLATE_LINEAR 1 -#define TGSI_INTERPOLATE_PERSPECTIVE 2 - -struct tgsi_declaration_interpolation -{ - unsigned Interpolate : 4; /* TGSI_INTERPOLATE_ */ - unsigned Padding : 28; -}; - -#define TGSI_SEMANTIC_POSITION 0 -#define TGSI_SEMANTIC_COLOR 1 -#define TGSI_SEMANTIC_BCOLOR 2 /**< back-face color */ -#define TGSI_SEMANTIC_FOG 3 -#define TGSI_SEMANTIC_PSIZE 4 -#define TGSI_SEMANTIC_GENERIC 5 -#define TGSI_SEMANTIC_COUNT 6 /**< number of semantic values */ - -struct tgsi_declaration_semantic -{ - unsigned SemanticName : 8; /* one of TGSI_SEMANTIC_ */ - unsigned SemanticIndex : 16; /* UINT */ - unsigned Padding : 8; -}; - -#define TGSI_IMM_FLOAT32 0 - -struct tgsi_immediate -{ - unsigned Type : 4; /* TGSI_TOKEN_TYPE_IMMEDIATE */ - unsigned Size : 8; /* UINT */ - unsigned DataType : 4; /* TGSI_IMM_ */ - unsigned Padding : 15; - unsigned Extended : 1; /* BOOL */ -}; - -struct tgsi_immediate_float32 -{ - float Float; -}; - -/* - * GL_NV_vertex_program - */ -#define TGSI_OPCODE_ARL 0 -#define TGSI_OPCODE_MOV 1 -#define TGSI_OPCODE_LIT 2 -#define TGSI_OPCODE_RCP 3 -#define TGSI_OPCODE_RSQ 4 -#define TGSI_OPCODE_EXP 5 -#define TGSI_OPCODE_LOG 6 -#define TGSI_OPCODE_MUL 7 -#define TGSI_OPCODE_ADD 8 -#define TGSI_OPCODE_DP3 9 -#define TGSI_OPCODE_DP4 10 -#define TGSI_OPCODE_DST 11 -#define TGSI_OPCODE_MIN 12 -#define TGSI_OPCODE_MAX 13 -#define TGSI_OPCODE_SLT 14 -#define TGSI_OPCODE_SGE 15 -#define TGSI_OPCODE_MAD 16 - -/* - * GL_ATI_fragment_shader - */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_MUL */ -#define TGSI_OPCODE_SUB 17 -#define TGSI_OPCODE_DOT3 TGSI_OPCODE_DP3 -#define TGSI_OPCODE_DOT4 TGSI_OPCODE_DP4 -/* TGSI_OPCODE_MAD */ -#define TGSI_OPCODE_LERP 18 -#define TGSI_OPCODE_CND 19 -#define TGSI_OPCODE_CND0 20 -#define TGSI_OPCODE_DOT2ADD 21 - -/* - * GL_EXT_vertex_shader - */ -#define TGSI_OPCODE_INDEX 22 -#define TGSI_OPCODE_NEGATE 23 -/* TGSI_OPCODE_DOT3 */ -/* TGSI_OPCODE_DOT4 */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_ADD */ -#define TGSI_OPCODE_MADD TGSI_OPCODE_MAD -#define TGSI_OPCODE_FRAC 24 -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -#define TGSI_OPCODE_SETGE TGSI_OPCODE_SGE -#define TGSI_OPCODE_SETLT TGSI_OPCODE_SLT -#define TGSI_OPCODE_CLAMP 25 -#define TGSI_OPCODE_FLOOR 26 -#define TGSI_OPCODE_ROUND 27 -#define TGSI_OPCODE_EXPBASE2 28 -#define TGSI_OPCODE_LOGBASE2 29 -#define TGSI_OPCODE_POWER 30 -#define TGSI_OPCODE_RECIP TGSI_OPCODE_RCP -#define TGSI_OPCODE_RECIPSQRT TGSI_OPCODE_RSQ -/* TGSI_OPCODE_SUB */ -#define TGSI_OPCODE_CROSSPRODUCT 31 -#define TGSI_OPCODE_MULTIPLYMATRIX 32 -/* TGSI_OPCODE_MOV */ - -/* - * GL_NV_vertex_program1_1 - */ -/* TGSI_OPCODE_ARL */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_LIT */ -#define TGSI_OPCODE_ABS 33 -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_EXP */ -/* TGSI_OPCODE_LOG */ -#define TGSI_OPCODE_RCC 34 -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SGE */ -#define TGSI_OPCODE_DPH 35 -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ - -/* - * GL_NV_fragment_program - */ -/* TGSI_OPCODE_ADD */ -#define TGSI_OPCODE_COS 36 -#define TGSI_OPCODE_DDX 37 -#define TGSI_OPCODE_DDY 38 -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DST */ -#define TGSI_OPCODE_EX2 TGSI_OPCODE_EXPBASE2 -#define TGSI_OPCODE_FLR TGSI_OPCODE_FLOOR -#define TGSI_OPCODE_FRC TGSI_OPCODE_FRAC -#define TGSI_OPCODE_KILP 39 /* predicated kill */ -#define TGSI_OPCODE_LG2 TGSI_OPCODE_LOGBASE2 -/* TGSI_OPCODE_LIT */ -#define TGSI_OPCODE_LRP TGSI_OPCODE_LERP -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_MUL */ -#define TGSI_OPCODE_PK2H 40 -#define TGSI_OPCODE_PK2US 41 -#define TGSI_OPCODE_PK4B 42 -#define TGSI_OPCODE_PK4UB 43 -#define TGSI_OPCODE_POW TGSI_OPCODE_POWER -/* TGSI_OPCODE_RCP */ -#define TGSI_OPCODE_RFL 44 -/* TGSI_OPCODE_RSQ */ -#define TGSI_OPCODE_SEQ 45 -#define TGSI_OPCODE_SFL 46 -/* TGSI_OPCODE_SGE */ -#define TGSI_OPCODE_SGT 47 -#define TGSI_OPCODE_SIN 48 -#define TGSI_OPCODE_SLE 49 -/* TGSI_OPCODE_SLT */ -#define TGSI_OPCODE_SNE 50 -#define TGSI_OPCODE_STR 51 -/* TGSI_OPCODE_SUB */ -#define TGSI_OPCODE_TEX 52 -#define TGSI_OPCODE_TXD 53 -/* TGSI_OPCODE_TXP */ -#define TGSI_OPCODE_UP2H 54 -#define TGSI_OPCODE_UP2US 55 -#define TGSI_OPCODE_UP4B 56 -#define TGSI_OPCODE_UP4UB 57 -#define TGSI_OPCODE_X2D 58 - -/* - * GL_NV_vertex_program2 - */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_ADD */ -#define TGSI_OPCODE_ARA 59 -/* TGSI_OPCODE_ARL */ -#define TGSI_OPCODE_ARR 60 -#define TGSI_OPCODE_BRA 61 -#define TGSI_OPCODE_CAL 62 -/* TGSI_OPCODE_COS */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DPH */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_EXP */ -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_LOG */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_RCC */ -/* TGSI_OPCODE_RCP */ -#define TGSI_OPCODE_RET 63 -/* TGSI_OPCODE_RSQNV - use TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SFL */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SIN */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SNE */ -#define TGSI_OPCODE_SSG 64 -/* TGSI_OPCODE_STR */ -/* TGSI_OPCODE_SUB */ - -/* - * GL_ARB_vertex_program - */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_ARL */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DPH */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_EXP */ -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_LOG */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_POW */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SUB */ -#define TGSI_OPCODE_SWZ TGSI_OPCODE_MOV -#define TGSI_OPCODE_XPD TGSI_OPCODE_CROSSPRODUCT - -/* - * GL_ARB_fragment_program - */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_ADD */ -#define TGSI_OPCODE_CMP 65 -/* TGSI_OPCODE_COS */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DPH */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_POW */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -#define TGSI_OPCODE_SCS 66 -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SIN */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_SWZ */ -/* TGSI_OPCODE_XPD */ -/* TGSI_OPCODE_TEX */ -/* TGSI_OPCODE_TXP */ -#define TGSI_OPCODE_TXB 67 -/* TGSI_OPCODE_KIL */ - -/* - * GL_NV_fragment_program_option - */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_DDX */ -/* TGSI_OPCODE_DDY */ -/* TGSI_OPCODE_PK2H */ -/* TGSI_OPCODE_PK2US */ -/* TGSI_OPCODE_PK4B */ -/* TGSI_OPCODE_PK4UB */ -/* TGSI_OPCODE_COS */ -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_SIN */ -/* TGSI_OPCODE_SCS */ -/* TGSI_OPCODE_UP2H */ -/* TGSI_OPCODE_UP2US */ -/* TGSI_OPCODE_UP4B */ -/* TGSI_OPCODE_UP4UB */ -/* TGSI_OPCODE_POW */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DPH */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_XPD */ -/* TGSI_OPCODE_RFL */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SFL */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SNE */ -/* TGSI_OPCODE_STR */ -/* TGSI_OPCODE_CMP */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_X2D */ -/* TGSI_OPCODE_SWZ */ -/* TGSI_OPCODE_TEX */ -/* TGSI_OPCODE_TXP */ -/* TGSI_OPCODE_TXB */ -/* TGSI_OPCODE_KIL */ -/* TGSI_OPCODE_TXD */ - -/* - * GL_NV_fragment_program2 - */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_DDX */ -/* TGSI_OPCODE_DDY */ -/* TGSI_OPCODE_PK2H */ -/* TGSI_OPCODE_PK2US */ -/* TGSI_OPCODE_PK4B */ -/* TGSI_OPCODE_PK4UB */ -#define TGSI_OPCODE_NRM 68 -#define TGSI_OPCODE_DIV 69 -/* TGSI_OPCODE_COS */ -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_SIN */ -/* TGSI_OPCODE_SCS */ -/* TGSI_OPCODE_UP2H */ -/* TGSI_OPCODE_UP2US */ -/* TGSI_OPCODE_UP4B */ -/* TGSI_OPCODE_UP4UB */ -/* TGSI_OPCODE_POW */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DPH */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_XPD */ -/* TGSI_OPCODE_RFL */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SFL */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SNE */ -/* TGSI_OPCODE_STR */ -#define TGSI_OPCODE_DP2 70 -/* TGSI_OPCODE_CMP */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_X2D */ -#define TGSI_OPCODE_DP2A TGSI_OPCODE_DOT2ADD -/* TGSI_OPCODE_SWZ */ -/* TGSI_OPCODE_TEX */ -/* TGSI_OPCODE_TXP */ -/* TGSI_OPCODE_TXB */ -#define TGSI_OPCODE_TXL 71 -/* TGSI_OPCODE_KIL */ -/* TGSI_OPCODE_TXD */ -/* TGSI_OPCODE_CAL */ -/* TGSI_OPCODE_RET */ -#define TGSI_OPCODE_BRK 72 -#define TGSI_OPCODE_IF 73 -#define TGSI_OPCODE_LOOP 74 -#define TGSI_OPCODE_REP 75 -#define TGSI_OPCODE_ELSE 76 -#define TGSI_OPCODE_ENDIF 77 -#define TGSI_OPCODE_ENDLOOP 78 -#define TGSI_OPCODE_ENDREP 79 - -/* - * GL_NV_vertex_program2_option - */ -/* TGSI_OPCODE_ARL */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_SSG */ -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_EXP */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LOG */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_COS */ -/* TGSI_OPCODE_RCC */ -/* TGSI_OPCODE_SIN */ -/* TGSI_OPCODE_POW */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DPH */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_XPD */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SFL */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SNE */ -/* TGSI_OPCODE_STR */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_SWZ */ -/* TGSI_OPCODE_ARR */ -/* TGSI_OPCODE_ARA */ -/* TGSI_OPCODE_BRA */ -/* TGSI_OPCODE_CAL */ -/* TGSI_OPCODE_RET */ - -/* - * GL_NV_vertex_program3 - */ -/* TGSI_OPCODE_ARL */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_SSG */ -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_EXP */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LOG */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_COS */ -/* TGSI_OPCODE_RCC */ -/* TGSI_OPCODE_SIN */ -/* TGSI_OPCODE_POW */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DPH */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_XPD */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SFL */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SNE */ -/* TGSI_OPCODE_STR */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_SWZ */ -/* TGSI_OPCODE_ARR */ -/* TGSI_OPCODE_ARA */ -/* TGSI_OPCODE_BRA */ -/* TGSI_OPCODE_CAL */ -/* TGSI_OPCODE_RET */ -#define TGSI_OPCODE_PUSHA 80 -#define TGSI_OPCODE_POPA 81 -/* TGSI_OPCODE_TEX */ -/* TGSI_OPCODE_TXP */ -/* TGSI_OPCODE_TXB */ -/* TGSI_OPCODE_TXL */ - -/* - * GL_NV_gpu_program4 - */ -/* TGSI_OPCODE_ABS */ -#define TGSI_OPCODE_CEIL 82 -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -#define TGSI_OPCODE_I2F 83 -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_MOV */ -#define TGSI_OPCODE_NOT 84 -/* TGSI_OPCODE_NRM */ -/* TGSI_OPCODE_PK2H */ -/* TGSI_OPCODE_PK2US */ -/* TGSI_OPCODE_PK4B */ -/* TGSI_OPCODE_PK4UB */ -/* TGSI_OPCODE_ROUND */ -/* TGSI_OPCODE_SSG */ -#define TGSI_OPCODE_TRUNC 85 -/* TGSI_OPCODE_COS */ -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_RCC */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_SCS */ -/* TGSI_OPCODE_SIN */ -/* TGSI_OPCODE_UP2H */ -/* TGSI_OPCODE_UP2US */ -/* TGSI_OPCODE_UP4B */ -/* TGSI_OPCODE_UP4UB */ -/* TGSI_OPCODE_POW */ -/* TGSI_OPCODE_DIV */ -#define TGSI_OPCODE_SHL 86 -#define TGSI_OPCODE_SHR 87 -/* TGSI_OPCODE_ADD */ -#define TGSI_OPCODE_AND 88 -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_DPH */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MUL */ -#define TGSI_OPCODE_OR 89 -/* TGSI_OPCODE_RFL */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SFL */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SNE */ -/* TGSI_OPCODE_STR */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_XPD */ -/* TGSI_OPCODE_DP2 */ -#define TGSI_OPCODE_MOD 90 -#define TGSI_OPCODE_XOR 91 -/* TGSI_OPCODE_CMP */ -/* TGSI_OPCODE_DP2A */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_MAD */ -#define TGSI_OPCODE_SAD 92 -/* TGSI_OPCODE_X2D */ -/* TGSI_OPCODE_SWZ */ -/* TGSI_OPCODE_TEX */ -/* TGSI_OPCODE_TXB */ -#define TGSI_OPCODE_TXF 93 -/* TGSI_OPCODE_TXL */ -/* TGSI_OPCODE_TXP */ -#define TGSI_OPCODE_TXQ 94 -/* TGSI_OPCODE_TXD */ -/* TGSI_OPCODE_CAL */ -/* TGSI_OPCODE_RET */ -/* TGSI_OPCODE_BRK */ -#define TGSI_OPCODE_CONT 95 -/* TGSI_OPCODE_IF */ -/* TGSI_OPCODE_REP */ -/* TGSI_OPCODE_ELSE */ -/* TGSI_OPCODE_ENDIF */ -/* TGSI_OPCODE_ENDREP */ - -/* - * GL_NV_vertex_program4 - */ -/* Same as GL_NV_gpu_program4 */ - -/* - * GL_NV_fragment_program4 - */ -/* Same as GL_NV_gpu_program4 */ -/* TGSI_OPCODE_KIL */ -/* TGSI_OPCODE_DDX */ -/* TGSI_OPCODE_DDY */ - -/* - * GL_NV_geometry_program4 - */ -/* Same as GL_NV_gpu_program4 */ -#define TGSI_OPCODE_EMIT 96 -#define TGSI_OPCODE_ENDPRIM 97 - -/* - * GLSL - */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_ADD */ -#define TGSI_OPCODE_BGNLOOP2 98 -#define TGSI_OPCODE_BGNSUB 99 -/* TGSI_OPCODE_BRA */ -/* TGSI_OPCODE_BRK */ -/* TGSI_OPCODE_CONT */ -/* TGSI_OPCODE_COS */ -/* TGSI_OPCODE_DDX */ -/* TGSI_OPCODE_DDY */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_ELSE */ -/* TGSI_OPCODE_ENDIF */ -#define TGSI_OPCODE_ENDLOOP2 100 -#define TGSI_OPCODE_ENDSUB 101 -/* TGSI_OPCODE_EX2 */ -/* TGSI_OPCODE_EXP */ -/* TGSI_OPCODE_FLR */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_IF */ -#define TGSI_OPCODE_INT TGSI_OPCODE_TRUNC -/* TGSI_OPCODE_KIL */ -/* TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LOG */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_MUL */ -#define TGSI_OPCODE_NOISE1 102 -#define TGSI_OPCODE_NOISE2 103 -#define TGSI_OPCODE_NOISE3 104 -#define TGSI_OPCODE_NOISE4 105 -#define TGSI_OPCODE_NOP 106 -/* TGSI_OPCODE_POW */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SIN */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SNE */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_TEX */ -/* TGSI_OPCODE_TXB */ -/* TGSI_OPCODE_TXD */ -/* TGSI_OPCODE_TXL */ -/* TGSI_OPCODE_TXP */ -/* TGSI_OPCODE_XPD */ - -/* - * ps_1_1 - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_LRP */ -#define TGSI_OPCODE_TEXCOORD TGSI_OPCODE_NOP -#define TGSI_OPCODE_TEXKILL TGSI_OPCODE_KIL -/* TGSI_OPCODE_TEX */ -#define TGSI_OPCODE_TEXBEM 107 -#define TGSI_OPCODE_TEXBEML 108 -#define TGSI_OPCODE_TEXREG2AR 109 -#define TGSI_OPCODE_TEXM3X2PAD 110 -#define TGSI_OPCODE_TEXM3X2TEX 111 -#define TGSI_OPCODE_TEXM3X3PAD 112 -#define TGSI_OPCODE_TEXM3X3TEX 113 -#define TGSI_OPCODE_TEXM3X3SPEC 114 -#define TGSI_OPCODE_TEXM3X3VSPEC 115 -/* TGSI_OPCODE_CND */ - -/* - * ps_1_2 - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_TEXCOORD */ -/* TGSI_OPCODE_TEXKILL */ -/* TGSI_OPCODE_TEX */ -/* TGSI_OPCODE_TEXBEM */ -/* TGSI_OPCODE_TEXBEML */ -/* TGSI_OPCODE_TEXREG2AR */ -#define TGSI_OPCODE_TEXREG2GB 116 -/* TGSI_OPCODE_TEXM3X2PAD */ -/* TGSI_OPCODE_TEXM3X2TEX */ -/* TGSI_OPCODE_TEXM3X3PAD */ -/* TGSI_OPCODE_TEXM3X3TEX */ -/* TGSI_OPCODE_TEXM3X3SPEC */ -/* TGSI_OPCODE_TEXM3X3VSPEC */ -/* TGSI_OPCODE_CND */ -#define TGSI_OPCODE_TEXREG2RGB 117 -#define TGSI_OPCODE_TEXDP3TEX 118 -#define TGSI_OPCODE_TEXDP3 119 -#define TGSI_OPCODE_TEXM3X3 120 -/* CMP - use TGSI_OPCODE_CND0 */ - -/* - * ps_1_3 - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_TEXCOORD */ -/* TGSI_OPCODE_TEXKILL */ -/* TGSI_OPCODE_TEX */ -/* TGSI_OPCODE_TEXBEM */ -/* TGSI_OPCODE_TEXBEML */ -/* TGSI_OPCODE_TEXREG2AR */ -/* TGSI_OPCODE_TEXREG2GB */ -/* TGSI_OPCODE_TEXM3X2PAD */ -/* TGSI_OPCODE_TEXM3X2TEX */ -/* TGSI_OPCODE_TEXM3X3PAD */ -/* TGSI_OPCODE_TEXM3X3TEX */ -/* TGSI_OPCODE_TEXM3X3SPEC */ -/* TGSI_OPCODE_TEXM3X3VSPEC */ -/* TGSI_OPCODE_CND */ -/* TGSI_OPCODE_TEXREG2RGB */ -/* TGSI_OPCODE_TEXDP3TEX */ -#define TGSI_OPCODE_TEXM3X2DEPTH 121 -/* TGSI_OPCODE_TEXDP3 */ -/* TGSI_OPCODE_TEXM3X3 */ -/* CMP - use TGSI_OPCODE_CND0 */ - -/* - * ps_1_4 - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_LRP */ -#define TGSI_OPCODE_TEXCRD TGSI_OPCODE_TEXCOORD -/* TGSI_OPCODE_TEXKILL */ -#define TGSI_OPCODE_TEXLD TGSI_OPCODE_TEX -/* TGSI_OPCODE_CND */ -#define TGSI_OPCODE_TEXDEPTH 122 -/* CMP - use TGSI_OPCODE_CND0 */ -#define TGSI_OPCODE_BEM 123 - -/* - * ps_2_0 - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ /* XXX: takes ABS */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MAX */ -/* EXP - use TGSI_OPCODE_EX2 */ -/* LOG - use TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_FRC */ -#define TGSI_OPCODE_M4X4 TGSI_OPCODE_MULTIPLYMATRIX -#define TGSI_OPCODE_M4X3 124 -#define TGSI_OPCODE_M3X4 125 -#define TGSI_OPCODE_M3X3 126 -#define TGSI_OPCODE_M3X2 127 -/* TGSI_OPCODE_POW */ /* XXX: takes ABS */ -#define TGSI_OPCODE_CRS TGSI_OPCODE_XPD -/* TGSI_OPCODE_ABS */ -#define TGSI_OPCODE_NRM4 128 -#define TGSI_OPCODE_SINCOS TGSI_OPCODE_SCS -/* TGSI_OPCODE_TEXKILL */ -/* TGSI_OPCODE_TEXLD */ -#define TGSI_OPCODE_TEXLDB TGSI_OPCODE_TXB -/* TGSI_OPCODE_TEXLDP */ -/* CMP - use TGSI_OPCODE_CND0 */ -#define TGSI_OPCODE_DP2ADD TGSI_OPCODE_DP2A - -/* - * ps_2_x - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ /* XXX: takes ABS */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SNE */ -/* EXP - use TGSI_OPCODE_EX2 */ -/* LOG - use TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_M4X4 */ -/* TGSI_OPCODE_M4X3 */ -/* TGSI_OPCODE_M3X4 */ -/* TGSI_OPCODE_M3X3 */ -/* TGSI_OPCODE_M3X2 */ -#define TGSI_OPCODE_CALL TGSI_OPCODE_CAL -#define TGSI_OPCODE_CALLNZ 129 -/* TGSI_OPCODE_RET */ -/* TGSI_OPCODE_POW */ /* XXX: takes ABS */ -/* TGSI_OPCODE_CRS */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_NRM4 */ -/* TGSI_OPCODE_SINCOS */ -/* TGSI_OPCODE_REP */ -/* TGSI_OPCODE_ENDREP */ -/* TGSI_OPCODE_IF */ -#define TGSI_OPCODE_IFC 130 -/* TGSI_OPCODE_ELSE */ -/* TGSI_OPCODE_ENDIF */ -#define TGSI_OPCODE_BREAK TGSI_OPCODE_BRK -#define TGSI_OPCODE_BREAKC 131 -/* TGSI_OPCODE_TEXKILL */ -/* TGSI_OPCODE_TEXLD */ -/* TGSI_OPCODE_TEXLDB */ -/* CMP - use TGSI_OPCODE_CND0 */ -/* TGSI_OPCODE_DP2ADD */ -#define TGSI_OPCODE_DSX TGSI_OPCODE_DDX -#define TGSI_OPCODE_DSY TGSI_OPCODE_DDY -#define TGSI_OPCODE_TEXLDD TGSI_OPCODE_TXD -/* TGSI_OPCODE_TEXLDP */ - -/* - * vs_1_1 - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ /* XXX: takes ABS */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SGE */ -/* EXP - use TGSI_OPCODE_EX2 */ -/* LOG - use TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_M4X4 */ -/* TGSI_OPCODE_M4X3 */ -/* TGSI_OPCODE_M3X4 */ -/* TGSI_OPCODE_M3X3 */ -/* TGSI_OPCODE_M3X2 */ -#define TGSI_OPCODE_EXPP TGSI_OPCODE_EXP -#define TGSI_OPCODE_LOGP TGSI_OPCODE_LG2 - -/* - * vs_2_0 - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ /* XXX: takes ABS */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SGE */ -/* EXP - use TGSI_OPCODE_EX2 */ -/* LOG - use TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_M4X4 */ -/* TGSI_OPCODE_M4X3 */ -/* TGSI_OPCODE_M3X4 */ -/* TGSI_OPCODE_M3X3 */ -/* TGSI_OPCODE_M3X2 */ -/* TGSI_OPCODE_CALL */ -/* TGSI_OPCODE_CALLNZ */ -/* TGSI_OPCODE_LOOP */ -/* TGSI_OPCODE_RET */ -/* TGSI_OPCODE_ENDLOOP */ -/* TGSI_OPCODE_POW */ /* XXX: takes ABS */ -/* TGSI_OPCODE_CRS */ -#define TGSI_OPCODE_SGN TGSI_OPCODE_SSG -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_NRM4 */ -/* TGSI_OPCODE_SINCOS */ -/* TGSI_OPCODE_REP */ -/* TGSI_OPCODE_ENDREP */ -/* TGSI_OPCODE_IF */ -/* TGSI_OPCODE_ELSE */ -/* TGSI_OPCODE_ENDIF */ -#define TGSI_OPCODE_MOVA TGSI_OPCODE_ARR -/* TGSI_OPCODE_LOGP */ - -/* - * vs_2_x - */ -/* TGSI_OPCODE_NOP */ -/* TGSI_OPCODE_MOV */ -/* TGSI_OPCODE_ADD */ -/* TGSI_OPCODE_SUB */ -/* TGSI_OPCODE_MAD */ -/* TGSI_OPCODE_MUL */ -/* TGSI_OPCODE_RCP */ -/* TGSI_OPCODE_RSQ */ /* XXX: takes ABS */ -/* TGSI_OPCODE_DP3 */ -/* TGSI_OPCODE_DP4 */ -/* TGSI_OPCODE_MIN */ -/* TGSI_OPCODE_MAX */ -/* TGSI_OPCODE_SLT */ -/* TGSI_OPCODE_SGE */ -/* TGSI_OPCODE_SGT */ -/* TGSI_OPCODE_SLE */ -/* TGSI_OPCODE_SEQ */ -/* TGSI_OPCODE_SNE */ -/* EXP - use TGSI_OPCODE_EX2 */ -/* LOG - use TGSI_OPCODE_LG2 */ -/* TGSI_OPCODE_LIT */ -/* TGSI_OPCODE_DST */ -/* TGSI_OPCODE_LRP */ -/* TGSI_OPCODE_FRC */ -/* TGSI_OPCODE_M4X4 */ -/* TGSI_OPCODE_M4X3 */ -/* TGSI_OPCODE_M3X4 */ -/* TGSI_OPCODE_M3X3 */ -/* TGSI_OPCODE_M3X2 */ -/* TGSI_OPCODE_CALL */ -/* TGSI_OPCODE_CALLNZ */ -/* TGSI_OPCODE_LOOP */ -/* TGSI_OPCODE_RET */ -/* TGSI_OPCODE_ENDLOOP */ -/* TGSI_OPCODE_POW */ /* XXX: takes ABS */ -/* TGSI_OPCODE_CRS */ -/* TGSI_OPCODE_SGN */ -/* TGSI_OPCODE_ABS */ -/* TGSI_OPCODE_NRM4 */ -/* TGSI_OPCODE_SINCOS */ -/* TGSI_OPCODE_REP */ -/* TGSI_OPCODE_ENDREP */ -/* TGSI_OPCODE_IF */ -/* TGSI_OPCODE_IFC */ -/* TGSI_OPCODE_ELSE */ -/* TGSI_OPCODE_ENDIF */ -/* TGSI_OPCODE_BREAK */ -/* TGSI_OPCODE_BREAKC */ -/* TGSI_OPCODE_MOVA */ -/* TGSI_OPCODE_LOGP */ - -#define TGSI_OPCODE_KIL 132 /* unpredicated kill */ -#define TGSI_OPCODE_END 133 /* aka HALT */ - -#define TGSI_OPCODE_LAST 134 - -#define TGSI_SAT_NONE 0 /* do not saturate */ -#define TGSI_SAT_ZERO_ONE 1 /* clamp to [0,1] */ -#define TGSI_SAT_MINUS_PLUS_ONE 2 /* clamp to [-1,1] */ - -/* - * Opcode is the operation code to execute. A given operation defines the - * semantics how the source registers (if any) are interpreted and what is - * written to the destination registers (if any) as a result of execution. - * - * NumDstRegs and NumSrcRegs is the number of destination and source registers, - * respectively. For a given operation code, those numbers are fixed and are - * present here only for convenience. - * - * If Extended is TRUE, it is now executed. - * - * Saturate controls how are final results in destination registers modified. - */ - -struct tgsi_instruction -{ - unsigned Type : 4; /* TGSI_TOKEN_TYPE_INSTRUCTION */ - unsigned Size : 8; /* UINT */ - unsigned Opcode : 8; /* TGSI_OPCODE_ */ - unsigned Saturate : 2; /* TGSI_SAT_ */ - unsigned NumDstRegs : 2; /* UINT */ - unsigned NumSrcRegs : 4; /* UINT */ - unsigned Padding : 3; - unsigned Extended : 1; /* BOOL */ -}; - -/* - * If tgsi_instruction::Extended is TRUE, tgsi_instruction_ext follows. - * - * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow. - * - * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow. - * - * tgsi_instruction::Size contains the total number of words that make the - * instruction, including the instruction word. - */ - -#define TGSI_INSTRUCTION_EXT_TYPE_NV 0 -#define TGSI_INSTRUCTION_EXT_TYPE_LABEL 1 -#define TGSI_INSTRUCTION_EXT_TYPE_TEXTURE 2 -#define TGSI_INSTRUCTION_EXT_TYPE_PREDICATE 3 - -struct tgsi_instruction_ext -{ - unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_ */ - unsigned Padding : 27; - unsigned Extended : 1; /* BOOL */ -}; - -/* - * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_NV, it should - * be cast to tgsi_instruction_ext_nv. - * - * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_LABEL, it - * should be cast to tgsi_instruction_ext_label. - * - * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_TEXTURE, it - * should be cast to tgsi_instruction_ext_texture. - * - * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_PREDICATE, it - * should be cast to tgsi_instruction_ext_predicate. - * - * If tgsi_instruction_ext::Extended is TRUE, another tgsi_instruction_ext - * follows. - */ - -#define TGSI_PRECISION_DEFAULT 0 -#define TGSI_PRECISION_FLOAT32 1 -#define TGSI_PRECISION_FLOAT16 2 -#define TGSI_PRECISION_FIXED12 3 - -#define TGSI_CC_GT 0 -#define TGSI_CC_EQ 1 -#define TGSI_CC_LT 2 -#define TGSI_CC_UN 3 -#define TGSI_CC_GE 4 -#define TGSI_CC_LE 5 -#define TGSI_CC_NE 6 -#define TGSI_CC_TR 7 -#define TGSI_CC_FL 8 - -#define TGSI_SWIZZLE_X 0 -#define TGSI_SWIZZLE_Y 1 -#define TGSI_SWIZZLE_Z 2 -#define TGSI_SWIZZLE_W 3 - -/* - * Precision controls the precision at which the operation should be executed. - * - * CondDstUpdate enables condition code register writes. When this field is - * TRUE, CondDstIndex specifies the index of the condition code register to - * update. - * - * CondFlowEnable enables conditional execution of the operation. When this - * field is TRUE, CondFlowIndex specifies the index of the condition code - * register to test against CondMask with component swizzle controled by - * CondSwizzleX, CondSwizzleY, CondSwizzleZ and CondSwizzleW. If the test fails, - * the operation is not executed. - */ - -struct tgsi_instruction_ext_nv -{ - unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_NV */ - unsigned Precision : 4; /* TGSI_PRECISION_ */ - unsigned CondDstIndex : 4; /* UINT */ - unsigned CondFlowIndex : 4; /* UINT */ - unsigned CondMask : 4; /* TGSI_CC_ */ - unsigned CondSwizzleX : 2; /* TGSI_SWIZZLE_ */ - unsigned CondSwizzleY : 2; /* TGSI_SWIZZLE_ */ - unsigned CondSwizzleZ : 2; /* TGSI_SWIZZLE_ */ - unsigned CondSwizzleW : 2; /* TGSI_SWIZZLE_ */ - unsigned CondDstUpdate : 1; /* BOOL */ - unsigned CondFlowEnable : 1; /* BOOL */ - unsigned Padding : 1; - unsigned Extended : 1; /* BOOL */ -}; - -struct tgsi_instruction_ext_label -{ - unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_LABEL */ - unsigned Label : 24; /* UINT */ - unsigned Padding : 3; - unsigned Extended : 1; /* BOOL */ -}; - -#define TGSI_TEXTURE_UNKNOWN 0 -#define TGSI_TEXTURE_1D 1 -#define TGSI_TEXTURE_2D 2 -#define TGSI_TEXTURE_3D 3 -#define TGSI_TEXTURE_CUBE 4 -#define TGSI_TEXTURE_RECT 5 -#define TGSI_TEXTURE_SHADOW1D 6 -#define TGSI_TEXTURE_SHADOW2D 7 -#define TGSI_TEXTURE_SHADOWRECT 8 - -struct tgsi_instruction_ext_texture -{ - unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_TEXTURE */ - unsigned Texture : 8; /* TGSI_TEXTURE_ */ - unsigned Padding : 19; - unsigned Extended : 1; /* BOOL */ -}; - -struct tgsi_instruction_ext_predicate -{ - unsigned Type : 4; /* TGSI_INSTRUCTION_EXT_TYPE_PREDICATE */ - unsigned PredDstIndex : 4; /* UINT */ - unsigned PredWriteMask : 4; /* TGSI_WRITEMASK_ */ - unsigned Padding : 19; - unsigned Extended : 1; /* BOOL */ -}; - -/* - * File specifies the register array to access. - * - * Index specifies the element number of a register in the register file. - * - * If Indirect is TRUE, Index should be offset by the X component of a source - * register that follows. The register can be now fetched into local storage - * for further processing. - * - * If Negate is TRUE, all components of the fetched register are negated. - * - * The fetched register components are swizzled according to SwizzleX, SwizzleY, - * SwizzleZ and SwizzleW. - * - * If Extended is TRUE, any further modifications to the source register are - * made to this temporary storage. - */ - -struct tgsi_src_register -{ - unsigned File : 4; /* TGSI_FILE_ */ - unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */ - unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */ - unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */ - unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */ - unsigned Negate : 1; /* BOOL */ - unsigned Indirect : 1; /* BOOL */ - unsigned Dimension : 1; /* BOOL */ - int Index : 16; /* SINT */ - unsigned Extended : 1; /* BOOL */ -}; - -/* - * If tgsi_src_register::Extended is TRUE, tgsi_src_register_ext follows. - * - * Then, if tgsi_src_register::Indirect is TRUE, another tgsi_src_register - * follows. - * - * Then, if tgsi_src_register::Dimension is TRUE, tgsi_dimension follows. - */ - -#define TGSI_SRC_REGISTER_EXT_TYPE_SWZ 0 -#define TGSI_SRC_REGISTER_EXT_TYPE_MOD 1 - -struct tgsi_src_register_ext -{ - unsigned Type : 4; /* TGSI_SRC_REGISTER_EXT_TYPE_ */ - unsigned Padding : 27; - unsigned Extended : 1; /* BOOL */ -}; - -/* - * If tgsi_src_register_ext::Type is TGSI_SRC_REGISTER_EXT_TYPE_SWZ, - * it should be cast to tgsi_src_register_ext_extswz. - * - * If tgsi_src_register_ext::Type is TGSI_SRC_REGISTER_EXT_TYPE_MOD, - * it should be cast to tgsi_src_register_ext_mod. - * - * If tgsi_dst_register_ext::Extended is TRUE, another tgsi_dst_register_ext - * follows. - */ - -#define TGSI_EXTSWIZZLE_X TGSI_SWIZZLE_X -#define TGSI_EXTSWIZZLE_Y TGSI_SWIZZLE_Y -#define TGSI_EXTSWIZZLE_Z TGSI_SWIZZLE_Z -#define TGSI_EXTSWIZZLE_W TGSI_SWIZZLE_W -#define TGSI_EXTSWIZZLE_ZERO 4 -#define TGSI_EXTSWIZZLE_ONE 5 - -/* - * ExtSwizzleX, ExtSwizzleY, ExtSwizzleZ and ExtSwizzleW swizzle the source - * register in an extended manner. - * - * NegateX, NegateY, NegateZ and NegateW negate individual components of the - * source register. - * - * ExtDivide specifies which component is used to divide all components of the - * source register. - */ - -struct tgsi_src_register_ext_swz -{ - unsigned Type : 4; /* TGSI_SRC_REGISTER_EXT_TYPE_SWZ */ - unsigned ExtSwizzleX : 4; /* TGSI_EXTSWIZZLE_ */ - unsigned ExtSwizzleY : 4; /* TGSI_EXTSWIZZLE_ */ - unsigned ExtSwizzleZ : 4; /* TGSI_EXTSWIZZLE_ */ - unsigned ExtSwizzleW : 4; /* TGSI_EXTSWIZZLE_ */ - unsigned NegateX : 1; /* BOOL */ - unsigned NegateY : 1; /* BOOL */ - unsigned NegateZ : 1; /* BOOL */ - unsigned NegateW : 1; /* BOOL */ - unsigned ExtDivide : 4; /* TGSI_EXTSWIZZLE_ */ - unsigned Padding : 3; - unsigned Extended : 1; /* BOOL */ -}; - -/** - * Extra src register modifiers - * - * If Complement is TRUE, the source register is modified by subtracting it - * from 1.0. - * - * If Bias is TRUE, the source register is modified by subtracting 0.5 from it. - * - * If Scale2X is TRUE, the source register is modified by multiplying it by 2.0. - * - * If Absolute is TRUE, the source register is modified by removing the sign. - * - * If Negate is TRUE, the source register is modified by negating it. - */ - -struct tgsi_src_register_ext_mod -{ - unsigned Type : 4; /* TGSI_SRC_REGISTER_EXT_TYPE_MOD */ - unsigned Complement : 1; /* BOOL */ - unsigned Bias : 1; /* BOOL */ - unsigned Scale2X : 1; /* BOOL */ - unsigned Absolute : 1; /* BOOL */ - unsigned Negate : 1; /* BOOL */ - unsigned Padding : 22; - unsigned Extended : 1; /* BOOL */ -}; - -struct tgsi_dimension -{ - unsigned Indirect : 1; /* BOOL */ - unsigned Dimension : 1; /* BOOL */ - unsigned Padding : 13; - int Index : 16; /* SINT */ - unsigned Extended : 1; /* BOOL */ -}; - -struct tgsi_dst_register -{ - unsigned File : 4; /* TGSI_FILE_ */ - unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */ - unsigned Indirect : 1; /* BOOL */ - unsigned Dimension : 1; /* BOOL */ - int Index : 16; /* SINT */ - unsigned Padding : 5; - unsigned Extended : 1; /* BOOL */ -}; - -/* - * If tgsi_dst_register::Extended is TRUE, tgsi_dst_register_ext follows. - * - * Then, if tgsi_dst_register::Indirect is TRUE, tgsi_src_register follows. - */ - -#define TGSI_DST_REGISTER_EXT_TYPE_CONDCODE 0 -#define TGSI_DST_REGISTER_EXT_TYPE_MODULATE 1 -#define TGSI_DST_REGISTER_EXT_TYPE_PREDICATE 2 - -struct tgsi_dst_register_ext -{ - unsigned Type : 4; /* TGSI_DST_REGISTER_EXT_TYPE_ */ - unsigned Padding : 27; - unsigned Extended : 1; /* BOOL */ -}; - -/** - * Extra destination register modifiers - * - * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_CONDCODE, - * it should be cast to tgsi_dst_register_ext_condcode. - * - * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_MODULATE, - * it should be cast to tgsi_dst_register_ext_modulate. - * - * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_PREDICATE, - * it should be cast to tgsi_dst_register_ext_predicate. - * - * If tgsi_dst_register_ext::Extended is TRUE, another tgsi_dst_register_ext - * follows. - */ -struct tgsi_dst_register_ext_concode -{ - unsigned Type : 4; /* TGSI_DST_REGISTER_EXT_TYPE_CONDCODE */ - unsigned CondMask : 4; /* TGSI_CC_ */ - unsigned CondSwizzleX : 2; /* TGSI_SWIZZLE_ */ - unsigned CondSwizzleY : 2; /* TGSI_SWIZZLE_ */ - unsigned CondSwizzleZ : 2; /* TGSI_SWIZZLE_ */ - unsigned CondSwizzleW : 2; /* TGSI_SWIZZLE_ */ - unsigned CondSrcIndex : 4; /* UINT */ - unsigned Padding : 11; - unsigned Extended : 1; /* BOOL */ -}; - -#define TGSI_MODULATE_1X 0 -#define TGSI_MODULATE_2X 1 -#define TGSI_MODULATE_4X 2 -#define TGSI_MODULATE_8X 3 -#define TGSI_MODULATE_HALF 4 -#define TGSI_MODULATE_QUARTER 5 -#define TGSI_MODULATE_EIGHTH 6 - -struct tgsi_dst_register_ext_modulate -{ - unsigned Type : 4; /* TGSI_DST_REGISTER_EXT_TYPE_MODULATE */ - unsigned Modulate : 4; /* TGSI_MODULATE_ */ - unsigned Padding : 23; - unsigned Extended : 1; /* BOOL */ -}; - -/* - * Currently, the following constraints apply. - * - * - PredSwizzleXYZW is either set to identity or replicate. - * - PredSrcIndex is 0. - */ - -struct tgsi_dst_register_ext_predicate -{ - unsigned Type : 4; /* TGSI_DST_REGISTER_EXT_TYPE_PREDICATE */ - unsigned PredSwizzleX : 2; /* TGSI_SWIZZLE_ */ - unsigned PredSwizzleY : 2; /* TGSI_SWIZZLE_ */ - unsigned PredSwizzleZ : 2; /* TGSI_SWIZZLE_ */ - unsigned PredSwizzleW : 2; /* TGSI_SWIZZLE_ */ - unsigned PredSrcIndex : 4; /* UINT */ - unsigned Negate : 1; /* BOOL */ - unsigned Padding : 14; - unsigned Extended : 1; /* BOOL */ -}; - - -#if defined __cplusplus -} // extern "C" -#endif // defined __cplusplus - -#endif // !defined TGSI_TOKEN_H - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_util.c b/src/mesa/pipe/tgsi/exec/tgsi_util.c deleted file mode 100644 index d1bc9355265..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_util.c +++ /dev/null @@ -1,270 +0,0 @@ -#include "tgsi_platform.h" -#include "tgsi_core.h" - -union pointer_hack -{ - void *pointer; - unsigned long long uint64; -}; - -void * -tgsi_align_128bit( - void *unaligned ) -{ - union pointer_hack ph; - - ph.uint64 = 0; - ph.pointer = unaligned; - ph.uint64 = (ph.uint64 + 15) & ~15; - return ph.pointer; -} - -unsigned -tgsi_util_get_src_register_swizzle( - const struct tgsi_src_register *reg, - unsigned component ) -{ - switch( component ) { - case 0: - return reg->SwizzleX; - case 1: - return reg->SwizzleY; - case 2: - return reg->SwizzleZ; - case 3: - return reg->SwizzleW; - default: - assert( 0 ); - } - return 0; -} - -unsigned -tgsi_util_get_src_register_extswizzle( - const struct tgsi_src_register_ext_swz *reg, - unsigned component ) -{ - switch( component ) { - case 0: - return reg->ExtSwizzleX; - case 1: - return reg->ExtSwizzleY; - case 2: - return reg->ExtSwizzleZ; - case 3: - return reg->ExtSwizzleW; - default: - assert( 0 ); - } - return 0; -} - -unsigned -tgsi_util_get_full_src_register_extswizzle( - const struct tgsi_full_src_register *reg, - unsigned component ) -{ - unsigned swizzle; - - /* - * First, calculate the extended swizzle for a given channel. This will give - * us either a channel index into the simple swizzle or a constant 1 or 0. - */ - swizzle = tgsi_util_get_src_register_extswizzle( - ®->SrcRegisterExtSwz, - component ); - - assert (TGSI_SWIZZLE_X == TGSI_EXTSWIZZLE_X); - assert (TGSI_SWIZZLE_Y == TGSI_EXTSWIZZLE_Y); - assert (TGSI_SWIZZLE_Z == TGSI_EXTSWIZZLE_Z); - assert (TGSI_SWIZZLE_W == TGSI_EXTSWIZZLE_W); - assert (TGSI_EXTSWIZZLE_ZERO > TGSI_SWIZZLE_W); - assert (TGSI_EXTSWIZZLE_ONE > TGSI_SWIZZLE_W); - - /* - * Second, calculate the simple swizzle for the unswizzled channel index. - * Leave the constants intact, they are not affected by the simple swizzle. - */ - if( swizzle <= TGSI_SWIZZLE_W ) { - swizzle = tgsi_util_get_src_register_swizzle( - ®->SrcRegister, - component ); - } - - return swizzle; -} - -void -tgsi_util_set_src_register_swizzle( - struct tgsi_src_register *reg, - unsigned swizzle, - unsigned component ) -{ - switch( component ) { - case 0: - reg->SwizzleX = swizzle; - break; - case 1: - reg->SwizzleY = swizzle; - break; - case 2: - reg->SwizzleZ = swizzle; - break; - case 3: - reg->SwizzleW = swizzle; - break; - default: - assert( 0 ); - } -} - -void -tgsi_util_set_src_register_extswizzle( - struct tgsi_src_register_ext_swz *reg, - unsigned swizzle, - unsigned component ) -{ - switch( component ) { - case 0: - reg->ExtSwizzleX = swizzle; - break; - case 1: - reg->ExtSwizzleY = swizzle; - break; - case 2: - reg->ExtSwizzleZ = swizzle; - break; - case 3: - reg->ExtSwizzleW = swizzle; - break; - default: - assert( 0 ); - } -} - -unsigned -tgsi_util_get_src_register_extnegate( - const struct tgsi_src_register_ext_swz *reg, - unsigned component ) -{ - switch( component ) { - case 0: - return reg->NegateX; - case 1: - return reg->NegateY; - case 2: - return reg->NegateZ; - case 3: - return reg->NegateW; - default: - assert( 0 ); - } - return 0; -} - -void -tgsi_util_set_src_register_extnegate( - struct tgsi_src_register_ext_swz *reg, - unsigned negate, - unsigned component ) -{ - switch( component ) { - case 0: - reg->NegateX = negate; - break; - case 1: - reg->NegateY = negate; - break; - case 2: - reg->NegateZ = negate; - break; - case 3: - reg->NegateW = negate; - break; - default: - assert( 0 ); - } -} - -unsigned -tgsi_util_get_full_src_register_sign_mode( - const struct tgsi_full_src_register *reg, - unsigned component ) -{ - unsigned sign_mode; - - if( reg->SrcRegisterExtMod.Absolute ) { - /* Consider only the post-abs negation. */ - - if( reg->SrcRegisterExtMod.Negate ) { - sign_mode = TGSI_UTIL_SIGN_SET; - } - else { - sign_mode = TGSI_UTIL_SIGN_CLEAR; - } - } - else { - /* Accumulate the three negations. */ - - unsigned negate; - - negate = reg->SrcRegister.Negate; - if( tgsi_util_get_src_register_extnegate( ®->SrcRegisterExtSwz, component ) ) { - negate = !negate; - } - if( reg->SrcRegisterExtMod.Negate ) { - negate = !negate; - } - - if( negate ) { - sign_mode = TGSI_UTIL_SIGN_TOGGLE; - } - else { - sign_mode = TGSI_UTIL_SIGN_KEEP; - } - } - - return sign_mode; -} - -void -tgsi_util_set_full_src_register_sign_mode( - struct tgsi_full_src_register *reg, - unsigned sign_mode ) -{ - reg->SrcRegisterExtSwz.NegateX = 0; - reg->SrcRegisterExtSwz.NegateY = 0; - reg->SrcRegisterExtSwz.NegateZ = 0; - reg->SrcRegisterExtSwz.NegateW = 0; - - switch (sign_mode) - { - case TGSI_UTIL_SIGN_CLEAR: - reg->SrcRegister.Negate = 0; - reg->SrcRegisterExtMod.Absolute = 1; - reg->SrcRegisterExtMod.Negate = 0; - break; - - case TGSI_UTIL_SIGN_SET: - reg->SrcRegister.Negate = 0; - reg->SrcRegisterExtMod.Absolute = 1; - reg->SrcRegisterExtMod.Negate = 1; - break; - - case TGSI_UTIL_SIGN_TOGGLE: - reg->SrcRegister.Negate = 1; - reg->SrcRegisterExtMod.Absolute = 0; - reg->SrcRegisterExtMod.Negate = 0; - break; - - case TGSI_UTIL_SIGN_KEEP: - reg->SrcRegister.Negate = 0; - reg->SrcRegisterExtMod.Absolute = 0; - reg->SrcRegisterExtMod.Negate = 0; - break; - - default: - assert( 0 ); - } -} - diff --git a/src/mesa/pipe/tgsi/exec/tgsi_util.h b/src/mesa/pipe/tgsi/exec/tgsi_util.h deleted file mode 100644 index ef14446f0e4..00000000000 --- a/src/mesa/pipe/tgsi/exec/tgsi_util.h +++ /dev/null @@ -1,70 +0,0 @@ -#if !defined TGSI_UTIL_H -#define TGSI_UTIL_H - -#if defined __cplusplus -extern "C" { -#endif // defined __cplusplus - -void * -tgsi_align_128bit( - void *unaligned ); - -unsigned -tgsi_util_get_src_register_swizzle( - const struct tgsi_src_register *reg, - unsigned component ); - -unsigned -tgsi_util_get_src_register_extswizzle( - const struct tgsi_src_register_ext_swz *reg, - unsigned component); - -unsigned -tgsi_util_get_full_src_register_extswizzle( - const struct tgsi_full_src_register *reg, - unsigned component ); - -void -tgsi_util_set_src_register_swizzle( - struct tgsi_src_register *reg, - unsigned swizzle, - unsigned component ); - -void -tgsi_util_set_src_register_extswizzle( - struct tgsi_src_register_ext_swz *reg, - unsigned swizzle, - unsigned component ); - -unsigned -tgsi_util_get_src_register_extnegate( - const struct tgsi_src_register_ext_swz *reg, - unsigned component ); - -void -tgsi_util_set_src_register_extnegate( - struct tgsi_src_register_ext_swz *reg, - unsigned negate, - unsigned component ); - -#define TGSI_UTIL_SIGN_CLEAR 0 /* Force positive */ -#define TGSI_UTIL_SIGN_SET 1 /* Force negative */ -#define TGSI_UTIL_SIGN_TOGGLE 2 /* Negate */ -#define TGSI_UTIL_SIGN_KEEP 3 /* No change */ - -unsigned -tgsi_util_get_full_src_register_sign_mode( - const struct tgsi_full_src_register *reg, - unsigned component ); - -void -tgsi_util_set_full_src_register_sign_mode( - struct tgsi_full_src_register *reg, - unsigned sign_mode ); - -#if defined __cplusplus -} // extern "C" -#endif // defined __cplusplus - -#endif // !defined TGSI_UTIL_H - diff --git a/src/mesa/pipe/tgsi/tgsi_platform.h b/src/mesa/pipe/tgsi/tgsi_platform.h deleted file mode 100644 index b98a1f21bec..00000000000 --- a/src/mesa/pipe/tgsi/tgsi_platform.h +++ /dev/null @@ -1,19 +0,0 @@ -#if !defined TGSI_PLATFORM_H -#define TGSI_PLATFORM_H - -#if defined __cplusplus -extern "C" { -#endif // defined __cplusplus - -#include "imports.h" -#include "mtypes.h" -#include "prog_instruction.h" -#include "program.h" -#include "pipe/p_compiler.h" - -#if defined __cplusplus -} // extern "C" -#endif // defined __cplusplus - -#endif // !defined TGSI_PLATFORM_H - diff --git a/src/mesa/pipe/tgsi/util/tgsi_build.c b/src/mesa/pipe/tgsi/util/tgsi_build.c new file mode 100644 index 00000000000..19b2aad921f --- /dev/null +++ b/src/mesa/pipe/tgsi/util/tgsi_build.c @@ -0,0 +1,1370 @@ +#include "pipe/p_util.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi_build.h" +#include "tgsi_parse.h" + +/* + * version + */ + +struct tgsi_version +tgsi_build_version( void ) +{ + struct tgsi_version version; + + version.MajorVersion = 1; + version.MinorVersion = 1; + version.Padding = 0; + + return version; +} + +/* + * header + */ + +struct tgsi_header +tgsi_build_header( void ) +{ + struct tgsi_header header; + + header.HeaderSize = 1; + header.BodySize = 0; + + return header; +} + +static void +header_headersize_grow( struct tgsi_header *header ) +{ + assert( header->HeaderSize < 0xFF ); + assert( header->BodySize == 0 ); + + header->HeaderSize++; +} + +static void +header_bodysize_grow( struct tgsi_header *header ) +{ + assert( header->BodySize < 0xFFFFFF ); + + header->BodySize++; +} + +struct tgsi_processor +tgsi_default_processor( void ) +{ + struct tgsi_processor processor; + + processor.Processor = TGSI_PROCESSOR_FRAGMENT; + processor.Padding = 0; + + return processor; +} + +struct tgsi_processor +tgsi_build_processor( + unsigned type, + struct tgsi_header *header ) +{ + struct tgsi_processor processor; + + processor = tgsi_default_processor(); + processor.Processor = type; + + header_headersize_grow( header ); + + return processor; +} + +/* + * declaration + */ + +struct tgsi_declaration +tgsi_default_declaration( void ) +{ + struct tgsi_declaration declaration; + + declaration.Type = TGSI_TOKEN_TYPE_DECLARATION; + declaration.Size = 1; + declaration.File = TGSI_FILE_NULL; + declaration.Declare = TGSI_DECLARE_RANGE; + declaration.UsageMask = TGSI_WRITEMASK_XYZW; + declaration.Interpolate = 0; + declaration.Semantic = 0; + declaration.Padding = 0; + declaration.Extended = 0; + + return declaration; +} + +struct tgsi_declaration +tgsi_build_declaration( + unsigned file, + unsigned declare, + unsigned usage_mask, + unsigned interpolate, + unsigned semantic, + struct tgsi_header *header ) +{ + struct tgsi_declaration declaration; + + assert( file <= TGSI_FILE_IMMEDIATE ); + assert( declare <= TGSI_DECLARE_MASK ); + + declaration = tgsi_default_declaration(); + declaration.File = file; + declaration.Declare = declare; + declaration.UsageMask = usage_mask; + declaration.Interpolate = interpolate; + declaration.Semantic = semantic; + + header_bodysize_grow( header ); + + return declaration; +} + +static void +declaration_grow( + struct tgsi_declaration *declaration, + struct tgsi_header *header ) +{ + assert( declaration->Size < 0xFF ); + + declaration->Size++; + + header_bodysize_grow( header ); +} + +struct tgsi_full_declaration +tgsi_default_full_declaration( void ) +{ + struct tgsi_full_declaration full_declaration; + + full_declaration.Declaration = tgsi_default_declaration(); + full_declaration.Interpolation = tgsi_default_declaration_interpolation(); + full_declaration.Semantic = tgsi_default_declaration_semantic(); + + return full_declaration; +} + +unsigned +tgsi_build_full_declaration( + const struct tgsi_full_declaration *full_decl, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ) +{ + unsigned size = 0; + struct tgsi_declaration *declaration; + + if( maxsize <= size ) + return 0; + declaration = (struct tgsi_declaration *) &tokens[size]; + size++; + + *declaration = tgsi_build_declaration( + full_decl->Declaration.File, + full_decl->Declaration.Declare, + full_decl->Declaration.UsageMask, + full_decl->Declaration.Interpolate, + full_decl->Declaration.Semantic, + header ); + + switch( full_decl->Declaration.Declare ) { + case TGSI_DECLARE_RANGE: + { + struct tgsi_declaration_range *dr; + + if( maxsize <= size ) + return 0; + dr = (struct tgsi_declaration_range *) &tokens[size]; + size++; + + *dr = tgsi_build_declaration_range( + full_decl->u.DeclarationRange.First, + full_decl->u.DeclarationRange.Last, + declaration, + header ); + break; + } + + case TGSI_DECLARE_MASK: + { + struct tgsi_declaration_mask *dm; + + if( maxsize <= size ) + return 0; + dm = (struct tgsi_declaration_mask *) &tokens[size]; + size++; + + *dm = tgsi_build_declaration_mask( + full_decl->u.DeclarationMask.Mask, + declaration, + header ); + break; + } + + default: + assert( 0 ); + } + + if( full_decl->Declaration.Interpolate ) { + struct tgsi_declaration_interpolation *di; + + if( maxsize <= size ) + return 0; + di = (struct tgsi_declaration_interpolation *) &tokens[size]; + size++; + + *di = tgsi_build_declaration_interpolation( + full_decl->Interpolation.Interpolate, + declaration, + header ); + } + + if( full_decl->Declaration.Semantic ) { + struct tgsi_declaration_semantic *ds; + + if( maxsize <= size ) + return 0; + ds = (struct tgsi_declaration_semantic *) &tokens[size]; + size++; + + *ds = tgsi_build_declaration_semantic( + full_decl->Semantic.SemanticName, + full_decl->Semantic.SemanticIndex, + declaration, + header ); + } + + return size; +} + +struct tgsi_declaration_range +tgsi_build_declaration_range( + unsigned first, + unsigned last, + struct tgsi_declaration *declaration, + struct tgsi_header *header ) +{ + struct tgsi_declaration_range declaration_range; + + assert( last >= first ); + assert( last <= 0xFFFF ); + + declaration_range.First = first; + declaration_range.Last = last; + + declaration_grow( declaration, header ); + + return declaration_range; +} + +struct tgsi_declaration_mask +tgsi_build_declaration_mask( + unsigned mask, + struct tgsi_declaration *declaration, + struct tgsi_header *header ) +{ + struct tgsi_declaration_mask declaration_mask; + + declaration_mask.Mask = mask; + + declaration_grow( declaration, header ); + + return declaration_mask; +} + +struct tgsi_declaration_interpolation +tgsi_default_declaration_interpolation( void ) +{ + struct tgsi_declaration_interpolation di; + + di.Interpolate = TGSI_INTERPOLATE_CONSTANT; + di.Padding = 0; + + return di; +} + +struct tgsi_declaration_interpolation +tgsi_build_declaration_interpolation( + unsigned interpolate, + struct tgsi_declaration *declaration, + struct tgsi_header *header ) +{ + struct tgsi_declaration_interpolation di; + + assert( interpolate <= TGSI_INTERPOLATE_PERSPECTIVE ); + + di = tgsi_default_declaration_interpolation(); + di.Interpolate = interpolate; + + declaration_grow( declaration, header ); + + return di; +} + +struct tgsi_declaration_semantic +tgsi_default_declaration_semantic( void ) +{ + struct tgsi_declaration_semantic ds; + + ds.SemanticName = TGSI_SEMANTIC_POSITION; + ds.SemanticIndex = 0; + ds.Padding = 0; + + return ds; +} + +struct tgsi_declaration_semantic +tgsi_build_declaration_semantic( + unsigned semantic_name, + unsigned semantic_index, + struct tgsi_declaration *declaration, + struct tgsi_header *header ) +{ + struct tgsi_declaration_semantic ds; + + assert( semantic_name <= TGSI_SEMANTIC_COUNT ); + assert( semantic_index <= 0xFFFF ); + + ds = tgsi_default_declaration_semantic(); + ds.SemanticName = semantic_name; + ds.SemanticIndex = semantic_index; + + declaration_grow( declaration, header ); + + return ds; +} + +/* + * immediate + */ + +struct tgsi_immediate +tgsi_default_immediate( void ) +{ + struct tgsi_immediate immediate; + + immediate.Type = TGSI_TOKEN_TYPE_IMMEDIATE; + immediate.Size = 1; + immediate.DataType = TGSI_IMM_FLOAT32; + immediate.Padding = 0; + immediate.Extended = 0; + + return immediate; +} + +struct tgsi_immediate +tgsi_build_immediate( + struct tgsi_header *header ) +{ + struct tgsi_immediate immediate; + + immediate = tgsi_default_immediate(); + + header_bodysize_grow( header ); + + return immediate; +} + +struct tgsi_full_immediate +tgsi_default_full_immediate( void ) +{ + struct tgsi_full_immediate fullimm; + + fullimm.Immediate = tgsi_default_immediate(); + fullimm.u.Pointer = (void *) 0; + + return fullimm; +} + +static void +immediate_grow( + struct tgsi_immediate *immediate, + struct tgsi_header *header ) +{ + assert( immediate->Size < 0xFF ); + + immediate->Size++; + + header_bodysize_grow( header ); +} + +struct tgsi_immediate_float32 +tgsi_build_immediate_float32( + float value, + struct tgsi_immediate *immediate, + struct tgsi_header *header ) +{ + struct tgsi_immediate_float32 immediate_float32; + + immediate_float32.Float = value; + + immediate_grow( immediate, header ); + + return immediate_float32; +} + +unsigned +tgsi_build_full_immediate( + const struct tgsi_full_immediate *full_imm, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ) +{ + unsigned size = 0, i; + struct tgsi_immediate *immediate; + + if( maxsize <= size ) + return 0; + immediate = (struct tgsi_immediate *) &tokens[size]; + size++; + + *immediate = tgsi_build_immediate( header ); + + for( i = 0; i < full_imm->Immediate.Size - 1; i++ ) { + struct tgsi_immediate_float32 *if32; + + if( maxsize <= size ) + return 0; + if32 = (struct tgsi_immediate_float32 *) &tokens[size]; + size++; + + *if32 = tgsi_build_immediate_float32( + full_imm->u.ImmediateFloat32[i].Float, + immediate, + header ); + } + + return size; +} + +/* + * instruction + */ + +struct tgsi_instruction +tgsi_default_instruction( void ) +{ + struct tgsi_instruction instruction; + + instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION; + instruction.Size = 1; + instruction.Opcode = TGSI_OPCODE_MOV; + instruction.Saturate = TGSI_SAT_NONE; + instruction.NumDstRegs = 1; + instruction.NumSrcRegs = 1; + instruction.Padding = 0; + instruction.Extended = 0; + + return instruction; +} + +struct tgsi_instruction +tgsi_build_instruction( + unsigned opcode, + unsigned saturate, + unsigned num_dst_regs, + unsigned num_src_regs, + struct tgsi_header *header ) +{ + struct tgsi_instruction instruction; + + assert (opcode <= TGSI_OPCODE_LAST); + assert (saturate <= TGSI_SAT_MINUS_PLUS_ONE); + assert (num_dst_regs <= 3); + assert (num_src_regs <= 15); + + instruction = tgsi_default_instruction(); + instruction.Opcode = opcode; + instruction.Saturate = saturate; + instruction.NumDstRegs = num_dst_regs; + instruction.NumSrcRegs = num_src_regs; + + header_bodysize_grow( header ); + + return instruction; +} + +static void +instruction_grow( + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + assert (instruction->Size < 0xFF); + + instruction->Size++; + + header_bodysize_grow( header ); +} + +struct tgsi_full_instruction +tgsi_default_full_instruction( void ) +{ + struct tgsi_full_instruction full_instruction; + unsigned i; + + full_instruction.Instruction = tgsi_default_instruction(); + full_instruction.InstructionExtNv = tgsi_default_instruction_ext_nv(); + full_instruction.InstructionExtLabel = tgsi_default_instruction_ext_label(); + full_instruction.InstructionExtTexture = tgsi_default_instruction_ext_texture(); + for( i = 0; i < TGSI_FULL_MAX_DST_REGISTERS; i++ ) { + full_instruction.FullDstRegisters[i] = tgsi_default_full_dst_register(); + } + for( i = 0; i < TGSI_FULL_MAX_SRC_REGISTERS; i++ ) { + full_instruction.FullSrcRegisters[i] = tgsi_default_full_src_register(); + } + + return full_instruction; +} + +unsigned +tgsi_build_full_instruction( + const struct tgsi_full_instruction *full_inst, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ) +{ + unsigned size = 0; + unsigned i; + struct tgsi_instruction *instruction; + struct tgsi_token *prev_token; + + if( maxsize <= size ) + return 0; + instruction = (struct tgsi_instruction *) &tokens[size]; + size++; + + *instruction = tgsi_build_instruction( + full_inst->Instruction.Opcode, + full_inst->Instruction.Saturate, + full_inst->Instruction.NumDstRegs, + full_inst->Instruction.NumSrcRegs, + header ); + prev_token = (struct tgsi_token *) instruction; + + if( tgsi_compare_instruction_ext_nv( + full_inst->InstructionExtNv, + tgsi_default_instruction_ext_nv() ) ) { + struct tgsi_instruction_ext_nv *instruction_ext_nv; + + if( maxsize <= size ) + return 0; + instruction_ext_nv = + (struct tgsi_instruction_ext_nv *) &tokens[size]; + size++; + + *instruction_ext_nv = tgsi_build_instruction_ext_nv( + full_inst->InstructionExtNv.Precision, + full_inst->InstructionExtNv.CondDstIndex, + full_inst->InstructionExtNv.CondFlowIndex, + full_inst->InstructionExtNv.CondMask, + full_inst->InstructionExtNv.CondSwizzleX, + full_inst->InstructionExtNv.CondSwizzleY, + full_inst->InstructionExtNv.CondSwizzleZ, + full_inst->InstructionExtNv.CondSwizzleW, + full_inst->InstructionExtNv.CondDstUpdate, + full_inst->InstructionExtNv.CondFlowEnable, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) instruction_ext_nv; + } + + if( tgsi_compare_instruction_ext_label( + full_inst->InstructionExtLabel, + tgsi_default_instruction_ext_label() ) ) { + struct tgsi_instruction_ext_label *instruction_ext_label; + + if( maxsize <= size ) + return 0; + instruction_ext_label = + (struct tgsi_instruction_ext_label *) &tokens[size]; + size++; + + *instruction_ext_label = tgsi_build_instruction_ext_label( + full_inst->InstructionExtLabel.Label, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) instruction_ext_label; + } + + if( tgsi_compare_instruction_ext_texture( + full_inst->InstructionExtTexture, + tgsi_default_instruction_ext_texture() ) ) { + struct tgsi_instruction_ext_texture *instruction_ext_texture; + + if( maxsize <= size ) + return 0; + instruction_ext_texture = + (struct tgsi_instruction_ext_texture *) &tokens[size]; + size++; + + *instruction_ext_texture = tgsi_build_instruction_ext_texture( + full_inst->InstructionExtTexture.Texture, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) instruction_ext_texture; + } + + for( i = 0; i < full_inst->Instruction.NumDstRegs; i++ ) { + const struct tgsi_full_dst_register *reg = &full_inst->FullDstRegisters[i]; + struct tgsi_dst_register *dst_register; + struct tgsi_token *prev_token; + + if( maxsize <= size ) + return 0; + dst_register = (struct tgsi_dst_register *) &tokens[size]; + size++; + + *dst_register = tgsi_build_dst_register( + reg->DstRegister.File, + reg->DstRegister.WriteMask, + reg->DstRegister.Index, + instruction, + header ); + prev_token = (struct tgsi_token *) dst_register; + + if( tgsi_compare_dst_register_ext_concode( + reg->DstRegisterExtConcode, + tgsi_default_dst_register_ext_concode() ) ) { + struct tgsi_dst_register_ext_concode *dst_register_ext_concode; + + if( maxsize <= size ) + return 0; + dst_register_ext_concode = + (struct tgsi_dst_register_ext_concode *) &tokens[size]; + size++; + + *dst_register_ext_concode = tgsi_build_dst_register_ext_concode( + reg->DstRegisterExtConcode.CondMask, + reg->DstRegisterExtConcode.CondSwizzleX, + reg->DstRegisterExtConcode.CondSwizzleY, + reg->DstRegisterExtConcode.CondSwizzleZ, + reg->DstRegisterExtConcode.CondSwizzleW, + reg->DstRegisterExtConcode.CondSrcIndex, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) dst_register_ext_concode; + } + + if( tgsi_compare_dst_register_ext_modulate( + reg->DstRegisterExtModulate, + tgsi_default_dst_register_ext_modulate() ) ) { + struct tgsi_dst_register_ext_modulate *dst_register_ext_modulate; + + if( maxsize <= size ) + return 0; + dst_register_ext_modulate = + (struct tgsi_dst_register_ext_modulate *) &tokens[size]; + size++; + + *dst_register_ext_modulate = tgsi_build_dst_register_ext_modulate( + reg->DstRegisterExtModulate.Modulate, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) dst_register_ext_modulate; + } + } + + for( i = 0; i < full_inst->Instruction.NumSrcRegs; i++ ) { + const struct tgsi_full_src_register *reg = &full_inst->FullSrcRegisters[i]; + struct tgsi_src_register *src_register; + struct tgsi_token *prev_token; + + if( maxsize <= size ) + return 0; + src_register = (struct tgsi_src_register *) &tokens[size]; + size++; + + *src_register = tgsi_build_src_register( + reg->SrcRegister.File, + reg->SrcRegister.SwizzleX, + reg->SrcRegister.SwizzleY, + reg->SrcRegister.SwizzleZ, + reg->SrcRegister.SwizzleW, + reg->SrcRegister.Negate, + reg->SrcRegister.Indirect, + reg->SrcRegister.Dimension, + reg->SrcRegister.Index, + instruction, + header ); + prev_token = (struct tgsi_token *) src_register; + + if( tgsi_compare_src_register_ext_swz( + reg->SrcRegisterExtSwz, + tgsi_default_src_register_ext_swz() ) ) { + struct tgsi_src_register_ext_swz *src_register_ext_swz; + + if( maxsize <= size ) + return 0; + src_register_ext_swz = + (struct tgsi_src_register_ext_swz *) &tokens[size]; + size++; + + *src_register_ext_swz = tgsi_build_src_register_ext_swz( + reg->SrcRegisterExtSwz.ExtSwizzleX, + reg->SrcRegisterExtSwz.ExtSwizzleY, + reg->SrcRegisterExtSwz.ExtSwizzleZ, + reg->SrcRegisterExtSwz.ExtSwizzleW, + reg->SrcRegisterExtSwz.NegateX, + reg->SrcRegisterExtSwz.NegateY, + reg->SrcRegisterExtSwz.NegateZ, + reg->SrcRegisterExtSwz.NegateW, + reg->SrcRegisterExtSwz.ExtDivide, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) src_register_ext_swz; + } + + if( tgsi_compare_src_register_ext_mod( + reg->SrcRegisterExtMod, + tgsi_default_src_register_ext_mod() ) ) { + struct tgsi_src_register_ext_mod *src_register_ext_mod; + + if( maxsize <= size ) + return 0; + src_register_ext_mod = + (struct tgsi_src_register_ext_mod *) &tokens[size]; + size++; + + *src_register_ext_mod = tgsi_build_src_register_ext_mod( + reg->SrcRegisterExtMod.Complement, + reg->SrcRegisterExtMod.Bias, + reg->SrcRegisterExtMod.Scale2X, + reg->SrcRegisterExtMod.Absolute, + reg->SrcRegisterExtMod.Negate, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) src_register_ext_mod; + } + + if( reg->SrcRegister.Indirect ) { + struct tgsi_src_register *ind; + + if( maxsize <= size ) + return 0; + ind = (struct tgsi_src_register *) &tokens[size]; + size++; + + *ind = tgsi_build_src_register( + reg->SrcRegisterInd.File, + reg->SrcRegisterInd.SwizzleX, + reg->SrcRegisterInd.SwizzleY, + reg->SrcRegisterInd.SwizzleZ, + reg->SrcRegisterInd.SwizzleW, + reg->SrcRegisterInd.Negate, + reg->SrcRegisterInd.Indirect, + reg->SrcRegisterInd.Dimension, + reg->SrcRegisterInd.Index, + instruction, + header ); + } + + if( reg->SrcRegister.Dimension ) { + struct tgsi_dimension *dim; + + assert( !reg->SrcRegisterDim.Dimension ); + + if( maxsize <= size ) + return 0; + dim = (struct tgsi_dimension *) &tokens[size]; + size++; + + *dim = tgsi_build_dimension( + reg->SrcRegisterDim.Indirect, + reg->SrcRegisterDim.Index, + instruction, + header ); + + if( reg->SrcRegisterDim.Indirect ) { + struct tgsi_src_register *ind; + + if( maxsize <= size ) + return 0; + ind = (struct tgsi_src_register *) &tokens[size]; + size++; + + *ind = tgsi_build_src_register( + reg->SrcRegisterDimInd.File, + reg->SrcRegisterDimInd.SwizzleX, + reg->SrcRegisterDimInd.SwizzleY, + reg->SrcRegisterDimInd.SwizzleZ, + reg->SrcRegisterDimInd.SwizzleW, + reg->SrcRegisterDimInd.Negate, + reg->SrcRegisterDimInd.Indirect, + reg->SrcRegisterDimInd.Dimension, + reg->SrcRegisterDimInd.Index, + instruction, + header ); + } + } + } + + return size; +} + +struct tgsi_instruction_ext_nv +tgsi_default_instruction_ext_nv( void ) +{ + struct tgsi_instruction_ext_nv instruction_ext_nv; + + instruction_ext_nv.Type = TGSI_INSTRUCTION_EXT_TYPE_NV; + instruction_ext_nv.Precision = TGSI_PRECISION_DEFAULT; + instruction_ext_nv.CondDstIndex = 0; + instruction_ext_nv.CondFlowIndex = 0; + instruction_ext_nv.CondMask = TGSI_CC_TR; + instruction_ext_nv.CondSwizzleX = TGSI_SWIZZLE_X; + instruction_ext_nv.CondSwizzleY = TGSI_SWIZZLE_Y; + instruction_ext_nv.CondSwizzleZ = TGSI_SWIZZLE_Z; + instruction_ext_nv.CondSwizzleW = TGSI_SWIZZLE_W; + instruction_ext_nv.CondDstUpdate = 0; + instruction_ext_nv.CondFlowEnable = 0; + instruction_ext_nv.Padding = 0; + instruction_ext_nv.Extended = 0; + + return instruction_ext_nv; +} + +union token_u32 +{ + unsigned u32; +}; + +unsigned +tgsi_compare_instruction_ext_nv( + struct tgsi_instruction_ext_nv a, + struct tgsi_instruction_ext_nv b ) +{ + a.Padding = b.Padding = 0; + a.Extended = b.Extended = 0; + return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; +} + +struct tgsi_instruction_ext_nv +tgsi_build_instruction_ext_nv( + unsigned precision, + unsigned cond_dst_index, + unsigned cond_flow_index, + unsigned cond_mask, + unsigned cond_swizzle_x, + unsigned cond_swizzle_y, + unsigned cond_swizzle_z, + unsigned cond_swizzle_w, + unsigned cond_dst_update, + unsigned cond_flow_update, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_instruction_ext_nv instruction_ext_nv; + + instruction_ext_nv = tgsi_default_instruction_ext_nv(); + instruction_ext_nv.Precision = precision; + instruction_ext_nv.CondDstIndex = cond_dst_index; + instruction_ext_nv.CondFlowIndex = cond_flow_index; + instruction_ext_nv.CondMask = cond_mask; + instruction_ext_nv.CondSwizzleX = cond_swizzle_x; + instruction_ext_nv.CondSwizzleY = cond_swizzle_y; + instruction_ext_nv.CondSwizzleZ = cond_swizzle_z; + instruction_ext_nv.CondSwizzleW = cond_swizzle_w; + instruction_ext_nv.CondDstUpdate = cond_dst_update; + instruction_ext_nv.CondFlowEnable = cond_flow_update; + + prev_token->Extended = 1; + instruction_grow( instruction, header ); + + return instruction_ext_nv; +} + +struct tgsi_instruction_ext_label +tgsi_default_instruction_ext_label( void ) +{ + struct tgsi_instruction_ext_label instruction_ext_label; + + instruction_ext_label.Type = TGSI_INSTRUCTION_EXT_TYPE_LABEL; + instruction_ext_label.Label = 0; + instruction_ext_label.Padding = 0; + instruction_ext_label.Extended = 0; + + return instruction_ext_label; +} + +unsigned +tgsi_compare_instruction_ext_label( + struct tgsi_instruction_ext_label a, + struct tgsi_instruction_ext_label b ) +{ + a.Padding = b.Padding = 0; + a.Extended = b.Extended = 0; + return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; +} + +struct tgsi_instruction_ext_label +tgsi_build_instruction_ext_label( + unsigned label, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_instruction_ext_label instruction_ext_label; + + instruction_ext_label = tgsi_default_instruction_ext_label(); + instruction_ext_label.Label = label; + + prev_token->Extended = 1; + instruction_grow( instruction, header ); + + return instruction_ext_label; +} + +struct tgsi_instruction_ext_texture +tgsi_default_instruction_ext_texture( void ) +{ + struct tgsi_instruction_ext_texture instruction_ext_texture; + + instruction_ext_texture.Type = TGSI_INSTRUCTION_EXT_TYPE_TEXTURE; + instruction_ext_texture.Texture = TGSI_TEXTURE_UNKNOWN; + instruction_ext_texture.Padding = 0; + instruction_ext_texture.Extended = 0; + + return instruction_ext_texture; +} + +unsigned +tgsi_compare_instruction_ext_texture( + struct tgsi_instruction_ext_texture a, + struct tgsi_instruction_ext_texture b ) +{ + a.Padding = b.Padding = 0; + a.Extended = b.Extended = 0; + return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; +} + +struct tgsi_instruction_ext_texture +tgsi_build_instruction_ext_texture( + unsigned texture, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_instruction_ext_texture instruction_ext_texture; + + instruction_ext_texture = tgsi_default_instruction_ext_texture(); + instruction_ext_texture.Texture = texture; + + prev_token->Extended = 1; + instruction_grow( instruction, header ); + + return instruction_ext_texture; +} + +struct tgsi_src_register +tgsi_default_src_register( void ) +{ + struct tgsi_src_register src_register; + + src_register.File = TGSI_FILE_NULL; + src_register.SwizzleX = TGSI_SWIZZLE_X; + src_register.SwizzleY = TGSI_SWIZZLE_Y; + src_register.SwizzleZ = TGSI_SWIZZLE_Z; + src_register.SwizzleW = TGSI_SWIZZLE_W; + src_register.Negate = 0; + src_register.Indirect = 0; + src_register.Dimension = 0; + src_register.Index = 0; + src_register.Extended = 0; + + return src_register; +} + +struct tgsi_src_register +tgsi_build_src_register( + unsigned file, + unsigned swizzle_x, + unsigned swizzle_y, + unsigned swizzle_z, + unsigned swizzle_w, + unsigned negate, + unsigned indirect, + unsigned dimension, + int index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_src_register src_register; + + assert( file <= TGSI_FILE_IMMEDIATE ); + assert( swizzle_x <= TGSI_SWIZZLE_W ); + assert( swizzle_y <= TGSI_SWIZZLE_W ); + assert( swizzle_z <= TGSI_SWIZZLE_W ); + assert( swizzle_w <= TGSI_SWIZZLE_W ); + assert( negate <= 1 ); + assert( index >= -0x8000 && index <= 0x7FFF ); + + src_register = tgsi_default_src_register(); + src_register.File = file; + src_register.SwizzleX = swizzle_x; + src_register.SwizzleY = swizzle_y; + src_register.SwizzleZ = swizzle_z; + src_register.SwizzleW = swizzle_w; + src_register.Negate = negate; + src_register.Indirect = indirect; + src_register.Dimension = dimension; + src_register.Index = index; + + instruction_grow( instruction, header ); + + return src_register; +} + +struct tgsi_full_src_register +tgsi_default_full_src_register( void ) +{ + struct tgsi_full_src_register full_src_register; + + full_src_register.SrcRegister = tgsi_default_src_register(); + full_src_register.SrcRegisterExtSwz = tgsi_default_src_register_ext_swz(); + full_src_register.SrcRegisterExtMod = tgsi_default_src_register_ext_mod(); + full_src_register.SrcRegisterInd = tgsi_default_src_register(); + full_src_register.SrcRegisterDim = tgsi_default_dimension(); + full_src_register.SrcRegisterDimInd = tgsi_default_src_register(); + + return full_src_register; +} + +struct tgsi_src_register_ext_swz +tgsi_default_src_register_ext_swz( void ) +{ + struct tgsi_src_register_ext_swz src_register_ext_swz; + + src_register_ext_swz.Type = TGSI_SRC_REGISTER_EXT_TYPE_SWZ; + src_register_ext_swz.ExtSwizzleX = TGSI_EXTSWIZZLE_X; + src_register_ext_swz.ExtSwizzleY = TGSI_EXTSWIZZLE_Y; + src_register_ext_swz.ExtSwizzleZ = TGSI_EXTSWIZZLE_Z; + src_register_ext_swz.ExtSwizzleW = TGSI_EXTSWIZZLE_W; + src_register_ext_swz.NegateX = 0; + src_register_ext_swz.NegateY = 0; + src_register_ext_swz.NegateZ = 0; + src_register_ext_swz.NegateW = 0; + src_register_ext_swz.ExtDivide = TGSI_EXTSWIZZLE_ONE; + src_register_ext_swz.Padding = 0; + src_register_ext_swz.Extended = 0; + + return src_register_ext_swz; +} + +unsigned +tgsi_compare_src_register_ext_swz( + struct tgsi_src_register_ext_swz a, + struct tgsi_src_register_ext_swz b ) +{ + a.Padding = b.Padding = 0; + a.Extended = b.Extended = 0; + return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; +} + +struct tgsi_src_register_ext_swz +tgsi_build_src_register_ext_swz( + unsigned ext_swizzle_x, + unsigned ext_swizzle_y, + unsigned ext_swizzle_z, + unsigned ext_swizzle_w, + unsigned negate_x, + unsigned negate_y, + unsigned negate_z, + unsigned negate_w, + unsigned ext_divide, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_src_register_ext_swz src_register_ext_swz; + + assert( ext_swizzle_x <= TGSI_EXTSWIZZLE_ONE ); + assert( ext_swizzle_y <= TGSI_EXTSWIZZLE_ONE ); + assert( ext_swizzle_z <= TGSI_EXTSWIZZLE_ONE ); + assert( ext_swizzle_w <= TGSI_EXTSWIZZLE_ONE ); + assert( negate_x <= 1 ); + assert( negate_y <= 1 ); + assert( negate_z <= 1 ); + assert( negate_w <= 1 ); + assert( ext_divide <= TGSI_EXTSWIZZLE_ONE ); + + src_register_ext_swz = tgsi_default_src_register_ext_swz(); + src_register_ext_swz.ExtSwizzleX = ext_swizzle_x; + src_register_ext_swz.ExtSwizzleY = ext_swizzle_y; + src_register_ext_swz.ExtSwizzleZ = ext_swizzle_z; + src_register_ext_swz.ExtSwizzleW = ext_swizzle_w; + src_register_ext_swz.NegateX = negate_x; + src_register_ext_swz.NegateY = negate_y; + src_register_ext_swz.NegateZ = negate_z; + src_register_ext_swz.NegateW = negate_w; + src_register_ext_swz.ExtDivide = ext_divide; + + prev_token->Extended = 1; + instruction_grow( instruction, header ); + + return src_register_ext_swz; +} + +struct tgsi_src_register_ext_mod +tgsi_default_src_register_ext_mod( void ) +{ + struct tgsi_src_register_ext_mod src_register_ext_mod; + + src_register_ext_mod.Type = TGSI_SRC_REGISTER_EXT_TYPE_MOD; + src_register_ext_mod.Complement = 0; + src_register_ext_mod.Bias = 0; + src_register_ext_mod.Scale2X = 0; + src_register_ext_mod.Absolute = 0; + src_register_ext_mod.Negate = 0; + src_register_ext_mod.Padding = 0; + src_register_ext_mod.Extended = 0; + + return src_register_ext_mod; +} + +unsigned +tgsi_compare_src_register_ext_mod( + struct tgsi_src_register_ext_mod a, + struct tgsi_src_register_ext_mod b ) +{ + a.Padding = b.Padding = 0; + a.Extended = b.Extended = 0; + return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; +} + +struct tgsi_src_register_ext_mod +tgsi_build_src_register_ext_mod( + unsigned complement, + unsigned bias, + unsigned scale_2x, + unsigned absolute, + unsigned negate, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_src_register_ext_mod src_register_ext_mod; + + assert( complement <= 1 ); + assert( bias <= 1 ); + assert( scale_2x <= 1 ); + assert( absolute <= 1 ); + assert( negate <= 1 ); + + src_register_ext_mod = tgsi_default_src_register_ext_mod(); + src_register_ext_mod.Complement = complement; + src_register_ext_mod.Bias = bias; + src_register_ext_mod.Scale2X = scale_2x; + src_register_ext_mod.Absolute = absolute; + src_register_ext_mod.Negate = negate; + + prev_token->Extended = 1; + instruction_grow( instruction, header ); + + return src_register_ext_mod; +} + +struct tgsi_dimension +tgsi_default_dimension( void ) +{ + struct tgsi_dimension dimension; + + dimension.Indirect = 0; + dimension.Dimension = 0; + dimension.Padding = 0; + dimension.Index = 0; + dimension.Extended = 0; + + return dimension; +} + +struct tgsi_dimension +tgsi_build_dimension( + unsigned indirect, + unsigned index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_dimension dimension; + + dimension = tgsi_default_dimension(); + dimension.Indirect = indirect; + dimension.Index = index; + + instruction_grow( instruction, header ); + + return dimension; +} + +struct tgsi_dst_register +tgsi_default_dst_register( void ) +{ + struct tgsi_dst_register dst_register; + + dst_register.File = TGSI_FILE_NULL; + dst_register.WriteMask = TGSI_WRITEMASK_XYZW; + dst_register.Indirect = 0; + dst_register.Dimension = 0; + dst_register.Index = 0; + dst_register.Padding = 0; + dst_register.Extended = 0; + + return dst_register; +} + +struct tgsi_dst_register +tgsi_build_dst_register( + unsigned file, + unsigned mask, + int index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_dst_register dst_register; + + assert( file <= TGSI_FILE_IMMEDIATE ); + assert( mask <= TGSI_WRITEMASK_XYZW ); + assert( index >= -32768 && index <= 32767 ); + + dst_register = tgsi_default_dst_register(); + dst_register.File = file; + dst_register.WriteMask = mask; + dst_register.Index = index; + + instruction_grow( instruction, header ); + + return dst_register; +} + +struct tgsi_full_dst_register +tgsi_default_full_dst_register( void ) +{ + struct tgsi_full_dst_register full_dst_register; + + full_dst_register.DstRegister = tgsi_default_dst_register(); + full_dst_register.DstRegisterExtConcode = + tgsi_default_dst_register_ext_concode(); + full_dst_register.DstRegisterExtModulate = + tgsi_default_dst_register_ext_modulate(); + + return full_dst_register; +} + +struct tgsi_dst_register_ext_concode +tgsi_default_dst_register_ext_concode( void ) +{ + struct tgsi_dst_register_ext_concode dst_register_ext_concode; + + dst_register_ext_concode.Type = TGSI_DST_REGISTER_EXT_TYPE_CONDCODE; + dst_register_ext_concode.CondMask = TGSI_CC_TR; + dst_register_ext_concode.CondSwizzleX = TGSI_SWIZZLE_X; + dst_register_ext_concode.CondSwizzleY = TGSI_SWIZZLE_Y; + dst_register_ext_concode.CondSwizzleZ = TGSI_SWIZZLE_Z; + dst_register_ext_concode.CondSwizzleW = TGSI_SWIZZLE_W; + dst_register_ext_concode.CondSrcIndex = 0; + dst_register_ext_concode.Padding = 0; + dst_register_ext_concode.Extended = 0; + + return dst_register_ext_concode; +} + +unsigned +tgsi_compare_dst_register_ext_concode( + struct tgsi_dst_register_ext_concode a, + struct tgsi_dst_register_ext_concode b ) +{ + a.Padding = b.Padding = 0; + a.Extended = b.Extended = 0; + return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; +} + +struct tgsi_dst_register_ext_concode +tgsi_build_dst_register_ext_concode( + unsigned cc, + unsigned swizzle_x, + unsigned swizzle_y, + unsigned swizzle_z, + unsigned swizzle_w, + int index, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_dst_register_ext_concode dst_register_ext_concode; + + assert( cc <= TGSI_CC_FL ); + assert( swizzle_x <= TGSI_SWIZZLE_W ); + assert( swizzle_y <= TGSI_SWIZZLE_W ); + assert( swizzle_z <= TGSI_SWIZZLE_W ); + assert( swizzle_w <= TGSI_SWIZZLE_W ); + assert( index >= -32768 && index <= 32767 ); + + dst_register_ext_concode = tgsi_default_dst_register_ext_concode(); + dst_register_ext_concode.CondMask = cc; + dst_register_ext_concode.CondSwizzleX = swizzle_x; + dst_register_ext_concode.CondSwizzleY = swizzle_y; + dst_register_ext_concode.CondSwizzleZ = swizzle_z; + dst_register_ext_concode.CondSwizzleW = swizzle_w; + dst_register_ext_concode.CondSrcIndex = index; + + prev_token->Extended = 1; + instruction_grow( instruction, header ); + + return dst_register_ext_concode; +} + +struct tgsi_dst_register_ext_modulate +tgsi_default_dst_register_ext_modulate( void ) +{ + struct tgsi_dst_register_ext_modulate dst_register_ext_modulate; + + dst_register_ext_modulate.Type = TGSI_DST_REGISTER_EXT_TYPE_MODULATE; + dst_register_ext_modulate.Modulate = TGSI_MODULATE_1X; + dst_register_ext_modulate.Padding = 0; + dst_register_ext_modulate.Extended = 0; + + return dst_register_ext_modulate; +} + +unsigned +tgsi_compare_dst_register_ext_modulate( + struct tgsi_dst_register_ext_modulate a, + struct tgsi_dst_register_ext_modulate b ) +{ + a.Padding = b.Padding = 0; + a.Extended = b.Extended = 0; + return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32; +} + +struct tgsi_dst_register_ext_modulate +tgsi_build_dst_register_ext_modulate( + unsigned modulate, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_dst_register_ext_modulate dst_register_ext_modulate; + + assert( modulate <= TGSI_MODULATE_EIGHTH ); + + dst_register_ext_modulate = tgsi_default_dst_register_ext_modulate(); + dst_register_ext_modulate.Modulate = modulate; + + prev_token->Extended = 1; + instruction_grow( instruction, header ); + + return dst_register_ext_modulate; +} + diff --git a/src/mesa/pipe/tgsi/util/tgsi_build.h b/src/mesa/pipe/tgsi/util/tgsi_build.h new file mode 100644 index 00000000000..116c78abf34 --- /dev/null +++ b/src/mesa/pipe/tgsi/util/tgsi_build.h @@ -0,0 +1,320 @@ +#if !defined TGSI_BUILD_H +#define TGSI_BUILD_H + +#if defined __cplusplus +extern "C" { +#endif // defined __cplusplus + +/* + * version + */ + +struct tgsi_version +tgsi_build_version( void ); + +/* + * header + */ + +struct tgsi_header +tgsi_build_header( void ); + +struct tgsi_processor +tgsi_default_processor( void ); + +struct tgsi_processor +tgsi_build_processor( + unsigned processor, + struct tgsi_header *header ); + +/* + * declaration + */ + +struct tgsi_declaration +tgsi_default_declaration( void ); + +struct tgsi_declaration +tgsi_build_declaration( + unsigned file, + unsigned declare, + unsigned usage_mask, + unsigned interpolate, + unsigned semantic, + struct tgsi_header *header ); + +struct tgsi_full_declaration +tgsi_default_full_declaration( void ); + +unsigned +tgsi_build_full_declaration( + const struct tgsi_full_declaration *full_decl, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ); + +struct tgsi_declaration_range +tgsi_build_declaration_range( + unsigned first, + unsigned last, + struct tgsi_declaration *declaration, + struct tgsi_header *header ); + +struct tgsi_declaration_mask +tgsi_build_declaration_mask( + unsigned mask, + struct tgsi_declaration *declaration, + struct tgsi_header *header ); + +struct tgsi_declaration_interpolation +tgsi_default_declaration_interpolation( void ); + +struct tgsi_declaration_interpolation +tgsi_build_declaration_interpolation( + unsigned interpolate, + struct tgsi_declaration *declaration, + struct tgsi_header *header ); + +struct tgsi_declaration_semantic +tgsi_default_declaration_semantic( void ); + +struct tgsi_declaration_semantic +tgsi_build_declaration_semantic( + unsigned semantic_name, + unsigned semantic_index, + struct tgsi_declaration *declaration, + struct tgsi_header *header ); + +/* + * immediate + */ + +struct tgsi_immediate +tgsi_default_immediate( void ); + +struct tgsi_immediate +tgsi_build_immediate( + struct tgsi_header *header ); + +struct tgsi_full_immediate +tgsi_default_full_immediate( void ); + +struct tgsi_immediate_float32 +tgsi_build_immediate_float32( + float value, + struct tgsi_immediate *immediate, + struct tgsi_header *header ); + +unsigned +tgsi_build_full_immediate( + const struct tgsi_full_immediate *full_imm, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ); + +/* + * instruction + */ + +struct tgsi_instruction +tgsi_default_instruction( void ); + +struct tgsi_instruction +tgsi_build_instruction( + unsigned opcode, + unsigned saturate, + unsigned num_dst_regs, + unsigned num_src_regs, + struct tgsi_header *header ); + +struct tgsi_full_instruction +tgsi_default_full_instruction( void ); + +unsigned +tgsi_build_full_instruction( + const struct tgsi_full_instruction *full_inst, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ); + +struct tgsi_instruction_ext_nv +tgsi_default_instruction_ext_nv( void ); + +unsigned +tgsi_compare_instruction_ext_nv( + struct tgsi_instruction_ext_nv a, + struct tgsi_instruction_ext_nv b ); + +struct tgsi_instruction_ext_nv +tgsi_build_instruction_ext_nv( + unsigned precision, + unsigned cond_dst_index, + unsigned cond_flow_index, + unsigned cond_mask, + unsigned cond_swizzle_x, + unsigned cond_swizzle_y, + unsigned cond_swizzle_z, + unsigned cond_swizzle_w, + unsigned cond_dst_update, + unsigned cond_flow_update, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_instruction_ext_label +tgsi_default_instruction_ext_label( void ); + +unsigned +tgsi_compare_instruction_ext_label( + struct tgsi_instruction_ext_label a, + struct tgsi_instruction_ext_label b ); + +struct tgsi_instruction_ext_label +tgsi_build_instruction_ext_label( + unsigned label, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_instruction_ext_texture +tgsi_default_instruction_ext_texture( void ); + +unsigned +tgsi_compare_instruction_ext_texture( + struct tgsi_instruction_ext_texture a, + struct tgsi_instruction_ext_texture b ); + +struct tgsi_instruction_ext_texture +tgsi_build_instruction_ext_texture( + unsigned texture, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_src_register +tgsi_default_src_register( void ); + +struct tgsi_src_register +tgsi_build_src_register( + unsigned file, + unsigned swizzle_x, + unsigned swizzle_y, + unsigned swizzle_z, + unsigned swizzle_w, + unsigned negate, + unsigned indirect, + unsigned dimension, + int index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_full_src_register +tgsi_default_full_src_register( void ); + +struct tgsi_src_register_ext_swz +tgsi_default_src_register_ext_swz( void ); + +unsigned +tgsi_compare_src_register_ext_swz( + struct tgsi_src_register_ext_swz a, + struct tgsi_src_register_ext_swz b ); + +struct tgsi_src_register_ext_swz +tgsi_build_src_register_ext_swz( + unsigned ext_swizzle_x, + unsigned ext_swizzle_y, + unsigned ext_swizzle_z, + unsigned ext_swizzle_w, + unsigned negate_x, + unsigned negate_y, + unsigned negate_z, + unsigned negate_w, + unsigned ext_divide, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_src_register_ext_mod +tgsi_default_src_register_ext_mod( void ); + +unsigned +tgsi_compare_src_register_ext_mod( + struct tgsi_src_register_ext_mod a, + struct tgsi_src_register_ext_mod b ); + +struct tgsi_src_register_ext_mod +tgsi_build_src_register_ext_mod( + unsigned complement, + unsigned bias, + unsigned scale_2x, + unsigned absolute, + unsigned negate, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_dimension +tgsi_default_dimension( void ); + +struct tgsi_dimension +tgsi_build_dimension( + unsigned indirect, + unsigned index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_dst_register +tgsi_default_dst_register( void ); + +struct tgsi_dst_register +tgsi_build_dst_register( + unsigned file, + unsigned mask, + int index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_full_dst_register +tgsi_default_full_dst_register( void ); + +struct tgsi_dst_register_ext_concode +tgsi_default_dst_register_ext_concode( void ); + +unsigned +tgsi_compare_dst_register_ext_concode( + struct tgsi_dst_register_ext_concode a, + struct tgsi_dst_register_ext_concode b ); + +struct tgsi_dst_register_ext_concode +tgsi_build_dst_register_ext_concode( + unsigned cc, + unsigned swizzle_x, + unsigned swizzle_y, + unsigned swizzle_z, + unsigned swizzle_w, + int index, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +struct tgsi_dst_register_ext_modulate +tgsi_default_dst_register_ext_modulate( void ); + +unsigned +tgsi_compare_dst_register_ext_modulate( + struct tgsi_dst_register_ext_modulate a, + struct tgsi_dst_register_ext_modulate b ); + +struct tgsi_dst_register_ext_modulate +tgsi_build_dst_register_ext_modulate( + unsigned modulate, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ); + +#if defined __cplusplus +} // extern "C" +#endif // defined __cplusplus + +#endif // !defined TGSI_BUILD_H + diff --git a/src/mesa/pipe/tgsi/util/tgsi_dump.c b/src/mesa/pipe/tgsi/util/tgsi_dump.c new file mode 100644 index 00000000000..982d5ce7969 --- /dev/null +++ b/src/mesa/pipe/tgsi/util/tgsi_dump.c @@ -0,0 +1,1459 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_util.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi_dump.h" +#include "tgsi_parse.h" +#include "tgsi_build.h" + +struct text_dump +{ + FILE *file; + unsigned tabs; +}; + +static void +text_dump_str( + struct text_dump *dump, + const char *str ) +{ + unsigned i; + size_t len = strlen( str ); + + for( i = 0; i < len; i++ ) { + fprintf( dump->file, "%c", str[i] ); + + if( str[i] == '\n' ) { + unsigned i; + + for( i = 0; i < dump->tabs; i++ ) { + fprintf( dump->file, " " ); + } + } + } +} + +static void +text_dump_chr( + struct text_dump *dump, + const char chr ) +{ + char str[2]; + + str[0] = chr; + str[1] = '\0'; + text_dump_str( dump, str ); +} + +static void +text_dump_uix( + struct text_dump *dump, + const unsigned ui ) +{ + char str[36]; + + sprintf( str, "0x%x", ui ); + text_dump_str( dump, str ); +} + +static void +text_dump_uid( + struct text_dump *dump, + const unsigned ui ) +{ + char str[16]; + + sprintf( str, "%u", ui ); + text_dump_str( dump, str ); +} + +static void +text_dump_sid( + struct text_dump *dump, + const int si ) +{ + char str[16]; + + sprintf( str, "%d", si ); + text_dump_str( dump, str ); +} + +static void +text_dump_flt( + struct text_dump *dump, + const float f ) +{ + char str[48]; + + sprintf( str, "%10.4f", f ); + text_dump_str( dump, str ); +} + +static void +text_dump_enum( + struct text_dump *dump, + const unsigned e, + const char **enums, + const unsigned enums_count ) +{ + if( e >= enums_count ) { + text_dump_uid( dump, e ); + } + else { + text_dump_str( dump, enums[e] ); + } +} + +static void +text_dump_tab( + struct text_dump *dump ) +{ + dump->tabs++; +} + +static void +text_dump_untab( + struct text_dump *dump ) +{ + assert( dump->tabs > 0 ); + + --dump->tabs; +} + +#define TXT(S) text_dump_str( dump, S ) +#define CHR(C) text_dump_chr( dump, C ) +#define UIX(I) text_dump_uix( dump, I ) +#define UID(I) text_dump_uid( dump, I ) +#define SID(I) text_dump_sid( dump, I ) +#define FLT(F) text_dump_flt( dump, F ) +#define TAB() text_dump_tab( dump ) +#define UNT() text_dump_untab( dump ) +#define ENM(E,ENUMS) text_dump_enum( dump, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) ) + +static const char *TGSI_PROCESSOR_TYPES[] = +{ + "PROCESSOR_FRAGMENT", + "PROCESSOR_VERTEX", + "PROCESSOR_GEOMETRY" +}; + +static const char *TGSI_PROCESSOR_TYPES_SHORT[] = +{ + "FRAG", + "VERT", + "GEOM" +}; + +static const char *TGSI_TOKEN_TYPES[] = +{ + "TOKEN_TYPE_DECLARATION", + "TOKEN_TYPE_IMMEDIATE", + "TOKEN_TYPE_INSTRUCTION" +}; + +static const char *TGSI_FILES[] = +{ + "FILE_NULL", + "FILE_CONSTANT", + "FILE_INPUT", + "FILE_OUTPUT", + "FILE_TEMPORARY", + "FILE_SAMPLER", + "FILE_ADDRESS", + "FILE_IMMEDIATE" +}; + +static const char *TGSI_FILES_SHORT[] = +{ + "NULL", + "CONST", + "IN", + "OUT", + "TEMP", + "SAMP", + "ADDR", + "IMM" +}; + +static const char *TGSI_DECLARES[] = +{ + "DECLARE_RANGE", + "DECLARE_MASK" +}; + +static const char *TGSI_INTERPOLATES[] = +{ + "INTERPOLATE_CONSTANT", + "INTERPOLATE_LINEAR", + "INTERPOLATE_PERSPECTIVE", + "INTERPOLATE_ATTRIB" +}; + +static const char *TGSI_INTERPOLATES_SHORT[] = +{ + "CONSTANT", + "LINEAR", + "PERSPECTIVE", + "ATTRIB" +}; + +static const char *TGSI_SEMANTICS[] = +{ + "SEMANTIC_POSITION", + "SEMANTIC_COLOR", + "SEMANTIC_BCOLOR", + "SEMANTIC_FOG", + "SEMANTIC_PSIZE", + "SEMANTIC_GENERIC," +}; + +static const char *TGSI_SEMANTICS_SHORT[] = +{ + "POSITION", + "COLOR", + "BCOLOR", + "FOG", + "PSIZE", + "GENERIC", +}; + +static const char *TGSI_IMMS[] = +{ + "IMM_FLOAT32" +}; + +static const char *TGSI_IMMS_SHORT[] = +{ + "FLT32" +}; + +static const char *TGSI_OPCODES[] = +{ + "OPCODE_ARL", + "OPCODE_MOV", + "OPCODE_LIT", + "OPCODE_RCP", + "OPCODE_RSQ", + "OPCODE_EXP", + "OPCODE_LOG", + "OPCODE_MUL", + "OPCODE_ADD", + "OPCODE_DP3", + "OPCODE_DP4", + "OPCODE_DST", + "OPCODE_MIN", + "OPCODE_MAX", + "OPCODE_SLT", + "OPCODE_SGE", + "OPCODE_MAD", + "OPCODE_SUB", + "OPCODE_LERP", + "OPCODE_CND", + "OPCODE_CND0", + "OPCODE_DOT2ADD", + "OPCODE_INDEX", + "OPCODE_NEGATE", + "OPCODE_FRAC", + "OPCODE_CLAMP", + "OPCODE_FLOOR", + "OPCODE_ROUND", + "OPCODE_EXPBASE2", + "OPCODE_LOGBASE2", + "OPCODE_POWER", + "OPCODE_CROSSPRODUCT", + "OPCODE_MULTIPLYMATRIX", + "OPCODE_ABS", + "OPCODE_RCC", + "OPCODE_DPH", + "OPCODE_COS", + "OPCODE_DDX", + "OPCODE_DDY", + "OPCODE_KILP", + "OPCODE_PK2H", + "OPCODE_PK2US", + "OPCODE_PK4B", + "OPCODE_PK4UB", + "OPCODE_RFL", + "OPCODE_SEQ", + "OPCODE_SFL", + "OPCODE_SGT", + "OPCODE_SIN", + "OPCODE_SLE", + "OPCODE_SNE", + "OPCODE_STR", + "OPCODE_TEX", + "OPCODE_TXD", + "OPCODE_UP2H", + "OPCODE_UP2US", + "OPCODE_UP4B", + "OPCODE_UP4UB", + "OPCODE_X2D", + "OPCODE_ARA", + "OPCODE_ARR", + "OPCODE_BRA", + "OPCODE_CAL", + "OPCODE_RET", + "OPCODE_SSG", + "OPCODE_CMP", + "OPCODE_SCS", + "OPCODE_TXB", + "OPCODE_NRM", + "OPCODE_DIV", + "OPCODE_DP2", + "OPCODE_TXL", + "OPCODE_BRK", + "OPCODE_IF", + "OPCODE_LOOP", + "OPCODE_REP", + "OPCODE_ELSE", + "OPCODE_ENDIF", + "OPCODE_ENDLOOP", + "OPCODE_ENDREP", + "OPCODE_PUSHA", + "OPCODE_POPA", + "OPCODE_CEIL", + "OPCODE_I2F", + "OPCODE_NOT", + "OPCODE_TRUNC", + "OPCODE_SHL", + "OPCODE_SHR", + "OPCODE_AND", + "OPCODE_OR", + "OPCODE_MOD", + "OPCODE_XOR", + "OPCODE_SAD", + "OPCODE_TXF", + "OPCODE_TXQ", + "OPCODE_CONT", + "OPCODE_EMIT", + "OPCODE_ENDPRIM", + "OPCODE_BGNLOOP2", + "OPCODE_BGNSUB", + "OPCODE_ENDLOOP2", + "OPCODE_ENDSUB", + "OPCODE_NOISE1", + "OPCODE_NOISE2", + "OPCODE_NOISE3", + "OPCODE_NOISE4", + "OPCODE_NOP", + "OPCODE_TEXBEM", + "OPCODE_TEXBEML", + "OPCODE_TEXREG2AR", + "OPCODE_TEXM3X2PAD", + "OPCODE_TEXM3X2TEX", + "OPCODE_TEXM3X3PAD", + "OPCODE_TEXM3X3TEX", + "OPCODE_TEXM3X3SPEC", + "OPCODE_TEXM3X3VSPEC", + "OPCODE_TEXREG2GB", + "OPCODE_TEXREG2RGB", + "OPCODE_TEXDP3TEX", + "OPCODE_TEXDP3", + "OPCODE_TEXM3X3", + "OPCODE_TEXM3X2DEPTH", + "OPCODE_TEXDEPTH", + "OPCODE_BEM", + "OPCODE_M4X3", + "OPCODE_M3X4", + "OPCODE_M3X3", + "OPCODE_M3X2", + "OPCODE_NRM4", + "OPCODE_CALLNZ", + "OPCODE_IFC", + "OPCODE_BREAKC", + "OPCODE_TXP", + "OPCODE_KIL", + "OPCODE_END" +}; + +static const char *TGSI_OPCODES_SHORT[] = +{ + "ARL", + "MOV", + "LIT", + "RCP", + "RSQ", + "EXP", + "LOG", + "MUL", + "ADD", + "DP3", + "DP4", + "DST", + "MIN", + "MAX", + "SLT", + "SGE", + "MAD", + "SUB", + "LERP", + "CND", + "CND0", + "DOT2ADD", + "INDEX", + "NEGATE", + "FRAC", + "CLAMP", + "FLOOR", + "ROUND", + "EXPBASE2", + "LOGBASE2", + "POWER", + "CROSSPRODUCT", + "MULTIPLYMATRIX", + "ABS", + "RCC", + "DPH", + "COS", + "DDX", + "DDY", + "KILP", + "PK2H", + "PK2US", + "PK4B", + "PK4UB", + "RFL", + "SEQ", + "SFL", + "SGT", + "SIN", + "SLE", + "SNE", + "STR", + "TEX", + "TXD", + "UP2H", + "UP2US", + "UP4B", + "UP4UB", + "X2D", + "ARA", + "ARR", + "BRA", + "CAL", + "RET", + "SSG", + "CMP", + "SCS", + "TXB", + "NRM", + "DIV", + "DP2", + "TXL", + "BRK", + "IF", + "LOOP", + "REP", + "ELSE", + "ENDIF", + "ENDLOOP", + "ENDREP", + "PUSHA", + "POPA", + "CEIL", + "I2F", + "NOT", + "TRUNC", + "SHL", + "SHR", + "AND", + "OR", + "MOD", + "XOR", + "SAD", + "TXF", + "TXQ", + "CONT", + "EMIT", + "ENDPRIM", + "BGNLOOP2", + "BGNSUB", + "ENDLOOP2", + "ENDSUB", + "NOISE1", + "NOISE2", + "NOISE3", + "NOISE4", + "NOP", + "TEXBEM", + "TEXBEML", + "TEXREG2AR", + "TEXM3X2PAD", + "TEXM3X2TEX", + "TEXM3X3PAD", + "TEXM3X3TEX", + "TEXM3X3SPEC", + "TEXM3X3VSPEC", + "TEXREG2GB", + "TEXREG2RGB", + "TEXDP3TEX", + "TEXDP3", + "TEXM3X3", + "TEXM3X2DEPTH", + "TEXDEPTH", + "BEM", + "M4X3", + "M3X4", + "M3X3", + "M3X2", + "NRM4", + "CALLNZ", + "IFC", + "BREAKC", + "TXP", + "KIL", + "END" +}; + +static const char *TGSI_SATS[] = +{ + "SAT_NONE", + "SAT_ZERO_ONE", + "SAT_MINUS_PLUS_ONE" +}; + +static const char *TGSI_INSTRUCTION_EXTS[] = +{ + "INSTRUCTION_EXT_TYPE_NV", + "INSTRUCTION_EXT_TYPE_LABEL", + "INSTRUCTION_EXT_TYPE_TEXTURE" +}; + +static const char *TGSI_PRECISIONS[] = +{ + "PRECISION_DEFAULT", + "TGSI_PRECISION_FLOAT32", + "TGSI_PRECISION_FLOAT16", + "TGSI_PRECISION_FIXED12" +}; + +static const char *TGSI_CCS[] = +{ + "CC_GT", + "CC_EQ", + "CC_LT", + "CC_UN", + "CC_GE", + "CC_LE", + "CC_NE", + "CC_TR", + "CC_FL" +}; + +static const char *TGSI_SWIZZLES[] = +{ + "SWIZZLE_X", + "SWIZZLE_Y", + "SWIZZLE_Z", + "SWIZZLE_W" +}; + +static const char *TGSI_SWIZZLES_SHORT[] = +{ + "x", + "y", + "z", + "w" +}; + +static const char *TGSI_TEXTURES[] = +{ + "TEXTURE_UNKNOWN", + "TEXTURE_1D", + "TEXTURE_2D", + "TEXTURE_3D", + "TEXTURE_CUBE", + "TEXTURE_RECT", + "TEXTURE_SHADOW1D", + "TEXTURE_SHADOW2D", + "TEXTURE_SHADOWRECT" +}; + +static const char *TGSI_SRC_REGISTER_EXTS[] = +{ + "SRC_REGISTER_EXT_TYPE_SWZ", + "SRC_REGISTER_EXT_TYPE_MOD" +}; + +static const char *TGSI_EXTSWIZZLES[] = +{ + "EXTSWIZZLE_X", + "EXTSWIZZLE_Y", + "EXTSWIZZLE_Z", + "EXTSWIZZLE_W", + "EXTSWIZZLE_ZERO", + "EXTSWIZZLE_ONE" +}; + +static const char *TGSI_EXTSWIZZLES_SHORT[] = +{ + "x", + "y", + "z", + "w", + "0", + "1" +}; + +static const char *TGSI_WRITEMASKS[] = +{ + "0", + "WRITEMASK_X", + "WRITEMASK_Y", + "WRITEMASK_XY", + "WRITEMASK_Z", + "WRITEMASK_XZ", + "WRITEMASK_YZ", + "WRITEMASK_XYZ", + "WRITEMASK_W", + "WRITEMASK_XW", + "WRITEMASK_YW", + "WRITEMASK_XYW", + "WRITEMASK_ZW", + "WRITEMASK_XZW", + "WRITEMASK_YZW", + "WRITEMASK_XYZW" +}; + +static const char *TGSI_DST_REGISTER_EXTS[] = +{ + "DST_REGISTER_EXT_TYPE_CONDCODE", + "DST_REGISTER_EXT_TYPE_MODULATE" +}; + +static const char *TGSI_MODULATES[] = +{ + "MODULATE_1X", + "MODULATE_2X", + "MODULATE_4X", + "MODULATE_8X", + "MODULATE_HALF", + "MODULATE_QUARTER", + "MODULATE_EIGHTH" +}; + +static void +dump_declaration_short( + struct text_dump *dump, + struct tgsi_full_declaration *decl ) +{ + TXT( "\nDCL " ); + ENM( decl->Declaration.File, TGSI_FILES_SHORT ); + + switch( decl->Declaration.Declare ) { + case TGSI_DECLARE_RANGE: + CHR( '[' ); + UID( decl->u.DeclarationRange.First ); + if( decl->u.DeclarationRange.First != decl->u.DeclarationRange.Last ) { + TXT( ".." ); + UID( decl->u.DeclarationRange.Last ); + } + CHR( ']' ); + break; + default: + assert( 0 ); + } + + if( decl->Declaration.UsageMask != TGSI_WRITEMASK_XYZW ) { + CHR( '.' ); + if( decl->Declaration.UsageMask & TGSI_WRITEMASK_X ) { + CHR( 'x' ); + } + if( decl->Declaration.UsageMask & TGSI_WRITEMASK_Y ) { + CHR( 'y' ); + } + if( decl->Declaration.UsageMask & TGSI_WRITEMASK_Z ) { + CHR( 'z' ); + } + if( decl->Declaration.UsageMask & TGSI_WRITEMASK_W ) { + CHR( 'w' ); + } + } + + if( decl->Declaration.Interpolate ) { + TXT( ", " ); + ENM( decl->Interpolation.Interpolate, TGSI_INTERPOLATES_SHORT ); + } + + if( decl->Declaration.Semantic ) { + TXT( ", " ); + ENM( decl->Semantic.SemanticName, TGSI_SEMANTICS_SHORT ); + CHR( '[' ); + UID( decl->Semantic.SemanticIndex ); + CHR( ']' ); + } +} + +static void +dump_declaration_verbose( + struct text_dump *dump, + struct tgsi_full_declaration *decl, + unsigned ignored, + unsigned deflt, + struct tgsi_full_declaration *fd ) +{ + TXT( "\nFile : " ); + ENM( decl->Declaration.File, TGSI_FILES ); + TXT( "\nDeclare : " ); + ENM( decl->Declaration.Declare, TGSI_DECLARES ); + if( deflt || fd->Declaration.UsageMask != decl->Declaration.UsageMask ) { + TXT( "\nUsageMask : " ); + if( decl->Declaration.UsageMask & TGSI_WRITEMASK_X ) { + CHR( 'X' ); + } + if( decl->Declaration.UsageMask & TGSI_WRITEMASK_Y ) { + CHR( 'Y' ); + } + if( decl->Declaration.UsageMask & TGSI_WRITEMASK_Z ) { + CHR( 'Z' ); + } + if( decl->Declaration.UsageMask & TGSI_WRITEMASK_W ) { + CHR( 'W' ); + } + } + if( deflt || fd->Declaration.Interpolate != decl->Declaration.Interpolate ) { + TXT( "\nInterpolate: " ); + UID( decl->Declaration.Interpolate ); + } + if( deflt || fd->Declaration.Semantic != decl->Declaration.Semantic ) { + TXT( "\nSemantic : " ); + UID( decl->Declaration.Semantic ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( decl->Declaration.Padding ); + } + + CHR( '\n' ); + switch( decl->Declaration.Declare ) { + case TGSI_DECLARE_RANGE: + TXT( "\nFirst: " ); + UID( decl->u.DeclarationRange.First ); + TXT( "\nLast : " ); + UID( decl->u.DeclarationRange.Last ); + break; + + case TGSI_DECLARE_MASK: + TXT( "\nMask: " ); + UIX( decl->u.DeclarationMask.Mask ); + break; + + default: + assert( 0 ); + } + + if( decl->Declaration.Interpolate ) { + CHR( '\n' ); + TXT( "\nInterpolate: " ); + ENM( decl->Interpolation.Interpolate, TGSI_INTERPOLATES ); + if( ignored ) { + TXT( "\nPadding : " ); + UIX( decl->Interpolation.Padding ); + } + } + + if( decl->Declaration.Semantic ) { + CHR( '\n' ); + TXT( "\nSemanticName : " ); + ENM( decl->Semantic.SemanticName, TGSI_SEMANTICS ); + TXT( "\nSemanticIndex: " ); + UID( decl->Semantic.SemanticIndex ); + if( ignored ) { + TXT( "\nPadding : " ); + UIX( decl->Semantic.Padding ); + } + } +} + +static void +dump_immediate_short( + struct text_dump *dump, + struct tgsi_full_immediate *imm ) +{ + unsigned i; + + TXT( "\nIMM " ); + ENM( imm->Immediate.DataType, TGSI_IMMS_SHORT ); + + TXT( " { " ); + for( i = 0; i < imm->Immediate.Size - 1; i++ ) { + switch( imm->Immediate.DataType ) { + case TGSI_IMM_FLOAT32: + FLT( imm->u.ImmediateFloat32[i].Float ); + break; + + default: + assert( 0 ); + } + + if( i < imm->Immediate.Size - 2 ) { + TXT( ", " ); + } + } + TXT( " }" ); +} + +static void +dump_immediate_verbose( + struct text_dump *dump, + struct tgsi_full_immediate *imm, + unsigned ignored ) +{ + unsigned i; + + TXT( "\nDataType : " ); + ENM( imm->Immediate.DataType, TGSI_IMMS ); + if( ignored ) { + TXT( "\nPadding : " ); + UIX( imm->Immediate.Padding ); + } + + for( i = 0; i < imm->Immediate.Size - 1; i++ ) { + CHR( '\n' ); + switch( imm->Immediate.DataType ) { + case TGSI_IMM_FLOAT32: + TXT( "\nFloat: " ); + FLT( imm->u.ImmediateFloat32[i].Float ); + break; + + default: + assert( 0 ); + } + } +} + +static void +dump_instruction_short( + struct text_dump *dump, + struct tgsi_full_instruction *inst, + unsigned instno ) +{ + unsigned i; + boolean first_reg = TRUE; + + CHR( '\n' ); + UID( instno ); + CHR( ':' ); + ENM( inst->Instruction.Opcode, TGSI_OPCODES_SHORT ); + + switch( inst->Instruction.Saturate ) { + case TGSI_SAT_NONE: + break; + case TGSI_SAT_ZERO_ONE: + TXT( "_SAT" ); + break; + case TGSI_SAT_MINUS_PLUS_ONE: + TXT( "_SAT[-1,1]" ); + break; + default: + assert( 0 ); + } + + for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) { + struct tgsi_full_dst_register *dst = &inst->FullDstRegisters[i]; + + if( !first_reg ) { + CHR( ',' ); + } + CHR( ' ' ); + + ENM( dst->DstRegister.File, TGSI_FILES_SHORT ); + + CHR( '[' ); + SID( dst->DstRegister.Index ); + CHR( ']' ); + + if( dst->DstRegister.WriteMask != TGSI_WRITEMASK_XYZW ) { + CHR( '.' ); + if( dst->DstRegister.WriteMask & TGSI_WRITEMASK_X ) { + CHR( 'x' ); + } + if( dst->DstRegister.WriteMask & TGSI_WRITEMASK_Y ) { + CHR( 'y' ); + } + if( dst->DstRegister.WriteMask & TGSI_WRITEMASK_Z ) { + CHR( 'z' ); + } + if( dst->DstRegister.WriteMask & TGSI_WRITEMASK_W ) { + CHR( 'w' ); + } + } + + first_reg = FALSE; + } + + for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) { + struct tgsi_full_src_register *src = &inst->FullSrcRegisters[i]; + + if( !first_reg ) { + CHR( ',' ); + } + CHR( ' ' ); + + if( src->SrcRegisterExtMod.Negate ) { + CHR( '-' ); + } + if( src->SrcRegisterExtMod.Absolute ) { + CHR( '|' ); + } + if( src->SrcRegister.Negate ) { + CHR( '-' ); + } + + ENM( src->SrcRegister.File, TGSI_FILES_SHORT ); + + CHR( '[' ); + SID( src->SrcRegister.Index ); + CHR( ']' ); + + if (src->SrcRegister.Extended) { + if (src->SrcRegisterExtSwz.ExtSwizzleX != TGSI_EXTSWIZZLE_X || + src->SrcRegisterExtSwz.ExtSwizzleY != TGSI_EXTSWIZZLE_Y || + src->SrcRegisterExtSwz.ExtSwizzleZ != TGSI_EXTSWIZZLE_Z || + src->SrcRegisterExtSwz.ExtSwizzleW != TGSI_EXTSWIZZLE_W) { + CHR( '.' ); + ENM( src->SrcRegisterExtSwz.ExtSwizzleX, TGSI_EXTSWIZZLES_SHORT ); + ENM( src->SrcRegisterExtSwz.ExtSwizzleY, TGSI_EXTSWIZZLES_SHORT ); + ENM( src->SrcRegisterExtSwz.ExtSwizzleZ, TGSI_EXTSWIZZLES_SHORT ); + ENM( src->SrcRegisterExtSwz.ExtSwizzleW, TGSI_EXTSWIZZLES_SHORT ); + } + } + else if( src->SrcRegister.SwizzleX != TGSI_SWIZZLE_X || + src->SrcRegister.SwizzleY != TGSI_SWIZZLE_Y || + src->SrcRegister.SwizzleZ != TGSI_SWIZZLE_Z || + src->SrcRegister.SwizzleW != TGSI_SWIZZLE_W ) { + CHR( '.' ); + ENM( src->SrcRegister.SwizzleX, TGSI_SWIZZLES_SHORT ); + ENM( src->SrcRegister.SwizzleY, TGSI_SWIZZLES_SHORT ); + ENM( src->SrcRegister.SwizzleZ, TGSI_SWIZZLES_SHORT ); + ENM( src->SrcRegister.SwizzleW, TGSI_SWIZZLES_SHORT ); + } + + if( src->SrcRegisterExtMod.Absolute ) { + CHR( '|' ); + } + + first_reg = FALSE; + } + + switch( inst->Instruction.Opcode ) { + case TGSI_OPCODE_IF: + case TGSI_OPCODE_ELSE: + case TGSI_OPCODE_BGNLOOP2: + case TGSI_OPCODE_ENDLOOP2: + case TGSI_OPCODE_CAL: + TXT( " :" ); + UID( inst->InstructionExtLabel.Label ); + break; + } +} + +static void +dump_instruction_verbose( + struct text_dump *dump, + struct tgsi_full_instruction *inst, + unsigned ignored, + unsigned deflt, + struct tgsi_full_instruction *fi ) +{ + unsigned i; + + TXT( "\nOpcode : " ); + ENM( inst->Instruction.Opcode, TGSI_OPCODES ); + if( deflt || fi->Instruction.Saturate != inst->Instruction.Saturate ) { + TXT( "\nSaturate : " ); + ENM( inst->Instruction.Saturate, TGSI_SATS ); + } + if( deflt || fi->Instruction.NumDstRegs != inst->Instruction.NumDstRegs ) { + TXT( "\nNumDstRegs : " ); + UID( inst->Instruction.NumDstRegs ); + } + if( deflt || fi->Instruction.NumSrcRegs != inst->Instruction.NumSrcRegs ) { + TXT( "\nNumSrcRegs : " ); + UID( inst->Instruction.NumSrcRegs ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( inst->Instruction.Padding ); + } + + if( deflt || tgsi_compare_instruction_ext_nv( inst->InstructionExtNv, fi->InstructionExtNv ) ) { + CHR( '\n' ); + TXT( "\nType : " ); + ENM( inst->InstructionExtNv.Type, TGSI_INSTRUCTION_EXTS ); + if( deflt || fi->InstructionExtNv.Precision != inst->InstructionExtNv.Precision ) { + TXT( "\nPrecision : " ); + ENM( inst->InstructionExtNv.Precision, TGSI_PRECISIONS ); + } + if( deflt || fi->InstructionExtNv.CondDstIndex != inst->InstructionExtNv.CondDstIndex ) { + TXT( "\nCondDstIndex : " ); + UID( inst->InstructionExtNv.CondDstIndex ); + } + if( deflt || fi->InstructionExtNv.CondFlowIndex != inst->InstructionExtNv.CondFlowIndex ) { + TXT( "\nCondFlowIndex : " ); + UID( inst->InstructionExtNv.CondFlowIndex ); + } + if( deflt || fi->InstructionExtNv.CondMask != inst->InstructionExtNv.CondMask ) { + TXT( "\nCondMask : " ); + ENM( inst->InstructionExtNv.CondMask, TGSI_CCS ); + } + if( deflt || fi->InstructionExtNv.CondSwizzleX != inst->InstructionExtNv.CondSwizzleX ) { + TXT( "\nCondSwizzleX : " ); + ENM( inst->InstructionExtNv.CondSwizzleX, TGSI_SWIZZLES ); + } + if( deflt || fi->InstructionExtNv.CondSwizzleY != inst->InstructionExtNv.CondSwizzleY ) { + TXT( "\nCondSwizzleY : " ); + ENM( inst->InstructionExtNv.CondSwizzleY, TGSI_SWIZZLES ); + } + if( deflt || fi->InstructionExtNv.CondSwizzleZ != inst->InstructionExtNv.CondSwizzleZ ) { + TXT( "\nCondSwizzleZ : " ); + ENM( inst->InstructionExtNv.CondSwizzleZ, TGSI_SWIZZLES ); + } + if( deflt || fi->InstructionExtNv.CondSwizzleW != inst->InstructionExtNv.CondSwizzleW ) { + TXT( "\nCondSwizzleW : " ); + ENM( inst->InstructionExtNv.CondSwizzleW, TGSI_SWIZZLES ); + } + if( deflt || fi->InstructionExtNv.CondDstUpdate != inst->InstructionExtNv.CondDstUpdate ) { + TXT( "\nCondDstUpdate : " ); + UID( inst->InstructionExtNv.CondDstUpdate ); + } + if( deflt || fi->InstructionExtNv.CondFlowEnable != inst->InstructionExtNv.CondFlowEnable ) { + TXT( "\nCondFlowEnable: " ); + UID( inst->InstructionExtNv.CondFlowEnable ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( inst->InstructionExtNv.Padding ); + if( deflt || fi->InstructionExtNv.Extended != inst->InstructionExtNv.Extended ) { + TXT( "\nExtended : " ); + UID( inst->InstructionExtNv.Extended ); + } + } + } + + if( deflt || tgsi_compare_instruction_ext_label( inst->InstructionExtLabel, fi->InstructionExtLabel ) ) { + CHR( '\n' ); + TXT( "\nType : " ); + ENM( inst->InstructionExtLabel.Type, TGSI_INSTRUCTION_EXTS ); + if( deflt || fi->InstructionExtLabel.Label != inst->InstructionExtLabel.Label ) { + TXT( "\nLabel : " ); + UID( inst->InstructionExtLabel.Label ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( inst->InstructionExtLabel.Padding ); + if( deflt || fi->InstructionExtLabel.Extended != inst->InstructionExtLabel.Extended ) { + TXT( "\nExtended: " ); + UID( inst->InstructionExtLabel.Extended ); + } + } + } + + if( deflt || tgsi_compare_instruction_ext_texture( inst->InstructionExtTexture, fi->InstructionExtTexture ) ) { + CHR( '\n' ); + TXT( "\nType : " ); + ENM( inst->InstructionExtTexture.Type, TGSI_INSTRUCTION_EXTS ); + if( deflt || fi->InstructionExtTexture.Texture != inst->InstructionExtTexture.Texture ) { + TXT( "\nTexture : " ); + ENM( inst->InstructionExtTexture.Texture, TGSI_TEXTURES ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( inst->InstructionExtTexture.Padding ); + if( deflt || fi->InstructionExtTexture.Extended != inst->InstructionExtTexture.Extended ) { + TXT( "\nExtended: " ); + UID( inst->InstructionExtTexture.Extended ); + } + } + } + + for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) { + struct tgsi_full_dst_register *dst = &inst->FullDstRegisters[i]; + struct tgsi_full_dst_register *fd = &fi->FullDstRegisters[i]; + + CHR( '\n' ); + TXT( "\nFile : " ); + ENM( dst->DstRegister.File, TGSI_FILES ); + if( deflt || fd->DstRegister.WriteMask != dst->DstRegister.WriteMask ) { + TXT( "\nWriteMask: " ); + ENM( dst->DstRegister.WriteMask, TGSI_WRITEMASKS ); + } + if( ignored ) { + if( deflt || fd->DstRegister.Indirect != dst->DstRegister.Indirect ) { + TXT( "\nIndirect : " ); + UID( dst->DstRegister.Indirect ); + } + if( deflt || fd->DstRegister.Dimension != dst->DstRegister.Dimension ) { + TXT( "\nDimension: " ); + UID( dst->DstRegister.Dimension ); + } + } + if( deflt || fd->DstRegister.Index != dst->DstRegister.Index ) { + TXT( "\nIndex : " ); + SID( dst->DstRegister.Index ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( dst->DstRegister.Padding ); + if( deflt || fd->DstRegister.Extended != dst->DstRegister.Extended ) { + TXT( "\nExtended : " ); + UID( dst->DstRegister.Extended ); + } + } + + if( deflt || tgsi_compare_dst_register_ext_concode( dst->DstRegisterExtConcode, fd->DstRegisterExtConcode ) ) { + CHR( '\n' ); + TXT( "\nType : " ); + ENM( dst->DstRegisterExtConcode.Type, TGSI_DST_REGISTER_EXTS ); + if( deflt || fd->DstRegisterExtConcode.CondMask != dst->DstRegisterExtConcode.CondMask ) { + TXT( "\nCondMask : " ); + ENM( dst->DstRegisterExtConcode.CondMask, TGSI_CCS ); + } + if( deflt || fd->DstRegisterExtConcode.CondSwizzleX != dst->DstRegisterExtConcode.CondSwizzleX ) { + TXT( "\nCondSwizzleX: " ); + ENM( dst->DstRegisterExtConcode.CondSwizzleX, TGSI_SWIZZLES ); + } + if( deflt || fd->DstRegisterExtConcode.CondSwizzleY != dst->DstRegisterExtConcode.CondSwizzleY ) { + TXT( "\nCondSwizzleY: " ); + ENM( dst->DstRegisterExtConcode.CondSwizzleY, TGSI_SWIZZLES ); + } + if( deflt || fd->DstRegisterExtConcode.CondSwizzleZ != dst->DstRegisterExtConcode.CondSwizzleZ ) { + TXT( "\nCondSwizzleZ: " ); + ENM( dst->DstRegisterExtConcode.CondSwizzleZ, TGSI_SWIZZLES ); + } + if( deflt || fd->DstRegisterExtConcode.CondSwizzleW != dst->DstRegisterExtConcode.CondSwizzleW ) { + TXT( "\nCondSwizzleW: " ); + ENM( dst->DstRegisterExtConcode.CondSwizzleW, TGSI_SWIZZLES ); + } + if( deflt || fd->DstRegisterExtConcode.CondSrcIndex != dst->DstRegisterExtConcode.CondSrcIndex ) { + TXT( "\nCondSrcIndex: " ); + UID( dst->DstRegisterExtConcode.CondSrcIndex ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( dst->DstRegisterExtConcode.Padding ); + if( deflt || fd->DstRegisterExtConcode.Extended != dst->DstRegisterExtConcode.Extended ) { + TXT( "\nExtended : " ); + UID( dst->DstRegisterExtConcode.Extended ); + } + } + } + + if( deflt || tgsi_compare_dst_register_ext_modulate( dst->DstRegisterExtModulate, fd->DstRegisterExtModulate ) ) { + CHR( '\n' ); + TXT( "\nType : " ); + ENM( dst->DstRegisterExtModulate.Type, TGSI_DST_REGISTER_EXTS ); + if( deflt || fd->DstRegisterExtModulate.Modulate != dst->DstRegisterExtModulate.Modulate ) { + TXT( "\nModulate: " ); + ENM( dst->DstRegisterExtModulate.Modulate, TGSI_MODULATES ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( dst->DstRegisterExtModulate.Padding ); + if( deflt || fd->DstRegisterExtModulate.Extended != dst->DstRegisterExtModulate.Extended ) { + TXT( "\nExtended: " ); + UID( dst->DstRegisterExtModulate.Extended ); + } + } + } + } + + for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) { + struct tgsi_full_src_register *src = &inst->FullSrcRegisters[i]; + struct tgsi_full_src_register *fs = &fi->FullSrcRegisters[i]; + + CHR( '\n' ); + TXT( "\nFile : "); + ENM( src->SrcRegister.File, TGSI_FILES ); + if( deflt || fs->SrcRegister.SwizzleX != src->SrcRegister.SwizzleX ) { + TXT( "\nSwizzleX : " ); + ENM( src->SrcRegister.SwizzleX, TGSI_SWIZZLES ); + } + if( deflt || fs->SrcRegister.SwizzleY != src->SrcRegister.SwizzleY ) { + TXT( "\nSwizzleY : " ); + ENM( src->SrcRegister.SwizzleY, TGSI_SWIZZLES ); + } + if( deflt || fs->SrcRegister.SwizzleZ != src->SrcRegister.SwizzleZ ) { + TXT( "\nSwizzleZ : " ); + ENM( src->SrcRegister.SwizzleZ, TGSI_SWIZZLES ); + } + if( deflt || fs->SrcRegister.SwizzleW != src->SrcRegister.SwizzleW ) { + TXT( "\nSwizzleW : " ); + ENM( src->SrcRegister.SwizzleW, TGSI_SWIZZLES ); + } + if( deflt || fs->SrcRegister.Negate != src->SrcRegister.Negate ) { + TXT( "\nNegate : " ); + UID( src->SrcRegister.Negate ); + } + if( ignored ) { + if( deflt || fs->SrcRegister.Indirect != src->SrcRegister.Indirect ) { + TXT( "\nIndirect : " ); + UID( src->SrcRegister.Indirect ); + } + if( deflt || fs->SrcRegister.Dimension != src->SrcRegister.Dimension ) { + TXT( "\nDimension: " ); + UID( src->SrcRegister.Dimension ); + } + } + if( deflt || fs->SrcRegister.Index != src->SrcRegister.Index ) { + TXT( "\nIndex : " ); + SID( src->SrcRegister.Index ); + } + if( ignored ) { + if( deflt || fs->SrcRegister.Extended != src->SrcRegister.Extended ) { + TXT( "\nExtended : " ); + UID( src->SrcRegister.Extended ); + } + } + + if( deflt || tgsi_compare_src_register_ext_swz( src->SrcRegisterExtSwz, fs->SrcRegisterExtSwz ) ) { + CHR( '\n' ); + TXT( "\nType : " ); + ENM( src->SrcRegisterExtSwz.Type, TGSI_SRC_REGISTER_EXTS ); + if( deflt || fs->SrcRegisterExtSwz.ExtSwizzleX != src->SrcRegisterExtSwz.ExtSwizzleX ) { + TXT( "\nExtSwizzleX: " ); + ENM( src->SrcRegisterExtSwz.ExtSwizzleX, TGSI_EXTSWIZZLES ); + } + if( deflt || fs->SrcRegisterExtSwz.ExtSwizzleY != src->SrcRegisterExtSwz.ExtSwizzleY ) { + TXT( "\nExtSwizzleY: " ); + ENM( src->SrcRegisterExtSwz.ExtSwizzleY, TGSI_EXTSWIZZLES ); + } + if( deflt || fs->SrcRegisterExtSwz.ExtSwizzleZ != src->SrcRegisterExtSwz.ExtSwizzleZ ) { + TXT( "\nExtSwizzleZ: " ); + ENM( src->SrcRegisterExtSwz.ExtSwizzleZ, TGSI_EXTSWIZZLES ); + } + if( deflt || fs->SrcRegisterExtSwz.ExtSwizzleW != src->SrcRegisterExtSwz.ExtSwizzleW ) { + TXT( "\nExtSwizzleW: " ); + ENM( src->SrcRegisterExtSwz.ExtSwizzleW, TGSI_EXTSWIZZLES ); + } + if( deflt || fs->SrcRegisterExtSwz.NegateX != src->SrcRegisterExtSwz.NegateX ) { + TXT( "\nNegateX : " ); + UID( src->SrcRegisterExtSwz.NegateX ); + } + if( deflt || fs->SrcRegisterExtSwz.NegateY != src->SrcRegisterExtSwz.NegateY ) { + TXT( "\nNegateY : " ); + UID( src->SrcRegisterExtSwz.NegateY ); + } + if( deflt || fs->SrcRegisterExtSwz.NegateZ != src->SrcRegisterExtSwz.NegateZ ) { + TXT( "\nNegateZ : " ); + UID( src->SrcRegisterExtSwz.NegateZ ); + } + if( deflt || fs->SrcRegisterExtSwz.NegateW != src->SrcRegisterExtSwz.NegateW ) { + TXT( "\nNegateW : " ); + UID( src->SrcRegisterExtSwz.NegateW ); + } + if( deflt || fs->SrcRegisterExtSwz.ExtDivide != src->SrcRegisterExtSwz.ExtDivide ) { + TXT( "\nExtDivide : " ); + ENM( src->SrcRegisterExtSwz.ExtDivide, TGSI_EXTSWIZZLES ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( src->SrcRegisterExtSwz.Padding ); + if( deflt || fs->SrcRegisterExtSwz.Extended != src->SrcRegisterExtSwz.Extended ) { + TXT( "\nExtended : " ); + UID( src->SrcRegisterExtSwz.Extended ); + } + } + } + + if( deflt || tgsi_compare_src_register_ext_mod( src->SrcRegisterExtMod, fs->SrcRegisterExtMod ) ) { + CHR( '\n' ); + TXT( "\nType : " ); + ENM( src->SrcRegisterExtMod.Type, TGSI_SRC_REGISTER_EXTS ); + if( deflt || fs->SrcRegisterExtMod.Complement != src->SrcRegisterExtMod.Complement ) { + TXT( "\nComplement: " ); + UID( src->SrcRegisterExtMod.Complement ); + } + if( deflt || fs->SrcRegisterExtMod.Bias != src->SrcRegisterExtMod.Bias ) { + TXT( "\nBias : " ); + UID( src->SrcRegisterExtMod.Bias ); + } + if( deflt || fs->SrcRegisterExtMod.Scale2X != src->SrcRegisterExtMod.Scale2X ) { + TXT( "\nScale2X : " ); + UID( src->SrcRegisterExtMod.Scale2X ); + } + if( deflt || fs->SrcRegisterExtMod.Absolute != src->SrcRegisterExtMod.Absolute ) { + TXT( "\nAbsolute : " ); + UID( src->SrcRegisterExtMod.Absolute ); + } + if( deflt || fs->SrcRegisterExtMod.Negate != src->SrcRegisterExtMod.Negate ) { + TXT( "\nNegate : " ); + UID( src->SrcRegisterExtMod.Negate ); + } + if( ignored ) { + TXT( "\nPadding : " ); + UIX( src->SrcRegisterExtMod.Padding ); + if( deflt || fs->SrcRegisterExtMod.Extended != src->SrcRegisterExtMod.Extended ) { + TXT( "\nExtended : " ); + UID( src->SrcRegisterExtMod.Extended ); + } + } + } + } +} + +void +tgsi_dump( + const struct tgsi_token *tokens, + unsigned flags ) +{ + struct text_dump _dump; + struct text_dump *dump = &_dump; + struct tgsi_parse_context parse; + struct tgsi_full_instruction fi; + struct tgsi_full_declaration fd; + unsigned verbose = flags & TGSI_DUMP_VERBOSE; + unsigned ignored = !(flags & TGSI_DUMP_NO_IGNORED); + unsigned deflt = !(flags & TGSI_DUMP_NO_DEFAULT); + unsigned instno = 0; + + { +#if 0 + static unsigned counter = 0; + char buffer[64]; + + sprintf( buffer, "tgsi-dump-%.4u.txt", counter++ ); + dump->file = fopen( buffer, "wt" ); +#else + dump->file = stderr; +#endif + dump->tabs = 0; + } + + /* sanity check */ + assert(strcmp(TGSI_OPCODES[TGSI_OPCODE_CONT], "OPCODE_CONT") == 0); + + tgsi_parse_init( &parse, tokens ); + + TXT( "tgsi-dump begin -----------------" ); + + CHR( '\n' ); + ENM( parse.FullHeader.Processor.Processor, TGSI_PROCESSOR_TYPES_SHORT ); + CHR( ' ' ); + UID( parse.FullVersion.Version.MajorVersion ); + CHR( '.' ); + UID( parse.FullVersion.Version.MinorVersion ); + + if( verbose ) { + TXT( "\nMajorVersion: " ); + UID( parse.FullVersion.Version.MajorVersion ); + TXT( "\nMinorVersion: " ); + UID( parse.FullVersion.Version.MinorVersion ); + CHR( '\n' ); + + TXT( "\nHeaderSize: " ); + UID( parse.FullHeader.Header.HeaderSize ); + TXT( "\nBodySize : " ); + UID( parse.FullHeader.Header.BodySize ); + TXT( "\nProcessor : " ); + ENM( parse.FullHeader.Processor.Processor, TGSI_PROCESSOR_TYPES ); + CHR( '\n' ); + } + + fi = tgsi_default_full_instruction(); + fd = tgsi_default_full_declaration(); + + while( !tgsi_parse_end_of_tokens( &parse ) ) { + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + dump_declaration_short( + dump, + &parse.FullToken.FullDeclaration ); + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + dump_immediate_short( + dump, + &parse.FullToken.FullImmediate ); + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + dump_instruction_short( + dump, + &parse.FullToken.FullInstruction, + instno ); + instno++; + break; + + default: + assert( 0 ); + } + + if( verbose ) { + TXT( "\nType : " ); + ENM( parse.FullToken.Token.Type, TGSI_TOKEN_TYPES ); + if( ignored ) { + TXT( "\nSize : " ); + UID( parse.FullToken.Token.Size ); + if( deflt || parse.FullToken.Token.Extended ) { + TXT( "\nExtended : " ); + UID( parse.FullToken.Token.Extended ); + } + } + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + dump_declaration_verbose( + dump, + &parse.FullToken.FullDeclaration, + ignored, + deflt, + &fd ); + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + dump_immediate_verbose( + dump, + &parse.FullToken.FullImmediate, + ignored ); + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + dump_instruction_verbose( + dump, + &parse.FullToken.FullInstruction, + ignored, + deflt, + &fi ); + break; + + default: + assert( 0 ); + } + + CHR( '\n' ); + } + } + + TXT( "\ntgsi-dump end -------------------\n" ); + + tgsi_parse_free( &parse ); +} + diff --git a/src/mesa/pipe/tgsi/util/tgsi_dump.h b/src/mesa/pipe/tgsi/util/tgsi_dump.h new file mode 100644 index 00000000000..70860c0885a --- /dev/null +++ b/src/mesa/pipe/tgsi/util/tgsi_dump.h @@ -0,0 +1,22 @@ +#if !defined TGSI_DUMP_H +#define TGSI_DUMP_H + +#if defined __cplusplus +extern "C" { +#endif // defined __cplusplus + +#define TGSI_DUMP_VERBOSE 1 +#define TGSI_DUMP_NO_IGNORED 2 +#define TGSI_DUMP_NO_DEFAULT 4 + +void +tgsi_dump( + const struct tgsi_token *tokens, + unsigned flags ); + +#if defined __cplusplus +} // extern "C" +#endif // defined __cplusplus + +#endif // !defined TGSI_DUMP_H + diff --git a/src/mesa/pipe/tgsi/util/tgsi_parse.c b/src/mesa/pipe/tgsi/util/tgsi_parse.c new file mode 100644 index 00000000000..f0f8d44ac20 --- /dev/null +++ b/src/mesa/pipe/tgsi/util/tgsi_parse.c @@ -0,0 +1,318 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_util.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi_parse.h" +#include "tgsi_build.h" + +void +tgsi_full_token_init( + union tgsi_full_token *full_token ) +{ + full_token->Token.Type = TGSI_TOKEN_TYPE_DECLARATION; +} + +void +tgsi_full_token_free( + union tgsi_full_token *full_token ) +{ + if( full_token->Token.Type == TGSI_TOKEN_TYPE_IMMEDIATE ) { + FREE( full_token->FullImmediate.u.Pointer ); + } +} + +unsigned +tgsi_parse_init( + struct tgsi_parse_context *ctx, + const struct tgsi_token *tokens ) +{ + ctx->FullVersion.Version = *(struct tgsi_version *) &tokens[0]; + if( ctx->FullVersion.Version.MajorVersion > 1 ) { + return TGSI_PARSE_ERROR; + } + + ctx->FullHeader.Header = *(struct tgsi_header *) &tokens[1]; + if( ctx->FullHeader.Header.HeaderSize >= 2 ) { + ctx->FullHeader.Processor = *(struct tgsi_processor *) &tokens[2]; + } + else { + ctx->FullHeader.Processor = tgsi_default_processor(); + } + + ctx->Tokens = tokens; + ctx->Position = 1 + ctx->FullHeader.Header.HeaderSize; + + tgsi_full_token_init( &ctx->FullToken ); + + return TGSI_PARSE_OK; +} + +void +tgsi_parse_free( + struct tgsi_parse_context *ctx ) +{ + tgsi_full_token_free( &ctx->FullToken ); +} + +boolean +tgsi_parse_end_of_tokens( + struct tgsi_parse_context *ctx ) +{ + return ctx->Position >= + 1 + ctx->FullHeader.Header.HeaderSize + ctx->FullHeader.Header.BodySize; +} + +static void +next_token( + struct tgsi_parse_context *ctx, + void *token ) +{ + assert( !tgsi_parse_end_of_tokens( ctx ) ); + + *(struct tgsi_token *) token = ctx->Tokens[ctx->Position++]; +} + +void +tgsi_parse_token( + struct tgsi_parse_context *ctx ) +{ + struct tgsi_token token; + unsigned i; + + tgsi_full_token_free( &ctx->FullToken ); + tgsi_full_token_init( &ctx->FullToken ); + + next_token( ctx, &token ); + + switch( token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + { + struct tgsi_full_declaration *decl = &ctx->FullToken.FullDeclaration; + + *decl = tgsi_default_full_declaration(); + decl->Declaration = *(struct tgsi_declaration *) &token; + + switch( decl->Declaration.Type ) { + case TGSI_DECLARE_RANGE: + next_token( ctx, &decl->u.DeclarationRange ); + break; + + case TGSI_DECLARE_MASK: + next_token( ctx, &decl->u.DeclarationMask ); + break; + + default: + assert (0); + } + + if( decl->Declaration.Interpolate ) { + next_token( ctx, &decl->Interpolation ); + } + + if( decl->Declaration.Semantic ) { + next_token( ctx, &decl->Semantic ); + } + + break; + } + + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + struct tgsi_full_immediate *imm = &ctx->FullToken.FullImmediate; + + *imm = tgsi_default_full_immediate(); + imm->Immediate = *(struct tgsi_immediate *) &token; + + assert( !imm->Immediate.Extended ); + + switch (imm->Immediate.DataType) { + case TGSI_IMM_FLOAT32: + imm->u.Pointer = MALLOC( + sizeof( struct tgsi_immediate_float32 ) * (imm->Immediate.Size - 1) ); + for( i = 0; i < imm->Immediate.Size - 1; i++ ) { + next_token( ctx, &imm->u.ImmediateFloat32[i] ); + } + break; + + default: + assert( 0 ); + } + + break; + } + + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + struct tgsi_full_instruction *inst = &ctx->FullToken.FullInstruction; + unsigned extended; + + *inst = tgsi_default_full_instruction(); + inst->Instruction = *(struct tgsi_instruction *) &token; + + extended = inst->Instruction.Extended; + + while( extended ) { + struct tgsi_src_register_ext token; + + next_token( ctx, &token ); + + switch( token.Type ) { + case TGSI_INSTRUCTION_EXT_TYPE_NV: + inst->InstructionExtNv = + *(struct tgsi_instruction_ext_nv *) &token; + break; + + case TGSI_INSTRUCTION_EXT_TYPE_LABEL: + inst->InstructionExtLabel = + *(struct tgsi_instruction_ext_label *) &token; + break; + + case TGSI_INSTRUCTION_EXT_TYPE_TEXTURE: + inst->InstructionExtTexture = + *(struct tgsi_instruction_ext_texture *) &token; + break; + + default: + assert( 0 ); + } + + extended = token.Extended; + } + + assert( inst->Instruction.NumDstRegs <= TGSI_FULL_MAX_DST_REGISTERS ); + + for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) { + unsigned extended; + + next_token( ctx, &inst->FullDstRegisters[i].DstRegister ); + + /* + * No support for indirect or multi-dimensional addressing. + */ + assert( !inst->FullDstRegisters[i].DstRegister.Indirect ); + assert( !inst->FullDstRegisters[i].DstRegister.Dimension ); + + extended = inst->FullDstRegisters[i].DstRegister.Extended; + + while( extended ) { + struct tgsi_src_register_ext token; + + next_token( ctx, &token ); + + switch( token.Type ) { + case TGSI_DST_REGISTER_EXT_TYPE_CONDCODE: + inst->FullDstRegisters[i].DstRegisterExtConcode = + *(struct tgsi_dst_register_ext_concode *) &token; + break; + + case TGSI_DST_REGISTER_EXT_TYPE_MODULATE: + inst->FullDstRegisters[i].DstRegisterExtModulate = + *(struct tgsi_dst_register_ext_modulate *) &token; + break; + + default: + assert( 0 ); + } + + extended = token.Extended; + } + } + + assert( inst->Instruction.NumSrcRegs <= TGSI_FULL_MAX_SRC_REGISTERS ); + + for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) { + unsigned extended; + + next_token( ctx, &inst->FullSrcRegisters[i].SrcRegister ); + + extended = inst->FullSrcRegisters[i].SrcRegister.Extended; + + while( extended ) { + struct tgsi_src_register_ext token; + + next_token( ctx, &token ); + + switch( token.Type ) { + case TGSI_SRC_REGISTER_EXT_TYPE_SWZ: + inst->FullSrcRegisters[i].SrcRegisterExtSwz = + *(struct tgsi_src_register_ext_swz *) &token; + break; + + case TGSI_SRC_REGISTER_EXT_TYPE_MOD: + inst->FullSrcRegisters[i].SrcRegisterExtMod = + *(struct tgsi_src_register_ext_mod *) &token; + break; + + default: + assert( 0 ); + } + + extended = token.Extended; + } + + if( inst->FullSrcRegisters[i].SrcRegister.Indirect ) { + next_token( ctx, &inst->FullSrcRegisters[i].SrcRegisterInd ); + + /* + * No support for indirect or multi-dimensional addressing. + */ + assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Indirect ); + assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Dimension ); + assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Extended ); + } + + if( inst->FullSrcRegisters[i].SrcRegister.Dimension ) { + next_token( ctx, &inst->FullSrcRegisters[i].SrcRegisterDim ); + + /* + * No support for multi-dimensional addressing. + */ + assert( !inst->FullSrcRegisters[i].SrcRegisterDim.Dimension ); + assert( !inst->FullSrcRegisters[i].SrcRegisterDim.Extended ); + + if( inst->FullSrcRegisters[i].SrcRegisterDim.Indirect ) { + next_token( ctx, &inst->FullSrcRegisters[i].SrcRegisterDimInd ); + + /* + * No support for indirect or multi-dimensional addressing. + */ + assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Indirect ); + assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Dimension ); + assert( !inst->FullSrcRegisters[i].SrcRegisterInd.Extended ); + } + } + } + + break; + } + + default: + assert( 0 ); + } +} + diff --git a/src/mesa/pipe/tgsi/util/tgsi_parse.h b/src/mesa/pipe/tgsi/util/tgsi_parse.h new file mode 100644 index 00000000000..9372da8d5d1 --- /dev/null +++ b/src/mesa/pipe/tgsi/util/tgsi_parse.h @@ -0,0 +1,121 @@ +#if !defined TGSI_PARSE_H +#define TGSI_PARSE_H + +#if defined __cplusplus +extern "C" { +#endif // defined __cplusplus + +struct tgsi_full_version +{ + struct tgsi_version Version; +}; + +struct tgsi_full_header +{ + struct tgsi_header Header; + struct tgsi_processor Processor; +}; + +struct tgsi_full_dst_register +{ + struct tgsi_dst_register DstRegister; + struct tgsi_dst_register_ext_concode DstRegisterExtConcode; + struct tgsi_dst_register_ext_modulate DstRegisterExtModulate; +}; + +struct tgsi_full_src_register +{ + struct tgsi_src_register SrcRegister; + struct tgsi_src_register_ext_swz SrcRegisterExtSwz; + struct tgsi_src_register_ext_mod SrcRegisterExtMod; + struct tgsi_src_register SrcRegisterInd; + struct tgsi_dimension SrcRegisterDim; + struct tgsi_src_register SrcRegisterDimInd; +}; + +struct tgsi_full_declaration +{ + struct tgsi_declaration Declaration; + union + { + struct tgsi_declaration_range DeclarationRange; + struct tgsi_declaration_mask DeclarationMask; + } u; + struct tgsi_declaration_interpolation Interpolation; + struct tgsi_declaration_semantic Semantic; +}; + +struct tgsi_full_immediate +{ + struct tgsi_immediate Immediate; + union + { + void *Pointer; + struct tgsi_immediate_float32 *ImmediateFloat32; + } u; +}; + +#define TGSI_FULL_MAX_DST_REGISTERS 2 +#define TGSI_FULL_MAX_SRC_REGISTERS 3 + +struct tgsi_full_instruction +{ + struct tgsi_instruction Instruction; + struct tgsi_instruction_ext_nv InstructionExtNv; + struct tgsi_instruction_ext_label InstructionExtLabel; + struct tgsi_instruction_ext_texture InstructionExtTexture; + struct tgsi_full_dst_register FullDstRegisters[TGSI_FULL_MAX_DST_REGISTERS]; + struct tgsi_full_src_register FullSrcRegisters[TGSI_FULL_MAX_SRC_REGISTERS]; +}; + +union tgsi_full_token +{ + struct tgsi_token Token; + struct tgsi_full_declaration FullDeclaration; + struct tgsi_full_immediate FullImmediate; + struct tgsi_full_instruction FullInstruction; +}; + +void +tgsi_full_token_init( + union tgsi_full_token *full_token ); + +void +tgsi_full_token_free( + union tgsi_full_token *full_token ); + +struct tgsi_parse_context +{ + const struct tgsi_token *Tokens; + unsigned Position; + struct tgsi_full_version FullVersion; + struct tgsi_full_header FullHeader; + union tgsi_full_token FullToken; +}; + +#define TGSI_PARSE_OK 0 +#define TGSI_PARSE_ERROR 1 + +unsigned +tgsi_parse_init( + struct tgsi_parse_context *ctx, + const struct tgsi_token *tokens ); + +void +tgsi_parse_free( + struct tgsi_parse_context *ctx ); + +boolean +tgsi_parse_end_of_tokens( + struct tgsi_parse_context *ctx ); + +void +tgsi_parse_token( + struct tgsi_parse_context *ctx ); + +#if defined __cplusplus +} // extern "C" +#endif // defined __cplusplus + +#endif // !defined TGSI_PARSE_H + diff --git a/src/mesa/pipe/tgsi/util/tgsi_util.c b/src/mesa/pipe/tgsi/util/tgsi_util.c new file mode 100644 index 00000000000..1e76b0f133a --- /dev/null +++ b/src/mesa/pipe/tgsi/util/tgsi_util.c @@ -0,0 +1,273 @@ +#include "pipe/p_util.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi_parse.h" +#include "tgsi_build.h" +#include "tgsi_util.h" + +union pointer_hack +{ + void *pointer; + unsigned long long uint64; +}; + +void * +tgsi_align_128bit( + void *unaligned ) +{ + union pointer_hack ph; + + ph.uint64 = 0; + ph.pointer = unaligned; + ph.uint64 = (ph.uint64 + 15) & ~15; + return ph.pointer; +} + +unsigned +tgsi_util_get_src_register_swizzle( + const struct tgsi_src_register *reg, + unsigned component ) +{ + switch( component ) { + case 0: + return reg->SwizzleX; + case 1: + return reg->SwizzleY; + case 2: + return reg->SwizzleZ; + case 3: + return reg->SwizzleW; + default: + assert( 0 ); + } + return 0; +} + +unsigned +tgsi_util_get_src_register_extswizzle( + const struct tgsi_src_register_ext_swz *reg, + unsigned component ) +{ + switch( component ) { + case 0: + return reg->ExtSwizzleX; + case 1: + return reg->ExtSwizzleY; + case 2: + return reg->ExtSwizzleZ; + case 3: + return reg->ExtSwizzleW; + default: + assert( 0 ); + } + return 0; +} + +unsigned +tgsi_util_get_full_src_register_extswizzle( + const struct tgsi_full_src_register *reg, + unsigned component ) +{ + unsigned swizzle; + + /* + * First, calculate the extended swizzle for a given channel. This will give + * us either a channel index into the simple swizzle or a constant 1 or 0. + */ + swizzle = tgsi_util_get_src_register_extswizzle( + ®->SrcRegisterExtSwz, + component ); + + assert (TGSI_SWIZZLE_X == TGSI_EXTSWIZZLE_X); + assert (TGSI_SWIZZLE_Y == TGSI_EXTSWIZZLE_Y); + assert (TGSI_SWIZZLE_Z == TGSI_EXTSWIZZLE_Z); + assert (TGSI_SWIZZLE_W == TGSI_EXTSWIZZLE_W); + assert (TGSI_EXTSWIZZLE_ZERO > TGSI_SWIZZLE_W); + assert (TGSI_EXTSWIZZLE_ONE > TGSI_SWIZZLE_W); + + /* + * Second, calculate the simple swizzle for the unswizzled channel index. + * Leave the constants intact, they are not affected by the simple swizzle. + */ + if( swizzle <= TGSI_SWIZZLE_W ) { + swizzle = tgsi_util_get_src_register_swizzle( + ®->SrcRegister, + component ); + } + + return swizzle; +} + +void +tgsi_util_set_src_register_swizzle( + struct tgsi_src_register *reg, + unsigned swizzle, + unsigned component ) +{ + switch( component ) { + case 0: + reg->SwizzleX = swizzle; + break; + case 1: + reg->SwizzleY = swizzle; + break; + case 2: + reg->SwizzleZ = swizzle; + break; + case 3: + reg->SwizzleW = swizzle; + break; + default: + assert( 0 ); + } +} + +void +tgsi_util_set_src_register_extswizzle( + struct tgsi_src_register_ext_swz *reg, + unsigned swizzle, + unsigned component ) +{ + switch( component ) { + case 0: + reg->ExtSwizzleX = swizzle; + break; + case 1: + reg->ExtSwizzleY = swizzle; + break; + case 2: + reg->ExtSwizzleZ = swizzle; + break; + case 3: + reg->ExtSwizzleW = swizzle; + break; + default: + assert( 0 ); + } +} + +unsigned +tgsi_util_get_src_register_extnegate( + const struct tgsi_src_register_ext_swz *reg, + unsigned component ) +{ + switch( component ) { + case 0: + return reg->NegateX; + case 1: + return reg->NegateY; + case 2: + return reg->NegateZ; + case 3: + return reg->NegateW; + default: + assert( 0 ); + } + return 0; +} + +void +tgsi_util_set_src_register_extnegate( + struct tgsi_src_register_ext_swz *reg, + unsigned negate, + unsigned component ) +{ + switch( component ) { + case 0: + reg->NegateX = negate; + break; + case 1: + reg->NegateY = negate; + break; + case 2: + reg->NegateZ = negate; + break; + case 3: + reg->NegateW = negate; + break; + default: + assert( 0 ); + } +} + +unsigned +tgsi_util_get_full_src_register_sign_mode( + const struct tgsi_full_src_register *reg, + unsigned component ) +{ + unsigned sign_mode; + + if( reg->SrcRegisterExtMod.Absolute ) { + /* Consider only the post-abs negation. */ + + if( reg->SrcRegisterExtMod.Negate ) { + sign_mode = TGSI_UTIL_SIGN_SET; + } + else { + sign_mode = TGSI_UTIL_SIGN_CLEAR; + } + } + else { + /* Accumulate the three negations. */ + + unsigned negate; + + negate = reg->SrcRegister.Negate; + if( tgsi_util_get_src_register_extnegate( ®->SrcRegisterExtSwz, component ) ) { + negate = !negate; + } + if( reg->SrcRegisterExtMod.Negate ) { + negate = !negate; + } + + if( negate ) { + sign_mode = TGSI_UTIL_SIGN_TOGGLE; + } + else { + sign_mode = TGSI_UTIL_SIGN_KEEP; + } + } + + return sign_mode; +} + +void +tgsi_util_set_full_src_register_sign_mode( + struct tgsi_full_src_register *reg, + unsigned sign_mode ) +{ + reg->SrcRegisterExtSwz.NegateX = 0; + reg->SrcRegisterExtSwz.NegateY = 0; + reg->SrcRegisterExtSwz.NegateZ = 0; + reg->SrcRegisterExtSwz.NegateW = 0; + + switch (sign_mode) + { + case TGSI_UTIL_SIGN_CLEAR: + reg->SrcRegister.Negate = 0; + reg->SrcRegisterExtMod.Absolute = 1; + reg->SrcRegisterExtMod.Negate = 0; + break; + + case TGSI_UTIL_SIGN_SET: + reg->SrcRegister.Negate = 0; + reg->SrcRegisterExtMod.Absolute = 1; + reg->SrcRegisterExtMod.Negate = 1; + break; + + case TGSI_UTIL_SIGN_TOGGLE: + reg->SrcRegister.Negate = 1; + reg->SrcRegisterExtMod.Absolute = 0; + reg->SrcRegisterExtMod.Negate = 0; + break; + + case TGSI_UTIL_SIGN_KEEP: + reg->SrcRegister.Negate = 0; + reg->SrcRegisterExtMod.Absolute = 0; + reg->SrcRegisterExtMod.Negate = 0; + break; + + default: + assert( 0 ); + } +} + diff --git a/src/mesa/pipe/tgsi/util/tgsi_util.h b/src/mesa/pipe/tgsi/util/tgsi_util.h new file mode 100644 index 00000000000..ef14446f0e4 --- /dev/null +++ b/src/mesa/pipe/tgsi/util/tgsi_util.h @@ -0,0 +1,70 @@ +#if !defined TGSI_UTIL_H +#define TGSI_UTIL_H + +#if defined __cplusplus +extern "C" { +#endif // defined __cplusplus + +void * +tgsi_align_128bit( + void *unaligned ); + +unsigned +tgsi_util_get_src_register_swizzle( + const struct tgsi_src_register *reg, + unsigned component ); + +unsigned +tgsi_util_get_src_register_extswizzle( + const struct tgsi_src_register_ext_swz *reg, + unsigned component); + +unsigned +tgsi_util_get_full_src_register_extswizzle( + const struct tgsi_full_src_register *reg, + unsigned component ); + +void +tgsi_util_set_src_register_swizzle( + struct tgsi_src_register *reg, + unsigned swizzle, + unsigned component ); + +void +tgsi_util_set_src_register_extswizzle( + struct tgsi_src_register_ext_swz *reg, + unsigned swizzle, + unsigned component ); + +unsigned +tgsi_util_get_src_register_extnegate( + const struct tgsi_src_register_ext_swz *reg, + unsigned component ); + +void +tgsi_util_set_src_register_extnegate( + struct tgsi_src_register_ext_swz *reg, + unsigned negate, + unsigned component ); + +#define TGSI_UTIL_SIGN_CLEAR 0 /* Force positive */ +#define TGSI_UTIL_SIGN_SET 1 /* Force negative */ +#define TGSI_UTIL_SIGN_TOGGLE 2 /* Negate */ +#define TGSI_UTIL_SIGN_KEEP 3 /* No change */ + +unsigned +tgsi_util_get_full_src_register_sign_mode( + const struct tgsi_full_src_register *reg, + unsigned component ); + +void +tgsi_util_set_full_src_register_sign_mode( + struct tgsi_full_src_register *reg, + unsigned sign_mode ); + +#if defined __cplusplus +} // extern "C" +#endif // defined __cplusplus + +#endif // !defined TGSI_UTIL_H + diff --git a/src/mesa/pipe/xlib/fakeglx.c b/src/mesa/pipe/xlib/fakeglx.c index d7e7b292d1f..6965ee0794c 100644 --- a/src/mesa/pipe/xlib/fakeglx.c +++ b/src/mesa/pipe/xlib/fakeglx.c @@ -1433,7 +1433,6 @@ Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo, return NULL; } - glxCtx->xmesaContext->direct = GL_FALSE; glxCtx->glxContext.isDirect = GL_FALSE; glxCtx->glxContext.currentDpy = dpy; glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */ @@ -1565,7 +1564,7 @@ Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap ) if (!b) { return 0; } - return b->frontxrb->pixmap; + return b->drawable; } @@ -1591,7 +1590,7 @@ Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo, if (!b) { return 0; } - return b->frontxrb->pixmap; + return b->drawable; } @@ -1662,9 +1661,9 @@ Fake_glXDestroyContext( Display *dpy, GLXContext ctx ) static Bool Fake_glXIsDirect( Display *dpy, GLXContext ctx ) { - struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx; (void) dpy; - return glxCtx->xmesaContext->direct; + (void) ctx; + return False; } @@ -2360,7 +2359,7 @@ Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config, * glXMakeCurrent takes. */ if (xmbuf) - return (GLXPbuffer) xmbuf->frontxrb->pixmap; + return (GLXPbuffer) xmbuf->drawable; else return 0; } @@ -2444,7 +2443,6 @@ Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config, return NULL; } - glxCtx->xmesaContext->direct = GL_FALSE; glxCtx->glxContext.isDirect = GL_FALSE; glxCtx->glxContext.currentDpy = dpy; glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */ @@ -2642,7 +2640,7 @@ Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixm { XMesaVisual xmvis = (XMesaVisual) config; XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0); - return xmbuf->frontxrb->pixmap; /* need to return an X ID */ + return xmbuf->drawable; /* need to return an X ID */ } @@ -2667,7 +2665,6 @@ Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int re return NULL; } - glxCtx->xmesaContext->direct = GL_FALSE; glxCtx->glxContext.isDirect = GL_FALSE; glxCtx->glxContext.currentDpy = dpy; glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */ @@ -2736,7 +2733,7 @@ Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, /* A GLXPbuffer handle must be an X Drawable because that's what * glXMakeCurrent takes. */ - return (GLXPbuffer) xmbuf->frontxrb->pixmap; + return (GLXPbuffer) xmbuf->drawable; } diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index e456ea2fd4d..9c7713790b8 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -48,12 +48,7 @@ * according to the display's visual red_mask, green_mask, and blue_mask. * If XPutPixel is used to put a pixel into an XImage then XPutPixel will * do byte swapping if needed. If one wants to directly "poke" the pixel - * into the XImage's buffer then the pixel must be byte swapped first. In - * Mesa, when byte swapping is needed we use the PF_TRUECOLOR pixel format - * and use XPutPixel everywhere except in the implementation of - * glClear(GL_COLOR_BUFFER_BIT). We want this function to be fast so - * instead of using XPutPixel we "poke" our values after byte-swapping - * the clear pixel value if needed. + * into the XImage's buffer then the pixel must be byte swapped first. * */ @@ -77,8 +72,8 @@ #include "state_tracker/st_public.h" #include "state_tracker/st_context.h" -#include "pipe/softpipe/sp_context.h" #include "pipe/p_defines.h" +#include "pipe/p_context.h" /** * Global X driver lock @@ -135,24 +130,6 @@ static int check_for_xshm( XMesaDisplay *display ) } -/** - * Apply gamma correction to an intensity value in [0..max]. Return the - * new intensity value. - */ -static GLint -gamma_adjust( GLfloat gamma, GLint value, GLint max ) -{ - if (gamma == 1.0) { - return value; - } - else { - double x = (double) value / (double) max; - return IROUND_POS((GLfloat) max * _mesa_pow(x, 1.0F/gamma)); - } -} - - - /** * Return the true number of bits per pixel for XImages. * For example, if we request a 24-bit deep visual we may actually need/get @@ -252,19 +229,19 @@ get_drawable_size( XMesaDisplay *dpy, Drawable d, GLuint *width, GLuint *height * \param width returns width in pixels * \param height returns height in pixels */ -void +static void xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b, GLuint *width, GLuint *height) { #ifdef XFree86Server - *width = MIN2(b->frontxrb->drawable->width, MAX_WIDTH); - *height = MIN2(b->frontxrb->drawable->height, MAX_HEIGHT); + *width = MIN2(b->drawable->width, MAX_WIDTH); + *height = MIN2(b->drawable->height, MAX_HEIGHT); #else Status stat; _glthread_LOCK_MUTEX(_xmesa_lock); XSync(b->xm_visual->display, 0); /* added for Chromium */ - stat = get_drawable_size(dpy, b->frontxrb->pixmap, width, height); + stat = get_drawable_size(dpy, b->drawable, width, height); _glthread_UNLOCK_MUTEX(_xmesa_lock); if (!stat) { @@ -301,7 +278,6 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, { XMesaBuffer b; GLframebuffer *fb; - struct pipe_winsys *winsys = xmesa_get_pipe_winsys(); ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); @@ -309,7 +285,8 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, if (!b) return NULL; - b->display = vis->display; + b->drawable = d; + b->xm_visual = vis; b->type = type; b->cmap = cmap; @@ -317,109 +294,20 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, /* * Create framebuffer, but we'll plug in our own renderbuffers below. */ - b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_FALSE, (void *) b); + b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_TRUE, (void *) b); fb = &b->stfb->Base; - fb->Delete = xmesa_delete_framebuffer; - - /* - * XXX we want to create surfaces for pipe, not renderbuffers for Mesa. - */ - - /* - * Front renderbuffer - */ - b->frontxrb = xmesa_create_renderbuffer(winsys, 0, &vis->mesa_visual, GL_FALSE); - if (!b->frontxrb) { - _mesa_free(b); - return NULL; - } - b->frontxrb->Parent = b; - b->frontxrb->drawable = d; - b->frontxrb->pixmap = (XMesaPixmap) d; - _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &b->frontxrb->St.Base); - - /* - * Back renderbuffer - */ - if (vis->mesa_visual.doubleBufferMode) { - b->backxrb = xmesa_create_renderbuffer(winsys, 0, &vis->mesa_visual, GL_TRUE); - if (!b->backxrb) { - /* XXX free front xrb too */ - _mesa_free(b); - return NULL; - } - b->backxrb->Parent = b; - /* determine back buffer implementation */ - b->db_mode = vis->ximage_flag ? BACK_XIMAGE : BACK_PIXMAP; - - _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &b->backxrb->St.Base); - } - - /* - * Software alpha planes - */ - if (vis->mesa_visual.alphaBits > 0 - && vis->undithered_pf != PF_8A8B8G8R - && vis->undithered_pf != PF_8A8R8G8B) { - /* Visual has alpha, but pixel format doesn't support it. - * We'll use an alpha renderbuffer wrapper. - */ - b->swAlpha = GL_TRUE; - } - else { - b->swAlpha = GL_FALSE; - } - - if (vis->mesa_visual.depthBits > 0 && - vis->mesa_visual.stencilBits > 0) { - /* combined depth/stencil */ - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb); - _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb); - } - else { - if (vis->mesa_visual.depthBits > 24) { - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT32); - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb); - } - else if (vis->mesa_visual.depthBits > 16) { - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb); - } - else if (vis->mesa_visual.depthBits > 1) { - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT16); - _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb); - } - - if (vis->mesa_visual.stencilBits > 0) { - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(GL_STENCIL_INDEX8_EXT); - _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb); - } - } - - if (vis->mesa_visual.accumRedBits > 0) { - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(GL_RGBA16); - _mesa_add_renderbuffer(fb, BUFFER_ACCUM, rb); - } - - /* - * Other renderbuffer (depth, stencil, etc) + * Create scratch XImage for xmesa_display_surface() */ - _mesa_add_soft_renderbuffers(fb, - GL_FALSE, /* color */ - GL_FALSE, /*vis->mesa_visual.haveDepthBuffer,*/ - GL_FALSE, /* stencil */ - GL_FALSE, /* accum */ - b->swAlpha, - vis->mesa_visual.numAuxBuffers > 0 ); + b->tempImage = XCreateImage(vis->display, + vis->visinfo->visual, + vis->visinfo->depth, + ZPixmap, 0, /* format, offset */ + NULL, /* data */ + 0, 0, /* size */ + 32, /* bitmap_pad */ + 0); /* bytes_per_line */ /* GLX_EXT_texture_from_pixmap */ b->TextureTarget = 0; @@ -442,8 +330,10 @@ XMesaBuffer xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis) { XMesaBuffer b; - for (b=XMesaBufferList; b; b=b->Next) { - if (b->display==dpy && b->cmap==cmap && b!=notThis) { + for (b = XMesaBufferList; b; b = b->Next) { + if (b->xm_visual->display == dpy && + b->cmap == cmap && + b != notThis) { return b; } } @@ -475,7 +365,10 @@ xmesa_free_buffer(XMesaBuffer buffer) /* Since the X window for the XMesaBuffer is going away, we don't * want to dereference this pointer in the future. */ - b->frontxrb->drawable = 0; + b->drawable = 0; + + buffer->tempImage->data = NULL; + XDestroyImage(buffer->tempImage); /* Unreference. If count = zero we'll really delete the buffer */ _mesa_unreference_framebuffer(&fb); @@ -490,22 +383,6 @@ xmesa_free_buffer(XMesaBuffer buffer) } -/** - * Copy X color table stuff from one XMesaBuffer to another. - */ -static void -copy_colortable_info(XMesaBuffer dst, const XMesaBuffer src) -{ - MEMCPY(dst->color_table, src->color_table, sizeof(src->color_table)); - MEMCPY(dst->pixel_to_r, src->pixel_to_r, sizeof(src->pixel_to_r)); - MEMCPY(dst->pixel_to_g, src->pixel_to_g, sizeof(src->pixel_to_g)); - MEMCPY(dst->pixel_to_b, src->pixel_to_b, sizeof(src->pixel_to_b)); - dst->num_alloced = src->num_alloced; - MEMCPY(dst->alloced_colors, src->alloced_colors, - sizeof(src->alloced_colors)); -} - - /**********************************************************************/ /***** Misc Private Functions *****/ @@ -513,450 +390,51 @@ copy_colortable_info(XMesaBuffer dst, const XMesaBuffer src) /** - * A replacement for XAllocColor. This function should never - * fail to allocate a color. When XAllocColor fails, we return - * the nearest matching color. If we have to allocate many colors - * this function isn't too efficient; the XQueryColors() could be - * done just once. - * Written by Michael Pichler, Brian Paul, Mark Kilgard - * Input: dpy - X display - * cmap - X colormap - * cmapSize - size of colormap - * In/Out: color - the XColor struct - * Output: exact - 1=exact color match, 0=closest match - * alloced - 1=XAlloc worked, 0=XAlloc failed + * Choose the pixel format for the given visual. + * This will tell the gallium driver how to pack pixel data into + * drawing surfaces. */ -static void -noFaultXAllocColor( int client, - XMesaDisplay *dpy, - XMesaColormap cmap, - int cmapSize, - XMesaColor *color, - int *exact, int *alloced ) +static GLuint +choose_pixel_format(XMesaVisual v) { -#ifdef XFree86Server - Pixel *ppixIn; - xrgb *ctable; -#else - /* we'll try to cache ctable for better remote display performance */ - static Display *prevDisplay = NULL; - static XMesaColormap prevCmap = 0; - static int prevCmapSize = 0; - static XMesaColor *ctable = NULL; -#endif - XMesaColor subColor; - int i, bestmatch; - double mindist; /* 3*2^16^2 exceeds long int precision. */ - - (void) client; - - /* First try just using XAllocColor. */ -#ifdef XFree86Server - if (AllocColor(cmap, - &color->red, &color->green, &color->blue, - &color->pixel, - client) == Success) -#else - if (XAllocColor(dpy, cmap, color)) -#endif - { - *exact = 1; - *alloced = 1; - return; - } - - /* Alloc failed, search for closest match */ - - /* Retrieve color table entries. */ - /* XXX alloca candidate. */ -#ifdef XFree86Server - ppixIn = (Pixel *) MALLOC(cmapSize * sizeof(Pixel)); - ctable = (xrgb *) MALLOC(cmapSize * sizeof(xrgb)); - for (i = 0; i < cmapSize; i++) { - ppixIn[i] = i; - } - QueryColors(cmap, cmapSize, ppixIn, ctable); -#else - if (prevDisplay != dpy || prevCmap != cmap - || prevCmapSize != cmapSize || !ctable) { - /* free previously cached color table */ - if (ctable) - _mesa_free(ctable); - /* Get the color table from X */ - ctable = (XMesaColor *) MALLOC(cmapSize * sizeof(XMesaColor)); - assert(ctable); - for (i = 0; i < cmapSize; i++) { - ctable[i].pixel = i; - } - XQueryColors(dpy, cmap, ctable, cmapSize); - prevDisplay = dpy; - prevCmap = cmap; - prevCmapSize = cmapSize; - } -#endif - - /* Find best match. */ - bestmatch = -1; - mindist = 0.0; - for (i = 0; i < cmapSize; i++) { - double dr = 0.30 * ((double) color->red - (double) ctable[i].red); - double dg = 0.59 * ((double) color->green - (double) ctable[i].green); - double db = 0.11 * ((double) color->blue - (double) ctable[i].blue); - double dist = dr * dr + dg * dg + db * db; - if (bestmatch < 0 || dist < mindist) { - bestmatch = i; - mindist = dist; - } - } - - /* Return result. */ - subColor.red = ctable[bestmatch].red; - subColor.green = ctable[bestmatch].green; - subColor.blue = ctable[bestmatch].blue; - /* Try to allocate the closest match color. This should only - * fail if the cell is read/write. Otherwise, we're incrementing - * the cell's reference count. - */ -#ifdef XFree86Server - if (AllocColor(cmap, - &subColor.red, &subColor.green, &subColor.blue, - &subColor.pixel, - client) == Success) { -#else - if (XAllocColor(dpy, cmap, &subColor)) { -#endif - *alloced = 1; - } - else { - /* do this to work around a problem reported by Frank Ortega */ - subColor.pixel = (unsigned long) bestmatch; - subColor.red = ctable[bestmatch].red; - subColor.green = ctable[bestmatch].green; - subColor.blue = ctable[bestmatch].blue; - subColor.flags = DoRed | DoGreen | DoBlue; - *alloced = 0; - } -#ifdef XFree86Server - _mesa_free(ppixIn); - _mesa_free(ctable); -#else - /* don't free table, save it for next time */ -#endif - - *color = subColor; - *exact = 0; -} - - - -/** - * Do setup for PF_GRAYSCALE pixel format. - * Note that buffer may be NULL. - */ -static GLboolean -setup_grayscale(int client, XMesaVisual v, - XMesaBuffer buffer, XMesaColormap cmap) -{ - if (GET_VISUAL_DEPTH(v)<4 || GET_VISUAL_DEPTH(v)>16) { - return GL_FALSE; - } - - if (buffer) { - XMesaBuffer prevBuffer; - - if (!cmap) { - return GL_FALSE; - } - - prevBuffer = xmesa_find_buffer(v->display, cmap, buffer); - if (prevBuffer && - (buffer->xm_visual->mesa_visual.rgbMode == - prevBuffer->xm_visual->mesa_visual.rgbMode)) { - /* Copy colormap stuff from previous XMesaBuffer which uses same - * X colormap. Do this to avoid time spent in noFaultXAllocColor. - */ - copy_colortable_info(buffer, prevBuffer); + if ( GET_REDMASK(v) == 0x0000ff + && GET_GREENMASK(v) == 0x00ff00 + && GET_BLUEMASK(v) == 0xff0000 + && v->BitsPerPixel == 32) { + if (CHECK_BYTE_ORDER(v)) { + /* no byteswapping needed */ + return 0 /* PIXEL_FORMAT_U_A8_B8_G8_R8 */; } else { - /* Allocate 256 shades of gray */ - int gray; - int colorsfailed = 0; - for (gray=0;gray<256;gray++) { - GLint r = gamma_adjust( v->RedGamma, gray, 255 ); - GLint g = gamma_adjust( v->GreenGamma, gray, 255 ); - GLint b = gamma_adjust( v->BlueGamma, gray, 255 ); - int exact, alloced; - XMesaColor xcol; - xcol.red = (r << 8) | r; - xcol.green = (g << 8) | g; - xcol.blue = (b << 8) | b; - noFaultXAllocColor( client, v->display, - cmap, GET_COLORMAP_SIZE(v), - &xcol, &exact, &alloced ); - if (!exact) { - colorsfailed++; - } - if (alloced) { - assert(buffer->num_alloced<256); - buffer->alloced_colors[buffer->num_alloced] = xcol.pixel; - buffer->num_alloced++; - } - - /*OLD - assert(gray < 576); - buffer->color_table[gray*3+0] = xcol.pixel; - buffer->color_table[gray*3+1] = xcol.pixel; - buffer->color_table[gray*3+2] = xcol.pixel; - assert(xcol.pixel < 65536); - buffer->pixel_to_r[xcol.pixel] = gray * 30 / 100; - buffer->pixel_to_g[xcol.pixel] = gray * 59 / 100; - buffer->pixel_to_b[xcol.pixel] = gray * 11 / 100; - */ - buffer->color_table[gray] = xcol.pixel; - assert(xcol.pixel < 65536); - buffer->pixel_to_r[xcol.pixel] = gray; - buffer->pixel_to_g[xcol.pixel] = gray; - buffer->pixel_to_b[xcol.pixel] = gray; - } - - if (colorsfailed && _mesa_getenv("MESA_DEBUG")) { - _mesa_warning(NULL, - "Note: %d out of 256 needed colors do not match exactly.\n", - colorsfailed ); - } + return PIPE_FORMAT_R8G8B8A8_UNORM; } } - - v->dithered_pf = PF_Grayscale; - v->undithered_pf = PF_Grayscale; - return GL_TRUE; -} - - - -/** - * Setup RGB rendering for a window with a PseudoColor, StaticColor, - * or 8-bit TrueColor visual visual. We try to allocate a palette of 225 - * colors (5 red, 9 green, 5 blue) and dither to approximate a 24-bit RGB - * color. While this function was originally designed just for 8-bit - * visuals, it has also proven to work from 4-bit up to 16-bit visuals. - * Dithering code contributed by Bob Mercier. - */ -static GLboolean -setup_dithered_color(int client, XMesaVisual v, - XMesaBuffer buffer, XMesaColormap cmap) -{ - if (GET_VISUAL_DEPTH(v)<4 || GET_VISUAL_DEPTH(v)>16) { - return GL_FALSE; - } - - if (buffer) { - XMesaBuffer prevBuffer; - - if (!cmap) { - return GL_FALSE; - } - - prevBuffer = xmesa_find_buffer(v->display, cmap, buffer); - if (prevBuffer && - (buffer->xm_visual->mesa_visual.rgbMode == - prevBuffer->xm_visual->mesa_visual.rgbMode)) { - /* Copy colormap stuff from previous, matching XMesaBuffer. - * Do this to avoid time spent in noFaultXAllocColor. - */ - copy_colortable_info(buffer, prevBuffer); + else if ( GET_REDMASK(v) == 0xff0000 + && GET_GREENMASK(v) == 0x00ff00 + && GET_BLUEMASK(v) == 0x0000ff + && v->BitsPerPixel == 32) { + if (CHECK_BYTE_ORDER(v)) { + /* no byteswapping needed */ + return PIPE_FORMAT_A8R8G8B8_UNORM; } else { - /* Allocate X colors and initialize color_table[], red_table[], etc */ - int r, g, b, i; - int colorsfailed = 0; - for (r = 0; r < DITH_R; r++) { - for (g = 0; g < DITH_G; g++) { - for (b = 0; b < DITH_B; b++) { - XMesaColor xcol; - int exact, alloced; - xcol.red =gamma_adjust(v->RedGamma, r*65535/(DITH_R-1),65535); - xcol.green=gamma_adjust(v->GreenGamma, g*65535/(DITH_G-1),65535); - xcol.blue =gamma_adjust(v->BlueGamma, b*65535/(DITH_B-1),65535); - noFaultXAllocColor( client, v->display, - cmap, GET_COLORMAP_SIZE(v), - &xcol, &exact, &alloced ); - if (!exact) { - colorsfailed++; - } - if (alloced) { - assert(buffer->num_alloced<256); - buffer->alloced_colors[buffer->num_alloced] = xcol.pixel; - buffer->num_alloced++; - } - i = DITH_MIX( r, g, b ); - assert(i < 576); - buffer->color_table[i] = xcol.pixel; - assert(xcol.pixel < 65536); - buffer->pixel_to_r[xcol.pixel] = r * 255 / (DITH_R-1); - buffer->pixel_to_g[xcol.pixel] = g * 255 / (DITH_G-1); - buffer->pixel_to_b[xcol.pixel] = b * 255 / (DITH_B-1); - } - } - } - - if (colorsfailed && _mesa_getenv("MESA_DEBUG")) { - _mesa_warning(NULL, - "Note: %d out of %d needed colors do not match exactly.\n", - colorsfailed, DITH_R * DITH_G * DITH_B ); - } - } - } - - v->dithered_pf = PF_Dither; - v->undithered_pf = PF_Lookup; - return GL_TRUE; -} - - -/** - * Setup RGB rendering for a window with a True/DirectColor visual. - */ -static void -setup_truecolor(XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap) -{ - unsigned long rmask, gmask, bmask; - (void) buffer; - (void) cmap; - - /* Compute red multiplier (mask) and bit shift */ - v->rshift = 0; - rmask = GET_REDMASK(v); - while ((rmask & 1)==0) { - v->rshift++; - rmask = rmask >> 1; - } - - /* Compute green multiplier (mask) and bit shift */ - v->gshift = 0; - gmask = GET_GREENMASK(v); - while ((gmask & 1)==0) { - v->gshift++; - gmask = gmask >> 1; - } - - /* Compute blue multiplier (mask) and bit shift */ - v->bshift = 0; - bmask = GET_BLUEMASK(v); - while ((bmask & 1)==0) { - v->bshift++; - bmask = bmask >> 1; - } - - /* - * Compute component-to-pixel lookup tables and dithering kernel - */ - { - static GLubyte kernel[16] = { - 0*16, 8*16, 2*16, 10*16, - 12*16, 4*16, 14*16, 6*16, - 3*16, 11*16, 1*16, 9*16, - 15*16, 7*16, 13*16, 5*16, - }; - GLint rBits = _mesa_bitcount(rmask); - GLint gBits = _mesa_bitcount(gmask); - GLint bBits = _mesa_bitcount(bmask); - GLint maxBits; - GLuint i; - - /* convert pixel components in [0,_mask] to RGB values in [0,255] */ - for (i=0; i<=rmask; i++) - v->PixelToR[i] = (unsigned char) ((i * 255) / rmask); - for (i=0; i<=gmask; i++) - v->PixelToG[i] = (unsigned char) ((i * 255) / gmask); - for (i=0; i<=bmask; i++) - v->PixelToB[i] = (unsigned char) ((i * 255) / bmask); - - /* convert RGB values from [0,255] to pixel components */ - - for (i=0;i<256;i++) { - GLint r = gamma_adjust(v->RedGamma, i, 255); - GLint g = gamma_adjust(v->GreenGamma, i, 255); - GLint b = gamma_adjust(v->BlueGamma, i, 255); - v->RtoPixel[i] = (r >> (8-rBits)) << v->rshift; - v->GtoPixel[i] = (g >> (8-gBits)) << v->gshift; - v->BtoPixel[i] = (b >> (8-bBits)) << v->bshift; + return PIPE_FORMAT_B8G8R8A8_UNORM; } - /* overflow protection */ - for (i=256;i<512;i++) { - v->RtoPixel[i] = v->RtoPixel[255]; - v->GtoPixel[i] = v->GtoPixel[255]; - v->BtoPixel[i] = v->BtoPixel[255]; - } - - /* setup dithering kernel */ - maxBits = rBits; - if (gBits > maxBits) maxBits = gBits; - if (bBits > maxBits) maxBits = bBits; - for (i=0;i<16;i++) { - v->Kernel[i] = kernel[i] >> maxBits; - } - - v->undithered_pf = PF_Truecolor; - v->dithered_pf = (GET_VISUAL_DEPTH(v)<24) ? PF_Dither_True : PF_Truecolor; } - - /* - * Now check for TrueColor visuals which we can optimize. - */ - if ( GET_REDMASK(v) ==0x0000ff - && GET_GREENMASK(v)==0x00ff00 - && GET_BLUEMASK(v) ==0xff0000 - && CHECK_BYTE_ORDER(v) - && v->BitsPerPixel==32 - && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { - /* common 32 bpp config used on SGI, Sun */ - v->undithered_pf = v->dithered_pf = PF_8A8B8G8R; /* ABGR */ - } - else if (GET_REDMASK(v) == 0xff0000 - && GET_GREENMASK(v)== 0x00ff00 - && GET_BLUEMASK(v) == 0x0000ff - && CHECK_BYTE_ORDER(v) - && v->RedGamma == 1.0 && v->GreenGamma == 1.0 && v->BlueGamma == 1.0){ - if (v->BitsPerPixel==32) { - /* if 32 bpp, and visual indicates 8 bpp alpha channel */ - if (GET_VISUAL_DEPTH(v) == 32 && v->mesa_visual.alphaBits == 8) - v->undithered_pf = v->dithered_pf = PF_8A8R8G8B; /* ARGB */ - else - v->undithered_pf = v->dithered_pf = PF_8R8G8B; /* xRGB */ - } - else if (v->BitsPerPixel == 24) { - v->undithered_pf = v->dithered_pf = PF_8R8G8B24; /* RGB */ - } - } - else if (GET_REDMASK(v) ==0xf800 - && GET_GREENMASK(v)==0x07e0 - && GET_BLUEMASK(v) ==0x001f - && CHECK_BYTE_ORDER(v) - && v->BitsPerPixel==16 - && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { + else if ( GET_REDMASK(v) == 0xf800 + && GET_GREENMASK(v) == 0x07e0 + && GET_BLUEMASK(v) == 0x001f + && CHECK_BYTE_ORDER(v) + && v->BitsPerPixel == 16) { /* 5-6-5 RGB */ - v->undithered_pf = PF_5R6G5B; - v->dithered_pf = PF_Dither_5R6G5B; + return PIPE_FORMAT_R5G6B5_UNORM; } -} - - -/** - * Setup RGB rendering for a window with a monochrome visual. - */ -static void -setup_monochrome( XMesaVisual v, XMesaBuffer b ) -{ - (void) b; - v->dithered_pf = v->undithered_pf = PF_1Bit; - /* if black=1 then we must flip pixel values */ - v->bitFlip = (GET_BLACK_PIXEL(v) != 0); + assert(0); + return 0; } - /** * When a context is bound for the first time, we can finally finish * initializing the context's visual and buffer information. @@ -972,10 +450,8 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, GLboolean rgb_flag, XMesaDrawable window, XMesaColormap cmap) { - int client = 0; - #ifdef XFree86Server - client = (window) ? CLIENT_ID(window->id) : 0; + int client = (window) ? CLIENT_ID(window->id) : 0; #endif ASSERT(!b || b->xm_visual == v); @@ -985,47 +461,22 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, assert(v->BitsPerPixel > 0); if (rgb_flag == GL_FALSE) { - /* COLOR-INDEXED WINDOW: - * Even if the visual is TrueColor or DirectColor we treat it as - * being color indexed. This is weird but might be useful to someone. - */ - v->dithered_pf = v->undithered_pf = PF_Index; - v->mesa_visual.indexBits = GET_VISUAL_DEPTH(v); + /* COLOR-INDEXED WINDOW: not supported*/ + return GL_FALSE; } else { /* RGB WINDOW: * We support RGB rendering into almost any kind of visual. */ const int xclass = v->mesa_visual.visualType; - if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { - setup_truecolor( v, b, cmap ); - } - else if (xclass == GLX_STATIC_GRAY && GET_VISUAL_DEPTH(v) == 1) { - setup_monochrome( v, b ); - } - else if (xclass == GLX_GRAY_SCALE || xclass == GLX_STATIC_GRAY) { - if (!setup_grayscale( client, v, b, cmap )) { - return GL_FALSE; - } - } - else if ((xclass == GLX_PSEUDO_COLOR || xclass == GLX_STATIC_COLOR) - && GET_VISUAL_DEPTH(v)>=4 && GET_VISUAL_DEPTH(v)<=16) { - if (!setup_dithered_color( client, v, b, cmap )) { - return GL_FALSE; - } - } - else { - _mesa_warning(NULL, "XMesa: RGB mode rendering not supported in given visual.\n"); + if (xclass != GLX_TRUE_COLOR && xclass == !GLX_DIRECT_COLOR) { + _mesa_warning(NULL, + "XMesa: RGB mode rendering not supported in given visual.\n"); return GL_FALSE; } v->mesa_visual.indexBits = 0; - - if (_mesa_getenv("MESA_NO_DITHER")) { - v->dithered_pf = v->undithered_pf; - } } - /* * If MESA_INFO env var is set print out some debugging info * which can help Brian figure out what's going on when a user @@ -1033,21 +484,14 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, */ if (_mesa_getenv("MESA_INFO")) { _mesa_printf("X/Mesa visual = %p\n", (void *) v); - _mesa_printf("X/Mesa dithered pf = %u\n", v->dithered_pf); - _mesa_printf("X/Mesa undithered pf = %u\n", v->undithered_pf); _mesa_printf("X/Mesa level = %d\n", v->mesa_visual.level); _mesa_printf("X/Mesa depth = %d\n", GET_VISUAL_DEPTH(v)); _mesa_printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); } if (b && window) { - char *data; - - /* Do window-specific initializations */ - /* these should have been set in create_xmesa_buffer */ - ASSERT(b->frontxrb->drawable == window); - ASSERT(b->frontxrb->pixmap == (XMesaPixmap) window); + ASSERT(b->drawable == window); /* Setup for single/double buffering */ if (v->mesa_visual.doubleBufferMode) { @@ -1055,59 +499,13 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, b->shm = check_for_xshm( v->display ); } - /* X11 graphics contexts */ + /* X11 graphics context */ #ifdef XFree86Server b->gc = CreateScratchGC(v->display, window->depth); #else b->gc = XCreateGC( v->display, window, 0, NULL ); #endif XMesaSetFunction( v->display, b->gc, GXcopy ); - - /* cleargc - for glClear() */ -#ifdef XFree86Server - b->cleargc = CreateScratchGC(v->display, window->depth); -#else - b->cleargc = XCreateGC( v->display, window, 0, NULL ); -#endif - XMesaSetFunction( v->display, b->cleargc, GXcopy ); - - /* - * Don't generate Graphics Expose/NoExpose events in swapbuffers(). - * Patch contributed by Michael Pichler May 15, 1995. - */ -#ifdef XFree86Server - b->swapgc = CreateScratchGC(v->display, window->depth); - { - CARD32 v[1]; - v[0] = FALSE; - dixChangeGC(NullClient, b->swapgc, GCGraphicsExposures, v, NULL); - } -#else - { - XGCValues gcvalues; - gcvalues.graphics_exposures = False; - b->swapgc = XCreateGC(v->display, window, - GCGraphicsExposures, &gcvalues); - } -#endif - XMesaSetFunction( v->display, b->swapgc, GXcopy ); - - /* Initialize the row buffer XImage for use in write_color_span() */ - data = (char*) MALLOC(MAX_WIDTH*4); -#ifdef XFree86Server - b->rowimage = XMesaCreateImage(GET_VISUAL_DEPTH(v), MAX_WIDTH, 1, data); -#else - b->rowimage = XCreateImage( v->display, - v->visinfo->visual, - v->visinfo->depth, - ZPixmap, 0, /*format, offset*/ - data, /*data*/ - MAX_WIDTH, 1, /*width, height*/ - 32, /*bitmap_pad*/ - 0 /*bytes_per_line*/ ); -#endif - if (!b->rowimage) - return GL_FALSE; } return GL_TRUE; @@ -1115,65 +513,6 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, -/* - * Convert an RGBA color to a pixel value. - */ -unsigned long -xmesa_color_to_pixel(XMesaContext xmesa, - GLubyte r, GLubyte g, GLubyte b, GLubyte a, - GLuint pixelFormat) -{ - GLcontext *ctx = xmesa->st->ctx; - - switch (pixelFormat) { - case PF_Index: - return 0; - case PF_Truecolor: - { - unsigned long p; - PACK_TRUECOLOR( p, r, g, b ); - return p; - } - case PF_8A8B8G8R: - return PACK_8A8B8G8R( r, g, b, a ); - case PF_8A8R8G8B: - return PACK_8A8R8G8B( r, g, b, a ); - case PF_8R8G8B: - /* fall through */ - case PF_8R8G8B24: - return PACK_8R8G8B( r, g, b ); - case PF_5R6G5B: - return PACK_5R6G5B( r, g, b ); - case PF_Dither: - { - DITHER_SETUP; - return DITHER( 1, 0, r, g, b ); - } - case PF_1Bit: - /* 382 = (3*255)/2 */ - return ((r+g+b) > 382) ^ xmesa->xm_visual->bitFlip; - case PF_Lookup: - { - LOOKUP_SETUP; - return LOOKUP( r, g, b ); - } - case PF_Grayscale: - return GRAY_RGB( r, g, b ); - case PF_Dither_True: - /* fall through */ - case PF_Dither_5R6G5B: - { - unsigned long p; - PACK_TRUEDITHER(p, 1, 0, r, g, b); - return p; - } - default: - _mesa_problem(ctx, "Bad pixel format in xmesa_color_to_pixel"); - } - return 0; -} - - #define NUM_VISUAL_TYPES 6 /** @@ -1248,7 +587,6 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, GLint level, GLint visualCaveat ) { - char *gamma; XMesaVisual v; GLint red_bits, green_bits, blue_bits, alpha_bits; @@ -1283,19 +621,6 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, MEMCPY(v->visinfo, visinfo, sizeof(*visinfo)); #endif - /* check for MESA_GAMMA environment variable */ - gamma = _mesa_getenv("MESA_GAMMA"); - if (gamma) { - v->RedGamma = v->GreenGamma = v->BlueGamma = 0.0; - sscanf( gamma, "%f %f %f", &v->RedGamma, &v->GreenGamma, &v->BlueGamma ); - if (v->RedGamma<=0.0) v->RedGamma = 1.0; - if (v->GreenGamma<=0.0) v->GreenGamma = v->RedGamma; - if (v->BlueGamma<=0.0) v->BlueGamma = v->RedGamma; - } - else { - v->RedGamma = v->GreenGamma = v->BlueGamma = 1.0; - } - v->ximage_flag = ximage_flag; #ifdef XFree86Server @@ -1384,66 +709,6 @@ void XMesaDestroyVisual( XMesaVisual v ) -static void -finish_or_flush( GLcontext *ctx ) -{ -#ifdef XFree86Server - /* NOT_NEEDED */ -#else - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - ctx->st->pipe->flush(ctx->st->pipe, 0); - if (xmesa) { - _glthread_LOCK_MUTEX(_xmesa_lock); - XSync( xmesa->display, False ); - _glthread_UNLOCK_MUTEX(_xmesa_lock); - } -#endif -} - - -/** - * Called by glViewport. - * This is a good time for us to poll the current X window size and adjust - * our renderbuffers to match the current window size. - * Remember, we have no opportunity to respond to conventional - * X Resize/StructureNotify events since the X driver has no event loop. - * Thus, we poll. - * Note that this trick isn't fool-proof. If the application never calls - * glViewport, our notion of the current window size may be incorrect. - * That problem led to the GLX_MESA_resize_buffers extension. - */ -static void -xmesa_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h) -{ - XMesaContext xmctx = XMESA_CONTEXT(ctx); - XMesaBuffer xmdrawbuf = XMESA_BUFFER(ctx->WinSysDrawBuffer); - XMesaBuffer xmreadbuf = XMESA_BUFFER(ctx->WinSysReadBuffer); - xmesa_check_and_update_buffer_size(xmctx, xmdrawbuf); - xmesa_check_and_update_buffer_size(xmctx, xmreadbuf); - (void) x; - (void) y; - (void) w; - (void) h; -} - - -/** - * Initialize the device driver function table with the functions - * we implement in this driver. - */ -static void -xmesa_init_driver_functions(struct dd_function_table *driver) -{ -#if 0 /* not needed for now */ - driver->Flush = finish_or_flush; - driver->Finish = finish_or_flush; -#else - (void) finish_or_flush; -#endif - driver->Viewport = xmesa_viewport; -} - - /** * Create a new XMesaContext. * \param v the XMesaVisual @@ -1458,6 +723,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) struct pipe_context *pipe; XMesaContext c; GLcontext *mesaCtx; + uint pf; if (firstTime) { _glthread_INIT_MUTEX(_xmesa_lock); @@ -1469,7 +735,10 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) if (!c) return NULL; - pipe = xmesa_create_context( c ); + pf = choose_pixel_format(v); + assert(pf); + + pipe = xmesa_create_pipe_context( c, pf ); c->st = st_create_context(pipe, &v->mesa_visual, share_list ? share_list->st : NULL); @@ -1491,27 +760,11 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) mesaCtx->Const.CheckArrayBounds = GL_TRUE; #endif - xmesa_init_driver_functions(&mesaCtx->Driver); - /* finish up xmesa context initializations */ - c->swapbytes = CHECK_BYTE_ORDER(v) ? GL_FALSE : GL_TRUE; c->xm_visual = v; c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */ - c->display = v->display; - c->pixelformat = v->dithered_pf; /* Dithering is enabled by default */ - /* override these functions, as if the xlib driver were derived from - * the softpipe driver. - */ - pipe->get_tile = xmesa_get_tile; - pipe->put_tile = xmesa_put_tile; - pipe->get_tile_rgba = xmesa_get_tile_rgba; - pipe->put_tile_rgba = xmesa_put_tile_rgba; - - c->st->haveFramebufferRegions = GL_FALSE; - - /* special pipe->clear function */ - pipe->clear = xmesa_clear; + c->st->haveFramebufferSurfaces = GL_TRUE; return c; } @@ -1731,8 +984,8 @@ XMesaDestroyBuffer(XMesaBuffer b) * and all attached renderbuffers. * Called when: * 1. the first time a buffer is bound to a context. - * 2. from glViewport to poll for window size changes - * 3. from the XMesaResizeBuffers() API function. + * 2. from the XMesaResizeBuffers() API function. + * 3. SwapBuffers. XXX probabaly from xm_flush_frontbuffer() too... * Note: it's possible (and legal) for xmctx to be NULL. That can happen * when resizing a buffer when no rendering context is bound. */ @@ -1740,7 +993,7 @@ void xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer) { GLuint width, height; - xmesa_get_window_size(drawBuffer->display, drawBuffer, &width, &height); + xmesa_get_window_size(drawBuffer->xm_visual->display, drawBuffer, &width, &height); st_resize_framebuffer(drawBuffer->stfb, width, height); } @@ -1770,7 +1023,7 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, if (&(c->mesa) == _mesa_get_current_context() && c->mesa.DrawBuffer == &drawBuffer->mesa_buffer && c->mesa.ReadBuffer == &readBuffer->mesa_buffer - && XMESA_BUFFER(c->mesa.DrawBuffer)->wasCurrent) { + && xmesa_buffer(c->mesa.DrawBuffer)->wasCurrent) { /* same context and buffer, do nothing */ return GL_TRUE; } @@ -1789,22 +1042,6 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, st_make_current(c->st, drawBuffer->stfb, readBuffer->stfb); -#if 0 - if (c->xm_visual->mesa_visual.rgbMode) { - /* - * Must recompute and set these pixel values because colormap - * can be different for different windows. - */ - c->clearpixel = xmesa_color_to_pixel( c, - c->clearcolor[0], - c->clearcolor[1], - c->clearcolor[2], - c->clearcolor[3], - c->xm_visual->undithered_pf); - XMesaSetForeground(c->display, drawBuffer->cleargc, c->clearpixel); - } -#endif - /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */ drawBuffer->wasCurrent = GL_TRUE; } @@ -1830,7 +1067,7 @@ XMesaContext XMesaGetCurrentContext( void ) { GET_CURRENT_CONTEXT(ctx); if (ctx) { - XMesaContext xmesa = XMESA_CONTEXT(ctx); + XMesaContext xmesa = xmesa_context(ctx); return xmesa; } else { @@ -1843,7 +1080,7 @@ XMesaBuffer XMesaGetCurrentBuffer( void ) { GET_CURRENT_CONTEXT(ctx); if (ctx) { - XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); + XMesaBuffer xmbuf = xmesa_buffer(ctx->DrawBuffer); return xmbuf; } else { @@ -1857,7 +1094,7 @@ XMesaBuffer XMesaGetCurrentReadBuffer( void ) { GET_CURRENT_CONTEXT(ctx); if (ctx) { - return XMESA_BUFFER(ctx->ReadBuffer); + return xmesa_buffer(ctx->ReadBuffer); } else { return 0; @@ -1918,62 +1155,19 @@ GLboolean XMesaSetFXmode( GLint mode ) PUBLIC void XMesaSwapBuffers( XMesaBuffer b ) { - if (!b->backxrb) { - /* single buffered */ - return; - } + struct pipe_surface *surf; /* If we're swapping the buffer associated with the current context * we have to flush any pending rendering commands first. */ st_notify_swapbuffers(b->stfb); - if (b->db_mode) { - if (b->backxrb->ximage) { - /* Copy Ximage (back buf) from client memory to server window */ -#if defined(USE_XSHM) && !defined(XFree86Server) - if (b->shm) { - /*_glthread_LOCK_MUTEX(_xmesa_lock);*/ - XShmPutImage( b->xm_visual->display, b->frontxrb->drawable, - b->swapgc, - b->backxrb->ximage, 0, 0, - 0, 0, xmesa_buffer_width(b), xmesa_buffer_height(b), - False ); - /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ - } - else -#endif - { - /*_glthread_LOCK_MUTEX(_xmesa_lock);*/ - XMesaPutImage( b->xm_visual->display, b->frontxrb->drawable, - b->swapgc, - b->backxrb->ximage, 0, 0, - 0, 0, - xmesa_buffer_width(b), xmesa_buffer_height(b)); - /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ - } - } - else if (b->backxrb->pixmap) { - /* Copy pixmap (back buf) to window (front buf) on server */ - /*_glthread_LOCK_MUTEX(_xmesa_lock);*/ - XMesaCopyArea( b->xm_visual->display, - b->backxrb->pixmap, /* source drawable */ - b->frontxrb->drawable, /* dest. drawable */ - b->swapgc, - 0, 0, xmesa_buffer_width(b), xmesa_buffer_height(b), - 0, 0 /* dest region */ - ); - /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ - } - - if (b->swAlpha) { - GET_CURRENT_CONTEXT(ctx); - _mesa_copy_soft_alpha_renderbuffers(ctx, &b->stfb->Base); - } + surf = st_get_framebuffer_surface(b->stfb, ST_SURFACE_BACK_LEFT); + if (surf) { + xmesa_display_surface(b, surf); } -#if !defined(XFree86Server) - XSync( b->xm_visual->display, False ); -#endif + + xmesa_check_and_update_buffer_size(NULL, b); } @@ -1983,82 +1177,22 @@ void XMesaSwapBuffers( XMesaBuffer b ) */ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) { - if (!b->backxrb) { - /* single buffered */ - return; - } + struct pipe_surface *surf_front + = st_get_framebuffer_surface(b->stfb, ST_SURFACE_FRONT_LEFT); + struct pipe_surface *surf_back + = st_get_framebuffer_surface(b->stfb, ST_SURFACE_BACK_LEFT); + struct pipe_context *pipe = NULL; /* XXX fix */ - /* If we're swapping the buffer associated with the current context - * we have to flush any pending rendering commands first. - */ - st_notify_swapbuffers(b->stfb); + if (!surf_front || !surf_back) + return; - if (b->db_mode) { - int yTop = xmesa_buffer_height(b) - y - height; - if (b->backxrb->ximage) { - /* Copy Ximage from host's memory to server's window */ -#if defined(USE_XSHM) && !defined(XFree86Server) - if (b->shm) { - /* XXX assuming width and height aren't too large! */ - XShmPutImage( b->xm_visual->display, b->frontxrb->drawable, - b->swapgc, - b->backxrb->ximage, x, yTop, - x, yTop, width, height, False ); - /* wait for finished event??? */ - } - else -#endif - { - /* XXX assuming width and height aren't too large! */ - XMesaPutImage( b->xm_visual->display, b->frontxrb->drawable, - b->swapgc, - b->backxrb->ximage, x, yTop, - x, yTop, width, height ); - } - } - else { - /* Copy pixmap to window on server */ - XMesaCopyArea( b->xm_visual->display, - b->backxrb->pixmap, /* source drawable */ - b->frontxrb->drawable, /* dest. drawable */ - b->swapgc, - x, yTop, width, height, /* source region */ - x, yTop /* dest region */ - ); - } - } + pipe->surface_copy(pipe, + surf_front, x, y, /* dest */ + surf_back, x, y, /* src */ + width, height); } -/* - * Return a pointer to the XMesa backbuffer Pixmap or XImage. This function - * is a way to get "under the hood" of X/Mesa so one can manipulate the - * back buffer directly. - * Output: pixmap - pointer to back buffer's Pixmap, or 0 - * ximage - pointer to back buffer's XImage, or NULL - * Return: GL_TRUE = context is double buffered - * GL_FALSE = context is single buffered - */ -#ifndef XFree86Server -GLboolean XMesaGetBackBuffer( XMesaBuffer b, - XMesaPixmap *pixmap, - XMesaImage **ximage ) -{ - if (b->db_mode) { - if (pixmap) - *pixmap = b->backxrb->pixmap; - if (ximage) - *ximage = b->backxrb->ximage; - return GL_TRUE; - } - else { - *pixmap = 0; - *ximage = NULL; - return GL_FALSE; - } -} -#endif /* XFree86Server */ - /* * Return the depth buffer associated with an XMesaBuffer. @@ -2071,33 +1205,32 @@ GLboolean XMesaGetBackBuffer( XMesaBuffer b, GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height, GLint *bytesPerValue, void **buffer ) { - struct gl_renderbuffer *rb - = b->stfb->Base.Attachment[BUFFER_DEPTH].Renderbuffer; - if (!rb || !rb->Data) { + 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; } - else { - *width = xmesa_buffer_width(b); - *height = xmesa_buffer_height(b); - *bytesPerValue = b->stfb->Base.Visual.depthBits <= 16 - ? sizeof(GLushort) : sizeof(GLuint); - *buffer = rb->Data; - return GL_TRUE; - } } void XMesaFlush( XMesaContext c ) { - if (c && c->display) { + if (c && c->xm_visual->display) { #ifdef XFree86Server /* NOT_NEEDED */ #else - XSync( c->display, False ); + XSync( c->xm_visual->display, False ); #endif } } @@ -2124,7 +1257,7 @@ XMesaBuffer XMesaFindBuffer( XMesaDisplay *dpy, XMesaDrawable d ) { XMesaBuffer b; for (b=XMesaBufferList; b; b=b->Next) { - if (b->frontxrb->drawable == d && b->display == dpy) { + if (b->drawable == d && b->xm_visual->display == dpy) { return b; } } @@ -2140,7 +1273,7 @@ void xmesa_destroy_buffers_on_display(XMesaDisplay *dpy) XMesaBuffer b, next; for (b = XMesaBufferList; b; b = next) { next = b->Next; - if (b->display == dpy) { + if (b->xm_visual->display == dpy) { xmesa_free_buffer(b); } } @@ -2156,12 +1289,15 @@ void XMesaGarbageCollect( void ) XMesaBuffer b, next; for (b=XMesaBufferList; b; b=next) { next = b->Next; - if (b->display && b->frontxrb->drawable && b->type == WINDOW) { + if (b->xm_visual && + b->xm_visual->display && + b->drawable && + b->type == WINDOW) { #ifdef XFree86Server /* NOT_NEEDED */ #else - XSync(b->display, False); - if (!window_exists( b->display, b->frontxrb->drawable )) { + XSync(b->xm_visual->display, False); + if (!window_exists( b->xm_visual->display, b->drawable )) { /* found a dead window, free the ancillary info */ XMesaDestroyBuffer( b ); } @@ -2175,55 +1311,7 @@ unsigned long XMesaDitherColor( XMesaContext xmesa, GLint x, GLint y, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ) { - GLcontext *ctx = xmesa->st->ctx; - GLint r = (GLint) (red * 255.0F); - GLint g = (GLint) (green * 255.0F); - GLint b = (GLint) (blue * 255.0F); - GLint a = (GLint) (alpha * 255.0F); - - switch (xmesa->pixelformat) { - case PF_Index: - return 0; - case PF_Truecolor: - { - unsigned long p; - PACK_TRUECOLOR( p, r, g, b ); - return p; - } - case PF_8A8B8G8R: - return PACK_8A8B8G8R( r, g, b, a ); - case PF_8A8R8G8B: - return PACK_8A8R8G8B( r, g, b, a ); - case PF_8R8G8B: - return PACK_8R8G8B( r, g, b ); - case PF_5R6G5B: - return PACK_5R6G5B( r, g, b ); - case PF_Dither: - { - DITHER_SETUP; - return DITHER( x, y, r, g, b ); - } - case PF_1Bit: - /* 382 = (3*255)/2 */ - return ((r+g+b) > 382) ^ xmesa->xm_visual->bitFlip; - case PF_Lookup: - { - LOOKUP_SETUP; - return LOOKUP( r, g, b ); - } - case PF_Grayscale: - return GRAY_RGB( r, g, b ); - case PF_Dither_5R6G5B: - /* fall through */ - case PF_Dither_True: - { - unsigned long p; - PACK_TRUEDITHER(p, x, y, r, g, b); - return p; - } - default: - _mesa_problem(NULL, "Bad pixel format in XMesaDitherColor"); - } + /* no longer supported */ return 0; } @@ -2236,149 +1324,19 @@ PUBLIC void XMesaResizeBuffers( XMesaBuffer b ) { GET_CURRENT_CONTEXT(ctx); - XMesaContext xmctx = XMESA_CONTEXT(ctx); + XMesaContext xmctx = xmesa_context(ctx); if (!xmctx) return; xmesa_check_and_update_buffer_size(xmctx, b); } -static GLint -xbuffer_to_renderbuffer(int buffer) -{ - assert(MAX_AUX_BUFFERS <= 4); - - switch (buffer) { - case GLX_FRONT_LEFT_EXT: - return BUFFER_FRONT_LEFT; - case GLX_FRONT_RIGHT_EXT: - return BUFFER_FRONT_RIGHT; - case GLX_BACK_LEFT_EXT: - return BUFFER_BACK_LEFT; - case GLX_BACK_RIGHT_EXT: - return BUFFER_BACK_RIGHT; - case GLX_AUX0_EXT: - return BUFFER_AUX0; - case GLX_AUX1_EXT: - return BUFFER_AUX1; - case GLX_AUX2_EXT: - return BUFFER_AUX2; - case GLX_AUX3_EXT: - return BUFFER_AUX3; - case GLX_AUX4_EXT: - case GLX_AUX5_EXT: - case GLX_AUX6_EXT: - case GLX_AUX7_EXT: - case GLX_AUX8_EXT: - case GLX_AUX9_EXT: - default: - /* BadValue error */ - return -1; - } -} PUBLIC void XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, const int *attrib_list) { -#if 0 - GET_CURRENT_CONTEXT(ctx); - const GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - struct gl_texture_object *texObj; -#endif - struct gl_renderbuffer *rb; - struct xmesa_renderbuffer *xrb; - GLint b; - XMesaImage *img = NULL; - GLboolean freeImg = GL_FALSE; - - b = xbuffer_to_renderbuffer(buffer); - if (b < 0) - return; - - if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_NONE_EXT) - return; /* BadMatch error */ - - rb = drawable->stfb->Base.Attachment[b].Renderbuffer; - if (!rb) { - /* invalid buffer */ - return; - } - xrb = xmesa_renderbuffer(rb); - -#if 0 - switch (drawable->TextureTarget) { - case GLX_TEXTURE_1D_EXT: - texObj = texUnit->Current1D; - break; - case GLX_TEXTURE_2D_EXT: - texObj = texUnit->Current2D; - break; - case GLX_TEXTURE_RECTANGLE_EXT: - texObj = texUnit->CurrentRect; - break; - default: - return; /* BadMatch error */ - } -#endif - - /* - * The following is a quick and simple way to implement - * BindTexImage. The better way is to write some new FetchTexel() - * functions which would extract texels from XImages. We'd still - * need to use GetImage when texturing from a Pixmap (front buffer) - * but texturing from a back buffer (XImage) would avoid an image - * copy. - */ - - /* get XImage */ - if (xrb->pixmap) { - img = XMesaGetImage(dpy, xrb->pixmap, 0, 0, rb->Width, rb->Height, ~0L, - ZPixmap); - freeImg = GL_TRUE; - } - else if (xrb->ximage) { - img = xrb->ximage; - } - - /* store the XImage as a new texture image */ - if (img) { - GLenum format, type, intFormat; - if (img->bits_per_pixel == 32) { - format = GL_BGRA; - type = GL_UNSIGNED_BYTE; - intFormat = GL_RGBA; - } - else if (img->bits_per_pixel == 24) { - format = GL_BGR; - type = GL_UNSIGNED_BYTE; - intFormat = GL_RGB; - } - else if (img->bits_per_pixel == 16) { - format = GL_BGR; - type = GL_UNSIGNED_SHORT_5_6_5; - intFormat = GL_RGB; - } - else { - _mesa_problem(NULL, "Unexpected XImage format in XMesaBindTexImage"); - return; - } - if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_RGBA_EXT) { - intFormat = GL_RGBA; - } - else if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_RGB_EXT) { - intFormat = GL_RGB; - } - - _mesa_TexImage2D(GL_TEXTURE_2D, 0, intFormat, rb->Width, rb->Height, 0, - format, type, img->data); - - if (freeImg) { - XMesaDestroyImage(img); - } - } } @@ -2386,10 +1344,5 @@ XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, PUBLIC void XMesaReleaseTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer) { - const GLint b = xbuffer_to_renderbuffer(buffer); - if (b < 0) - return; - - /* no-op for now */ } diff --git a/src/mesa/pipe/xlib/xm_buffer.c b/src/mesa/pipe/xlib/xm_buffer.c deleted file mode 100644 index 7dc85bf2ebe..00000000000 --- a/src/mesa/pipe/xlib/xm_buffer.c +++ /dev/null @@ -1,482 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5.2 - * - * Copyright (C) 1999-2006 Brian Paul 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. - * - * 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. - */ - - -/** - * \file xm_buffer.h - * Framebuffer and renderbuffer-related functions. - */ - - -#include "GL/xmesa.h" -#include "glxheader.h" -#include "xmesaP.h" -#include "main/imports.h" -#include "main/framebuffer.h" -#include "main/renderbuffer.h" -#include "pipe/p_state.h" -#include "pipe/p_defines.h" -#include "pipe/p_winsys.h" -#include "state_tracker/st_context.h" - - -#if defined(USE_XSHM) && !defined(XFree86Server) -static volatile int mesaXErrorFlag = 0; - -/** - * Catches potential Xlib errors. - */ -static int -mesaHandleXError(XMesaDisplay *dpy, XErrorEvent *event) -{ - (void) dpy; - (void) event; - mesaXErrorFlag = 1; - return 0; -} - -/** - * Allocate a shared memory XImage back buffer for the given XMesaBuffer. - * Return: GL_TRUE if success, GL_FALSE if error - */ -static GLboolean -alloc_back_shm_ximage(XMesaBuffer b, GLuint width, GLuint height) -{ - /* - * We have to do a _lot_ of error checking here to be sure we can - * really use the XSHM extension. It seems different servers trigger - * errors at different points if the extension won't work. Therefore - * we have to be very careful... - */ - GC gc; - int (*old_handler)(XMesaDisplay *, XErrorEvent *); - - if (width == 0 || height == 0) { - /* this will be true the first time we're called on 'b' */ - return GL_FALSE; - } - - b->backxrb->ximage = XShmCreateImage(b->xm_visual->display, - b->xm_visual->visinfo->visual, - b->xm_visual->visinfo->depth, - ZPixmap, NULL, &b->shminfo, - width, height); - if (b->backxrb->ximage == NULL) { - _mesa_warning(NULL, "alloc_back_buffer: Shared memory error (XShmCreateImage), disabling.\n"); - b->shm = 0; - return GL_FALSE; - } - - b->shminfo.shmid = shmget(IPC_PRIVATE, b->backxrb->ximage->bytes_per_line - * b->backxrb->ximage->height, IPC_CREAT|0777); - if (b->shminfo.shmid < 0) { - _mesa_warning(NULL, "shmget failed while allocating back buffer.\n"); - XDestroyImage(b->backxrb->ximage); - b->backxrb->ximage = NULL; - _mesa_warning(NULL, "alloc_back_buffer: Shared memory error (shmget), disabling.\n"); - b->shm = 0; - return GL_FALSE; - } - - b->shminfo.shmaddr = b->backxrb->ximage->data - = (char*)shmat(b->shminfo.shmid, 0, 0); - if (b->shminfo.shmaddr == (char *) -1) { - _mesa_warning(NULL, "shmat() failed while allocating back buffer.\n"); - XDestroyImage(b->backxrb->ximage); - shmctl(b->shminfo.shmid, IPC_RMID, 0); - b->backxrb->ximage = NULL; - _mesa_warning(NULL, "alloc_back_buffer: Shared memory error (shmat), disabling.\n"); - b->shm = 0; - return GL_FALSE; - } - - b->shminfo.readOnly = False; - mesaXErrorFlag = 0; - old_handler = XSetErrorHandler(mesaHandleXError); - /* This may trigger the X protocol error we're ready to catch: */ - XShmAttach(b->xm_visual->display, &b->shminfo); - XSync(b->xm_visual->display, False); - - if (mesaXErrorFlag) { - /* we are on a remote display, this error is normal, don't print it */ - XFlush(b->xm_visual->display); - mesaXErrorFlag = 0; - XDestroyImage(b->backxrb->ximage); - shmdt(b->shminfo.shmaddr); - shmctl(b->shminfo.shmid, IPC_RMID, 0); - b->backxrb->ximage = NULL; - b->shm = 0; - (void) XSetErrorHandler(old_handler); - return GL_FALSE; - } - - shmctl(b->shminfo.shmid, IPC_RMID, 0); /* nobody else needs it */ - - /* Finally, try an XShmPutImage to be really sure the extension works */ - gc = XCreateGC(b->xm_visual->display, b->frontxrb->drawable, 0, NULL); - XShmPutImage(b->xm_visual->display, b->frontxrb->drawable, gc, - b->backxrb->ximage, 0, 0, 0, 0, 1, 1 /*one pixel*/, False); - XSync(b->xm_visual->display, False); - XFreeGC(b->xm_visual->display, gc); - (void) XSetErrorHandler(old_handler); - if (mesaXErrorFlag) { - XFlush(b->xm_visual->display); - mesaXErrorFlag = 0; - XDestroyImage(b->backxrb->ximage); - shmdt(b->shminfo.shmaddr); - shmctl(b->shminfo.shmid, IPC_RMID, 0); - b->backxrb->ximage = NULL; - b->shm = 0; - return GL_FALSE; - } - - return GL_TRUE; -} -#else -static GLboolean -alloc_back_shm_ximage(XMesaBuffer b, GLuint width, GLuint height) -{ - /* Can't compile XSHM support */ - return GL_FALSE; -} -#endif - - - -/** - * Setup an off-screen pixmap or Ximage to use as the back buffer. - * Input: b - the X/Mesa buffer - */ -static void -alloc_back_buffer(XMesaBuffer b, GLuint width, GLuint height) -{ - if (b->db_mode == BACK_XIMAGE) { - /* Deallocate the old backxrb->ximage, if any */ - if (b->backxrb->ximage) { -#if defined(USE_XSHM) && !defined(XFree86Server) - if (b->shm) { - XShmDetach(b->xm_visual->display, &b->shminfo); - XDestroyImage(b->backxrb->ximage); - shmdt(b->shminfo.shmaddr); - } - else -#endif - XMesaDestroyImage(b->backxrb->ximage); - b->backxrb->ximage = NULL; - } - - if (width == 0 || height == 0) - return; - - /* Allocate new back buffer */ - if (b->shm == 0 || !alloc_back_shm_ximage(b, width, height)) { - /* Allocate a regular XImage for the back buffer. */ -#ifdef XFree86Server - b->backxrb->ximage = XMesaCreateImage(b->xm_visual->BitsPerPixel, - width, height, NULL); -#else - b->backxrb->ximage = XCreateImage(b->xm_visual->display, - b->xm_visual->visinfo->visual, - GET_VISUAL_DEPTH(b->xm_visual), - ZPixmap, 0, /* format, offset */ - NULL, - width, height, - 8, 0); /* pad, bytes_per_line */ -#endif - if (!b->backxrb->ximage) { - _mesa_warning(NULL, "alloc_back_buffer: XCreateImage failed.\n"); - return; - } - b->backxrb->ximage->data = (char *) MALLOC(b->backxrb->ximage->height - * b->backxrb->ximage->bytes_per_line); - if (!b->backxrb->ximage->data) { - _mesa_warning(NULL, "alloc_back_buffer: MALLOC failed.\n"); - XMesaDestroyImage(b->backxrb->ximage); - b->backxrb->ximage = NULL; - } - } - b->backxrb->pixmap = None; - } - else if (b->db_mode == BACK_PIXMAP) { - /* Free the old back pixmap */ - if (b->backxrb->pixmap) { - XMesaFreePixmap(b->xm_visual->display, b->backxrb->pixmap); - b->backxrb->pixmap = 0; - } - - if (width > 0 && height > 0) { - /* Allocate new back pixmap */ - b->backxrb->pixmap = XMesaCreatePixmap(b->xm_visual->display, - b->frontxrb->drawable, - width, height, - GET_VISUAL_DEPTH(b->xm_visual)); - } - - b->backxrb->ximage = NULL; - } -} - - -static void -xmesa_delete_renderbuffer(struct gl_renderbuffer *rb) -{ - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - if (xrb->St.surface) { - struct pipe_winsys *ws = xrb->St.surface->winsys; - ws->surface_release(ws, &xrb->St.surface); - } - - /* XXX Note: the ximage or Pixmap attached to this renderbuffer - * should probably get freed here, but that's currently done in - * XMesaDestroyBuffer(). - */ - _mesa_free(rb); -} - - -static void -finish_surface_init(GLcontext *ctx, struct xmesa_renderbuffer *xrb) -{ - struct pipe_context *pipe = ctx->st->pipe; - if (!xrb->St.surface->region) { - int w = 1, h = 1; - xrb->St.surface->region = pipe->winsys->region_alloc(pipe->winsys, - 1, w, h, 0x0); - } -} - - -/** - * Reallocate renderbuffer storage for front color buffer. - * Called via gl_renderbuffer::AllocStorage() - */ -static GLboolean -xmesa_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, GLuint width, GLuint height) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - struct xmesa_surface *xms = xmesa_surface(xrb->St.surface); - - /* just clear these to be sure we don't accidentally use them */ - xrb->origin1 = NULL; - xrb->origin2 = NULL; - xrb->origin3 = NULL; - xrb->origin4 = NULL; - - /* for the FLIP macro: */ - xrb->bottom = height - 1; - - rb->Width = width; - rb->Height = height; - rb->InternalFormat = internalFormat; - - if (!xrb->St.surface || !xrb->St.surface->region) - finish_surface_init(ctx, xrb); - - /* surface info */ - xms->surface.width = width; - xms->surface.height = height; - xms->display = xmesa->display; - xms->drawable = xrb->drawable; - xms->gc = xrb->Parent->cleargc; - xms->ximage = NULL; - - return GL_TRUE; -} - - -/** - * Reallocate renderbuffer storage for back color buffer. - * Called via gl_renderbuffer::AllocStorage() - */ -static GLboolean -xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, GLuint width, GLuint height) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - struct xmesa_surface *xms = xmesa_surface(xrb->St.surface); - - /* reallocate the back buffer XImage or Pixmap */ - assert(xrb->Parent); - alloc_back_buffer(xrb->Parent, width, height); - - /* same as front buffer */ - /* XXX why is this here? */ - (void) xmesa_alloc_front_storage(ctx, rb, internalFormat, width, height); - - /* plus... */ - if (xrb->ximage) { - /* Needed by PIXELADDR1 macro */ - xrb->width1 = xrb->ximage->bytes_per_line; - xrb->origin1 = (GLubyte *) xrb->ximage->data + xrb->width1 * (height - 1); - - /* Needed by PIXELADDR2 macro */ - xrb->width2 = xrb->ximage->bytes_per_line / 2; - xrb->origin2 = (GLushort *) xrb->ximage->data + xrb->width2 * (height - 1); - - /* Needed by PIXELADDR3 macro */ - xrb->width3 = xrb->ximage->bytes_per_line; - xrb->origin3 = (GLubyte *) xrb->ximage->data + xrb->width3 * (height - 1); - - /* Needed by PIXELADDR4 macro */ - xrb->width4 = xrb->ximage->width; - xrb->origin4 = (GLuint *) xrb->ximage->data + xrb->width4 * (height - 1); - } - else { - /* out of memory or buffer size is 0 x 0 */ - xrb->width1 = xrb->width2 = xrb->width3 = xrb->width4 = 0; - xrb->origin1 = NULL; - xrb->origin2 = NULL; - xrb->origin3 = NULL; - xrb->origin4 = NULL; - } - - if (!xrb->St.surface || !xrb->St.surface->region) - finish_surface_init(ctx, xrb); - - xrb->St.surface->width = width; - xrb->St.surface->height = height; - - /* surface info */ - xms->surface.width = width; - xms->surface.height = height; - xms->display = xmesa->display; - xms->drawable = xrb->drawable; - xms->gc = xrb->Parent->cleargc; - xms->ximage = xrb->ximage; - - return GL_TRUE; -} - - -/** - * Called to create the front/back color renderbuffers, not user-created - * renderbuffers. - */ -struct xmesa_renderbuffer * -xmesa_create_renderbuffer(struct pipe_winsys *winsys, - GLuint name, const GLvisual *visual, - GLboolean backBuffer) -{ - struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer); - if (xrb) { - GLuint name = 0; - GLuint pipeFormat = 0; - struct xmesa_surface *xms; - - _mesa_init_renderbuffer(&xrb->St.Base, name); - - xrb->St.Base.Delete = xmesa_delete_renderbuffer; - if (backBuffer) - xrb->St.Base.AllocStorage = xmesa_alloc_back_storage; - else - xrb->St.Base.AllocStorage = xmesa_alloc_front_storage; - - if (visual->rgbMode) { - xrb->St.Base.InternalFormat = GL_RGBA; - xrb->St.Base._BaseFormat = GL_RGBA; - xrb->St.Base.DataType = GL_UNSIGNED_BYTE; - xrb->St.Base.RedBits = visual->redBits; - xrb->St.Base.GreenBits = visual->greenBits; - xrb->St.Base.BlueBits = visual->blueBits; - xrb->St.Base.AlphaBits = visual->alphaBits; - pipeFormat = PIPE_FORMAT_U_A8_R8_G8_B8; - } - else { - xrb->St.Base.InternalFormat = GL_COLOR_INDEX; - xrb->St.Base._BaseFormat = GL_COLOR_INDEX; - xrb->St.Base.DataType = GL_UNSIGNED_INT; - xrb->St.Base.IndexBits = visual->indexBits; - } - /* only need to set Red/Green/EtcBits fields for user-created RBs */ - xrb->St.surface = xmesa_new_color_surface(winsys, pipeFormat); - xms = (struct xmesa_surface *) xrb->St.surface; - xms->xrb = xrb; - } - return xrb; -} - - -/** - * Called via gl_framebuffer::Delete() method when this buffer - * is _really_ being deleted. - */ -void -xmesa_delete_framebuffer(struct gl_framebuffer *fb) -{ - XMesaBuffer b = XMESA_BUFFER(fb); - - if (b->num_alloced > 0) { - /* If no other buffer uses this X colormap then free the colors. */ - if (!xmesa_find_buffer(b->display, b->cmap, b)) { -#ifdef XFree86Server - int client = 0; - if (b->frontxrb->drawable) - client = CLIENT_ID(b->frontxrb->drawable->id); - (void)FreeColors(b->cmap, client, - b->num_alloced, b->alloced_colors, 0); -#else - XFreeColors(b->display, b->cmap, - b->alloced_colors, b->num_alloced, 0); -#endif - } - } - - if (b->gc) - XMesaFreeGC(b->display, b->gc); - if (b->cleargc) - XMesaFreeGC(b->display, b->cleargc); - if (b->swapgc) - XMesaFreeGC(b->display, b->swapgc); - - if (fb->Visual.doubleBufferMode) { - /* free back ximage/pixmap/shmregion */ - if (b->backxrb->ximage) { -#if defined(USE_XSHM) && !defined(XFree86Server) - if (b->shm) { - XShmDetach( b->display, &b->shminfo ); - XDestroyImage( b->backxrb->ximage ); - shmdt( b->shminfo.shmaddr ); - } - else -#endif - XMesaDestroyImage( b->backxrb->ximage ); - b->backxrb->ximage = NULL; - } - if (b->backxrb->pixmap) { - XMesaFreePixmap( b->display, b->backxrb->pixmap ); - } - } - - if (b->rowimage) { - _mesa_free( b->rowimage->data ); - b->rowimage->data = NULL; - XMesaDestroyImage( b->rowimage ); - } - - _mesa_free_framebuffer_data(fb); - _mesa_free(fb); -} diff --git a/src/mesa/pipe/xlib/xm_surface.c b/src/mesa/pipe/xlib/xm_surface.c deleted file mode 100644 index 43e50507476..00000000000 --- a/src/mesa/pipe/xlib/xm_surface.c +++ /dev/null @@ -1,730 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.1 - * - * Copyright (C) 1999-2007 Brian Paul 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. - * - * 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. - */ - - -/** - * \file xm_surface.c - * Code to allow the softpipe code to write to X windows/buffers. - * This is a bit of a hack for now. We've basically got two different - * abstractions for color buffers: gl_renderbuffer and pipe_surface. - * They'll need to get merged someday... - * For now, they're separate things that point to each other. - */ - - -#include "GL/xmesa.h" -#include "glxheader.h" -#include "xmesaP.h" -#include "main/context.h" -#include "main/imports.h" -#include "main/macros.h" - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_winsys.h" -#include "pipe/softpipe/sp_context.h" -#include "pipe/softpipe/sp_clear.h" -#include "pipe/softpipe/sp_tile_cache.h" -#include "pipe/softpipe/sp_surface.h" -#include "state_tracker/st_context.h" - - -/* - * Dithering kernels and lookup tables. - */ - -const int xmesa_kernel8[DITH_DY * DITH_DX] = { - 0 * MAXC, 8 * MAXC, 2 * MAXC, 10 * MAXC, - 12 * MAXC, 4 * MAXC, 14 * MAXC, 6 * MAXC, - 3 * MAXC, 11 * MAXC, 1 * MAXC, 9 * MAXC, - 15 * MAXC, 7 * MAXC, 13 * MAXC, 5 * MAXC, -}; - -const int xmesa_kernel1[16] = { - 0*47, 9*47, 4*47, 12*47, /* 47 = (255*3)/16 */ - 6*47, 2*47, 14*47, 8*47, - 10*47, 1*47, 5*47, 11*47, - 7*47, 13*47, 3*47, 15*47 -}; - - - -#define CLIP_TILE \ - do { \ - if (x >= ps->width) \ - return; \ - if (y >= ps->height) \ - return; \ - if (x + w > ps->width) \ - w = ps->width - x; \ - if (y + h > ps->height) \ - h = ps->height -y; \ - } while(0) - - - -/* - * The following functions are used to trap XGetImage() calls which - * generate BadMatch errors if the drawable isn't mapped. - */ - -#ifndef XFree86Server -static int caught_xgetimage_error = 0; -static int (*old_xerror_handler)( XMesaDisplay *dpy, XErrorEvent *ev ); -static unsigned long xgetimage_serial; - -/* - * This is the error handler which will be called if XGetImage fails. - */ -static int xgetimage_error_handler( XMesaDisplay *dpy, XErrorEvent *ev ) -{ - if (ev->serial==xgetimage_serial && ev->error_code==BadMatch) { - /* caught the expected error */ - caught_xgetimage_error = 0; - } - else { - /* call the original X error handler, if any. otherwise ignore */ - if (old_xerror_handler) { - (*old_xerror_handler)( dpy, ev ); - } - } - return 0; -} - - -/* - * Call this right before XGetImage to setup error trap. - */ -static void catch_xgetimage_errors( XMesaDisplay *dpy ) -{ - xgetimage_serial = NextRequest( dpy ); - old_xerror_handler = XSetErrorHandler( xgetimage_error_handler ); - caught_xgetimage_error = 0; -} - - -/* - * Call this right after XGetImage to check if an error occured. - */ -static int check_xgetimage_errors( void ) -{ - /* restore old handler */ - (void) XSetErrorHandler( old_xerror_handler ); - /* return 0=no error, 1=error caught */ - return caught_xgetimage_error; -} -#endif - - -/** - * Wrapper for XGetImage() that catches BadMatch errors that can occur - * when the window is unmapped or the x/y/w/h extend beyond the window - * bounds. - * If build into xserver, wrap the internal GetImage method. - */ -static XMesaImage * -xget_image(XMesaDisplay *dpy, Drawable d, int x, int y, uint w, uint h) -{ -#ifdef XFree86Server - uint bpp = 4; /* XXX fix this */ - XMesaImage *ximage = (XMesaImage *) malloc(sizeof(XMesaImage)); - if (ximage) { - ximage->data = malloc(width * height * bpp); - } - (*dpy->GetImage)(d, x, y, w, h, ZPixmap, ~0L, (pointer)ximage->data); - ximage->width = w; - ximage->height = h; - ximage->bytes_per_row = w * bpp; - return ximage; -#else - int error; - XMesaImage *ximage; - catch_xgetimage_errors(dpy); - ximage = XGetImage(dpy, d, x, y, w, h, AllPlanes, ZPixmap); - error = check_xgetimage_errors(); - return ximage; -#endif -} - - - -/** - * Return raw pixels from pixmap or XImage. - */ -void -xmesa_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, void *p, int dst_stride) -{ - const uint w0 = w; - struct xmesa_surface *xms = xmesa_surface(ps); - XMesaImage *ximage = NULL; - ubyte *dst = (ubyte *) p; - uint i; - - if (!xms->drawable && !xms->ximage) { - /* not an X surface */ - softpipe_get_tile(pipe, ps, x, y, w, h, p, dst_stride); - return; - } - - CLIP_TILE; - - if (!xms->ximage) { - /* XImage = pixmap data */ - assert(xms->drawable); - ximage = xget_image(xms->display, xms->drawable, x, y, w, h); - if (!ximage) - return; - x = y = 0; - } - else { - ximage = xms->ximage; - } - - /* this could be optimized/simplified */ - switch (ps->format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - if (!dst_stride) { - dst_stride = w0 * 4; - } - for (i = 0; i < h; i++) { - memcpy(dst, ximage->data + y * ximage->bytes_per_line + x * 4, 4 * w); - dst += dst_stride; - } - break; - case PIPE_FORMAT_U_R5_G6_B5: - if (!dst_stride) { - dst_stride = w0 * 2; - } - for (i = 0; i < h; i++) { - memcpy(dst, ximage->data + y * ximage->bytes_per_line + x * 2, 4 * 2); - dst += dst_stride; - } - break; - default: - assert(0); - } - - if (!xms->ximage) { - XMesaDestroyImage(ximage); - } -} - - -/** - * Put raw pixels into pixmap or XImage. - */ -void -xmesa_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, const void *p, int src_stride) -{ - const uint w0 = w; - struct xmesa_surface *xms = xmesa_surface(ps); - const ubyte *src = (const ubyte *) p; - XMesaImage *ximage; - - if (!xms->drawable && !xms->ximage) { - /* not an X surface */ - softpipe_put_tile(pipe, ps, x, y, w, h, p, src_stride); - return; - } - - CLIP_TILE; - - if (xms->ximage) { - /* put to ximage */ - ximage = xms->ximage; - char *dst; - int i; - - /* this could be optimized/simplified */ - switch (ps->format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - if (!src_stride) { - src_stride = w0 * 4; - } - dst = ximage->data + y * ximage->bytes_per_line + x * 4; - for (i = 0; i < h; i++) { - memcpy(dst, src, w * 4); - dst += ximage->bytes_per_line; - src += src_stride; - } - break; - case PIPE_FORMAT_U_R5_G6_B5: - if (!src_stride) { - src_stride = w0 * 2; - } - dst = ximage->data + y * ximage->bytes_per_line + x * 2; - for (i = 0; i < h; i++) { - memcpy(dst, src, w * 2); - dst += ximage->bytes_per_line; - src += src_stride; - } - break; - default: - assert(0); - } - } - else { - /* put to pixmap/window */ - /* Create temp XImage for data */ -#ifdef XFree86Server - ximage = XMesaCreateImage(GET_VISUAL_DEPTH(v), w, h, p); -#else - XVisualInfo *visinfo = xms->xrb->Parent->xm_visual->visinfo; - ximage = XCreateImage(xms->display, - visinfo->visual, - visinfo->depth, - ZPixmap, 0, /* format, offset */ - (char *) p, /* data */ - w, h, /* width, height */ - 32, /* bitmap_pad */ - 0); /* bytes_per_line */ -#endif - - /* send XImage data to pixmap */ - XPutImage(xms->display, xms->drawable, xms->gc, - ximage, 0, 0, x, y, w, h); - /* clean-up */ - ximage->data = NULL; /* prevents freeing user data at 'p' */ - XMesaDestroyImage(ximage); - } -} - - -void -xmesa_get_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, float *pixels) -{ - const uint w0 = w; - struct xmesa_surface *xms = xmesa_surface(ps); - XMesaImage *ximage = NULL; - float *pRow = pixels; - uint i, j; - - if (!xms->drawable && !xms->ximage) { - /* not an X surface */ - softpipe_get_tile_rgba(pipe, ps, x, y, w, h, pixels); - return; - } - - CLIP_TILE; - - if (!xms->ximage) { - /* XImage = pixmap data */ - assert(xms->drawable); - ximage = xget_image(xms->display, xms->drawable, x, y, w, h); - if (!ximage) - return; - x = y = 0; - } - else { - ximage = xms->ximage; - } - - switch (ps->format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - { - const uint *src - = (uint *) (ximage->data + y * ximage->bytes_per_line + x * 4); - for (i = 0; i < h; i++) { - float *p = pRow; - for (j = 0; j < w; j++) { - uint pix = src[j]; - ubyte r = ((pix >> 16) & 0xff); - ubyte g = ((pix >> 8) & 0xff); - ubyte b = ( pix & 0xff); - ubyte a = ((pix >> 24) & 0xff); - p[0] = UBYTE_TO_FLOAT(r); - p[1] = UBYTE_TO_FLOAT(g); - p[2] = UBYTE_TO_FLOAT(b); - p[3] = UBYTE_TO_FLOAT(a); - p += 4; - } - src += ximage->width; - pRow += 4 * w0; - } - } - break; - case PIPE_FORMAT_U_R5_G6_B5: - { - ushort *src - = (ushort *) (ximage->data + y * ximage->bytes_per_line + x * 2); - for (i = 0; i < h; i++) { - float *p = pRow; - for (j = 0; j < w; j++) { - uint pix = src[j]; - ubyte r = (pix >> 8) | ((pix >> 13) & 0x7); - ubyte g = (pix >> 3) | ((pix >> 9) & 0x3); - ubyte b = ((pix & 0x1f) << 3) | ((pix >> 2) & 0x3); - p[0] = UBYTE_TO_FLOAT(r); - p[1] = UBYTE_TO_FLOAT(g); - p[2] = UBYTE_TO_FLOAT(b); - p[3] = 1.0; - p += 4; - } - src += ximage->width; - pRow += 4 * w0; - } - } - break; - default: - assert(0); - } - - if (!xms->ximage) { - XMesaDestroyImage(ximage); - } -} - - -void -xmesa_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, const float *pixels) -{ - const uint x0 = x, y0 = y, w0 = w; - struct xmesa_surface *xms = xmesa_surface(ps); - XMesaImage *ximage; - uint i, j; - - if (!xms->drawable && !xms->ximage) { - /* not an X surface */ - softpipe_put_tile_rgba(pipe, ps, x, y, w, h, pixels); - return; - } - - CLIP_TILE; - - if (!xms->ximage) { - /* create temp XImage */ - char *data = (char *) malloc(w * h * 4); -#ifdef XFree86Server - ximage = XMesaCreateImage(GET_VISUAL_DEPTH(v), w, h, data); -#else - XVisualInfo *visinfo = xms->xrb->Parent->xm_visual->visinfo; - ximage = XCreateImage(xms->display, - visinfo->visual, - visinfo->depth, - ZPixmap, 0, /* format, offset */ - data, /* data */ - w, h, /* width, height */ - 32, /* bitmap_pad */ - 0); /* bytes_per_line */ -#endif - x = y = 0; - } - else { - ximage = xms->ximage; - } - - /* convert floats to ximage's format */ - switch (ps->format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - { - uint *dst - = (uint *) (ximage->data + y * ximage->bytes_per_line + x * 4); - const float *pRow = pixels; - for (i = 0; i < h; i++) { - const float *p = pRow; - for (j = 0; j < w; j++) { - ubyte r, g, b, a; - UNCLAMPED_FLOAT_TO_UBYTE(r, p[0]); - UNCLAMPED_FLOAT_TO_UBYTE(g, p[1]); - UNCLAMPED_FLOAT_TO_UBYTE(b, p[2]); - UNCLAMPED_FLOAT_TO_UBYTE(a, p[3]); - dst[j] = PACK_8A8R8G8B(r, g, b, a); - p += 4; - } - dst += ximage->width; - pRow += 4 * w0; - } - } - break; - case PIPE_FORMAT_U_R5_G6_B5: - { - ushort *dst = - (ushort *) (ximage->data + y * ximage->bytes_per_line + x * 2); - const float *pRow = pixels; - for (i = 0; i < h; i++) { - const float *p = pRow; - for (j = 0; j < w; j++) { - ubyte r, g, b; - UNCLAMPED_FLOAT_TO_UBYTE(r, p[0]); - UNCLAMPED_FLOAT_TO_UBYTE(g, p[1]); - UNCLAMPED_FLOAT_TO_UBYTE(b, p[2]); - dst[j] = PACK_5R6G5B(r, g, b); - p += 4; - } - dst += ximage->width; - pRow += 4 * w0; - } - } - break; - - default: - assert(0); - } - - if (!xms->ximage) { - /* send XImage data to pixmap */ - XPutImage(xms->display, xms->drawable, xms->gc, - ximage, 0, 0, x0, y0, w, h); - /* clean-up */ - free(ximage->data); - ximage->data = NULL; - XMesaDestroyImage(ximage); - } -} - - -static void -clear_pixmap_surface(struct pipe_context *pipe, struct pipe_surface *ps, - uint value) -{ - struct xmesa_surface *xms = xmesa_surface(ps); - assert(xms); - assert(xms->display); - assert(xms->drawable); - assert(xms->gc); - XMesaSetForeground( xms->display, xms->gc, value ); - XMesaFillRectangle( xms->display, xms->drawable, xms->gc, - 0, 0, ps->width, ps->height); -} - -static void -clear_nbit_ximage_surface(struct pipe_context *pipe, struct pipe_surface *ps, - uint value) -{ - struct xmesa_surface *xms = xmesa_surface(ps); - int width = xms->surface.width; - int height = xms->surface.height; - int i, j; - for (j = 0; j < height; j++) { - for (i = 0; i < width; i++) { - XMesaPutPixel(xms->ximage, i, j, value); - } - } -} - -static void -clear_8bit_ximage_surface(struct pipe_context *pipe, struct pipe_surface *ps, - uint value) -{ - struct xmesa_surface *xms = xmesa_surface(ps); - memset(xms->ximage->data, - value, - xms->ximage->bytes_per_line * xms->ximage->height); -} - -static void -clear_16bit_ximage_surface(struct pipe_context *pipe, struct pipe_surface *ps, - uint value) -{ - struct xmesa_surface *xms = xmesa_surface(ps); - const int n = xms->ximage->width * xms->ximage->height; - ushort *dst = (ushort *) xms->ximage->data; - int i; - for (i = 0; i < n; i++) { - dst[i] = value; - } -} - - -/* Optimized code provided by Nozomi Ytow */ -static void -clear_24bit_ximage_surface(struct pipe_context *pipe, struct pipe_surface *ps, - uint value) -{ - struct xmesa_surface *xms = xmesa_surface(ps); - const ubyte r = (value ) & 0xff; - const ubyte g = (value >> 8) & 0xff; - const ubyte b = (value >> 16) & 0xff; - - if (r == g && g == b) { - /* same value for all three components (gray) */ - memset(xms->ximage->data, r, - xms->ximage->bytes_per_line * xms->ximage->height); - } - else { - /* non-gray clear color */ - const int n = xms->ximage->width * xms->ximage->height; - int i; - bgr_t *ptr3 = (bgr_t *) xms->ximage->data; - for (i = 0; i < n; i++) { - ptr3->r = r; - ptr3->g = g; - ptr3->b = b; - ptr3++; - } - } -} - -static void -clear_32bit_ximage_surface(struct pipe_context *pipe, struct pipe_surface *ps, - uint value) -{ - struct xmesa_surface *xms = xmesa_surface(ps); - - if (value == 0) { - /* common case */ - memset(xms->ximage->data, value, - xms->ximage->bytes_per_line * xms->ximage->height); - } - else { - const int n = xms->ximage->width * xms->ximage->height; - uint *dst = (uint *) xms->ximage->data; - int i; - for (i = 0; i < n; i++) - dst[i] = value; - } -} - - - - -/** - * Called to create a pipe_surface for each X renderbuffer. - * Note: this is being used instead of pipe->surface_alloc() since we - * have special/unique quad read/write functions for X. - */ -struct pipe_surface * -xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint pipeFormat) -{ - struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); - - assert(pipeFormat); - - xms->surface.format = pipeFormat; - xms->surface.refcount = 1; - xms->surface.winsys = winsys; - - /* Note, the region we allocate doesn't actually have any storage - * since we're drawing into an XImage or Pixmap. - * The region's size will get set in the xmesa_alloc_front/back_storage() - * functions. - */ - xms->surface.region = winsys->region_alloc(winsys, 1, 1, 1, 0x0); - - return &xms->surface; -} - - -/** - * Called via pipe->surface_alloc() to create new surfaces (textures, - * renderbuffers, etc. - */ -struct pipe_surface * -xmesa_surface_alloc(struct pipe_context *pipe, GLuint pipeFormat) -{ - struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); - - assert(pipe); - assert(pipeFormat); - - xms->surface.format = pipeFormat; - xms->surface.refcount = 1; - xms->surface.winsys = pipe->winsys; - - return &xms->surface; -} - - -/** - * Called via pipe->clear() to clear entire surface to a certain value. - * If the surface is not an X pixmap or XImage, pass the call to - * softpipe_clear(). - */ -void -xmesa_clear(struct pipe_context *pipe, struct pipe_surface *ps, uint value) -{ - struct xmesa_surface *xms = xmesa_surface(ps); - - /* XXX actually, we should just discard any cached tiles from this - * surface since we don't want to accidentally re-use them after clearing. - */ - pipe->flush(pipe, 0); - - { - struct softpipe_context *sp = softpipe_context(pipe); - if (ps == sp_tile_cache_get_surface(sp->cbuf_cache[0])) { - float clear[4]; - clear[0] = 0.2; /* XXX hack */ - clear[1] = 0.2; - clear[2] = 0.2; - clear[3] = 0.2; - sp_tile_cache_clear(sp->cbuf_cache[0], clear); - } - } - -#if 1 - (void) clear_8bit_ximage_surface; - (void) clear_24bit_ximage_surface; -#endif - - if (xms->ximage) { - /* back color buffer */ - switch (xms->surface.format) { - case PIPE_FORMAT_U_R5_G6_B5: - clear_16bit_ximage_surface(pipe, ps, value); - break; - case PIPE_FORMAT_U_A8_R8_G8_B8: - clear_32bit_ximage_surface(pipe, ps, value); - break; - default: - clear_nbit_ximage_surface(pipe, ps, value); - break; - } - } - else if (xms->drawable) { - /* front color buffer */ - clear_pixmap_surface(pipe, ps, value); - } - else { - /* other kind of buffer */ - softpipe_clear(pipe, ps, value); - } -} - - -/** XXX unfinished sketch... */ -struct pipe_surface * -xmesa_create_front_surface(XMesaVisual vis, Window win) -{ - struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); - if (!xms) { - return NULL; - } - - xms->display = vis->display; - xms->drawable = win; - - xms->surface.format = PIPE_FORMAT_U_A8_R8_G8_B8; - xms->surface.refcount = 1; -#if 0 - xms->surface.region = pipe->winsys->region_alloc(pipe->winsys, - 1, 0, 0, 0x0); -#endif - return &xms->surface; -} - diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index b842cf766e3..976884ad520 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -38,6 +38,8 @@ #include "main/macros.h" #include "pipe/p_winsys.h" +#include "pipe/p_format.h" +#include "pipe/p_context.h" #include "pipe/softpipe/sp_winsys.h" @@ -54,17 +56,52 @@ struct xm_buffer }; +struct xmesa_surface +{ + struct pipe_surface surface; + /* no extra fields for now */ +}; + + +/** + * Derived from softpipe_winsys. + * We just need one extra field which indicates the pixel format to use for + * drawing surfaces so that we're compatible with the XVisual/window format. + */ +struct xmesa_softpipe_winsys +{ + struct softpipe_winsys spws; + uint pixelformat; +}; + + + +/** Cast wrapper */ +static INLINE struct xmesa_surface * +xmesa_surface(struct pipe_surface *ps) +{ + assert(0); + return (struct xmesa_surface *) ps; +} -/* Turn the softpipe opaque buffer pointer into a dri_bufmgr opaque +/** cast wrapper */ +static INLINE struct xmesa_softpipe_winsys * +xmesa_softpipe_winsys(struct softpipe_winsys *spws) +{ + return (struct xmesa_softpipe_winsys *) spws; +} + +/** + * Turn the softpipe opaque buffer pointer into a dri_bufmgr opaque * buffer pointer... */ -static inline struct xm_buffer * +static INLINE struct xm_buffer * xm_bo( struct pipe_buffer_handle *bo ) { return (struct xm_buffer *) bo; } -static inline struct pipe_buffer_handle * +static INLINE struct pipe_buffer_handle * pipe_bo( struct xm_buffer *bo ) { return (struct pipe_buffer_handle *) bo; @@ -156,6 +193,33 @@ xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, memcpy(data, b + offset, size); } + +/** + * Display/copy the image in the surface into the X window specified + * by the XMesaBuffer. + */ +void +xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf) +{ + XImage *ximage = b->tempImage; + struct xm_buffer *xm_buf = xm_bo(surf->buffer); + + /* check that the XImage has been previously initialized */ + assert(ximage->format); + assert(ximage->bitmap_unit); + + /* update XImage's fields */ + ximage->width = surf->width; + ximage->height = surf->height; + ximage->bytes_per_line = surf->pitch * (ximage->bits_per_pixel / 8); + ximage->data = xm_buf->data; + + /* display image in Window */ + XPutImage(b->xm_visual->display, b->drawable, b->gc, + ximage, 0, 0, 0, 0, surf->width, surf->height); +} + + static void xm_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf, @@ -166,9 +230,13 @@ xm_flush_frontbuffer(struct pipe_winsys *pws, * If we instead did front buffer rendering to a temporary XImage, * this would be the place to copy the Ximage to the on-screen Window. */ + XMesaContext xmctx = (XMesaContext) context_private; + + xmesa_display_surface(xmctx->xm_buffer, surf); } + static void xm_printf(struct pipe_winsys *pws, const char *fmtString, ...) { @@ -178,6 +246,7 @@ xm_printf(struct pipe_winsys *pws, const char *fmtString, ...) va_end( args ); } + static const char * xm_get_name(struct pipe_winsys *pws) { @@ -186,7 +255,7 @@ xm_get_name(struct pipe_winsys *pws) static struct pipe_buffer_handle * -xm_buffer_create(struct pipe_winsys *pws, unsigned alignment) +xm_buffer_create(struct pipe_winsys *pws, unsigned flags) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); buffer->refcount = 1; @@ -219,50 +288,11 @@ round_up(unsigned n, unsigned multiple) return (n + multiple - 1) & ~(multiple - 1); } - -static struct pipe_region * -xm_region_alloc(struct pipe_winsys *winsys, - unsigned cpp, unsigned width, unsigned height, unsigned flags) -{ - struct pipe_region *region = CALLOC_STRUCT(pipe_region); - const unsigned alignment = 64; - - region->cpp = cpp; - region->pitch = round_up(width, alignment / cpp); - region->height = height; - region->refcount = 1; - - assert(region->pitch > 0); - - region->buffer = winsys->buffer_create( winsys, alignment ) -; - - /* NULL data --> just allocate the space */ - winsys->buffer_data( winsys, - region->buffer, - region->pitch * cpp * height, - NULL, - PIPE_BUFFER_USAGE_PIXEL ); - return region; -} - - -static void -xm_region_release(struct pipe_winsys *winsys, struct pipe_region **region) +static unsigned +xm_surface_pitch(struct pipe_winsys *winsys, unsigned cpp, unsigned width, + unsigned flags) { - if (!*region) - return; - - assert((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - - winsys->buffer_reference( winsys, &((*region)->buffer), NULL ); - free(*region); - } - *region = NULL; + return round_up(width, 64 / cpp); } @@ -271,7 +301,7 @@ xm_region_release(struct pipe_winsys *winsys, struct pipe_region **region) * renderbuffers, etc. */ static struct pipe_surface * -xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) +xm_surface_alloc(struct pipe_winsys *ws, enum pipe_format pipeFormat) { struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); @@ -281,12 +311,7 @@ xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) xms->surface.format = pipeFormat; xms->surface.refcount = 1; xms->surface.winsys = ws; -#if 0 - /* - * This is really just a softpipe surface, not an XImage/Pixmap surface. - */ - softpipe_init_surface_funcs(&xms->surface); -#endif + return &xms->surface; } @@ -298,8 +323,8 @@ xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) struct pipe_surface *surf = *s; surf->refcount--; if (surf->refcount == 0) { - if (surf->region) - winsys->region_release(winsys, &surf->region); + if (surf->buffer) + winsys->buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -312,7 +337,7 @@ xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) * For Xlib, this is a singleton object. * Nothing special for the Xlib driver so no subclassing or anything. */ -struct pipe_winsys * +static struct pipe_winsys * xmesa_get_pipe_winsys(void) { static struct pipe_winsys *ws = NULL; @@ -332,9 +357,7 @@ xmesa_get_pipe_winsys(void) ws->buffer_subdata = xm_buffer_subdata; ws->buffer_get_subdata = xm_buffer_get_subdata; - ws->region_alloc = xm_region_alloc; - ws->region_release = xm_region_release; - + ws->surface_pitch = xm_surface_pitch; ws->surface_alloc = xm_surface_alloc; ws->surface_release = xm_surface_release; @@ -348,59 +371,66 @@ xmesa_get_pipe_winsys(void) /** - * XXX this depends on the depths supported by the screen (8/16/32/etc). - * Maybe when we're about to create a context/drawable we create a new - * softpipe_winsys object that corresponds to the specified screen... + * The winsys being queried will have been created at glXCreateContext + * time, with a pixel format corresponding to the context's visual. * - * Also, this query only really matters for on-screen drawables. - * For textures and FBOs we (softpipe) can support any format.o + * XXX we should pass a flag indicating if the format is going to be + * use for a drawing surface vs. a texture. In the later case, we + * can support any format. */ static boolean -xmesa_is_format_supported(struct softpipe_winsys *sws, uint format) +xmesa_is_format_supported(struct softpipe_winsys *sws, + enum pipe_format format) { - /* Any format supported by softpipe can be listed here. - * This query is not used for allocating window-system color buffers - * (which would depend on the screen depth/bpp). - */ - switch (format) { - case PIPE_FORMAT_U_A8_R8_G8_B8: - case PIPE_FORMAT_S_R16_G16_B16_A16: - case PIPE_FORMAT_S8_Z24: - case PIPE_FORMAT_U_S8: - case PIPE_FORMAT_U_Z16: - case PIPE_FORMAT_U_Z32: + struct xmesa_softpipe_winsys *xmws = xmesa_softpipe_winsys(sws); + + if (format == xmws->pixelformat) { return TRUE; - default: - return FALSE; - }; + } + else { + /* non-color / window surface format */ + switch (format) { + case PIPE_FORMAT_R16G16B16A16_SNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_U_S8: + case PIPE_FORMAT_Z16_UNORM: + case PIPE_FORMAT_Z32_UNORM: + return TRUE; + default: + return FALSE; + } + } } /** * Return pointer to a softpipe_winsys object. - * For Xlib, this is a singleton object. */ static struct softpipe_winsys * -xmesa_get_softpipe_winsys(void) +xmesa_get_softpipe_winsys(uint pixelformat) { - static struct softpipe_winsys *spws = NULL; + struct xmesa_softpipe_winsys *xmws + = CALLOC_STRUCT(xmesa_softpipe_winsys); + if (!xmws) + return NULL; - if (!spws) { - spws = CALLOC_STRUCT(softpipe_winsys); - if (spws) { - spws->is_format_supported = xmesa_is_format_supported; - } - } + xmws->spws.is_format_supported = xmesa_is_format_supported; + xmws->pixelformat = pixelformat; - return spws; + return &xmws->spws; } struct pipe_context * -xmesa_create_context(XMesaContext xmesa) +xmesa_create_pipe_context(XMesaContext xmesa, uint pixelformat) { struct pipe_winsys *pws = xmesa_get_pipe_winsys(); - struct softpipe_winsys *spws = xmesa_get_softpipe_winsys(); + struct softpipe_winsys *spws = xmesa_get_softpipe_winsys(pixelformat); + struct pipe_context *pipe; - return softpipe_create( pws, spws ); + pipe = softpipe_create( pws, spws ); + if (pipe) + pipe->priv = xmesa; + + return pipe; } diff --git a/src/mesa/pipe/xlib/xmesaP.h b/src/mesa/pipe/xlib/xmesaP.h index ba0ccdbcecb..e8c2a597a69 100644 --- a/src/mesa/pipe/xlib/xmesaP.h +++ b/src/mesa/pipe/xlib/xmesaP.h @@ -32,42 +32,15 @@ #ifdef XFree86Server #include "xm_image.h" #endif -#include "state_tracker/st_cb_fbo.h" + #include "state_tracker/st_context.h" #include "state_tracker/st_public.h" -#include "pipe/softpipe/sp_context.h" -#include "pipe/softpipe/sp_surface.h" extern _glthread_Mutex _xmesa_lock; extern XMesaBuffer XMesaBufferList; -/* for PF_8R8G8B24 pixel format */ -typedef struct { - GLubyte b; - GLubyte g; - GLubyte r; -} bgr_t; - - -/** Framebuffer pixel formats */ -enum pixel_format { - PF_Index, /**< Color Index mode */ - PF_Truecolor, /**< TrueColor or DirectColor, any depth */ - PF_Dither_True, /**< TrueColor with dithering */ - PF_8A8R8G8B, /**< 32-bit TrueColor: 8-A, 8-R, 8-G, 8-B bits */ - PF_8A8B8G8R, /**< 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R bits */ - PF_8R8G8B, /**< 32-bit TrueColor: 8-R, 8-G, 8-B bits */ - PF_8R8G8B24, /**< 24-bit TrueColor: 8-R, 8-G, 8-B bits */ - PF_5R6G5B, /**< 16-bit TrueColor: 5-R, 6-G, 5-B bits */ - PF_Dither, /**< Color-mapped RGB with dither */ - PF_Lookup, /**< Color-mapped RGB without dither */ - PF_1Bit, /**< monochrome dithering of RGB */ - PF_Grayscale, /**< Grayscale or StaticGray */ - PF_Dither_5R6G5B /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */ -}; - /** * Visual inforation, derived from GLvisual. @@ -86,47 +59,17 @@ struct xmesa_visual { GLint BitsPerPixel; /* True bits per pixel for XImages */ GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */ - - enum pixel_format dithered_pf; /* Pixel format when dithering */ - enum pixel_format undithered_pf;/* Pixel format when not dithering */ - - GLfloat RedGamma; /* Gamma values, 1.0 is default */ - GLfloat GreenGamma; - GLfloat BlueGamma; - - /* For PF_TRUECOLOR */ - GLint rshift, gshift, bshift;/* Pixel color component shifts */ - GLubyte Kernel[16]; /* Dither kernel */ - unsigned long RtoPixel[512]; /* RGB to pixel conversion */ - unsigned long GtoPixel[512]; - unsigned long BtoPixel[512]; - GLubyte PixelToR[256]; /* Pixel to RGB conversion */ - GLubyte PixelToG[256]; - GLubyte PixelToB[256]; - - /* For PF_1BIT */ - int bitFlip; }; /** - * Context info, derived from GLcontext. + * Context info, derived from st_context. * Basically corresponds to a GLXContext. */ struct xmesa_context { struct st_context *st; - - XMesaVisual xm_visual; /* Describes the buffers */ - XMesaBuffer xm_buffer; /* current span/point/line/triangle buffer */ - - XMesaDisplay *display; /* == xm_visual->display */ - GLboolean swapbytes; /* Host byte order != display byte order? */ - GLboolean direct; /* Direct rendering context? */ - - enum pixel_format pixelformat; - - GLubyte clearcolor[4]; /* current clearing color */ - unsigned long clearpixel; /* current clearing pixel value */ + XMesaVisual xm_visual; /** pixel format info */ + XMesaBuffer xm_buffer; /** current drawbuffer */ }; @@ -141,46 +84,6 @@ typedef enum { } BufferType; -/** Values for db_mode: */ -/*@{*/ -#define BACK_PIXMAP 1 -#define BACK_XIMAGE 2 -/*@}*/ - - -/** - * An xmesa_renderbuffer represents the back or front color buffer. - * For the front color buffer: - * is the X window - * For the back color buffer: - * Either or will be used, never both. - * In any case, always equals . - * For stand-alone Mesa, we could merge and into one - * field. We don't do that for the server-side GLcore module because - * pixmaps and drawables are different and we'd need a bunch of casts. - */ -struct xmesa_renderbuffer -{ - struct st_renderbuffer St; /**< Base class (XXX temporary?) */ - - XMesaBuffer Parent; /**< The XMesaBuffer this renderbuffer belongs to */ - XMesaDrawable drawable; /* Usually the X window ID */ - XMesaPixmap pixmap; /* Back color buffer */ - XMesaImage *ximage; /* The back buffer, if not using a Pixmap */ - - GLubyte *origin1; /* used for PIXEL_ADDR1 macro */ - GLint width1; - GLushort *origin2; /* used for PIXEL_ADDR2 macro */ - GLint width2; - GLubyte *origin3; /* used for PIXEL_ADDR3 macro */ - GLint width3; - GLuint *origin4; /* used for PIXEL_ADDR4 macro */ - GLint width4; - - GLint bottom; /* used for FLIP macro, equals height - 1 */ -}; - - /** * Framebuffer information, derived from. * Basically corresponds to a GLXDrawable. @@ -190,22 +93,13 @@ struct xmesa_buffer { GLboolean wasCurrent; /* was ever the current buffer? */ XMesaVisual xm_visual; /* the X/Mesa visual */ - - XMesaDisplay *display; - BufferType type; /* window, pixmap, pbuffer or glxwindow */ - - struct xmesa_renderbuffer *frontxrb; /* front color renderbuffer */ - struct xmesa_renderbuffer *backxrb; /* back color renderbuffer */ - + XMesaDrawable drawable; /* Usually the X window ID */ XMesaColormap cmap; /* the X colormap */ + BufferType type; /* window, pixmap, pbuffer or glxwindow */ + XMesaImage *tempImage; unsigned long selectedEvents;/* for pbuffers only */ - GLint db_mode; /* 0 = single buffered */ - /* BACK_PIXMAP = use Pixmap for back buffer */ - /* BACK_XIMAGE = use XImage for back buffer */ - GLboolean swAlpha; - GLuint shm; /* X Shared Memory extension status: */ /* 0 = not available */ /* 1 = XImage support available */ @@ -214,33 +108,7 @@ struct xmesa_buffer { XShmSegmentInfo shminfo; #endif - XMesaImage *rowimage; /* Used for optimized span writing */ - XMesaPixmap stipple_pixmap; /* For polygon stippling */ - XMesaGC stipple_gc; /* For polygon stippling */ - XMesaGC gc; /* scratch GC for span, line, tri drawing */ - XMesaGC cleargc; /* GC for clearing the color buffer */ - XMesaGC swapgc; /* GC for swapping the color buffers */ - - /* The following are here instead of in the XMesaVisual - * because they depend on the window's colormap. - */ - - /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */ - unsigned long color_table[576]; /* RGB -> pixel value */ - - /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */ - GLubyte pixel_to_r[65536]; /* pixel value -> red */ - GLubyte pixel_to_g[65536]; /* pixel value -> green */ - GLubyte pixel_to_b[65536]; /* pixel value -> blue */ - - /* Used to do XAllocColor/XFreeColors accounting: */ - int num_alloced; -#if defined(XFree86Server) - Pixel alloced_colors[256]; -#else - unsigned long alloced_colors[256]; -#endif /* GLX_EXT_texture_from_pixmap */ GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */ @@ -251,321 +119,38 @@ struct xmesa_buffer { }; -/** - * If pixelformat==PF_TRUECOLOR: - */ -#define PACK_TRUECOLOR( PIXEL, R, G, B ) \ - PIXEL = xmesa->xm_visual->RtoPixel[R] \ - | xmesa->xm_visual->GtoPixel[G] \ - | xmesa->xm_visual->BtoPixel[B]; \ - - -/** - * If pixelformat==PF_TRUEDITHER: - */ -#define PACK_TRUEDITHER( PIXEL, X, Y, R, G, B ) \ -{ \ - int d = xmesa->xm_visual->Kernel[((X)&3) | (((Y)&3)<<2)]; \ - PIXEL = xmesa->xm_visual->RtoPixel[(R)+d] \ - | xmesa->xm_visual->GtoPixel[(G)+d] \ - | xmesa->xm_visual->BtoPixel[(B)+d]; \ -} - - - -/** - * If pixelformat==PF_8A8B8G8R: - */ -#define PACK_8A8B8G8R( R, G, B, A ) \ - ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) ) - - -/** - * Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable - * shortcut. - */ -#define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) ) - - - -/** - * If pixelformat==PF_8R8G8B: - */ -#define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) ) - -/** - * If pixelformat==PF_5R6G5B: - */ -#define PACK_5R6G5B( R, G, B) ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) ) - - -/** - * If pixelformat==PF_8A8R8G8B: - */ -#define PACK_8A8R8G8B( R, G, B, A ) \ - ( ((A) << 24) | ((R) << 16) | ((G) << 8) | (B) ) - - - -/** - * If pixelformat==PF_DITHER: - * - * Improved 8-bit RGB dithering code contributed by Bob Mercier - * (mercier@hollywood.cinenet.net). Thanks Bob! - */ -#ifdef DITHER666 -# define DITH_R 6 -# define DITH_G 6 -# define DITH_B 6 -# define DITH_MIX(r,g,b) (((r) * DITH_G + (g)) * DITH_B + (b)) -#else -# define DITH_R 5 -# define DITH_G 9 -# define DITH_B 5 -# define DITH_MIX(r,g,b) (((g) << 6) | ((b) << 3) | (r)) -#endif -#define DITH_DX 4 -#define DITH_DY 4 -#define DITH_N (DITH_DX * DITH_DY) - -#define _dither(C, c, d) (((unsigned)((DITH_N * (C - 1) + 1) * c + d)) >> 12) - -#define MAXC 256 -extern const int xmesa_kernel8[DITH_DY * DITH_DX]; - -/* Dither for random X,Y */ -#define DITHER_SETUP \ - int __d; \ - unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table; - -#define DITHER( X, Y, R, G, B ) \ - (__d = xmesa_kernel8[(((Y)&3)<<2) | ((X)&3)], \ - ctable[DITH_MIX(_dither(DITH_R, (R), __d), \ - _dither(DITH_G, (G), __d), \ - _dither(DITH_B, (B), __d))]) - -/* Dither for random X, fixed Y */ -#define XDITHER_SETUP(Y) \ - int __d; \ - unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table; \ - const int *kernel = &xmesa_kernel8[ ((Y)&3) << 2 ]; - -#define XDITHER( X, R, G, B ) \ - (__d = kernel[(X)&3], \ - ctable[DITH_MIX(_dither(DITH_R, (R), __d), \ - _dither(DITH_G, (G), __d), \ - _dither(DITH_B, (B), __d))]) - - - -/* - * Dithering for flat-shaded triangles. Precompute all 16 possible - * pixel values given the triangle's RGB color. Contributed by Martin Shenk. - */ -#define FLAT_DITHER_SETUP( R, G, B ) \ - GLushort ditherValues[16]; \ - { \ - unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table; \ - int msdr = (DITH_N*((DITH_R)-1)+1) * (R); \ - int msdg = (DITH_N*((DITH_G)-1)+1) * (G); \ - int msdb = (DITH_N*((DITH_B)-1)+1) * (B); \ - int i; \ - for (i=0;i<16;i++) { \ - int k = xmesa_kernel8[i]; \ - int j = DITH_MIX( (msdr+k)>>12, (msdg+k)>>12, (msdb+k)>>12 );\ - ditherValues[i] = (GLushort) ctable[j]; \ - } \ - } - -#define FLAT_DITHER_ROW_SETUP(Y) \ - GLushort *ditherRow = ditherValues + ( ((Y)&3) << 2); - -#define FLAT_DITHER(X) ditherRow[(X)&3] - - - -/** - * If pixelformat==PF_LOOKUP: - */ -#define _dither_lookup(C, c) (((unsigned)((DITH_N * (C - 1) + 1) * c)) >> 12) - -#define LOOKUP_SETUP \ - unsigned long *ctable = XMESA_BUFFER(ctx->DrawBuffer)->color_table - -#define LOOKUP( R, G, B ) \ - ctable[DITH_MIX(_dither_lookup(DITH_R, (R)), \ - _dither_lookup(DITH_G, (G)), \ - _dither_lookup(DITH_B, (B)))] - - - -/** - * If pixelformat==PF_1BIT: - */ -extern const int xmesa_kernel1[16]; - -#define SETUP_1BIT int bitFlip = xmesa->xm_visual->bitFlip -#define DITHER_1BIT( X, Y, R, G, B ) \ - (( ((int)(R)+(int)(G)+(int)(B)) > xmesa_kernel1[(((Y)&3) << 2) | ((X)&3)] ) ^ bitFlip) - - - -/** - * If pixelformat==PF_GRAYSCALE: - */ -#define GRAY_RGB( R, G, B ) XMESA_BUFFER(ctx->DrawBuffer)->color_table[((R) + (G) + (B))/3] - - - -/** - * Converts a GL window Y coord to an X window Y coord: - */ -#define YFLIP(XRB, Y) ((XRB)->bottom - (Y)) - - -/** - * Return the address of a 1, 2 or 4-byte pixel in the buffer's XImage: - * X==0 is left, Y==0 is bottom. - */ -#define PIXEL_ADDR1(XRB, X, Y) \ - ( (XRB)->origin1 - (Y) * (XRB)->width1 + (X) ) - -#define PIXEL_ADDR2(XRB, X, Y) \ - ( (XRB)->origin2 - (Y) * (XRB)->width2 + (X) ) - -#define PIXEL_ADDR3(XRB, X, Y) \ - ( (bgr_t *) ( (XRB)->origin3 - (Y) * (XRB)->width3 + 3 * (X) )) - -#define PIXEL_ADDR4(XRB, X, Y) \ - ( (XRB)->origin4 - (Y) * (XRB)->width4 + (X) ) - - - -/* - * External functions: - */ - -extern struct xmesa_renderbuffer * -xmesa_create_renderbuffer(struct pipe_winsys *winsys, - GLuint name, const GLvisual *visual, - GLboolean backBuffer); - -extern void -xmesa_delete_framebuffer(struct gl_framebuffer *fb); - -extern XMesaBuffer -xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis); - -extern unsigned long -xmesa_color_to_pixel( XMesaContext xmesa, - GLubyte r, GLubyte g, GLubyte b, GLubyte a, - GLuint pixelFormat ); - -extern void -xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b, - GLuint *width, GLuint *height); - -extern void -xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer); - - -extern void -xmesa_destroy_buffers_on_display(XMesaDisplay *dpy); - - -/** - * Using a function instead of an ordinary cast is safer. - */ -static INLINE struct xmesa_renderbuffer * -xmesa_renderbuffer(struct gl_renderbuffer *rb) -{ - return (struct xmesa_renderbuffer *) rb; -} - - -/** - * Return pointer to XMesaContext corresponding to a Mesa GLcontext. - * Since we're using structure containment, it's just a cast!. - * XXX should use inlined function for better type safety. - */ +/** cast wrapper */ static INLINE XMesaContext -XMESA_CONTEXT(GLcontext *ctx) +xmesa_context(GLcontext *ctx) { return (XMesaContext) ctx->DriverCtx; } -/** - * Return pointer to XMesaBuffer corresponding to a Mesa GLframebuffer. - * Since we're using structure containment, it's just a cast!. - * XXX should use inlined function for better type safety. - */ +/** cast wrapper */ static INLINE XMesaBuffer -XMESA_BUFFER(GLframebuffer *fb) +xmesa_buffer(GLframebuffer *fb) { struct st_framebuffer *stfb = (struct st_framebuffer *) fb; return (XMesaBuffer) st_framebuffer_private(stfb); } - -struct pipe_context; - -struct xmesa_surface -{ - struct pipe_surface surface; - struct xmesa_renderbuffer *xrb; - XMesaDisplay *display; - BufferType type; - XMesaDrawable drawable; - XMesaImage *ximage; - XMesaGC gc; -}; - - -/** Cast wrapper */ -static INLINE struct xmesa_surface * -xmesa_surface(struct pipe_surface *ps) -{ - return (struct xmesa_surface *) ps; -} - - extern void -xmesa_clear(struct pipe_context *pipe, struct pipe_surface *ps, uint value); - -extern struct pipe_context * -xmesa_create_context(XMesaContext xm); - -extern struct pipe_surface * -xmesa_surface_alloc(struct pipe_context *pipe, GLuint format); - -extern struct pipe_surface * -xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint format); - -extern struct pipe_winsys * -xmesa_get_pipe_winsys(void); - -extern void -xmesa_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, void *p, int dst_stride); +xmesa_delete_framebuffer(struct gl_framebuffer *fb); -extern void -xmesa_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, const void *p, int src_stride); +extern XMesaBuffer +xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis); extern void -xmesa_get_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, float *p); +xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer); extern void -xmesa_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, const float *p); - +xmesa_destroy_buffers_on_display(XMesaDisplay *dpy); -extern struct pipe_surface * -xmesa_create_front_surface(XMesaVisual vis, Window win); +extern struct pipe_context * +xmesa_create_pipe_context(XMesaContext xm, uint pixelformat); static INLINE GLuint xmesa_buffer_width(XMesaBuffer b) @@ -579,5 +164,7 @@ xmesa_buffer_height(XMesaBuffer b) return b->stfb->Base.Height; } +extern void +xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf); #endif diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index bc5ecdaa156..4470a87af0a 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -52,7 +52,7 @@ /** * Allocate a new gl_shader_program object, initialize it. */ -struct gl_shader_program * +static struct gl_shader_program * _mesa_new_shader_program(GLcontext *ctx, GLuint name) { struct gl_shader_program *shProg; @@ -371,7 +371,7 @@ copy_string(GLchar *dst, GLsizei maxLength, GLsizei *length, const GLchar *src) /** * Called via ctx->Driver.AttachShader() */ -void +static void _mesa_attach_shader(GLcontext *ctx, GLuint program, GLuint shader) { struct gl_shader_program *shProg @@ -410,7 +410,38 @@ _mesa_attach_shader(GLcontext *ctx, GLuint program, GLuint shader) } -void +static GLint +_mesa_get_attrib_location(GLcontext *ctx, GLuint program, + const GLchar *name) +{ + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); + + if (!shProg) { + _mesa_error(ctx, GL_INVALID_VALUE, "glGetAttribLocation"); + return -1; + } + + if (!shProg->LinkStatus) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glGetAttribLocation(program not linked)"); + return -1; + } + + if (!name) + return -1; + + if (shProg->Attributes) { + GLint i = _mesa_lookup_parameter_index(shProg->Attributes, -1, name); + if (i >= 0) { + return shProg->Attributes->Parameters[i].StateIndexes[0]; + } + } + return -1; +} + + +static void _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index, const GLchar *name) { @@ -456,7 +487,7 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index, } -GLuint +static GLuint _mesa_create_shader(GLcontext *ctx, GLenum type) { struct gl_shader *sh; @@ -480,7 +511,7 @@ _mesa_create_shader(GLcontext *ctx, GLenum type) } -GLuint +static GLuint _mesa_create_program(GLcontext *ctx) { GLuint name; @@ -501,7 +532,7 @@ _mesa_create_program(GLcontext *ctx) * Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's * DeleteProgramARB. */ -void +static void _mesa_delete_program2(GLcontext *ctx, GLuint name) { /* @@ -527,7 +558,7 @@ _mesa_delete_program2(GLcontext *ctx, GLuint name) } -void +static void _mesa_delete_shader(GLcontext *ctx, GLuint shader) { struct gl_shader *sh = _mesa_lookup_shader(ctx, shader); @@ -542,7 +573,7 @@ _mesa_delete_shader(GLcontext *ctx, GLuint shader) } -void +static void _mesa_detach_shader(GLcontext *ctx, GLuint program, GLuint shader) { struct gl_shader_program *shProg @@ -602,7 +633,7 @@ _mesa_detach_shader(GLcontext *ctx, GLuint program, GLuint shader) } -void +static void _mesa_get_active_attrib(GLcontext *ctx, GLuint program, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *nameOut) @@ -637,7 +668,7 @@ _mesa_get_active_attrib(GLcontext *ctx, GLuint program, GLuint index, /** * Called via ctx->Driver.GetActiveUniform(). */ -void +static void _mesa_get_active_uniform(GLcontext *ctx, GLuint program, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLchar *nameOut) @@ -681,7 +712,7 @@ _mesa_get_active_uniform(GLcontext *ctx, GLuint program, GLuint index, /** * Called via ctx->Driver.GetAttachedShaders(). */ -void +static void _mesa_get_attached_shaders(GLcontext *ctx, GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj) { @@ -701,38 +732,7 @@ _mesa_get_attached_shaders(GLcontext *ctx, GLuint program, GLsizei maxCount, } -GLint -_mesa_get_attrib_location(GLcontext *ctx, GLuint program, - const GLchar *name) -{ - struct gl_shader_program *shProg - = _mesa_lookup_shader_program(ctx, program); - - if (!shProg) { - _mesa_error(ctx, GL_INVALID_VALUE, "glGetAttribLocation"); - return -1; - } - - if (!shProg->LinkStatus) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glGetAttribLocation(program not linked)"); - return -1; - } - - if (!name) - return -1; - - if (shProg->Attributes) { - GLint i = _mesa_lookup_parameter_index(shProg->Attributes, -1, name); - if (i >= 0) { - return shProg->Attributes->Parameters[i].StateIndexes[0]; - } - } - return -1; -} - - -GLuint +static GLuint _mesa_get_handle(GLcontext *ctx, GLenum pname) { #if 0 @@ -756,7 +756,7 @@ _mesa_get_handle(GLcontext *ctx, GLenum pname) } -void +static void _mesa_get_programiv(GLcontext *ctx, GLuint program, GLenum pname, GLint *params) { @@ -810,7 +810,7 @@ _mesa_get_programiv(GLcontext *ctx, GLuint program, } -void +static void _mesa_get_shaderiv(GLcontext *ctx, GLuint name, GLenum pname, GLint *params) { struct gl_shader *shader = _mesa_lookup_shader(ctx, name); @@ -843,7 +843,7 @@ _mesa_get_shaderiv(GLcontext *ctx, GLuint name, GLenum pname, GLint *params) } -void +static void _mesa_get_program_info_log(GLcontext *ctx, GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog) { @@ -857,7 +857,7 @@ _mesa_get_program_info_log(GLcontext *ctx, GLuint program, GLsizei bufSize, } -void +static void _mesa_get_shader_info_log(GLcontext *ctx, GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) { @@ -873,7 +873,7 @@ _mesa_get_shader_info_log(GLcontext *ctx, GLuint shader, GLsizei bufSize, /** * Called via ctx->Driver.GetShaderSource(). */ -void +static void _mesa_get_shader_source(GLcontext *ctx, GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *sourceOut) { @@ -889,7 +889,7 @@ _mesa_get_shader_source(GLcontext *ctx, GLuint shader, GLsizei maxLength, /** * Called via ctx->Driver.GetUniformfv(). */ -void +static void _mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location, GLfloat *params) { @@ -915,7 +915,7 @@ _mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location, /** * Called via ctx->Driver.GetUniformLocation(). */ -GLint +static GLint _mesa_get_uniform_location(GLcontext *ctx, GLuint program, const GLchar *name) { struct gl_shader_program *shProg @@ -940,7 +940,7 @@ _mesa_get_uniform_location(GLcontext *ctx, GLuint program, const GLchar *name) } -GLboolean +static GLboolean _mesa_is_program(GLcontext *ctx, GLuint name) { struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, name); @@ -948,7 +948,7 @@ _mesa_is_program(GLcontext *ctx, GLuint name) } -GLboolean +static GLboolean _mesa_is_shader(GLcontext *ctx, GLuint name) { struct gl_shader *shader = _mesa_lookup_shader(ctx, name); @@ -960,7 +960,7 @@ _mesa_is_shader(GLcontext *ctx, GLuint name) /** * Called via ctx->Driver.ShaderSource() */ -void +static void _mesa_shader_source(GLcontext *ctx, GLuint shader, const GLchar *source) { struct gl_shader *sh = _mesa_lookup_shader(ctx, shader); @@ -981,7 +981,7 @@ _mesa_shader_source(GLcontext *ctx, GLuint shader, const GLchar *source) /** * Called via ctx->Driver.CompileShader() */ -void +static void _mesa_compile_shader(GLcontext *ctx, GLuint shaderObj) { struct gl_shader *sh = _mesa_lookup_shader(ctx, shaderObj); @@ -998,7 +998,7 @@ _mesa_compile_shader(GLcontext *ctx, GLuint shaderObj) /** * Called via ctx->Driver.LinkProgram() */ -void +static void _mesa_link_program(GLcontext *ctx, GLuint program) { struct gl_shader_program *shProg; @@ -1070,7 +1070,7 @@ update_textures_used(struct gl_program *prog) /** * Called via ctx->Driver.Uniform(). */ -void +static void _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count, const GLvoid *values, GLenum type) { @@ -1182,7 +1182,7 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count, /** * Called by ctx->Driver.UniformMatrix(). */ -void +static void _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows, GLenum matrixType, GLint location, GLsizei count, GLboolean transpose, const GLfloat *values) @@ -1230,7 +1230,7 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows, } -void +static void _mesa_validate_program(GLcontext *ctx, GLuint program) { struct gl_shader_program *shProg; @@ -1256,3 +1256,40 @@ _mesa_validate_program(GLcontext *ctx, GLuint program) image units allowed. */ } + + +/** + * Plug in Mesa's GLSL functions into the device driver function table. + */ +void +_mesa_init_glsl_driver_functions(struct dd_function_table *driver) +{ + driver->AttachShader = _mesa_attach_shader; + driver->BindAttribLocation = _mesa_bind_attrib_location; + driver->CompileShader = _mesa_compile_shader; + driver->CreateProgram = _mesa_create_program; + driver->CreateShader = _mesa_create_shader; + driver->DeleteProgram2 = _mesa_delete_program2; + driver->DeleteShader = _mesa_delete_shader; + driver->DetachShader = _mesa_detach_shader; + driver->GetActiveAttrib = _mesa_get_active_attrib; + driver->GetActiveUniform = _mesa_get_active_uniform; + driver->GetAttachedShaders = _mesa_get_attached_shaders; + driver->GetAttribLocation = _mesa_get_attrib_location; + driver->GetHandle = _mesa_get_handle; + driver->GetProgramiv = _mesa_get_programiv; + driver->GetProgramInfoLog = _mesa_get_program_info_log; + driver->GetShaderiv = _mesa_get_shaderiv; + driver->GetShaderInfoLog = _mesa_get_shader_info_log; + driver->GetShaderSource = _mesa_get_shader_source; + driver->GetUniformfv = _mesa_get_uniformfv; + driver->GetUniformLocation = _mesa_get_uniform_location; + driver->IsProgram = _mesa_is_program; + driver->IsShader = _mesa_is_shader; + driver->LinkProgram = _mesa_link_program; + driver->ShaderSource = _mesa_shader_source; + driver->Uniform = _mesa_uniform; + driver->UniformMatrix = _mesa_uniform_matrix; + driver->UseProgram = _mesa_use_program; + driver->ValidateProgram = _mesa_validate_program; +} diff --git a/src/mesa/shader/shader_api.h b/src/mesa/shader/shader_api.h index 27e5870d705..5521c585b53 100644 --- a/src/mesa/shader/shader_api.h +++ b/src/mesa/shader/shader_api.h @@ -41,9 +41,10 @@ _mesa_init_shader_state(GLcontext * ctx); extern void _mesa_free_shader_state(GLcontext *ctx); +/* extern struct gl_shader_program * _mesa_new_shader_program(GLcontext *ctx, GLuint name); - +*/ extern void _mesa_clear_shader_program_data(GLcontext *ctx, struct gl_shader_program *shProg); @@ -78,108 +79,12 @@ extern struct gl_shader * _mesa_lookup_shader(GLcontext *ctx, GLuint name); -/** - * API/Driver functions - */ - -extern void -_mesa_attach_shader(GLcontext *ctx, GLuint program, GLuint shader); - -extern void -_mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index, - const GLchar *name); - -extern void -_mesa_compile_shader(GLcontext *ctx, GLuint shaderObj); - -extern GLuint -_mesa_create_shader(GLcontext *ctx, GLenum type); - -extern GLuint -_mesa_create_program(GLcontext *ctx); - -extern void -_mesa_delete_program2(GLcontext *ctx, GLuint name); - -extern void -_mesa_delete_shader(GLcontext *ctx, GLuint shader); - -extern void -_mesa_detach_shader(GLcontext *ctx, GLuint program, GLuint shader); - -extern void -_mesa_get_active_attrib(GLcontext *ctx, GLuint program, GLuint index, - GLsizei maxLength, GLsizei *length, GLint *size, - GLenum *type, GLchar *name); - -extern void -_mesa_get_active_uniform(GLcontext *ctx, GLuint program, GLuint index, - GLsizei maxLength, GLsizei *length, GLint *size, - GLenum *type, GLchar *name); - -extern void -_mesa_get_attached_shaders(GLcontext *ctx, GLuint program, GLsizei maxCount, - GLsizei *count, GLuint *obj); - -extern GLint -_mesa_get_attrib_location(GLcontext *ctx, GLuint program, - const GLchar *name); - -extern GLuint -_mesa_get_handle(GLcontext *ctx, GLenum pname); - -extern void -_mesa_get_programiv(GLcontext *ctx, GLuint program, - GLenum pname, GLint *params); - -extern void -_mesa_get_program_info_log(GLcontext *ctx, GLuint program, GLsizei bufSize, - GLsizei *length, GLchar *infoLog); - -extern void -_mesa_get_shaderiv(GLcontext *ctx, GLuint shader, GLenum pname, GLint *params); - -extern void -_mesa_get_shader_info_log(GLcontext *ctx, GLuint shader, GLsizei bufSize, - GLsizei *length, GLchar *infoLog); - -extern void -_mesa_get_shader_source(GLcontext *ctx, GLuint shader, GLsizei maxLength, - GLsizei *length, GLchar *sourceOut); - -extern void -_mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location, - GLfloat *params); - -extern GLint -_mesa_get_uniform_location(GLcontext *ctx, GLuint program, const GLchar *name); - -extern GLboolean -_mesa_is_program(GLcontext *ctx, GLuint name); - -extern GLboolean -_mesa_is_shader(GLcontext *ctx, GLuint name); - -extern void -_mesa_link_program(GLcontext *ctx, GLuint program); - -extern void -_mesa_shader_source(GLcontext *ctx, GLuint shader, const GLchar *source); - -extern void -_mesa_uniform(GLcontext *ctx, GLint location, GLsizei count, - const GLvoid *values, GLenum type); - -void -_mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows, - GLenum matrixType, GLint location, GLsizei count, - GLboolean transpose, const GLfloat *values); - extern void _mesa_use_program(GLcontext *ctx, GLuint program); + extern void -_mesa_validate_program(GLcontext *ctx, GLuint program); +_mesa_init_glsl_driver_functions(struct dd_function_table *driver); #endif /* SHADER_API_H */ diff --git a/src/mesa/sources b/src/mesa/sources index 0b9b5fca3aa..32e1805ecab 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -80,7 +80,7 @@ MATH_SOURCES = \ math/m_vector.c \ math/m_xform.c -SWRAST_SOURCES = \ +__SWRAST_SOURCES = \ swrast/s_aaline.c \ swrast/s_aatriangle.c \ swrast/s_accum.c \ @@ -111,11 +111,11 @@ SWRAST_SOURCES = \ swrast/s_triangle.c \ swrast/s_zoom.c -SWRAST_SETUP_SOURCES = \ +__SWRAST_SETUP_SOURCES = \ swrast_setup/ss_context.c \ swrast_setup/ss_triangle.c -TNL_SOURCES = \ +__TNL_SOURCES = \ tnl/t_context.c \ tnl/t_pipeline.c \ tnl/t_draw.c \ @@ -169,6 +169,7 @@ DRAW_SOURCES = \ pipe/draw/draw_twoside.c \ pipe/draw/draw_unfilled.c \ pipe/draw/draw_validate.c \ + pipe/draw/draw_vbuf.c \ pipe/draw/draw_vertex.c \ pipe/draw/draw_vertex_cache.c \ pipe/draw/draw_vertex_fetch.c \ @@ -177,15 +178,14 @@ DRAW_SOURCES = \ pipe/draw/draw_wide_prims.c TGSIEXEC_SOURCES = \ - pipe/tgsi/exec/tgsi_build.c \ - pipe/tgsi/exec/tgsi_dump.c \ pipe/tgsi/exec/tgsi_exec.c \ - pipe/tgsi/exec/tgsi_parse.c \ - pipe/tgsi/exec/tgsi_sse2.c \ - pipe/tgsi/exec/tgsi_util.c + pipe/tgsi/exec/tgsi_sse2.c -TGSIDECO_SOURCES = \ - pipe/tgsi/deco/deco_caps.c +TGSIUTIL_SOURCES = \ + pipe/tgsi/util/tgsi_build.c \ + pipe/tgsi/util/tgsi_dump.c \ + pipe/tgsi/util/tgsi_parse.c \ + pipe/tgsi/util/tgsi_util.c LLVMTGSI_SOURCES = \ @@ -236,7 +236,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_framebuffer.c \ state_tracker/st_mesa_to_tgsi.c \ state_tracker/st_program.c \ - state_tracker/st_mipmap_tree.c + state_tracker/st_texture.c SHADER_SOURCES = \ shader/arbprogparse.c \ @@ -326,7 +326,7 @@ SPARC_SOURCES = \ SPARC_API = \ sparc/glapi_sparc.S -COMMON_DRIVER_SOURCES = \ +__COMMON_DRIVER_SOURCES = \ drivers/common/driverfuncs.c X11_DRIVER_SOURCES = \ @@ -334,9 +334,7 @@ X11_DRIVER_SOURCES = \ pipe/xlib/fakeglx.c \ pipe/xlib/xfonts.c \ pipe/xlib/xm_api.c \ - pipe/xlib/xm_buffer.c \ - pipe/xlib/xm_winsys.c \ - pipe/xlib/xm_surface.c + pipe/xlib/xm_winsys.c OSMESA_DRIVER_SOURCES = \ drivers/osmesa/osmesa.c @@ -384,7 +382,7 @@ SOLO_SOURCES = \ $(VF_SOURCES) \ $(DRAW_SOURCES) \ $(TGSIEXEC_SOURCES) \ - $(TGSIDECO_SOURCES) \ + $(TGSIUTIL_SOURCES) \ $(STATECACHE_SOURCES) \ $(STATETRACKER_SOURCES) \ $(TNL_SOURCES) \ diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index d4976941f9a..4ec10badad3 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -41,7 +41,7 @@ #include "main/mtypes.h" #include "pipe/p_context.h" -#include "pipe/tgsi/exec/tgsi_core.h" +#include "pipe/p_shader_tokens.h" #include "st_context.h" #include "st_cache.h" diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index f25cfd386a3..c4e5af02d59 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -51,24 +51,24 @@ update_textures(struct st_context *st) for (u = 0; u < st->ctx->Const.MaxTextureImageUnits; u++) { struct gl_texture_object *texObj = st->ctx->Texture.Unit[u]._Current; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; if (texObj) { GLboolean flush, retval; - retval = st_finalize_mipmap_tree(st->ctx, st->pipe, u, &flush); + retval = st_finalize_texture(st->ctx, st->pipe, u, &flush); #if 0 - printf("finalize_mipmap_tree returned %d, flush = %d\n", + printf("finalize_texture returned %d, flush = %d\n", retval, flush); #endif - mt = st_get_texobj_mipmap_tree(texObj); + pt = st_get_texobj_texture(texObj); } else { - mt = NULL; + pt = NULL; } - st->state.texture[u] = mt; - st->pipe->set_texture_state(st->pipe, u, mt); + st->state.texture[u] = pt; + st->pipe->set_texture_state(st->pipe, u, pt); } } diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 7a245b0ed6d..c8d9cba12f3 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -42,6 +42,7 @@ #include "st_format.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" /** @@ -68,7 +69,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) GLfloat *accBuf; GLint i; - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(acc_ps); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); @@ -83,7 +84,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) free(accBuf); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(acc_ps); } @@ -99,7 +100,7 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); @@ -111,7 +112,7 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, free(accBuf); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(acc_ps); } @@ -128,8 +129,8 @@ accum_accum(struct pipe_context *pipe, GLfloat value, colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - colorMap = pipe->region_map(pipe, color_ps->region); - accMap = pipe->region_map(pipe, acc_ps->region); + colorMap = pipe_surface_map(color_ps); + accMap = pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); @@ -143,8 +144,8 @@ accum_accum(struct pipe_context *pipe, GLfloat value, free(colorBuf); free(accBuf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(color_ps); + pipe_surface_unmap(acc_ps); } @@ -159,8 +160,8 @@ accum_load(struct pipe_context *pipe, GLfloat value, buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, color_ps->region); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(color_ps); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf); @@ -172,8 +173,8 @@ accum_load(struct pipe_context *pipe, GLfloat value, free(buf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(color_ps); + pipe_surface_unmap(acc_ps); } @@ -190,8 +191,8 @@ accum_return(GLcontext *ctx, GLfloat value, abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, color_ps->region); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(color_ps); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf); @@ -218,8 +219,8 @@ accum_return(GLcontext *ctx, GLfloat value, if (cbuf) free(cbuf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + 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 219a5afcbdd..b4b2429a2aa 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -55,7 +55,7 @@ static GLuint -color_value(GLuint pipeFormat, const GLfloat color[4]) +color_value(enum pipe_format pipeFormat, const GLfloat color[4]) { GLubyte r, g, b, a; @@ -65,33 +65,36 @@ color_value(GLuint pipeFormat, const GLfloat color[4]) UNCLAMPED_FLOAT_TO_UBYTE(a, color[3]); switch (pipeFormat) { - case PIPE_FORMAT_U_R8_G8_B8_A8: + case PIPE_FORMAT_R8G8B8A8_UNORM: return (r << 24) | (g << 16) | (b << 8) | a; - case PIPE_FORMAT_U_A8_R8_G8_B8: + case PIPE_FORMAT_A8R8G8B8_UNORM: return (a << 24) | (r << 16) | (g << 8) | b; - case PIPE_FORMAT_U_R5_G6_B5: + case PIPE_FORMAT_B8G8R8A8_UNORM: + return (b << 24) | (g << 16) | (r << 8) | a; + case PIPE_FORMAT_R5G6B5_UNORM: return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); default: + assert(0); return 0; } } static uint -depth_value(GLuint pipeFormat, GLfloat value) +depth_value(enum pipe_format pipeFormat, GLfloat value) { switch (pipeFormat) { - case PIPE_FORMAT_U_Z16: + case PIPE_FORMAT_Z16_UNORM: return (uint) (value * 0xffff); - case PIPE_FORMAT_U_Z32: + case PIPE_FORMAT_Z32_UNORM: /* special-case to avoid overflow */ if (value == 1.0) return 0xffffffff; else return (uint) (value * 0xffffffff); - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: return (uint) (value * 0xffffff); - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: return ((uint) (value * 0xffffff)) << 8; default: assert(0); @@ -101,11 +104,11 @@ depth_value(GLuint pipeFormat, GLfloat value) static GLboolean -is_depth_stencil_format(GLuint pipeFormat) +is_depth_stencil_format(enum pipe_format pipeFormat) { switch (pipeFormat) { - case PIPE_FORMAT_S8_Z24: - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: return GL_TRUE; default: return GL_FALSE; @@ -520,10 +523,10 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); switch (strb->surface->format) { - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: clearValue |= ctx->Stencil.Clear << 24; break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: clearValue |= clearValue | ctx->Stencil.Clear; break; default: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index df41d5ce5b2..c0e41dbeec5 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -33,6 +33,7 @@ #include "main/imports.h" #include "main/image.h" #include "main/macros.h" +#include "main/texformat.h" #include "shader/program.h" #include "shader/prog_parameter.h" #include "shader/prog_print.h" @@ -50,6 +51,7 @@ #include "st_draw.h" #include "st_format.h" #include "st_mesa_to_tgsi.h" +#include "st_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" @@ -440,65 +442,22 @@ _mesa_base_format(GLenum format) } - -static struct pipe_mipmap_tree * -alloc_mipmap_tree(struct st_context *st, - GLsizei width, GLsizei height, uint pipeFormat) -{ - const GLbitfield flags = PIPE_SURFACE_FLAG_TEXTURE; - struct pipe_mipmap_tree *mt; - GLuint cpp; - - mt = CALLOC_STRUCT(pipe_mipmap_tree); - if (!mt) - return NULL; - - cpp = st_sizeof_format(pipeFormat); - - /* allocate texture region/storage */ - mt->region = st->pipe->winsys->region_alloc(st->pipe->winsys, - cpp, width, height, flags); - - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = pipeFormat; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->pitch = mt->region->pitch; - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; - - return mt; -} - - /** - * Make mipmap tree containing an image for glDrawPixels image. + * Make texture containing an image for glDrawPixels image. * If 'pixels' is NULL, leave the texture image data undefined. */ -static struct pipe_mipmap_tree * -make_mipmap_tree(struct st_context *st, - GLsizei width, GLsizei height, GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels) +static struct pipe_texture * +make_texture(struct st_context *st, + GLsizei width, GLsizei height, GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels) { GLcontext *ctx = st->ctx; struct pipe_context *pipe = st->pipe; const struct gl_texture_format *mformat; - struct pipe_mipmap_tree *mt; - GLuint pipeFormat, cpp; + struct pipe_texture *pt; + enum pipe_format pipeFormat; + GLuint cpp; GLenum baseFormat; baseFormat = _mesa_base_format(format); @@ -510,31 +469,34 @@ make_mipmap_tree(struct st_context *st, assert(pipeFormat); cpp = st_sizeof_format(pipeFormat); - mt = alloc_mipmap_tree(st, width, height, pipeFormat); - if (!mt) + pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, baseFormat, 0, 0, + width, height, 1, 0); + if (!pt) return NULL; if (unpack->BufferObj && unpack->BufferObj->Name) { /* - mt->region = buffer_object_region(unpack->BufferObj); + pt->region = buffer_object_region(unpack->BufferObj); */ printf("st_DrawPixels (sourcing from PBO not implemented yet)\n"); } { + struct pipe_surface *surface; static const GLuint dstImageOffsets = 0; GLboolean success; - GLuint pitch = mt->region->pitch; GLubyte *dest; const GLbitfield imageTransferStateSave = ctx->_ImageTransferState; /* we'll do pixel transfer in a fragment shader */ ctx->_ImageTransferState = 0x0; - /* map texture region */ - dest = pipe->region_map(pipe, mt->region); + surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); - /* Put image into texture region. + /* map texture surface */ + dest = pipe_surface_map(surface); + + /* Put image into texture surface. * Note that the image is actually going to be upside down in * the texture. We deal with that with texcoords. */ @@ -543,7 +505,7 @@ make_mipmap_tree(struct st_context *st, mformat, /* gl_texture_format */ dest, /* dest */ 0, 0, 0, /* dstX/Y/Zoffset */ - pitch * cpp, /* dstRowStride, bytes */ + surface->pitch * cpp, /* dstRowStride, bytes */ &dstImageOffsets, /* dstImageOffsets */ width, height, 1, /* size */ format, type, /* src format/type */ @@ -551,44 +513,15 @@ make_mipmap_tree(struct st_context *st, unpack); /* unmap */ - pipe->region_unmap(pipe, mt->region); + pipe_surface_unmap(surface); + pipe_surface_reference(&surface, NULL); assert(success); /* restore */ ctx->_ImageTransferState = imageTransferStateSave; } -#if 0 - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = pipeFormat; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->pitch = mt->region->pitch; - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; -#endif - return mt; -} - - -static void -free_mipmap_tree(struct pipe_context *pipe, struct pipe_mipmap_tree *mt) -{ - pipe->winsys->region_release(pipe->winsys, &mt->region); - free(mt); + return pt; } @@ -694,7 +627,7 @@ static void draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, GLsizei width, GLsizei height, GLfloat zoomX, GLfloat zoomY, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, struct st_vertex_program *stvp, struct st_fragment_program *stfp, const GLfloat *color, @@ -762,9 +695,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_viewport_state(pipe, &vp); } - /* mipmap tree state: */ + /* texture state: */ { - pipe->set_texture_state(pipe, unit, mt); + pipe->set_texture_state(pipe, unit, pt); } /* Compute window coords (y=0=bottom) with pixel zoom. @@ -797,47 +730,47 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, * XXX probably move this to a re-usable place. */ static GLboolean -compatible_formats(GLenum format, GLenum type, GLuint pipeFormat) +compatible_formats(GLenum format, GLenum type, enum pipe_format pipeFormat) { static const GLuint one = 1; GLubyte littleEndian = *((GLubyte *) &one); - if (pipeFormat == PIPE_FORMAT_U_R8_G8_B8_A8 && + if (pipeFormat == PIPE_FORMAT_R8G8B8A8_UNORM && format == GL_RGBA && type == GL_UNSIGNED_BYTE && !littleEndian) { return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_R8_G8_B8_A8 && + else if (pipeFormat == PIPE_FORMAT_R8G8B8A8_UNORM && format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && littleEndian) { return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_A8_R8_G8_B8 && + else if (pipeFormat == PIPE_FORMAT_A8R8G8B8_UNORM && format == GL_BGRA && type == GL_UNSIGNED_BYTE && littleEndian) { return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_R5_G6_B5 && + else if (pipeFormat == PIPE_FORMAT_R5G6B5_UNORM && format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { /* endian don't care */ return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_R5_G6_B5 && + else if (pipeFormat == PIPE_FORMAT_R5G6B5_UNORM && format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5_REV) { /* endian don't care */ return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_S8 && + else if (pipeFormat == PIPE_FORMAT_S8_UNORM && format == GL_STENCIL_INDEX && type == GL_UNSIGNED_BYTE) { return GL_TRUE; } - else if (pipeFormat == PIPE_FORMAT_U_Z32 && + else if (pipeFormat == PIPE_FORMAT_Z32_UNORM && format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_INT) { return GL_TRUE; @@ -919,7 +852,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, pipe->flush(pipe, 0); /* map the stencil buffer */ - stmap = pipe->region_map(pipe, ps->region); + stmap = pipe_surface_map(ps); /* if width > MAX_WIDTH, have to process image in chunks */ skipPixels = 0; @@ -952,13 +885,13 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, switch (ps->format) { case PIPE_FORMAT_U_S8: { - ubyte *dest = stmap + spanY * ps->region->pitch + spanX; + ubyte *dest = stmap + spanY * ps->pitch + spanX; memcpy(dest, values, spanWidth); } break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: { - uint *dest = (uint *) stmap + spanY * ps->region->pitch + spanX; + uint *dest = (uint *) stmap + spanY * ps->pitch + spanX; GLint k; for (k = 0; k < spanWidth; k++) { uint p = dest[k]; @@ -976,7 +909,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* unmap the stencil buffer */ - pipe->region_unmap(pipe, ps->region); + pipe_surface_unmap(ps); } @@ -1026,14 +959,13 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, any_pixel_transfer_ops(st) || !compatible_formats(format, type, ps->format)) { /* textured quad */ - struct pipe_mipmap_tree *mt - = make_mipmap_tree(ctx->st, width, height, format, type, - unpack, pixels); - if (mt) { + struct pipe_texture *pt + = make_texture(ctx->st, width, height, format, type, unpack, pixels); + if (pt) { draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, - mt, stvp, stfp, color, GL_FALSE); - free_mipmap_tree(st->pipe, mt); + pt, stvp, stfp, color, GL_FALSE); + st->pipe->texture_release(st->pipe, &pt); } } else { @@ -1047,26 +979,29 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /** * Create a texture which represents a bitmap image. */ -static struct pipe_mipmap_tree * +static struct pipe_texture * make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap) { struct pipe_context *pipe = ctx->st->pipe; - const uint flags = PIPE_SURFACE_FLAG_TEXTURE; - uint format = 0, cpp, comp, pitch; + struct pipe_surface *surface; + uint format = 0, cpp, comp; + GLenum internal_format; ubyte *dest; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; int row, col; /* find a texture format we know */ if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 )) { format = PIPE_FORMAT_U_I8; + internal_format = GL_INTENSITY8; cpp = 1; comp = 0; } - else if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) { - format = PIPE_FORMAT_U_A8_R8_G8_B8; + else if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM )) { + format = PIPE_FORMAT_A8R8G8B8_UNORM; + internal_format = GL_RGBA8; cpp = 4; comp = 3; /* alpha channel */ /*XXX little-endian dependency */ } @@ -1076,33 +1011,26 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, } /** - * Create a mipmap tree. + * Create a texture. */ - mt = CALLOC_STRUCT(pipe_mipmap_tree); - if (!mt) + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, internal_format, + 0, 0, width, height, 1, 0); + if (!pt) return NULL; if (unpack->BufferObj && unpack->BufferObj->Name) { /* - mt->region = buffer_object_region(unpack->BufferObj); + pt->region = buffer_object_region(unpack->BufferObj); */ printf("st_Bitmap (sourcing from PBO not implemented yet)\n"); } + surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); - /* allocate texture region/storage */ - mt->region = pipe->winsys->region_alloc(pipe->winsys, - cpp, width, height, flags); - pitch = mt->region->pitch; + /* map texture surface */ + dest = pipe_surface_map(surface); - /* map texture region */ - dest = pipe->region_map(pipe, mt->region); - if (!dest) { - printf("st_Bitmap region_map() failed!?!"); - return NULL; - } - - /* Put image into texture region. + /* Put image into texture surface. * Note that the image is actually going to be upside down in * the texture. We deal with that with texcoords. */ @@ -1110,7 +1038,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, for (row = 0; row < height; row++) { const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); - ubyte *destRow = dest + row * pitch * cpp; + ubyte *destRow = dest + row * surface->pitch * cpp; if (unpack->LsbFirst) { /* Lsb first */ @@ -1159,31 +1087,13 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, } /* row */ - /* unmap */ - pipe->region_unmap(pipe, mt->region); - - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = format; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->pitch = mt->region->pitch; - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; - - return mt; + /* Release surface */ + pipe_surface_unmap(surface); + pipe_surface_reference(&surface, NULL); + + pt->format = format; + + return pt; } @@ -1195,21 +1105,21 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct st_fragment_program *stfp; struct st_vertex_program *stvp; struct st_context *st = ctx->st; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; stvp = make_vertex_shader(ctx->st, GL_TRUE); stfp = combined_bitmap_fragment_program(ctx); st_validate_state(st); - mt = make_bitmap_texture(ctx, width, height, unpack, bitmap); - if (mt) { + pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); + if (pt) { draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, 1.0, 1.0, - mt, stvp, stfp, + pt, stvp, stfp, ctx->Current.RasterColor, GL_FALSE); - free_mipmap_tree(st->pipe, mt); + st->pipe->texture_release(st->pipe, &pt); } } @@ -1219,8 +1129,6 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty) { - struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; struct st_renderbuffer *rbRead = st_renderbuffer(ctx->ReadBuffer->_StencilBuffer); struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer); struct pipe_surface *psRead = rbRead->surface; @@ -1236,8 +1144,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } /* map the stencil buffers */ - readMap = pipe->region_map(pipe, psRead->region); - drawMap = pipe->region_map(pipe, psDraw->region); + readMap = pipe_surface_map(psRead); + drawMap = pipe_surface_map(psDraw); /* this will do stencil pixel transfer ops */ st_read_stencil_pixels(ctx, srcx, srcy, width, height, GL_UNSIGNED_BYTE, @@ -1256,11 +1164,11 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, y = ctx->DrawBuffer->Height - y - 1; } - dst = drawMap + (y * psDraw->region->pitch + dstx) * psDraw->region->cpp; + dst = drawMap + (y * psDraw->pitch + dstx) * psDraw->cpp; src = buffer + i * width; switch (psDraw->format) { - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: { uint *dst4 = (uint *) dst; int j; @@ -1281,8 +1189,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, free(buffer); /* unmap the stencil buffers */ - pipe->region_unmap(pipe, psRead->region); - pipe->region_unmap(pipe, psDraw->region); + pipe_surface_unmap(psRead); + pipe_surface_unmap(psDraw); } @@ -1297,7 +1205,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, struct st_vertex_program *stvp; struct st_fragment_program *stfp; struct pipe_surface *psRead; - struct pipe_mipmap_tree *mt; + struct pipe_surface *psTex; + struct pipe_texture *pt; GLfloat *color; uint format; @@ -1328,56 +1237,52 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, psRead = rbRead->surface; format = psRead->format; - mt = alloc_mipmap_tree(ctx->st, width, height, format); - if (!mt) + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, + rbRead->Base.InternalFormat, 0, 0, width, height, 1, 0); + if (!pt) return; + psTex = pipe->get_tex_surface(pipe, pt, 0, 0, 0); + if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { srcy = ctx->DrawBuffer->Height - srcy - height; } /* For some drivers (like Xlib) it's not possible to treat the - * front/back color buffers as regions (they're XImages and Pixmaps). - * So, this var tells us if we can use region_copy here... + * front/back color buffers as surfaces (they're XImages and Pixmaps). + * So, this var tells us if we can use surface_copy here... */ - if (st->haveFramebufferRegions) { - /* copy source framebuffer region into mipmap/texture */ - pipe->region_copy(pipe, - mt->region, /* dest */ - 0, /* dest_offset */ - 0, 0, /* destx/y */ - psRead->region, - 0, /* src_offset */ - srcx, srcy, width, height); + if (st->haveFramebufferSurfaces) { + /* copy source framebuffer surface into mipmap/texture */ + pipe->surface_copy(pipe, + psTex, /* dest */ + 0, 0, /* destx/y */ + psRead, + srcx, srcy, width, height); } else { /* alternate path using get/put_tile() */ - struct pipe_surface *psTex; GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - psTex = pipe->get_tex_surface(pipe, mt, 0, 0, 0); - - (void) pipe->region_map(pipe, psRead->region); - (void) pipe->region_map(pipe, psTex->region); + (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->region_unmap(pipe, psRead->region); - pipe->region_unmap(pipe, psTex->region); - - pipe_surface_reference(&psTex, NULL); + pipe_surface_unmap(psRead); + pipe_surface_unmap(psTex); free(buf); } - /* draw textured quad */ draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, - mt, stvp, stfp, color, GL_TRUE); + pt, stvp, stfp, color, GL_TRUE); - free_mipmap_tree(st->pipe, mt); + pipe_surface_reference(&psTex, NULL); + st->pipe->texture_release(st->pipe, &pt); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index f58d532b2a7..cbda56b5c3d 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -55,7 +55,8 @@ * Compute the renderbuffer's Red/Green/EtcBit fields from the pipe format. */ static int -init_renderbuffer_bits(struct st_renderbuffer *strb, uint pipeFormat) +init_renderbuffer_bits(struct st_renderbuffer *strb, + enum pipe_format pipeFormat) { struct pipe_format_info info; @@ -86,7 +87,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - const uint pipeFormat + const enum pipe_format pipeFormat = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); GLuint cpp; GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ @@ -104,23 +105,28 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, assert(strb->surface); if (!strb->surface) return GL_FALSE; + strb->surface->cpp = cpp; } - /* free old region */ - if (strb->surface->region) { - /* loop here since mapping is refcounted */ - struct pipe_region *r = strb->surface->region; - while (r->map) - pipe->region_unmap(pipe, r); - pipe->winsys->region_release(pipe->winsys, &strb->surface->region); - } + strb->surface->pitch = pipe->winsys->surface_pitch(pipe->winsys, cpp, + width, flags); + + /* 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); - strb->surface->region = pipe->winsys->region_alloc(pipe->winsys, cpp, - width, height, flags); - if (!strb->surface->region) + strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, flags); + if (!strb->surface->buffer) return GL_FALSE; /* out of memory, try s/w buffer? */ - ASSERT(strb->surface->region->buffer); + pipe->winsys->buffer_data(pipe->winsys, strb->surface->buffer, + strb->surface->pitch * cpp * height, NULL, + PIPE_BUFFER_USAGE_PIXEL); + + ASSERT(strb->surface->buffer); ASSERT(strb->surface->format); strb->Base.Width = strb->surface->width = width; @@ -282,7 +288,7 @@ st_render_texture(GLcontext *ctx, struct st_renderbuffer *strb; struct gl_renderbuffer *rb; struct pipe_context *pipe = st->pipe; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; assert(!att->Renderbuffer); @@ -298,26 +304,26 @@ st_render_texture(GLcontext *ctx, rb->AllocStorage = NULL; /* should not get called */ strb = st_renderbuffer(rb); - /* get the mipmap tree for the texture */ - mt = st_get_texobj_mipmap_tree(att->Texture); - assert(mt); - assert(mt->level[att->TextureLevel].width); + /* get the texture for the texture object */ + pt = st_get_texobj_texture(att->Texture); + assert(pt); + assert(pt->width[att->TextureLevel]); - rb->Width = mt->level[att->TextureLevel].width; - rb->Height = mt->level[att->TextureLevel].height; + rb->Width = pt->width[att->TextureLevel]; + rb->Height = pt->height[att->TextureLevel]; - /* the renderbuffer's surface is inside the mipmap_tree: */ - strb->surface = pipe->get_tex_surface(pipe, mt, + /* the renderbuffer's surface is inside the texture */ + strb->surface = pipe->get_tex_surface(pipe, pt, att->CubeMapFace, att->TextureLevel, att->Zoffset); assert(strb->surface); - init_renderbuffer_bits(strb, mt->format); + init_renderbuffer_bits(strb, pt->format); /* - printf("RENDER TO TEXTURE obj=%p mt=%p surf=%p %d x %d\n", - att->Texture, mt, strb->surface, rb->Width, rb->Height); + printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p %d x %d\n", + att->Texture, pt, strb->surface, rb->Width, rb->Height); */ /* Invalidate buffer state so that the pipe's framebuffer state diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c index a9fd2579a22..ea775b9452d 100644 --- a/src/mesa/state_tracker/st_cb_feedback.c +++ b/src/mesa/state_tracker/st_cb_feedback.c @@ -43,7 +43,6 @@ #include "main/macros.h" #include "vbo/vbo.h" -#include "vbo/vbo_context.h" #include "st_context.h" #include "st_atom.h" @@ -281,26 +280,25 @@ static void st_RenderMode(GLcontext *ctx, GLenum newMode ) { struct st_context *st = ctx->st; - struct vbo_context *vbo = (struct vbo_context *) ctx->swtnl_im; struct draw_context *draw = st->draw; if (newMode == GL_RENDER) { /* restore normal VBO draw function */ - vbo->draw_prims = st_draw_vbo; + vbo_set_draw_func(ctx, st_draw_vbo); } else if (newMode == GL_SELECT) { if (!st->selection_stage) st->selection_stage = draw_glselect_stage(ctx, draw); draw_set_rasterize_stage(draw, st->selection_stage); /* Plug in new vbo draw function */ - vbo->draw_prims = st_feedback_draw_vbo; + vbo_set_draw_func(ctx, st_feedback_draw_vbo); } else { if (!st->feedback_stage) st->feedback_stage = draw_glfeedback_stage(ctx, draw); draw_set_rasterize_stage(draw, st->feedback_stage); /* Plug in new vbo draw function */ - vbo->draw_prims = st_feedback_draw_vbo; + vbo_set_draw_func(ctx, st_feedback_draw_vbo); /* need to generate/use a vertex program that emits pos/color/tex */ 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 2e7c01672a1..96829fcfa0f 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -39,6 +39,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "st_context.h" #include "st_cb_readpixels.h" #include "st_cb_fbo.h" @@ -56,8 +57,6 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, const struct gl_pixelstore_attrib *packing, GLvoid *pixels) { - struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer); struct pipe_surface *ps = strb->surface; @@ -65,7 +64,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLint j; /* map the stencil buffer */ - stmap = pipe->region_map(pipe, ps->region); + stmap = pipe_surface_map(ps); /* width should never be > MAX_WIDTH since we did clipping earlier */ ASSERT(width <= MAX_WIDTH); @@ -87,22 +86,22 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, switch (ps->format) { case PIPE_FORMAT_U_S8: { - const ubyte *src = stmap + srcY * ps->region->pitch + x; + const ubyte *src = stmap + srcY * ps->pitch + x; memcpy(values, src, width); } break; - case PIPE_FORMAT_S8_Z24: + case PIPE_FORMAT_S8Z24_UNORM: { - const uint *src = (uint *) stmap + srcY * ps->region->pitch + x; + const uint *src = (uint *) stmap + srcY * ps->pitch + x; GLint k; for (k = 0; k < width; k++) { values[k] = src[k] >> 24; } } break; - case PIPE_FORMAT_Z24_S8: + case PIPE_FORMAT_Z24S8_UNORM: { - const uint *src = (uint *) stmap + srcY * ps->region->pitch + x; + const uint *src = (uint *) stmap + srcY * ps->pitch + x; GLint k; for (k = 0; k < width; k++) { values[k] = src[k] & 0xff; @@ -122,7 +121,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ - pipe->region_unmap(pipe, ps->region); + pipe_surface_unmap(ps); } @@ -151,7 +150,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* Do all needed clipping here, so that we can forget about it later */ if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) { - /* The ReadPixels region is totally outside the window bounds */ + /* The ReadPixels surface is totally outside the window bounds */ return; } @@ -180,7 +179,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (!strb) return; - pipe->region_map(pipe, strb->surface->region); + pipe_surface_map(strb->surface); if (format == GL_RGBA && type == GL_FLOAT) { /* write tile(row) directly into user's buffer */ @@ -231,7 +230,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } - pipe->region_unmap(pipe, strb->surface->region); + 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 4e6d4857f48..14f8d38def8 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -40,10 +40,11 @@ #include "state_tracker/st_cb_fbo.h" #include "state_tracker/st_cb_texture.h" #include "state_tracker/st_format.h" -#include "state_tracker/st_mipmap_tree.h" +#include "state_tracker/st_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #define DBG if (0) printf @@ -53,8 +54,7 @@ struct st_texture_object { struct gl_texture_object base; /* The "parent" object */ - /* The mipmap tree must include at least these levels once - * validated: + /* The texture must include at least these levels once validated: */ GLuint firstLevel; GLuint lastLevel; @@ -64,9 +64,9 @@ struct st_texture_object GLuint textureOffset; /* On validation any active images held in main memory or in other - * regions will be copied to this region and the old storage freed. + * textures will be copied to this texture and the old storage freed. */ - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; GLboolean imageOverride; GLint depthOverride; @@ -75,24 +75,6 @@ struct st_texture_object -struct st_texture_image -{ - struct gl_texture_image base; - - /* These aren't stored in gl_texture_image - */ - GLuint level; - GLuint face; - - /* If stImage->mt != NULL, image data is stored here. - * Else if stImage->base.Data != NULL, image is stored there. - * Else there is no image data. - */ - struct pipe_mipmap_tree *mt; -}; - - - static INLINE struct st_texture_object * st_texture_object(struct gl_texture_object *obj) @@ -107,11 +89,11 @@ st_texture_image(struct gl_texture_image *img) } -struct pipe_mipmap_tree * -st_get_texobj_mipmap_tree(struct gl_texture_object *texObj) +struct pipe_texture * +st_get_texobj_texture(struct gl_texture_object *texObj) { struct st_texture_object *stObj = st_texture_object(texObj); - return stObj->mt; + return stObj->pt; } @@ -173,9 +155,9 @@ st_IsTextureResident(GLcontext * ctx, struct gl_texture_object *texObj) struct st_texture_object *stObj = st_texture_object(texObj); return - stObj->mt && - stObj->mt->region && - intel_is_region_resident(intel, stObj->mt->region); + stObj->pt && + stObj->pt->region && + intel_is_region_resident(intel, stObj->pt->region); #endif return 1; } @@ -206,11 +188,10 @@ static void st_DeleteTextureObject(GLcontext *ctx, struct gl_texture_object *texObj) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_object *stObj = st_texture_object(texObj); - if (stObj->mt) - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); _mesa_delete_texture_object(ctx, texObj); } @@ -219,13 +200,12 @@ st_DeleteTextureObject(GLcontext *ctx, static void st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); DBG("%s\n", __FUNCTION__); - if (stImage->mt) { - st_miptree_release(pipe, &stImage->mt); + if (stImage->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stImage->pt); } if (texImage->Data) { @@ -286,10 +266,10 @@ do_memcpy(void *dest, const void *src, size_t n) } -/* Functions to store texture images. Where possible, mipmap_tree's +/* Functions to store texture images. Where possible, textures * will be created or further instantiated with image data, otherwise * images will be stored in malloc'd memory. A validation step is - * required to pull those images into a mipmap tree, or otherwise + * required to pull those images into a texture, or otherwise * decide a fallback is required. */ @@ -312,17 +292,16 @@ logbase2(int n) /* Otherwise, store it in memory if (Border != 0) or (any dimension == * 1). * - * Otherwise, if max_level >= level >= min_level, create tree with - * space for textures from min_level down to max_level. + * Otherwise, if max_level >= level >= min_level, create texture with + * space for images from min_level down to max_level. * - * Otherwise, create tree with space for textures from (level - * 0)..(1x1). Consider pruning this tree at a validation if the - * saving is worth it. + * Otherwise, create texture with space for images from (level 0)..(1x1). + * Consider pruning this texture at a validation if the saving is worth it. */ static void -guess_and_alloc_mipmap_tree(struct pipe_context *pipe, - struct st_texture_object *stObj, - struct st_texture_image *stImage) +guess_and_alloc_texture(struct st_context *st, + struct st_texture_object *stObj, + struct st_texture_image *stImage) { GLuint firstLevel; GLuint lastLevel; @@ -381,23 +360,20 @@ guess_and_alloc_mipmap_tree(struct pipe_context *pipe, lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth); } - assert(!stObj->mt); + assert(!stObj->pt); if (stImage->base.IsCompressed) comp_byte = compressed_num_bytes(stImage->base.TexFormat->MesaFormat); - stObj->mt = st_miptree_create(pipe, + stObj->pt = st_texture_create(st, gl_target_to_pipe(stObj->base.Target), - stImage->base.InternalFormat, + st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat), + stImage->base.InternalFormat, firstLevel, lastLevel, width, height, depth, - stImage->base.TexFormat->TexelBytes, comp_byte); - stObj->mt->format - = st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat); - DBG("%s - success\n", __FUNCTION__); } @@ -481,11 +457,11 @@ try_pbo_upload(GLcontext *ctx, else src_stride = width; - dst_offset = st_miptree_image_offset(stImage->mt, + dst_offset = st_texture_image_offset(stImage->pt, stImage->face, stImage->level); - dst_stride = stImage->mt->pitch; + dst_stride = stImage->pt->pitch; { struct _DriBufferObject *src_buffer = @@ -494,11 +470,11 @@ try_pbo_upload(GLcontext *ctx, /* Temporary hack: cast to _DriBufferObject: */ struct _DriBufferObject *dst_buffer = - (struct _DriBufferObject *)stImage->mt->region->buffer; + (struct _DriBufferObject *)stImage->pt->region->buffer; intelEmitCopyBlit(intel, - stImage->mt->cpp, + stImage->pt->cpp, src_stride, src_buffer, src_offset, dst_stride, dst_buffer, dst_offset, 0, 0, 0, 0, width, height, @@ -539,7 +515,6 @@ st_TexImage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage, GLsizei imageSize, int compressed) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLint postConvWidth = width; @@ -588,58 +563,58 @@ st_TexImage(GLcontext * ctx, /* Release the reference to a potentially orphaned buffer. * Release any old malloced memory. */ - if (stImage->mt) { - st_miptree_release(pipe, &stImage->mt); + if (stImage->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stImage->pt); assert(!texImage->Data); } else if (texImage->Data) { _mesa_align_free(texImage->Data); } - /* If this is the only texture image in the tree, could call + /* If this is the only texture image in the texture, could call * bmBufferData with NULL data to free the old block and avoid * waiting on any outstanding fences. */ - if (stObj->mt && - stObj->mt->first_level == level && - stObj->mt->last_level == level && - stObj->mt->target != PIPE_TEXTURE_CUBE && - !st_miptree_match_image(stObj->mt, &stImage->base, + if (stObj->pt && + stObj->pt->first_level == level && + stObj->pt->last_level == level && + stObj->pt->target != PIPE_TEXTURE_CUBE && + !st_texture_match_image(stObj->pt, &stImage->base, stImage->face, stImage->level)) { DBG("release it\n"); - st_miptree_release(pipe, &stObj->mt); - assert(!stObj->mt); + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); + assert(!stObj->pt); } - if (!stObj->mt) { - guess_and_alloc_mipmap_tree(pipe, stObj, stImage); - if (!stObj->mt) { - DBG("guess_and_alloc_mipmap_tree: failed\n"); + if (!stObj->pt) { + guess_and_alloc_texture(ctx->st, stObj, stImage); + if (!stObj->pt) { + DBG("guess_and_alloc_texture: failed\n"); } } - assert(!stImage->mt); + assert(!stImage->pt); - if (stObj->mt && - st_miptree_match_image(stObj->mt, &stImage->base, + if (stObj->pt && + st_texture_match_image(stObj->pt, &stImage->base, stImage->face, stImage->level)) { - st_miptree_reference(&stImage->mt, stObj->mt); - assert(stImage->mt); + pipe_texture_reference(ctx->st->pipe, &stImage->pt, stObj->pt); + assert(stImage->pt); } - if (!stImage->mt) - DBG("XXX: Image did not fit into tree - storing in local memory!\n"); + if (!stImage->pt) + DBG("XXX: Image did not fit into texture - storing in local memory!\n"); #if 0 /* XXX FIX when st_buffer_objects are in place */ /* PBO fastpaths: */ if (dims <= 2 && - stImage->mt && + stImage->pt && intel_buffer_object(unpack->BufferObj) && check_pbo_format(internalFormat, format, - type, stImage->base.TexFormat)) { + type, texImage->TexFormat)) { DBG("trying pbo upload\n"); @@ -649,9 +624,9 @@ st_TexImage(GLcontext * ctx, * performance (in particular when pipe_region_cow() is * required). */ - if (stObj->mt == stImage->mt && - stObj->mt->first_level == level && - stObj->mt->last_level == level) { + if (stObj->pt == stImage->pt && + stObj->pt->first_level == level && + stObj->pt->last_level == level) { if (try_pbo_zcopy(intel, stImage, unpack, internalFormat, @@ -681,8 +656,8 @@ st_TexImage(GLcontext * ctx, #endif - /* intelCopyTexImage calls this function with pixels == NULL, with - * the expectation that the mipmap tree will be set up but nothing + /* st_CopyTexImage calls this function with pixels == NULL, with + * the expectation that the texture will be set up but nothing * more will be done. This is where those calls return: */ if (compressed) { @@ -697,13 +672,9 @@ st_TexImage(GLcontext * ctx, if (!pixels) return; - if (stImage->mt) { - texImage->Data = st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &dstRowStride, - stImage->base.ImageOffsets); + if (stImage->pt) { + texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + dstRowStride = stImage->surface->pitch * stImage->surface->cpp; } else { /* Allocate regular memory and store the image there temporarily. */ @@ -731,22 +702,37 @@ st_TexImage(GLcontext * ctx, if (compressed) { memcpy(texImage->Data, pixels, imageSize); } - else if (!texImage->TexFormat->StoreImage(ctx, dims, - texImage->_BaseFormat, - texImage->TexFormat, - texImage->Data, - 0, 0, 0, /* dstX/Y/Zoffset */ - dstRowStride, - texImage->ImageOffsets, - width, height, depth, - format, type, pixels, unpack)) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); + else { + GLuint srcImageStride = _mesa_image_image_stride(unpack, width, height, + format, type); + int i; + const GLubyte *src = (const GLubyte *) pixels; + + for (i = 0; i++ < depth;) { + if (!texImage->TexFormat->StoreImage(ctx, dims, + texImage->_BaseFormat, + texImage->TexFormat, + texImage->Data, + 0, 0, 0, /* dstX/Y/Zoffset */ + dstRowStride, + texImage->ImageOffsets, + width, height, 1, + format, type, src, unpack)) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i); + src += srcImageStride; + } + } } _mesa_unmap_teximage_pbo(ctx, unpack); - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); + if (stImage->pt) { + st_texture_image_unmap(stImage); texImage->Data = NULL; } @@ -835,52 +821,61 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage, int compressed) { - /* - struct intel_context *intel = intel_context(ctx); - */ - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); + GLuint dstImageStride = _mesa_image_image_stride(&ctx->Pack, texImage->Width, + texImage->Height, format, + type); + GLuint depth; + int i; + GLubyte *dest; /* Map */ - if (stImage->mt) { + if (stImage->pt) { /* Image is stored in hardware format in a buffer managed by the * kernel. Need to explicitly map and unmap it. */ - stImage->base.Data = - st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &stImage->base.RowStride, - stImage->base.ImageOffsets); - stImage->base.RowStride /= stImage->mt->cpp; + texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + texImage->RowStride = stImage->surface->pitch; } else { /* Otherwise, the image should actually be stored in - * stImage->base.Data. This is pretty confusing for + * texImage->Data. This is pretty confusing for * everybody, I'd much prefer to separate the two functions of * texImage->Data - storage for texture images in main memory * and access (ie mappings) of images. In other words, we'd * create a new texImage->Map field and leave Data simply for * storage. */ - assert(stImage->base.Data); + assert(texImage->Data); } + depth = texImage->Depth; + texImage->Depth = 1; - if (compressed) { - _mesa_get_compressed_teximage(ctx, target, level, pixels, - texObj, texImage); - } else { - _mesa_get_teximage(ctx, target, level, format, type, pixels, - texObj, texImage); + dest = (GLubyte *) pixels; + + for (i = 0; i++ < depth;) { + if (compressed) { + _mesa_get_compressed_teximage(ctx, target, level, dest, + texObj, texImage); + } else { + _mesa_get_teximage(ctx, target, level, format, type, dest, + texObj, texImage); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i); + dest += dstImageStride; + } } - + + texImage->Depth = depth; /* Unmap */ - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); - stImage->base.Data = NULL; + if (stImage->pt) { + st_texture_image_unmap(stImage); + texImage->Data = NULL; } } @@ -920,9 +915,12 @@ st_TexSubimage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride; + GLuint srcImageStride = _mesa_image_image_stride(packing, width, height, + format, type); + int i; + const GLubyte *src; DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__, _mesa_lookup_enum_by_nr(target), @@ -937,25 +935,30 @@ st_TexSubimage(GLcontext * ctx, /* Map buffer if necessary. Need to lock to prevent other contexts * from uploading the buffer under us. */ - if (stImage->mt) - texImage->Data = st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &dstRowStride, - texImage->ImageOffsets); - - assert(dstRowStride); - - if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, - texImage->TexFormat, - texImage->Data, - xoffset, yoffset, zoffset, - dstRowStride, - texImage->ImageOffsets, - width, height, depth, - format, type, pixels, packing)) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage"); + if (stImage->pt) { + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset); + dstRowStride = stImage->surface->pitch * stImage->surface->cpp; + } + + src = (const GLubyte *) pixels; + + for (i = 0; i++ < depth;) { + if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, + texImage->TexFormat, + texImage->Data, + xoffset, yoffset, 0, + dstRowStride, + texImage->ImageOffsets, + width, height, 1, + format, type, src, packing)) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "st_TexSubImage"); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i); + src += srcImageStride; + } } #if 0 @@ -969,8 +972,8 @@ st_TexSubimage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, packing); - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); + if (stImage->pt) { + st_texture_image_unmap(stImage); texImage->Data = NULL; } } @@ -1055,8 +1058,8 @@ texture_face(GLenum target) /** - * Do a CopyTexSubImage operation by mapping the source region and - * dest region and using get_tile()/put_tile() to access the pixels/texels. + * Do a CopyTexSubImage operation by mapping the source surface and + * dest surface and using get_tile()/put_tile() to access the pixels/texels. * * Note: srcY=0=TOP of renderbuffer */ @@ -1073,7 +1076,7 @@ fallback_copy_texsubimage(GLcontext *ctx, { struct pipe_context *pipe = ctx->st->pipe; const uint face = texture_face(target); - struct pipe_mipmap_tree *mt = stImage->mt; + struct pipe_texture *pt = stImage->pt; struct pipe_surface *src_surf, *dest_surf; GLfloat *data; GLint row, yStep; @@ -1089,11 +1092,11 @@ fallback_copy_texsubimage(GLcontext *ctx, src_surf = strb->surface; - dest_surf = pipe->get_tex_surface(pipe, mt, + dest_surf = pipe->get_tex_surface(pipe, pt, face, level, destZ); - (void) pipe->region_map(pipe, dest_surf->region); - (void) pipe->region_map(pipe, src_surf->region); + (void) pipe_surface_map(dest_surf); + (void) pipe_surface_map(src_surf); /* buffer for one row */ data = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); @@ -1114,8 +1117,8 @@ fallback_copy_texsubimage(GLcontext *ctx, } - (void) pipe->region_unmap(pipe, dest_surf->region); - (void) pipe->region_unmap(pipe, src_surf->region); + (void) pipe_surface_unmap(dest_surf); + (void) pipe_surface_unmap(src_surf); free(data); } @@ -1149,8 +1152,7 @@ do_copy_texsubimage(GLcontext *ctx, struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb; struct pipe_context *pipe = ctx->st->pipe; - struct pipe_region *src_region, *dest_region; - uint dest_offset, src_offset; + struct pipe_surface *dest_surface; uint dest_format, src_format; (void) texImage; @@ -1169,28 +1171,24 @@ do_copy_texsubimage(GLcontext *ctx, assert(strb); assert(strb->surface); - assert(stImage->mt); + assert(stImage->pt); if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { srcY = strb->Base.Height - srcY - height; } src_format = strb->surface->format; - dest_format = stImage->mt->format; + dest_format = stImage->pt->format; - src_region = strb->surface->region; - dest_region = stImage->mt->region; + dest_surface = pipe->get_tex_surface(pipe, stImage->pt, stImage->face, + stImage->level, destZ); if (src_format == dest_format && ctx->_ImageTransferState == 0x0 && - src_region && - dest_region && - src_region->cpp == dest_region->cpp) { + strb->surface->buffer && + dest_surface->buffer && + strb->surface->cpp == stImage->pt->cpp) { /* do blit-style copy */ - src_offset = 0; - dest_offset = st_miptree_image_offset(stImage->mt, - stImage->face, - stImage->level); /* XXX may need to invert image depending on window * vs. user-created FBO @@ -1202,28 +1200,26 @@ do_copy_texsubimage(GLcontext *ctx, * worth it: */ intelEmitCopyBlit(intel, - stImage->mt->cpp, + stImage->pt->cpp, -src->pitch, src->buffer, src->height * src->pitch * src->cpp, - stImage->mt->pitch, - stImage->mt->region->buffer, + stImage->pt->pitch, + stImage->pt->region->buffer, dest_offset, x, y + height, dstx, dsty, width, height, GL_COPY); /* ? */ #else - pipe->region_copy(pipe, - /* dest */ - dest_region, - dest_offset, - destX, destY, - /* src */ - src_region, - src_offset, - srcX, srcY, - /* size */ - width, height); + pipe->surface_copy(pipe, + /* dest */ + dest_surface, + destX, destY, + /* src */ + strb->surface, + srcX, srcY, + /* size */ + width, height); #endif } else { @@ -1233,6 +1229,7 @@ do_copy_texsubimage(GLcontext *ctx, srcX, srcY, width, height); } + pipe_surface_reference(&dest_surface, NULL); #if 0 /* GL_SGIS_generate_mipmap -- this can be accelerated now. @@ -1266,7 +1263,7 @@ st_CopyTexImage1D(GLcontext * ctx, GLenum target, GLint level, goto fail; #endif - /* Setup or redefine the texture object, mipmap tree and texture + /* Setup or redefine the texture object, texture and texture * image. Don't populate yet. */ ctx->Driver.TexImage1D(ctx, target, level, internalFormat, @@ -1298,7 +1295,7 @@ st_CopyTexImage2D(GLcontext * ctx, GLenum target, GLint level, goto fail; #endif - /* Setup or redefine the texture object, mipmap tree and texture + /* Setup or redefine the texture object, texture and texture * image. Don't populate yet. */ ctx->Driver.TexImage2D(ctx, target, level, internalFormat, @@ -1406,28 +1403,28 @@ calculate_first_last_level(struct st_texture_object *stObj) static void -copy_image_data_to_tree(struct pipe_context *pipe, - struct st_texture_object *stObj, - struct st_texture_image *stImage) +copy_image_data_to_texture(struct st_context *st, + struct st_texture_object *stObj, + struct st_texture_image *stImage) { - if (stImage->mt) { + if (stImage->pt) { /* Copy potentially with the blitter: */ - st_miptree_image_copy(pipe, - stObj->mt, /* dest miptree */ + st_texture_image_copy(st->pipe, + stObj->pt, /* dest texture */ stImage->face, stImage->level, - stImage->mt /* src miptree */ + stImage->pt /* src texture */ ); - st_miptree_release(pipe, &stImage->mt); + st->pipe->texture_release(st->pipe, &stImage->pt); } else { assert(stImage->base.Data != NULL); /* More straightforward upload. */ - st_miptree_image_data(pipe, - stObj->mt, + st_texture_image_data(st->pipe, + stObj->pt, stImage->face, stImage->level, stImage->base.Data, @@ -1438,16 +1435,16 @@ copy_image_data_to_tree(struct pipe_context *pipe, stImage->base.Data = NULL; } - st_miptree_reference(&stImage->mt, stObj->mt); + pipe_texture_reference(st->pipe, &stImage->pt, stObj->pt); } /* */ GLboolean -st_finalize_mipmap_tree(GLcontext *ctx, - struct pipe_context *pipe, GLuint unit, - GLboolean *needFlush) +st_finalize_texture(GLcontext *ctx, + struct pipe_context *pipe, GLuint unit, + GLboolean *needFlush) { struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current; struct st_texture_object *stObj = st_texture_object(tObj); @@ -1464,7 +1461,7 @@ st_finalize_mipmap_tree(GLcontext *ctx, */ assert(stObj->base._Complete); - /* What levels must the tree include at a minimum? + /* What levels must the texture include at a minimum? */ calculate_first_last_level(stObj); firstImage = @@ -1473,27 +1470,27 @@ st_finalize_mipmap_tree(GLcontext *ctx, /* Fallback case: */ if (firstImage->base.Border) { - if (stObj->mt) { - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); } return GL_FALSE; } - /* If both firstImage and stObj have a tree which can contain + /* If both firstImage and stObj point to a texture which can contain * all active images, favour firstImage. Note that because of the * completeness requirement, we know that the image dimensions * will match. */ - if (firstImage->mt && - firstImage->mt != stObj->mt && - firstImage->mt->first_level <= stObj->firstLevel && - firstImage->mt->last_level >= stObj->lastLevel) { + if (firstImage->pt && + firstImage->pt != stObj->pt && + firstImage->pt->first_level <= stObj->firstLevel && + firstImage->pt->last_level >= stObj->lastLevel) { - if (stObj->mt) - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); - st_miptree_reference(&stObj->mt, firstImage->mt); + pipe_texture_reference(ctx->st->pipe, &stObj->pt, firstImage->pt); } if (firstImage->base.IsCompressed) { @@ -1504,48 +1501,45 @@ st_finalize_mipmap_tree(GLcontext *ctx, cpp = firstImage->base.TexFormat->TexelBytes; } - /* Check tree can hold all active levels. Check tree matches + /* Check texture can hold all active levels. Check texture matches * target, imageFormat, etc. * * XXX: For some layouts (eg i945?), the test might have to be - * first_level == firstLevel, as the tree isn't valid except at the + * first_level == firstLevel, as the texture isn't valid except at the * original start level. Hope to get around this by * programming minLod, maxLod, baseLevel into the hardware and - * leaving the tree alone. + * leaving the texture alone. */ - if (stObj->mt && - (stObj->mt->target != gl_target_to_pipe(stObj->base.Target) || - stObj->mt->internal_format != firstImage->base.InternalFormat || - stObj->mt->first_level != stObj->firstLevel || - stObj->mt->last_level != stObj->lastLevel || - stObj->mt->width0 != firstImage->base.Width || - stObj->mt->height0 != firstImage->base.Height || - stObj->mt->depth0 != firstImage->base.Depth || - stObj->mt->cpp != cpp || - stObj->mt->compressed != firstImage->base.IsCompressed)) { - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt && + (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) || + stObj->pt->internal_format != firstImage->base.InternalFormat || + stObj->pt->first_level != stObj->firstLevel || + stObj->pt->last_level != stObj->lastLevel || + stObj->pt->width[0] != firstImage->base.Width || + stObj->pt->height[0] != firstImage->base.Height || + stObj->pt->depth[0] != firstImage->base.Depth || + stObj->pt->cpp != cpp || + stObj->pt->compressed != firstImage->base.IsCompressed)) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); } - /* May need to create a new tree: + /* May need to create a new texture: */ - if (!stObj->mt) { - stObj->mt = st_miptree_create(pipe, + if (!stObj->pt) { + stObj->pt = st_texture_create(ctx->st, gl_target_to_pipe(stObj->base.Target), - firstImage->base.InternalFormat, + st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat), + firstImage->base.InternalFormat, stObj->firstLevel, stObj->lastLevel, firstImage->base.Width, firstImage->base.Height, firstImage->base.Depth, - cpp, comp_byte); - - stObj->mt->format - = st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat); } - /* Pull in any images not in the object's tree: + /* Pull in any images not in the object's texture: */ nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; for (face = 0; face < nr_faces; face++) { @@ -1553,10 +1547,10 @@ st_finalize_mipmap_tree(GLcontext *ctx, struct st_texture_image *stImage = st_texture_image(stObj->base.Image[face][i]); - /* Need to import images in main memory or held in other trees. + /* Need to import images in main memory or held in other textures. */ - if (stObj->mt != stImage->mt) { - copy_image_data_to_tree(pipe, stObj, stImage); + if (stObj->pt != stImage->pt) { + copy_image_data_to_texture(ctx->st, stObj, stImage); *needFlush = GL_TRUE; } } diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index 7a1867dc58a..7f8082b029d 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -2,14 +2,14 @@ #define ST_CB_TEXTURE_H -extern struct pipe_mipmap_tree * -st_get_texobj_mipmap_tree(struct gl_texture_object *texObj); +extern struct pipe_texture * +st_get_texobj_texture(struct gl_texture_object *texObj); extern GLboolean -st_finalize_mipmap_tree(GLcontext *ctx, - struct pipe_context *pipe, GLuint unit, - GLboolean *needFlush); +st_finalize_texture(GLcontext *ctx, + struct pipe_context *pipe, GLuint unit, + GLboolean *needFlush); extern void diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index a4ec3721bef..524e06fb00a 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -29,7 +29,7 @@ #include "main/context.h" #include "main/extensions.h" #include "vbo/vbo.h" -#include "drivers/common/driverfuncs.h" +#include "shader/shader_api.h" #include "st_public.h" #include "st_context.h" #include "st_cb_accum.h" @@ -103,7 +103,7 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; - st->haveFramebufferRegions = GL_TRUE; + st->haveFramebufferSurfaces = GL_TRUE; st->pixel_xfer.cache = _mesa_new_program_cache(); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index a6045230a0f..c31b76c63f3 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -34,9 +34,7 @@ struct st_context; -struct st_region; struct st_texture_object; -struct st_texture_image; struct st_fragment_program; struct draw_context; struct draw_stage; @@ -61,6 +59,25 @@ struct st_tracked_state { +struct st_texture_image +{ + struct gl_texture_image base; + + /* These aren't stored in gl_texture_image + */ + GLuint level; + GLuint face; + + /* If stImage->pt != NULL, image data is stored here. + * Else if stImage->base.Data != NULL, image is stored there. + * Else there is no image data. + */ + struct pipe_texture *pt; + + struct pipe_surface *surface; +}; + + struct st_context { @@ -91,7 +108,7 @@ struct st_context struct pipe_constant_buffer constants[2]; struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; @@ -113,11 +130,11 @@ struct st_context char vendor[100]; char renderer[100]; - /** Can we access the front/back color buffers as pipe_regions? + /** Can we access the front/back color buffers as pipe_surfaces? * We can't with the Xlib driver... * This is a hack that should be fixed someday. */ - GLboolean haveFramebufferRegions; + GLboolean haveFramebufferSurfaces; /* State to be validated: */ diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c index e00684ac036..cffd66751de 100644 --- a/src/mesa/state_tracker/st_debug.c +++ b/src/mesa/state_tracker/st_debug.c @@ -30,7 +30,8 @@ #include "shader/prog_print.h" #include "pipe/p_state.h" -#include "pipe/tgsi/exec/tgsi_core.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/tgsi/util/tgsi_dump.h" #include "pipe/cso_cache/cso_cache.h" diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 3b6d8291452..32dcd73c46c 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -34,7 +34,6 @@ #include "main/image.h" #include "vbo/vbo.h" -#include "vbo/vbo_context.h" #include "st_atom.h" #include "st_cache.h" @@ -83,6 +82,7 @@ pipe_vertex_format(GLenum type, GLuint size) default: assert(0); } + return 0; /* silence compiler warning */ } @@ -324,27 +324,26 @@ static void set_feedback_vertex_format(GLcontext *ctx) { struct st_context *st = ctx->st; - uint attrs[PIPE_MAX_SHADER_OUTPUTS]; - enum interp_mode interp[PIPE_MAX_SHADER_OUTPUTS]; - GLuint n, i; + struct vertex_info vinfo; + GLuint i; if (ctx->RenderMode == GL_SELECT) { assert(ctx->RenderMode == GL_SELECT); - n = 1; - attrs[0] = FORMAT_4F; - interp[0] = INTERP_NONE; + vinfo.num_attribs = 1; + vinfo.format[0] = FORMAT_4F; + vinfo.interp_mode[0] = INTERP_NONE; } else { /* GL_FEEDBACK, or glRasterPos */ /* emit all attribs (pos, color, texcoord) as GLfloat[4] */ - n = st->state.vs->state.num_outputs; - for (i = 0; i < n; i++) { - attrs[i] = FORMAT_4F; - interp[i] = INTERP_NONE; + vinfo.num_attribs = st->state.vs->state.num_outputs; + for (i = 0; i < vinfo.num_attribs; i++) { + vinfo.format[i] = FORMAT_4F; + vinfo.interp_mode[i] = INTERP_LINEAR; } } - draw_set_vertex_attributes(st->draw, attrs, interp, n); + draw_set_vertex_info(st->draw, &vinfo); } @@ -519,14 +518,11 @@ st_feedback_draw_vbo(GLcontext *ctx, void st_init_draw( struct st_context *st ) { GLcontext *ctx = st->ctx; - struct vbo_context *vbo = (struct vbo_context *) ctx->swtnl_im; /* actually, not used here, but elsewhere */ create_default_attribs_buffer(st); - assert(vbo); - assert(vbo->draw_prims); - vbo->draw_prims = st_draw_vbo; + vbo_set_draw_func(ctx, st_draw_vbo); } diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index c6b5bc968f0..8d39e1bec69 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -99,9 +99,7 @@ format_size( * XXX temporary here */ GLboolean -st_get_format_info( - GLuint format, - struct pipe_format_info *pinfo ) +st_get_format_info(enum pipe_format format, struct pipe_format_info *pinfo) { if (pf_layout(format) == PIPE_FORMAT_LAYOUT_RGBAZS) { pipe_format_rgbazs_t info; @@ -109,16 +107,18 @@ st_get_format_info( info = format; #if 0 - printf( - "PIPE_FORMAT: X(%u), Y(%u), Z(%u), W(%u)\n", - info.sizeX, - info.sizeY, - info.sizeZ, - info.sizeW ); + { + char fmtname[256]; + + pf_sprint_name( fmtname, format ); + printf( + "%s\n", + fmtname ); + } #endif /* Data type */ - if (format == PIPE_FORMAT_U_A1_R5_G5_B5 || format == PIPE_FORMAT_U_R5_G6_B5) { + if (format == PIPE_FORMAT_A1R5G5B5_UNORM || format == PIPE_FORMAT_R5G6B5_UNORM) { pinfo->datatype = GL_UNSIGNED_SHORT; } else { @@ -220,10 +220,10 @@ st_get_format_info( * Return bytes per pixel for the given format. */ GLuint -st_sizeof_format(GLuint pipeFormat) +st_sizeof_format(enum pipe_format format) { struct pipe_format_info info; - if (!st_get_format_info( pipeFormat, &info )) { + if (!st_get_format_info( format, &info )) { assert( 0 ); return 0; } @@ -235,10 +235,10 @@ st_sizeof_format(GLuint pipeFormat) * Return bytes per pixel for the given format. */ GLenum -st_format_datatype(GLuint pipeFormat) +st_format_datatype(enum pipe_format format) { struct pipe_format_info info; - if (!st_get_format_info( pipeFormat, &info )) { + if (!st_get_format_info( format, &info )) { assert( 0 ); return 0; } @@ -246,14 +246,16 @@ st_format_datatype(GLuint pipeFormat) } -GLuint +enum pipe_format st_mesa_format_to_pipe_format(GLuint mesaFormat) { switch (mesaFormat) { /* fix this */ case MESA_FORMAT_ARGB8888_REV: case MESA_FORMAT_ARGB8888: - return PIPE_FORMAT_U_A8_R8_G8_B8; + return PIPE_FORMAT_A8R8G8B8_UNORM; + case MESA_FORMAT_ARGB4444: + return PIPE_FORMAT_A4R4G4B4_UNORM; case MESA_FORMAT_AL88: return PIPE_FORMAT_U_A8_L8; case MESA_FORMAT_A8: @@ -263,7 +265,7 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) case MESA_FORMAT_I8: return PIPE_FORMAT_U_I8; case MESA_FORMAT_Z16: - return PIPE_FORMAT_U_Z16; + return PIPE_FORMAT_Z16_UNORM; default: assert(0); return 0; @@ -271,20 +273,23 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) } /** - * Search list of formats for first RGBA format. + * Find an RGBA format supported by the context/winsys. */ static GLuint default_rgba_format( struct pipe_context *pipe ) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_R8_G8_B8_A8 )) { - return PIPE_FORMAT_U_R8_G8_B8_A8; - } - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) { - return PIPE_FORMAT_U_A8_R8_G8_B8; - } - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_R5_G6_B5 )) { - return PIPE_FORMAT_U_R5_G6_B5; + static const uint colorFormats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_R5G6B5_UNORM + }; + uint i; + for (i = 0; i < Elements(colorFormats); i++) { + if (pipe->is_format_supported( pipe, colorFormats[i] )) { + return colorFormats[i]; + } } return PIPE_FORMAT_NONE; } @@ -297,35 +302,36 @@ static GLuint default_deep_rgba_format( struct pipe_context *pipe ) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S_R16_G16_B16_A16 )) { - return PIPE_FORMAT_S_R16_G16_B16_A16; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_R16G16B16A16_SNORM )) { + return PIPE_FORMAT_R16G16B16A16_SNORM; } return PIPE_FORMAT_NONE; } /** - * Search list of formats for first depth/Z format. + * Find an Z format supported by the context/winsys. */ static GLuint default_depth_format( struct pipe_context *pipe ) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z16 )) { - return PIPE_FORMAT_U_Z16; - } - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z32 )) { - return PIPE_FORMAT_U_Z32; - } - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) { - return PIPE_FORMAT_S8_Z24; - } - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) { - return PIPE_FORMAT_Z24_S8; + static const uint zFormats[] = { + PIPE_FORMAT_Z16_UNORM, + PIPE_FORMAT_Z32_UNORM, + PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_Z24S8_UNORM + }; + uint i; + for (i = 0; i < Elements(zFormats); i++) { + if (pipe->is_format_supported( pipe, zFormats[i] )) { + return zFormats[i]; + } } return PIPE_FORMAT_NONE; } + /** * Choose the PIPE_FORMAT_ to use for storing a texture image based * on the user's internalFormat, format and type parameters. @@ -350,16 +356,16 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_COMPRESSED_RGBA: if (format == GL_BGRA) { if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) - return PIPE_FORMAT_U_A8_R8_G8_B8; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM )) + return PIPE_FORMAT_A8R8G8B8_UNORM; } else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 )) - return PIPE_FORMAT_U_A4_R4_G4_B4; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM )) + return PIPE_FORMAT_A4R4G4B4_UNORM; } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 )) - return PIPE_FORMAT_U_A1_R5_G5_B5; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + return PIPE_FORMAT_A1R5G5B5_UNORM; } } return default_rgba_format( pipe ); @@ -368,8 +374,8 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGB: case GL_COMPRESSED_RGB: if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_R5_G6_B5 )) - return PIPE_FORMAT_U_R5_G6_B5; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_R5G6B5_UNORM )) + return PIPE_FORMAT_R5G6B5_UNORM; } return default_rgba_format( pipe ); @@ -382,13 +388,13 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGBA4: case GL_RGBA2: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 )) - return PIPE_FORMAT_U_A4_R4_G4_B4; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM )) + return PIPE_FORMAT_A4R4G4B4_UNORM; return default_rgba_format( pipe ); case GL_RGB5_A1: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 )) - return PIPE_FORMAT_U_A1_R5_G5_B5; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + return PIPE_FORMAT_A1R5G5B5_UNORM; return default_rgba_format( pipe ); case GL_RGB8: @@ -400,8 +406,8 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 )) - return PIPE_FORMAT_U_A1_R5_G5_B5; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + return PIPE_FORMAT_A1R5G5B5_UNORM; return default_rgba_format( pipe ); case GL_ALPHA: @@ -483,18 +489,18 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, #endif case GL_DEPTH_COMPONENT16: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z16 )) - return PIPE_FORMAT_U_Z16; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z16_UNORM )) + return PIPE_FORMAT_Z16_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT24: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) - return PIPE_FORMAT_S8_Z24; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) - return PIPE_FORMAT_Z24_S8; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + return PIPE_FORMAT_S8Z24_UNORM; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + return PIPE_FORMAT_Z24S8_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT32: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z32 )) - return PIPE_FORMAT_U_Z32; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z32_UNORM )) + return PIPE_FORMAT_Z32_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT: return default_depth_format( pipe ); @@ -506,18 +512,18 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_STENCIL_INDEX16_EXT: if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_S8 )) return PIPE_FORMAT_U_S8; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) - return PIPE_FORMAT_S8_Z24; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) - return PIPE_FORMAT_Z24_S8; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + return PIPE_FORMAT_S8Z24_UNORM; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 )) - return PIPE_FORMAT_S8_Z24; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 )) - return PIPE_FORMAT_Z24_S8; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + return PIPE_FORMAT_S8Z24_UNORM; + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; default: @@ -537,7 +543,7 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, */ const struct gl_texture_format * st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat, - GLenum format, GLenum type) + GLenum format, GLenum type) { #if 0 struct intel_context *intel = intel_context(ctx); @@ -546,6 +552,8 @@ st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat, const GLboolean do32bpt = 1; #endif + (void) ctx; + switch (internalFormat) { case 4: case GL_RGBA: diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index 23abc36edff..6ccf5536f9d 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -26,13 +26,13 @@ **************************************************************************/ -#ifndef ST_CB_TEXIMAGE_H -#define ST_CB_TEXIMAGE_H +#ifndef ST_FORMAT_H +#define ST_FORMAT_H struct pipe_format_info { - GLuint format; + enum pipe_format format; GLenum base_format; GLenum datatype; GLubyte red_bits; @@ -47,21 +47,19 @@ struct pipe_format_info }; -extern GLboolean -st_get_format_info( - GLuint format, - struct pipe_format_info *pinfo ); +GLboolean +st_get_format_info(enum pipe_format format, struct pipe_format_info *pinfo); extern GLuint -st_sizeof_format(GLuint pipeFormat); +st_sizeof_format(enum pipe_format format); extern GLenum -st_format_datatype(GLuint pipeFormat); +st_format_datatype(enum pipe_format format); -extern GLuint +extern enum pipe_format st_mesa_format_to_pipe_format(GLuint mesaFormat); diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 4ae2837f0a0..8633f431b29 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -155,7 +155,7 @@ st_get_framebuffer_surface(struct st_framebuffer *stfb, uint surfIndex) { struct st_renderbuffer *strb; - assert(surfIndex <= ST_SURFACE_BACK_RIGHT); + assert(surfIndex <= ST_SURFACE_DEPTH); /* sanity checks, ST tokens should match Mesa tokens */ assert(ST_SURFACE_FRONT_LEFT == BUFFER_FRONT_LEFT); diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index ab7aa504a1d..b392edf16d2 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -30,10 +30,13 @@ * Michal Krol */ - -#include "tgsi_platform.h" -#include "pipe/tgsi/exec/tgsi_core.h" +#include "pipe/p_compiler.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/tgsi/util/tgsi_parse.h" +#include "pipe/tgsi/util/tgsi_build.h" +#include "pipe/tgsi/util/tgsi_util.h" #include "st_mesa_to_tgsi.h" +#include "shader/prog_instruction.h" #include "shader/prog_parameter.h" #define TGSI_DEBUG 0 diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.h b/src/mesa/state_tracker/st_mesa_to_tgsi.h index 941a75ab058..4cd4b96a589 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.h +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.h @@ -29,11 +29,15 @@ #ifndef ST_MESA_TO_TGSI_H #define ST_MESA_TO_TGSI_H +#include "mtypes.h" + + #if defined __cplusplus extern "C" { #endif struct tgsi_token; +struct gl_program; GLboolean tgsi_translate_mesa_program( diff --git a/src/mesa/state_tracker/st_mipmap_tree.c b/src/mesa/state_tracker/st_mipmap_tree.c deleted file mode 100644 index d1db590bee4..00000000000 --- a/src/mesa/state_tracker/st_mipmap_tree.c +++ /dev/null @@ -1,320 +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. - * - **************************************************************************/ - -#include "st_mipmap_tree.h" -#include "enums.h" - -#include "pipe/p_state.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_winsys.h" - - -#define DBG if(0) printf - -#if 0 -static GLenum -target_to_target(GLenum target) -{ - switch (target) { - case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: - return GL_TEXTURE_CUBE_MAP_ARB; - default: - return target; - } -} -#endif - -struct pipe_mipmap_tree * -st_miptree_create(struct pipe_context *pipe, - unsigned target, - GLenum internal_format, - GLuint first_level, - GLuint last_level, - GLuint width0, - GLuint height0, - GLuint depth0, GLuint cpp, GLuint compress_byte) -{ - GLboolean ok; - struct pipe_mipmap_tree *mt = calloc(sizeof(*mt), 1); - GLbitfield flags = 0x0; - - assert(target <= PIPE_TEXTURE_CUBE); - - DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(target), - _mesa_lookup_enum_by_nr(internal_format), first_level, last_level); - - mt->target = target; - mt->internal_format = internal_format; - mt->first_level = first_level; - mt->last_level = last_level; - mt->width0 = width0; - mt->height0 = height0; - mt->depth0 = depth0; - mt->cpp = compress_byte ? compress_byte : cpp; - mt->compressed = compress_byte ? 1 : 0; - mt->refcount = 1; - - ok = pipe->mipmap_tree_layout(pipe, mt); - if (ok) { - /* note: it's OK to pass 'pitch' as 'width' here: */ - mt->region = pipe->winsys->region_alloc(pipe->winsys, mt->cpp, mt->pitch, - mt->total_height, flags); - mt->pitch = mt->region->pitch; /*XXX NEW */ - } - - if (!mt->region) { - free(mt); - return NULL; - } - - return mt; -} - - -void -st_miptree_reference(struct pipe_mipmap_tree **dst, - struct pipe_mipmap_tree *src) -{ - src->refcount++; - *dst = src; - DBG("%s %p refcount now %d\n", __FUNCTION__, (void *) src, src->refcount); -} - -void -st_miptree_release(struct pipe_context *pipe, - struct pipe_mipmap_tree **mt) -{ - if (!*mt) - return; - - DBG("%s %p refcount will be %d\n", - __FUNCTION__, (void *) *mt, (*mt)->refcount - 1); - if (--(*mt)->refcount <= 0) { - GLuint i; - - DBG("%s deleting %p\n", __FUNCTION__, (void *) *mt); - - pipe->winsys->region_release(pipe->winsys, &((*mt)->region)); - - for (i = 0; i < MAX_TEXTURE_LEVELS; i++) - if ((*mt)->level[i].image_offset) - free((*mt)->level[i].image_offset); - - free(*mt); - } - *mt = NULL; -} - - - - -/* Can the image be pulled into a unified mipmap tree. This mirrors - * the completeness test in a lot of ways. - * - * Not sure whether I want to pass gl_texture_image here. - */ -GLboolean -st_miptree_match_image(struct pipe_mipmap_tree *mt, - struct gl_texture_image *image, - GLuint face, GLuint level) -{ - /* Images with borders are never pulled into mipmap trees. - */ - if (image->Border) - return GL_FALSE; - - if (image->InternalFormat != mt->internal_format || - image->IsCompressed != mt->compressed) - return GL_FALSE; - - /* Test image dimensions against the base level image adjusted for - * minification. This will also catch images not present in the - * tree, changed targets, etc. - */ - if (image->Width != mt->level[level].width || - image->Height != mt->level[level].height || - image->Depth != mt->level[level].depth) - return GL_FALSE; - - return GL_TRUE; -} - - -/* Although we use the image_offset[] array to store relative offsets - * to cube faces, Mesa doesn't know anything about this and expects - * each cube face to be treated as a separate image. - * - * These functions present that view to mesa: - */ -const GLuint * -st_miptree_depth_offsets(struct pipe_mipmap_tree *mt, GLuint level) -{ - static const GLuint zero = 0; - - if (mt->target != PIPE_TEXTURE_3D || mt->level[level].nr_images == 1) - return &zero; - else - return mt->level[level].image_offset; -} - - -/** - * Return the offset to the given mipmap texture image within the - * texture memory buffer, in bytes. - */ -GLuint -st_miptree_image_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level) -{ - if (mt->target == PIPE_TEXTURE_CUBE) - return (mt->level[level].level_offset + - mt->level[level].image_offset[face] * mt->cpp); - else - return mt->level[level].level_offset; -} - - -GLuint -st_miptree_texel_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level, - GLuint col, GLuint row, GLuint img) -{ - GLuint imgOffset = st_miptree_image_offset(mt, face, level); - - return imgOffset + row * (mt->pitch + col) * mt->cpp; -} - - - -/** - * Map a teximage in a mipmap tree. - * \param row_stride returns row stride in bytes - * \param image_stride returns image stride in bytes (for 3D textures). - * \return address of mapping - */ -GLubyte * -st_miptree_image_map(struct pipe_context *pipe, - struct pipe_mipmap_tree * mt, - GLuint face, - GLuint level, - GLuint * row_stride, GLuint * image_offsets) -{ - GLubyte *ptr; - DBG("%s \n", __FUNCTION__); - - if (row_stride) - *row_stride = mt->pitch * mt->cpp; - - if (image_offsets) - memcpy(image_offsets, mt->level[level].image_offset, - mt->level[level].depth * sizeof(GLuint)); - - ptr = pipe->region_map(pipe, mt->region); - - return ptr + st_miptree_image_offset(mt, face, level); -} - -void -st_miptree_image_unmap(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt) -{ - DBG("%s\n", __FUNCTION__); - pipe->region_unmap(pipe, mt->region); -} - - - -/* Upload data for a particular image. - */ -void -st_miptree_image_data(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, - GLuint level, - void *src, - GLuint src_row_pitch, GLuint src_image_pitch) -{ - GLuint depth = dst->level[level].depth; - GLuint dst_offset = st_miptree_image_offset(dst, face, level); - const GLuint *dst_depth_offset = st_miptree_depth_offsets(dst, level); - GLuint i; - GLuint height = 0; - const GLubyte *srcUB = src; - - DBG("%s\n", __FUNCTION__); - for (i = 0; i < depth; i++) { - height = dst->level[level].height; - if(dst->compressed) - height /= 4; - pipe->region_data(pipe, dst->region, - dst_offset + dst_depth_offset[i], /* dst_offset */ - 0, 0, /* dstx, dsty */ - srcUB, - src_row_pitch, - 0, 0, /* source x, y */ - dst->level[level].width, height); /* width, height */ - - srcUB += src_image_pitch * dst->cpp; - } -} - -/* Copy mipmap image between trees - */ -void -st_miptree_image_copy(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, - struct pipe_mipmap_tree *src) -{ - GLuint width = src->level[level].width; - GLuint height = src->level[level].height; - GLuint depth = src->level[level].depth; - GLuint dst_offset = st_miptree_image_offset(dst, face, level); - GLuint src_offset = st_miptree_image_offset(src, face, level); - const GLuint *dst_depth_offset = st_miptree_depth_offsets(dst, level); - const GLuint *src_depth_offset = st_miptree_depth_offsets(src, level); - GLuint i; - - if (dst->compressed) - height /= 4; - for (i = 0; i < depth; i++) { - pipe->region_copy(pipe, - dst->region, dst_offset + dst_depth_offset[i], - 0, 0, /* destX, Y */ - src->region, src_offset + src_depth_offset[i], - 0, 0, /* srcX, Y */ - width, height); - } - -} diff --git a/src/mesa/state_tracker/st_mipmap_tree.h b/src/mesa/state_tracker/st_mipmap_tree.h deleted file mode 100644 index 3e7fd7fa0ce..00000000000 --- a/src/mesa/state_tracker/st_mipmap_tree.h +++ /dev/null @@ -1,118 +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. - * - **************************************************************************/ - -#ifndef ST_MIPMAP_TREE_H -#define ST_MIPMAP_TREE_H - - -#include "main/mtypes.h" - -struct pipe_context; -struct pipe_mipmap_tree; -struct pipe_region; - - -extern struct pipe_mipmap_tree * -st_miptree_create(struct pipe_context *pipe, - GLenum target, - GLenum internal_format, - GLuint first_level, - GLuint last_level, - GLuint width0, - GLuint height0, - GLuint depth0, - GLuint cpp, - GLuint compress_byte); - -extern void -st_miptree_reference(struct pipe_mipmap_tree **dst, - struct pipe_mipmap_tree *src); - -extern void -st_miptree_release(struct pipe_context *pipe, struct pipe_mipmap_tree **mt); - - -/* Check if an image fits an existing mipmap tree layout - */ -extern GLboolean -st_miptree_match_image(struct pipe_mipmap_tree *mt, - struct gl_texture_image *image, - GLuint face, GLuint level); - -/* Return a pointer to an image within a tree. Return image stride as - * well. - */ -extern GLubyte * -st_miptree_image_map(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, - GLuint face, GLuint level, - GLuint * row_stride, GLuint * image_stride); - -extern void -st_miptree_image_unmap(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt); - - -/* Return pointers to each 2d slice within an image. Indexed by depth - * value. - */ -extern const GLuint * -st_miptree_depth_offsets(struct pipe_mipmap_tree *mt, GLuint level); - - -/* Return the linear offset of an image relative to the start of the - * tree: - */ -extern GLuint -st_miptree_image_offset(const struct pipe_mipmap_tree *mt, - GLuint face, GLuint level); - -extern GLuint -st_miptree_texel_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level, - GLuint col, GLuint row, GLuint img); - - -/* Upload an image into a tree - */ -extern void -st_miptree_image_data(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, void *src, - GLuint src_row_pitch, GLuint src_image_pitch); - - -/* Copy an image between two trees - */ -extern void -st_miptree_image_copy(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, - struct pipe_mipmap_tree *src); - - -#endif diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index ce5384671cd..e64bf14d56a 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -36,8 +36,9 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" #include "pipe/draw/draw_context.h" -#include "pipe/tgsi/exec/tgsi_core.h" +#include "pipe/tgsi/util/tgsi_dump.h" #include "st_context.h" #include "st_cache.h" diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 51877af8da9..049f9f659fa 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -35,7 +35,7 @@ #define ST_PROGRAM_H #include "mtypes.h" -#include "pipe/tgsi/exec/tgsi_token.h" +#include "pipe/p_shader_tokens.h" #include "x86/rtasm/x86sse.h" diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 408e1927e5b..307635936bc 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -35,6 +35,7 @@ #define ST_SURFACE_BACK_LEFT 1 #define ST_SURFACE_FRONT_RIGHT 2 #define ST_SURFACE_BACK_RIGHT 3 +#define ST_SURFACE_DEPTH 8 struct st_context; diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c new file mode 100644 index 00000000000..1ec45148736 --- /dev/null +++ b/src/mesa/state_tracker/st_texture.c @@ -0,0 +1,275 @@ +/************************************************************************** + * + * 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 "st_context.h" +#include "st_format.h" +#include "st_texture.h" +#include "enums.h" + +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_inlines.h" +#include "pipe/p_util.h" +#include "pipe/p_inlines.h" +#include "pipe/p_winsys.h" + + +#define DBG if(0) printf + +#if 0 +static GLenum +target_to_target(GLenum target) +{ + switch (target) { + case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: + return GL_TEXTURE_CUBE_MAP_ARB; + default: + return target; + } +} +#endif + +struct pipe_texture * +st_texture_create(struct st_context *st, + unsigned target, + unsigned format, + GLenum internal_format, + GLuint first_level, + GLuint last_level, + GLuint width0, + GLuint height0, + GLuint depth0, + GLuint compress_byte) +{ + struct pipe_texture *pt = CALLOC_STRUCT(pipe_texture); + + assert(target <= PIPE_TEXTURE_CUBE); + + DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, + _mesa_lookup_enum_by_nr(target), + _mesa_lookup_enum_by_nr(internal_format), first_level, last_level); + + if (!pt) + return NULL; + + assert(format); + + pt->target = target; + pt->format = format; + pt->internal_format = internal_format; + pt->first_level = first_level; + pt->last_level = last_level; + pt->width[0] = width0; + pt->height[0] = height0; + pt->depth[0] = depth0; + pt->compressed = compress_byte ? 1 : 0; + pt->cpp = pt->compressed ? compress_byte : st_sizeof_format(format); + pt->refcount = 1; + + st->pipe->texture_create(st->pipe, &pt); + + return pt; +} + + + + +/* Can the image be pulled into a unified mipmap texture. This mirrors + * the completeness test in a lot of ways. + * + * Not sure whether I want to pass gl_texture_image here. + */ +GLboolean +st_texture_match_image(struct pipe_texture *pt, + struct gl_texture_image *image, + GLuint face, GLuint level) +{ + /* Images with borders are never pulled into mipmap textures. + */ + if (image->Border) + return GL_FALSE; + + if (image->InternalFormat != pt->internal_format || + image->IsCompressed != pt->compressed) + return GL_FALSE; + + /* Test image dimensions against the base level image adjusted for + * minification. This will also catch images not present in the + * texture, changed targets, etc. + */ + if (image->Width != pt->width[level] || + image->Height != pt->height[level] || + image->Depth != pt->depth[level]) + return GL_FALSE; + + return GL_TRUE; +} + + +#if 000 +/* Although we use the image_offset[] array to store relative offsets + * to cube faces, Mesa doesn't know anything about this and expects + * each cube face to be treated as a separate image. + * + * These functions present that view to mesa: + */ +const GLuint * +st_texture_depth_offsets(struct pipe_texture *pt, GLuint level) +{ + static const GLuint zero = 0; + + if (pt->target != PIPE_TEXTURE_3D || pt->level[level].nr_images == 1) + return &zero; + else + return pt->level[level].image_offset; +} + + +/** + * Return the offset to the given mipmap texture image within the + * texture memory buffer, in bytes. + */ +GLuint +st_texture_image_offset(const struct pipe_texture * pt, + GLuint face, GLuint level) +{ + if (pt->target == PIPE_TEXTURE_CUBE) + return (pt->level[level].level_offset + + pt->level[level].image_offset[face] * pt->cpp); + else + return pt->level[level].level_offset; +} +#endif + + +/** + * Map a teximage in a mipmap texture. + * \param row_stride returns row stride in bytes + * \param image_stride returns image stride in bytes (for 3D textures). + * \return address of mapping + */ +GLubyte * +st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, + GLuint zoffset) +{ + struct pipe_texture *pt = stImage->pt; + DBG("%s \n", __FUNCTION__); + + stImage->surface = st->pipe->get_tex_surface(st->pipe, pt, stImage->face, + stImage->level, zoffset); + + return pipe_surface_map(stImage->surface); +} + +void +st_texture_image_unmap(struct st_texture_image *stImage) +{ + DBG("%s\n", __FUNCTION__); + + pipe_surface_unmap(stImage->surface); + + pipe_surface_reference(&stImage->surface, NULL); +} + + + +/* Upload data for a particular image. + */ +void +st_texture_image_data(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, + GLuint level, + void *src, + GLuint src_row_pitch, GLuint src_image_pitch) +{ + GLuint depth = dst->depth[level]; + GLuint i; + GLuint height = 0; + const GLubyte *srcUB = src; + struct pipe_surface *dst_surface; + + DBG("%s\n", __FUNCTION__); + for (i = 0; i < depth; i++) { + height = dst->height[level]; + if(dst->compressed) + height /= 4; + + dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + + pipe->surface_data(pipe, dst_surface, + 0, 0, /* dstx, dsty */ + srcUB, + src_row_pitch, + 0, 0, /* source x, y */ + dst->width[level], height); /* width, height */ + + pipe_surface_reference(&dst_surface, NULL); + + srcUB += src_image_pitch * dst->cpp; + } +} + +/* Copy mipmap image between textures + */ +void +st_texture_image_copy(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, + struct pipe_texture *src) +{ + GLuint width = src->width[level]; + GLuint height = src->height[level]; + GLuint depth = src->depth[level]; + struct pipe_surface *src_surface; + struct pipe_surface *dst_surface; + GLuint i; + + if (dst->compressed) + height /= 4; + for (i = 0; i < depth; i++) { + dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + src_surface = pipe->get_tex_surface(pipe, src, face, level, i); + + pipe->surface_copy(pipe, + dst_surface, + 0, 0, /* destX, Y */ + src_surface, + 0, 0, /* srcX, Y */ + width, height); + + pipe_surface_reference(&dst_surface, NULL); + pipe_surface_reference(&src_surface, NULL); + } + +} diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h new file mode 100644 index 00000000000..f49d91a0692 --- /dev/null +++ b/src/mesa/state_tracker/st_texture.h @@ -0,0 +1,108 @@ +/************************************************************************** + * + * 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 ST_TEXTURE_H +#define ST_TEXTURE_H + + +#include "main/mtypes.h" + +struct pipe_context; +struct pipe_texture; +struct pipe_region; + + +extern struct pipe_texture * +st_texture_create(struct st_context *st, + unsigned target, + unsigned format, + GLenum internal_format, + GLuint first_level, + GLuint last_level, + GLuint width0, + GLuint height0, + GLuint depth0, + GLuint compress_byte); + + +/* Check if an image fits an existing texture + */ +extern GLboolean +st_texture_match_image(struct pipe_texture *pt, + struct gl_texture_image *image, + GLuint face, GLuint level); + +/* Return a pointer to an image within a texture. Return image stride as + * well. + */ +extern GLubyte * +st_texture_image_map(struct st_context *st, + struct st_texture_image *stImage, + GLuint zoffset); + +extern void +st_texture_image_unmap(struct st_texture_image *stImage); + + +/* Return pointers to each 2d slice within an image. Indexed by depth + * value. + */ +extern const GLuint * +st_texture_depth_offsets(struct pipe_texture *pt, GLuint level); + + +/* Return the linear offset of an image relative to the start of its region: + */ +extern GLuint +st_texture_image_offset(const struct pipe_texture *pt, + GLuint face, GLuint level); + +extern GLuint +st_texture_texel_offset(const struct pipe_texture * pt, + GLuint face, GLuint level, + GLuint col, GLuint row, GLuint img); + + +/* Upload an image into a texture + */ +extern void +st_texture_image_data(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, void *src, + GLuint src_row_pitch, GLuint src_image_pitch); + + +/* Copy an image between two textures + */ +extern void +st_texture_image_copy(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, + struct pipe_texture *src); + + +#endif diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c index b87452d2eb4..0ace5c2d6f1 100644 --- a/src/mesa/tnl/t_context.c +++ b/src/mesa/tnl/t_context.c @@ -78,6 +78,9 @@ _tnl_CreateContext( GLcontext *ctx ) tnl->nr_blocks = 0; + /* plug in the VBO drawing function */ + vbo_set_draw_func(ctx, _tnl_draw_prims); + return GL_TRUE; } diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h index 4c51b44cdad..79d33d09c16 100644 --- a/src/mesa/vbo/vbo.h +++ b/src/mesa/vbo/vbo.h @@ -117,4 +117,7 @@ void vbo_rebase_prims( GLcontext *ctx, void vbo_use_buffer_objects(GLcontext *ctx); +void vbo_set_draw_func(GLcontext *ctx, vbo_draw_func func); + + #endif diff --git a/src/mesa/vbo/vbo_context.c b/src/mesa/vbo/vbo_context.c index ad4556c500b..60d0b76ab62 100644 --- a/src/mesa/vbo/vbo_context.c +++ b/src/mesa/vbo/vbo_context.c @@ -31,6 +31,7 @@ #include "vbo.h" #include "vbo_context.h" +#if 0 /* Reach out and grab this to use as the default: */ extern void _tnl_draw_prims( GLcontext *ctx, @@ -40,6 +41,7 @@ extern void _tnl_draw_prims( GLcontext *ctx, const struct _mesa_index_buffer *ib, GLuint min_index, GLuint max_index ); +#endif @@ -214,7 +216,9 @@ GLboolean _vbo_CreateContext( GLcontext *ctx ) /* By default: */ +#if 0 /* dead - see vbo_set_draw_func() */ vbo->draw_prims = _tnl_draw_prims; +#endif /* Hook our functions into exec and compile dispatch tables. These * will pretty much be permanently installed, which means that the @@ -245,3 +249,11 @@ void _vbo_DestroyContext( GLcontext *ctx ) FREE(vbo_context(ctx)); ctx->swtnl_im = NULL; } + + +void vbo_set_draw_func(GLcontext *ctx, vbo_draw_func func) +{ + struct vbo_context *vbo = vbo_context(ctx); + vbo->draw_prims = func; +} +