mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-29 17:23:40 +01:00
Use promises to hold shader modules, for later asyncification
This commit is contained in:
1 parent
cd0fff2df8
commit
ec0586ba50
5 files changed
+41
-22
No files matched your search
@@ -449,6 +449,10 @@ void VulkanRenderManager::CompileThreadFunc() {
|
||||
if (!run_) {
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: Here we can sort the pending pipelines by vertex and fragment shaders,
|
||||
// and split up further.
|
||||
// Those with the same pairs of shaders should be on the same thread.
|
||||
for (auto &entry : toCompile) {
|
||||
switch (entry.type) {
|
||||
case CompileQueueEntry::Type::GRAPHICS:
|
||||
|
||||
+10
-1
@@ -33,6 +33,7 @@ public:
|
||||
// Has ownership over the data. Single use.
|
||||
// TODO: Split Mailbox (rx_ and tx_) up into separate proxy objects.
|
||||
// NOTE: Poll/BlockUntilReady should only be used from one thread.
|
||||
// TODO: Make movable?
|
||||
template<class T>
|
||||
class Promise {
|
||||
public:
|
||||
@@ -47,6 +48,13 @@ public:
|
||||
return promise;
|
||||
}
|
||||
|
||||
static Promise<T> *AlreadyDone(T data) {
|
||||
Promise<T> *promise = new Promise<T>();
|
||||
promise->data_ = data;
|
||||
promise->ready_ = true;
|
||||
return promise;
|
||||
}
|
||||
|
||||
~Promise() {
|
||||
// A promise should have been fulfilled before it's destroyed.
|
||||
_assert_(ready_);
|
||||
@@ -85,7 +93,8 @@ public:
|
||||
private:
|
||||
Promise() {}
|
||||
|
||||
// Promise can only be constructed in Spawn.
|
||||
T data_ = nullptr;
|
||||
bool ready_ = false;
|
||||
Mailbox<T> *rx_;
|
||||
Mailbox<T> *rx_ = nullptr;
|
||||
};
|
||||
@@ -260,13 +260,13 @@ static VulkanPipeline *CreateVulkanPipeline(VulkanRenderManager *renderManager,
|
||||
ss[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
ss[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
ss[0].pSpecializationInfo = nullptr;
|
||||
ss[0].module = vs->GetModule();
|
||||
ss[0].module = vs->GetModule()->BlockUntilReady();
|
||||
ss[0].pName = "main";
|
||||
ss[0].flags = 0;
|
||||
ss[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
ss[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
ss[1].pSpecializationInfo = nullptr;
|
||||
ss[1].module = fs->GetModule();
|
||||
ss[1].module = fs->GetModule()->BlockUntilReady();
|
||||
ss[1].pName = "main";
|
||||
ss[1].flags = 0;
|
||||
|
||||
@@ -369,8 +369,8 @@ VulkanPipeline *PipelineManagerVulkan::GetOrCreatePipeline(VulkanRenderManager *
|
||||
key.raster = rasterKey;
|
||||
key.renderPass = renderPass;
|
||||
key.useHWTransform = useHwTransform;
|
||||
key.vShader = vs->GetModule();
|
||||
key.fShader = fs->GetModule();
|
||||
key.vShader = vs->GetModule()->BlockUntilReady();
|
||||
key.fShader = fs->GetModule()->BlockUntilReady();
|
||||
key.vtxFmtId = useHwTransform ? decFmt->id : 0;
|
||||
|
||||
auto iter = pipelines_.Get(key);
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "GPU/Vulkan/DrawEngineVulkan.h"
|
||||
#include "GPU/Vulkan/FramebufferManagerVulkan.h"
|
||||
|
||||
VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code) {
|
||||
Promise<VkShaderModule> *CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code) {
|
||||
PROFILE_THIS_SCOPE("shadercomp");
|
||||
|
||||
std::string errorMessage;
|
||||
@@ -67,11 +67,10 @@ VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits
|
||||
#endif
|
||||
Reporting::ReportMessage("Vulkan error in shader compilation: info: %s / code: %s", errorMessage.c_str(), code);
|
||||
} else {
|
||||
VkShaderModule shaderModule;
|
||||
success = vulkan->CreateShaderModule(spirv, &shaderModule);
|
||||
#ifdef SHADERLOG
|
||||
OutputDebugStringA(LineNumberString(code).c_str());
|
||||
#endif
|
||||
#ifdef SHADERLOG
|
||||
OutputDebugStringA("OK\n");
|
||||
OutputDebugStringA("OK");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -79,7 +78,7 @@ VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits
|
||||
vulkan->CreateShaderModule(spirv, &shaderModule);
|
||||
}
|
||||
|
||||
return shaderModule;
|
||||
return Promise<VkShaderModule>::AlreadyDone(shaderModule);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,8 +95,9 @@ VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id,
|
||||
}
|
||||
|
||||
VulkanFragmentShader::~VulkanFragmentShader() {
|
||||
if (module_ != VK_NULL_HANDLE) {
|
||||
vulkan_->Delete().QueueDeleteShaderModule(module_);
|
||||
if (module_) {
|
||||
VkShaderModule shaderModule = module_->BlockUntilReady();
|
||||
vulkan_->Delete().QueueDeleteShaderModule(shaderModule);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,13 +120,14 @@ VulkanVertexShader::VulkanVertexShader(VulkanContext *vulkan, VShaderID id, cons
|
||||
failed_ = true;
|
||||
return;
|
||||
} else {
|
||||
VERBOSE_LOG(G3D, "Compiled vertex shader:\n%s\n", (const char *)code);
|
||||
VERBOSE_LOG(G3D, "Compiled fragment shader:\n%s\n", (const char *)code);
|
||||
}
|
||||
}
|
||||
|
||||
VulkanVertexShader::~VulkanVertexShader() {
|
||||
if (module_ != VK_NULL_HANDLE) {
|
||||
vulkan_->Delete().QueueDeleteShaderModule(module_);
|
||||
if (module_) {
|
||||
VkShaderModule shaderModule = module_->BlockUntilReady();
|
||||
vulkan_->Delete().QueueDeleteShaderModule(shaderModule);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +335,9 @@ std::string ShaderManagerVulkan::DebugGetShaderString(std::string id, DebugShade
|
||||
VulkanVertexShader *ShaderManagerVulkan::GetVertexShaderFromModule(VkShaderModule module) {
|
||||
VulkanVertexShader *vs = nullptr;
|
||||
vsCache_.Iterate([&](const VShaderID &id, VulkanVertexShader *shader) {
|
||||
if (shader->GetModule() == module)
|
||||
Promise<VkShaderModule> *p = shader->GetModule();
|
||||
VkShaderModule m = p->BlockUntilReady();
|
||||
if (m == module)
|
||||
vs = shader;
|
||||
});
|
||||
return vs;
|
||||
@@ -343,7 +346,9 @@ VulkanVertexShader *ShaderManagerVulkan::GetVertexShaderFromModule(VkShaderModul
|
||||
VulkanFragmentShader *ShaderManagerVulkan::GetFragmentShaderFromModule(VkShaderModule module) {
|
||||
VulkanFragmentShader *fs = nullptr;
|
||||
fsCache_.Iterate([&](const FShaderID &id, VulkanFragmentShader *shader) {
|
||||
if (shader->GetModule() == module)
|
||||
Promise<VkShaderModule> *p = shader->GetModule();
|
||||
VkShaderModule m = p->BlockUntilReady();
|
||||
if (m == module)
|
||||
fs = shader;
|
||||
});
|
||||
return fs;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
#include "Common/Thread/Promise.h"
|
||||
#include "Common/Data/Collections/Hashmaps.h"
|
||||
#include "Common/GPU/Vulkan/VulkanMemory.h"
|
||||
#include "GPU/Common/ShaderCommon.h"
|
||||
@@ -43,11 +44,11 @@ public:
|
||||
bool Failed() const { return failed_; }
|
||||
|
||||
std::string GetShaderString(DebugShaderStringType type) const;
|
||||
VkShaderModule GetModule() const { return module_; }
|
||||
Promise<VkShaderModule> *GetModule() { return module_; }
|
||||
const FShaderID &GetID() { return id_; }
|
||||
|
||||
protected:
|
||||
VkShaderModule module_ = VK_NULL_HANDLE;
|
||||
Promise<VkShaderModule> *module_;
|
||||
|
||||
VulkanContext *vulkan_;
|
||||
std::string source_;
|
||||
@@ -66,11 +67,11 @@ public:
|
||||
bool UseHWTransform() const { return useHWTransform_; }
|
||||
|
||||
std::string GetShaderString(DebugShaderStringType type) const;
|
||||
VkShaderModule GetModule() const { return module_; }
|
||||
Promise<VkShaderModule> *GetModule() { return module_; }
|
||||
const VShaderID &GetID() { return id_; }
|
||||
|
||||
protected:
|
||||
VkShaderModule module_ = VK_NULL_HANDLE;
|
||||
Promise<VkShaderModule> *module_ = nullptr;
|
||||
|
||||
VulkanContext *vulkan_;
|
||||
std::string source_;
|
||||
|
||||
Reference in new issue
Block a user