1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci/* 28bf215546Sopenharmony_ci * Authors: 29bf215546Sopenharmony_ci * Keith Whitwell <keithw@vmware.com> 30bf215546Sopenharmony_ci */ 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "util/u_memory.h" 33bf215546Sopenharmony_ci#include "i915_context.h" 34bf215546Sopenharmony_ci#include "i915_reg.h" 35bf215546Sopenharmony_ci#include "i915_state.h" 36bf215546Sopenharmony_ci#include "i915_state_inlines.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci/* Convinience function to check immediate state. 39bf215546Sopenharmony_ci */ 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_cistatic inline void 42bf215546Sopenharmony_ciset_immediate(struct i915_context *i915, unsigned offset, const unsigned state) 43bf215546Sopenharmony_ci{ 44bf215546Sopenharmony_ci if (i915->current.immediate[offset] == state) 45bf215546Sopenharmony_ci return; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci i915->current.immediate[offset] = state; 48bf215546Sopenharmony_ci i915->immediate_dirty |= 1 << offset; 49bf215546Sopenharmony_ci i915->hardware_dirty |= I915_HW_IMMEDIATE; 50bf215546Sopenharmony_ci} 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci/*********************************************************************** 53bf215546Sopenharmony_ci * S0,S1: Vertex buffer state. 54bf215546Sopenharmony_ci */ 55bf215546Sopenharmony_cistatic void 56bf215546Sopenharmony_ciupload_S0S1(struct i915_context *i915) 57bf215546Sopenharmony_ci{ 58bf215546Sopenharmony_ci unsigned LIS0, LIS1; 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci /* I915_NEW_VBO 61bf215546Sopenharmony_ci */ 62bf215546Sopenharmony_ci LIS0 = i915->vbo_offset; 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci /* Need to force this */ 65bf215546Sopenharmony_ci if (i915->dirty & I915_NEW_VBO) { 66bf215546Sopenharmony_ci i915->immediate_dirty |= 1 << I915_IMMEDIATE_S0; 67bf215546Sopenharmony_ci i915->hardware_dirty |= I915_HW_IMMEDIATE; 68bf215546Sopenharmony_ci } 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci /* I915_NEW_VERTEX_SIZE 71bf215546Sopenharmony_ci */ 72bf215546Sopenharmony_ci { 73bf215546Sopenharmony_ci unsigned vertex_size = i915->current.vertex_info.size; 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci LIS1 = ((vertex_size << 24) | (vertex_size << 16)); 76bf215546Sopenharmony_ci } 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci set_immediate(i915, I915_IMMEDIATE_S0, LIS0); 79bf215546Sopenharmony_ci set_immediate(i915, I915_IMMEDIATE_S1, LIS1); 80bf215546Sopenharmony_ci} 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ciconst struct i915_tracked_state i915_upload_S0S1 = { 83bf215546Sopenharmony_ci "imm S0 S1", upload_S0S1, I915_NEW_VBO | I915_NEW_VERTEX_FORMAT}; 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci/*********************************************************************** 86bf215546Sopenharmony_ci * S4: Vertex format, rasterization state 87bf215546Sopenharmony_ci */ 88bf215546Sopenharmony_cistatic void 89bf215546Sopenharmony_ciupload_S2S4(struct i915_context *i915) 90bf215546Sopenharmony_ci{ 91bf215546Sopenharmony_ci unsigned LIS2, LIS4; 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci /* I915_NEW_VERTEX_FORMAT 94bf215546Sopenharmony_ci */ 95bf215546Sopenharmony_ci { 96bf215546Sopenharmony_ci LIS2 = i915->current.vertex_info.hwfmt[1]; 97bf215546Sopenharmony_ci LIS4 = i915->current.vertex_info.hwfmt[0]; 98bf215546Sopenharmony_ci assert(LIS4); /* should never be zero? */ 99bf215546Sopenharmony_ci } 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci LIS4 |= i915->rasterizer->LIS4; 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci set_immediate(i915, I915_IMMEDIATE_S2, LIS2); 104bf215546Sopenharmony_ci set_immediate(i915, I915_IMMEDIATE_S4, LIS4); 105bf215546Sopenharmony_ci} 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ciconst struct i915_tracked_state i915_upload_S2S4 = { 108bf215546Sopenharmony_ci "imm S2 S4", upload_S2S4, I915_NEW_RASTERIZER | I915_NEW_VERTEX_FORMAT}; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci/*********************************************************************** 111bf215546Sopenharmony_ci */ 112bf215546Sopenharmony_cistatic void 113bf215546Sopenharmony_ciupload_S5(struct i915_context *i915) 114bf215546Sopenharmony_ci{ 115bf215546Sopenharmony_ci unsigned LIS5 = 0; 116bf215546Sopenharmony_ci bool stencil_ccw = i915_stencil_ccw(i915); 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ci /* I915_NEW_DEPTH_STENCIL 119bf215546Sopenharmony_ci */ 120bf215546Sopenharmony_ci if (stencil_ccw) 121bf215546Sopenharmony_ci LIS5 |= i915->depth_stencil->stencil_LIS5_ccw; 122bf215546Sopenharmony_ci else 123bf215546Sopenharmony_ci LIS5 |= i915->depth_stencil->stencil_LIS5_cw; 124bf215546Sopenharmony_ci /* hope it's safe to set stencil ref value even if stencil test is disabled? 125bf215546Sopenharmony_ci */ 126bf215546Sopenharmony_ci LIS5 |= i915->stencil_ref.ref_value[stencil_ccw] << S5_STENCIL_REF_SHIFT; 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci /* I915_NEW_BLEND 129bf215546Sopenharmony_ci */ 130bf215546Sopenharmony_ci LIS5 |= i915->blend->LIS5; 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci#if 0 133bf215546Sopenharmony_ci /* I915_NEW_RASTERIZER 134bf215546Sopenharmony_ci */ 135bf215546Sopenharmony_ci if (i915->rasterizer->LIS7) { 136bf215546Sopenharmony_ci LIS5 |= S5_GLOBAL_DEPTH_OFFSET_ENABLE; 137bf215546Sopenharmony_ci } 138bf215546Sopenharmony_ci#endif 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci set_immediate(i915, I915_IMMEDIATE_S5, LIS5); 141bf215546Sopenharmony_ci} 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ciconst struct i915_tracked_state i915_upload_S5 = { 144bf215546Sopenharmony_ci "imm S5", upload_S5, 145bf215546Sopenharmony_ci I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_RASTERIZER}; 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci/*********************************************************************** 148bf215546Sopenharmony_ci */ 149bf215546Sopenharmony_cistatic void 150bf215546Sopenharmony_ciupload_S6(struct i915_context *i915) 151bf215546Sopenharmony_ci{ 152bf215546Sopenharmony_ci unsigned LIS6 = 0; 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_ci /* I915_NEW_FRAMEBUFFER 155bf215546Sopenharmony_ci */ 156bf215546Sopenharmony_ci if (i915->framebuffer.cbufs[0]) 157bf215546Sopenharmony_ci LIS6 |= S6_COLOR_WRITE_ENABLE; 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_ci /* I915_NEW_BLEND 160bf215546Sopenharmony_ci */ 161bf215546Sopenharmony_ci if (i915->blend) { 162bf215546Sopenharmony_ci struct i915_surface *cbuf = i915_surface(i915->framebuffer.cbufs[0]); 163bf215546Sopenharmony_ci if (cbuf && cbuf->alpha_in_g) 164bf215546Sopenharmony_ci LIS6 |= i915->blend->LIS6_alpha_in_g; 165bf215546Sopenharmony_ci else if (cbuf && cbuf->alpha_is_x) 166bf215546Sopenharmony_ci LIS6 |= i915->blend->LIS6_alpha_is_x; 167bf215546Sopenharmony_ci else 168bf215546Sopenharmony_ci LIS6 |= i915->blend->LIS6; 169bf215546Sopenharmony_ci } 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci /* I915_NEW_DEPTH 172bf215546Sopenharmony_ci */ 173bf215546Sopenharmony_ci if (i915->depth_stencil) 174bf215546Sopenharmony_ci LIS6 |= i915->depth_stencil->depth_LIS6; 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci if (i915->rasterizer) 177bf215546Sopenharmony_ci LIS6 |= i915->rasterizer->LIS6; 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_ci set_immediate(i915, I915_IMMEDIATE_S6, LIS6); 180bf215546Sopenharmony_ci} 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ciconst struct i915_tracked_state i915_upload_S6 = { 183bf215546Sopenharmony_ci "imm S6", upload_S6, 184bf215546Sopenharmony_ci I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL | I915_NEW_FRAMEBUFFER | 185bf215546Sopenharmony_ci I915_NEW_RASTERIZER}; 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci/*********************************************************************** 188bf215546Sopenharmony_ci */ 189bf215546Sopenharmony_cistatic void 190bf215546Sopenharmony_ciupload_S7(struct i915_context *i915) 191bf215546Sopenharmony_ci{ 192bf215546Sopenharmony_ci#if 0 193bf215546Sopenharmony_ci unsigned LIS7; 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci /* I915_NEW_RASTERIZER 196bf215546Sopenharmony_ci */ 197bf215546Sopenharmony_ci LIS7 = i915->rasterizer->LIS7; 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci set_immediate(i915, I915_IMMEDIATE_S7, LIS7); 200bf215546Sopenharmony_ci#endif 201bf215546Sopenharmony_ci} 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ciconst struct i915_tracked_state i915_upload_S7 = {"imm S7", upload_S7, 204bf215546Sopenharmony_ci I915_NEW_RASTERIZER}; 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_ci/*********************************************************************** 207bf215546Sopenharmony_ci */ 208bf215546Sopenharmony_cistatic const struct i915_tracked_state *atoms[] = { 209bf215546Sopenharmony_ci &i915_upload_S0S1, &i915_upload_S2S4, &i915_upload_S5, &i915_upload_S6, 210bf215546Sopenharmony_ci &i915_upload_S7}; 211bf215546Sopenharmony_ci 212bf215546Sopenharmony_cistatic void 213bf215546Sopenharmony_ciupdate_immediate(struct i915_context *i915) 214bf215546Sopenharmony_ci{ 215bf215546Sopenharmony_ci int i; 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(atoms); i++) 218bf215546Sopenharmony_ci if (i915->dirty & atoms[i]->dirty) 219bf215546Sopenharmony_ci atoms[i]->update(i915); 220bf215546Sopenharmony_ci} 221bf215546Sopenharmony_ci 222bf215546Sopenharmony_cistruct i915_tracked_state i915_hw_immediate = { 223bf215546Sopenharmony_ci "immediate", update_immediate, 224bf215546Sopenharmony_ci ~0 /* all state atoms, because we do internal checking */ 225bf215546Sopenharmony_ci}; 226