Start porting TextureCache. Lots of stubbing going on.

This commit is contained in:
Henrik Rydgard 2016-01-03 23:09:37 +01:00
parent 5216a24590
commit cfcfd406fc
18 changed files with 2129 additions and 14 deletions

View File

@ -27,7 +27,7 @@
#define WRITE p+=sprintf
// Uses integer instructions available since OpenGL 3.0. Suitable for ES 3.0 as well.
void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat) {
void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat, ShaderLanguage language) {
char *p = buffer;
if (gl_extensions.IsGLES) {
WRITE(p, "#version 300 es\n");
@ -250,7 +250,8 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat, ShaderLanguag
GenerateDepalShaderFloat(buffer, pixelFormat, language);
break;
case GLSL_300:
GenerateDepalShader300(buffer, pixelFormat);
case GLSL_VULKAN:
GenerateDepalShader300(buffer, pixelFormat, language);
break;
case HLSL_DX9:
GenerateDepalShaderFloat(buffer, pixelFormat, language);

View File

@ -22,6 +22,7 @@
enum ShaderLanguage {
GLSL_140,
GLSL_300,
GLSL_VULKAN,
HLSL_DX9,
};

View File

@ -51,6 +51,8 @@ namespace DX9 {
struct FBO_DX9;
}
class VulkanFramebuffer;
struct VirtualFramebuffer {
int last_frame_used;
int last_frame_attached;
@ -90,6 +92,7 @@ struct VirtualFramebuffer {
union {
FBO *fbo;
DX9::FBO_DX9 *fbo_dx9;
VulkanFramebuffer *fbo_vk;
};
u16 drawnWidth;

View File

@ -39,6 +39,8 @@ enum FramebufferNotification {
struct VirtualFramebuffer;
class CachedTextureVulkan;
class TextureCacheCommon {
public:
TextureCacheCommon();
@ -96,6 +98,7 @@ public:
union {
u32 textureName;
void *texturePtr;
CachedTextureVulkan *vkTex;
};
int invalidHint;
u32 fullhash;

View File

@ -244,6 +244,7 @@
<ClInclude Include="Software\SoftGpu.h" />
<ClInclude Include="Software\TransformUnit.h" />
<ClInclude Include="Common\TextureDecoder.h" />
<ClInclude Include="Vulkan\DepalettizeShaderVulkan.h" />
<ClInclude Include="Vulkan\DrawEngineVulkan.h" />
<ClInclude Include="Vulkan\FragmentShaderGeneratorVulkan.h" />
<ClInclude Include="Vulkan\FramebufferVulkan.h" />
@ -251,6 +252,7 @@
<ClInclude Include="Vulkan\PipelineManagerVulkan.h" />
<ClInclude Include="Vulkan\ShaderManagerVulkan.h" />
<ClInclude Include="Vulkan\TextureCacheVulkan.h" />
<ClInclude Include="Vulkan\TextureScalerVulkan.h" />
<ClInclude Include="Vulkan\VertexShaderGeneratorVulkan.h" />
<ClInclude Include="Vulkan\VulkanUtil.h" />
</ItemGroup>
@ -339,6 +341,7 @@
<ClCompile Include="Vulkan\ShaderManagerVulkan.cpp" />
<ClCompile Include="Vulkan\StateMappingVulkan.cpp" />
<ClCompile Include="Vulkan\TextureCacheVulkan.cpp" />
<ClCompile Include="Vulkan\TextureScalerVulkan.cpp" />
<ClCompile Include="Vulkan\VertexShaderGeneratorVulkan.cpp" />
</ItemGroup>
<ItemGroup>

View File

@ -210,6 +210,8 @@
<ClInclude Include="Vulkan\VertexShaderGeneratorVulkan.h" />
<ClInclude Include="Vulkan\FragmentShaderGeneratorVulkan.h" />
<ClInclude Include="Vulkan\ShaderManagerVulkan.h" />
<ClInclude Include="Vulkan\TextureScalerVulkan.h" />
<ClInclude Include="Vulkan\DepalettizeShaderVulkan.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Math3D.cpp">
@ -404,5 +406,6 @@
<ClCompile Include="Vulkan\FragmentShaderGeneratorVulkan.cpp" />
<ClCompile Include="Vulkan\ShaderManagerVulkan.cpp" />
<ClCompile Include="Vulkan\TextureCacheVulkan.cpp" />
<ClCompile Include="Vulkan\TextureScalerVulkan.cpp" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,61 @@
#pragma once
// Copyright (c) 2014- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <map>
#include "Common/CommonTypes.h"
#include "GPU/ge_constants.h"
class DepalShader {
public:
/*
GLuint program;
GLuint fragShader;
GLint a_position;
GLint a_texcoord0;
*/
};
class DepalTexture {
public:
int texture;
int lastFrame;
};
// Caches both shaders and palette textures.
// Could even avoid bothering with palette texture and just use uniform data...
class DepalShaderCacheVulkan {
public:
DepalShaderCacheVulkan();
~DepalShaderCacheVulkan();
// This also uploads the palette and binds the correct texture.
DepalShader *GetDepalettizeShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat);
VulkanTexture *GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut);
void Clear();
void Decimate();
private:
u32 GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat);
bool CreateVertexShader();
// GLuint vertexShader_;
std::map<u32, DepalShader *> cache_;
std::map<u32, DepalTexture *> texCache_;
};

View File

@ -433,8 +433,8 @@ void DrawEngineVulkan::DoFlush(VkCommandBuffer cmd) {
};
vkCmdBindDescriptorSets(cmd_, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &ds, 3, dynamicUBOOffsets);
ibOffset = (uint32_t)(frame->pushData->Push(decIndex, 2 * indexGen.VertexCount()));
// vbOffset = frame->pushData->Push(decoded, )
ibOffset = (uint32_t)frame->pushData->Push(decIndex, 2 * indexGen.VertexCount());
vbOffset = (uint32_t)frame->pushData->Push(decoded, vertexCount * dec_->GetDecVtxFmt().stride);
VkDeviceSize offsets[1] = { vbOffset };
if (useElements) {

View File

@ -0,0 +1,24 @@
// Copyright (c) 2015- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include "GPU/Vulkan/FramebufferVulkan.h"
VulkanFramebuffer *FramebufferManagerVulkan::GetTempFBO(int width, int height, VulkanFBOColorDepth colorDepth) {
return nullptr;
}

View File

@ -20,6 +20,14 @@
#include "GPU/Common/FramebufferCommon.h"
#include "GPU/Vulkan/VulkanUtil.h"
// TODO: WTF?
enum VulkanFBOColorDepth {
VK_FBO_8888,
VK_FBO_565,
VK_FBO_4444,
VK_FBO_5551,
};
class FramebufferManagerVulkan : public FramebufferManagerCommon {
public:
// Subsequent commands will be enqueued on this buffer.
@ -29,6 +37,7 @@ public:
virtual void ClearBuffer(bool keepState = false) override {
throw std::logic_error("The method or operation is not implemented.");
}
VulkanFramebuffer *GetTempFBO(int width, int height, VulkanFBOColorDepth colorDepth);
virtual void RebindFramebuffer() override {
throw std::logic_error("The method or operation is not implemented.");

View File

@ -17,7 +17,7 @@
#include "GPU/Vulkan/GPU_Vulkan.h"
GPU_Vulkan::GPU_Vulkan(VulkanContext *vulkan) : transformDraw_(vulkan) {
GPU_Vulkan::GPU_Vulkan(VulkanContext *vulkan) : transformDraw_(vulkan), textureCache_(vulkan) {
}

View File

@ -65,7 +65,7 @@ public:
void Resized() override;
void ClearShaderCache() override;
bool DecodeTexture(u8 *dest, const GPUgstate &state) override {
return textureCache_.DecodeTexture(dest, state);
return false;
}
bool FramebufferDirty() override;
bool FramebufferReallyDirty() override;

File diff suppressed because it is too large Load Diff

View File

@ -17,22 +17,126 @@
#pragma once
#include "GPU/Common/TextureCacheCommon.h"
#include <map>
#include "Globals.h"
#include "GPU/GPUInterface.h"
#include "GPU/GPUState.h"
#include "GPU/Vulkan/TextureScalerVulkan.h"
#include "GPU/Common/TextureCacheCommon.h"
struct VirtualFramebuffer;
class FramebufferManagerVulkan;
class DepalShaderCacheVulkan;
class ShaderManagerVulkan;
class DrawEngineVulkan;
class VulkanContext;
struct SamplerCacheKey;
class TextureCacheVulkan : public TextureCacheCommon {
public:
bool SetOffsetTexture(u32 offset) override {
return false;
TextureCacheVulkan(VulkanContext *vulkan);
~TextureCacheVulkan();
void SetTexture(VkCommandBuffer cmd, VkImageView &imageView);
virtual bool SetOffsetTexture(u32 offset) override;
void Clear(bool delete_them);
void StartFrame();
void Invalidate(u32 addr, int size, GPUInvalidationType type);
void InvalidateAll(GPUInvalidationType type);
void ClearNextFrame();
void SetFramebufferManager(FramebufferManagerVulkan *fbManager) {
framebufferManager_ = fbManager;
}
void SetDepalShaderCache(DepalShaderCacheVulkan *dpCache) {
depalShaderCache_ = dpCache;
}
void SetShaderManager(ShaderManagerVulkan *sm) {
shaderManager_ = sm;
}
void SetTransformDrawEngine(DrawEngineVulkan *td) {
transformDraw_ = td;
}
size_t NumLoadedTextures() const {
return cache.size();
}
void ForgetLastTexture() {
lastBoundTexture = nullptr;
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void ApplyTexture(VkImageView &imageView, VkSampler &sampler);
bool DecodeTexture(u8 *dest, const GPUgstate &state) {
return false;
}
bool AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer, u32 texaddrOffset = 0) override;
void DetachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer) override;
void DownloadFramebufferForClut(u32 clutAddr, u32 bytes) override {
}
private:
void Decimate(); // Run this once per frame to get rid of old textures.
void DeleteTexture(TexCache::iterator it);
void *ReadIndexedTex(int level, const u8 *texptr, int bytesPerIndex, VkFormat dstFmt, int bufw);
void UpdateSamplingParams(TexCacheEntry &entry, bool force);
void LoadTextureLevel(TexCacheEntry &entry, int level, bool replaceImages, int scaleFactor, VkFormat dstFmt);
VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
void *DecodeTextureLevel(GETextureFormat format, GEPaletteFormat clutformat, int level, u32 &texByteAlign, VkFormat dstFmt, int scaleFactor, int *bufw = 0);
TexCacheEntry::Status CheckAlpha(const u32 *pixelData, VkFormat dstFmt, int stride, int w, int h);
template <typename T>
const T *GetCurrentClut();
u32 GetCurrentClutHash();
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple);
bool AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer, u32 texaddrOffset = 0) override;
void DetachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer) override;
void SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer);
void ApplyTextureFramebuffer(VkCommandBuffer cmd, TexCacheEntry *entry, VirtualFramebuffer *framebuffer, VkImageView &image, VkSampler &sampler);
void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key);
VulkanContext *vulkan_;
TexCache secondCache;
std::vector<u32> nameCache_;
u32 cacheSizeEstimate_;
u32 secondCacheSizeEstimate_;
// Separate to keep main texture cache size down.
struct AttachedFramebufferInfo {
u32 xOffset;
u32 yOffset;
};
std::map<u32, AttachedFramebufferInfo> fbTexInfo_;
void AttachFramebufferValid(TexCacheEntry *entry, VirtualFramebuffer *framebuffer, const AttachedFramebufferInfo &fbInfo);
void AttachFramebufferInvalid(TexCacheEntry *entry, VirtualFramebuffer *framebuffer, const AttachedFramebufferInfo &fbInfo);
bool clearCacheNextFrame_;
bool lowMemoryMode_;
TextureScalerVulkan scaler;
u32 *clutBuf_;
u32 clutHash_;
// True if the clut is just alpha values in the same order (RGBA4444-bit only.)
bool clutAlphaLinear_;
u16 clutAlphaLinearColor_;
CachedTextureVulkan *lastBoundTexture;
float maxAnisotropyLevel;
int decimationCounter_;
int texelsScaledThisFrame_;
int timesInvalidatedAllThisFrame_;
FramebufferManagerVulkan *framebufferManager_;
DepalShaderCacheVulkan *depalShaderCache_;
ShaderManagerVulkan *shaderManager_;
DrawEngineVulkan *transformDraw_;
};
VkFormat getClutDestFormatVulkan(GEPaletteFormat format);

View File

@ -0,0 +1,62 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#if _MSC_VER == 1700
// Has to be included before TextureScaler.h, else we get those std::bind errors in VS2012..
#include "../native/base/basictypes.h"
#endif
#include <algorithm>
#include "gfx/gl_common.h"
#include "GPU/Common/TextureScalerCommon.h"
#include "GPU/Vulkan/TextureScalerVulkan.h"
#include "Common/ColorConv.h"
#include "Common/Log.h"
#include "Common/ThreadPools.h"
int TextureScalerVulkan::BytesPerPixel(u32 format) {
return (format == GL_UNSIGNED_BYTE) ? 4 : 2;
}
u32 TextureScalerVulkan::Get8888Format() {
return GL_UNSIGNED_BYTE;
}
void TextureScalerVulkan::ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) {
switch (format) {
case GL_UNSIGNED_BYTE:
dest = source; // already fine
break;
case GL_UNSIGNED_SHORT_4_4_4_4:
GlobalThreadPool::Loop(std::bind(&convert4444_gl, (u16*)source, dest, width, placeholder::_1, placeholder::_2), 0, height);
break;
case GL_UNSIGNED_SHORT_5_6_5:
GlobalThreadPool::Loop(std::bind(&convert565_gl, (u16*)source, dest, width, placeholder::_1, placeholder::_2), 0, height);
break;
case GL_UNSIGNED_SHORT_5_5_5_1:
GlobalThreadPool::Loop(std::bind(&convert5551_gl, (u16*)source, dest, width, placeholder::_1, placeholder::_2), 0, height);
break;
default:
dest = source;
ERROR_LOG(G3D, "iXBRZTexScaling: unsupported texture format");
}
}

View File

@ -0,0 +1,27 @@
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include "Common/CommonTypes.h"
#include "GPU/Common/TextureScalerCommon.h"
class TextureScalerVulkan : public TextureScaler {
void ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) override;
int BytesPerPixel(u32 format) override;
u32 Get8888Format() override;
};

