Permalink
Browse files

Vulkan pipeline: Merge a few property fields to a flags field.

To make saving/loading them easier.
  • Loading branch information...
hrydgard committed Mar 16, 2018
1 parent 4546489 commit 8dc85c1a606b3e63879a1c1825bb2d1203d5d1f9
Showing with 21 additions and 15 deletions.
  1. +4 −4 GPU/Vulkan/DrawEngineVulkan.cpp
  2. +7 −5 GPU/Vulkan/PipelineManagerVulkan.cpp
  3. +10 −6 GPU/Vulkan/PipelineManagerVulkan.h
@@ -783,12 +783,12 @@ void DrawEngineVulkan::DoFlush() {
BindShaderBlendTex(); // This might cause copies so important to do before BindPipeline.
renderManager->BindPipeline(pipeline->pipeline);
if (pipeline != lastPipeline_) {
if (lastPipeline_ && !lastPipeline_->useBlendConstant && pipeline->useBlendConstant) {
if (lastPipeline_ && !(lastPipeline_->UsesBlendConstant() && pipeline->UsesBlendConstant())) {
gstate_c.Dirty(DIRTY_BLEND_STATE);
}
lastPipeline_ = pipeline;
}
ApplyDrawStateLate(renderManager, false, 0, pipeline->useBlendConstant);
ApplyDrawStateLate(renderManager, false, 0, pipeline->UsesBlendConstant());
gstate_c.Clean(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
lastPipeline_ = pipeline;
@@ -887,12 +887,12 @@ void DrawEngineVulkan::DoFlush() {
BindShaderBlendTex(); // This might cause copies so super important to do before BindPipeline.
renderManager->BindPipeline(pipeline->pipeline);
if (pipeline != lastPipeline_) {
if (lastPipeline_ && !lastPipeline_->useBlendConstant && pipeline->useBlendConstant) {
if (lastPipeline_ && !lastPipeline_->UsesBlendConstant() && pipeline->UsesBlendConstant()) {
gstate_c.Dirty(DIRTY_BLEND_STATE);
}
lastPipeline_ = pipeline;
}
ApplyDrawStateLate(renderManager, result.setStencil, result.stencilValue, pipeline->useBlendConstant);
ApplyDrawStateLate(renderManager, result.setStencil, result.stencilValue, pipeline->UsesBlendConstant());
gstate_c.Clean(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
lastPipeline_ = pipeline;
@@ -285,12 +285,14 @@ static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pip
VulkanPipeline *vulkanPipeline = new VulkanPipeline();
vulkanPipeline->pipeline = pipeline;
vulkanPipeline->uniformBlocks = UB_VS_FS_BASE;
vulkanPipeline->useBlendConstant = useBlendConstant;
vulkanPipeline->usesLines = key.topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST || key.topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
vulkanPipeline->flags = PIPELINE_FLAG_USES_BASE_UB;
if (useBlendConstant)
vulkanPipeline->flags |= PIPELINE_FLAG_USES_BLEND_CONSTANT;
if (key.topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST || key.topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP)
vulkanPipeline->flags |= PIPELINE_FLAG_USES_LINES;
if (useHwTransform) {
if (vs->HasLights()) {
vulkanPipeline->uniformBlocks |= UB_VS_LIGHTS;
vulkanPipeline->flags |= PIPELINE_FLAG_USES_LIGHT_UB;
}
}
return vulkanPipeline;
@@ -489,7 +491,7 @@ void PipelineManagerVulkan::SetLineWidth(float lineWidth) {
// Wipe all line-drawing pipelines.
pipelines_.Iterate([&](const VulkanPipelineKey &key, VulkanPipeline *value) {
if (value->usesLines) {
if (value->UsesLines()) {
vulkan_->Delete().QueueDeletePipeline(value->pipeline);
delete value;
pipelines_.Remove(key);
@@ -54,17 +54,21 @@ struct VulkanPipelineKey {
}
};
enum {
UB_VS_FS_BASE = (1 << 0),
UB_VS_LIGHTS = (1 << 1),
enum PipelineFlags {
PIPELINE_FLAG_USES_BASE_UB = (1 << 0),
PIPELINE_FLAG_USES_LIGHT_UB = (1 << 1),
PIPELINE_FLAG_USES_LINES = (1 << 2),
PIPELINE_FLAG_USES_BLEND_CONSTANT = (1 << 3),
};
// Simply wraps a Vulkan pipeline, providing some metadata.
struct VulkanPipeline {
VkPipeline pipeline;
int uniformBlocks; // UB_ enum above.
bool useBlendConstant;
bool usesLines;
int flags; // PipelineFlags enum above.
// Convenience.
bool UsesBlendConstant() const { return (flags & PIPELINE_FLAG_USES_BLEND_CONSTANT) != 0; }
bool UsesLines() const { return (flags & PIPELINE_FLAG_USES_LINES) != 0; }
};
class VulkanContext;

0 comments on commit 8dc85c1

Please sign in to comment.