graphics: create depth images for comparison textures

This commit is contained in:
nmzik
2026-09-04 00:54:59 +02:00
parent d762d24f73
commit 0ce19357f6
3 changed files with 130 additions and 5 deletions
+3 -2
View File
@@ -939,7 +939,7 @@ void TextureCache::UploadImage(Image& image, const ImageDesc& desc, Buffer& sour
image.Upload(copies, linear.buffer, linear.offset, linear.size);
};
if (desc.type != BindingType::DepthTarget) {
if (!info.IsDepth()) {
auto plan = BuildColorTransfer(image, desc.type, TransferDirection::Upload);
if (!plan.valid) {
EXIT("TextureCache: invalid color upload: binding=%u addr=0x%016" PRIx64
@@ -963,7 +963,8 @@ void TextureCache::UploadImage(Image& image, const ImageDesc& desc, Buffer& sour
return;
}
if (desc.type != BindingType::DepthTarget || info.samples != 1 || image.backing.samples != 1 ||
if ((desc.type != BindingType::Texture && desc.type != BindingType::DepthTarget) ||
info.samples != 1 || image.backing.samples != 1 ||
info.resources.layers == 0 || info.data.size % info.resources.layers != 0 ||
Prospero::NumBytesPerElement(info.guest_format) != info.bytes_per_block) {
EXIT("TextureCache: invalid depth upload\n");
@@ -512,6 +512,20 @@ struct NullImageSpec {
Prospero::BufferFormat guest_format;
};
static vk::Format TextureBackingFormat(const ShaderRecompiler::IR::ImageResource& resource,
Prospero::BufferFormat guest_format,
vk::Format view_format) {
if (!resource.depth_compare) {
return view_format;
}
const auto* policy = FindGuestDepthFormatPolicy(guest_format);
if (!IsSupportedSampledDepthResource(resource) || policy == nullptr) {
EXIT("unsupported comparison-sampled texture: format=%u\n",
static_cast<uint32_t>(guest_format));
}
return policy->depth_attachment_format;
}
static NullImageSpec NullTextureSpec(const ShaderRecompiler::IR::ImageResource& resource) {
switch (resource.numeric_class) {
case Prospero::TextureNumericClass::Float:
@@ -529,7 +543,7 @@ static TextureCache::ImageDesc NullTextureDesc(const ShaderRecompiler::IR::Image
TextureCache::BindingType binding) {
const auto spec = NullTextureSpec(resource);
TextureCache::ImageDesc desc {};
desc.info.pixel_format = spec.format;
desc.info.pixel_format = TextureBackingFormat(resource, spec.guest_format, spec.format);
desc.info.guest_format = spec.guest_format;
desc.info.type = Prospero::ImageType::kColor2D;
desc.info.extent = {1, 1, 1};
@@ -537,7 +551,7 @@ static TextureCache::ImageDesc NullTextureDesc(const ShaderRecompiler::IR::Image
desc.info.bytes_per_block = 4;
desc.info.samples = 1;
desc.info.mip_layout[0] = {0, 0, 1, 1};
desc.view_info.format = desc.info.pixel_format;
desc.view_info.format = spec.format;
desc.view_info.type = vk::ImageViewType::e2D;
desc.view_info.aspect = vk::ImageAspectFlagBits::eColor;
desc.view_info.usage = binding == TextureCache::BindingType::Storage
@@ -753,7 +767,7 @@ TextureBinding RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageR
const auto block_bytes = Prospero::BlockCompressedBytesPerBlock(format);
TextureCache::ImageDesc desc {};
desc.info.data = {address, size.size};
desc.info.pixel_format = pixel_format;
desc.info.pixel_format = TextureBackingFormat(resource, format, pixel_format);
desc.info.guest_format = format;
desc.info.type = TextureBaseType(type);
desc.info.extent = {width, height, volume ? depth : 1u};