intel_mipmap_tree.c revision 747f0307626ef5bcf2f889ab66bcc95ab8eda2c8
177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/************************************************************************** 277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * 377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. 477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * All Rights Reserved. 577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * 677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Permission is hereby granted, free of charge, to any person obtaining a 777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * copy of this software and associated documentation files (the 877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * "Software"), to deal in the Software without restriction, including 977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * without limitation the rights to use, copy, modify, merge, publish, 1077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * distribute, sub license, and/or sell copies of the Software, and to 1177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * permit persons to whom the Software is furnished to do so, subject to 1277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * the following conditions: 1377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * 1477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * The above copyright notice and this permission notice (including the 1577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * next paragraph) shall be included in all copies or substantial portions 1677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * of the Software. 1777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * 1877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 2177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 2277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * 2677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt **************************************************************************/ 2777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 283eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace#include "intel_batchbuffer.h" 2977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_context.h" 3077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_mipmap_tree.h" 3177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_regions.h" 322945abea338031cbe90665df60152982bfca6177Chad Versace#include "intel_resolve_map.h" 333eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace#include "intel_span.h" 343732d0a77d2cbae50874f5a4ebdb3d8f06021a57Brian Paul#include "intel_tex_layout.h" 356dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt#include "intel_tex.h" 36b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt#include "intel_blit.h" 373eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace 38ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h" 39c374487a54aca2dd1053645092367c1cf0414ef7Eric Anholt#include "main/formats.h" 403eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace#include "main/image.h" 41b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt#include "main/teximage.h" 4277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 4377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#define FILE_DEBUG_FLAG DEBUG_MIPTREE 4477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 4577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic GLenum 4677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholttarget_to_target(GLenum target) 4777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 4877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt switch (target) { 4977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: 5077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: 5177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: 5277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: 5377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: 5477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: 5577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt return GL_TEXTURE_CUBE_MAP_ARB; 5677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt default: 5777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt return target; 5877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt } 5977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt} 6077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 616d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstatic struct intel_mipmap_tree * 626d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create_internal(struct intel_context *intel, 636d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg GLenum target, 64d5809115b568d8b74f47316607dce0730964517aEric Anholt gl_format format, 655b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt GLuint first_level, 665b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt GLuint last_level, 676d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg GLuint width0, 686d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg GLuint height0, 6936a91e45f755af164232ef908419bc4cb64ba45bIan Romanick GLuint depth0) 7077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 7177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt struct intel_mipmap_tree *mt = calloc(sizeof(*mt), 1); 726dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt int compress_byte = 0; 7377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 745b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt DBG("%s target %s format %s level %d..%d <-- %p\n", __FUNCTION__, 7577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt _mesa_lookup_enum_by_nr(target), 769a523a48af05118424714f0a34ca3dda6861186aEric Anholt _mesa_get_format_name(format), 775b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt first_level, last_level, mt); 7877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 796dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt if (_mesa_is_format_compressed(format)) 806dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt compress_byte = intel_compressed_num_bytes(format); 816dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt 8277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt mt->target = target_to_target(target); 83d5809115b568d8b74f47316607dce0730964517aEric Anholt mt->format = format; 845b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt mt->first_level = first_level; 855b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt mt->last_level = last_level; 8677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt mt->width0 = width0; 8777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt mt->height0 = height0; 88f94fef83db10f0c9327bd3dd43510ad31c94d82aEric Anholt mt->cpp = compress_byte ? compress_byte : _mesa_get_format_bytes(mt->format); 8977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt mt->compressed = compress_byte ? 1 : 0; 9077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt mt->refcount = 1; 9177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 92d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace if (target == GL_TEXTURE_CUBE_MAP) { 93d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace assert(depth0 == 1); 94d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace mt->depth0 = 6; 95d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace } else { 96d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace mt->depth0 = depth0; 97d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace } 98d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace 993eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace if (format == MESA_FORMAT_S8) { 1003eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace /* The stencil buffer has quirky pitch requirements. From Vol 2a, 1013eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch": 1023eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * The pitch must be set to 2x the value computed based on width, as 1033eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * the stencil buffer is stored with two rows interleaved. 1043eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace */ 1053eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace assert(intel->has_separate_stencil); 1063eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace mt->cpp = 2; 1073eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace } 1083eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace 1095c9a55665d78b96bfb8ce8eab43b5558dd656a6dEric Anholt if (_mesa_is_depthstencil_format(_mesa_get_format_base_format(format)) && 1105c9a55665d78b96bfb8ce8eab43b5558dd656a6dEric Anholt (intel->must_use_separate_stencil || 1115c9a55665d78b96bfb8ce8eab43b5558dd656a6dEric Anholt (intel->has_separate_stencil && 1125c9a55665d78b96bfb8ce8eab43b5558dd656a6dEric Anholt intel->vtbl.is_hiz_depth_format(intel, format)))) { 1133eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace mt->stencil_mt = intel_miptree_create(intel, 1143eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace mt->target, 1153eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace MESA_FORMAT_S8, 1163eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace mt->first_level, 1173eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace mt->last_level, 1183eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace mt->width0, 1193eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace mt->height0, 1203eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace mt->depth0, 1213eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace true); 1223eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace if (!mt->stencil_mt) { 1233eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace intel_miptree_release(&mt); 1243eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace return NULL; 1253eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace } 126fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt 127fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt /* Fix up the Z miptree format for how we're splitting out separate 128fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt * stencil. Gen7 expects there to be no stencil bits in its depth buffer. 129fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt */ 130fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt if (mt->format == MESA_FORMAT_S8_Z24) { 131fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt mt->format = MESA_FORMAT_X8_Z24; 1324790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt } else if (mt->format == MESA_FORMAT_Z32_FLOAT_X24S8) { 1334790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt mt->format = MESA_FORMAT_Z32_FLOAT; 1344790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt mt->cpp = 4; 135fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt } else { 1364790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt _mesa_problem(NULL, "Unknown format %s in separate stencil mt\n", 137fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt _mesa_get_format_name(mt->format)); 138fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt } 1393eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace } 1403eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace 1414790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt intel_get_texture_alignment_unit(intel, mt->format, 1424790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt &mt->align_w, &mt->align_h); 1434790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt 1444790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt#ifdef I915 1454790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt (void) intel; 1464790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt if (intel->is_945) 1474790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt i945_miptree_layout(mt); 1484790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt else 1494790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt i915_miptree_layout(mt); 1504790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt#else 1514790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt brw_miptree_layout(intel, mt); 1524790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt#endif 1534790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt 1546d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg return mt; 1556d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg} 1566d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg 15747a7535f413d6467082de224f64eecc046227406Brian Paul 1586d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstruct intel_mipmap_tree * 1596d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create(struct intel_context *intel, 1606d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg GLenum target, 161d5809115b568d8b74f47316607dce0730964517aEric Anholt gl_format format, 1625b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt GLuint first_level, 1635b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt GLuint last_level, 1646d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg GLuint width0, 1656d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg GLuint height0, 166f94fef83db10f0c9327bd3dd43510ad31c94d82aEric Anholt GLuint depth0, 1672e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke bool expect_accelerated_upload) 1686d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg{ 1696d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg struct intel_mipmap_tree *mt; 170453f0b1f243b26e02b371293e9c8bbf09362c14aEric Anholt uint32_t tiling = I915_TILING_NONE; 1719c5fdbb721147f7304faaa8960f5b64e25a8f673Eric Anholt GLenum base_format = _mesa_get_format_base_format(format); 1721ba96651e12b3c74fb9c8f5a61b183ef36a27b1eEric Anholt 1736dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt if (intel->use_texture_tiling && !_mesa_is_format_compressed(format)) { 174caf3038123d6d29afd7d1f0cd6db98a2282c3ca1Eric Anholt if (intel->gen >= 4 && 1759c0ba017c8ff7caafc3ff94da3c035e687231596Eric Anholt (base_format == GL_DEPTH_COMPONENT || 1769c0ba017c8ff7caafc3ff94da3c035e687231596Eric Anholt base_format == GL_DEPTH_STENCIL_EXT)) 177bd10f0e84f1491363d76d92dcbd410ab5cc43dbeEric Anholt tiling = I915_TILING_Y; 178453f0b1f243b26e02b371293e9c8bbf09362c14aEric Anholt else if (width0 >= 64) 179bd10f0e84f1491363d76d92dcbd410ab5cc43dbeEric Anholt tiling = I915_TILING_X; 180453f0b1f243b26e02b371293e9c8bbf09362c14aEric Anholt } 1816d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg 182f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt if (format == MESA_FORMAT_S8) { 183f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt /* The stencil buffer is W tiled. However, we request from the kernel a 184f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * non-tiled buffer because the GTT is incapable of W fencing. 185f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * 186f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * The stencil buffer has quirky pitch requirements. From Vol 2a, 187f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch": 188f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * The pitch must be set to 2x the value computed based on width, as 189f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * the stencil buffer is stored with two rows interleaved. 190f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * To accomplish this, we resort to the nasty hack of doubling the drm 191f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * region's cpp and halving its height. 192f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * 193f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt * If we neglect to double the pitch, then render corruption occurs. 194f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt */ 195f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt tiling = I915_TILING_NONE; 196f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt width0 = ALIGN(width0, 64); 197f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt height0 = ALIGN((height0 + 1) / 2, 64); 198f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt } 199f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt 2009a523a48af05118424714f0a34ca3dda6861186aEric Anholt mt = intel_miptree_create_internal(intel, target, format, 2015b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt first_level, last_level, width0, 20236a91e45f755af164232ef908419bc4cb64ba45bIan Romanick height0, depth0); 2037ed1fd5d8438e55fe24091844cdfccb0881306bcXiang, Haihao /* 2048b69c42b356d51c3a37bc0af41738b016c2adc5bXiang, Haihao * pitch == 0 || height == 0 indicates the null texture 2057ed1fd5d8438e55fe24091844cdfccb0881306bcXiang, Haihao */ 2061a662e7c18cab98f1b122f6766faf338725de673Yuanhan Liu if (!mt || !mt->total_width || !mt->total_height) { 207747f0307626ef5bcf2f889ab66bcc95ab8eda2c8Chad Versace intel_miptree_release(&mt); 2086d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg return NULL; 209a7d0665c00053839065592c339bfb298187a82beVinson Lee } 2106d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg 2119087ba128089ed0dc00e6eb38f37126fb7557d3bKristian Høgsberg mt->region = intel_region_alloc(intel->intelScreen, 2121ba96651e12b3c74fb9c8f5a61b183ef36a27b1eEric Anholt tiling, 2138db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt mt->cpp, 214362c1bf75eb74de5b4655c481b74f79718ed4a34Eric Anholt mt->total_width, 2158db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt mt->total_height, 21640dd024be618d805b3744e15d25e115018641324Eric Anholt expect_accelerated_upload); 2176d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg 21877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt if (!mt->region) { 219747f0307626ef5bcf2f889ab66bcc95ab8eda2c8Chad Versace intel_miptree_release(&mt); 2206d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg return NULL; 2216d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg } 2226d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg 2236d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg return mt; 2246d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg} 2256d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg 22647a7535f413d6467082de224f64eecc046227406Brian Paul 2276d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstruct intel_mipmap_tree * 2286d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create_for_region(struct intel_context *intel, 2296d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg GLenum target, 230d5809115b568d8b74f47316607dce0730964517aEric Anholt gl_format format, 2316f23d9b637602d9997896c6ca5cba0dfe36a092eIan Romanick struct intel_region *region) 2326d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg{ 2336d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg struct intel_mipmap_tree *mt; 2346d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg 2359a523a48af05118424714f0a34ca3dda6861186aEric Anholt mt = intel_miptree_create_internal(intel, target, format, 2365b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt 0, 0, 23736a91e45f755af164232ef908419bc4cb64ba45bIan Romanick region->width, region->height, 1); 2386d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg if (!mt) 2396d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg return mt; 240da011faf48155a5c02ebc1fe1fa20a4f54b8c657Eric Anholt 241e72a44215312ae1f3c812ba28e47b4aec3589de9Pierre Willenbrock intel_region_reference(&mt->region, region); 24277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 24377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt return mt; 24447a7535f413d6467082de224f64eecc046227406Brian Paul} 24547a7535f413d6467082de224f64eecc046227406Brian Paul 246005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versacestruct intel_mipmap_tree* 247005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versaceintel_miptree_create_for_renderbuffer(struct intel_context *intel, 248005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace gl_format format, 249005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace uint32_t width, 250005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace uint32_t height) 251005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace{ 252005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace struct intel_mipmap_tree *mt; 253005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace 254f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt mt = intel_miptree_create(intel, GL_TEXTURE_2D, format, 0, 0, 255f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt width, height, 1, true); 256005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace 257005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace return mt; 258005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace} 259005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace 26077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid 26177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_reference(struct intel_mipmap_tree **dst, 26277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt struct intel_mipmap_tree *src) 26377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 26432fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt if (*dst == src) 26532fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt return; 26632fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt 26732fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt intel_miptree_release(dst); 26832fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt 26932fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt if (src) { 27032fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt src->refcount++; 27132fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt DBG("%s %p refcount now %d\n", __FUNCTION__, src, src->refcount); 27232fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt } 27332fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt 27477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *dst = src; 27577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt} 27677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 27747a7535f413d6467082de224f64eecc046227406Brian Paul 27877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid 279db3ada6055814a4bd5aa95fc9505fc101864391dEric Anholtintel_miptree_release(struct intel_mipmap_tree **mt) 28077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 28177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt if (!*mt) 28277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt return; 28377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 28477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt DBG("%s %p refcount will be %d\n", __FUNCTION__, *mt, (*mt)->refcount - 1); 28577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt if (--(*mt)->refcount <= 0) { 28677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt GLuint i; 28777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 28877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt DBG("%s deleting %p\n", __FUNCTION__, *mt); 28977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 29077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt intel_region_release(&((*mt)->region)); 2913eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace intel_miptree_release(&(*mt)->stencil_mt); 292a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace intel_miptree_release(&(*mt)->hiz_mt); 2932945abea338031cbe90665df60152982bfca6177Chad Versace intel_resolve_map_clear(&(*mt)->hiz_map); 29477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 2952d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { 296c2ddde70daece24d1eb7185946032158993a9e4dChad Versace free((*mt)->level[i].slice); 2972d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt } 29877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 29977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt free(*mt); 30077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt } 30177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *mt = NULL; 30277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt} 30377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 304fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholtvoid 305fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholtintel_miptree_get_dimensions_for_image(struct gl_texture_image *image, 306fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt int *width, int *height, int *depth) 307fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt{ 308fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt switch (image->TexObject->Target) { 309fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt case GL_TEXTURE_1D_ARRAY: 310fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt *width = image->Width; 311fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt *height = 1; 312fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt *depth = image->Height; 313fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt break; 314fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt default: 315fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt *width = image->Width; 316fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt *height = image->Height; 317fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt *depth = image->Depth; 318fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt break; 319fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt } 320fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt} 32177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 32247a7535f413d6467082de224f64eecc046227406Brian Paul/** 32347a7535f413d6467082de224f64eecc046227406Brian Paul * Can the image be pulled into a unified mipmap tree? This mirrors 32477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * the completeness test in a lot of ways. 32577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * 32677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Not sure whether I want to pass gl_texture_image here. 32777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */ 3282e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkebool 32977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_match_image(struct intel_mipmap_tree *mt, 3308f30ceaaefc33401b08739a16ce1c5638d6432faEric Anholt struct gl_texture_image *image) 33177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 3328f30ceaaefc33401b08739a16ce1c5638d6432faEric Anholt struct intel_texture_image *intelImage = intel_texture_image(image); 333fa2c886863492cc3eeee6d2059ae24edc1cb2bffBrian Paul GLuint level = intelImage->base.Base.Level; 334fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt int width, height, depth; 335b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul 336ab7794cada02f3b3b5e3a642c20eeedeb17b65a6Eric Anholt if (target_to_target(image->TexObject->Target) != mt->target) 337ab7794cada02f3b3b5e3a642c20eeedeb17b65a6Eric Anholt return false; 338ab7794cada02f3b3b5e3a642c20eeedeb17b65a6Eric Anholt 339fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt if (image->TexFormat != mt->format && 340fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt !(image->TexFormat == MESA_FORMAT_S8_Z24 && 341fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt mt->format == MESA_FORMAT_X8_Z24 && 342fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt mt->stencil_mt)) { 3432e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return false; 344fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt } 345d12fa3511da23d8285f3ea1a51a1f328cdbb1462Xiang, Haihao 346fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt intel_miptree_get_dimensions_for_image(image, &width, &height, &depth); 347fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt 3487f854a5028ef00a0e041e78a770456204dc58eefEric Anholt if (mt->target == GL_TEXTURE_CUBE_MAP) 3497f854a5028ef00a0e041e78a770456204dc58eefEric Anholt depth = 6; 3507f854a5028ef00a0e041e78a770456204dc58eefEric Anholt 35177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt /* Test image dimensions against the base level image adjusted for 35277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * minification. This will also catch images not present in the 35377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * tree, changed targets, etc. 35477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */ 355fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt if (width != mt->level[level].width || 356fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt height != mt->level[level].height || 357fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt depth != mt->level[level].depth) 3582e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return false; 35977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 3602e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return true; 36177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt} 36277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 36377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 36477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid 36577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_set_level_info(struct intel_mipmap_tree *mt, 366659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt GLuint level, 367659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt GLuint x, GLuint y, 368659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt GLuint w, GLuint h, GLuint d) 36977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 37077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt mt->level[level].width = w; 37177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt mt->level[level].height = h; 37277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt mt->level[level].depth = d; 3732d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt mt->level[level].level_x = x; 3742d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt mt->level[level].level_y = y; 37577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 3760c51390e4b5e04b992e50fcbed751024e6c329deEric Anholt DBG("%s level %d size: %d,%d,%d offset %d,%d\n", __FUNCTION__, 3770c51390e4b5e04b992e50fcbed751024e6c329deEric Anholt level, w, h, d, x, y); 37877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 379c2ddde70daece24d1eb7185946032158993a9e4dChad Versace assert(mt->level[level].slice == NULL); 38077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 381221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt mt->level[level].slice = calloc(d, sizeof(*mt->level[0].slice)); 382c2ddde70daece24d1eb7185946032158993a9e4dChad Versace mt->level[level].slice[0].x_offset = mt->level[level].level_x; 383c2ddde70daece24d1eb7185946032158993a9e4dChad Versace mt->level[level].slice[0].y_offset = mt->level[level].level_y; 38477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt} 38577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 38677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 38777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid 3882d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholtintel_miptree_set_image_offset(struct intel_mipmap_tree *mt, 3892d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt GLuint level, GLuint img, 3902d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt GLuint x, GLuint y) 39177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 39277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt if (img == 0 && level == 0) 39377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt assert(x == 0 && y == 0); 39477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 395d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace assert(img < mt->level[level].depth); 39677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 397c2ddde70daece24d1eb7185946032158993a9e4dChad Versace mt->level[level].slice[img].x_offset = mt->level[level].level_x + x; 398c2ddde70daece24d1eb7185946032158993a9e4dChad Versace mt->level[level].slice[img].y_offset = mt->level[level].level_y + y; 39977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 4002d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt DBG("%s level %d img %d pos %d,%d\n", 4012d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt __FUNCTION__, level, img, 402c2ddde70daece24d1eb7185946032158993a9e4dChad Versace mt->level[level].slice[img].x_offset, 403c2ddde70daece24d1eb7185946032158993a9e4dChad Versace mt->level[level].slice[img].y_offset); 40477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt} 40577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 40647a7535f413d6467082de224f64eecc046227406Brian Paul 407d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace/** 408d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace * For cube map textures, either the \c face parameter can be used, of course, 409d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace * or the cube face can be interpreted as a depth layer and the \c layer 410d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace * parameter used. 411d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace */ 4122995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihaovoid 4132d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholtintel_miptree_get_image_offset(struct intel_mipmap_tree *mt, 414d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace GLuint level, GLuint face, GLuint layer, 4152d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt GLuint *x, GLuint *y) 41677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 417d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace int slice; 418d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace 419d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace if (face > 0) { 420d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace assert(mt->target == GL_TEXTURE_CUBE_MAP); 421d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace assert(face < 6); 422d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace assert(layer == 0); 423d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace slice = face; 424d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace } else { 425d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace /* This branch may be taken even if the texture target is a cube map. In 426d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace * that case, the caller chose to interpret each cube face as a layer. 427d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace */ 428d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace assert(face == 0); 429d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace slice = layer; 4302d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt } 431d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace 432d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace *x = mt->level[level].slice[slice].x_offset; 433d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace *y = mt->level[level].slice[slice].y_offset; 43477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt} 43577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 436278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versacestatic void 437278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versaceintel_miptree_copy_slice(struct intel_context *intel, 438278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace struct intel_mipmap_tree *dst_mt, 439278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace struct intel_mipmap_tree *src_mt, 440278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace int level, 441278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace int face, 442278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace int depth) 443278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 444278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace{ 445278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace gl_format format = src_mt->format; 446278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace uint32_t width = src_mt->level[level].width; 447278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace uint32_t height = src_mt->level[level].height; 448278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 449278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace assert(depth < src_mt->level[level].depth); 450278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 451278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace if (dst_mt->compressed) { 452017c13d55b5b086774d6afea2ca754482c624c6aChad Versace height = ALIGN(height, dst_mt->align_h) / dst_mt->align_h; 453017c13d55b5b086774d6afea2ca754482c624c6aChad Versace width = ALIGN(width, dst_mt->align_w); 454278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace } 455278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 456278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace uint32_t dst_x, dst_y, src_x, src_y; 457278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace intel_miptree_get_image_offset(dst_mt, level, face, depth, 458278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace &dst_x, &dst_y); 459278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace intel_miptree_get_image_offset(src_mt, level, face, depth, 460278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace &src_x, &src_y); 461278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 462278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace DBG("validate blit mt %p %d,%d/%d -> mt %p %d,%d/%d (%dx%d)\n", 463278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace src_mt, src_x, src_y, src_mt->region->pitch * src_mt->region->cpp, 464278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace dst_mt, dst_x, dst_y, dst_mt->region->pitch * dst_mt->region->cpp, 465278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace width, height); 466278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 467278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace if (!intelEmitCopyBlit(intel, 468278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace dst_mt->region->cpp, 469278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace src_mt->region->pitch, src_mt->region->bo, 470278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 0, src_mt->region->tiling, 471278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace dst_mt->region->pitch, dst_mt->region->bo, 472278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 0, dst_mt->region->tiling, 473278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace src_x, src_y, 474278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace dst_x, dst_y, 475278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace width, height, 476278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace GL_COPY)) { 477278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 478278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace fallback_debug("miptree validate blit for %s failed\n", 479278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace _mesa_get_format_name(format)); 480278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace void *dst = intel_region_map(intel, dst_mt->region, GL_MAP_WRITE_BIT); 481278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace void *src = intel_region_map(intel, src_mt->region, GL_MAP_READ_BIT); 482278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 483278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace _mesa_copy_rect(dst, 484278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace dst_mt->cpp, 485278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace dst_mt->region->pitch, 486278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace dst_x, dst_y, 487278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace width, height, 488278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace src, src_mt->region->pitch, 489278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace src_x, src_y); 490278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 491278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace intel_region_unmap(intel, dst_mt->region); 492278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace intel_region_unmap(intel, src_mt->region); 493278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace } 4943eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace 4953eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace if (src_mt->stencil_mt) { 4963eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace intel_miptree_copy_slice(intel, 4973eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace dst_mt->stencil_mt, src_mt->stencil_mt, 4983eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace level, face, depth); 4993eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace } 500278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace} 501278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 50277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/** 503b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt * Copies the image's current data to the given miptree, and associates that 504b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt * miptree with the image. 50577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */ 50677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid 507b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholtintel_miptree_copy_teximage(struct intel_context *intel, 508b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt struct intel_texture_image *intelImage, 509b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt struct intel_mipmap_tree *dst_mt) 51077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{ 511b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt struct intel_mipmap_tree *src_mt = intelImage->mt; 512b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt int level = intelImage->base.Base.Level; 513b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt int face = intelImage->base.Base.Face; 514d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace GLuint depth = intelImage->base.Base.Depth; 515b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt 516278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace for (int slice = 0; slice < depth; slice++) { 517278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace intel_miptree_copy_slice(intel, dst_mt, src_mt, level, face, slice); 51877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt } 51977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt 520b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt intel_miptree_reference(&intelImage->mt, dst_mt); 52177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt} 522278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace 523a2e44b0813e956440c451c107cf5564b56cbe98eChad Versacebool 524a2e44b0813e956440c451c107cf5564b56cbe98eChad Versaceintel_miptree_alloc_hiz(struct intel_context *intel, 525a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace struct intel_mipmap_tree *mt) 526a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace{ 527a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace assert(mt->hiz_mt == NULL); 528a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace mt->hiz_mt = intel_miptree_create(intel, 529a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace mt->target, 530a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace MESA_FORMAT_X8_Z24, 531a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace mt->first_level, 532a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace mt->last_level, 533a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace mt->width0, 534a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace mt->height0, 535a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace mt->depth0, 536a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace true); 5373d760664e6349c72624aa6d54d40df0233995c8eChad Versace 5383d760664e6349c72624aa6d54d40df0233995c8eChad Versace if (!mt->hiz_mt) 5393d760664e6349c72624aa6d54d40df0233995c8eChad Versace return false; 5403d760664e6349c72624aa6d54d40df0233995c8eChad Versace 5413d760664e6349c72624aa6d54d40df0233995c8eChad Versace /* Mark that all slices need a HiZ resolve. */ 5423d760664e6349c72624aa6d54d40df0233995c8eChad Versace struct intel_resolve_map *head = &mt->hiz_map; 5433d760664e6349c72624aa6d54d40df0233995c8eChad Versace for (int level = mt->first_level; level <= mt->last_level; ++level) { 5443d760664e6349c72624aa6d54d40df0233995c8eChad Versace for (int layer = 0; layer < mt->level[level].depth; ++layer) { 5453d760664e6349c72624aa6d54d40df0233995c8eChad Versace head->next = malloc(sizeof(*head->next)); 5463d760664e6349c72624aa6d54d40df0233995c8eChad Versace head->next->prev = head; 5473d760664e6349c72624aa6d54d40df0233995c8eChad Versace head->next->next = NULL; 5483d760664e6349c72624aa6d54d40df0233995c8eChad Versace head = head->next; 5493d760664e6349c72624aa6d54d40df0233995c8eChad Versace 5503d760664e6349c72624aa6d54d40df0233995c8eChad Versace head->level = level; 5513d760664e6349c72624aa6d54d40df0233995c8eChad Versace head->layer = layer; 5523d760664e6349c72624aa6d54d40df0233995c8eChad Versace head->need = INTEL_NEED_HIZ_RESOLVE; 5533d760664e6349c72624aa6d54d40df0233995c8eChad Versace } 5543d760664e6349c72624aa6d54d40df0233995c8eChad Versace } 5553d760664e6349c72624aa6d54d40df0233995c8eChad Versace 5563d760664e6349c72624aa6d54d40df0233995c8eChad Versace return true; 557a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace} 5582945abea338031cbe90665df60152982bfca6177Chad Versace 5592945abea338031cbe90665df60152982bfca6177Chad Versacevoid 5602945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree *mt, 5612945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t level, 5622945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t layer) 5632945abea338031cbe90665df60152982bfca6177Chad Versace{ 5642945abea338031cbe90665df60152982bfca6177Chad Versace intel_miptree_check_level_layer(mt, level, layer); 5652945abea338031cbe90665df60152982bfca6177Chad Versace 5662945abea338031cbe90665df60152982bfca6177Chad Versace if (!mt->hiz_mt) 5672945abea338031cbe90665df60152982bfca6177Chad Versace return; 5682945abea338031cbe90665df60152982bfca6177Chad Versace 5692945abea338031cbe90665df60152982bfca6177Chad Versace intel_resolve_map_set(&mt->hiz_map, 5702945abea338031cbe90665df60152982bfca6177Chad Versace level, layer, INTEL_NEED_HIZ_RESOLVE); 5712945abea338031cbe90665df60152982bfca6177Chad Versace} 5722945abea338031cbe90665df60152982bfca6177Chad Versace 5732945abea338031cbe90665df60152982bfca6177Chad Versace 5742945abea338031cbe90665df60152982bfca6177Chad Versacevoid 5752945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree *mt, 5762945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t level, 5772945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t layer) 5782945abea338031cbe90665df60152982bfca6177Chad Versace{ 5792945abea338031cbe90665df60152982bfca6177Chad Versace intel_miptree_check_level_layer(mt, level, layer); 5802945abea338031cbe90665df60152982bfca6177Chad Versace 5812945abea338031cbe90665df60152982bfca6177Chad Versace if (!mt->hiz_mt) 5822945abea338031cbe90665df60152982bfca6177Chad Versace return; 5832945abea338031cbe90665df60152982bfca6177Chad Versace 5842945abea338031cbe90665df60152982bfca6177Chad Versace intel_resolve_map_set(&mt->hiz_map, 5852945abea338031cbe90665df60152982bfca6177Chad Versace level, layer, INTEL_NEED_DEPTH_RESOLVE); 5862945abea338031cbe90665df60152982bfca6177Chad Versace} 5872945abea338031cbe90665df60152982bfca6177Chad Versace 5882945abea338031cbe90665df60152982bfca6177Chad Versacetypedef void (*resolve_func_t)(struct intel_context *intel, 5892945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_mipmap_tree *mt, 5902945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t level, 5912945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t layer); 5922945abea338031cbe90665df60152982bfca6177Chad Versace 5932945abea338031cbe90665df60152982bfca6177Chad Versacestatic bool 5942945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_resolve(struct intel_context *intel, 5952945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_mipmap_tree *mt, 5962945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t level, 5972945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t layer, 5982945abea338031cbe90665df60152982bfca6177Chad Versace enum intel_need_resolve need, 5992945abea338031cbe90665df60152982bfca6177Chad Versace resolve_func_t func) 6002945abea338031cbe90665df60152982bfca6177Chad Versace{ 6012945abea338031cbe90665df60152982bfca6177Chad Versace intel_miptree_check_level_layer(mt, level, layer); 6022945abea338031cbe90665df60152982bfca6177Chad Versace 6032945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_resolve_map *item = 6042945abea338031cbe90665df60152982bfca6177Chad Versace intel_resolve_map_get(&mt->hiz_map, level, layer); 6052945abea338031cbe90665df60152982bfca6177Chad Versace 6062945abea338031cbe90665df60152982bfca6177Chad Versace if (!item || item->need != need) 6072945abea338031cbe90665df60152982bfca6177Chad Versace return false; 6082945abea338031cbe90665df60152982bfca6177Chad Versace 6092945abea338031cbe90665df60152982bfca6177Chad Versace func(intel, mt, level, layer); 6102945abea338031cbe90665df60152982bfca6177Chad Versace intel_resolve_map_remove(item); 6112945abea338031cbe90665df60152982bfca6177Chad Versace return true; 6122945abea338031cbe90665df60152982bfca6177Chad Versace} 6132945abea338031cbe90665df60152982bfca6177Chad Versace 6142945abea338031cbe90665df60152982bfca6177Chad Versacebool 6152945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_resolve_hiz(struct intel_context *intel, 6162945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_mipmap_tree *mt, 6172945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t level, 6182945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t layer) 6192945abea338031cbe90665df60152982bfca6177Chad Versace{ 6202945abea338031cbe90665df60152982bfca6177Chad Versace return intel_miptree_slice_resolve(intel, mt, level, layer, 6212945abea338031cbe90665df60152982bfca6177Chad Versace INTEL_NEED_HIZ_RESOLVE, 6222945abea338031cbe90665df60152982bfca6177Chad Versace intel->vtbl.resolve_hiz_slice); 6232945abea338031cbe90665df60152982bfca6177Chad Versace} 6242945abea338031cbe90665df60152982bfca6177Chad Versace 6252945abea338031cbe90665df60152982bfca6177Chad Versacebool 6262945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_resolve_depth(struct intel_context *intel, 6272945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_mipmap_tree *mt, 6282945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t level, 6292945abea338031cbe90665df60152982bfca6177Chad Versace uint32_t layer) 6302945abea338031cbe90665df60152982bfca6177Chad Versace{ 6312945abea338031cbe90665df60152982bfca6177Chad Versace return intel_miptree_slice_resolve(intel, mt, level, layer, 6322945abea338031cbe90665df60152982bfca6177Chad Versace INTEL_NEED_DEPTH_RESOLVE, 6332945abea338031cbe90665df60152982bfca6177Chad Versace intel->vtbl.resolve_depth_slice); 6342945abea338031cbe90665df60152982bfca6177Chad Versace} 6352945abea338031cbe90665df60152982bfca6177Chad Versace 6362945abea338031cbe90665df60152982bfca6177Chad Versacestatic bool 6372945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_resolve(struct intel_context *intel, 6382945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_mipmap_tree *mt, 6392945abea338031cbe90665df60152982bfca6177Chad Versace enum intel_need_resolve need, 6402945abea338031cbe90665df60152982bfca6177Chad Versace resolve_func_t func) 6412945abea338031cbe90665df60152982bfca6177Chad Versace{ 6422945abea338031cbe90665df60152982bfca6177Chad Versace bool did_resolve = false; 6432945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_resolve_map *i; 6442945abea338031cbe90665df60152982bfca6177Chad Versace 6452945abea338031cbe90665df60152982bfca6177Chad Versace for (i = mt->hiz_map.next; i; i = i->next) { 6462945abea338031cbe90665df60152982bfca6177Chad Versace if (i->need != need) 6472945abea338031cbe90665df60152982bfca6177Chad Versace continue; 6482945abea338031cbe90665df60152982bfca6177Chad Versace func(intel, mt, i->level, i->layer); 6492945abea338031cbe90665df60152982bfca6177Chad Versace intel_resolve_map_remove(i); 6502945abea338031cbe90665df60152982bfca6177Chad Versace did_resolve = true; 6512945abea338031cbe90665df60152982bfca6177Chad Versace } 6522945abea338031cbe90665df60152982bfca6177Chad Versace 6532945abea338031cbe90665df60152982bfca6177Chad Versace return did_resolve; 6542945abea338031cbe90665df60152982bfca6177Chad Versace} 6552945abea338031cbe90665df60152982bfca6177Chad Versace 6562945abea338031cbe90665df60152982bfca6177Chad Versacebool 6572945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_resolve_hiz(struct intel_context *intel, 6582945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_mipmap_tree *mt) 6592945abea338031cbe90665df60152982bfca6177Chad Versace{ 6602945abea338031cbe90665df60152982bfca6177Chad Versace return intel_miptree_all_slices_resolve(intel, mt, 6612945abea338031cbe90665df60152982bfca6177Chad Versace INTEL_NEED_HIZ_RESOLVE, 6622945abea338031cbe90665df60152982bfca6177Chad Versace intel->vtbl.resolve_hiz_slice); 6632945abea338031cbe90665df60152982bfca6177Chad Versace} 6642945abea338031cbe90665df60152982bfca6177Chad Versace 6652945abea338031cbe90665df60152982bfca6177Chad Versacebool 6662945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_resolve_depth(struct intel_context *intel, 6672945abea338031cbe90665df60152982bfca6177Chad Versace struct intel_mipmap_tree *mt) 6682945abea338031cbe90665df60152982bfca6177Chad Versace{ 6692945abea338031cbe90665df60152982bfca6177Chad Versace return intel_miptree_all_slices_resolve(intel, mt, 6702945abea338031cbe90665df60152982bfca6177Chad Versace INTEL_NEED_DEPTH_RESOLVE, 6712945abea338031cbe90665df60152982bfca6177Chad Versace intel->vtbl.resolve_depth_slice); 6722945abea338031cbe90665df60152982bfca6177Chad Versace} 673b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt 674baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtstatic void 675baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtintel_miptree_map_gtt(struct intel_context *intel, 676baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt struct intel_mipmap_tree *mt, 677baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt struct intel_miptree_map *map, 678baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int level, unsigned int slice) 679b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt{ 680b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt unsigned int bw, bh; 681b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt void *base; 682b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt unsigned int image_x, image_y; 683baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt int x = map->x; 684baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt int y = map->y; 685221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt 686b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt /* For compressed formats, the stride is the number of bytes per 687b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt * row of blocks. intel_miptree_get_image_offset() already does 688b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt * the divide. 689b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt */ 690b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt _mesa_get_format_block_size(mt->format, &bw, &bh); 691b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt assert(y % bh == 0); 692b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt y /= bh; 693b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt 694baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt base = intel_region_map(intel, mt->region, map->mode); 695b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt /* Note that in the case of cube maps, the caller must have passed the slice 696b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt * number referencing the face. 697b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt */ 698b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y); 699b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt x += image_x; 700b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt y += image_y; 701b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt 702221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt map->stride = mt->region->pitch * mt->cpp; 703221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt map->ptr = base + y * map->stride + x * mt->cpp; 704221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt 705b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt DBG("%s: %d,%d %dx%d from mt %p (%s) %d,%d = %p/%d\n", __FUNCTION__, 706221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt map->x, map->y, map->w, map->h, 707b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt mt, _mesa_get_format_name(mt->format), 708221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt x, y, map->ptr, map->stride); 709b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt} 710b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt 711baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtstatic void 712baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtintel_miptree_unmap_gtt(struct intel_context *intel, 713baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt struct intel_mipmap_tree *mt, 714baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt struct intel_miptree_map *map, 715baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int level, 716baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int slice) 717baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt{ 718baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt intel_region_unmap(intel, mt->region); 719baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt} 720baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt 721b48c3bca87b30003f9e117d299011380e743aec9Eric Anholtstatic void 7225655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtintel_miptree_map_blit(struct intel_context *intel, 7235655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt struct intel_mipmap_tree *mt, 7245655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt struct intel_miptree_map *map, 7255655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt unsigned int level, unsigned int slice) 7265655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt{ 7275655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt unsigned int image_x, image_y; 7285655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt int x = map->x; 7295655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt int y = map->y; 7305655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt int ret; 7315655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7325655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt /* The blitter requires the pitch to be aligned to 4. */ 7335655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->stride = ALIGN(map->w * mt->region->cpp, 4); 7345655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7355655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->bo = drm_intel_bo_alloc(intel->bufmgr, "intel_miptree_map_blit() temp", 7365655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->stride * map->h, 4096); 7375655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt if (!map->bo) { 7385655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt fprintf(stderr, "Failed to allocate blit temporary\n"); 7395655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt goto fail; 7405655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt } 7415655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7425655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y); 7435655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt x += image_x; 7445655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt y += image_y; 7455655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7465655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt if (!intelEmitCopyBlit(intel, 7475655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt mt->region->cpp, 7485655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt mt->region->pitch, mt->region->bo, 7495655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 0, mt->region->tiling, 7505655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->stride / mt->region->cpp, map->bo, 7515655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 0, I915_TILING_NONE, 7525655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt x, y, 7535655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 0, 0, 7545655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->w, map->h, 7555655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt GL_COPY)) { 7565655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt fprintf(stderr, "Failed to blit\n"); 7575655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt goto fail; 7585655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt } 7595655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7605655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt intel_batchbuffer_flush(intel); 7615655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt ret = drm_intel_bo_map(map->bo, (map->mode & GL_MAP_WRITE_BIT) != 0); 7625655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt if (ret) { 7635655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt fprintf(stderr, "Failed to map blit temporary\n"); 7645655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt goto fail; 7655655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt } 7665655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7675655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->ptr = map->bo->virtual; 7685655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7695655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt DBG("%s: %d,%d %dx%d from mt %p (%s) %d,%d = %p/%d\n", __FUNCTION__, 7705655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->x, map->y, map->w, map->h, 7715655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt mt, _mesa_get_format_name(mt->format), 7725655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt x, y, map->ptr, map->stride); 7735655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7745655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt return; 7755655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7765655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtfail: 7775655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt drm_intel_bo_unreference(map->bo); 7785655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->ptr = NULL; 7795655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt map->stride = 0; 7805655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt} 7815655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7825655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtstatic void 7835655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtintel_miptree_unmap_blit(struct intel_context *intel, 7845655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt struct intel_mipmap_tree *mt, 7855655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt struct intel_miptree_map *map, 7865655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt unsigned int level, 7875655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt unsigned int slice) 7885655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt{ 7895655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt assert(!(map->mode & GL_MAP_WRITE_BIT)); 7905655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7915655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt drm_intel_bo_unmap(map->bo); 7925655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt drm_intel_bo_unreference(map->bo); 7935655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt} 7945655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt 7955655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtstatic void 796b48c3bca87b30003f9e117d299011380e743aec9Eric Anholtintel_miptree_map_s8(struct intel_context *intel, 797b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt struct intel_mipmap_tree *mt, 798b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt struct intel_miptree_map *map, 799b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt unsigned int level, unsigned int slice) 800b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt{ 801b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt map->stride = map->w; 802b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt map->buffer = map->ptr = malloc(map->stride * map->h); 803b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt if (!map->buffer) 804b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt return; 805b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 806b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt /* One of either READ_BIT or WRITE_BIT or both is set. READ_BIT implies no 807b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt * INVALIDATE_RANGE_BIT. WRITE_BIT needs the original values read in unless 808b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt * invalidate is set, since we'll be writing the whole rectangle from our 809b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt * temporary buffer back out. 810b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt */ 811b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt if (!(map->mode & GL_MAP_INVALIDATE_RANGE_BIT)) { 812b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt uint8_t *untiled_s8_map = map->ptr; 813b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt uint8_t *tiled_s8_map = intel_region_map(intel, mt->region, 814b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt GL_MAP_READ_BIT); 815b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt unsigned int image_x, image_y; 816b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 817b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y); 818b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 819b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt for (uint32_t y = 0; y < map->h; y++) { 820b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt for (uint32_t x = 0; x < map->w; x++) { 821b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt ptrdiff_t offset = intel_offset_S8(mt->region->pitch, 822b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt x + image_x + map->x, 823b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt y + image_y + map->y); 824b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt untiled_s8_map[y * map->w + x] = tiled_s8_map[offset]; 825b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } 826b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } 827b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 828b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt intel_region_unmap(intel, mt->region); 829b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 830b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt DBG("%s: %d,%d %dx%d from mt %p %d,%d = %p/%d\n", __FUNCTION__, 831b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt map->x, map->y, map->w, map->h, 832b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt mt, map->x + image_x, map->y + image_y, map->ptr, map->stride); 833b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } else { 834b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt DBG("%s: %d,%d %dx%d from mt %p = %p/%d\n", __FUNCTION__, 835b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt map->x, map->y, map->w, map->h, 836b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt mt, map->ptr, map->stride); 837b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } 838b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt} 839b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 840b48c3bca87b30003f9e117d299011380e743aec9Eric Anholtstatic void 841b48c3bca87b30003f9e117d299011380e743aec9Eric Anholtintel_miptree_unmap_s8(struct intel_context *intel, 842b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt struct intel_mipmap_tree *mt, 843b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt struct intel_miptree_map *map, 844b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt unsigned int level, 845b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt unsigned int slice) 846b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt{ 847b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt if (map->mode & GL_MAP_WRITE_BIT) { 848b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt unsigned int image_x, image_y; 849b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt uint8_t *untiled_s8_map = map->ptr; 850b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt uint8_t *tiled_s8_map = intel_region_map(intel, mt->region, map->mode); 851b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 852b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y); 853b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 854b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt for (uint32_t y = 0; y < map->h; y++) { 855b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt for (uint32_t x = 0; x < map->w; x++) { 856b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt ptrdiff_t offset = intel_offset_S8(mt->region->pitch, 857b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt x + map->x, 858b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt y + map->y); 859b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt tiled_s8_map[offset] = untiled_s8_map[y * map->w + x]; 860b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } 861b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } 862b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 863b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt intel_region_unmap(intel, mt->region); 864b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } 865b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 866b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt free(map->buffer); 867b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt} 868b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt 869ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt/** 870ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * Mapping function for packed depth/stencil miptrees backed by real separate 871ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * miptrees for depth and stencil. 872ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * 873ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * On gen7, and to support HiZ pre-gen7, we have to have the stencil buffer 874ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * separate from the depth buffer. Yet at the GL API level, we have to expose 875ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * packed depth/stencil textures and FBO attachments, and Mesa core expects to 876ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * be able to map that memory for texture storage and glReadPixels-type 877ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * operations. We give Mesa core that access by mallocing a temporary and 878ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * copying the data between the actual backing store and the temporary. 879ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt */ 880ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholtstatic void 881ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholtintel_miptree_map_depthstencil(struct intel_context *intel, 882ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt struct intel_mipmap_tree *mt, 883ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt struct intel_miptree_map *map, 884ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt unsigned int level, unsigned int slice) 885ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt{ 886ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt struct intel_mipmap_tree *z_mt = mt; 887ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt struct intel_mipmap_tree *s_mt = mt->stencil_mt; 888353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt bool map_z32f_x24s8 = mt->format == MESA_FORMAT_Z32_FLOAT; 889353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt int packed_bpp = map_z32f_x24s8 ? 8 : 4; 890ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 891ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map->stride = map->w * packed_bpp; 892ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map->buffer = map->ptr = malloc(map->stride * map->h); 893ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt if (!map->buffer) 894ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt return; 895ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 896ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt /* One of either READ_BIT or WRITE_BIT or both is set. READ_BIT implies no 897ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * INVALIDATE_RANGE_BIT. WRITE_BIT needs the original values read in unless 898ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * invalidate is set, since we'll be writing the whole rectangle from our 899ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * temporary buffer back out. 900ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt */ 901ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt if (!(map->mode & GL_MAP_INVALIDATE_RANGE_BIT)) { 902ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt uint32_t *packed_map = map->ptr; 903ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt uint8_t *s_map = intel_region_map(intel, s_mt->region, GL_MAP_READ_BIT); 904ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt uint32_t *z_map = intel_region_map(intel, z_mt->region, GL_MAP_READ_BIT); 905ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt unsigned int s_image_x, s_image_y; 906ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt unsigned int z_image_x, z_image_y; 907ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 908ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_miptree_get_image_offset(s_mt, level, 0, slice, 909ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt &s_image_x, &s_image_y); 910ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_miptree_get_image_offset(z_mt, level, 0, slice, 911ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt &z_image_x, &z_image_y); 912ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 913ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt for (uint32_t y = 0; y < map->h; y++) { 914ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt for (uint32_t x = 0; x < map->w; x++) { 915ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt int map_x = map->x + x, map_y = map->y + y; 916ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt ptrdiff_t s_offset = intel_offset_S8(s_mt->region->pitch, 917ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map_x + s_image_x, 918ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map_y + s_image_y); 919ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt ptrdiff_t z_offset = ((map_y + z_image_y) * z_mt->region->pitch + 920ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt (map_x + z_image_x)); 921ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt uint8_t s = s_map[s_offset]; 922ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt uint32_t z = z_map[z_offset]; 923ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 924353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt if (map_z32f_x24s8) { 925353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt packed_map[(y * map->w + x) * 2 + 0] = z; 926353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt packed_map[(y * map->w + x) * 2 + 1] = s; 927353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt } else { 928353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt packed_map[y * map->w + x] = (s << 24) | (z & 0x00ffffff); 929353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt } 930ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } 931ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } 932ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 933ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_region_unmap(intel, s_mt->region); 934ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_region_unmap(intel, z_mt->region); 935ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 936ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt DBG("%s: %d,%d %dx%d from z mt %p %d,%d, s mt %p %d,%d = %p/%d\n", 937ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt __FUNCTION__, 938ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map->x, map->y, map->w, map->h, 939ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt z_mt, map->x + z_image_x, map->y + z_image_y, 940ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt s_mt, map->x + s_image_x, map->y + s_image_y, 941ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map->ptr, map->stride); 942ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } else { 943ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt DBG("%s: %d,%d %dx%d from mt %p = %p/%d\n", __FUNCTION__, 944ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map->x, map->y, map->w, map->h, 945ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt mt, map->ptr, map->stride); 946ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } 947ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt} 948ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 949ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholtstatic void 950ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholtintel_miptree_unmap_depthstencil(struct intel_context *intel, 951ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt struct intel_mipmap_tree *mt, 952ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt struct intel_miptree_map *map, 953ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt unsigned int level, 954ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt unsigned int slice) 955ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt{ 956ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt struct intel_mipmap_tree *z_mt = mt; 957ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt struct intel_mipmap_tree *s_mt = mt->stencil_mt; 958353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt bool map_z32f_x24s8 = mt->format == MESA_FORMAT_Z32_FLOAT; 959ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 960ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt if (map->mode & GL_MAP_WRITE_BIT) { 961ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt uint32_t *packed_map = map->ptr; 962ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt uint8_t *s_map = intel_region_map(intel, s_mt->region, map->mode); 963ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt uint32_t *z_map = intel_region_map(intel, z_mt->region, map->mode); 964ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt unsigned int s_image_x, s_image_y; 965ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt unsigned int z_image_x, z_image_y; 966ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 967ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_miptree_get_image_offset(s_mt, level, 0, slice, 968ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt &s_image_x, &s_image_y); 969ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_miptree_get_image_offset(z_mt, level, 0, slice, 970ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt &z_image_x, &z_image_y); 971ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 972ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt for (uint32_t y = 0; y < map->h; y++) { 973ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt for (uint32_t x = 0; x < map->w; x++) { 974ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt ptrdiff_t s_offset = intel_offset_S8(s_mt->region->pitch, 975ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt x + s_image_x + map->x, 976ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt y + s_image_y + map->y); 977ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt ptrdiff_t z_offset = ((y + z_image_y) * z_mt->region->pitch + 978ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt (x + z_image_x)); 979ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 980353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt if (map_z32f_x24s8) { 981353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt z_map[z_offset] = packed_map[(y * map->w + x) * 2 + 0]; 982353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt s_map[s_offset] = packed_map[(y * map->w + x) * 2 + 1]; 983353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt } else { 984353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt uint32_t packed = packed_map[y * map->w + x]; 985353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt s_map[s_offset] = packed >> 24; 986353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt z_map[z_offset] = packed; 987353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt } 988ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } 989ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } 990ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 991ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_region_unmap(intel, s_mt->region); 992ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_region_unmap(intel, z_mt->region); 993ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 994ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt DBG("%s: %d,%d %dx%d from z mt %p (%s) %d,%d, s mt %p %d,%d = %p/%d\n", 995ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt __FUNCTION__, 996ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map->x, map->y, map->w, map->h, 997ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt z_mt, _mesa_get_format_name(z_mt->format), 998ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map->x + z_image_x, map->y + z_image_y, 999ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt s_mt, map->x + s_image_x, map->y + s_image_y, 1000ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt map->ptr, map->stride); 1001ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } 1002ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 1003ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt free(map->buffer); 1004ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt} 1005ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt 1006baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtvoid 1007baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtintel_miptree_map(struct intel_context *intel, 1008baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt struct intel_mipmap_tree *mt, 1009baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int level, 1010baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int slice, 1011baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int x, 1012baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int y, 1013baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int w, 1014baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt unsigned int h, 1015baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt GLbitfield mode, 1016baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt void **out_ptr, 1017baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt int *out_stride) 1018baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt{ 1019baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt struct intel_miptree_map *map; 1020baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt 1021baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt map = calloc(1, sizeof(struct intel_miptree_map)); 1022baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt if (!map){ 1023baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt *out_ptr = NULL; 1024baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt *out_stride = 0; 1025baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt return; 1026baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt } 1027baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt 1028baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt assert(!mt->level[level].slice[slice].map); 1029baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt mt->level[level].slice[slice].map = map; 1030baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt map->mode = mode; 1031baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt map->x = x; 1032baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt map->y = y; 1033baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt map->w = w; 1034baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt map->h = h; 1035baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt 1036baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt intel_miptree_slice_resolve_depth(intel, mt, level, slice); 1037baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt if (map->mode & GL_MAP_WRITE_BIT) { 1038baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt intel_miptree_slice_set_needs_hiz_resolve(mt, level, slice); 1039baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt } 1040baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt 1041b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt if (mt->format == MESA_FORMAT_S8) { 1042b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt intel_miptree_map_s8(intel, mt, map, level, slice); 1043ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } else if (mt->stencil_mt) { 1044ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_miptree_map_depthstencil(intel, mt, map, level, slice); 10455655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt } else if (intel->gen >= 6 && 10465655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt !(mode & GL_MAP_WRITE_BIT) && 10475655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt !mt->compressed && 10485655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt mt->region->tiling == I915_TILING_X) { 10495655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt intel_miptree_map_blit(intel, mt, map, level, slice); 1050b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } else { 1051b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt intel_miptree_map_gtt(intel, mt, map, level, slice); 1052b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } 1053baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt 1054baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt *out_ptr = map->ptr; 1055baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt *out_stride = map->stride; 1056baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt} 1057baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt 1058b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholtvoid 1059b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholtintel_miptree_unmap(struct intel_context *intel, 1060b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt struct intel_mipmap_tree *mt, 1061b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt unsigned int level, 1062b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt unsigned int slice) 1063b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt{ 1064221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt struct intel_miptree_map *map = mt->level[level].slice[slice].map; 1065221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt 1066221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt if (!map) 1067221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt return; 1068221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt 1069b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt DBG("%s: mt %p (%s) level %d slice %d\n", __FUNCTION__, 1070b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt mt, _mesa_get_format_name(mt->format), level, slice); 1071b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt 1072b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt if (mt->format == MESA_FORMAT_S8) { 1073b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt intel_miptree_unmap_s8(intel, mt, map, level, slice); 1074ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt } else if (mt->stencil_mt) { 1075ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt intel_miptree_unmap_depthstencil(intel, mt, map, level, slice); 10765655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt } else if (map->bo) { 10775655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt intel_miptree_unmap_blit(intel, mt, map, level, slice); 1078b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } else { 1079b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt intel_miptree_unmap_gtt(intel, mt, map, level, slice); 1080b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt } 1081221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt 1082221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt mt->level[level].slice[slice].map = NULL; 1083221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt free(map); 1084b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt} 1085