mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Buildfixes
This commit is contained in:
1 parent
92a3d45340
commit
de10c1fddd
8 files changed
+4
-306
No files matched your search
@@ -1460,8 +1460,6 @@ set(GPU_GLES
|
||||
)
|
||||
|
||||
set(GPU_VULKAN
|
||||
GPU/Vulkan/DepalettizeShaderVulkan.cpp
|
||||
GPU/Vulkan/DepalettizeShaderVulkan.h
|
||||
GPU/Vulkan/DebugVisVulkan.cpp
|
||||
GPU/Vulkan/DebugVisVulkan.h
|
||||
GPU/Vulkan/DrawEngineVulkan.cpp
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
// 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 "Common/Data/Convert/ColorConv.h"
|
||||
#include "Common/GPU/Vulkan/VulkanImage.h"
|
||||
#include "Common/GPU/Vulkan/VulkanMemory.h"
|
||||
#include "Common/GPU/Vulkan/VulkanContext.h"
|
||||
#include "GPU/ge_constants.h"
|
||||
#include "GPU/GPUState.h"
|
||||
#include "GPU/Common/DepalettizeShaderCommon.h"
|
||||
#include "GPU/Vulkan/DepalettizeShaderVulkan.h"
|
||||
#include "GPU/Vulkan/VulkanUtil.h"
|
||||
#include "Common/GPU/Vulkan/VulkanImage.h"
|
||||
|
||||
static const char depal_vs[] = R"(#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
#extension GL_ARB_shading_language_420pack : enable
|
||||
layout (location = 0) in vec3 a_position;
|
||||
layout (location = 1) in vec2 a_texcoord0;
|
||||
layout (location = 0) out vec2 v_texcoord0;
|
||||
out gl_PerVertex { vec4 gl_Position; };
|
||||
void main() {
|
||||
v_texcoord0 = a_texcoord0;
|
||||
gl_Position = vec4(a_position, 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
static VkFormat GetClutDestFormat(GEPaletteFormat format, VkComponentMapping *componentMapping) {
|
||||
switch (format) {
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
*componentMapping = VULKAN_4444_SWIZZLE;
|
||||
return VULKAN_4444_FORMAT;
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
*componentMapping = VULKAN_1555_SWIZZLE;
|
||||
return VULKAN_1555_FORMAT;
|
||||
case GE_CMODE_16BIT_BGR5650:
|
||||
*componentMapping = VULKAN_565_SWIZZLE;
|
||||
return VULKAN_565_FORMAT;
|
||||
case GE_CMODE_32BIT_ABGR8888:
|
||||
*componentMapping = VULKAN_8888_SWIZZLE;
|
||||
return VULKAN_8888_FORMAT;
|
||||
}
|
||||
return VK_FORMAT_UNDEFINED;
|
||||
}
|
||||
|
||||
DepalShaderCacheVulkan::DepalShaderCacheVulkan(Draw::DrawContext *draw)
|
||||
: draw_(draw) {
|
||||
DeviceRestore(draw);
|
||||
}
|
||||
|
||||
DepalShaderCacheVulkan::~DepalShaderCacheVulkan() {
|
||||
DeviceLost();
|
||||
}
|
||||
|
||||
void DepalShaderCacheVulkan::DeviceLost() {
|
||||
Clear();
|
||||
if (vshader_) {
|
||||
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
||||
vulkan2D_->PurgeVertexShader(vshader_);
|
||||
vulkan->Delete().QueueDeleteShaderModule(vshader_);
|
||||
vshader_ = VK_NULL_HANDLE;
|
||||
}
|
||||
draw_ = nullptr;
|
||||
}
|
||||
|
||||
void DepalShaderCacheVulkan::DeviceRestore(Draw::DrawContext *draw) {
|
||||
draw_ = draw;
|
||||
std::string errors;
|
||||
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
||||
vshader_ = CompileShaderModule(vulkan, VK_SHADER_STAGE_VERTEX_BIT, depal_vs, &errors);
|
||||
_assert_(vshader_ != VK_NULL_HANDLE);
|
||||
}
|
||||
|
||||
DepalShaderVulkan *DepalShaderCacheVulkan::GetDepalettizeShader(uint32_t clutMode, GEBufferFormat pixelFormat) {
|
||||
u32 id = GenerateShaderID(clutMode, pixelFormat);
|
||||
|
||||
auto shader = cache_.find(id);
|
||||
if (shader != cache_.end()) {
|
||||
return shader->second;
|
||||
}
|
||||
|
||||
VkRenderPass rp = (VkRenderPass)draw_->GetNativeObject(Draw::NativeObject::FRAMEBUFFER_RENDERPASS);
|
||||
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
||||
|
||||
char *buffer = new char[2048];
|
||||
GenerateDepalShader(buffer, pixelFormat, GLSL_VULKAN);
|
||||
|
||||
std::string error;
|
||||
VkShaderModule fshader = CompileShaderModule(vulkan, VK_SHADER_STAGE_FRAGMENT_BIT, buffer, &error);
|
||||
if (fshader == VK_NULL_HANDLE) {
|
||||
INFO_LOG(G3D, "Source:\n%s\n\n", buffer);
|
||||
Crash();
|
||||
delete[] buffer;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VkPipeline pipeline = vulkan2D_->GetPipeline(rp, vshader_, fshader);
|
||||
// Can delete the shader module now that the pipeline has been created.
|
||||
// Maybe don't even need to queue it..
|
||||
// "true" keeps the pipeline itself alive, forgetting the fshader.
|
||||
vulkan2D_->PurgeFragmentShader(fshader, true);
|
||||
vulkan->Delete().QueueDeleteShaderModule(fshader);
|
||||
|
||||
DepalShaderVulkan *depal = new DepalShaderVulkan();
|
||||
depal->pipeline = pipeline;
|
||||
depal->code = buffer;
|
||||
cache_[id] = depal;
|
||||
return depal;
|
||||
}
|
||||
|
||||
VulkanTexture *DepalShaderCacheVulkan::GetClutTexture(GEPaletteFormat clutFormat, u32 clutHash, u32 *rawClut, bool expandTo32bit) {
|
||||
u32 clutId = GetClutID(clutFormat, clutHash);
|
||||
auto oldtex = texCache_.find(clutId);
|
||||
if (oldtex != texCache_.end()) {
|
||||
oldtex->second->texture->Touch();
|
||||
oldtex->second->lastFrame = gpuStats.numFlips;
|
||||
return oldtex->second->texture;
|
||||
}
|
||||
|
||||
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
||||
VkComponentMapping componentMapping;
|
||||
VkFormat destFormat = GetClutDestFormat(clutFormat, &componentMapping);
|
||||
|
||||
int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512;
|
||||
int bpp = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 4 : 2;
|
||||
VkFormat dstFmt;
|
||||
uint32_t *expanded = nullptr;
|
||||
if (expandTo32bit && clutFormat != GE_CMODE_32BIT_ABGR8888) {
|
||||
expanded = new uint32_t[texturePixels];
|
||||
switch (clutFormat) {
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
ConvertRGBA4444ToRGBA8888(expanded, (const uint16_t *)rawClut, texturePixels);
|
||||
break;
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
ConvertRGBA5551ToRGBA8888(expanded, (const uint16_t *)rawClut, texturePixels);
|
||||
break;
|
||||
case GE_CMODE_16BIT_BGR5650:
|
||||
ConvertRGB565ToRGBA8888(expanded, (const uint16_t *)rawClut, texturePixels);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
rawClut = expanded;
|
||||
dstFmt = VK_FORMAT_R8G8B8A8_UNORM;
|
||||
bpp = 4;
|
||||
componentMapping.r = VkComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
componentMapping.g = VkComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
componentMapping.b = VkComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
componentMapping.a = VkComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
} else {
|
||||
dstFmt = GetClutDestFormat(clutFormat, &componentMapping);
|
||||
}
|
||||
|
||||
VulkanTexture *vktex = new VulkanTexture(vulkan);
|
||||
vktex->SetTag("DepalClut");
|
||||
VkCommandBuffer cmd = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::INIT_COMMANDBUFFER);
|
||||
if (!vktex->CreateDirect(cmd, texturePixels, 1, 1, 1, destFormat,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, &componentMapping)) {
|
||||
ERROR_LOG(G3D, "Failed to create texture for CLUT");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VkBuffer pushBuffer;
|
||||
uint32_t pushOffset = push_->PushAligned(rawClut, 1024, 4, &pushBuffer);
|
||||
|
||||
vktex->UploadMip(cmd, 0, texturePixels, 1, 0, pushBuffer, pushOffset, texturePixels);
|
||||
vktex->EndCreate(cmd, false, VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
|
||||
DepalTextureVulkan *tex = new DepalTextureVulkan();
|
||||
tex->texture = vktex;
|
||||
tex->lastFrame = gpuStats.numFlips;
|
||||
texCache_[clutId] = tex;
|
||||
|
||||
if (expandTo32bit) {
|
||||
delete[] expanded;
|
||||
}
|
||||
|
||||
return tex->texture;
|
||||
}
|
||||
|
||||
void DepalShaderCacheVulkan::Clear() {
|
||||
for (auto shader = cache_.begin(); shader != cache_.end(); ++shader) {
|
||||
// Don't need to destroy the pipelines, they're handled by Vulkan2D.
|
||||
delete shader->second;
|
||||
}
|
||||
cache_.clear();
|
||||
|
||||
for (auto tex = texCache_.begin(); tex != texCache_.end(); ++tex) {
|
||||
delete tex->second->texture;
|
||||
delete tex->second;
|
||||
}
|
||||
texCache_.clear();
|
||||
}
|
||||
|
||||
void DepalShaderCacheVulkan::Decimate() {
|
||||
// We don't bother decimating the generated shaders, there are never very many of them.
|
||||
for (auto tex = texCache_.begin(); tex != texCache_.end(); ) {
|
||||
if (tex->second->lastFrame + DEPAL_TEXTURE_OLD_AGE < gpuStats.numFlips) {
|
||||
delete tex->second->texture;
|
||||
delete tex->second;
|
||||
texCache_.erase(tex++);
|
||||
} else {
|
||||
++tex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
// 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/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/GPU/Vulkan/VulkanContext.h"
|
||||
#include "Common/GPU/thin3d.h"
|
||||
#include "GPU/Common/DepalettizeShaderCommon.h"
|
||||
|
||||
class DepalShaderVulkan {
|
||||
public:
|
||||
~DepalShaderVulkan() {
|
||||
delete[] code;
|
||||
}
|
||||
// A Vulkan2D pipeline. Set texture to slot 0 and palette texture to slot 1.
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
const char *code = nullptr;
|
||||
};
|
||||
|
||||
class DepalTextureVulkan {
|
||||
public:
|
||||
VulkanTexture *texture = nullptr;
|
||||
int lastFrame;
|
||||
};
|
||||
|
||||
class VulkanTexture;
|
||||
class Vulkan2D;
|
||||
class VulkanPushBuffer;
|
||||
|
||||
// Caches both shaders and palette textures.
|
||||
// Could even avoid bothering with palette texture and just use uniform data...
|
||||
class DepalShaderCacheVulkan : public DepalShaderCacheCommon {
|
||||
public:
|
||||
DepalShaderCacheVulkan(Draw::DrawContext *draw);
|
||||
~DepalShaderCacheVulkan();
|
||||
void DeviceLost();
|
||||
void DeviceRestore(Draw::DrawContext *draw);
|
||||
|
||||
// This also uploads the palette and binds the correct texture.
|
||||
DepalShaderVulkan *GetDepalettizeShader(uint32_t clutMode, GEBufferFormat pixelFormat);
|
||||
VulkanTexture *GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut, bool expandTo32bit);
|
||||
void Clear();
|
||||
void Decimate();
|
||||
|
||||
void SetVulkan2D(Vulkan2D *vk2d) { vulkan2D_ = vk2d; }
|
||||
void SetPushBuffer(VulkanPushBuffer *push) { push_ = push; }
|
||||
void SetAllocator(VulkanDeviceAllocator *alloc) { alloc_ = alloc; }
|
||||
void SetVShader(VkShaderModule vshader) { vshader_ = vshader; }
|
||||
|
||||
private:
|
||||
Draw::DrawContext *draw_ = nullptr;
|
||||
VulkanPushBuffer *push_ = nullptr;
|
||||
VulkanDeviceAllocator *alloc_ = nullptr;
|
||||
VkShaderModule vshader_ = VK_NULL_HANDLE;
|
||||
Vulkan2D *vulkan2D_ = nullptr;
|
||||
|
||||
std::map<u32, DepalShaderVulkan *> cache_;
|
||||
std::map<u32, DepalTextureVulkan *> texCache_;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "GPU/Common/GPUDebugInterface.h"
|
||||
#include "GPU/Common/PresentationCommon.h"
|
||||
#include "GPU/Vulkan/VulkanUtil.h"
|
||||
#include "GPU/Vulkan/DepalettizeShaderVulkan.h"
|
||||
|
||||
class TextureCacheVulkan;
|
||||
class DrawEngineVulkan;
|
||||
@@ -50,8 +49,4 @@ public:
|
||||
// If within a render pass, this will just issue a regular clear. If beginning a new render pass,
|
||||
// do that.
|
||||
void NotifyClear(bool clearColor, bool clearAlpha, bool clearDepth, uint32_t color, float depth);
|
||||
|
||||
private:
|
||||
// Simple 2D drawing engine.
|
||||
Vulkan2D *vulkan2D_;
|
||||
};
|
||||
@@ -379,6 +379,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\GPU\Common\DepalettizeCommon.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\DepalettizeShaderCommon.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\Draw2D.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\DrawEngineCommon.h" />
|
||||
@@ -438,6 +439,7 @@
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\GPU\Common\DepalettizeCommon.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\DepalettizeShaderCommon.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\Draw2D.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\DrawEngineCommon.cpp" />
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
<ClCompile Include="..\..\GPU\Common\VertexShaderGenerator.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\ReinterpretFramebuffer.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\Draw2D.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\DepalettizeCommon.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\GPU\Common\DepalettizeShaderCommon.h" />
|
||||
@@ -116,5 +117,6 @@
|
||||
<ClInclude Include="..\..\GPU\Common\VertexShaderGenerator.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\ReinterpretFramebuffer.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\Draw2D.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\DepalettizeCommon.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -134,7 +134,6 @@ VULKAN_FILES := \
|
||||
$(SRC)/GPU/Vulkan/ShaderManagerVulkan.cpp \
|
||||
$(SRC)/GPU/Vulkan/StateMappingVulkan.cpp \
|
||||
$(SRC)/GPU/Vulkan/TextureCacheVulkan.cpp \
|
||||
$(SRC)/GPU/Vulkan/DepalettizeShaderVulkan.cpp \
|
||||
$(SRC)/GPU/Vulkan/VulkanUtil.cpp \
|
||||
$(SRC)/GPU/Vulkan/DebugVisVulkan.cpp
|
||||
#endif
|
||||
|
||||
@@ -727,7 +727,6 @@ SOURCES_C += \
|
||||
$(EXTDIR)/miniupnp/miniupnpc/upnpreplyparse.c
|
||||
|
||||
SOURCES_CXX += \
|
||||
$(GPUDIR)/Vulkan/DepalettizeShaderVulkan.cpp \
|
||||
$(GPUDIR)/Vulkan/DrawEngineVulkan.cpp \
|
||||
$(GPUDIR)/Vulkan/FramebufferManagerVulkan.cpp \
|
||||
$(GPUDIR)/Vulkan/GPU_Vulkan.cpp \
|
||||
|
||||
Reference in new issue
Block a user