Skip to content

Commit

Permalink
Add way to bind cached textures to a DrawContext
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Sep 14, 2022
1 parent f745e94 commit abd5819
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions GPU/Common/TextureCacheCommon.cpp
Expand Up @@ -2163,7 +2163,7 @@ void TextureCacheCommon::ApplyTextureDepal(TexCacheEntry *entry) {
Draw::Viewport vp{ 0.0f, 0.0f, (float)texWidth, (float)texHeight, 0.0f, 1.0f };
draw_->SetViewports(1, &vp);

draw_->BindNativeTexture(0, framebuffer->fbo);
draw_->BindNativeTexture(0, GetNativeTextureView(entry));
draw_->BindFramebufferAsTexture(clutFbo, 1, Draw::FB_COLOR_BIT, 0);
Draw::SamplerState *nearest = textureShaderCache_->GetSampler(false);
Draw::SamplerState *clutSampler = textureShaderCache_->GetSampler(false);
Expand All @@ -2185,8 +2185,8 @@ void TextureCacheCommon::ApplyTextureDepal(TexCacheEntry *entry) {
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;

CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBufRaw_, clutFormat, clutTotalColors);
gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL);
// We don't know about alpha at all.
gstate_c.SetTextureFullAlpha(false);

draw_->InvalidateCachedState();
shaderManager_->DirtyLastShader();
Expand Down
3 changes: 3 additions & 0 deletions GPU/Common/TextureCacheCommon.h
Expand Up @@ -108,6 +108,8 @@ struct TextureDefinition {

// NOTE: These only handle textures loaded directly from PSP memory contents.
// Framebuffer textures do not have entries, we bind the framebuffers directly.
// At one point we might merge the concepts of framebuffers and textures, but that
// moment is far away.
struct TexCacheEntry {
~TexCacheEntry() {
if (texturePtr || textureName || vkTex)
Expand Down Expand Up @@ -345,6 +347,7 @@ class TextureCacheCommon {
virtual bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { return false; }

protected:
virtual void *GetNativeTextureView(const TexCacheEntry *entry) = 0;
bool PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEntry *entry);

virtual void BindTexture(TexCacheEntry *entry) = 0;
Expand Down
5 changes: 5 additions & 0 deletions GPU/D3D11/TextureCacheD3D11.cpp
Expand Up @@ -525,3 +525,8 @@ bool TextureCacheD3D11::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level
stagingCopy->Release();
return true;
}

void *TextureCacheD3D11::GetNativeTextureView(const TexCacheEntry *entry) {
ID3D11ShaderResourceView *textureView = DxView(entry);
return (void *)textureView;
}
5 changes: 3 additions & 2 deletions GPU/D3D11/TextureCacheD3D11.h
Expand Up @@ -61,6 +61,7 @@ class TextureCacheD3D11 : public TextureCacheCommon {
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
void ApplySamplingParams(const SamplerCacheKey &key) override;
void *GetNativeTextureView(const TexCacheEntry *entry) override;

private:
DXGI_FORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
Expand All @@ -72,10 +73,10 @@ class TextureCacheD3D11 : public TextureCacheCommon {
ID3D11Device *device_;
ID3D11DeviceContext *context_;

ID3D11Resource *&DxTex(TexCacheEntry *entry) {
ID3D11Resource *&DxTex(const TexCacheEntry *entry) {
return (ID3D11Resource *&)entry->texturePtr;
}
ID3D11ShaderResourceView *DxView(TexCacheEntry *entry) {
ID3D11ShaderResourceView *DxView(const TexCacheEntry *entry) {
return (ID3D11ShaderResourceView *)entry->textureView;
}

Expand Down
5 changes: 5 additions & 0 deletions GPU/Directx9/TextureCacheDX9.cpp
Expand Up @@ -454,3 +454,8 @@ bool TextureCacheDX9::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level)

return success;
}

void *TextureCacheDX9::GetNativeTextureView(const TexCacheEntry *entry) {
LPDIRECT3DBASETEXTURE9 tex = DxTex(entry);
return (void *)tex;
}
3 changes: 2 additions & 1 deletion GPU/Directx9/TextureCacheDX9.h
Expand Up @@ -50,6 +50,7 @@ class TextureCacheDX9 : public TextureCacheCommon {
void Unbind() override;
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
void *GetNativeTextureView(const TexCacheEntry *entry) override;

private:
void ApplySamplingParams(const SamplerCacheKey &key) override;
Expand All @@ -60,7 +61,7 @@ class TextureCacheDX9 : public TextureCacheCommon {

void BuildTexture(TexCacheEntry *const entry) override;

LPDIRECT3DBASETEXTURE9 &DxTex(TexCacheEntry *entry) {
LPDIRECT3DBASETEXTURE9 &DxTex(const TexCacheEntry *entry) const {
return *(LPDIRECT3DBASETEXTURE9 *)&entry->texturePtr;
}

Expand Down
5 changes: 5 additions & 0 deletions GPU/GLES/TextureCacheGLES.cpp
Expand Up @@ -443,3 +443,8 @@ void TextureCacheGLES::DeviceRestore(Draw::DrawContext *draw) {
render_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
textureShaderCache_->DeviceRestore(draw);
}

void *TextureCacheGLES::GetNativeTextureView(const TexCacheEntry *entry) {
GLRTexture *tex = entry->textureName;
return (void *)tex;
}
1 change: 1 addition & 0 deletions GPU/GLES/TextureCacheGLES.h
Expand Up @@ -66,6 +66,7 @@ class TextureCacheGLES : public TextureCacheCommon {
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;

void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
void *GetNativeTextureView(const TexCacheEntry *entry) override;

private:
void ApplySamplingParams(const SamplerCacheKey &key) override;
Expand Down
5 changes: 5 additions & 0 deletions GPU/Vulkan/TextureCacheVulkan.cpp
Expand Up @@ -857,3 +857,8 @@ std::vector<std::string> TextureCacheVulkan::DebugGetSamplerIDs() const {
std::string TextureCacheVulkan::DebugGetSamplerString(std::string id, DebugShaderStringType stringType) {
return samplerCache_.DebugGetSamplerString(id, stringType);
}

void *TextureCacheVulkan::GetNativeTextureView(const TexCacheEntry *entry) {
VkImageView view = entry->vkTex->GetImageView();
return (void *)view;
}
1 change: 1 addition & 0 deletions GPU/Vulkan/TextureCacheVulkan.h
Expand Up @@ -97,6 +97,7 @@ class TextureCacheVulkan : public TextureCacheCommon {
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
void ApplySamplingParams(const SamplerCacheKey &key) override;
void BoundFramebufferTexture() override;
void *GetNativeTextureView(const TexCacheEntry *entry) override;

private:
void LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt);
Expand Down

0 comments on commit abd5819

Please sign in to comment.