Return null texture on encountering unmapped textures

This commit is contained in:
Billy Laws 2022-12-31 23:06:00 +00:00
parent 97e127153b
commit ec519a7d52

View File

@ -183,31 +183,7 @@ namespace skyline::gpu::interconnect {
}; };
} }
TextureView *Textures::GetTexture(InterconnectContext &ctx, u32 index, Shader::TextureType shaderType) { static std::shared_ptr<TextureView> CreateNullTexture(InterconnectContext &ctx) {
auto textureHeaders{texturePool.UpdateGet(ctx).textureHeaders};
if (textureHeaderCache.size() != textureHeaders.size()) {
textureHeaderCache.resize(textureHeaders.size());
std::fill(textureHeaderCache.begin(), textureHeaderCache.end(), CacheEntry{});
} else if (auto &cached{textureHeaderCache[index]}; cached.view) {
if (cached.executionTag == ctx.executor.executionTag)
return cached.view;
if (cached.tic == textureHeaders[index] && !cached.view->texture->replaced) {
cached.executionTag = ctx.executor.executionTag;
return cached.view;
}
}
TextureImageControl &textureHeader{textureHeaders[index]};
auto &texture{textureHeaderStore[textureHeader]};
if (!texture || texture->texture->replaced) {
// If the entry didn't exist prior then we need to convert the TIC to a GuestTexture
GuestTexture guest{};
if (auto format{ConvertTicFormat(textureHeader.formatWord, textureHeader.isSrgb)}) {
guest.format = format;
} else {
if (!nullTextureView) {
constexpr texture::Format NullImageFormat{format::R8G8B8A8Unorm}; constexpr texture::Format NullImageFormat{format::R8G8B8A8Unorm};
constexpr texture::Dimensions NullImageDimensions{1, 1, 1}; constexpr texture::Dimensions NullImageDimensions{1, 1, 1};
constexpr vk::ImageLayout NullImageInitialLayout{vk::ImageLayout::eUndefined}; constexpr vk::ImageLayout NullImageInitialLayout{vk::ImageLayout::eUndefined};
@ -235,13 +211,40 @@ namespace skyline::gpu::interconnect {
auto nullTexture{std::make_shared<Texture>(ctx.gpu, std::move(vkImage), NullImageDimensions, NullImageFormat, NullImageInitialLayout, NullImageTiling, NullImageFlags, NullImageUsage)}; auto nullTexture{std::make_shared<Texture>(ctx.gpu, std::move(vkImage), NullImageDimensions, NullImageFormat, NullImageInitialLayout, NullImageTiling, NullImageFlags, NullImageUsage)};
nullTexture->TransitionLayout(vk::ImageLayout::eGeneral); nullTexture->TransitionLayout(vk::ImageLayout::eGeneral);
nullTextureView = nullTexture->GetView(vk::ImageViewType::e2D, vk::ImageSubresourceRange{ return nullTexture->GetView(vk::ImageViewType::e2D, vk::ImageSubresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eColor, .aspectMask = vk::ImageAspectFlagBits::eColor,
.levelCount = 1, .levelCount = 1,
.layerCount = 1, .layerCount = 1,
}); });;
} }
TextureView *Textures::GetTexture(InterconnectContext &ctx, u32 index, Shader::TextureType shaderType) {
auto textureHeaders{texturePool.UpdateGet(ctx).textureHeaders};
if (textureHeaderCache.size() != textureHeaders.size()) {
textureHeaderCache.resize(textureHeaders.size());
std::fill(textureHeaderCache.begin(), textureHeaderCache.end(), CacheEntry{});
} else if (auto &cached{textureHeaderCache[index]}; cached.view) {
if (cached.executionTag == ctx.executor.executionTag)
return cached.view;
if (cached.tic == textureHeaders[index] && !cached.view->texture->replaced) {
cached.executionTag = ctx.executor.executionTag;
return cached.view;
}
}
TextureImageControl &textureHeader{textureHeaders[index]};
auto &texture{textureHeaderStore[textureHeader]};
if (!texture || texture->texture->replaced) {
// If the entry didn't exist prior then we need to convert the TIC to a GuestTexture
GuestTexture guest{};
if (auto format{ConvertTicFormat(textureHeader.formatWord, textureHeader.isSrgb)}) {
guest.format = format;
} else {
if (!nullTextureView)
nullTextureView = CreateNullTexture(ctx);
return nullTextureView.get(); return nullTextureView.get();
} }
@ -317,6 +320,13 @@ namespace skyline::gpu::interconnect {
auto mappings{ctx.channelCtx.asCtx->gmmu.TranslateRange(textureHeader.Iova(), guest.GetSize())}; auto mappings{ctx.channelCtx.asCtx->gmmu.TranslateRange(textureHeader.Iova(), guest.GetSize())};
guest.mappings.assign(mappings.begin(), mappings.end()); guest.mappings.assign(mappings.begin(), mappings.end());
if (guest.mappings.empty() || !guest.mappings.front().valid()) {
Logger::Warn("Unmapped texture in pool: 0x{:X}", textureHeader.Iova());
if (!nullTextureView)
nullTextureView = CreateNullTexture(ctx);
return nullTextureView.get();
}
texture = ctx.gpu.texture.FindOrCreate(guest, ctx.executor.tag); texture = ctx.gpu.texture.FindOrCreate(guest, ctx.executor.tag);
} }