Path: blob/21.2-virgl/src/gallium/drivers/i915/i915_state_immediate.c
4570 views
/**************************************************************************1*2* Copyright 2007 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/26/*27* Authors:28* Keith Whitwell <[email protected]>29*/3031#include "util/u_memory.h"32#include "i915_context.h"33#include "i915_reg.h"34#include "i915_state.h"35#include "i915_state_inlines.h"3637/* Convinience function to check immediate state.38*/3940static inline void41set_immediate(struct i915_context *i915, unsigned offset, const unsigned state)42{43if (i915->current.immediate[offset] == state)44return;4546i915->current.immediate[offset] = state;47i915->immediate_dirty |= 1 << offset;48i915->hardware_dirty |= I915_HW_IMMEDIATE;49}5051/***********************************************************************52* S0,S1: Vertex buffer state.53*/54static void55upload_S0S1(struct i915_context *i915)56{57unsigned LIS0, LIS1;5859/* I915_NEW_VBO60*/61LIS0 = i915->vbo_offset;6263/* Need to force this */64if (i915->dirty & I915_NEW_VBO) {65i915->immediate_dirty |= 1 << I915_IMMEDIATE_S0;66i915->hardware_dirty |= I915_HW_IMMEDIATE;67}6869/* I915_NEW_VERTEX_SIZE70*/71{72unsigned vertex_size = i915->current.vertex_info.size;7374LIS1 = ((vertex_size << 24) | (vertex_size << 16));75}7677set_immediate(i915, I915_IMMEDIATE_S0, LIS0);78set_immediate(i915, I915_IMMEDIATE_S1, LIS1);79}8081const struct i915_tracked_state i915_upload_S0S1 = {82"imm S0 S1", upload_S0S1, I915_NEW_VBO | I915_NEW_VERTEX_FORMAT};8384/***********************************************************************85* S4: Vertex format, rasterization state86*/87static void88upload_S2S4(struct i915_context *i915)89{90unsigned LIS2, LIS4;9192/* I915_NEW_VERTEX_FORMAT93*/94{95LIS2 = i915->current.vertex_info.hwfmt[1];96LIS4 = i915->current.vertex_info.hwfmt[0];97assert(LIS4); /* should never be zero? */98}99100LIS4 |= i915->rasterizer->LIS4;101102set_immediate(i915, I915_IMMEDIATE_S2, LIS2);103set_immediate(i915, I915_IMMEDIATE_S4, LIS4);104}105106const struct i915_tracked_state i915_upload_S2S4 = {107"imm S2 S4", upload_S2S4, I915_NEW_RASTERIZER | I915_NEW_VERTEX_FORMAT};108109/***********************************************************************110*/111static void112upload_S5(struct i915_context *i915)113{114unsigned LIS5 = 0;115bool stencil_ccw = i915_stencil_ccw(i915);116117/* I915_NEW_DEPTH_STENCIL118*/119if (stencil_ccw)120LIS5 |= i915->depth_stencil->stencil_LIS5_ccw;121else122LIS5 |= i915->depth_stencil->stencil_LIS5_cw;123/* hope it's safe to set stencil ref value even if stencil test is disabled?124*/125LIS5 |= i915->stencil_ref.ref_value[stencil_ccw] << S5_STENCIL_REF_SHIFT;126127/* I915_NEW_BLEND128*/129LIS5 |= i915->blend->LIS5;130131#if 0132/* I915_NEW_RASTERIZER133*/134if (i915->rasterizer->LIS7) {135LIS5 |= S5_GLOBAL_DEPTH_OFFSET_ENABLE;136}137#endif138139set_immediate(i915, I915_IMMEDIATE_S5, LIS5);140}141142const struct i915_tracked_state i915_upload_S5 = {143"imm S5", upload_S5,144I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_RASTERIZER};145146/***********************************************************************147*/148static void149upload_S6(struct i915_context *i915)150{151unsigned LIS6 = 0;152153/* I915_NEW_FRAMEBUFFER154*/155if (i915->framebuffer.cbufs[0])156LIS6 |= S6_COLOR_WRITE_ENABLE;157158/* I915_NEW_BLEND159*/160if (i915->blend) {161struct i915_surface *cbuf = i915_surface(i915->framebuffer.cbufs[0]);162if (cbuf && cbuf->alpha_in_g)163LIS6 |= i915->blend->LIS6_alpha_in_g;164else if (cbuf && cbuf->alpha_is_x)165LIS6 |= i915->blend->LIS6_alpha_is_x;166else167LIS6 |= i915->blend->LIS6;168}169170/* I915_NEW_DEPTH171*/172if (i915->depth_stencil)173LIS6 |= i915->depth_stencil->depth_LIS6;174175if (i915->rasterizer)176LIS6 |= i915->rasterizer->LIS6;177178set_immediate(i915, I915_IMMEDIATE_S6, LIS6);179}180181const struct i915_tracked_state i915_upload_S6 = {182"imm S6", upload_S6,183I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL | I915_NEW_FRAMEBUFFER |184I915_NEW_RASTERIZER};185186/***********************************************************************187*/188static void189upload_S7(struct i915_context *i915)190{191#if 0192unsigned LIS7;193194/* I915_NEW_RASTERIZER195*/196LIS7 = i915->rasterizer->LIS7;197198set_immediate(i915, I915_IMMEDIATE_S7, LIS7);199#endif200}201202const struct i915_tracked_state i915_upload_S7 = {"imm S7", upload_S7,203I915_NEW_RASTERIZER};204205/***********************************************************************206*/207static const struct i915_tracked_state *atoms[] = {208&i915_upload_S0S1, &i915_upload_S2S4, &i915_upload_S5, &i915_upload_S6,209&i915_upload_S7};210211static void212update_immediate(struct i915_context *i915)213{214int i;215216for (i = 0; i < ARRAY_SIZE(atoms); i++)217if (i915->dirty & atoms[i]->dirty)218atoms[i]->update(i915);219}220221struct i915_tracked_state i915_hw_immediate = {222"immediate", update_immediate,223~0 /* all state atoms, because we do internal checking */224};225226227