1 #pragma once 2 3 #include "Common/GPU/Vulkan/VulkanLoader.h" 4 5 #include <cstring> 6 7 class FramebufferManagerVulkan; 8 9 struct VulkanDynamicState { 10 VkViewport viewport; 11 VkRect2D scissor; 12 bool useBlendColor; 13 uint32_t blendColor; 14 bool useStencil; 15 uint8_t stencilRef; 16 uint8_t stencilWriteMask; 17 uint8_t stencilCompareMask; 18 }; 19 20 // Let's pack this tight using bitfields. 21 // If an enable flag is set to 0, all the data fields for that section should 22 // also be set to 0. 23 // ~64 bits. 24 // Can't use enums unfortunately, they end up signed and breaking values above half their ranges. 25 struct VulkanPipelineRasterStateKey { 26 // Blend 27 unsigned int blendEnable : 1; 28 unsigned int srcColor : 5; // VkBlendFactor 29 unsigned int destColor : 5; // VkBlendFactor 30 unsigned int srcAlpha : 5; // VkBlendFactor 31 unsigned int destAlpha : 5; // VkBlendFactor 32 // bool useBlendConstant : 1; // sacrifice a bit to cheaply check if we need to update the blend color 33 unsigned int blendOpColor : 3; // VkBlendOp 34 unsigned int blendOpAlpha : 3; // VkBlendOp 35 unsigned int logicOpEnable : 1; 36 unsigned int logicOp : 4; // VkLogicOp 37 unsigned int colorWriteMask : 4; 38 39 // Depth/Stencil 40 unsigned int depthClampEnable : 1; 41 unsigned int depthTestEnable : 1; 42 unsigned int depthWriteEnable : 1; 43 unsigned int depthCompareOp : 3; // VkCompareOp 44 unsigned int stencilTestEnable : 1; 45 unsigned int stencilCompareOp : 3; // VkCompareOp 46 unsigned int stencilPassOp : 4; // VkStencilOp 47 unsigned int stencilFailOp : 4; // VkStencilOp 48 unsigned int stencilDepthFailOp : 4; // VkStencilOp 49 50 // We'll use dynamic state for writemask, reference and comparemask to start with, 51 // and viewport/scissor. 52 53 // Rasterizer 54 unsigned int cullMode : 2; // VkCullModeFlagBits 55 unsigned int topology : 4; // VkPrimitiveTopology 56 57 bool operator < (const VulkanPipelineRasterStateKey &other) const { 58 size_t size = sizeof(VulkanPipelineRasterStateKey); 59 return memcmp(this, &other, size) < 0; 60 } 61 }; 62