- [GPU] Rename TextureMemoryUsage to TextureExtent (and relevant functions/etc).

- [GPU] Precalculate memory byte usage for base mip (and any additional mip levels).
- [GPU] Change TextureCache::WatchCallback so that if it's fired multiple times for the same texture it does not assert.
- [GPU] Add write watches for texture memory associated with additional mipmap levels.
This commit is contained in:
gibbed 2018-05-31 19:36:25 -05:00
parent cd39bbed5c
commit e89a31006f
9 changed files with 213 additions and 152 deletions

View File

@ -67,8 +67,7 @@ bool TextureInfo::Prepare(const xe_gpu_texture_fetch_t& fetch,
info.is_tiled = fetch.tiled;
info.has_packed_mips = fetch.packed_mips;
info.guest_address = fetch.address << 12;
info.mip_address = fetch.mip_address << 12;
info.SetupMemoryInfo(fetch.base_address << 12, fetch.mip_address << 12);
if (info.format_info()->format == TextureFormat::kUnknown) {
XELOGE("Attempting to fetch from unsupported texture format %d",
@ -76,7 +75,7 @@ bool TextureInfo::Prepare(const xe_gpu_texture_fetch_t& fetch,
return false;
}
info.memory_usage = TextureMemoryUsage::Calculate(out_info, true);
info.extent = TextureExtent::Calculate(out_info, true);
return true;
}
@ -92,25 +91,27 @@ bool TextureInfo::PrepareResolve(uint32_t physical_address,
auto& info = *out_info;
info.format = format;
info.endianness = endian;
info.dimension = Dimension::k2D;
info.width = width - 1;
info.height = height - 1;
info.mip_levels = 1;
info.depth = depth - 1;
info.pitch = pitch;
info.mip_levels = 1;
info.endianness = endian;
info.is_tiled = true;
info.has_packed_mips = false;
info.guest_address = physical_address;
info.mip_address = 0;
info.SetupMemoryInfo(physical_address, 0);
if (info.format_info()->format == TextureFormat::kUnknown) {
assert_true("Unsupported texture format");
return false;
}
info.memory_usage = TextureMemoryUsage::Calculate(out_info, true);
info.extent = TextureExtent::Calculate(out_info, true);
return true;
}
@ -118,15 +119,15 @@ uint32_t TextureInfo::GetMaxMipLevels() const {
return 1 + xe::log2_floor(std::max({width + 1, height + 1, depth + 1}));
}
const TextureMemoryUsage TextureInfo::GetMipMemoryUsage(uint32_t mip,
bool is_guest) const {
const TextureExtent TextureInfo::GetMipExtent(uint32_t mip,
bool is_guest) const {
if (mip == 0) {
return memory_usage;
return extent;
}
uint32_t mip_width = xe::next_pow2(width + 1) >> mip;
uint32_t mip_height = xe::next_pow2(height + 1) >> mip;
return TextureMemoryUsage::Calculate(format_info(), mip_width, mip_height,
depth + 1, is_tiled, is_guest);
return TextureExtent::Calculate(format_info(), mip_width, mip_height,
depth + 1, is_tiled, is_guest);
}
void TextureInfo::GetMipSize(uint32_t mip, uint32_t* out_width,
@ -154,7 +155,7 @@ uint32_t TextureInfo::GetMipLocation(uint32_t mip, uint32_t* offset_x,
} else {
GetPackedTileOffset(0, offset_x, offset_y);
}
return guest_address;
return memory.base_address;
}
uint32_t address_base, address_offset;
@ -162,19 +163,22 @@ uint32_t TextureInfo::GetMipLocation(uint32_t mip, uint32_t* offset_x,
// If the texture is <= 16 pixels w/h, the mips are packed with the base
// texture. Otherwise, they're stored beginning from mip_address.
if (std::min(width, height) < 16) {
address_base = guest_address;
address_base = memory.base_address;
address_offset = 0;
} else if (guest_address == mip_address) {
address_base = guest_address;
address_offset = GetMipByteSize(0, is_guest);
} else if (memory.base_address == memory.mip_address) {
address_base = memory.base_address;
address_offset = memory.base_size;
} else {
address_base = mip_address;
address_base = memory.mip_address;
address_offset = 0;
}
auto bytes_per_block = format_info()->bytes_per_block();
if (!has_packed_mips) {
for (uint32_t i = 1; i < mip; i++) {
address_offset += GetMipByteSize(i, is_guest);
address_offset +=
GetMipExtent(i, is_guest).all_blocks() * bytes_per_block;
}
*offset_x = 0;
*offset_y = 0;
@ -193,7 +197,7 @@ uint32_t TextureInfo::GetMipLocation(uint32_t mip, uint32_t* offset_x,
// We've reached the point where the mips are packed into a single tile.
break;
}
address_offset += GetMipByteSize(i, is_guest);
address_offset += GetMipExtent(i, is_guest).all_blocks() * bytes_per_block;
}
// Now, check if the mip is packed at an offset.
@ -202,26 +206,6 @@ uint32_t TextureInfo::GetMipLocation(uint32_t mip, uint32_t* offset_x,
return address_base + address_offset;
}
uint32_t TextureInfo::GetMipByteSize(uint32_t mip, bool is_guest) const {
uint32_t bytes_per_block = format_info()->bytes_per_block();
auto mip_usage = GetMipMemoryUsage(mip, is_guest);
return mip_usage.all_blocks() * bytes_per_block;
}
uint32_t TextureInfo::GetMipVisibleByteSize(uint32_t mip, bool is_guest) const {
uint32_t bytes_per_block = format_info()->bytes_per_block();
auto mip_usage = GetMipMemoryUsage(mip, is_guest);
return mip_usage.visible_blocks() * bytes_per_block;
}
uint32_t TextureInfo::GetByteSize(bool is_guest) const {
uint32_t length = 0;
for (uint32_t mip = 0; mip < mip_levels; ++mip) {
length += GetMipByteSize(mip, is_guest);
}
return length;
}
bool TextureInfo::GetPackedTileOffset(uint32_t width, uint32_t height,
const FormatInfo* format_info,
int packed_tile, uint32_t* offset_x,
@ -314,5 +298,57 @@ uint64_t TextureInfo::hash() const {
return XXH64(this, sizeof(TextureInfo), 0);
}
void TextureInfo::SetupMemoryInfo(uint32_t base_address, uint32_t mip_address) {
memory.base_address = base_address;
memory.base_size = 0;
memory.mip_address = 0;
memory.mip_size = 0;
uint32_t bytes_per_block = format_info()->bytes_per_block();
if (mip_levels <= 1) {
// Sort circuit. Only one mip.
memory.base_size = GetMipExtent(0, true).all_blocks() * bytes_per_block;
return;
}
if (!has_packed_mips) {
assert_true(mip_address == 0 || mip_address == base_address);
for (uint32_t mip = 0; mip < mip_levels - 1; mip++) {
memory.base_size +=
GetMipExtent(mip, true).all_blocks() * bytes_per_block;
}
memory.base_size +=
GetMipExtent(mip_levels - 1, true).visible_blocks() * bytes_per_block;
return;
}
uint32_t total_size = 0;
uint32_t width_pow2 = xe::next_pow2(width + 1);
uint32_t height_pow2 = xe::next_pow2(height + 1);
// Walk forward to find the address of the mip.
uint32_t packed_mip_base = 1;
for (uint32_t mip = packed_mip_base; mip < mip_levels - 1;
mip++, packed_mip_base++) {
uint32_t mip_width = std::max(width_pow2 >> mip, 1u);
uint32_t mip_height = std::max(height_pow2 >> mip, 1u);
if (std::min(mip_width, mip_height) <= 16) {
// We've reached the point where the mips are packed into a single tile.
break;
}
total_size += GetMipExtent(mip, true).all_blocks() * bytes_per_block;
}
if (mip_address != base_address) {
memory.mip_address = mip_address;
memory.mip_size = total_size;
} else {
memory.base_size = GetMipExtent(0, true).all_blocks() * bytes_per_block;
memory.base_size += total_size;
}
}
} // namespace gpu
} // namespace xe

View File

@ -290,7 +290,7 @@ struct FormatInfo {
struct TextureInfo;
struct TextureMemoryUsage {
struct TextureExtent {
uint32_t pitch; // texel pitch
uint32_t height; // texel height
uint32_t block_height; // # of vertical blocks
@ -303,12 +303,18 @@ struct TextureMemoryUsage {
return block_pitch_h * block_height * depth;
}
static TextureMemoryUsage Calculate(const FormatInfo* format_info,
uint32_t pitch, uint32_t height,
uint32_t depth, bool is_tiled,
bool is_guest);
static TextureMemoryUsage Calculate(const TextureInfo* texture_info,
bool is_guest);
static TextureExtent Calculate(const FormatInfo* format_info, uint32_t pitch,
uint32_t height, uint32_t depth, bool is_tiled,
bool is_guest);
static TextureExtent Calculate(const TextureInfo* texture_info,
bool is_guest);
};
struct TextureMemoryInfo {
uint32_t base_address;
uint32_t base_size;
uint32_t mip_address;
uint32_t mip_size;
};
struct TextureInfo {
@ -324,10 +330,8 @@ struct TextureInfo {
bool is_tiled;
bool has_packed_mips;
TextureMemoryUsage memory_usage;
uint32_t guest_address;
uint32_t mip_address;
TextureMemoryInfo memory;
TextureExtent extent;
const FormatInfo* format_info() const {
return FormatInfo::Get(static_cast<uint32_t>(format));
@ -347,7 +351,7 @@ struct TextureInfo {
uint32_t GetMaxMipLevels() const;
const TextureMemoryUsage GetMipMemoryUsage(uint32_t mip, bool is_guest) const;
const TextureExtent GetMipExtent(uint32_t mip, bool is_guest) const;
void GetMipSize(uint32_t mip, uint32_t* width, uint32_t* height) const;
@ -355,11 +359,6 @@ struct TextureInfo {
uint32_t GetMipLocation(uint32_t mip, uint32_t* offset_x, uint32_t* offset_y,
bool is_guest) const;
uint32_t GetMipByteSize(uint32_t mip, bool is_guest) const;
uint32_t GetMipVisibleByteSize(uint32_t mip, bool is_guest) const;
uint32_t GetByteSize(bool is_guest) const;
static bool GetPackedTileOffset(uint32_t width, uint32_t height,
const FormatInfo* format_info,
int packed_tile, uint32_t* offset_x,
@ -372,6 +371,9 @@ struct TextureInfo {
bool operator==(const TextureInfo& other) const {
return std::memcmp(this, &other, sizeof(TextureInfo)) == 0;
}
private:
void SetupMemoryInfo(uint32_t base_address, uint32_t mip_address);
};
} // namespace gpu

View File

@ -19,11 +19,11 @@ namespace gpu {
using namespace xe::gpu::xenos;
static TextureMemoryUsage CalculateMemoryUsage(const FormatInfo* format_info,
uint32_t pitch, uint32_t height,
uint32_t depth, bool is_tiled,
bool is_guest) {
TextureMemoryUsage usage;
static TextureExtent CalculateExtent(const FormatInfo* format_info,
uint32_t pitch, uint32_t height,
uint32_t depth, bool is_tiled,
bool is_guest) {
TextureExtent usage;
usage.pitch = pitch;
usage.height = height;
@ -60,21 +60,17 @@ static TextureMemoryUsage CalculateMemoryUsage(const FormatInfo* format_info,
return usage;
}
TextureMemoryUsage TextureMemoryUsage::Calculate(const FormatInfo* format_info,
uint32_t pitch,
uint32_t height,
uint32_t depth, bool is_tiled,
bool is_guest) {
return CalculateMemoryUsage(format_info, pitch, height, depth, is_tiled,
is_guest);
TextureExtent TextureExtent::Calculate(const FormatInfo* format_info,
uint32_t pitch, uint32_t height,
uint32_t depth, bool is_tiled,
bool is_guest) {
return CalculateExtent(format_info, pitch, height, depth, is_tiled, is_guest);
}
TextureMemoryUsage TextureMemoryUsage::Calculate(const TextureInfo* info,
bool is_guest) {
TextureExtent TextureExtent::Calculate(const TextureInfo* info, bool is_guest) {
assert_not_null(info);
return CalculateMemoryUsage(info->format_info(), info->pitch,
info->height + 1, info->depth + 1, info->is_tiled,
is_guest);
return CalculateExtent(info->format_info(), info->pitch, info->height + 1,
info->depth + 1, info->is_tiled, is_guest);
}
} // namespace gpu

View File

@ -686,7 +686,7 @@ void TraceViewer::DrawTextureInfo(
}
ImGui::NextColumn();
ImGui::Text("Fetch Slot: %u", texture_binding.fetch_constant);
ImGui::Text("Guest Address: %.8X", texture_info.guest_address);
ImGui::Text("Guest Address: %.8X", texture_info.memory.base_address);
ImGui::Text("Format: %s", texture_info.format_info()->name);
switch (texture_info.dimension) {
case Dimension::k1D:

View File

@ -316,6 +316,10 @@ void TextureCache::WatchCallback(void* context_ptr, void* data_ptr,
uint32_t address) {
auto self = reinterpret_cast<TextureCache*>(context_ptr);
auto touched_texture = reinterpret_cast<Texture*>(data_ptr);
if (!touched_texture || !touched_texture->access_watch_handle) {
return;
}
// Clear watch handle first so we don't redundantly
// remove.
assert_not_zero(touched_texture->access_watch_handle);
@ -343,8 +347,12 @@ TextureCache::Texture* TextureCache::DemandResolveTexture(
}
// Tell the trace writer to "cache" this memory (but not read it)
trace_writer_->WriteMemoryReadCachedNop(texture_info.guest_address,
texture_info.GetByteSize(true));
trace_writer_->WriteMemoryReadCached(texture_info.memory.base_address,
texture_info.memory.base_size);
if (texture_info.memory.mip_address) {
trace_writer_->WriteMemoryReadCached(texture_info.memory.mip_address,
texture_info.memory.mip_size);
}
return it->second;
}
@ -370,18 +378,21 @@ TextureCache::Texture* TextureCache::DemandResolveTexture(
device_->DbgSetObjectName(
reinterpret_cast<uint64_t>(texture->image),
VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
xe::format_string("RT: 0x%.8X - 0x%.8X (%s, %s)",
texture_info.guest_address,
texture_info.guest_address +
texture_info.GetMipVisibleByteSize(0, true),
texture_info.format_info()->name,
get_dimension_name(texture_info.dimension)));
xe::format_string(
"RT: 0x%.8X - 0x%.8X (%s, %s)", texture_info.memory.base_address,
texture_info.memory.base_address + texture_info.memory.base_size,
texture_info.format_info()->name,
get_dimension_name(texture_info.dimension)));
// Setup an access watch. If this texture is touched, it is destroyed.
// TODO(gibbed): Setup access watch for mipmap data.
texture->access_watch_handle = memory_->AddPhysicalAccessWatch(
texture_info.guest_address, texture_info.GetMipVisibleByteSize(0, true),
texture_info.memory.base_address, texture_info.memory.base_size,
cpu::MMIOHandler::kWatchWrite, &WatchCallback, this, texture);
if (texture_info.memory.mip_address) {
texture->access_watch_handle = memory_->AddPhysicalAccessWatch(
texture_info.memory.mip_address, texture_info.memory.mip_size,
cpu::MMIOHandler::kWatchWrite, &WatchCallback, this, texture);
}
textures_[texture_hash] = texture;
COUNT_profile_set("gpu/texture_cache/textures", textures_.size());
@ -401,8 +412,12 @@ TextureCache::Texture* TextureCache::Demand(const TextureInfo& texture_info,
break;
}
trace_writer_->WriteMemoryReadCached(texture_info.guest_address,
texture_info.GetByteSize(true));
trace_writer_->WriteMemoryReadCached(texture_info.memory.base_address,
texture_info.memory.base_size);
if (texture_info.memory.mip_address) {
trace_writer_->WriteMemoryReadCached(texture_info.memory.mip_address,
texture_info.memory.mip_size);
}
return it->second;
}
}
@ -427,21 +442,30 @@ TextureCache::Texture* TextureCache::Demand(const TextureInfo& texture_info,
// TODO: Byte count -> pixel count (on x and y axes)
VkOffset2D offset;
auto collide_tex = LookupAddress(
texture_info.guest_address, texture_info.width + 1,
texture_info.memory.base_address, texture_info.width + 1,
texture_info.height + 1, texture_info.format_info()->format, &offset);
if (collide_tex != nullptr) {
// assert_always();
}
trace_writer_->WriteMemoryRead(texture_info.guest_address,
texture_info.GetByteSize(true));
trace_writer_->WriteMemoryReadCached(texture_info.memory.base_address,
texture_info.memory.base_size);
if (texture_info.memory.mip_address) {
trace_writer_->WriteMemoryReadCached(texture_info.memory.mip_address,
texture_info.memory.mip_size);
}
// Okay. Put a writewatch on it to tell us if it's been modified from the
// guest.
// TODO(gibbed): Setup access watch for mipmap data.
texture->access_watch_handle = memory_->AddPhysicalAccessWatch(
texture_info.guest_address, texture_info.GetMipVisibleByteSize(0, true),
texture_info.memory.base_address, texture_info.memory.base_size,
cpu::MMIOHandler::kWatchWrite, &WatchCallback, this, texture);
if (texture_info.memory.mip_address) {
texture->access_watch_handle = memory_->AddPhysicalAccessWatch(
texture_info.memory.mip_address, texture_info.memory.mip_size,
cpu::MMIOHandler::kWatchWrite, &WatchCallback, this, texture);
}
if (!UploadTexture(command_buffer, completion_fence, texture, texture_info)) {
FreeTexture(texture);
@ -453,8 +477,8 @@ TextureCache::Texture* TextureCache::Demand(const TextureInfo& texture_info,
reinterpret_cast<uint64_t>(texture->image),
VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
xe::format_string(
"T: 0x%.8X - 0x%.8X (%s, %s)", texture_info.guest_address,
texture_info.guest_address + texture_info.GetByteSize(true),
"T: 0x%.8X - 0x%.8X (%s, %s)", texture_info.memory.base_address,
texture_info.memory.base_address + texture_info.memory.base_size,
texture_info.format_info()->name,
get_dimension_name(texture_info.dimension)));
@ -712,24 +736,28 @@ TextureCache::Texture* TextureCache::Lookup(const TextureInfo& texture_info) {
return it->second;
}
}
// slow path
for (auto it = textures_.begin(); it != textures_.end(); ++it) {
const auto& other_texture_info = it->second->texture_info;
#define COMPARE_FIELD(x) \
if (texture_info.x != other_texture_info.x) continue
COMPARE_FIELD(guest_address);
COMPARE_FIELD(memory.base_address);
COMPARE_FIELD(memory.base_size);
COMPARE_FIELD(dimension);
COMPARE_FIELD(width);
COMPARE_FIELD(height);
COMPARE_FIELD(depth);
COMPARE_FIELD(endianness);
COMPARE_FIELD(is_tiled);
COMPARE_FIELD(GetByteSize(true));
#undef COMPARE_FIELD
if (!TextureFormatIsSimilar(texture_info.format,
other_texture_info.format)) {
continue;
}
/*const auto format_info = texture_info.format_info();
const auto other_format_info = other_texture_info.format_info();
#define COMPARE_FIELD(x) if (format_info->x != other_format_info->x) continue
@ -751,12 +779,12 @@ TextureCache::Texture* TextureCache::LookupAddress(uint32_t guest_address,
VkOffset2D* out_offset) {
for (auto it = textures_.begin(); it != textures_.end(); ++it) {
const auto& texture_info = it->second->texture_info;
if (guest_address >= texture_info.guest_address &&
guest_address < texture_info.guest_address +
texture_info.GetMipVisibleByteSize(0, true) &&
if (guest_address >= texture_info.memory.base_address &&
guest_address <
texture_info.memory.base_address + texture_info.memory.base_size &&
texture_info.pitch >= width && texture_info.height >= height &&
out_offset) {
auto offset_bytes = guest_address - texture_info.guest_address;
auto offset_bytes = guest_address - texture_info.memory.base_address;
if (texture_info.dimension == Dimension::k2D) {
out_offset->x = 0;
@ -769,7 +797,7 @@ TextureCache::Texture* TextureCache::LookupAddress(uint32_t guest_address,
return it->second;
}
if (texture_info.guest_address == guest_address &&
if (texture_info.memory.base_address == guest_address &&
texture_info.dimension == Dimension::k2D &&
texture_info.pitch == width && texture_info.height == height) {
if (out_offset) {
@ -831,60 +859,60 @@ bool TextureCache::ConvertTexture(uint8_t* dest, VkBufferImageCopy* copy_region,
void* host_address = memory_->TranslatePhysical(address);
auto is_cube = src.dimension == Dimension::kCube;
auto src_usage = src.GetMipMemoryUsage(mip, true);
auto dst_usage = GetMipMemoryUsage(src, mip);
auto src_extent = src.GetMipExtent(mip, true);
auto dst_extent = GetMipExtent(src, mip);
uint32_t src_pitch =
src_usage.block_pitch_h * src.format_info()->bytes_per_block();
src_extent.block_pitch_h * src.format_info()->bytes_per_block();
uint32_t dst_pitch =
dst_usage.block_pitch_h * GetFormatInfo(src.format)->bytes_per_block();
dst_extent.block_pitch_h * GetFormatInfo(src.format)->bytes_per_block();
auto copy_block = GetFormatCopyBlock(src.format);
const uint8_t* src_mem = reinterpret_cast<const uint8_t*>(host_address);
if (!src.is_tiled) {
for (uint32_t face = 0; face < dst_usage.depth; face++) {
for (uint32_t face = 0; face < dst_extent.depth; face++) {
src_mem += offset_y * src_pitch;
src_mem += offset_x * src.format_info()->bytes_per_block();
for (uint32_t y = 0; y < dst_usage.block_height; y++) {
for (uint32_t y = 0; y < dst_extent.block_height; y++) {
copy_block(src.endianness, dest + y * dst_pitch,
src_mem + y * src_pitch, dst_pitch);
}
src_mem += src_pitch * src_usage.block_pitch_v;
dest += dst_pitch * dst_usage.block_pitch_v;
src_mem += src_pitch * src_extent.block_pitch_v;
dest += dst_pitch * dst_extent.block_pitch_v;
}
} else {
// Untile image.
// We could do this in a shader to speed things up, as this is pretty slow.
for (uint32_t face = 0; face < dst_usage.depth; face++) {
for (uint32_t face = 0; face < dst_extent.depth; face++) {
texture_conversion::UntileInfo untile_info;
std::memset(&untile_info, 0, sizeof(untile_info));
untile_info.offset_x = offset_x;
untile_info.offset_y = offset_y;
untile_info.width = dst_usage.block_pitch_h;
untile_info.height = dst_usage.block_height;
untile_info.input_pitch = src_usage.block_pitch_h;
untile_info.output_pitch = dst_usage.block_pitch_h;
untile_info.width = dst_extent.block_pitch_h;
untile_info.height = dst_extent.block_height;
untile_info.input_pitch = src_extent.block_pitch_h;
untile_info.output_pitch = dst_extent.block_pitch_h;
untile_info.input_format_info = src.format_info();
untile_info.output_format_info = GetFormatInfo(src.format);
untile_info.copy_callback = [=](auto o, auto i, auto l) {
copy_block(src.endianness, o, i, l);
};
texture_conversion::Untile(dest, src_mem, &untile_info);
src_mem += src_pitch * src_usage.block_pitch_v;
dest += dst_pitch * dst_usage.block_pitch_v;
src_mem += src_pitch * src_extent.block_pitch_v;
dest += dst_pitch * dst_extent.block_pitch_v;
}
}
copy_region->bufferRowLength = dst_usage.pitch;
copy_region->bufferImageHeight = dst_usage.height;
copy_region->bufferRowLength = dst_extent.pitch;
copy_region->bufferImageHeight = dst_extent.height;
copy_region->imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy_region->imageSubresource.mipLevel = mip;
copy_region->imageSubresource.baseArrayLayer = 0;
copy_region->imageSubresource.layerCount = !is_cube ? 1 : 6;
copy_region->imageExtent.width = std::max(1u, (src.width + 1) >> mip);
copy_region->imageExtent.height = std::max(1u, (src.height + 1) >> mip);
copy_region->imageExtent.depth = !is_cube ? dst_usage.depth : 1;
copy_region->imageExtent.depth = !is_cube ? dst_extent.depth : 1;
return true;
}
@ -898,11 +926,12 @@ bool TextureCache::UploadTexture(VkCommandBuffer command_buffer,
size_t unpack_length = ComputeTextureStorage(src);
XELOGGPU(
"Uploading texture @ 0x%.8X (%dx%dx%d, length: 0x%.8X, format: %s, dim: "
"%s, levels: %d, tiled: %s)",
src.guest_address, src.width + 1, src.height + 1, src.depth + 1,
unpack_length, src.format_info()->name, get_dimension_name(src.dimension),
src.mip_levels, src.is_tiled ? "yes" : "no");
"Uploading texture @ 0x%.8X/0x%.8X (%dx%dx%d, length: 0x%.8X, format: "
"%s, dim: %s, levels: %d, tiled: %s)",
src.memory.base_address, src.memory.mip_address, src.width + 1,
src.height + 1, src.depth + 1, unpack_length, src.format_info()->name,
get_dimension_name(src.dimension), src.mip_levels,
src.is_tiled ? "yes" : "no");
if (!unpack_length) {
XELOGW("Failed to compute texture storage!");
@ -936,8 +965,8 @@ bool TextureCache::UploadTexture(VkCommandBuffer command_buffer,
// DEBUG: Check the source address. If it's completely zero'd out, print it.
bool valid = false;
auto src_data = memory_->TranslatePhysical(src.guest_address);
for (uint32_t i = 0; i < unpack_length; i++) {
auto src_data = memory_->TranslatePhysical(src.memory.base_address);
for (uint32_t i = 0; i < src.memory.base_size; i++) {
if (src_data[i] != 0) {
valid = true;
break;
@ -945,7 +974,7 @@ bool TextureCache::UploadTexture(VkCommandBuffer command_buffer,
}
if (!valid) {
XELOGW("Warning: Texture @ 0x%.8X is blank!", src.guest_address);
XELOGW("Warning: Texture @ 0x%.8X is blank!", src.memory.base_address);
}
// Upload texture into GPU memory.
@ -1057,21 +1086,20 @@ texture_conversion::CopyBlockCallback TextureCache::GetFormatCopyBlock(
}
}
TextureMemoryUsage TextureCache::GetMipMemoryUsage(const TextureInfo& src,
uint32_t mip) {
TextureExtent TextureCache::GetMipExtent(const TextureInfo& src, uint32_t mip) {
auto format_info = GetFormatInfo(src.format);
uint32_t width = src.width + 1;
uint32_t height = src.height + 1;
uint32_t depth = src.depth + 1;
TextureMemoryUsage usage;
TextureExtent usage;
if (mip == 0) {
usage = TextureMemoryUsage::Calculate(format_info, width, height, depth,
width, false);
usage = TextureExtent::Calculate(format_info, width, height, depth, width,
false);
} else {
uint32_t mip_width = xe::next_pow2(width) >> mip;
uint32_t mip_height = xe::next_pow2(height) >> mip;
usage = TextureMemoryUsage::Calculate(format_info, mip_width, mip_height,
depth, mip_width, false);
usage = TextureExtent::Calculate(format_info, mip_width, mip_height, depth,
mip_width, false);
}
return usage;
}
@ -1080,15 +1108,15 @@ uint32_t TextureCache::ComputeMipStorage(const FormatInfo* format_info,
uint32_t width, uint32_t height,
uint32_t depth, uint32_t mip) {
assert_not_null(format_info);
TextureMemoryUsage usage;
TextureExtent usage;
if (mip == 0) {
usage = TextureMemoryUsage::Calculate(format_info, width, height, depth,
false, false);
usage = TextureExtent::Calculate(format_info, width, height, depth, false,
false);
} else {
uint32_t mip_width = xe::next_pow2(width) >> mip;
uint32_t mip_height = xe::next_pow2(height) >> mip;
usage = TextureMemoryUsage::Calculate(format_info, mip_width, mip_height,
depth, false, false);
usage = TextureExtent::Calculate(format_info, mip_width, mip_height, depth,
false, false);
}
uint32_t bytes_per_block = format_info->bytes_per_block();
return usage.all_blocks() * bytes_per_block;
@ -1184,10 +1212,10 @@ void TextureCache::WritebackTexture(Texture* texture) {
wb_command_pool_->EndBatch();
auto dest = memory_->TranslatePhysical(texture->texture_info.guest_address);
if (status == VK_SUCCESS) {
std::memcpy(dest, alloc->host_ptr,
texture->texture_info.GetByteSize(false));
auto dest =
memory_->TranslatePhysical(texture->texture_info.memory.base_address);
std::memcpy(dest, alloc->host_ptr, texture->texture_info.memory.base_size);
}
wb_staging_buffer_.Scavenge();

View File

@ -156,8 +156,7 @@ class TextureCache {
static const FormatInfo* GetFormatInfo(TextureFormat format);
static texture_conversion::CopyBlockCallback GetFormatCopyBlock(
TextureFormat format);
static TextureMemoryUsage GetMipMemoryUsage(const TextureInfo& src,
uint32_t mip);
static TextureExtent GetMipExtent(const TextureInfo& src, uint32_t mip);
static uint32_t ComputeMipStorage(const FormatInfo* format_info,
uint32_t width, uint32_t height,
uint32_t depth, uint32_t mip);

View File

@ -1048,7 +1048,7 @@ bool VulkanCommandProcessor::IssueCopy() {
texture->in_flight_fence = current_batch_fence_;
// For debugging purposes only (trace viewer)
last_copy_base_ = texture->texture_info.guest_address;
last_copy_base_ = texture->texture_info.memory.base_address;
if (!frame_open_) {
BeginFrame();

View File

@ -408,12 +408,12 @@ XEPACKEDUNION(xe_gpu_texture_fetch_t, {
uint32_t pitch : 9; // +22 byte_pitch >> 5
uint32_t tiled : 1; // +31
uint32_t format : 6; // +0 dword_1
uint32_t endianness : 2; // +6
uint32_t request_size : 2; // +8
uint32_t stacked : 1; // +10
uint32_t clamp_policy : 1; // +11 d3d/opengl
uint32_t address : 20; // +12
uint32_t format : 6; // +0 dword_1
uint32_t endianness : 2; // +6
uint32_t request_size : 2; // +8
uint32_t stacked : 1; // +10
uint32_t clamp_policy : 1; // +11 d3d/opengl
uint32_t base_address : 20; // +12
union { // dword_2
struct {

View File

@ -381,7 +381,7 @@ void VdSwap(lpvoid_t buffer_ptr, // ptr into primary ringbuffer
buffer_ptr.Zero(64 * 4);
// virtual -> physical
fetch.address &= 0x1FFFF;
fetch.base_address &= 0x1FFFF;
uint32_t offset = 0;
auto dwords = buffer_ptr.as_array<uint32_t>();