Path: blob/21.2-virgl/src/gallium/drivers/i915/i915_state_static.c
4570 views
/**************************************************************************1*2* Copyright © 2010 Jakob Bornecrantz3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23**************************************************************************/2425#include "i915_context.h"26#include "i915_reg.h"27#include "i915_resource.h"28#include "i915_screen.h"29#include "i915_state.h"3031/***********************************************************************32* Update framebuffer state33*/34static unsigned35translate_format(enum pipe_format format)36{37switch (format) {38case PIPE_FORMAT_B8G8R8A8_UNORM:39case PIPE_FORMAT_B8G8R8A8_SRGB:40case PIPE_FORMAT_B8G8R8X8_UNORM:41case PIPE_FORMAT_R8G8B8A8_UNORM:42case PIPE_FORMAT_R8G8B8X8_UNORM:43return COLOR_BUF_ARGB8888;44case PIPE_FORMAT_B5G6R5_UNORM:45return COLOR_BUF_RGB565;46case PIPE_FORMAT_B5G5R5A1_UNORM:47return COLOR_BUF_ARGB1555;48case PIPE_FORMAT_B4G4R4A4_UNORM:49return COLOR_BUF_ARGB4444;50case PIPE_FORMAT_B10G10R10A2_UNORM:51return COLOR_BUF_ARGB2101010;52case PIPE_FORMAT_L8_UNORM:53case PIPE_FORMAT_A8_UNORM:54case PIPE_FORMAT_I8_UNORM:55return COLOR_BUF_8BIT;56default:57assert(0);58return 0;59}60}6162static unsigned63translate_depth_format(enum pipe_format zformat)64{65switch (zformat) {66case PIPE_FORMAT_Z24X8_UNORM:67case PIPE_FORMAT_Z24_UNORM_S8_UINT:68return DEPTH_FRMT_24_FIXED_8_OTHER;69case PIPE_FORMAT_Z16_UNORM:70return DEPTH_FRMT_16_FIXED;71default:72assert(0);73return 0;74}75}7677static void78update_framebuffer(struct i915_context *i915)79{80struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];81struct pipe_surface *depth_surface = i915->framebuffer.zsbuf;82unsigned x, y;83int layer;84uint32_t draw_offset, draw_size;8586if (cbuf_surface) {87struct i915_surface *surf = i915_surface(cbuf_surface);88struct i915_texture *tex = i915_texture(cbuf_surface->texture);89assert(tex);9091i915->current.cbuf_bo = tex->buffer;92i915->current.cbuf_flags = surf->buf_info;9394layer = cbuf_surface->u.tex.first_layer;9596x = tex->image_offset[cbuf_surface->u.tex.level][layer].nblocksx;97y = tex->image_offset[cbuf_surface->u.tex.level][layer].nblocksy;98} else {99i915->current.cbuf_bo = NULL;100x = y = 0;101}102i915->static_dirty |= I915_DST_BUF_COLOR;103104/* What happens if no zbuf??105*/106if (depth_surface) {107struct i915_surface *surf = i915_surface(depth_surface);108struct i915_texture *tex = i915_texture(depth_surface->texture);109unsigned offset = i915_texture_offset(tex, depth_surface->u.tex.level,110depth_surface->u.tex.first_layer);111assert(tex);112if (offset != 0)113debug_printf("Depth offset is %d\n", offset);114115i915->current.depth_bo = tex->buffer;116i915->current.depth_flags = surf->buf_info;117} else118i915->current.depth_bo = NULL;119i915->static_dirty |= I915_DST_BUF_DEPTH;120121/* drawing rect calculations */122draw_offset = x | (y << 16);123draw_size = (i915->framebuffer.width - 1 + x) |124((i915->framebuffer.height - 1 + y) << 16);125if (i915->current.draw_offset != draw_offset) {126i915->current.draw_offset = draw_offset;127i915_set_flush_dirty(i915, I915_PIPELINE_FLUSH);128i915->static_dirty |= I915_DST_RECT;129}130if (i915->current.draw_size != draw_size) {131i915->current.draw_size = draw_size;132i915->static_dirty |= I915_DST_RECT;133}134135i915->hardware_dirty |= I915_HW_STATIC;136137/* flush the cache in case we sample from the old renderbuffers */138i915_set_flush_dirty(i915, I915_FLUSH_CACHE);139}140141struct i915_tracked_state i915_hw_framebuffer = {142"framebuffer", update_framebuffer, I915_NEW_FRAMEBUFFER};143144static void145update_dst_buf_vars(struct i915_context *i915)146{147struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];148struct pipe_surface *depth_surface = i915->framebuffer.zsbuf;149uint32_t dst_buf_vars, cformat, zformat;150uint32_t early_z = 0;151152if (cbuf_surface)153cformat = cbuf_surface->format;154else155cformat = PIPE_FORMAT_B8G8R8A8_UNORM; /* arbitrary */156cformat = translate_format(cformat);157158if (depth_surface) {159struct i915_texture *tex = i915_texture(depth_surface->texture);160struct i915_screen *is = i915_screen(i915->base.screen);161162zformat = translate_depth_format(depth_surface->format);163164if (is->is_i945 && tex->tiling != I915_TILE_NONE &&165(i915->fs && !i915->fs->info.writes_z))166early_z = CLASSIC_EARLY_DEPTH;167} else168zformat = 0;169170dst_buf_vars = DSTORG_HORT_BIAS(0x8) | /* .5 */171DSTORG_VERT_BIAS(0x8) | /* .5 */172LOD_PRECLAMP_OGL | TEX_DEFAULT_COLOR_OGL | cformat | zformat |173early_z;174175if (i915->current.dst_buf_vars != dst_buf_vars) {176if (early_z != (i915->current.dst_buf_vars & CLASSIC_EARLY_DEPTH))177i915_set_flush_dirty(i915, I915_PIPELINE_FLUSH);178179i915->current.dst_buf_vars = dst_buf_vars;180i915->static_dirty |= I915_DST_VARS;181i915->hardware_dirty |= I915_HW_STATIC;182}183}184185struct i915_tracked_state i915_hw_dst_buf_vars = {186"dst buf vars", update_dst_buf_vars, I915_NEW_FRAMEBUFFER | I915_NEW_FS};187188189