Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoCommon: allow multiple texture assets to associate with a texture cache entry #11991

Conversation

iwubcode
Copy link
Contributor

(used in a future review)

@iwubcode iwubcode force-pushed the tcache_multiple_texture_dependencies branch from 838a5f6 to 0bec10d Compare June 24, 2023 07:22
@iwubcode iwubcode changed the title VideoCommon: allow multiple assets to associate with a texture cache entry VideoCommon: allow multiple texture assets to associate with a texture cache entry Jun 25, 2023
@AdmiralCurtiss
Copy link
Contributor

Can you explain why this is useful and what you plan to use it for?

@iwubcode
Copy link
Contributor Author

iwubcode commented Jun 30, 2023

@AdmiralCurtiss - apologies, I should have explained it in the opening. I was being lazy. I'm going to give you a bit of TMI but I want to explain things so that you have a better understanding of where I'm going.

First, I'll distinguish between a "texture" (the thing the graphics API loads onto the GPU) and an image, what you might author in Photoshop.

Images can be added as a singular texture, much like Dolphin does for its game textures that exist in the Texture Cache or you can add a separate image to an existing texture as another layer. Dolphin has support for layers because it uses them for stereo 3d to handle multiple views. Just a side note for the future: a layer has the requirement that the image must be the same size and the same format as the rest of the layers.

In addition to a texture, there's a thing called a sampler. The sampler tells a shader how to pull out pixels from the texture!

When you provide a shader details about a texture, you also provide a sampler. Samplers are limited, even on modern GPUs you can only have something like 16. Technically you can have many many textures which is why we can have so many in the TextureCache!

Ok, so at the moment Dolphin supports a single custom texture to be loaded. What this does, is instead of loading the game texture into layer 0, we load the custom texture instead!

But what if we want more images? Modern lighting implementations can use a bunch of images!

We could load multiple images, each as its own texture. But we'd have to expose it to the shader with individual samplers. Dolphin already uses up to 8 samplers on Wii/GC for a single draw. If we wanted to do something crazy we'd either need more (remember we can only have at most 16) or we'd have to know how many Dolphin was using and use whatever was left. I do want to support more samplers in the near future but not now.

The other option, is to load the other images as separate layers in the existing game texture! That is what is happening in this PR.

The other thing this PR does is associate this texture cache entry with not just the game texture asset but also all these additional images as assets as well. This means if I go and tweak my Nth image layer on a texture using Photoshop and save it, the image asset will trigger the texture to be reloaded in Dolphin automatically.

This PR is ultimately to support an updated #11300 . In the current implementation of that PR, I append the additional layers after Dolphin loads the custom texture. This is very inefficient because to create a texture, you have to tell it how many layers you intend to have up front.

Please let me know if you have any questions. I'm sorry for the wall of text.

@iwubcode iwubcode force-pushed the tcache_multiple_texture_dependencies branch from 0bec10d to 67b7d33 Compare July 2, 2023 17:49
@iwubcode iwubcode force-pushed the tcache_multiple_texture_dependencies branch from 67b7d33 to a93e6e7 Compare July 2, 2023 17:50
@AdmiralCurtiss AdmiralCurtiss merged commit 6d7bf60 into dolphin-emu:master Jul 2, 2023
14 checks passed
@iwubcode iwubcode deleted the tcache_multiple_texture_dependencies branch July 2, 2023 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants