Vulkan: Store saw equal depth flag in cache.

This commit is contained in:
Unknown W. Brackets committed 2023-01-05 18:24:29 -08:00
1 parent c3530e63ed
commit 3f20562b9f
4 files changed
+48 -7

No files matched your search

+3
View File
@@ -110,6 +110,9 @@ public:
bool EverUsedExactEqualDepth() const {
return everUsedExactEqualDepth_;
}
void SetEverUsedExactEqualDepth(bool v) {
everUsedExactEqualDepth_ = v;
}
bool IsCodePtrVertexDecoder(const u8 *ptr) const {
return decJitCache_->IsInSpace(ptr);
+11 -3
View File
@@ -129,9 +129,17 @@ void GPU_Vulkan::LoadCache(const Path &filename) {
// First compile shaders to SPIR-V, then load the pipeline cache and recreate the pipelines.
// It's when recreating the pipelines that the pipeline cache is useful - in the ideal case,
// it can just memcpy the finished shader binaries out of the pipeline cache file.
bool result = shaderManagerVulkan_->LoadCache(f);
bool result = shaderManagerVulkan_->LoadCacheFlags(f, &drawEngine_);
if (!result) {
WARN_LOG(G3D, "ShaderManagerVulkan failed to load cache.");
WARN_LOG(G3D, "ShaderManagerVulkan failed to load cache header.");
}
if (result) {
// Reload use flags in case LoadCacheFlags() changed them.
gstate_c.SetUseFlags(CheckGPUFeatures());
result = shaderManagerVulkan_->LoadCache(f);
if (!result) {
WARN_LOG(G3D, "ShaderManagerVulkan failed to load cache.");
}
}
if (result) {
// WARNING: See comment in LoadPipelineCache if you are tempted to flip the second parameter to true.
@@ -163,7 +171,7 @@ void GPU_Vulkan::SaveCache(const Path &filename) {
FILE *f = File::OpenCFile(filename, "wb");
if (!f)
return;
shaderManagerVulkan_->SaveCache(f);
shaderManagerVulkan_->SaveCache(f, &drawEngine_);
// WARNING: See comment in LoadCache if you are tempted to flip the second parameter to true.
pipelineManager_->SavePipelineCache(f, false, shaderManagerVulkan_, draw_);
INFO_LOG(G3D, "Saved Vulkan pipeline cache");
+31 -3
View File
@@ -496,18 +496,44 @@ VulkanGeometryShader *ShaderManagerVulkan::GetGeometryShaderFromModule(VkShaderM
// pipelines compiled from SPIR-V matching these shaders, pipeline creation will be practically
// instantaneous.
enum class VulkanCacheDetectFlags {
EQUAL_DEPTH = 1,
};
#define CACHE_HEADER_MAGIC 0xff51f420
#define CACHE_VERSION 35
struct VulkanCacheHeader {
uint32_t magic;
uint32_t version;
uint32_t useFlags;
uint32_t reserved;
uint32_t detectFlags;
int numVertexShaders;
int numFragmentShaders;
int numGeometryShaders;
};
bool ShaderManagerVulkan::LoadCacheFlags(FILE *f, DrawEngineVulkan *drawEngine) {
VulkanCacheHeader header{};
long pos = ftell(f);
bool success = fread(&header, sizeof(header), 1, f) == 1;
// We'll read it again later, this is just to check the flags.
success = success && fseek(f, pos, SEEK_SET) == 0;
if (!success || header.magic != CACHE_HEADER_MAGIC) {
WARN_LOG(G3D, "Shader cache magic mismatch");
return false;
}
if (header.version != CACHE_VERSION) {
WARN_LOG(G3D, "Shader cache version mismatch, %d, expected %d", header.version, CACHE_VERSION);
return false;
}
if ((header.detectFlags & (uint32_t)VulkanCacheDetectFlags::EQUAL_DEPTH) != 0) {
drawEngine->SetEverUsedExactEqualDepth(true);
}
return true;
}
bool ShaderManagerVulkan::LoadCache(FILE *f) {
VulkanCacheHeader header{};
bool success = fread(&header, sizeof(header), 1, f) == 1;
@@ -594,12 +620,14 @@ bool ShaderManagerVulkan::LoadCache(FILE *f) {
return true;
}
void ShaderManagerVulkan::SaveCache(FILE *f) {
void ShaderManagerVulkan::SaveCache(FILE *f, DrawEngineVulkan *drawEngine) {
VulkanCacheHeader header{};
header.magic = CACHE_HEADER_MAGIC;
header.version = CACHE_VERSION;
header.useFlags = gstate_c.GetUseFlags();
header.reserved = 0;
header.detectFlags = 0;
if (drawEngine->EverUsedExactEqualDepth())
header.detectFlags |= (uint32_t)VulkanCacheDetectFlags::EQUAL_DEPTH;
header.numVertexShaders = (int)vsCache_.size();
header.numFragmentShaders = (int)fsCache_.size();
header.numGeometryShaders = (int)gsCache_.size();
+3 -1
View File
@@ -32,6 +32,7 @@
#include "GPU/Common/ShaderUniforms.h"
class VulkanContext;
class DrawEngineVulkan;
class VulkanPushBuffer;
class VulkanFragmentShader {
@@ -154,8 +155,9 @@ public:
return dest->PushAligned(&ub_bones, sizeof(ub_bones), uboAlignment_, buf);
}
bool LoadCacheFlags(FILE *f, DrawEngineVulkan *drawEngine);
bool LoadCache(FILE *f);
void SaveCache(FILE *f);
void SaveCache(FILE *f, DrawEngineVulkan *drawEngine);
private:
void Clear();