View File

@ -1672,3 +1672,22 @@ const char *VulkanResultToString(VkResult res) {
void VulkanAssertImpl(VkResult check, const char *function, const char *file, int line) {
const char *error = "(none)";
}
void VulkanFramebuffer::Create(VulkanContext *vulkan, int w, int h, VkFormat format) {
}
// void TransitionToImage()
void VulkanFramebuffer::BeginPass(VkCommandBuffer cmd) {
}
void VulkanFramebuffer::EndPass(VkCommandBuffer cmd) {
}
void VulkanFramebuffer::TransitionToTexture(VkCommandBuffer cmd) {
}
VkImageView VulkanFramebuffer::GetColorImageView() {
return nullptr;
}

View File

@ -337,6 +337,24 @@ private:
bool needStaging;
};
// Placeholder
class VulkanFramebuffer {
public:
void Create(VulkanContext *vulkan, int w, int h, VkFormat format);
// void TransitionToImage()
void BeginPass(VkCommandBuffer cmd);
void EndPass(VkCommandBuffer cmd);
void TransitionToTexture(VkCommandBuffer cmd);
VkImageView GetColorImageView();
private:
VkImage image_;
VkFramebuffer framebuffer_;
};
// Use these to push vertex, index and uniform data.
// TODO: Make it possible to suballocate pushbuffers from a large DeviceMemory block.
// TODO: Make this dynamically grow by chaining new buffers in the future.