rocr: Add support for Mipmapped Array (#1847)

SWDEV-539526 - Add support for Mipmapped Array in Rocr

Add support for Mipmapped Array functionality in Rocr Runtimeenabling GPU applications to work with multi-level texture mipmaps. The implementation introduces new public APIs for creating, querying, and managing mipmapped arrays across different GPU architectures.

Signed-off-by: Apurv Mishra <Apurv.Mishra@amd.com>
Co-authored-by: Shweta Khatri <shweta.khatri@amd.com>
Co-authored-by: taosang2 <tao.sang@amd.com>
Αυτή η υποβολή περιλαμβάνεται σε:
authored and GitHub committed 2026-01-08 17:14:39 -06:00
1 γονέας 8b529e7b29
υποβολή be375c2dbf
21 files changed
+2918 -101

No files matched your search

@@ -216,14 +216,24 @@ ImageManagerGfx12::~ImageManagerGfx12() {}
hsa_status_t ImageManagerGfx12::CalculateImageSizeAndAlignment(
hsa_agent_t component, const hsa_ext_image_descriptor_t& desc,
hsa_ext_image_data_layout_t image_data_layout,
uint32_t num_mipmap_levels,
size_t image_data_row_pitch,
size_t image_data_slice_pitch,
hsa_ext_image_data_info_t& image_info) const {
ADDR3_COMPUTE_SURFACE_INFO_OUTPUT out = {0};
hsa_profile_t profile;
ADDR3_COMPUTE_SURFACE_INFO_OUTPUT out = {0};
// Allocate persistent memory for mip info on the heap
ADDR3_MIP_INFO* mip_info_storage = new ADDR3_MIP_INFO[num_mipmap_levels];
memset(mip_info_storage, 0, sizeof(ADDR3_MIP_INFO) * num_mipmap_levels);
out.pMipInfo = mip_info_storage;
hsa_profile_t profile;
hsa_status_t status = HSA::hsa_agent_get_info(component, HSA_AGENT_INFO_PROFILE, &profile);
if (status != HSA_STATUS_SUCCESS) return status;
if (status != HSA_STATUS_SUCCESS) {
delete[] mip_info_storage;
return status;
}
Image::TileMode tileMode = Image::TileMode::LINEAR;
if (image_data_layout == HSA_EXT_IMAGE_DATA_LAYOUT_OPAQUE) {
@@ -231,9 +241,9 @@ hsa_status_t ImageManagerGfx12::CalculateImageSizeAndAlignment(
desc.geometry != HSA_EXT_IMAGE_GEOMETRY_1DB)?
Image::TileMode::TILED : Image::TileMode::LINEAR;
}
if (GetAddrlibSurfaceInfoNv(component, desc, tileMode,
image_data_row_pitch, image_data_slice_pitch, out) ==
(uint32_t)(-1)) {
if (GetAddrlibSurfaceInfoNv(component, desc, num_mipmap_levels, tileMode,
image_data_row_pitch, image_data_slice_pitch, out) == (uint32_t)(-1)) {
delete[] mip_info_storage;
return HSA_STATUS_ERROR;
}
@@ -243,6 +253,7 @@ hsa_status_t ImageManagerGfx12::CalculateImageSizeAndAlignment(
image_data_layout == HSA_EXT_IMAGE_DATA_LAYOUT_LINEAR &&
((image_data_row_pitch && (rowPitch != image_data_row_pitch)) ||
(image_data_slice_pitch && (slicePitch != image_data_slice_pitch)))) {
delete[] mip_info_storage;
return static_cast<hsa_status_t>(
HSA_EXT_STATUS_ERROR_IMAGE_PITCH_UNSUPPORTED);
}
@@ -252,6 +263,9 @@ hsa_status_t ImageManagerGfx12::CalculateImageSizeAndAlignment(
image_info.alignment = out.baseAlign;
assert(image_info.alignment != 0);
// Clean up temporary mip info storage
delete[] mip_info_storage;
return HSA_STATUS_SUCCESS;
}
@@ -430,7 +444,6 @@ hsa_status_t ImageManagerGfx12::PopulateImageSrd(Image& image) const {
word1.val = 0;
word1.f.BASE_ADDRESS_HI = PtrHigh32(image_data_addr);
word1.f.STRIDE = image_prop.element_size;
word1.f.SWIZZLE_ENABLE = 0;
word2.f.NUM_RECORDS = image.desc.width * image_prop.element_size;
@@ -471,9 +484,8 @@ hsa_status_t ImageManagerGfx12::PopulateImageSrd(Image& image) const {
ADDR3_COMPUTE_SURFACE_INFO_OUTPUT out = {0};
uint32_t swizzleMode = GetAddrlibSurfaceInfoNv(
image.component, image.desc, image.tile_mode,
image.row_pitch, image.slice_pitch, out);
uint32_t swizzleMode = GetAddrlibSurfaceInfoNv(image.component, image.desc,
1, image.tile_mode, image.row_pitch, image.slice_pitch, out);
if (swizzleMode == (uint32_t)(-1)) {
return HSA_STATUS_ERROR;
}
@@ -642,6 +654,7 @@ hsa_status_t ImageManagerGfx12::PopulateSamplerSrd(Sampler& sampler) const {
uint32_t ImageManagerGfx12::GetAddrlibSurfaceInfoNv(
hsa_agent_t component, const hsa_ext_image_descriptor_t& desc,
uint32_t num_mipmap_levels,
Image::TileMode tileMode,
size_t image_data_row_pitch,
size_t image_data_slice_pitch,
@@ -664,7 +677,7 @@ uint32_t ImageManagerGfx12::GetAddrlibSurfaceInfoNv(
in.width = width;
in.height = height;
in.numSlices = num_slice;
in.pitchInElement = image_data_row_pitch / image_prop.element_size;
in.numMipLevels = num_mipmap_levels;
switch (desc.geometry) {
case HSA_EXT_IMAGE_GEOMETRY_1D:
@@ -672,46 +685,44 @@ uint32_t ImageManagerGfx12::GetAddrlibSurfaceInfoNv(
case HSA_EXT_IMAGE_GEOMETRY_1DA:
in.resourceType = ADDR_RSRC_TEX_1D;
break;
case HSA_EXT_IMAGE_GEOMETRY_2D:
case HSA_EXT_IMAGE_GEOMETRY_2DDEPTH:
case HSA_EXT_IMAGE_GEOMETRY_2DA:
case HSA_EXT_IMAGE_GEOMETRY_2DADEPTH:
in.resourceType = ADDR_RSRC_TEX_2D;
break;
case HSA_EXT_IMAGE_GEOMETRY_3D:
{
in.resourceType = ADDR_RSRC_TEX_3D;
/*
* 3D swizzle modes on GFX12 enforces alignment
* of the number of slices to the block depth.
* If numSlices = 3 then the 3 slices are
* interleaved for 3D locality among the 8 slices
* that make up each block. This causes the memory
* footprint to jump from an ideal size of ~12 GB
* to ~32 GB.
* 'enable3DSwizzleMode' flag tests for env variable
* HSA_IMAGE_ENABLE_3D_SWIZZLE_DEBUG to enable or disable
* 3D swizzle:
* true: Keep view3dAs2dArray = 0 for real 3D interleaving.
* false: Use view3dAs2dArray = 1 to avoid the alignment
* expansion.
* 2D swizzle modes can lower size overhead but may yield
* suboptimal cache behavior for fully 3D volumetric
* operations.
*/
bool enable3DSwizzleMode = core::Runtime::runtime_singleton_->flag().enable_3d_swizzle();
if (enable3DSwizzleMode)
{
in.resourceType = ADDR_RSRC_TEX_3D;
/*
* 3D swizzle modes on GFX12 enforces alignment
* of the number of slices to the block depth.
* If numSlices = 3 then the 3 slices are
* interleaved for 3D locality among the 8 slices
* that make up each block. This causes the memory
* footprint to jump from an ideal size of ~12 GB
* to ~32 GB.
* 'enable3DSwizzleMode' flag tests for env variable
* HSA_IMAGE_ENABLE_3D_SWIZZLE_DEBUG to enable or disable
* 3D swizzle:
* true: Keep view3dAs2dArray = 0 for real 3D interleaving.
* false: Use view3dAs2dArray = 1 to avoid the alignment
* expansion.
* 2D swizzle modes can lower size overhead but may yield
* suboptimal cache behavior for fully 3D volumetric
* operations.
*/
bool enable3DSwizzleMode = core::Runtime::runtime_singleton_->flag().enable_3d_swizzle();
if (enable3DSwizzleMode)
{
in.flags.view3dAs2dArray = 0;
}
else
{
in.flags.view3dAs2dArray = 1;
}
break;
in.flags.view3dAs2dArray = 0;
}
else
{
in.flags.view3dAs2dArray = 1;
}
break;
}
}
in.flags.texture = 1;
@@ -781,8 +792,9 @@ uint32_t ImageManagerGfx12::GetAddrlibSurfaceInfoNv(
const UINT_32 ratioLow = 2;
const UINT_32 ratioHigh = 1;
// Same behaviour as GFX11, remove linear if height is 1.
if (in.height > 1) {
// Remove linear swizzle mode for multi-dimensional or mipmapped textures.
// Linear mode is only appropriate for simple 1D single-level textures.
if (in.height > 1 || in.numMipLevels > 1) {
swOut.validModes.swLinear = 0;
}
@@ -793,6 +805,10 @@ uint32_t ImageManagerGfx12::GetAddrlibSurfaceInfoNv(
if (swOut.validModes.value & (1 << i)) {
ADDR3_COMPUTE_SURFACE_INFO_OUTPUT localOut = {0};
// pMipInfo not needed - set to nullptr and AddrLib will ignore it
localOut.pMipInfo = nullptr;
localOut.size = sizeof(ADDR3_COMPUTE_SURFACE_INFO_OUTPUT);
in.swizzleMode = (Addr3SwizzleMode) i;
@@ -908,5 +924,456 @@ hsa_status_t ImageManagerGfx12::FillImage(const Image& image, const void* patter
return status;
}
hsa_status_t ImageManagerGfx12::PopulateMipmapSrd(MipmappedArray& mipmap) const {
// Map format/geometry to hardware encoding
ImageProperty mipmap_prop = ImageLut().MapFormat(mipmap.desc.format, mipmap.desc.geometry);
assert(mipmap_prop.cap != HSA_EXT_IMAGE_CAPABILITY_NOT_SUPPORTED);
assert(mipmap_prop.element_size != 0);
assert(mipmap.num_levels >= 1);
const void* mipmap_data_addr = mipmap.data;
if (IsLocalMemory(mipmap.data)) {
mipmap_data_addr = reinterpret_cast<const void*>(
reinterpret_cast<uintptr_t>(mipmap.data) - local_memory_base_address_);
}
if (mipmap.desc.geometry == HSA_EXT_IMAGE_GEOMETRY_1DB) {
SQ_BUF_RSRC_WORD0 word0;
SQ_BUF_RSRC_WORD1 word1;
SQ_BUF_RSRC_WORD2 word2;
SQ_BUF_RSRC_WORD3 word3;
word0.val = 0;
word0.f.BASE_ADDRESS = PtrLow32(mipmap_data_addr);
word1.val = 0;
word1.f.BASE_ADDRESS_HI = PtrHigh32(mipmap_data_addr);
word1.f.STRIDE = mipmap_prop.element_size;
word1.f.SWIZZLE_ENABLE = 0;
word2.val = 0;
word2.f.NUM_RECORDS = mipmap.desc.width * mipmap_prop.element_size;
const Swizzle swizzle = ImageLut().MapSwizzle(mipmap.desc.format.channel_order);
word3.val = 0;
word3.f.DST_SEL_X = swizzle.x;
word3.f.DST_SEL_Y = swizzle.y;
word3.f.DST_SEL_Z = swizzle.z;
word3.f.DST_SEL_W = swizzle.w;
word3.f.FORMAT = GetCombinedFormat(mipmap_prop.data_format, mipmap_prop.data_type);
word3.f.INDEX_STRIDE = mipmap_prop.element_size;
// GFX12 compression features (disabled for now)
// word3.f.WRITE_COMPRESS_ENABLE = 0;
// word3.f.COMPRESSION_EN = 0;
// word3.f.COMPRESSION_ACCESS_MODE = 0;
word3.f.TYPE = ImageLut().MapGeometry(mipmap.desc.geometry);
mipmap.srd[0] = word0.val;
mipmap.srd[1] = word1.val;
mipmap.srd[2] = word2.val;
mipmap.srd[3] = word3.val;
// 1DB mipmaps don't use words 4-7
mipmap.srd[4] = 0;
mipmap.srd[5] = 0;
mipmap.srd[6] = 0;
mipmap.srd[7] = 0;
mipmap.row_pitch = mipmap.desc.width * mipmap_prop.element_size;
mipmap.slice_pitch = mipmap.row_pitch;
} else {
SQ_IMG_RSRC_WORD0 word0;
SQ_IMG_RSRC_WORD1 word1;
SQ_IMG_RSRC_WORD2 word2;
SQ_IMG_RSRC_WORD3 word3;
SQ_IMG_RSRC_WORD4 word4;
SQ_IMG_RSRC_WORD5 word5;
SQ_IMG_RSRC_WORD6 word6;
SQ_IMG_RSRC_WORD7 word7;
// Get ADDR3 surface information
ADDR3_COMPUTE_SURFACE_INFO_OUTPUT out = {0};
// pMipInfo not needed - set to nullptr and AddrLib will ignore it
out.pMipInfo = nullptr;
unsigned int swizzleMode = GetAddrlibSurfaceInfoNv(mipmap.component,
mipmap.desc, mipmap.num_levels, mipmap.tile_mode,
mipmap.row_pitch, mipmap.slice_pitch, out);
if (swizzleMode == (uint32_t)(-1)) {
return HSA_STATUS_ERROR;
}
mipmap.addr_output.addr3 = out;
mipmap.size = out.surfSize;
assert((out.bpp / 8) == mipmap_prop.element_size);
const size_t row_pitch_size = out.pitch * mipmap_prop.element_size;
word0.val = 0;
word0.f.BASE_ADDRESS = PtrLow40Shift8(mipmap_data_addr);
word1.val = 0;
word1.f.BASE_ADDRESS_HI = PtrHigh64Shift40(mipmap_data_addr);
word1.f.MAX_MIP = mipmap.num_levels - 1;
word1.f.BASE_LEVEL = 0; // New to GFX12
word1.f.FORMAT = GetCombinedFormat(mipmap_prop.data_format, mipmap_prop.data_type);
// Only take the lowest 2 bits of (image.desc.width - 1)
word1.f.WIDTH = BitSelect<0, 1>(mipmap.desc.width - 1);
word2.val = 0;
// Take the high 14 bits of (mipmap.desc.width - 1)
word2.f.WIDTH_HI = BitSelect<2, 15>(mipmap.desc.width - 1);
word2.f.HEIGHT = mipmap.desc.height ? mipmap.desc.height - 1 : 0;
const Swizzle swizzle = ImageLut().MapSwizzle(mipmap.desc.format.channel_order);
word3.val = 0;
word3.f.DST_SEL_X = swizzle.x;
word3.f.DST_SEL_Y = swizzle.y;
word3.f.DST_SEL_Z = swizzle.z;
word3.f.DST_SEL_W = swizzle.w;
// word3.f.NO_EDGE_CLAMP = 0; // New to GFX12
word3.f.LAST_LEVEL = mipmap.num_levels - 1;
word3.f.SW_MODE = swizzleMode;
word3.f.BC_SWIZZLE = GetBcSwizzle(swizzle);
word3.f.TYPE = ImageLut().MapGeometry(mipmap.desc.geometry);
const bool mipmap_array =
(mipmap.desc.geometry == HSA_EXT_IMAGE_GEOMETRY_1DA ||
mipmap.desc.geometry == HSA_EXT_IMAGE_GEOMETRY_2DA ||
mipmap.desc.geometry == HSA_EXT_IMAGE_GEOMETRY_2DADEPTH);
const bool mipmap_3d = (mipmap.desc.geometry == HSA_EXT_IMAGE_GEOMETRY_3D);
word4.val = 0;
// For 1d, 2d and 2d-msaa, fields DEPTH+PITCH_MSB encode pitch-1
if (!mipmap_array && !mipmap_3d) {
uint32_t encPitch = out.pitch - 1;
word4.f.DEPTH = encPitch & 0x3fff; // first 14 bits
word4.f.PITCH_MSB = (encPitch >> 14) & 0x3; // last 2 bits
} else {
word4.f.DEPTH =
(mipmap_array) // Doesn't hurt but isn't array_size already >0?
? std::max(mipmap.desc.array_size, static_cast<size_t>(1)) - 1
: (mipmap_3d) ? mipmap.desc.depth - 1 : 0;
}
word5.val = 0;
word6.val = 0;
word7.val = 0;
mipmap.srd[0] = word0.val;
mipmap.srd[1] = word1.val;
mipmap.srd[2] = word2.val;
mipmap.srd[3] = word3.val;
mipmap.srd[4] = word4.val;
mipmap.srd[5] = word5.val;
mipmap.srd[6] = word6.val;
mipmap.srd[7] = word7.val;
mipmap.row_pitch = row_pitch_size;
mipmap.slice_pitch = out.sliceSize;
}
mipmap.srd[8] = mipmap.desc.format.channel_type;
mipmap.srd[9] = mipmap.desc.format.channel_order;
mipmap.srd[10] = static_cast<uint32_t>(mipmap.desc.width);
// Mipmap-specific
mipmap.srd[11] = mipmap.num_levels;
return HSA_STATUS_SUCCESS;
}
hsa_status_t ImageManagerGfx12::PopulateMipmapSrd(MipmappedArray& mipmap_array, const metadata_amd_t* desc) const {
const metadata_amd_gfx12_t* desc_gfx12 = reinterpret_cast<const metadata_amd_gfx12_t*>(desc);
const void* mipmap_data_addr = mipmap_array.data;
ImageProperty mipmap_prop = ImageLut().MapFormat(mipmap_array.desc.format, mipmap_array.desc.geometry);
if (mipmap_prop.cap == HSA_EXT_IMAGE_CAPABILITY_NOT_SUPPORTED || mipmap_prop.element_size == 0) {
return (hsa_status_t)HSA_EXT_STATUS_ERROR_IMAGE_FORMAT_UNSUPPORTED;
}
const Swizzle swizzle = ImageLut().MapSwizzle(mipmap_array.desc.format.channel_order);
if (IsLocalMemory(mipmap_array.data)) {
mipmap_data_addr = reinterpret_cast<const void*>(
reinterpret_cast<uintptr_t>(mipmap_array.data) - local_memory_base_address_);
}
// Copy the pre-computed SRD words 0-7 from metadata
mipmap_array.srd[0] = desc_gfx12->word0.u32All;
mipmap_array.srd[1] = desc_gfx12->word1.u32All;
mipmap_array.srd[2] = desc_gfx12->word2.u32All;
mipmap_array.srd[3] = desc_gfx12->word3.u32All;
mipmap_array.srd[4] = desc_gfx12->word4.u32All;
mipmap_array.srd[5] = desc_gfx12->word5.u32All;
mipmap_array.srd[6] = desc_gfx12->word6.u32All;
mipmap_array.srd[7] = desc_gfx12->word7.u32All;
if (mipmap_array.desc.geometry == HSA_EXT_IMAGE_GEOMETRY_1DB) {
// 1DB uses buffer descriptors
SQ_BUF_RSRC_WORD0 word0;
SQ_BUF_RSRC_WORD1 word1;
SQ_BUF_RSRC_WORD3 word3;
word0.val = 0;
word0.f.BASE_ADDRESS = PtrLow32(mipmap_data_addr);
word1.val = mipmap_array.srd[1];
word1.f.BASE_ADDRESS_HI = PtrHigh32(mipmap_data_addr);
word1.f.STRIDE = mipmap_prop.element_size;
word3.val = mipmap_array.srd[3];
word3.f.DST_SEL_X = swizzle.x;
word3.f.DST_SEL_Y = swizzle.y;
word3.f.DST_SEL_Z = swizzle.z;
word3.f.DST_SEL_W = swizzle.w;
word3.f.FORMAT = GetCombinedFormat(mipmap_prop.data_format, mipmap_prop.data_type);
word3.f.INDEX_STRIDE = mipmap_prop.element_size;
mipmap_array.srd[0] = word0.val;
mipmap_array.srd[1] = word1.val;
mipmap_array.srd[3] = word3.val;
mipmap_array.row_pitch = mipmap_array.desc.width * mipmap_prop.element_size;
mipmap_array.slice_pitch = mipmap_array.row_pitch;
} else {
// Non-1DB uses image descriptors
uint32_t hwPixelSize = ImageLut().GetPixelSize(mipmap_prop.data_format, mipmap_prop.data_type);
if (mipmap_prop.element_size != hwPixelSize) {
return (hsa_status_t)HSA_EXT_STATUS_ERROR_IMAGE_FORMAT_UNSUPPORTED;
}
reinterpret_cast<SQ_IMG_RSRC_WORD0*>(&mipmap_array.srd[0])->bits.BASE_ADDRESS = PtrLow40Shift8(mipmap_data_addr);
reinterpret_cast<SQ_IMG_RSRC_WORD1*>(&mipmap_array.srd[1])->bits.BASE_ADDRESS_HI = PtrHigh64Shift40(mipmap_data_addr);
reinterpret_cast<SQ_IMG_RSRC_WORD1*>(&mipmap_array.srd[1])->bits.FORMAT = GetCombinedFormat(mipmap_prop.data_format, mipmap_prop.data_type);
reinterpret_cast<SQ_IMG_RSRC_WORD3*>(&mipmap_array.srd[3])->bits.DST_SEL_X = swizzle.x;
reinterpret_cast<SQ_IMG_RSRC_WORD3*>(&mipmap_array.srd[3])->bits.DST_SEL_Y = swizzle.y;
reinterpret_cast<SQ_IMG_RSRC_WORD3*>(&mipmap_array.srd[3])->bits.DST_SEL_Z = swizzle.z;
reinterpret_cast<SQ_IMG_RSRC_WORD3*>(&mipmap_array.srd[3])->bits.DST_SEL_W = swizzle.w;
if (mipmap_array.desc.geometry == HSA_EXT_IMAGE_GEOMETRY_1DA ||
mipmap_array.desc.geometry == HSA_EXT_IMAGE_GEOMETRY_1D) {
reinterpret_cast<SQ_IMG_RSRC_WORD3*>(&mipmap_array.srd[3])->bits.TYPE =
ImageLut().MapGeometry(mipmap_array.desc.geometry);
}
}
// Looks like this is only used for CPU copies.
mipmap_array.row_pitch = 0;
mipmap_array.slice_pitch = 0;
// Store mipmap-specific metadata
mipmap_array.srd[8] = mipmap_array.desc.format.channel_type;
mipmap_array.srd[9] = mipmap_array.desc.format.channel_order;
mipmap_array.srd[10] = static_cast<uint32_t>(mipmap_array.desc.width);
mipmap_array.srd[11] = mipmap_array.num_levels;
// Allocate and populate pMipInfo from metadata mip_offsets
ADDR3_MIP_INFO* mip_info_storage = new ADDR3_MIP_INFO[mipmap_array.num_levels];
memset(mip_info_storage, 0, sizeof(ADDR3_MIP_INFO) * mipmap_array.num_levels);
// Extract per-level information from mip_offsets array
for (uint32_t level = 0; level < mipmap_array.num_levels; level++) {
// mip_offsets contains offset bits [39:8], shift left by 8 to get actual byte offset
mip_info_storage[level].offset = static_cast<uint64_t>(desc_gfx12->mip_offsets[level]) << 8;
// Calculate dimensions for this level (halve at each level)
mip_info_storage[level].pixelPitch = std::max(1u, static_cast<uint32_t>(mipmap_array.desc.width >> level));
mip_info_storage[level].pixelHeight = std::max(1u, static_cast<uint32_t>(mipmap_array.desc.height >> level));
mip_info_storage[level].depth = std::max(1u, static_cast<uint32_t>(mipmap_array.desc.depth >> level));
}
// Store pMipInfo in addr_output for later use by PopulateMipLevelSrd
mipmap_array.addr_output.addr3.pMipInfo = mip_info_storage;
// Total size calculation from metadata (estimate from last level)
uint32_t last_level = mipmap_array.num_levels - 1;
uint64_t last_level_size = mip_info_storage[last_level].pixelPitch *
mip_info_storage[last_level].pixelHeight *
mip_info_storage[last_level].depth *
mipmap_prop.element_size;
mipmap_array.size = mip_info_storage[last_level].offset + last_level_size;
return HSA_STATUS_SUCCESS;
}
void ImageManagerGfx12::printSRDDetailed(const uint32_t* srd) const {
if (!srd) {
printf("\n========== Image SRD (GFX12) - Detailed ==========\n");
printf("ERROR: No SRD data provided.\n");
printf("===============================================\n\n");
return;
}
printf("\n========== Image SRD (GFX12) - Detailed ==========\n");
// Print all 12 words with bit field annotations
for (int i = 0; i < 12; i++) {
printf("WORD %d: 0x%08x ", i, srd[i]);
// Binary representation
printf("(");
for (int bit = 31; bit >= 0; bit--) {
printf("%d", (srd[i] >> bit) & 1);
if (bit % 4 == 0 && bit != 0) printf("_");
}
printf(")\n");
}
// WORD 0: SQ_IMG_RSRC_WORD0
SQ_IMG_RSRC_WORD0 word0;
word0.val = srd[0];
printf("\nWORD 0: BASE_ADDRESS (bits 39:8) = 0x%08x\n", word0.f.BASE_ADDRESS);
// WORD 1: SQ_IMG_RSRC_WORD1
SQ_IMG_RSRC_WORD1 word1;
word1.val = srd[1];
printf("WORD 1: BASE_ADDRESS_HI = 0x%08x\n", word1.f.BASE_ADDRESS_HI);
printf(" MAX_MIP = %u ◄──── Total mip levels - 1\n", word1.f.MAX_MIP);
printf(" BASE_LEVEL = %u ◄──── Current base level\n", word1.f.BASE_LEVEL);
printf(" FORMAT = %u\n", word1.f.FORMAT);
printf(" WIDTH (bits 1:0) = %u\n", word1.f.WIDTH);
// Calculate full address (GFX12 uses 40-bit shifted by 8)
uint64_t base_addr = ((uint64_t)word1.f.BASE_ADDRESS_HI << 40) | ((uint64_t)word0.f.BASE_ADDRESS << 8);
printf(" → Full Base Address = 0x%016lx\n", base_addr);
// WORD 2: SQ_IMG_RSRC_WORD2
SQ_IMG_RSRC_WORD2 word2;
word2.val = srd[2];
printf("WORD 2: WIDTH_HI (bits 15:2) = %u\n", word2.f.WIDTH_HI);
printf(" HEIGHT = %u\n", word2.f.HEIGHT);
// Calculate full width
uint32_t full_width = word1.f.WIDTH | (word2.f.WIDTH_HI << 2);
printf(" → Full Width = %u (actual: %u)\n", full_width, full_width + 1);
printf(" → Full Height = %u (actual: %u)\n", word2.f.HEIGHT, word2.f.HEIGHT + 1);
// WORD 3: SQ_IMG_RSRC_WORD3
SQ_IMG_RSRC_WORD3 word3;
word3.val = srd[3];
printf("WORD 3: DST_SEL_X = %u ", word3.f.DST_SEL_X);
printChannelSelect(word3.f.DST_SEL_X);
printf(" DST_SEL_Y = %u ", word3.f.DST_SEL_Y);
printChannelSelect(word3.f.DST_SEL_Y);
printf(" DST_SEL_Z = %u ", word3.f.DST_SEL_Z);
printChannelSelect(word3.f.DST_SEL_Z);
printf(" DST_SEL_W = %u ", word3.f.DST_SEL_W);
printChannelSelect(word3.f.DST_SEL_W);
printf(" LAST_LEVEL = %u ◄──── Current last level (GFX12 NEW)\n", word3.f.LAST_LEVEL);
printf(" SW_MODE = %u ", word3.f.SW_MODE);
printSwizzleMode(word3.f.SW_MODE);
printf(" BC_SWIZZLE = %u\n", word3.f.BC_SWIZZLE);
printf(" TYPE = %u ", word3.f.TYPE);
printResourceType(word3.f.TYPE);
// WORD 4: SQ_IMG_RSRC_WORD4
SQ_IMG_RSRC_WORD4 word4;
word4.val = srd[4];
printf("WORD 4: DEPTH = %u\n", word4.f.DEPTH);
printf(" PITCH_MSB = %u\n", word4.f.PITCH_MSB);
// Calculate effective depth/pitch based on geometry
uint32_t type = word3.f.TYPE;
if (type == 10) { // 3D
printf(" → 3D Depth = %u (actual: %u)\n", word4.f.DEPTH, word4.f.DEPTH + 1);
} else if (type == 13 || type == 12) { // Arrays
printf(" → Array Size = %u (actual: %u)\n", word4.f.DEPTH, word4.f.DEPTH + 1);
} else { // 1D/2D - encodes pitch
uint32_t encoded_pitch = word4.f.DEPTH | (word4.f.PITCH_MSB << 14);
printf(" → Encoded Pitch = %u (actual: %u)\n", encoded_pitch, encoded_pitch + 1);
}
// WORD 5-7: Usually zero for basic images
printf("WORD 5: Reserved = 0x%08x\n", srd[5]);
printf("WORD 6: Reserved = 0x%08x\n", srd[6]);
printf("WORD 7: Reserved = 0x%08x\n", srd[7]);
// Mipmap analysis
if (word1.f.MAX_MIP > 0) {
printf("\nMIPMAP ANALYSIS:\n");
printf(" Total Levels = %u (MAX_MIP + 1)\n", word1.f.MAX_MIP + 1);
printf(" Active Range = [%u, %u]\n", word1.f.BASE_LEVEL, word3.f.LAST_LEVEL);
if (word1.f.BASE_LEVEL == word3.f.LAST_LEVEL) {
printf(" Mode = SINGLE LEVEL VIEW ◄──── Mip level view\n");
uint32_t level = word1.f.BASE_LEVEL;
uint32_t level_width = std::max(1u, (full_width + 1) >> level);
uint32_t level_height = std::max(1u, static_cast<uint32_t>((word2.f.HEIGHT + 1) >> level));
printf(" Effective Dimensions = %ux%u (level %u)\n", level_width, level_height, level);
} else {
printf(" Mode = FULL MIPMAP CHAIN\n");
}
}
printf("===============================================\n\n");
}
void ImageManagerGfx12::printChannelSelect(uint32_t sel) const {
switch(sel) {
case 0: printf("(SEL_0)\n"); break;
case 1: printf("(SEL_1)\n"); break;
case 4: printf("(SEL_X/R)\n"); break;
case 5: printf("(SEL_Y/G)\n"); break;
case 6: printf("(SEL_Z/B)\n"); break;
case 7: printf("(SEL_W/A)\n"); break;
default: printf("(UNKNOWN)\n"); break;
}
}
void ImageManagerGfx12::printResourceType(uint32_t type) const {
switch(type) {
case 8: printf("(1D)\n"); break;
case 9: printf("(2D)\n"); break;
case 10: printf("(3D)\n"); break;
case 11: printf("(CUBE)\n"); break;
case 12: printf("(1D_ARRAY/1DB)\n"); break;
case 13: printf("(2D_ARRAY)\n"); break;
case 14: printf("(2D_MSAA)\n"); break;
case 15: printf("(2D_MSAA_ARRAY)\n"); break;
default: printf("(UNKNOWN=%u)\n", type); break;
}
}
void ImageManagerGfx12::printSwizzleMode(uint32_t sw_mode) const {
if (sw_mode == 0) {
printf("(LINEAR)\n");
} else if (sw_mode < 5) {
printf("(SW_256B_%u)\n", sw_mode);
} else if (sw_mode < 9) {
printf("(SW_4KB_%u)\n", sw_mode - 4);
} else if (sw_mode < 13) {
printf("(SW_64KB_%u)\n", sw_mode - 8);
} else if (sw_mode < 22) {
printf("(SW_VAR_%u)\n", sw_mode - 12);
} else {
printf("(UNKNOWN=%u)\n", sw_mode);
}
}
hsa_status_t ImageManagerGfx12::PopulateMipLevelSrd(
MipmappedArray& level_view,
const MipmappedArray& mipmap_array,
uint32_t mip_level) const {
// SRD already copied from parent, just modify BASE_LEVEL/LAST_LEVEL fields
uint32_t* srd_words = reinterpret_cast<uint32_t*>(level_view.srd);
// GFX12 SRD WORDs 1 and 3 has BASE_LEVEL and LAST_LEVEL fields
SQ_IMG_RSRC_WORD1* word1 = reinterpret_cast<SQ_IMG_RSRC_WORD1*>(&srd_words[1]);
SQ_IMG_RSRC_WORD3* word3 = reinterpret_cast<SQ_IMG_RSRC_WORD3*>(&srd_words[3]);
// Set both to same value - hardware samples only this level
word1->f.BASE_LEVEL = mip_level;
word3->f.LAST_LEVEL = mip_level;
debug_print("Set SRD mip selection: BASE_LEVEL=%u, LAST_LEVEL=%u", mip_level, mip_level);
return HSA_STATUS_SUCCESS;
}
} // namespace image
} // namespace rocr