Commit 69ffc317 by Nicolas Capens Committed by Nicolas Capens

Initialize the blend state using memset

The BlendState structure is part of the cache key used to look up pixel routines, which must not contain any uninitialized bits. The PixelProcessor::States structure gets zero-initialized as a whole by the Memset<> base class, but when writing BlendState structures into it any uninitialized bits may get copied over. Thus BlendState must also be zero-initialized, using Memset<>. Bug: b/140286664 Bug: b/140193782 Change-Id: I031ec1a5f3be4329ae16366bfd4c8f17e2371384 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/35768Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent 680d3761
...@@ -24,19 +24,6 @@ ...@@ -24,19 +24,6 @@
namespace sw namespace sw
{ {
void BlendState::init()
{
alphaBlendEnable = false;
sourceBlendFactor = VK_BLEND_FACTOR_ONE;
destBlendFactor = VK_BLEND_FACTOR_ZERO;
blendOperation = VK_BLEND_OP_ADD;
sourceBlendFactorAlpha = VK_BLEND_FACTOR_ONE;
destBlendFactorAlpha = VK_BLEND_FACTOR_ZERO;
blendOperationAlpha = VK_BLEND_OP_ADD;
}
Context::Context() Context::Context()
{ {
init(); init();
...@@ -101,9 +88,8 @@ namespace sw ...@@ -101,9 +88,8 @@ namespace sw
for(int i = 0; i < RENDERTARGETS; ++i) for(int i = 0; i < RENDERTARGETS; ++i)
{ {
renderTarget[i] = nullptr; renderTarget[i] = nullptr;
blendState[i].init();
} }
depthBuffer = nullptr; depthBuffer = nullptr;
stencilBuffer = nullptr; stencilBuffer = nullptr;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "Vulkan/VkConfig.h" #include "Vulkan/VkConfig.h"
#include "Vulkan/VkDescriptorSet.hpp" #include "Vulkan/VkDescriptorSet.hpp"
#include "Config.hpp" #include "Config.hpp"
#include "Memset.hpp"
#include "Stream.hpp" #include "Stream.hpp"
#include "System/Types.hpp" #include "System/Types.hpp"
...@@ -36,9 +37,26 @@ namespace sw ...@@ -36,9 +37,26 @@ namespace sw
unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE]; unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE];
}; };
struct BlendState struct BlendState : Memset<BlendState>
{ {
void init(); BlendState() : Memset(this, 0) {}
BlendState(bool alphaBlendEnable,
VkBlendFactor sourceBlendFactor,
VkBlendFactor destBlendFactor,
VkBlendOp blendOperation,
VkBlendFactor sourceBlendFactorAlpha,
VkBlendFactor destBlendFactorAlpha,
VkBlendOp blendOperationAlpha) :
Memset(this, 0),
alphaBlendEnable(alphaBlendEnable),
sourceBlendFactor(sourceBlendFactor),
destBlendFactor(destBlendFactor),
blendOperation(blendOperation),
sourceBlendFactorAlpha(sourceBlendFactorAlpha),
destBlendFactorAlpha(destBlendFactorAlpha),
blendOperationAlpha(blendOperationAlpha)
{}
bool alphaBlendEnable; bool alphaBlendEnable;
VkBlendFactor sourceBlendFactor; VkBlendFactor sourceBlendFactor;
......
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