1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc. 4bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc. 5bf215546Sopenharmony_ci * All Rights Reserved. 6bf215546Sopenharmony_ci * 7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 9bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 10bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 11bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 12bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 13bf215546Sopenharmony_ci * the following conditions: 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 16bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 17bf215546Sopenharmony_ci * of the Software. 18bf215546Sopenharmony_ci * 19bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 23bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26bf215546Sopenharmony_ci * 27bf215546Sopenharmony_ci **************************************************************************/ 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci/** 30bf215546Sopenharmony_ci * @author Jose Fonseca <jfonseca@vmware.com> 31bf215546Sopenharmony_ci * @author Keith Whitwell <keithw@vmware.com> 32bf215546Sopenharmony_ci */ 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#include "util/u_memory.h" 35bf215546Sopenharmony_ci#include "util/u_math.h" 36bf215546Sopenharmony_ci#include "util/u_dump.h" 37bf215546Sopenharmony_ci#include "draw/draw_context.h" 38bf215546Sopenharmony_ci#include "lp_screen.h" 39bf215546Sopenharmony_ci#include "lp_context.h" 40bf215546Sopenharmony_ci#include "lp_state.h" 41bf215546Sopenharmony_ci#include "lp_debug.h" 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_cistatic void * 45bf215546Sopenharmony_cillvmpipe_create_blend_state(struct pipe_context *pipe, 46bf215546Sopenharmony_ci const struct pipe_blend_state *blend) 47bf215546Sopenharmony_ci{ 48bf215546Sopenharmony_ci struct pipe_blend_state *state = mem_dup(blend, sizeof *blend); 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_ci if (LP_PERF & PERF_NO_BLEND) { 51bf215546Sopenharmony_ci state->independent_blend_enable = 0; 52bf215546Sopenharmony_ci for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; i++) 53bf215546Sopenharmony_ci state->rt[i].blend_enable = 0; 54bf215546Sopenharmony_ci } 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci return state; 57bf215546Sopenharmony_ci} 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_cistatic void 61bf215546Sopenharmony_cillvmpipe_bind_blend_state(struct pipe_context *pipe, void *blend) 62bf215546Sopenharmony_ci{ 63bf215546Sopenharmony_ci struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci if (llvmpipe->blend == blend) 66bf215546Sopenharmony_ci return; 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci draw_flush(llvmpipe->draw); 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci llvmpipe->blend = blend; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci llvmpipe->dirty |= LP_NEW_BLEND; 73bf215546Sopenharmony_ci} 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_cistatic void 77bf215546Sopenharmony_cillvmpipe_delete_blend_state(struct pipe_context *pipe, void *blend) 78bf215546Sopenharmony_ci{ 79bf215546Sopenharmony_ci FREE(blend); 80bf215546Sopenharmony_ci} 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_cistatic void 84bf215546Sopenharmony_cillvmpipe_set_blend_color(struct pipe_context *pipe, 85bf215546Sopenharmony_ci const struct pipe_blend_color *blend_color) 86bf215546Sopenharmony_ci{ 87bf215546Sopenharmony_ci struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci if (!blend_color) 90bf215546Sopenharmony_ci return; 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci if (memcmp(&llvmpipe->blend_color, blend_color, sizeof *blend_color) == 0) 93bf215546Sopenharmony_ci return; 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci draw_flush(llvmpipe->draw); 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci memcpy(&llvmpipe->blend_color, blend_color, sizeof *blend_color); 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci llvmpipe->dirty |= LP_NEW_BLEND_COLOR; 100bf215546Sopenharmony_ci} 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci/** XXX move someday? Or consolidate all these simple state setters 104bf215546Sopenharmony_ci * into one file. 105bf215546Sopenharmony_ci */ 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_cistatic void * 109bf215546Sopenharmony_cillvmpipe_create_depth_stencil_state(struct pipe_context *pipe, 110bf215546Sopenharmony_ci const struct pipe_depth_stencil_alpha_state *depth_stencil) 111bf215546Sopenharmony_ci{ 112bf215546Sopenharmony_ci struct pipe_depth_stencil_alpha_state *state; 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci state = mem_dup(depth_stencil, sizeof *depth_stencil); 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci if (LP_PERF & PERF_NO_DEPTH) { 117bf215546Sopenharmony_ci state->depth_enabled = 0; 118bf215546Sopenharmony_ci state->depth_writemask = 0; 119bf215546Sopenharmony_ci state->stencil[0].enabled = 0; 120bf215546Sopenharmony_ci state->stencil[1].enabled = 0; 121bf215546Sopenharmony_ci } 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci if (LP_PERF & PERF_NO_ALPHATEST) { 124bf215546Sopenharmony_ci state->alpha_enabled = 0; 125bf215546Sopenharmony_ci } 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci return state; 128bf215546Sopenharmony_ci} 129bf215546Sopenharmony_ci 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_cistatic void 132bf215546Sopenharmony_cillvmpipe_bind_depth_stencil_state(struct pipe_context *pipe, 133bf215546Sopenharmony_ci void *depth_stencil) 134bf215546Sopenharmony_ci{ 135bf215546Sopenharmony_ci struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci if (llvmpipe->depth_stencil == depth_stencil) 138bf215546Sopenharmony_ci return; 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci draw_flush(llvmpipe->draw); 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci llvmpipe->depth_stencil = depth_stencil; 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci llvmpipe->dirty |= LP_NEW_DEPTH_STENCIL_ALPHA; 145bf215546Sopenharmony_ci} 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_cistatic void 149bf215546Sopenharmony_cillvmpipe_delete_depth_stencil_state(struct pipe_context *pipe, void *depth) 150bf215546Sopenharmony_ci{ 151bf215546Sopenharmony_ci FREE(depth); 152bf215546Sopenharmony_ci} 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_cistatic void 156bf215546Sopenharmony_cillvmpipe_set_stencil_ref(struct pipe_context *pipe, 157bf215546Sopenharmony_ci const struct pipe_stencil_ref stencil_ref) 158bf215546Sopenharmony_ci{ 159bf215546Sopenharmony_ci struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci if (memcmp(&llvmpipe->stencil_ref, &stencil_ref, sizeof stencil_ref) == 0) 162bf215546Sopenharmony_ci return; 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci draw_flush(llvmpipe->draw); 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ci memcpy(&llvmpipe->stencil_ref, &stencil_ref, sizeof stencil_ref); 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ci /* not sure. want new flag? */ 169bf215546Sopenharmony_ci llvmpipe->dirty |= LP_NEW_DEPTH_STENCIL_ALPHA; 170bf215546Sopenharmony_ci} 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_cistatic void 173bf215546Sopenharmony_cillvmpipe_set_sample_mask(struct pipe_context *pipe, 174bf215546Sopenharmony_ci unsigned sample_mask) 175bf215546Sopenharmony_ci{ 176bf215546Sopenharmony_ci struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci if (sample_mask != llvmpipe->sample_mask) { 179bf215546Sopenharmony_ci draw_flush(llvmpipe->draw); 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_ci llvmpipe->sample_mask = sample_mask; 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_ci llvmpipe->dirty |= LP_NEW_SAMPLE_MASK; 184bf215546Sopenharmony_ci } 185bf215546Sopenharmony_ci} 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_cistatic void 188bf215546Sopenharmony_cillvmpipe_set_min_samples(struct pipe_context *pipe, 189bf215546Sopenharmony_ci unsigned min_samples) 190bf215546Sopenharmony_ci{ 191bf215546Sopenharmony_ci struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci if (min_samples != llvmpipe->min_samples) { 194bf215546Sopenharmony_ci llvmpipe->min_samples = min_samples; 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci llvmpipe->dirty |= LP_NEW_FS; 197bf215546Sopenharmony_ci } 198bf215546Sopenharmony_ci} 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_civoid 201bf215546Sopenharmony_cillvmpipe_init_blend_funcs(struct llvmpipe_context *llvmpipe) 202bf215546Sopenharmony_ci{ 203bf215546Sopenharmony_ci llvmpipe->pipe.create_blend_state = llvmpipe_create_blend_state; 204bf215546Sopenharmony_ci llvmpipe->pipe.bind_blend_state = llvmpipe_bind_blend_state; 205bf215546Sopenharmony_ci llvmpipe->pipe.delete_blend_state = llvmpipe_delete_blend_state; 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci llvmpipe->pipe.create_depth_stencil_alpha_state = llvmpipe_create_depth_stencil_state; 208bf215546Sopenharmony_ci llvmpipe->pipe.bind_depth_stencil_alpha_state = llvmpipe_bind_depth_stencil_state; 209bf215546Sopenharmony_ci llvmpipe->pipe.delete_depth_stencil_alpha_state = llvmpipe_delete_depth_stencil_state; 210bf215546Sopenharmony_ci 211bf215546Sopenharmony_ci llvmpipe->pipe.set_blend_color = llvmpipe_set_blend_color; 212bf215546Sopenharmony_ci 213bf215546Sopenharmony_ci llvmpipe->pipe.set_stencil_ref = llvmpipe_set_stencil_ref; 214bf215546Sopenharmony_ci llvmpipe->pipe.set_sample_mask = llvmpipe_set_sample_mask; 215bf215546Sopenharmony_ci llvmpipe->pipe.set_min_samples = llvmpipe_set_min_samples; 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci llvmpipe->dirty |= LP_NEW_SAMPLE_MASK; 218bf215546Sopenharmony_ci llvmpipe->sample_mask = ~0; 219bf215546Sopenharmony_ci} 220