Commit 73832434 by Alexis Hetu Committed by Alexis Hétu

Dynamic state implementation

Implemented all dynamic state commands and applied the proper state within the draw command. Bug b/118619338 Change-Id: Ifeca42be1698f642e137e807aa59958447921fcc Tests: dEQP-VK.dynamic_state.* Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28890Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Presubmit-Ready: Alexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 17ecf2a6
......@@ -133,6 +133,7 @@ namespace sw
rasterizerDiscard = false;
depthCompareMode = VK_COMPARE_OP_LESS;
depthBoundsTestEnable = false;
depthBufferEnable = false;
depthWriteEnable = false;
......
......@@ -179,6 +179,7 @@ namespace sw
// Pixel processor states
bool rasterizerDiscard;
bool depthBoundsTestEnable;
bool depthBufferEnable;
VkCompareOp depthCompareMode;
bool depthWriteEnable;
......
......@@ -135,6 +135,24 @@ public:
RenderPass* renderPass = nullptr;
Framebuffer* renderPassFramebuffer = nullptr;
std::array<PipelineState, VK_PIPELINE_BIND_POINT_RANGE_SIZE> pipelineState;
struct DynamicState
{
VkViewport viewport;
VkRect2D scissor;
sw::Color<float> blendConstants;
float depthBiasConstantFactor = 0.0f;
float depthBiasClamp = 0.0f;
float depthBiasSlopeFactor = 0.0f;
float minDepthBounds = 0.0f;
float maxDepthBounds = 0.0f;
uint32_t compareMask[2] = { 0 };
uint32_t writeMask[2] = { 0 };
uint32_t reference[2] = { 0 };
};
DynamicState dynamicState;
sw::PushConstantStorage pushConstants;
struct VertexInputBinding
......
......@@ -231,12 +231,36 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
{
if(((pCreateInfo->flags & ~(VK_PIPELINE_CREATE_DERIVATIVE_BIT | VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT)) != 0) ||
(pCreateInfo->stageCount != 2) ||
(pCreateInfo->pTessellationState != nullptr) ||
(pCreateInfo->pDynamicState != nullptr))
(pCreateInfo->pTessellationState != nullptr))
{
UNIMPLEMENTED("pCreateInfo settings");
}
if(pCreateInfo->pDynamicState)
{
for(uint32_t i = 0; i < pCreateInfo->pDynamicState->dynamicStateCount; i++)
{
VkDynamicState dynamicState = pCreateInfo->pDynamicState->pDynamicStates[i];
switch(dynamicState)
{
case VK_DYNAMIC_STATE_VIEWPORT:
case VK_DYNAMIC_STATE_SCISSOR:
case VK_DYNAMIC_STATE_LINE_WIDTH:
case VK_DYNAMIC_STATE_DEPTH_BIAS:
case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
ASSERT(dynamicState < (sizeof(dynamicStateFlags) * 8));
dynamicStateFlags |= (1 << dynamicState);
break;
default:
UNIMPLEMENTED("dynamic state");
}
}
}
const VkPipelineVertexInputStateCreateInfo* vertexInputState = pCreateInfo->pVertexInputState;
if(vertexInputState->flags != 0)
{
......@@ -346,6 +370,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
UNIMPLEMENTED("depthStencilState");
}
context.depthBoundsTestEnable = depthStencilState->depthBoundsTestEnable;
context.depthBufferEnable = depthStencilState->depthTestEnable;
context.depthWriteEnable = depthStencilState->depthWriteEnable;
context.depthCompareMode = depthStencilState->depthCompareOp;
......@@ -480,6 +505,11 @@ const sw::Color<float>& GraphicsPipeline::getBlendConstants() const
return blendConstants;
}
bool GraphicsPipeline::hasDynamicState(VkDynamicState dynamicState) const
{
return (dynamicStateFlags & (1 << dynamicState)) != 0;
}
ComputePipeline::ComputePipeline(const VkComputePipelineCreateInfo* pCreateInfo, void* mem)
: Pipeline(Cast(pCreateInfo->layout))
{
......
......@@ -75,11 +75,13 @@ public:
const VkRect2D& getScissor() const;
const VkViewport& getViewport() const;
const sw::Color<float>& getBlendConstants() const;
bool hasDynamicState(VkDynamicState dynamicState) const;
private:
sw::SpirvShader *vertexShader = nullptr;
sw::SpirvShader *fragmentShader = nullptr;
uint32_t dynamicStateFlags = 0;
sw::Context context;
VkRect2D scissor;
VkViewport viewport;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment