static void intel_miptree_set_total_width_height(struct brw_context *brw, struct intel_mipmap_tree *mt) { switch (mt->target) { case GL_TEXTURE_CUBE_MAP: if (brw->gen == 4) { /* Gen4 stores cube maps as 3D textures. */ assert(mt->physical_depth0 == 6); brw_miptree_layout_texture_3d(brw, mt); } else { /* All other hardware stores cube maps as 2D arrays. */ brw_miptree_layout_texture_array(brw, mt); } break; case GL_TEXTURE_3D: if (brw->gen >= 9) brw_miptree_layout_texture_array(brw, mt); else brw_miptree_layout_texture_3d(brw, mt); break; case GL_TEXTURE_1D_ARRAY: case GL_TEXTURE_2D_ARRAY: case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: case GL_TEXTURE_CUBE_MAP_ARRAY: brw_miptree_layout_texture_array(brw, mt); break; default: switch (mt->msaa_layout) { case INTEL_MSAA_LAYOUT_UMS: case INTEL_MSAA_LAYOUT_CMS: brw_miptree_layout_texture_array(brw, mt); break; case INTEL_MSAA_LAYOUT_NONE: case INTEL_MSAA_LAYOUT_IMS: if (gen9_use_linear_1d_layout(brw, mt)) gen9_miptree_layout_1d(mt); else brw_miptree_layout_2d(mt); break; } break; } DBG("%s: %dx%dx%d\n", __func__, mt->total_width, mt->total_height, mt->cpp); }
static void brw_miptree_layout_texture_array(struct brw_context *brw, struct intel_mipmap_tree *mt) { unsigned height = mt->physical_height0; bool layout_1d = gen9_use_linear_1d_layout(brw, mt); int physical_qpitch; if (layout_1d) gen9_miptree_layout_1d(mt); else brw_miptree_layout_2d(mt); if (layout_1d) { physical_qpitch = 1; /* When using the horizontal layout the qpitch specifies the distance in * pixels between array slices. The total_width is forced to be a * multiple of the horizontal alignment in brw_miptree_layout_1d (in * this case it's always 64). The vertical alignment is ignored. */ mt->qpitch = mt->total_width; } else { mt->qpitch = brw_miptree_get_vertical_slice_pitch(brw, mt, 0); /* Unlike previous generations the qpitch is a multiple of the * compressed block size on Gen9 so physical_qpitch matches mt->qpitch. */ physical_qpitch = (mt->compressed && brw->gen < 9 ? mt->qpitch / 4 : mt->qpitch); } for (unsigned level = mt->first_level; level <= mt->last_level; level++) { unsigned img_height; img_height = ALIGN_NPOT(height, mt->align_h); if (mt->compressed) img_height /= mt->align_h; for (unsigned q = 0; q < mt->level[level].depth; q++) { if (mt->array_layout == ALL_SLICES_AT_EACH_LOD) { intel_miptree_set_image_offset(mt, level, q, 0, q * img_height); } else { intel_miptree_set_image_offset(mt, level, q, 0, q * physical_qpitch); } } height = minify(height, 1); } if (mt->array_layout == ALL_LOD_IN_EACH_SLICE) mt->total_height = physical_qpitch * mt->physical_depth0; align_cube(mt); }
static void brw_miptree_layout_texture_array(struct brw_context *brw, struct intel_mipmap_tree *mt) { int h0, h1; unsigned height = mt->physical_height0; bool layout_1d = use_linear_1d_layout(brw, mt); h0 = ALIGN(mt->physical_height0, mt->align_h); h1 = ALIGN(minify(mt->physical_height0, 1), mt->align_h); if (mt->array_layout == ALL_SLICES_AT_EACH_LOD) mt->qpitch = h0; else mt->qpitch = (h0 + h1 + (brw->gen >= 7 ? 12 : 11) * mt->align_h); int physical_qpitch = mt->compressed ? mt->qpitch / 4 : mt->qpitch; if (layout_1d) gen9_miptree_layout_1d(mt); else brw_miptree_layout_2d(mt); for (unsigned level = mt->first_level; level <= mt->last_level; level++) { unsigned img_height; img_height = ALIGN(height, mt->align_h); if (mt->compressed) img_height /= mt->align_h; for (int q = 0; q < mt->level[level].depth; q++) { if (mt->array_layout == ALL_SLICES_AT_EACH_LOD) { intel_miptree_set_image_offset(mt, level, q, 0, q * img_height); } else { intel_miptree_set_image_offset(mt, level, q, 0, q * physical_qpitch); } } height = minify(height, 1); } if (mt->array_layout == ALL_LOD_IN_EACH_SLICE) mt->total_height = physical_qpitch * mt->physical_depth0; align_cube(mt); }
void brw_miptree_layout(struct brw_context *brw, struct intel_mipmap_tree *mt) { bool multisampled = mt->num_samples > 1; bool gen6_hiz_or_stencil = false; if (brw->gen == 6 && mt->array_layout == ALL_SLICES_AT_EACH_LOD) { const GLenum base_format = _mesa_get_format_base_format(mt->format); gen6_hiz_or_stencil = _mesa_is_depth_or_stencil_format(base_format); } if (gen6_hiz_or_stencil) { /* On gen6, we use ALL_SLICES_AT_EACH_LOD for stencil/hiz because the * hardware doesn't support multiple mip levels on stencil/hiz. * * PRM Vol 2, Part 1, 7.5.3 Hierarchical Depth Buffer: * "The hierarchical depth buffer does not support the LOD field" * * PRM Vol 2, Part 1, 7.5.4.1 Separate Stencil Buffer: * "The stencil depth buffer does not support the LOD field" */ if (mt->format == MESA_FORMAT_S_UINT8) { /* Stencil uses W tiling, so we force W tiling alignment for the * ALL_SLICES_AT_EACH_LOD miptree layout. */ mt->align_w = 64; mt->align_h = 64; } else { /* Depth uses Y tiling, so we force need Y tiling alignment for the * ALL_SLICES_AT_EACH_LOD miptree layout. */ mt->align_w = 128 / mt->cpp; mt->align_h = 32; } } else { mt->align_w = intel_horizontal_texture_alignment_unit(brw, mt); mt->align_h = intel_vertical_texture_alignment_unit(brw, mt->format, multisampled); } switch (mt->target) { case GL_TEXTURE_CUBE_MAP: if (brw->gen == 4) { /* Gen4 stores cube maps as 3D textures. */ assert(mt->physical_depth0 == 6); brw_miptree_layout_texture_3d(brw, mt); } else { /* All other hardware stores cube maps as 2D arrays. */ brw_miptree_layout_texture_array(brw, mt); } break; case GL_TEXTURE_3D: if (brw->gen >= 9) brw_miptree_layout_texture_array(brw, mt); else brw_miptree_layout_texture_3d(brw, mt); break; case GL_TEXTURE_1D_ARRAY: case GL_TEXTURE_2D_ARRAY: case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: case GL_TEXTURE_CUBE_MAP_ARRAY: brw_miptree_layout_texture_array(brw, mt); break; default: switch (mt->msaa_layout) { case INTEL_MSAA_LAYOUT_UMS: case INTEL_MSAA_LAYOUT_CMS: brw_miptree_layout_texture_array(brw, mt); break; case INTEL_MSAA_LAYOUT_NONE: case INTEL_MSAA_LAYOUT_IMS: if (use_linear_1d_layout(brw, mt)) gen9_miptree_layout_1d(mt); else brw_miptree_layout_2d(mt); break; } break; } DBG("%s: %dx%dx%d\n", __FUNCTION__, mt->total_width, mt->total_height, mt->cpp); }