Don't use VK_TRUE comparisons
The spec states that "Applications must not pass any other values than
VK_TRUE or VK_FALSE into a Vulkan implementation where a VkBool32 is
expected." However, in case applications do use other values, the
least surprising behavior is for non-0 values to be interpreted as true.
Bug: b/134584057
Change-Id: I861691442683d534b4e34bd55deb18643adb3a99
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40448
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Pipeline/SpirvShaderSampling.cpp b/src/Pipeline/SpirvShaderSampling.cpp
index fa07d73..96837a9 100644
--- a/src/Pipeline/SpirvShaderSampling.cpp
+++ b/src/Pipeline/SpirvShaderSampling.cpp
@@ -80,9 +80,9 @@
samplerState.mipmapFilter = convertMipmapMode(sampler);
- samplerState.compareEnable = (sampler->compareEnable == VK_TRUE);
+ samplerState.compareEnable = (sampler->compareEnable != VK_FALSE);
samplerState.compareOp = sampler->compareOp;
- samplerState.unnormalizedCoordinates = (sampler->unnormalizedCoordinates == VK_TRUE);
+ samplerState.unnormalizedCoordinates = (sampler->unnormalizedCoordinates != VK_FALSE);
if(sampler->ycbcrConversion)
{
@@ -224,7 +224,7 @@
sw::FilterType SpirvShader::convertFilterMode(const vk::Sampler *sampler)
{
- if(sampler->anisotropyEnable == VK_TRUE)
+ if(sampler->anisotropyEnable != VK_FALSE)
{
return FILTER_ANISOTROPIC;
}
diff --git a/src/Vulkan/VkPhysicalDevice.cpp b/src/Vulkan/VkPhysicalDevice.cpp
index 364c26d..f3e62f5 100644
--- a/src/Vulkan/VkPhysicalDevice.cpp
+++ b/src/Vulkan/VkPhysicalDevice.cpp
@@ -450,7 +450,7 @@
for(unsigned int i = 0; i < featureCount; i++)
{
- if((requestedFeature[i] == VK_TRUE) && (supportedFeature[i] != VK_TRUE))
+ if((requestedFeature[i] != VK_FALSE) && (supportedFeature[i] == VK_FALSE))
{
return false;
}
diff --git a/src/Vulkan/VkPipeline.cpp b/src/Vulkan/VkPipeline.cpp
index a009c5e..cdf4873 100644
--- a/src/Vulkan/VkPipeline.cpp
+++ b/src/Vulkan/VkPipeline.cpp
@@ -251,7 +251,7 @@
UNIMPLEMENTED("pCreateInfo->pRasterizationState settings");
}
- context.rasterizerDiscard = (rasterizationState->rasterizerDiscardEnable == VK_TRUE);
+ context.rasterizerDiscard = (rasterizationState->rasterizerDiscardEnable != VK_FALSE);
context.cullMode = rasterizationState->cullMode;
context.frontFace = rasterizationState->frontFace;
context.polygonMode = rasterizationState->polygonMode;
@@ -307,7 +307,7 @@
context.sampleMask = multisampleState->pSampleMask[0];
}
- context.alphaToCoverage = (multisampleState->alphaToCoverageEnable == VK_TRUE);
+ context.alphaToCoverage = (multisampleState->alphaToCoverageEnable != VK_FALSE);
if((multisampleState->flags != 0) ||
(multisampleState->sampleShadingEnable != VK_FALSE) ||
@@ -330,12 +330,12 @@
UNIMPLEMENTED("depthStencilState");
}
- context.depthBoundsTestEnable = (depthStencilState->depthBoundsTestEnable == VK_TRUE);
- context.depthBufferEnable = (depthStencilState->depthTestEnable == VK_TRUE);
- context.depthWriteEnable = (depthStencilState->depthWriteEnable == VK_TRUE);
+ context.depthBoundsTestEnable = (depthStencilState->depthBoundsTestEnable != VK_FALSE);
+ context.depthBufferEnable = (depthStencilState->depthTestEnable != VK_FALSE);
+ context.depthWriteEnable = (depthStencilState->depthWriteEnable != VK_FALSE);
context.depthCompareMode = depthStencilState->depthCompareOp;
- context.stencilEnable = (depthStencilState->stencilTestEnable == VK_TRUE);
+ context.stencilEnable = (depthStencilState->stencilTestEnable != VK_FALSE);
if(context.stencilEnable)
{
context.frontStencil = depthStencilState->front;
@@ -365,7 +365,7 @@
const VkPipelineColorBlendAttachmentState &attachment = colorBlendState->pAttachments[i];
context.colorWriteMask[i] = attachment.colorWriteMask;
- context.setBlendState(i, { (attachment.blendEnable == VK_TRUE),
+ context.setBlendState(i, { (attachment.blendEnable != VK_FALSE),
attachment.srcColorBlendFactor, attachment.dstColorBlendFactor, attachment.colorBlendOp,
attachment.srcAlphaBlendFactor, attachment.dstAlphaBlendFactor, attachment.alphaBlendOp });
}
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp
index 72d8e69..7ad1de9 100644
--- a/src/Vulkan/libVulkan.cpp
+++ b/src/Vulkan/libVulkan.cpp
@@ -561,10 +561,10 @@
{
const VkPhysicalDevice16BitStorageFeatures *storage16BitFeatures = reinterpret_cast<const VkPhysicalDevice16BitStorageFeatures *>(extensionCreateInfo);
- if(storage16BitFeatures->storageBuffer16BitAccess == VK_TRUE ||
- storage16BitFeatures->uniformAndStorageBuffer16BitAccess == VK_TRUE ||
- storage16BitFeatures->storagePushConstant16 == VK_TRUE ||
- storage16BitFeatures->storageInputOutput16 == VK_TRUE)
+ if(storage16BitFeatures->storageBuffer16BitAccess != VK_FALSE ||
+ storage16BitFeatures->uniformAndStorageBuffer16BitAccess != VK_FALSE ||
+ storage16BitFeatures->storagePushConstant16 != VK_FALSE ||
+ storage16BitFeatures->storageInputOutput16 != VK_FALSE)
{
return VK_ERROR_FEATURE_NOT_PRESENT;
}
@@ -574,8 +574,8 @@
{
const VkPhysicalDeviceVariablePointerFeatures *variablePointerFeatures = reinterpret_cast<const VkPhysicalDeviceVariablePointerFeatures *>(extensionCreateInfo);
- if(variablePointerFeatures->variablePointersStorageBuffer == VK_TRUE ||
- variablePointerFeatures->variablePointers == VK_TRUE)
+ if(variablePointerFeatures->variablePointersStorageBuffer != VK_FALSE ||
+ variablePointerFeatures->variablePointers != VK_FALSE)
{
return VK_ERROR_FEATURE_NOT_PRESENT;
}
@@ -616,10 +616,10 @@
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT:
{
const VkPhysicalDeviceLineRasterizationFeaturesEXT *lineRasterizationFeatures = reinterpret_cast<const VkPhysicalDeviceLineRasterizationFeaturesEXT *>(extensionCreateInfo);
- if((lineRasterizationFeatures->smoothLines == VK_TRUE) ||
- (lineRasterizationFeatures->stippledBresenhamLines == VK_TRUE) ||
- (lineRasterizationFeatures->stippledRectangularLines == VK_TRUE) ||
- (lineRasterizationFeatures->stippledSmoothLines == VK_TRUE))
+ if((lineRasterizationFeatures->smoothLines != VK_FALSE) ||
+ (lineRasterizationFeatures->stippledBresenhamLines != VK_FALSE) ||
+ (lineRasterizationFeatures->stippledRectangularLines != VK_FALSE) ||
+ (lineRasterizationFeatures->stippledSmoothLines != VK_FALSE))
{
return VK_ERROR_FEATURE_NOT_PRESENT;
}