Skip to content

Commit

Permalink
rpcsx-gpu: implement depth formats
Browse files Browse the repository at this point in the history
  • Loading branch information
DHrpcs3 committed Oct 2, 2024
1 parent 951d0a3 commit 60cecf4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
39 changes: 35 additions & 4 deletions rpcsx-gpu/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions rpcsx-gpu/Cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct Cache {

struct Image {
VkImage handle = VK_NULL_HANDLE;
VkFormat format;
VkImageSubresourceRange subresource;
};

Expand Down
2 changes: 2 additions & 0 deletions rpcsx-gpu/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions rpcsx-gpu/lib/gnm/include/gnm/gnm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ constexpr NumericFormat getNumericFormat(ZFormat format) {
case kZFormat32Float:
return kNumericFormatFloat;
case kZFormat16:
return kNumericFormatUInt;
return kNumericFormatUNorm;

case kZFormatInvalid:
break;
Expand All @@ -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;
Expand Down

0 comments on commit 60cecf4

Please sign in to comment.