1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/************************************************************************** 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved. 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish, 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions: 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software. 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/ 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_defines.h" 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_memory.h" 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "lp_context.h" 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "lp_state.h" 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "lp_setup.h" 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "draw/draw_context.h" 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct lp_rast_state { 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct pipe_rasterizer_state lp_state; 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct pipe_rasterizer_state draw_state; 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* State which might be handled in either the draw module or locally. 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * This function is used to turn that state off in one of the two 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * places. 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclear_flags(struct pipe_rasterizer_state *rast) 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org rast->light_twoside = 0; 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org rast->offset_tri = 0; 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void * 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgllvmpipe_create_rasterizer_state(struct pipe_context *pipe, 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct pipe_rasterizer_state *rast) 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org boolean need_pipeline; 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Partition rasterizer state into what we want the draw module to 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * handle, and what we'll look after ourselves. 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct lp_rast_state *state = MALLOC_STRUCT(lp_rast_state); 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (state == NULL) 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return NULL; 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org memcpy(&state->draw_state, rast, sizeof *rast); 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org memcpy(&state->lp_state, rast, sizeof *rast); 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* We rely on draw module to do unfilled polyons, AA lines and 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * points and stipple. 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Over time, reduce this list of conditions, and expand the list 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of flags which get cleared in clear_flags(). 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org need_pipeline = (rast->fill_front != PIPE_POLYGON_MODE_FILL || 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org rast->fill_back != PIPE_POLYGON_MODE_FILL || 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org rast->point_smooth || 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org rast->line_smooth || 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org rast->line_stipple_enable || 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org rast->poly_stipple_enable); 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* If not using the pipeline, clear out the flags which we can 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * handle ourselves. If we *are* using the pipeline, do everything 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * on the pipeline and clear those flags on our internal copy of 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the state. 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (need_pipeline) 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org clear_flags(&state->lp_state); 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org else 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org clear_flags(&state->draw_state); 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return state; 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgllvmpipe_bind_rasterizer_state(struct pipe_context *pipe, void *handle) 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct lp_rast_state *state = 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (const struct lp_rast_state *) handle; 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (state) { 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org llvmpipe->rasterizer = &state->lp_state; 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org draw_set_rasterizer_state(llvmpipe->draw, &state->draw_state, handle); 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* XXX: just pass lp_state directly to setup. 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org lp_setup_set_triangle_state( llvmpipe->setup, 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.cull_face, 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.front_ccw, 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.scissor, 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.gl_rasterization_rules); 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org lp_setup_set_flatshade_first( llvmpipe->setup, 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.flatshade_first); 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org lp_setup_set_line_state( llvmpipe->setup, 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.line_width); 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org lp_setup_set_point_state( llvmpipe->setup, 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.point_size, 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.point_size_per_vertex, 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.sprite_coord_enable, 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org state->lp_state.sprite_coord_mode); 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org else { 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org llvmpipe->rasterizer = NULL; 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org draw_set_rasterizer_state(llvmpipe->draw, NULL, handle); 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org llvmpipe->dirty |= LP_NEW_RASTERIZER; 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgllvmpipe_delete_rasterizer_state(struct pipe_context *pipe, 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void *rasterizer) 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org FREE( rasterizer ); 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgllvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe) 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org llvmpipe->pipe.create_rasterizer_state = llvmpipe_create_rasterizer_state; 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org llvmpipe->pipe.bind_rasterizer_state = llvmpipe_bind_rasterizer_state; 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org llvmpipe->pipe.delete_rasterizer_state = llvmpipe_delete_rasterizer_state; 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 150