Separate uniform updates from shader updates

This commit is contained in:
Henrik Rydgard 2016-01-09 12:17:02 +01:00
parent d67d187b72
commit 6141c3651b
3 changed files with 25 additions and 24 deletions

View file

@ -514,6 +514,7 @@ void DrawEngineVulkan::DoFlush(VkCommandBuffer cmd) {
vkCmdSetStencilWriteMask(cmd_, VK_STENCIL_FRONT_AND_BACK, dynState.stencilWriteMask);
vkCmdSetStencilCompareMask(cmd_, VK_STENCIL_FRONT_AND_BACK, dynState.stencilCompareMask);
// vkCmdSetBlendConstants(cmd_, dynState.blendColor);
shaderManager_->UpdateUniforms();
shaderManager_->GetShaders(prim, lastVType_, &vshader, &fshader, useHWTransform);
VulkanPipeline *pipeline = pipelineManager_->GetOrCreatePipeline(pipelineLayout_, pipelineKey, dec_, vshader->GetModule(), fshader->GetModule(), true);
vkCmdBindPipeline(cmd_, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline); // TODO: Avoid if same as last draw.
@ -596,6 +597,7 @@ void DrawEngineVulkan::DoFlush(VkCommandBuffer cmd) {
}
// vkCmdSetBlendConstants(cmd_, dynState.blendColor);
shaderManager_->UpdateUniforms();
shaderManager_->GetShaders(prim, lastVType_, &vshader, &fshader, useHWTransform);
VulkanPipeline *pipeline = pipelineManager_->GetOrCreatePipeline(pipelineLayout_, pipelineKey, dec_, vshader->GetModule(), fshader->GetModule(), false);
vkCmdBindPipeline(cmd_, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline); // TODO: Avoid if same as last draw.

View file

@ -474,6 +474,14 @@ void ShaderManagerVulkan::DirtyLastShader() { // disables vertex arrays
lastFShader_ = nullptr;
}
void ShaderManagerVulkan::UpdateUniforms() {
if (globalDirty_) {
BaseUpdateUniforms(globalDirty_);
LightUpdateUniforms(globalDirty_);
BoneUpdateUniforms(globalDirty_);
globalDirty_ = 0;
}
}
void ShaderManagerVulkan::GetShaders(int prim, u32 vertType, VulkanVertexShader **vshader, VulkanFragmentShader **fshader, bool useHWTransform) {
ShaderID VSID;
@ -483,12 +491,6 @@ void ShaderManagerVulkan::GetShaders(int prim, u32 vertType, VulkanVertexShader
// Just update uniforms if this is the same shader as last time.
if (lastVShader_ != nullptr && lastFShader_ != nullptr && VSID == lastVSID_ && FSID == lastFSID_) {
if (globalDirty_) {
BaseUpdateUniforms(globalDirty_);
LightUpdateUniforms(globalDirty_);
BoneUpdateUniforms(globalDirty_);
globalDirty_ = 0;
}
*vshader = lastVShader_;
*fshader = lastFShader_;
// Already all set, no need to look up in shader maps.
@ -520,12 +522,6 @@ void ShaderManagerVulkan::GetShaders(int prim, u32 vertType, VulkanVertexShader
lastFSID_ = FSID;
if (globalDirty_) {
BaseUpdateUniforms(globalDirty_);
LightUpdateUniforms(globalDirty_);
BoneUpdateUniforms(globalDirty_);
globalDirty_ = 0;
}
*vshader = vs;
*fshader = fs;
}

View file

@ -216,9 +216,6 @@ public:
void GetShaders(int prim, u32 vertType, VulkanVertexShader **vshader, VulkanFragmentShader **fshader, bool useHWTransform);
void DirtyShader();
void DirtyUniform(u32 what) {
globalDirty_ |= what;
}
void DirtyLastShader();
int GetNumVertexShaders() const { return (int)vsCache_.size(); }
@ -227,6 +224,12 @@ public:
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type);
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType);
void UpdateUniforms();
void DirtyUniform(u32 what) {
globalDirty_ |= what;
}
// TODO: Avoid copying these buffers if same as last draw, can still point to it assuming we're still in the same pushbuffer.
// Applies dirty changes and copies the buffer.
bool IsBaseDirty() { return true; }
@ -246,21 +249,21 @@ private:
VulkanContext *vulkan_;
uint32_t globalDirty_;
uint32_t uboAlignment_;
char *codeBuffer_;
// Uniform block scratchpad. These (the relevant ones) are copied to the current pushbuffer at draw time.
UB_VS_FS_Base ub_base;
UB_VS_Lights ub_lights;
UB_VS_Bones ub_bones;
typedef std::map<ShaderID, VulkanFragmentShader *> FSCache;
FSCache fsCache_;
typedef std::map<ShaderID, VulkanVertexShader *> VSCache;
VSCache vsCache_;
char *codeBuffer_;
uint32_t globalDirty_;
uint32_t uboAlignment_;
// Uniform block scratchpad. These (the relevant ones) are copied to the current pushbuffer at draw time.
UB_VS_FS_Base ub_base;
UB_VS_Lights ub_lights;
UB_VS_Bones ub_bones;
VulkanFragmentShader *lastFShader_;
VulkanVertexShader *lastVShader_;