rpcsx-gpu: implement depth formats

This commit is contained in:
DH 2024-10-02 15:27:32 +03:00
parent 951d0a35a2
commit 60cecf4fbc
4 changed files with 40 additions and 6 deletions

View file

@ -1091,6 +1091,8 @@ Cache::Image Cache::Tag::getImage(const ImageKey &key, Access access) {
VkImageUsageFlags usage =
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
VkFormat format;
if (key.kind == ImageKind::Color) {
usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
bool isCompressed =
@ -1103,14 +1105,39 @@ Cache::Image Cache::Tag::getImage(const ImageKey &key, Access access) {
if (!isCompressed) {
usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
}
format = gnm::toVkFormat(key.dfmt, key.nfmt);
} else {
if (key.kind == ImageKind::Depth) {
if (key.dfmt == gnm::kDataFormat32 &&
key.nfmt == gnm::kNumericFormatFloat) {
format = VK_FORMAT_D32_SFLOAT;
} else if (key.dfmt == gnm::kDataFormat16 &&
key.nfmt == gnm::kNumericFormatUNorm) {
format = VK_FORMAT_D16_UNORM;
} else {
rx::die("unexpected depth format %u, %u", static_cast<int>(key.dfmt),
static_cast<int>(key.nfmt));
}
} else if (key.kind == ImageKind::Stencil) {
if (key.dfmt == gnm::kDataFormat8 &&
key.nfmt == gnm::kNumericFormatUInt) {
format = VK_FORMAT_S8_UINT;
} else {
rx::die("unexpected stencil format %u, %u", static_cast<int>(key.dfmt),
static_cast<int>(key.nfmt));
}
} else {
rx::die("image kind %u %u, %u", static_cast<int>(key.kind),
static_cast<int>(key.dfmt), static_cast<int>(key.nfmt));
}
usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
auto image = vk::Image::Allocate(
vk::getDeviceLocalMemory(), gnm::toVkImageType(key.type), key.extent,
key.mipCount, key.arrayLayerCount, gnm::toVkFormat(key.dfmt, key.nfmt),
VK_SAMPLE_COUNT_1_BIT, usage);
key.mipCount, key.arrayLayerCount, format, VK_SAMPLE_COUNT_1_BIT, usage);
VkImageSubresourceRange subresourceRange{
.aspectMask = toAspect(key.kind),
@ -1236,13 +1263,17 @@ Cache::Image Cache::Tag::getImage(const ImageKey &key, Access access) {
cached->acquiredDfmt = key.dfmt;
mStorage->mAcquiredResources.push_back(cached);
return {.handle = cached->image.getHandle(), .subresource = subresourceRange};
return {
.handle = cached->image.getHandle(),
.format = format,
.subresource = subresourceRange,
};
}
Cache::ImageView Cache::Tag::getImageView(const ImageKey &key, Access access) {
auto image = getImage(key, access);
auto result = vk::ImageView(gnm::toVkImageViewType(key.type), image.handle,
gnm::toVkFormat(key.dfmt, key.nfmt), {},
image.format, {},
{
.aspectMask = toAspect(key.kind),
.baseMipLevel = key.baseMipLevel,

View file

@ -148,6 +148,7 @@ struct Cache {
struct Image {
VkImage handle = VK_NULL_HANDLE;
VkFormat format;
VkImageSubresourceRange subresource;
};

View file

@ -220,6 +220,8 @@ void amdgpu::draw(GraphicsPipe &pipe, int vmId, std::uint32_t firstVertex,
.depth = 1,
},
.pitch = viewPortRect.extent.width,
.mipCount = 1,
.arrayLayerCount = 1,
.kind = ImageKind::Depth,
},
depthAccess);

View file

@ -272,7 +272,7 @@ constexpr NumericFormat getNumericFormat(ZFormat format) {
case kZFormat32Float:
return kNumericFormatFloat;
case kZFormat16:
return kNumericFormatUInt;
return kNumericFormatUNorm;
case kZFormatInvalid:
break;
@ -296,7 +296,7 @@ constexpr DataFormat getDataFormat(StencilFormat format) {
constexpr NumericFormat getNumericFormat(StencilFormat format) {
switch (format) {
case kStencil8:
return kNumericFormatSInt;
return kNumericFormatUInt;
case kStencilInvalid:
break;