- /**************************************************************************\r
- * \r
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.\r
- * All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the\r
- * "Software"), to deal in the Software without restriction, including\r
- * without limitation the rights to use, copy, modify, merge, publish,\r
- * distribute, sub license, and/or sell copies of the Software, and to\r
- * permit persons to whom the Software is furnished to do so, subject to\r
- * the following conditions:\r
- * \r
- * The above copyright notice and this permission notice (including the\r
- * next paragraph) shall be included in all copies or substantial portions\r
- * of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\r
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR\r
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- * \r
- **************************************************************************/\r
-\r
-#ifndef I915_CONTEXT_H\r
-#define I915_CONTEXT_H\r
-\r
-\r
-#include "pipe/p_context.h"\r
-#include "pipe/p_defines.h"\r
-#include "pipe/p_state.h"\r
-\r
-#include "draw/draw_vertex.h"\r
-\r
-#include "tgsi/util/tgsi_scan.h"\r
-\r
-\r
-#define I915_TEX_UNITS 8\r
-\r
-#define I915_DYNAMIC_MODES4 0\r
-#define I915_DYNAMIC_DEPTHSCALE_0 1 /* just the header */\r
-#define I915_DYNAMIC_DEPTHSCALE_1 2 \r
-#define I915_DYNAMIC_IAB 3\r
-#define I915_DYNAMIC_BC_0 4 /* just the header */\r
-#define I915_DYNAMIC_BC_1 5\r
-#define I915_DYNAMIC_BFO_0 6 \r
-#define I915_DYNAMIC_BFO_1 7\r
-#define I915_DYNAMIC_STP_0 8 \r
-#define I915_DYNAMIC_STP_1 9 \r
-#define I915_DYNAMIC_SC_ENA_0 10 \r
-#define I915_DYNAMIC_SC_RECT_0 11 \r
-#define I915_DYNAMIC_SC_RECT_1 12 \r
-#define I915_DYNAMIC_SC_RECT_2 13 \r
-#define I915_MAX_DYNAMIC 14\r
-\r
-\r
-#define I915_IMMEDIATE_S0 0\r
-#define I915_IMMEDIATE_S1 1\r
-#define I915_IMMEDIATE_S2 2\r
-#define I915_IMMEDIATE_S3 3\r
-#define I915_IMMEDIATE_S4 4\r
-#define I915_IMMEDIATE_S5 5\r
-#define I915_IMMEDIATE_S6 6\r
-#define I915_IMMEDIATE_S7 7\r
-#define I915_MAX_IMMEDIATE 8\r
-\r
-/* These must mach the order of LI0_STATE_* bits, as they will be used\r
- * to generate hardware packets:\r
- */\r
-#define I915_CACHE_STATIC 0 \r
-#define I915_CACHE_DYNAMIC 1 /* handled specially */\r
-#define I915_CACHE_SAMPLER 2\r
-#define I915_CACHE_MAP 3\r
-#define I915_CACHE_PROGRAM 4\r
-#define I915_CACHE_CONSTANTS 5\r
-#define I915_MAX_CACHE 6\r
-\r
-#define I915_MAX_CONSTANT 32\r
-\r
-\r
-/** See constant_flags[] below */\r
-#define I915_CONSTFLAG_USER 0x1f\r
-\r
-\r
-/**\r
- * Subclass of pipe_shader_state\r
- */\r
-struct i915_fragment_shader\r
-{\r
- struct pipe_shader_state state;\r
-\r
- struct tgsi_shader_info info;\r
-\r
- uint *program;\r
- uint program_len;\r
-\r
- /**\r
- * constants introduced during translation.\r
- * These are placed at the end of the constant buffer and grow toward\r
- * the beginning (eg: slot 31, 30 29, ...)\r
- * User-provided constants start at 0.\r
- * This allows both types of constants to co-exist (until there's too many)\r
- * and doesn't require regenerating/changing the fragment program to\r
- * shuffle constants around.\r
- */\r
- uint num_constants;\r
- float constants[I915_MAX_CONSTANT][4];\r
-\r
- /**\r
- * Status of each constant\r
- * if I915_CONSTFLAG_PARAM, the value must be taken from the corresponding\r
- * slot of the user's constant buffer. (set by pipe->set_constant_buffer())\r
- * Else, the bitmask indicates which components are occupied by immediates.\r
- */\r
- ubyte constant_flags[I915_MAX_CONSTANT];\r
-};\r
-\r
-\r
-struct i915_cache_context;\r
-\r
-/* Use to calculate differences between state emitted to hardware and\r
- * current driver-calculated state. \r
- */\r
-struct i915_state \r
-{\r
- unsigned immediate[I915_MAX_IMMEDIATE];\r
- unsigned dynamic[I915_MAX_DYNAMIC];\r
-\r
- float constants[PIPE_SHADER_TYPES][I915_MAX_CONSTANT][4];\r
- /** number of constants passed in through a constant buffer */\r
- uint num_user_constants[PIPE_SHADER_TYPES];\r
-\r
- /* texture sampler state */\r
- unsigned sampler[I915_TEX_UNITS][3];\r
- unsigned sampler_enable_flags;\r
- unsigned sampler_enable_nr;\r
-\r
- /* texture image buffers */\r
- unsigned texbuffer[I915_TEX_UNITS][2];\r
-\r
- /** Describes the current hardware vertex layout */\r
- struct vertex_info vertex_info;\r
- \r
- unsigned id; /* track lost context events */\r
-};\r
-\r
-struct i915_blend_state {\r
- unsigned iab;\r
- unsigned modes4;\r
- unsigned LIS5;\r
- unsigned LIS6;\r
-};\r
-\r
-struct i915_depth_stencil_state {\r
- unsigned stencil_modes4;\r
- unsigned bfo[2];\r
- unsigned stencil_LIS5;\r
- unsigned depth_LIS6;\r
-};\r
-\r
-struct i915_rasterizer_state {\r
- int light_twoside : 1;\r
- unsigned st;\r
- enum interp_mode color_interp;\r
-\r
- unsigned LIS4;\r
- unsigned LIS7;\r
- unsigned sc[1];\r
-\r
- const struct pipe_rasterizer_state *templ;\r
-\r
- union { float f; unsigned u; } ds[2];\r
-};\r
-\r
-struct i915_sampler_state {\r
- unsigned state[3];\r
- const struct pipe_sampler_state *templ;\r
-};\r
-\r
-\r
-struct i915_texture {\r
- struct pipe_texture base;\r
-\r
- /* Derived from the above:\r
- */\r
- unsigned pitch;\r
- unsigned depth_pitch; /* per-image on i945? */\r
- unsigned total_height;\r
-\r
- unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS];\r
-\r
- /* Explicitly store the offset of each image for each cube face or\r
- * depth value. Pretty much have to accept that hardware formats\r
- * are going to be so diverse that there is no unified way to\r
- * compute the offsets of depth/cube images within a mipmap level,\r
- * so have to store them as a lookup table:\r
- */\r
- unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */\r
-\r
- /* Includes image offset tables:\r
- */\r
- unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS];\r
-\r
- /* The data is held here:\r
- */\r
- struct pipe_buffer *buffer;\r
-};\r
-\r
-struct i915_context\r
-{\r
- struct pipe_context pipe;\r
- struct i915_winsys *winsys;\r
- struct draw_context *draw;\r
-\r
- /* The most recent drawing state as set by the driver:\r
- */\r
- const struct i915_blend_state *blend;\r
- const struct i915_sampler_state *sampler[PIPE_MAX_SAMPLERS];\r
- const struct i915_depth_stencil_state *depth_stencil;\r
- const struct i915_rasterizer_state *rasterizer;\r
-\r
- struct i915_fragment_shader *fs;\r
-\r
- struct pipe_blend_color blend_color;\r
- struct pipe_clip_state clip;\r
- struct pipe_constant_buffer constants[PIPE_SHADER_TYPES];\r
- struct pipe_framebuffer_state framebuffer;\r
- struct pipe_poly_stipple poly_stipple;\r
- struct pipe_scissor_state scissor;\r
- struct i915_texture *texture[PIPE_MAX_SAMPLERS];\r
- struct pipe_viewport_state viewport;\r
- struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];\r
-\r
- unsigned dirty;\r
-\r
- unsigned num_samplers;\r
- unsigned num_textures;\r
- unsigned num_vertex_elements;\r
- unsigned num_vertex_buffers;\r
-\r
- unsigned *batch_start;\r
-\r
- /** Vertex buffer */\r
- struct pipe_buffer *vbo;\r
-\r
- struct i915_state current;\r
- unsigned hardware_dirty;\r
- \r
- unsigned debug;\r
-};\r
-\r
-/* A flag for each state_tracker state object:\r
- */\r
-#define I915_NEW_VIEWPORT 0x1\r
-#define I915_NEW_RASTERIZER 0x2\r
-#define I915_NEW_FS 0x4\r
-#define I915_NEW_BLEND 0x8\r
-#define I915_NEW_CLIP 0x10\r
-#define I915_NEW_SCISSOR 0x20\r
-#define I915_NEW_STIPPLE 0x40\r
-#define I915_NEW_FRAMEBUFFER 0x80\r
-#define I915_NEW_ALPHA_TEST 0x100\r
-#define I915_NEW_DEPTH_STENCIL 0x200\r
-#define I915_NEW_SAMPLER 0x400\r
-#define I915_NEW_TEXTURE 0x800\r
-#define I915_NEW_CONSTANTS 0x1000\r
-#define I915_NEW_VBO 0x2000\r
-#define I915_NEW_VS 0x4000\r
-\r
-\r
-/* Driver's internally generated state flags:\r
- */\r
-#define I915_NEW_VERTEX_FORMAT 0x10000\r
-\r
-\r
-/* Dirty flags for hardware emit\r
- */\r
-#define I915_HW_STATIC (1<<I915_CACHE_STATIC)\r
-#define I915_HW_DYNAMIC (1<<I915_CACHE_DYNAMIC)\r
-#define I915_HW_SAMPLER (1<<I915_CACHE_SAMPLER)\r
-#define I915_HW_MAP (1<<I915_CACHE_MAP)\r
-#define I915_HW_PROGRAM (1<<I915_CACHE_PROGRAM)\r
-#define I915_HW_CONSTANTS (1<<I915_CACHE_CONSTANTS)\r
-#define I915_HW_IMMEDIATE (1<<(I915_MAX_CACHE+0))\r
-#define I915_HW_INVARIENT (1<<(I915_MAX_CACHE+1))\r
-\r
-\r
-/***********************************************************************\r
- * i915_prim_emit.c: \r
- */\r
-struct draw_stage *i915_draw_render_stage( struct i915_context *i915 );\r
-\r
-\r
-/***********************************************************************\r
- * i915_prim_vbuf.c: \r
- */\r
-struct draw_stage *i915_draw_vbuf_stage( struct i915_context *i915 );\r
-\r
-\r
-/***********************************************************************\r
- * i915_state_emit.c: \r
- */\r
-void i915_emit_hardware_state(struct i915_context *i915 );\r
-\r
-\r
-\r
-/***********************************************************************\r
- * i915_clear.c: \r
- */\r
-void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps,\r
- unsigned clearValue);\r
-\r
-\r
-/***********************************************************************\r
- * i915_surface.c: \r
- */\r
-void i915_init_surface_functions( struct i915_context *i915 );\r
-\r
-void i915_init_state_functions( struct i915_context *i915 );\r
-void i915_init_flush_functions( struct i915_context *i915 );\r
-void i915_init_string_functions( struct i915_context *i915 );\r
-\r
-\r
-\r
-\r
-/***********************************************************************\r
- * Inline conversion functions. These are better-typed than the\r
- * macros used previously:\r
- */\r
-static INLINE struct i915_context *\r
-i915_context( struct pipe_context *pipe )\r
-{\r
- return (struct i915_context *)pipe;\r
-}\r
-\r
-\r
-\r
-#endif\r
+ /**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef I915_CONTEXT_H
+#define I915_CONTEXT_H
+
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_state.h"
+
+#include "draw/draw_vertex.h"
+
+#include "tgsi/util/tgsi_scan.h"
+
+
+#define I915_TEX_UNITS 8
+
+#define I915_DYNAMIC_MODES4 0
+#define I915_DYNAMIC_DEPTHSCALE_0 1 /* just the header */
+#define I915_DYNAMIC_DEPTHSCALE_1 2
+#define I915_DYNAMIC_IAB 3
+#define I915_DYNAMIC_BC_0 4 /* just the header */
+#define I915_DYNAMIC_BC_1 5
+#define I915_DYNAMIC_BFO_0 6
+#define I915_DYNAMIC_BFO_1 7
+#define I915_DYNAMIC_STP_0 8
+#define I915_DYNAMIC_STP_1 9
+#define I915_DYNAMIC_SC_ENA_0 10
+#define I915_DYNAMIC_SC_RECT_0 11
+#define I915_DYNAMIC_SC_RECT_1 12
+#define I915_DYNAMIC_SC_RECT_2 13
+#define I915_MAX_DYNAMIC 14
+
+
+#define I915_IMMEDIATE_S0 0
+#define I915_IMMEDIATE_S1 1
+#define I915_IMMEDIATE_S2 2
+#define I915_IMMEDIATE_S3 3
+#define I915_IMMEDIATE_S4 4
+#define I915_IMMEDIATE_S5 5
+#define I915_IMMEDIATE_S6 6
+#define I915_IMMEDIATE_S7 7
+#define I915_MAX_IMMEDIATE 8
+
+/* These must mach the order of LI0_STATE_* bits, as they will be used
+ * to generate hardware packets:
+ */
+#define I915_CACHE_STATIC 0
+#define I915_CACHE_DYNAMIC 1 /* handled specially */
+#define I915_CACHE_SAMPLER 2
+#define I915_CACHE_MAP 3
+#define I915_CACHE_PROGRAM 4
+#define I915_CACHE_CONSTANTS 5
+#define I915_MAX_CACHE 6
+
+#define I915_MAX_CONSTANT 32
+
+
+/** See constant_flags[] below */
+#define I915_CONSTFLAG_USER 0x1f
+
+
+/**
+ * Subclass of pipe_shader_state
+ */
+struct i915_fragment_shader
+{
+ struct pipe_shader_state state;
+
+ struct tgsi_shader_info info;
+
+ uint *program;
+ uint program_len;
+
+ /**
+ * constants introduced during translation.
+ * These are placed at the end of the constant buffer and grow toward
+ * the beginning (eg: slot 31, 30 29, ...)
+ * User-provided constants start at 0.
+ * This allows both types of constants to co-exist (until there's too many)
+ * and doesn't require regenerating/changing the fragment program to
+ * shuffle constants around.
+ */
+ uint num_constants;
+ float constants[I915_MAX_CONSTANT][4];
+
+ /**
+ * Status of each constant
+ * if I915_CONSTFLAG_PARAM, the value must be taken from the corresponding
+ * slot of the user's constant buffer. (set by pipe->set_constant_buffer())
+ * Else, the bitmask indicates which components are occupied by immediates.
+ */
+ ubyte constant_flags[I915_MAX_CONSTANT];
+};
+
+
+struct i915_cache_context;
+
+/* Use to calculate differences between state emitted to hardware and
+ * current driver-calculated state.
+ */
+struct i915_state
+{
+ unsigned immediate[I915_MAX_IMMEDIATE];
+ unsigned dynamic[I915_MAX_DYNAMIC];
+
+ float constants[PIPE_SHADER_TYPES][I915_MAX_CONSTANT][4];
+ /** number of constants passed in through a constant buffer */
+ uint num_user_constants[PIPE_SHADER_TYPES];
+
+ /* texture sampler state */
+ unsigned sampler[I915_TEX_UNITS][3];
+ unsigned sampler_enable_flags;
+ unsigned sampler_enable_nr;
+
+ /* texture image buffers */
+ unsigned texbuffer[I915_TEX_UNITS][2];
+
+ /** Describes the current hardware vertex layout */
+ struct vertex_info vertex_info;
+
+ unsigned id; /* track lost context events */
+};
+
+struct i915_blend_state {
+ unsigned iab;
+ unsigned modes4;
+ unsigned LIS5;
+ unsigned LIS6;
+};
+
+struct i915_depth_stencil_state {
+ unsigned stencil_modes4;
+ unsigned bfo[2];
+ unsigned stencil_LIS5;
+ unsigned depth_LIS6;
+};
+
+struct i915_rasterizer_state {
+ int light_twoside : 1;
+ unsigned st;
+ enum interp_mode color_interp;
+
+ unsigned LIS4;
+ unsigned LIS7;
+ unsigned sc[1];
+
+ const struct pipe_rasterizer_state *templ;
+
+ union { float f; unsigned u; } ds[2];
+};
+
+struct i915_sampler_state {
+ unsigned state[3];
+ const struct pipe_sampler_state *templ;
+};
+
+
+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 *buffer;
+};
+
+struct i915_context
+{
+ struct pipe_context pipe;
+ struct i915_winsys *winsys;
+ struct draw_context *draw;
+
+ /* The most recent drawing state as set by the driver:
+ */
+ const struct i915_blend_state *blend;
+ const struct i915_sampler_state *sampler[PIPE_MAX_SAMPLERS];
+ const struct i915_depth_stencil_state *depth_stencil;
+ const struct i915_rasterizer_state *rasterizer;
+
+ struct i915_fragment_shader *fs;
+
+ struct pipe_blend_color blend_color;
+ struct pipe_clip_state clip;
+ struct pipe_constant_buffer constants[PIPE_SHADER_TYPES];
+ struct pipe_framebuffer_state framebuffer;
+ struct pipe_poly_stipple poly_stipple;
+ struct pipe_scissor_state scissor;
+ struct i915_texture *texture[PIPE_MAX_SAMPLERS];
+ struct pipe_viewport_state viewport;
+ struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
+
+ unsigned dirty;
+
+ unsigned num_samplers;
+ unsigned num_textures;
+ unsigned num_vertex_elements;
+ unsigned num_vertex_buffers;
+
+ unsigned *batch_start;
+
+ /** Vertex buffer */
+ struct pipe_buffer *vbo;
+
+ struct i915_state current;
+ unsigned hardware_dirty;
+
+ unsigned debug;
+};
+
+/* A flag for each state_tracker state object:
+ */
+#define I915_NEW_VIEWPORT 0x1
+#define I915_NEW_RASTERIZER 0x2
+#define I915_NEW_FS 0x4
+#define I915_NEW_BLEND 0x8
+#define I915_NEW_CLIP 0x10
+#define I915_NEW_SCISSOR 0x20
+#define I915_NEW_STIPPLE 0x40
+#define I915_NEW_FRAMEBUFFER 0x80
+#define I915_NEW_ALPHA_TEST 0x100
+#define I915_NEW_DEPTH_STENCIL 0x200
+#define I915_NEW_SAMPLER 0x400
+#define I915_NEW_TEXTURE 0x800
+#define I915_NEW_CONSTANTS 0x1000
+#define I915_NEW_VBO 0x2000
+#define I915_NEW_VS 0x4000
+
+
+/* Driver's internally generated state flags:
+ */
+#define I915_NEW_VERTEX_FORMAT 0x10000
+
+
+/* Dirty flags for hardware emit
+ */
+#define I915_HW_STATIC (1<<I915_CACHE_STATIC)
+#define I915_HW_DYNAMIC (1<<I915_CACHE_DYNAMIC)
+#define I915_HW_SAMPLER (1<<I915_CACHE_SAMPLER)
+#define I915_HW_MAP (1<<I915_CACHE_MAP)
+#define I915_HW_PROGRAM (1<<I915_CACHE_PROGRAM)
+#define I915_HW_CONSTANTS (1<<I915_CACHE_CONSTANTS)
+#define I915_HW_IMMEDIATE (1<<(I915_MAX_CACHE+0))
+#define I915_HW_INVARIENT (1<<(I915_MAX_CACHE+1))
+
+
+/***********************************************************************
+ * i915_prim_emit.c:
+ */
+struct draw_stage *i915_draw_render_stage( struct i915_context *i915 );
+
+
+/***********************************************************************
+ * i915_prim_vbuf.c:
+ */
+struct draw_stage *i915_draw_vbuf_stage( struct i915_context *i915 );
+
+
+/***********************************************************************
+ * i915_state_emit.c:
+ */
+void i915_emit_hardware_state(struct i915_context *i915 );
+
+
+
+/***********************************************************************
+ * i915_clear.c:
+ */
+void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps,
+ unsigned clearValue);
+
+
+/***********************************************************************
+ * i915_surface.c:
+ */
+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 );
+
+
+
+
+/***********************************************************************
+ * Inline conversion functions. These are better-typed than the
+ * macros used previously:
+ */
+static INLINE struct i915_context *
+i915_context( struct pipe_context *pipe )
+{
+ return (struct i915_context *)pipe;
+}
+
+
+
+#endif
-/*\r
- Copyright (C) Intel Corp. 2006. All Rights Reserved.\r
- Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to\r
- develop this 3D driver.\r
-\r
- Permission is hereby granted, free of charge, to any person obtaining\r
- a copy of this software and associated documentation files (the\r
- "Software"), to deal in the Software without restriction, including\r
- without limitation the rights to use, copy, modify, merge, publish,\r
- distribute, sublicense, and/or sell copies of the Software, and to\r
- permit persons to whom the Software is furnished to do so, subject to\r
- the following conditions:\r
-\r
- The above copyright notice and this permission notice (including the\r
- next paragraph) shall be included in all copies or substantial\r
- portions of the Software.\r
-\r
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
- IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE\r
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-\r
- **********************************************************************/\r
- /*\r
- * Authors:\r
- * Keith Whitwell <keith@tungstengraphics.com>\r
- */\r
-\r
-\r
-#ifndef BRWCONTEXT_INC\r
-#define BRWCONTEXT_INC\r
-\r
-\r
-#include "pipe/p_context.h"\r
-#include "pipe/p_defines.h"\r
-#include "pipe/p_state.h"\r
-\r
-#include "tgsi/util/tgsi_scan.h"\r
-\r
-#include "brw_structs.h"\r
-#include "brw_winsys.h"\r
-\r
-\r
-/* Glossary:\r
- *\r
- * URB - uniform resource buffer. A mid-sized buffer which is\r
- * partitioned between the fixed function units and used for passing\r
- * values (vertices, primitives, constants) between them.\r
- *\r
- * CURBE - constant URB entry. An urb region (entry) used to hold\r
- * constant values which the fixed function units can be instructed to\r
- * preload into the GRF when spawining a thread.\r
- *\r
- * VUE - vertex URB entry. An urb entry holding a vertex and usually\r
- * a vertex header. The header contains control information and\r
- * things like primitive type, Begin/end flags and clip codes.\r
- *\r
- * PUE - primitive URB entry. An urb entry produced by the setup (SF)\r
- * unit holding rasterization and interpolation parameters.\r
- *\r
- * GRF - general register file. One of several register files\r
- * addressable by programmed threads. The inputs (r0, payload, curbe,\r
- * urb) of the thread are preloaded to this area before the thread is\r
- * spawned. The registers are individually 8 dwords wide and suitable\r
- * for general usage. Registers holding thread input values are not\r
- * special and may be overwritten.\r
- *\r
- * MRF - message register file. Threads communicate (and terminate)\r
- * by sending messages. Message parameters are placed in contigous\r
- * MRF registers. All program output is via these messages. URB\r
- * entries are populated by sending a message to the shared URB\r
- * function containing the new data, together with a control word,\r
- * often an unmodified copy of R0.\r
- *\r
- * R0 - GRF register 0. Typically holds control information used when\r
- * sending messages to other threads.\r
- *\r
- * EU or GEN4 EU: The name of the programmable subsystem of the\r
- * i965 hardware. Threads are executed by the EU, the registers\r
- * described above are part of the EU architecture.\r
- *\r
- * Fixed function units:\r
- *\r
- * CS - Command streamer. Notional first unit, little software\r
- * interaction. Holds the URB entries used for constant data, ie the\r
- * CURBEs.\r
- *\r
- * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of\r
- * this unit is responsible for pulling vertices out of vertex buffers\r
- * in vram and injecting them into the processing pipe as VUEs. If\r
- * enabled, it first passes them to a VS thread which is a good place\r
- * for the driver to implement any active vertex shader.\r
- *\r
- * GS - Geometry Shader. This corresponds to a new DX10 concept. If\r
- * enabled, incoming strips etc are passed to GS threads in individual\r
- * line/triangle/point units. The GS thread may perform arbitary\r
- * computation and emit whatever primtives with whatever vertices it\r
- * chooses. This makes GS an excellent place to implement GL's\r
- * unfilled polygon modes, though of course it is capable of much\r
- * more. Additionally, GS is used to translate away primitives not\r
- * handled by latter units, including Quads and Lineloops.\r
- *\r
- * CS - Clipper. Mesa's clipping algorithms are imported to run on\r
- * this unit. The fixed function part performs cliptesting against\r
- * the 6 fixed clipplanes and makes descisions on whether or not the\r
- * incoming primitive needs to be passed to a thread for clipping.\r
- * User clip planes are handled via cooperation with the VS thread.\r
- *\r
- * SF - Strips Fans or Setup: Triangles are prepared for\r
- * rasterization. Interpolation coefficients are calculated.\r
- * Flatshading and two-side lighting usually performed here.\r
- *\r
- * WM - Windower. Interpolation of vertex attributes performed here.\r
- * Fragment shader implemented here. SIMD aspects of EU taken full\r
- * advantage of, as pixels are processed in blocks of 16.\r
- *\r
- * CC - Color Calculator. No EU threads associated with this unit.\r
- * Handles blending and (presumably) depth and stencil testing.\r
- */\r
-\r
-#define BRW_MAX_CURBE (32*16)\r
-\r
-struct brw_context;\r
-struct brw_winsys;\r
-\r
-\r
-/* Raised when we receive new state across the pipe interface:\r
- */\r
-#define BRW_NEW_VIEWPORT 0x1\r
-#define BRW_NEW_RASTERIZER 0x2\r
-#define BRW_NEW_FS 0x4\r
-#define BRW_NEW_BLEND 0x8\r
-#define BRW_NEW_CLIP 0x10\r
-#define BRW_NEW_SCISSOR 0x20\r
-#define BRW_NEW_STIPPLE 0x40\r
-#define BRW_NEW_FRAMEBUFFER 0x80\r
-#define BRW_NEW_ALPHA_TEST 0x100\r
-#define BRW_NEW_DEPTH_STENCIL 0x200\r
-#define BRW_NEW_SAMPLER 0x400\r
-#define BRW_NEW_TEXTURE 0x800\r
-#define BRW_NEW_CONSTANTS 0x1000\r
-#define BRW_NEW_VBO 0x2000\r
-#define BRW_NEW_VS 0x4000\r
-\r
-/* Raised for other internal events:\r
- */\r
-#define BRW_NEW_URB_FENCE 0x10000\r
-#define BRW_NEW_PSP 0x20000\r
-#define BRW_NEW_CURBE_OFFSETS 0x40000\r
-#define BRW_NEW_REDUCED_PRIMITIVE 0x80000\r
-#define BRW_NEW_PRIMITIVE 0x100000\r
-#define BRW_NEW_SCENE 0x200000\r
-#define BRW_NEW_SF_LINKAGE 0x400000\r
-\r
-extern int BRW_DEBUG;\r
-\r
-#define DEBUG_TEXTURE 0x1\r
-#define DEBUG_STATE 0x2\r
-#define DEBUG_IOCTL 0x4\r
-#define DEBUG_PRIMS 0x8\r
-#define DEBUG_VERTS 0x10\r
-#define DEBUG_FALLBACKS 0x20\r
-#define DEBUG_VERBOSE 0x40\r
-#define DEBUG_DRI 0x80\r
-#define DEBUG_DMA 0x100\r
-#define DEBUG_SANITY 0x200\r
-#define DEBUG_SYNC 0x400\r
-#define DEBUG_SLEEP 0x800\r
-#define DEBUG_PIXEL 0x1000\r
-#define DEBUG_STATS 0x2000\r
-#define DEBUG_TILE 0x4000\r
-#define DEBUG_SINGLE_THREAD 0x8000\r
-#define DEBUG_WM 0x10000\r
-#define DEBUG_URB 0x20000\r
-#define DEBUG_VS 0x40000\r
-#define DEBUG_BATCH 0x80000\r
-#define DEBUG_BUFMGR 0x100000\r
-#define DEBUG_BLIT 0x200000\r
-#define DEBUG_REGION 0x400000\r
-#define DEBUG_MIPTREE 0x800000\r
-\r
-#define DBG(...) do { \\r
- if (BRW_DEBUG & FILE_DEBUG_FLAG) \\r
- debug_printf(__VA_ARGS__); \\r
-} while(0)\r
-\r
-#define PRINT(...) do { \\r
- debug_printf(brw->pipe.winsys, __VA_ARGS__); \\r
-} while(0)\r
-\r
-struct brw_state_flags {\r
- unsigned cache;\r
- unsigned brw;\r
-};\r
-\r
-\r
-struct brw_vertex_program {\r
- struct pipe_shader_state program;\r
- struct tgsi_shader_info info;\r
- int id;\r
-};\r
-\r
-\r
-struct brw_fragment_program {\r
- struct pipe_shader_state program;\r
- struct tgsi_shader_info info;\r
- \r
- boolean UsesDepth; /* XXX add this to tgsi_shader_info? */\r
- int id;\r
-};\r
-\r
-\r
-struct pipe_setup_linkage {\r
- struct {\r
- unsigned vp_output:5;\r
- unsigned interp_mode:4;\r
- unsigned bf_vp_output:5;\r
- } fp_input[PIPE_MAX_SHADER_INPUTS];\r
-\r
- unsigned fp_input_count:5;\r
- unsigned max_vp_output:5;\r
-};\r
- \r
-\r
-\r
-struct brw_texture {\r
- struct pipe_texture base;\r
-\r
- /* Derived from the above:\r
- */\r
- unsigned pitch;\r
- unsigned depth_pitch; /* per-image on i945? */\r
- unsigned total_height;\r
-\r
- unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS];\r
-\r
- /* Explicitly store the offset of each image for each cube face or\r
- * depth value. Pretty much have to accept that hardware formats\r
- * are going to be so diverse that there is no unified way to\r
- * compute the offsets of depth/cube images within a mipmap level,\r
- * so have to store them as a lookup table:\r
- */\r
- unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */\r
-\r
- /* Includes image offset tables:\r
- */\r
- unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS];\r
-\r
- /* The data is held here:\r
- */\r
- struct pipe_buffer *buffer;\r
-};\r
-\r
-/* Data about a particular attempt to compile a program. Note that\r
- * there can be many of these, each in a different GL state\r
- * corresponding to a different brw_wm_prog_key struct, with different\r
- * compiled programs:\r
- */\r
-/* Data about a particular attempt to compile a program. Note that\r
- * there can be many of these, each in a different GL state\r
- * corresponding to a different brw_wm_prog_key struct, with different\r
- * compiled programs:\r
- */\r
-\r
-struct brw_wm_prog_data {\r
- unsigned curb_read_length;\r
- unsigned urb_read_length;\r
-\r
- unsigned first_curbe_grf;\r
- unsigned total_grf;\r
- unsigned total_scratch;\r
-\r
- /* Internally generated constants for the CURBE. These are loaded\r
- * ahead of the data from the constant buffer.\r
- */\r
- const float internal_const[8];\r
- unsigned nr_internal_consts;\r
- unsigned max_const;\r
-\r
- boolean error;\r
-};\r
-\r
-struct brw_sf_prog_data {\r
- unsigned urb_read_length;\r
- unsigned total_grf;\r
-\r
- /* Each vertex may have upto 12 attributes, 4 components each,\r
- * except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11\r
- * rows.\r
- *\r
- * Actually we use 4 for each, so call it 12 rows.\r
- */\r
- unsigned urb_entry_size;\r
-};\r
-\r
-struct brw_clip_prog_data {\r
- unsigned curb_read_length; /* user planes? */\r
- unsigned clip_mode;\r
- unsigned urb_read_length;\r
- unsigned total_grf;\r
-};\r
-\r
-struct brw_gs_prog_data {\r
- unsigned urb_read_length;\r
- unsigned total_grf;\r
-};\r
-\r
-struct brw_vs_prog_data {\r
- unsigned curb_read_length;\r
- unsigned urb_read_length;\r
- unsigned total_grf;\r
- unsigned outputs_written;\r
-\r
- unsigned inputs_read;\r
-\r
- unsigned max_const;\r
-\r
- float imm_buf[PIPE_MAX_CONSTANT][4];\r
- unsigned num_imm;\r
- unsigned num_consts;\r
-\r
- /* Used for calculating urb partitions:\r
- */\r
- unsigned urb_entry_size;\r
-};\r
-\r
-\r
-#define BRW_MAX_TEX_UNIT 8\r
-#define BRW_WM_MAX_SURF BRW_MAX_TEX_UNIT + 1\r
-\r
-/* Create a fixed sized struct for caching binding tables:\r
- */\r
-struct brw_surface_binding_table {\r
- unsigned surf_ss_offset[BRW_WM_MAX_SURF];\r
-};\r
-\r
-\r
-struct brw_cache;\r
-\r
-struct brw_mem_pool {\r
- struct pipe_buffer *buffer;\r
-\r
- unsigned size;\r
- unsigned offset; /* offset of first free byte */\r
-\r
- struct brw_context *brw;\r
-};\r
-\r
-struct brw_cache_item {\r
- unsigned hash;\r
- unsigned key_size; /* for variable-sized keys */\r
- const void *key;\r
-\r
- unsigned offset; /* offset within pool's buffer */\r
- unsigned data_size;\r
-\r
- struct brw_cache_item *next;\r
-};\r
-\r
-\r
-\r
-struct brw_cache {\r
- unsigned id;\r
-\r
- const char *name;\r
-\r
- struct brw_context *brw;\r
- struct brw_mem_pool *pool;\r
-\r
- struct brw_cache_item **items;\r
- unsigned size, n_items;\r
-\r
- unsigned key_size; /* for fixed-size keys */\r
- unsigned aux_size;\r
-\r
- unsigned last_addr; /* offset of active item */\r
-};\r
-\r
-\r
-\r
-\r
-/* Considered adding a member to this struct to document which flags\r
- * an update might raise so that ordering of the state atoms can be\r
- * checked or derived at runtime. Dropped the idea in favor of having\r
- * a debug mode where the state is monitored for flags which are\r
- * raised that have already been tested against.\r
- */\r
-struct brw_tracked_state {\r
- struct brw_state_flags dirty;\r
- void (*update)( struct brw_context *brw );\r
-};\r
-\r
-\r
-/* Flags for brw->state.cache.\r
- */\r
-#define CACHE_NEW_CC_VP (1<<BRW_CC_VP)\r
-#define CACHE_NEW_CC_UNIT (1<<BRW_CC_UNIT)\r
-#define CACHE_NEW_WM_PROG (1<<BRW_WM_PROG)\r
-#define CACHE_NEW_SAMPLER_DEFAULT_COLOR (1<<BRW_SAMPLER_DEFAULT_COLOR)\r
-#define CACHE_NEW_SAMPLER (1<<BRW_SAMPLER)\r
-#define CACHE_NEW_WM_UNIT (1<<BRW_WM_UNIT)\r
-#define CACHE_NEW_SF_PROG (1<<BRW_SF_PROG)\r
-#define CACHE_NEW_SF_VP (1<<BRW_SF_VP)\r
-#define CACHE_NEW_SF_UNIT (1<<BRW_SF_UNIT)\r
-#define CACHE_NEW_VS_UNIT (1<<BRW_VS_UNIT)\r
-#define CACHE_NEW_VS_PROG (1<<BRW_VS_PROG)\r
-#define CACHE_NEW_GS_UNIT (1<<BRW_GS_UNIT)\r
-#define CACHE_NEW_GS_PROG (1<<BRW_GS_PROG)\r
-#define CACHE_NEW_CLIP_VP (1<<BRW_CLIP_VP)\r
-#define CACHE_NEW_CLIP_UNIT (1<<BRW_CLIP_UNIT)\r
-#define CACHE_NEW_CLIP_PROG (1<<BRW_CLIP_PROG)\r
-#define CACHE_NEW_SURFACE (1<<BRW_SS_SURFACE)\r
-#define CACHE_NEW_SURF_BIND (1<<BRW_SS_SURF_BIND)\r
-\r
-\r
-\r
-\r
-enum brw_mempool_id {\r
- BRW_GS_POOL,\r
- BRW_SS_POOL,\r
- BRW_MAX_POOL\r
-};\r
-\r
-\r
-struct brw_cached_batch_item {\r
- struct header *header;\r
- unsigned sz;\r
- struct brw_cached_batch_item *next;\r
-};\r
-\r
-\r
-\r
-/* Protect against a future where PIPE_MAX_ATTRIBS > 32. Wouldn't life\r
- * be easier if C allowed arrays of packed elements?\r
- */\r
-#define ATTRIB_BIT_DWORDS ((PIPE_MAX_ATTRIBS+31)/32)\r
-\r
-\r
-\r
-\r
-struct brw_vertex_info {\r
- unsigned varying; /* varying:1[PIPE_MAX_ATTRIBS] */\r
- unsigned sizes[ATTRIB_BIT_DWORDS * 2]; /* sizes:2[PIPE_MAX_ATTRIBS] */\r
-};\r
-\r
-\r
-\r
-\r
-\r
-struct brw_context\r
-{\r
- struct pipe_context pipe;\r
- struct brw_winsys *winsys;\r
-\r
- unsigned primitive;\r
- unsigned reduced_primitive;\r
-\r
- boolean emit_state_always;\r
-\r
- struct {\r
- struct brw_state_flags dirty;\r
- } state;\r
-\r
-\r
- struct {\r
- const struct pipe_blend_state *Blend;\r
- const struct pipe_depth_stencil_alpha_state *DepthStencil;\r
- const struct pipe_poly_stipple *PolygonStipple;\r
- const struct pipe_rasterizer_state *Raster;\r
- const struct pipe_sampler_state *Samplers[PIPE_MAX_SAMPLERS];\r
- const struct brw_vertex_program *VertexProgram;\r
- const struct brw_fragment_program *FragmentProgram;\r
-\r
- struct pipe_clip_state Clip;\r
- struct pipe_blend_color BlendColor;\r
- struct pipe_scissor_state Scissor;\r
- struct pipe_viewport_state Viewport;\r
- struct pipe_framebuffer_state FrameBuffer;\r
-\r
- const struct pipe_constant_buffer *Constants[2];\r
- const struct brw_texture *Texture[PIPE_MAX_SAMPLERS];\r
- } attribs;\r
-\r
- unsigned num_samplers;\r
- unsigned num_textures;\r
-\r
- struct brw_mem_pool pool[BRW_MAX_POOL];\r
- struct brw_cache cache[BRW_MAX_CACHE];\r
- struct brw_cached_batch_item *cached_batch_items;\r
-\r
- struct {\r
-\r
- /* Arrays with buffer objects to copy non-bufferobj arrays into\r
- * for upload:\r
- */\r
- const struct pipe_vertex_buffer *vbo_array[PIPE_MAX_ATTRIBS];\r
-\r
- struct brw_vertex_element_state inputs[PIPE_MAX_ATTRIBS];\r
-\r
-#define BRW_NR_UPLOAD_BUFS 17\r
-#define BRW_UPLOAD_INIT_SIZE (128*1024)\r
-\r
- /* Summary of size and varying of active arrays, so we can check\r
- * for changes to this state:\r
- */\r
- struct brw_vertex_info info;\r
- } vb;\r
-\r
-\r
- unsigned hardware_dirty;\r
- unsigned dirty;\r
- unsigned pci_id;\r
- /* BRW_NEW_URB_ALLOCATIONS:\r
- */\r
- struct {\r
- unsigned vsize; /* vertex size plus header in urb registers */\r
- unsigned csize; /* constant buffer size in urb registers */\r
- unsigned sfsize; /* setup data size in urb registers */\r
-\r
- boolean constrained;\r
-\r
- unsigned nr_vs_entries;\r
- unsigned nr_gs_entries;\r
- unsigned nr_clip_entries;\r
- unsigned nr_sf_entries;\r
- unsigned nr_cs_entries;\r
-\r
-/* unsigned vs_size; */\r
-/* unsigned gs_size; */\r
-/* unsigned clip_size; */\r
-/* unsigned sf_size; */\r
-/* unsigned cs_size; */\r
-\r
- unsigned vs_start;\r
- unsigned gs_start;\r
- unsigned clip_start;\r
- unsigned sf_start;\r
- unsigned cs_start;\r
- } urb;\r
-\r
-\r
- /* BRW_NEW_CURBE_OFFSETS:\r
- */\r
- struct {\r
- unsigned wm_start;\r
- unsigned wm_size;\r
- unsigned clip_start;\r
- unsigned clip_size;\r
- unsigned vs_start;\r
- unsigned vs_size;\r
- unsigned total_size;\r
-\r
- unsigned gs_offset;\r
-\r
- float *last_buf;\r
- unsigned last_bufsz;\r
- } curbe;\r
-\r
- struct {\r
- struct brw_vs_prog_data *prog_data;\r
-\r
- unsigned prog_gs_offset;\r
- unsigned state_gs_offset;\r
- } vs;\r
-\r
- struct {\r
- struct brw_gs_prog_data *prog_data;\r
-\r
- boolean prog_active;\r
- unsigned prog_gs_offset;\r
- unsigned state_gs_offset;\r
- } gs;\r
-\r
- struct {\r
- struct brw_clip_prog_data *prog_data;\r
-\r
- unsigned prog_gs_offset;\r
- unsigned vp_gs_offset;\r
- unsigned state_gs_offset;\r
- } clip;\r
-\r
-\r
- struct {\r
- struct brw_sf_prog_data *prog_data;\r
-\r
- struct pipe_setup_linkage linkage;\r
-\r
- unsigned prog_gs_offset;\r
- unsigned vp_gs_offset;\r
- unsigned state_gs_offset;\r
- } sf;\r
-\r
- struct {\r
- struct brw_wm_prog_data *prog_data;\r
-\r
-// struct brw_wm_compiler *compile_data;\r
-\r
-\r
- /**\r
- * Array of sampler state uploaded at sampler_gs_offset of BRW_SAMPLER\r
- * cache\r
- */\r
- struct brw_sampler_state sampler[BRW_MAX_TEX_UNIT];\r
-\r
- unsigned render_surf;\r
- unsigned nr_surfaces;\r
-\r
- unsigned max_threads;\r
- struct pipe_buffer *scratch_buffer;\r
- unsigned scratch_buffer_size;\r
-\r
- unsigned sampler_count;\r
- unsigned sampler_gs_offset;\r
-\r
- struct brw_surface_binding_table bind;\r
- unsigned bind_ss_offset;\r
-\r
- unsigned prog_gs_offset;\r
- unsigned state_gs_offset;\r
- } wm;\r
-\r
-\r
- struct {\r
- unsigned vp_gs_offset;\r
- unsigned state_gs_offset;\r
- } cc;\r
-\r
-\r
- /* Used to give every program string a unique id\r
- */\r
- unsigned program_id;\r
-};\r
-\r
-\r
-#define BRW_PACKCOLOR8888(r,g,b,a) ((r<<24) | (g<<16) | (b<<8) | a)\r
-\r
-\r
-/*======================================================================\r
- * brw_vtbl.c\r
- */\r
-void brw_do_flush( struct brw_context *brw,\r
- unsigned flags );\r
-\r
-\r
-/*======================================================================\r
- * brw_state.c\r
- */\r
-void brw_validate_state(struct brw_context *brw);\r
-void brw_init_state(struct brw_context *brw);\r
-void brw_destroy_state(struct brw_context *brw);\r
-\r
-\r
-/*======================================================================\r
- * brw_tex.c\r
- */\r
-void brwUpdateTextureState( struct brw_context *brw );\r
-\r
-\r
-/* brw_urb.c\r
- */\r
-void brw_upload_urb_fence(struct brw_context *brw);\r
-\r
-void brw_upload_constant_buffer_state(struct brw_context *brw);\r
-\r
-void brw_init_surface_functions(struct brw_context *brw);\r
-void brw_init_state_functions(struct brw_context *brw);\r
-void brw_init_flush_functions(struct brw_context *brw);\r
-void brw_init_string_functions(struct brw_context *brw);\r
-\r
-/*======================================================================\r
- * Inline conversion functions. These are better-typed than the\r
- * macros used previously:\r
- */\r
-static inline struct brw_context *\r
-brw_context( struct pipe_context *ctx )\r
-{\r
- return (struct brw_context *)ctx;\r
-}\r
-\r
-#endif\r
-\r
+/*
+ Copyright (C) Intel Corp. 2006. All Rights Reserved.
+ Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ develop this 3D driver.
+
+ 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 (including the
+ next paragraph) shall be included in all copies or substantial
+ portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ **********************************************************************/
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#ifndef BRWCONTEXT_INC
+#define BRWCONTEXT_INC
+
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_state.h"
+
+#include "tgsi/util/tgsi_scan.h"
+
+#include "brw_structs.h"
+#include "brw_winsys.h"
+
+
+/* Glossary:
+ *
+ * URB - uniform resource buffer. A mid-sized buffer which is
+ * partitioned between the fixed function units and used for passing
+ * values (vertices, primitives, constants) between them.
+ *
+ * CURBE - constant URB entry. An urb region (entry) used to hold
+ * constant values which the fixed function units can be instructed to
+ * preload into the GRF when spawining a thread.
+ *
+ * VUE - vertex URB entry. An urb entry holding a vertex and usually
+ * a vertex header. The header contains control information and
+ * things like primitive type, Begin/end flags and clip codes.
+ *
+ * PUE - primitive URB entry. An urb entry produced by the setup (SF)
+ * unit holding rasterization and interpolation parameters.
+ *
+ * GRF - general register file. One of several register files
+ * addressable by programmed threads. The inputs (r0, payload, curbe,
+ * urb) of the thread are preloaded to this area before the thread is
+ * spawned. The registers are individually 8 dwords wide and suitable
+ * for general usage. Registers holding thread input values are not
+ * special and may be overwritten.
+ *
+ * MRF - message register file. Threads communicate (and terminate)
+ * by sending messages. Message parameters are placed in contigous
+ * MRF registers. All program output is via these messages. URB
+ * entries are populated by sending a message to the shared URB
+ * function containing the new data, together with a control word,
+ * often an unmodified copy of R0.
+ *
+ * R0 - GRF register 0. Typically holds control information used when
+ * sending messages to other threads.
+ *
+ * EU or GEN4 EU: The name of the programmable subsystem of the
+ * i965 hardware. Threads are executed by the EU, the registers
+ * described above are part of the EU architecture.
+ *
+ * Fixed function units:
+ *
+ * CS - Command streamer. Notional first unit, little software
+ * interaction. Holds the URB entries used for constant data, ie the
+ * CURBEs.
+ *
+ * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of
+ * this unit is responsible for pulling vertices out of vertex buffers
+ * in vram and injecting them into the processing pipe as VUEs. If
+ * enabled, it first passes them to a VS thread which is a good place
+ * for the driver to implement any active vertex shader.
+ *
+ * GS - Geometry Shader. This corresponds to a new DX10 concept. If
+ * enabled, incoming strips etc are passed to GS threads in individual
+ * line/triangle/point units. The GS thread may perform arbitary
+ * computation and emit whatever primtives with whatever vertices it
+ * chooses. This makes GS an excellent place to implement GL's
+ * unfilled polygon modes, though of course it is capable of much
+ * more. Additionally, GS is used to translate away primitives not
+ * handled by latter units, including Quads and Lineloops.
+ *
+ * CS - Clipper. Mesa's clipping algorithms are imported to run on
+ * this unit. The fixed function part performs cliptesting against
+ * the 6 fixed clipplanes and makes descisions on whether or not the
+ * incoming primitive needs to be passed to a thread for clipping.
+ * User clip planes are handled via cooperation with the VS thread.
+ *
+ * SF - Strips Fans or Setup: Triangles are prepared for
+ * rasterization. Interpolation coefficients are calculated.
+ * Flatshading and two-side lighting usually performed here.
+ *
+ * WM - Windower. Interpolation of vertex attributes performed here.
+ * Fragment shader implemented here. SIMD aspects of EU taken full
+ * advantage of, as pixels are processed in blocks of 16.
+ *
+ * CC - Color Calculator. No EU threads associated with this unit.
+ * Handles blending and (presumably) depth and stencil testing.
+ */
+
+#define BRW_MAX_CURBE (32*16)
+
+struct brw_context;
+struct brw_winsys;
+
+
+/* Raised when we receive new state across the pipe interface:
+ */
+#define BRW_NEW_VIEWPORT 0x1
+#define BRW_NEW_RASTERIZER 0x2
+#define BRW_NEW_FS 0x4
+#define BRW_NEW_BLEND 0x8
+#define BRW_NEW_CLIP 0x10
+#define BRW_NEW_SCISSOR 0x20
+#define BRW_NEW_STIPPLE 0x40
+#define BRW_NEW_FRAMEBUFFER 0x80
+#define BRW_NEW_ALPHA_TEST 0x100
+#define BRW_NEW_DEPTH_STENCIL 0x200
+#define BRW_NEW_SAMPLER 0x400
+#define BRW_NEW_TEXTURE 0x800
+#define BRW_NEW_CONSTANTS 0x1000
+#define BRW_NEW_VBO 0x2000
+#define BRW_NEW_VS 0x4000
+
+/* Raised for other internal events:
+ */
+#define BRW_NEW_URB_FENCE 0x10000
+#define BRW_NEW_PSP 0x20000
+#define BRW_NEW_CURBE_OFFSETS 0x40000
+#define BRW_NEW_REDUCED_PRIMITIVE 0x80000
+#define BRW_NEW_PRIMITIVE 0x100000
+#define BRW_NEW_SCENE 0x200000
+#define BRW_NEW_SF_LINKAGE 0x400000
+
+extern int BRW_DEBUG;
+
+#define DEBUG_TEXTURE 0x1
+#define DEBUG_STATE 0x2
+#define DEBUG_IOCTL 0x4
+#define DEBUG_PRIMS 0x8
+#define DEBUG_VERTS 0x10
+#define DEBUG_FALLBACKS 0x20
+#define DEBUG_VERBOSE 0x40
+#define DEBUG_DRI 0x80
+#define DEBUG_DMA 0x100
+#define DEBUG_SANITY 0x200
+#define DEBUG_SYNC 0x400
+#define DEBUG_SLEEP 0x800
+#define DEBUG_PIXEL 0x1000
+#define DEBUG_STATS 0x2000
+#define DEBUG_TILE 0x4000
+#define DEBUG_SINGLE_THREAD 0x8000
+#define DEBUG_WM 0x10000
+#define DEBUG_URB 0x20000
+#define DEBUG_VS 0x40000
+#define DEBUG_BATCH 0x80000
+#define DEBUG_BUFMGR 0x100000
+#define DEBUG_BLIT 0x200000
+#define DEBUG_REGION 0x400000
+#define DEBUG_MIPTREE 0x800000
+
+#define DBG(...) do { \
+ if (BRW_DEBUG & FILE_DEBUG_FLAG) \
+ debug_printf(__VA_ARGS__); \
+} while(0)
+
+#define PRINT(...) do { \
+ debug_printf(brw->pipe.winsys, __VA_ARGS__); \
+} while(0)
+
+struct brw_state_flags {
+ unsigned cache;
+ unsigned brw;
+};
+
+
+struct brw_vertex_program {
+ struct pipe_shader_state program;
+ struct tgsi_shader_info info;
+ int id;
+};
+
+
+struct brw_fragment_program {
+ struct pipe_shader_state program;
+ struct tgsi_shader_info info;
+
+ boolean UsesDepth; /* XXX add this to tgsi_shader_info? */
+ int id;
+};
+
+
+struct pipe_setup_linkage {
+ struct {
+ unsigned vp_output:5;
+ unsigned interp_mode:4;
+ unsigned bf_vp_output:5;
+ } fp_input[PIPE_MAX_SHADER_INPUTS];
+
+ unsigned fp_input_count:5;
+ unsigned max_vp_output:5;
+};
+
+
+
+struct brw_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 *buffer;
+};
+
+/* Data about a particular attempt to compile a program. Note that
+ * there can be many of these, each in a different GL state
+ * corresponding to a different brw_wm_prog_key struct, with different
+ * compiled programs:
+ */
+/* Data about a particular attempt to compile a program. Note that
+ * there can be many of these, each in a different GL state
+ * corresponding to a different brw_wm_prog_key struct, with different
+ * compiled programs:
+ */
+
+struct brw_wm_prog_data {
+ unsigned curb_read_length;
+ unsigned urb_read_length;
+
+ unsigned first_curbe_grf;
+ unsigned total_grf;
+ unsigned total_scratch;
+
+ /* Internally generated constants for the CURBE. These are loaded
+ * ahead of the data from the constant buffer.
+ */
+ const float internal_const[8];
+ unsigned nr_internal_consts;
+ unsigned max_const;
+
+ boolean error;
+};
+
+struct brw_sf_prog_data {
+ unsigned urb_read_length;
+ unsigned total_grf;
+
+ /* Each vertex may have upto 12 attributes, 4 components each,
+ * except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11
+ * rows.
+ *
+ * Actually we use 4 for each, so call it 12 rows.
+ */
+ unsigned urb_entry_size;
+};
+
+struct brw_clip_prog_data {
+ unsigned curb_read_length; /* user planes? */
+ unsigned clip_mode;
+ unsigned urb_read_length;
+ unsigned total_grf;
+};
+
+struct brw_gs_prog_data {
+ unsigned urb_read_length;
+ unsigned total_grf;
+};
+
+struct brw_vs_prog_data {
+ unsigned curb_read_length;
+ unsigned urb_read_length;
+ unsigned total_grf;
+ unsigned outputs_written;
+
+ unsigned inputs_read;
+
+ unsigned max_const;
+
+ float imm_buf[PIPE_MAX_CONSTANT][4];
+ unsigned num_imm;
+ unsigned num_consts;
+
+ /* Used for calculating urb partitions:
+ */
+ unsigned urb_entry_size;
+};
+
+
+#define BRW_MAX_TEX_UNIT 8
+#define BRW_WM_MAX_SURF BRW_MAX_TEX_UNIT + 1
+
+/* Create a fixed sized struct for caching binding tables:
+ */
+struct brw_surface_binding_table {
+ unsigned surf_ss_offset[BRW_WM_MAX_SURF];
+};
+
+
+struct brw_cache;
+
+struct brw_mem_pool {
+ struct pipe_buffer *buffer;
+
+ unsigned size;
+ unsigned offset; /* offset of first free byte */
+
+ struct brw_context *brw;
+};
+
+struct brw_cache_item {
+ unsigned hash;
+ unsigned key_size; /* for variable-sized keys */
+ const void *key;
+
+ unsigned offset; /* offset within pool's buffer */
+ unsigned data_size;
+
+ struct brw_cache_item *next;
+};
+
+
+
+struct brw_cache {
+ unsigned id;
+
+ const char *name;
+
+ struct brw_context *brw;
+ struct brw_mem_pool *pool;
+
+ struct brw_cache_item **items;
+ unsigned size, n_items;
+
+ unsigned key_size; /* for fixed-size keys */
+ unsigned aux_size;
+
+ unsigned last_addr; /* offset of active item */
+};
+
+
+
+
+/* Considered adding a member to this struct to document which flags
+ * an update might raise so that ordering of the state atoms can be
+ * checked or derived at runtime. Dropped the idea in favor of having
+ * a debug mode where the state is monitored for flags which are
+ * raised that have already been tested against.
+ */
+struct brw_tracked_state {
+ struct brw_state_flags dirty;
+ void (*update)( struct brw_context *brw );
+};
+
+
+/* Flags for brw->state.cache.
+ */
+#define CACHE_NEW_CC_VP (1<<BRW_CC_VP)
+#define CACHE_NEW_CC_UNIT (1<<BRW_CC_UNIT)
+#define CACHE_NEW_WM_PROG (1<<BRW_WM_PROG)
+#define CACHE_NEW_SAMPLER_DEFAULT_COLOR (1<<BRW_SAMPLER_DEFAULT_COLOR)
+#define CACHE_NEW_SAMPLER (1<<BRW_SAMPLER)
+#define CACHE_NEW_WM_UNIT (1<<BRW_WM_UNIT)
+#define CACHE_NEW_SF_PROG (1<<BRW_SF_PROG)
+#define CACHE_NEW_SF_VP (1<<BRW_SF_VP)
+#define CACHE_NEW_SF_UNIT (1<<BRW_SF_UNIT)
+#define CACHE_NEW_VS_UNIT (1<<BRW_VS_UNIT)
+#define CACHE_NEW_VS_PROG (1<<BRW_VS_PROG)
+#define CACHE_NEW_GS_UNIT (1<<BRW_GS_UNIT)
+#define CACHE_NEW_GS_PROG (1<<BRW_GS_PROG)
+#define CACHE_NEW_CLIP_VP (1<<BRW_CLIP_VP)
+#define CACHE_NEW_CLIP_UNIT (1<<BRW_CLIP_UNIT)
+#define CACHE_NEW_CLIP_PROG (1<<BRW_CLIP_PROG)
+#define CACHE_NEW_SURFACE (1<<BRW_SS_SURFACE)
+#define CACHE_NEW_SURF_BIND (1<<BRW_SS_SURF_BIND)
+
+
+
+
+enum brw_mempool_id {
+ BRW_GS_POOL,
+ BRW_SS_POOL,
+ BRW_MAX_POOL
+};
+
+
+struct brw_cached_batch_item {
+ struct header *header;
+ unsigned sz;
+ struct brw_cached_batch_item *next;
+};
+
+
+
+/* Protect against a future where PIPE_MAX_ATTRIBS > 32. Wouldn't life
+ * be easier if C allowed arrays of packed elements?
+ */
+#define ATTRIB_BIT_DWORDS ((PIPE_MAX_ATTRIBS+31)/32)
+
+
+
+
+struct brw_vertex_info {
+ unsigned varying; /* varying:1[PIPE_MAX_ATTRIBS] */
+ unsigned sizes[ATTRIB_BIT_DWORDS * 2]; /* sizes:2[PIPE_MAX_ATTRIBS] */
+};
+
+
+
+
+
+struct brw_context
+{
+ struct pipe_context pipe;
+ struct brw_winsys *winsys;
+
+ unsigned primitive;
+ unsigned reduced_primitive;
+
+ boolean emit_state_always;
+
+ struct {
+ struct brw_state_flags dirty;
+ } state;
+
+
+ struct {
+ const struct pipe_blend_state *Blend;
+ const struct pipe_depth_stencil_alpha_state *DepthStencil;
+ const struct pipe_poly_stipple *PolygonStipple;
+ const struct pipe_rasterizer_state *Raster;
+ const struct pipe_sampler_state *Samplers[PIPE_MAX_SAMPLERS];
+ const struct brw_vertex_program *VertexProgram;
+ const struct brw_fragment_program *FragmentProgram;
+
+ struct pipe_clip_state Clip;
+ struct pipe_blend_color BlendColor;
+ struct pipe_scissor_state Scissor;
+ struct pipe_viewport_state Viewport;
+ struct pipe_framebuffer_state FrameBuffer;
+
+ const struct pipe_constant_buffer *Constants[2];
+ const struct brw_texture *Texture[PIPE_MAX_SAMPLERS];
+ } attribs;
+
+ unsigned num_samplers;
+ unsigned num_textures;
+
+ struct brw_mem_pool pool[BRW_MAX_POOL];
+ struct brw_cache cache[BRW_MAX_CACHE];
+ struct brw_cached_batch_item *cached_batch_items;
+
+ struct {
+
+ /* Arrays with buffer objects to copy non-bufferobj arrays into
+ * for upload:
+ */
+ const struct pipe_vertex_buffer *vbo_array[PIPE_MAX_ATTRIBS];
+
+ struct brw_vertex_element_state inputs[PIPE_MAX_ATTRIBS];
+
+#define BRW_NR_UPLOAD_BUFS 17
+#define BRW_UPLOAD_INIT_SIZE (128*1024)
+
+ /* Summary of size and varying of active arrays, so we can check
+ * for changes to this state:
+ */
+ struct brw_vertex_info info;
+ } vb;
+
+
+ unsigned hardware_dirty;
+ unsigned dirty;
+ unsigned pci_id;
+ /* BRW_NEW_URB_ALLOCATIONS:
+ */
+ struct {
+ unsigned vsize; /* vertex size plus header in urb registers */
+ unsigned csize; /* constant buffer size in urb registers */
+ unsigned sfsize; /* setup data size in urb registers */
+
+ boolean constrained;
+
+ unsigned nr_vs_entries;
+ unsigned nr_gs_entries;
+ unsigned nr_clip_entries;
+ unsigned nr_sf_entries;
+ unsigned nr_cs_entries;
+
+/* unsigned vs_size; */
+/* unsigned gs_size; */
+/* unsigned clip_size; */
+/* unsigned sf_size; */
+/* unsigned cs_size; */
+
+ unsigned vs_start;
+ unsigned gs_start;
+ unsigned clip_start;
+ unsigned sf_start;
+ unsigned cs_start;
+ } urb;
+
+
+ /* BRW_NEW_CURBE_OFFSETS:
+ */
+ struct {
+ unsigned wm_start;
+ unsigned wm_size;
+ unsigned clip_start;
+ unsigned clip_size;
+ unsigned vs_start;
+ unsigned vs_size;
+ unsigned total_size;
+
+ unsigned gs_offset;
+
+ float *last_buf;
+ unsigned last_bufsz;
+ } curbe;
+
+ struct {
+ struct brw_vs_prog_data *prog_data;
+
+ unsigned prog_gs_offset;
+ unsigned state_gs_offset;
+ } vs;
+
+ struct {
+ struct brw_gs_prog_data *prog_data;
+
+ boolean prog_active;
+ unsigned prog_gs_offset;
+ unsigned state_gs_offset;
+ } gs;
+
+ struct {
+ struct brw_clip_prog_data *prog_data;
+
+ unsigned prog_gs_offset;
+ unsigned vp_gs_offset;
+ unsigned state_gs_offset;
+ } clip;
+
+
+ struct {
+ struct brw_sf_prog_data *prog_data;
+
+ struct pipe_setup_linkage linkage;
+
+ unsigned prog_gs_offset;
+ unsigned vp_gs_offset;
+ unsigned state_gs_offset;
+ } sf;
+
+ struct {
+ struct brw_wm_prog_data *prog_data;
+
+// struct brw_wm_compiler *compile_data;
+
+
+ /**
+ * Array of sampler state uploaded at sampler_gs_offset of BRW_SAMPLER
+ * cache
+ */
+ struct brw_sampler_state sampler[BRW_MAX_TEX_UNIT];
+
+ unsigned render_surf;
+ unsigned nr_surfaces;
+
+ unsigned max_threads;
+ struct pipe_buffer *scratch_buffer;
+ unsigned scratch_buffer_size;
+
+ unsigned sampler_count;
+ unsigned sampler_gs_offset;
+
+ struct brw_surface_binding_table bind;
+ unsigned bind_ss_offset;
+
+ unsigned prog_gs_offset;
+ unsigned state_gs_offset;
+ } wm;
+
+
+ struct {
+ unsigned vp_gs_offset;
+ unsigned state_gs_offset;
+ } cc;
+
+
+ /* Used to give every program string a unique id
+ */
+ unsigned program_id;
+};
+
+
+#define BRW_PACKCOLOR8888(r,g,b,a) ((r<<24) | (g<<16) | (b<<8) | a)
+
+
+/*======================================================================
+ * brw_vtbl.c
+ */
+void brw_do_flush( struct brw_context *brw,
+ unsigned flags );
+
+
+/*======================================================================
+ * brw_state.c
+ */
+void brw_validate_state(struct brw_context *brw);
+void brw_init_state(struct brw_context *brw);
+void brw_destroy_state(struct brw_context *brw);
+
+
+/*======================================================================
+ * brw_tex.c
+ */
+void brwUpdateTextureState( struct brw_context *brw );
+
+
+/* brw_urb.c
+ */
+void brw_upload_urb_fence(struct brw_context *brw);
+
+void brw_upload_constant_buffer_state(struct brw_context *brw);
+
+void brw_init_surface_functions(struct brw_context *brw);
+void brw_init_state_functions(struct brw_context *brw);
+void brw_init_flush_functions(struct brw_context *brw);
+void brw_init_string_functions(struct brw_context *brw);
+
+/*======================================================================
+ * Inline conversion functions. These are better-typed than the
+ * macros used previously:
+ */
+static inline struct brw_context *
+brw_context( struct pipe_context *ctx )
+{
+ return (struct brw_context *)ctx;
+}
+
+#endif
+
-/**************************************************************************\r
- *\r
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.\r
- * All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the\r
- * "Software"), to deal in the Software without restriction, including\r
- * without limitation the rights to use, copy, modify, merge, publish,\r
- * distribute, sub license, and/or sell copies of the Software, and to\r
- * permit persons to whom the Software is furnished to do so, subject to\r
- * the following conditions:\r
- *\r
- * The above copyright notice and this permission notice (including the\r
- * next paragraph) shall be included in all copies or substantial portions\r
- * of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\r
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR\r
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- **************************************************************************/\r
-\r
-/* Authors: Zack Rusin <zack@tungstengraphics.com>\r
- * Keith Whitwell <keith@tungstengraphics.com>\r
- */\r
-\r
-\r
-#include "pipe/p_winsys.h"\r
-#include "pipe/p_util.h"\r
-#include "pipe/p_inlines.h"\r
-#include "pipe/p_shader_tokens.h"\r
-#include "tgsi/util/tgsi_dump.h"\r
-#include "tgsi/util/tgsi_parse.h"\r
-\r
-#include "brw_context.h"\r
-#include "brw_defines.h"\r
-#include "brw_state.h"\r
-#include "brw_draw.h"\r
-\r
-\r
-#define DUP( TYPE, VAL ) \\r
-do { \\r
- struct TYPE *x = malloc(sizeof(*x)); \\r
- memcpy(x, VAL, sizeof(*x) ); \\r
- return x; \\r
-} while (0)\r
-\r
-/************************************************************************\r
- * Blend \r
- */\r
-static void *\r
-brw_create_blend_state(struct pipe_context *pipe,\r
- const struct pipe_blend_state *blend)\r
-{ \r
- DUP( pipe_blend_state, blend );\r
-}\r
-\r
-static void brw_bind_blend_state(struct pipe_context *pipe,\r
- void *blend)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.Blend = (struct pipe_blend_state*)blend;\r
- brw->state.dirty.brw |= BRW_NEW_BLEND;\r
-}\r
-\r
-\r
-static void brw_delete_blend_state(struct pipe_context *pipe, void *blend)\r
-{\r
- free(blend);\r
-}\r
-\r
-static void brw_set_blend_color( struct pipe_context *pipe,\r
- const struct pipe_blend_color *blend_color )\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.BlendColor = *blend_color;\r
-\r
- brw->state.dirty.brw |= BRW_NEW_BLEND;\r
-}\r
-\r
-/************************************************************************\r
- * Sampler \r
- */\r
-\r
-static void *\r
-brw_create_sampler_state(struct pipe_context *pipe,\r
- const struct pipe_sampler_state *sampler)\r
-{\r
- DUP( pipe_sampler_state, sampler );\r
-}\r
-\r
-static void brw_bind_sampler_states(struct pipe_context *pipe,\r
- unsigned num, void **sampler)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- assert(num <= PIPE_MAX_SAMPLERS);\r
-\r
- /* Check for no-op */\r
- if (num == brw->num_samplers &&\r
- !memcmp(brw->attribs.Samplers, sampler, num * sizeof(void *)))\r
- return;\r
-\r
- memcpy(brw->attribs.Samplers, sampler, num * sizeof(void *));\r
- memset(&brw->attribs.Samplers[num], 0, (PIPE_MAX_SAMPLERS - num) *\r
- sizeof(void *));\r
-\r
- brw->num_samplers = num;\r
-\r
- brw->state.dirty.brw |= BRW_NEW_SAMPLER;\r
-}\r
-\r
-static void brw_delete_sampler_state(struct pipe_context *pipe,\r
- void *sampler)\r
-{\r
- free(sampler);\r
-}\r
-\r
-\r
-/************************************************************************\r
- * Depth stencil \r
- */\r
-\r
-static void *\r
-brw_create_depth_stencil_state(struct pipe_context *pipe,\r
- const struct pipe_depth_stencil_alpha_state *depth_stencil)\r
-{\r
- DUP( pipe_depth_stencil_alpha_state, depth_stencil );\r
-}\r
-\r
-static void brw_bind_depth_stencil_state(struct pipe_context *pipe,\r
- void *depth_stencil)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.DepthStencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil;\r
-\r
- brw->state.dirty.brw |= BRW_NEW_DEPTH_STENCIL;\r
-}\r
-\r
-static void brw_delete_depth_stencil_state(struct pipe_context *pipe,\r
- void *depth_stencil)\r
-{\r
- free(depth_stencil);\r
-}\r
-\r
-/************************************************************************\r
- * Scissor\r
- */\r
-static void brw_set_scissor_state( struct pipe_context *pipe,\r
- const struct pipe_scissor_state *scissor )\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- memcpy( &brw->attribs.Scissor, scissor, sizeof(*scissor) );\r
- brw->state.dirty.brw |= BRW_NEW_SCISSOR;\r
-}\r
-\r
-\r
-/************************************************************************\r
- * Stipple\r
- */\r
-\r
-static void brw_set_polygon_stipple( struct pipe_context *pipe,\r
- const struct pipe_poly_stipple *stipple )\r
-{\r
-}\r
-\r
-\r
-/************************************************************************\r
- * Fragment shader\r
- */\r
-\r
-static void * brw_create_fs_state(struct pipe_context *pipe,\r
- const struct pipe_shader_state *shader)\r
-{\r
- struct brw_fragment_program *brw_fp = CALLOC_STRUCT(brw_fragment_program);\r
-\r
- brw_fp->program.tokens = tgsi_dup_tokens(shader->tokens);\r
- brw_fp->id = brw_context(pipe)->program_id++;\r
-\r
- tgsi_scan_shader(shader->tokens, &brw_fp->info);\r
-\r
-#if 0\r
- brw_shader_info(shader->tokens,\r
- &brw_fp->info2);\r
-#endif\r
-\r
- tgsi_dump(shader->tokens, 0);\r
-\r
-\r
- return (void *)brw_fp;\r
-}\r
-\r
-static void brw_bind_fs_state(struct pipe_context *pipe, void *shader)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.FragmentProgram = (struct brw_fragment_program *)shader;\r
- brw->state.dirty.brw |= BRW_NEW_FS;\r
-}\r
-\r
-static void brw_delete_fs_state(struct pipe_context *pipe, void *shader)\r
-{\r
- struct brw_fragment_program *brw_fp = (struct brw_fragment_program *) shader;\r
-\r
- FREE((void *) brw_fp->program.tokens);\r
- FREE(brw_fp);\r
-}\r
-\r
-\r
-/************************************************************************\r
- * Vertex shader and other TNL state \r
- */\r
-\r
-static void *brw_create_vs_state(struct pipe_context *pipe,\r
- const struct pipe_shader_state *shader)\r
-{\r
- struct brw_vertex_program *brw_vp = CALLOC_STRUCT(brw_vertex_program);\r
-\r
- brw_vp->program.tokens = tgsi_dup_tokens(shader->tokens);\r
- brw_vp->id = brw_context(pipe)->program_id++;\r
-\r
- tgsi_scan_shader(shader->tokens, &brw_vp->info);\r
-\r
-#if 0\r
- brw_shader_info(shader->tokens,\r
- &brw_vp->info2);\r
-#endif\r
- tgsi_dump(shader->tokens, 0);\r
-\r
- return (void *)brw_vp;\r
-}\r
-\r
-static void brw_bind_vs_state(struct pipe_context *pipe, void *vs)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.VertexProgram = (struct brw_vertex_program *)vs;\r
- brw->state.dirty.brw |= BRW_NEW_VS;\r
-\r
- debug_printf("YYYYYYYYYYYYY BINDING VERTEX SHADER\n");\r
-}\r
-\r
-static void brw_delete_vs_state(struct pipe_context *pipe, void *shader)\r
-{\r
- struct brw_vertex_program *brw_vp = (struct brw_vertex_program *) shader;\r
-\r
- FREE((void *) brw_vp->program.tokens);\r
- FREE(brw_vp);\r
-}\r
-\r
-\r
-static void brw_set_clip_state( struct pipe_context *pipe,\r
- const struct pipe_clip_state *clip )\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.Clip = *clip;\r
-}\r
-\r
-\r
-static void brw_set_viewport_state( struct pipe_context *pipe,\r
- const struct pipe_viewport_state *viewport )\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.Viewport = *viewport; /* struct copy */\r
- brw->state.dirty.brw |= BRW_NEW_VIEWPORT;\r
-\r
- /* pass the viewport info to the draw module */\r
- //draw_set_viewport_state(brw->draw, viewport);\r
-}\r
-\r
-\r
-static void brw_set_vertex_buffers(struct pipe_context *pipe,\r
- unsigned count,\r
- const struct pipe_vertex_buffer *buffers)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
- memcpy(brw->vb.vbo_array, buffers, count * sizeof(buffers[0]));\r
-}\r
-\r
-static void brw_set_vertex_elements(struct pipe_context *pipe,\r
- unsigned count,\r
- const struct pipe_vertex_element *elements)\r
-{\r
- /* flush ? */\r
- struct brw_context *brw = brw_context(pipe);\r
- uint i;\r
-\r
- assert(count <= PIPE_MAX_ATTRIBS);\r
-\r
- for (i = 0; i < count; i++) {\r
- struct brw_vertex_element_state el;\r
- memset(&el, 0, sizeof(el));\r
-\r
- el.ve0.src_offset = elements[i].src_offset;\r
- el.ve0.src_format = brw_translate_surface_format(elements[i].src_format);\r
- el.ve0.valid = 1;\r
- el.ve0.vertex_buffer_index = elements[i].vertex_buffer_index;\r
-\r
- el.ve1.dst_offset = i * 4;\r
-\r
- el.ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_SRC;\r
- el.ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_SRC;\r
- el.ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_SRC;\r
- el.ve1.vfcomponent0 = BRW_VFCOMPONENT_STORE_SRC;\r
-\r
- switch (elements[i].nr_components) {\r
- case 1: el.ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_0;\r
- case 2: el.ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_0;\r
- case 3: el.ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_1_FLT;\r
- break;\r
- }\r
-\r
- brw->vb.inputs[i] = el;\r
- }\r
-}\r
-\r
-\r
-\r
-/************************************************************************\r
- * Constant buffers\r
- */\r
-\r
-static void brw_set_constant_buffer(struct pipe_context *pipe,\r
- uint shader, uint index,\r
- const struct pipe_constant_buffer *buf)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- assert(buf == 0 || index == 0);\r
-\r
- brw->attribs.Constants[shader] = buf;\r
- brw->state.dirty.brw |= BRW_NEW_CONSTANTS;\r
-}\r
-\r
-\r
-/************************************************************************\r
- * Texture surfaces\r
- */\r
-\r
-\r
-static void brw_set_sampler_textures(struct pipe_context *pipe,\r
- unsigned num,\r
- struct pipe_texture **texture)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
- uint i;\r
-\r
- assert(num <= PIPE_MAX_SAMPLERS);\r
-\r
- /* Check for no-op */\r
- if (num == brw->num_textures &&\r
- !memcmp(brw->attribs.Texture, texture, num *\r
- sizeof(struct pipe_texture *)))\r
- return;\r
-\r
- for (i = 0; i < num; i++)\r
- pipe_texture_reference((struct pipe_texture **) &brw->attribs.Texture[i],\r
- texture[i]);\r
-\r
- for (i = num; i < brw->num_textures; i++)\r
- pipe_texture_reference((struct pipe_texture **) &brw->attribs.Texture[i],\r
- NULL);\r
-\r
- brw->num_textures = num;\r
-\r
- brw->state.dirty.brw |= BRW_NEW_TEXTURE;\r
-}\r
-\r
-\r
-/************************************************************************\r
- * Render targets, etc\r
- */\r
-\r
-static void brw_set_framebuffer_state(struct pipe_context *pipe,\r
- const struct pipe_framebuffer_state *fb)\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.FrameBuffer = *fb; /* struct copy */\r
-\r
- brw->state.dirty.brw |= BRW_NEW_FRAMEBUFFER;\r
-}\r
-\r
-\r
-\r
-/************************************************************************\r
- * Rasterizer state\r
- */\r
-\r
-static void *\r
-brw_create_rasterizer_state(struct pipe_context *pipe,\r
- const struct pipe_rasterizer_state *rasterizer)\r
-{\r
- DUP(pipe_rasterizer_state, rasterizer);\r
-}\r
-\r
-static void brw_bind_rasterizer_state( struct pipe_context *pipe,\r
- void *setup )\r
-{\r
- struct brw_context *brw = brw_context(pipe);\r
-\r
- brw->attribs.Raster = (struct pipe_rasterizer_state *)setup;\r
-\r
- /* Also pass-through to draw module:\r
- */\r
- //draw_set_rasterizer_state(brw->draw, setup);\r
-\r
- brw->state.dirty.brw |= BRW_NEW_RASTERIZER;\r
-}\r
-\r
-static void brw_delete_rasterizer_state(struct pipe_context *pipe,\r
- void *setup)\r
-{\r
- free(setup);\r
-}\r
-\r
-\r
-\r
-void\r
-brw_init_state_functions( struct brw_context *brw )\r
-{\r
- brw->pipe.create_blend_state = brw_create_blend_state;\r
- brw->pipe.bind_blend_state = brw_bind_blend_state;\r
- brw->pipe.delete_blend_state = brw_delete_blend_state;\r
-\r
- brw->pipe.create_sampler_state = brw_create_sampler_state;\r
- brw->pipe.bind_sampler_states = brw_bind_sampler_states;\r
- brw->pipe.delete_sampler_state = brw_delete_sampler_state;\r
-\r
- brw->pipe.create_depth_stencil_alpha_state = brw_create_depth_stencil_state;\r
- brw->pipe.bind_depth_stencil_alpha_state = brw_bind_depth_stencil_state;\r
- brw->pipe.delete_depth_stencil_alpha_state = brw_delete_depth_stencil_state;\r
-\r
- brw->pipe.create_rasterizer_state = brw_create_rasterizer_state;\r
- brw->pipe.bind_rasterizer_state = brw_bind_rasterizer_state;\r
- brw->pipe.delete_rasterizer_state = brw_delete_rasterizer_state;\r
- brw->pipe.create_fs_state = brw_create_fs_state;\r
- brw->pipe.bind_fs_state = brw_bind_fs_state;\r
- brw->pipe.delete_fs_state = brw_delete_fs_state;\r
- brw->pipe.create_vs_state = brw_create_vs_state;\r
- brw->pipe.bind_vs_state = brw_bind_vs_state;\r
- brw->pipe.delete_vs_state = brw_delete_vs_state;\r
-\r
- brw->pipe.set_blend_color = brw_set_blend_color;\r
- brw->pipe.set_clip_state = brw_set_clip_state;\r
- brw->pipe.set_constant_buffer = brw_set_constant_buffer;\r
- brw->pipe.set_framebuffer_state = brw_set_framebuffer_state;\r
-\r
-// brw->pipe.set_feedback_state = brw_set_feedback_state;\r
-// brw->pipe.set_feedback_buffer = brw_set_feedback_buffer;\r
-\r
- brw->pipe.set_polygon_stipple = brw_set_polygon_stipple;\r
- brw->pipe.set_scissor_state = brw_set_scissor_state;\r
- brw->pipe.set_sampler_textures = brw_set_sampler_textures;\r
- brw->pipe.set_viewport_state = brw_set_viewport_state;\r
- brw->pipe.set_vertex_buffers = brw_set_vertex_buffers;\r
- brw->pipe.set_vertex_elements = brw_set_vertex_elements;\r
-}\r
+/**************************************************************************
+ *
+ * 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: Zack Rusin <zack@tungstengraphics.com>
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#include "pipe/p_winsys.h"
+#include "pipe/p_util.h"
+#include "pipe/p_inlines.h"
+#include "pipe/p_shader_tokens.h"
+#include "tgsi/util/tgsi_dump.h"
+#include "tgsi/util/tgsi_parse.h"
+
+#include "brw_context.h"
+#include "brw_defines.h"
+#include "brw_state.h"
+#include "brw_draw.h"
+
+
+#define DUP( TYPE, VAL ) \
+do { \
+ struct TYPE *x = malloc(sizeof(*x)); \
+ memcpy(x, VAL, sizeof(*x) ); \
+ return x; \
+} while (0)
+
+/************************************************************************
+ * Blend
+ */
+static void *
+brw_create_blend_state(struct pipe_context *pipe,
+ const struct pipe_blend_state *blend)
+{
+ DUP( pipe_blend_state, blend );
+}
+
+static void brw_bind_blend_state(struct pipe_context *pipe,
+ void *blend)
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.Blend = (struct pipe_blend_state*)blend;
+ brw->state.dirty.brw |= BRW_NEW_BLEND;
+}
+
+
+static void brw_delete_blend_state(struct pipe_context *pipe, void *blend)
+{
+ free(blend);
+}
+
+static void brw_set_blend_color( struct pipe_context *pipe,
+ const struct pipe_blend_color *blend_color )
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.BlendColor = *blend_color;
+
+ brw->state.dirty.brw |= BRW_NEW_BLEND;
+}
+
+/************************************************************************
+ * Sampler
+ */
+
+static void *
+brw_create_sampler_state(struct pipe_context *pipe,
+ const struct pipe_sampler_state *sampler)
+{
+ DUP( pipe_sampler_state, sampler );
+}
+
+static void brw_bind_sampler_states(struct pipe_context *pipe,
+ unsigned num, void **sampler)
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ assert(num <= PIPE_MAX_SAMPLERS);
+
+ /* Check for no-op */
+ if (num == brw->num_samplers &&
+ !memcmp(brw->attribs.Samplers, sampler, num * sizeof(void *)))
+ return;
+
+ memcpy(brw->attribs.Samplers, sampler, num * sizeof(void *));
+ memset(&brw->attribs.Samplers[num], 0, (PIPE_MAX_SAMPLERS - num) *
+ sizeof(void *));
+
+ brw->num_samplers = num;
+
+ brw->state.dirty.brw |= BRW_NEW_SAMPLER;
+}
+
+static void brw_delete_sampler_state(struct pipe_context *pipe,
+ void *sampler)
+{
+ free(sampler);
+}
+
+
+/************************************************************************
+ * Depth stencil
+ */
+
+static void *
+brw_create_depth_stencil_state(struct pipe_context *pipe,
+ const struct pipe_depth_stencil_alpha_state *depth_stencil)
+{
+ DUP( pipe_depth_stencil_alpha_state, depth_stencil );
+}
+
+static void brw_bind_depth_stencil_state(struct pipe_context *pipe,
+ void *depth_stencil)
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.DepthStencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil;
+
+ brw->state.dirty.brw |= BRW_NEW_DEPTH_STENCIL;
+}
+
+static void brw_delete_depth_stencil_state(struct pipe_context *pipe,
+ void *depth_stencil)
+{
+ free(depth_stencil);
+}
+
+/************************************************************************
+ * Scissor
+ */
+static void brw_set_scissor_state( struct pipe_context *pipe,
+ const struct pipe_scissor_state *scissor )
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ memcpy( &brw->attribs.Scissor, scissor, sizeof(*scissor) );
+ brw->state.dirty.brw |= BRW_NEW_SCISSOR;
+}
+
+
+/************************************************************************
+ * Stipple
+ */
+
+static void brw_set_polygon_stipple( struct pipe_context *pipe,
+ const struct pipe_poly_stipple *stipple )
+{
+}
+
+
+/************************************************************************
+ * Fragment shader
+ */
+
+static void * brw_create_fs_state(struct pipe_context *pipe,
+ const struct pipe_shader_state *shader)
+{
+ struct brw_fragment_program *brw_fp = CALLOC_STRUCT(brw_fragment_program);
+
+ brw_fp->program.tokens = tgsi_dup_tokens(shader->tokens);
+ brw_fp->id = brw_context(pipe)->program_id++;
+
+ tgsi_scan_shader(shader->tokens, &brw_fp->info);
+
+#if 0
+ brw_shader_info(shader->tokens,
+ &brw_fp->info2);
+#endif
+
+ tgsi_dump(shader->tokens, 0);
+
+
+ return (void *)brw_fp;
+}
+
+static void brw_bind_fs_state(struct pipe_context *pipe, void *shader)
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.FragmentProgram = (struct brw_fragment_program *)shader;
+ brw->state.dirty.brw |= BRW_NEW_FS;
+}
+
+static void brw_delete_fs_state(struct pipe_context *pipe, void *shader)
+{
+ struct brw_fragment_program *brw_fp = (struct brw_fragment_program *) shader;
+
+ FREE((void *) brw_fp->program.tokens);
+ FREE(brw_fp);
+}
+
+
+/************************************************************************
+ * Vertex shader and other TNL state
+ */
+
+static void *brw_create_vs_state(struct pipe_context *pipe,
+ const struct pipe_shader_state *shader)
+{
+ struct brw_vertex_program *brw_vp = CALLOC_STRUCT(brw_vertex_program);
+
+ brw_vp->program.tokens = tgsi_dup_tokens(shader->tokens);
+ brw_vp->id = brw_context(pipe)->program_id++;
+
+ tgsi_scan_shader(shader->tokens, &brw_vp->info);
+
+#if 0
+ brw_shader_info(shader->tokens,
+ &brw_vp->info2);
+#endif
+ tgsi_dump(shader->tokens, 0);
+
+ return (void *)brw_vp;
+}
+
+static void brw_bind_vs_state(struct pipe_context *pipe, void *vs)
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.VertexProgram = (struct brw_vertex_program *)vs;
+ brw->state.dirty.brw |= BRW_NEW_VS;
+
+ debug_printf("YYYYYYYYYYYYY BINDING VERTEX SHADER\n");
+}
+
+static void brw_delete_vs_state(struct pipe_context *pipe, void *shader)
+{
+ struct brw_vertex_program *brw_vp = (struct brw_vertex_program *) shader;
+
+ FREE((void *) brw_vp->program.tokens);
+ FREE(brw_vp);
+}
+
+
+static void brw_set_clip_state( struct pipe_context *pipe,
+ const struct pipe_clip_state *clip )
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.Clip = *clip;
+}
+
+
+static void brw_set_viewport_state( struct pipe_context *pipe,
+ const struct pipe_viewport_state *viewport )
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.Viewport = *viewport; /* struct copy */
+ brw->state.dirty.brw |= BRW_NEW_VIEWPORT;
+
+ /* pass the viewport info to the draw module */
+ //draw_set_viewport_state(brw->draw, viewport);
+}
+
+
+static void brw_set_vertex_buffers(struct pipe_context *pipe,
+ unsigned count,
+ const struct pipe_vertex_buffer *buffers)
+{
+ struct brw_context *brw = brw_context(pipe);
+ memcpy(brw->vb.vbo_array, buffers, count * sizeof(buffers[0]));
+}
+
+static void brw_set_vertex_elements(struct pipe_context *pipe,
+ unsigned count,
+ const struct pipe_vertex_element *elements)
+{
+ /* flush ? */
+ struct brw_context *brw = brw_context(pipe);
+ uint i;
+
+ assert(count <= PIPE_MAX_ATTRIBS);
+
+ for (i = 0; i < count; i++) {
+ struct brw_vertex_element_state el;
+ memset(&el, 0, sizeof(el));
+
+ el.ve0.src_offset = elements[i].src_offset;
+ el.ve0.src_format = brw_translate_surface_format(elements[i].src_format);
+ el.ve0.valid = 1;
+ el.ve0.vertex_buffer_index = elements[i].vertex_buffer_index;
+
+ el.ve1.dst_offset = i * 4;
+
+ el.ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_SRC;
+ el.ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_SRC;
+ el.ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_SRC;
+ el.ve1.vfcomponent0 = BRW_VFCOMPONENT_STORE_SRC;
+
+ switch (elements[i].nr_components) {
+ case 1: el.ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_0;
+ case 2: el.ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_0;
+ case 3: el.ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_1_FLT;
+ break;
+ }
+
+ brw->vb.inputs[i] = el;
+ }
+}
+
+
+
+/************************************************************************
+ * Constant buffers
+ */
+
+static void brw_set_constant_buffer(struct pipe_context *pipe,
+ uint shader, uint index,
+ const struct pipe_constant_buffer *buf)
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ assert(buf == 0 || index == 0);
+
+ brw->attribs.Constants[shader] = buf;
+ brw->state.dirty.brw |= BRW_NEW_CONSTANTS;
+}
+
+
+/************************************************************************
+ * Texture surfaces
+ */
+
+
+static void brw_set_sampler_textures(struct pipe_context *pipe,
+ unsigned num,
+ struct pipe_texture **texture)
+{
+ struct brw_context *brw = brw_context(pipe);
+ uint i;
+
+ assert(num <= PIPE_MAX_SAMPLERS);
+
+ /* Check for no-op */
+ if (num == brw->num_textures &&
+ !memcmp(brw->attribs.Texture, texture, num *
+ sizeof(struct pipe_texture *)))
+ return;
+
+ for (i = 0; i < num; i++)
+ pipe_texture_reference((struct pipe_texture **) &brw->attribs.Texture[i],
+ texture[i]);
+
+ for (i = num; i < brw->num_textures; i++)
+ pipe_texture_reference((struct pipe_texture **) &brw->attribs.Texture[i],
+ NULL);
+
+ brw->num_textures = num;
+
+ brw->state.dirty.brw |= BRW_NEW_TEXTURE;
+}
+
+
+/************************************************************************
+ * Render targets, etc
+ */
+
+static void brw_set_framebuffer_state(struct pipe_context *pipe,
+ const struct pipe_framebuffer_state *fb)
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.FrameBuffer = *fb; /* struct copy */
+
+ brw->state.dirty.brw |= BRW_NEW_FRAMEBUFFER;
+}
+
+
+
+/************************************************************************
+ * Rasterizer state
+ */
+
+static void *
+brw_create_rasterizer_state(struct pipe_context *pipe,
+ const struct pipe_rasterizer_state *rasterizer)
+{
+ DUP(pipe_rasterizer_state, rasterizer);
+}
+
+static void brw_bind_rasterizer_state( struct pipe_context *pipe,
+ void *setup )
+{
+ struct brw_context *brw = brw_context(pipe);
+
+ brw->attribs.Raster = (struct pipe_rasterizer_state *)setup;
+
+ /* Also pass-through to draw module:
+ */
+ //draw_set_rasterizer_state(brw->draw, setup);
+
+ brw->state.dirty.brw |= BRW_NEW_RASTERIZER;
+}
+
+static void brw_delete_rasterizer_state(struct pipe_context *pipe,
+ void *setup)
+{
+ free(setup);
+}
+
+
+
+void
+brw_init_state_functions( struct brw_context *brw )
+{
+ brw->pipe.create_blend_state = brw_create_blend_state;
+ brw->pipe.bind_blend_state = brw_bind_blend_state;
+ brw->pipe.delete_blend_state = brw_delete_blend_state;
+
+ brw->pipe.create_sampler_state = brw_create_sampler_state;
+ brw->pipe.bind_sampler_states = brw_bind_sampler_states;
+ brw->pipe.delete_sampler_state = brw_delete_sampler_state;
+
+ brw->pipe.create_depth_stencil_alpha_state = brw_create_depth_stencil_state;
+ brw->pipe.bind_depth_stencil_alpha_state = brw_bind_depth_stencil_state;
+ brw->pipe.delete_depth_stencil_alpha_state = brw_delete_depth_stencil_state;
+
+ brw->pipe.create_rasterizer_state = brw_create_rasterizer_state;
+ brw->pipe.bind_rasterizer_state = brw_bind_rasterizer_state;
+ brw->pipe.delete_rasterizer_state = brw_delete_rasterizer_state;
+ brw->pipe.create_fs_state = brw_create_fs_state;
+ brw->pipe.bind_fs_state = brw_bind_fs_state;
+ brw->pipe.delete_fs_state = brw_delete_fs_state;
+ brw->pipe.create_vs_state = brw_create_vs_state;
+ brw->pipe.bind_vs_state = brw_bind_vs_state;
+ brw->pipe.delete_vs_state = brw_delete_vs_state;
+
+ brw->pipe.set_blend_color = brw_set_blend_color;
+ brw->pipe.set_clip_state = brw_set_clip_state;
+ brw->pipe.set_constant_buffer = brw_set_constant_buffer;
+ brw->pipe.set_framebuffer_state = brw_set_framebuffer_state;
+
+// brw->pipe.set_feedback_state = brw_set_feedback_state;
+// brw->pipe.set_feedback_buffer = brw_set_feedback_buffer;
+
+ brw->pipe.set_polygon_stipple = brw_set_polygon_stipple;
+ brw->pipe.set_scissor_state = brw_set_scissor_state;
+ brw->pipe.set_sampler_textures = brw_set_sampler_textures;
+ brw->pipe.set_viewport_state = brw_set_viewport_state;
+ brw->pipe.set_vertex_buffers = brw_set_vertex_buffers;
+ brw->pipe.set_vertex_elements = brw_set_vertex_elements;
+}