Commit 940f2acc by Nicolas Capens Committed by Nicolas Capens

Value-initialize all vk::GraphicsState members

The vk::GraphicsState constructor does not initialize all members in all code paths. We were relying on the zero-initializing done by vk::allocate() which is used to allocate vk::GraphicsPipeline which in turn contains a GraphicsState member. We want to change vk::allocate() to no longer zero-initialize all memory, to catch more MemorySanitizer errors made by applications. Thus we must also not rely on such automatic initialization ourselves. Note that this change might also hide MemorySantizer violations committed by the application side. For example some state is only copied from VkGraphicsPipelineCreateInfo into vk::GraphicsState on construction when flags indicate they're not dynamic state. If the application forgets to makerecord commands that set the dynamic state, their value is undefined: Vulkan 1.2.178 section 6. Command Buffers: "When a command buffer begins recording, all state in that command buffer is undefined." Vulkan 1.2.178 section 10.11. Dynamic State: "If the state is specified as dynamic in the new pipeline object, then that command buffer state is not disturbed. Before any draw or dispatch call with this pipeline there must have been at least one call to each of the corresponding dynamic state setting commands since the command buffer recording was begun, or the last bound pipeline object with that state specified as static, whichever was the latter." Thus once sw::allocate() no longer also zeroes this data, we should revert the value-initialization where possible and ensure we don't touch the uninitialized data ourselves, unless as a consequence of an application bug. Bug: b/140991626 Change-Id: I060e8d8a79e93b0676669eed361fab4f86ab1b56 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/53089 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 491ade49
...@@ -204,55 +204,55 @@ private: ...@@ -204,55 +204,55 @@ private:
bool alphaBlendActive(int index, const Attachments &attachments, bool fragmentContainsKill) const; bool alphaBlendActive(int index, const Attachments &attachments, bool fragmentContainsKill) const;
bool colorWriteActive(const Attachments &attachments) const; bool colorWriteActive(const Attachments &attachments) const;
const PipelineLayout *pipelineLayout; const PipelineLayout *pipelineLayout = nullptr;
const bool robustBufferAccess = true; const bool robustBufferAccess = false;
uint32_t dynamicStateFlags = 0; uint32_t dynamicStateFlags = 0;
VkPrimitiveTopology topology; VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
VkProvokingVertexModeEXT provokingVertexMode; VkProvokingVertexModeEXT provokingVertexMode = VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT;
bool stencilEnable; bool stencilEnable = false;
VkStencilOpState frontStencil; VkStencilOpState frontStencil = {};
VkStencilOpState backStencil; VkStencilOpState backStencil = {};
// Pixel processor states // Pixel processor states
VkCullModeFlags cullMode; VkCullModeFlags cullMode = 0;
VkFrontFace frontFace; VkFrontFace frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
VkPolygonMode polygonMode; VkPolygonMode polygonMode = VK_POLYGON_MODE_FILL;
VkLineRasterizationModeEXT lineRasterizationMode; VkLineRasterizationModeEXT lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
float constantDepthBias; float constantDepthBias = 0.0f;
float slopeDepthBias; float slopeDepthBias = 0.0f;
float depthBiasClamp; float depthBiasClamp = 0.0f;
float minDepthBounds; float minDepthBounds = 0.0f;
float maxDepthBounds; float maxDepthBounds = 0.0f;
bool depthRangeUnrestricted; bool depthRangeUnrestricted = false;
// Pixel processor states // Pixel processor states
bool rasterizerDiscard; bool rasterizerDiscard = false;
bool depthBoundsTestEnable; bool depthBoundsTestEnable = false;
bool depthBufferEnable; bool depthBufferEnable = false;
VkCompareOp depthCompareMode; VkCompareOp depthCompareMode = VK_COMPARE_OP_NEVER;
bool depthWriteEnable; bool depthWriteEnable = false;
bool depthClampEnable; bool depthClampEnable = false;
bool depthClipEnable; bool depthClipEnable = false;
float lineWidth; float lineWidth = 0.0f;
int colorWriteMask[sw::RENDERTARGETS]; // RGBA int colorWriteMask[sw::RENDERTARGETS] = {}; // RGBA
unsigned int multiSampleMask; unsigned int multiSampleMask = 0;
int sampleCount; int sampleCount = 0;
bool alphaToCoverage; bool alphaToCoverage = false;
bool sampleShadingEnable = false; bool sampleShadingEnable = false;
float minSampleShading = 0.0f; float minSampleShading = 0.0f;
bool primitiveRestartEnable = false; bool primitiveRestartEnable = false;
VkRect2D scissor; VkRect2D scissor = {};
VkViewport viewport; VkViewport viewport = {};
sw::float4 blendConstants; sw::float4 blendConstants = {};
BlendState blendState[sw::RENDERTARGETS]; BlendState blendState[sw::RENDERTARGETS] = {};
}; };
} // namespace vk } // namespace vk
......
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