Add default Undefined sampler compare function

Bug: dawn:367
Change-Id: I27ee54b0117c90dd554690e4fabc939d679c4005
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/18422
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2020-04-17 19:32:07 +00:00 committed by Commit Bot service account
parent f93791ab62
commit d6a5431304
8 changed files with 54 additions and 36 deletions

View File

@ -394,14 +394,15 @@
"compare function": {
"category": "enum",
"values": [
{"value": 0, "name": "never"},
{"value": 1, "name": "less"},
{"value": 2, "name": "less equal"},
{"value": 3, "name": "greater"},
{"value": 4, "name": "greater equal"},
{"value": 5, "name": "equal"},
{"value": 6, "name": "not equal"},
{"value": 7, "name": "always"}
{"value": 0, "name": "undefined"},
{"value": 1, "name": "never"},
{"value": 2, "name": "less"},
{"value": 3, "name": "less equal"},
{"value": 4, "name": "greater"},
{"value": 5, "name": "greater equal"},
{"value": 6, "name": "equal"},
{"value": 7, "name": "not equal"},
{"value": 8, "name": "always"}
]
},
"compute pass descriptor": {
@ -1248,7 +1249,7 @@
{"name": "mipmap filter", "type": "filter mode", "default": "nearest"},
{"name": "lod min clamp", "type": "float", "default": "0.0f"},
{"name": "lod max clamp", "type": "float", "default": "1000.0f"},
{"name": "compare", "type": "compare function", "default": "never"}
{"name": "compare", "type": "compare function", "default": "undefined"}
]
},
"sampler descriptor dummy anisotropic filtering": {

View File

@ -83,7 +83,12 @@ namespace dawn_native { namespace d3d12 {
mSamplerDesc.AddressW = AddressMode(descriptor->addressModeW);
mSamplerDesc.MipLODBias = 0.f;
mSamplerDesc.MaxAnisotropy = 1;
mSamplerDesc.ComparisonFunc = ToD3D12ComparisonFunc(descriptor->compare);
if (descriptor->compare != wgpu::CompareFunction::Undefined) {
mSamplerDesc.ComparisonFunc = ToD3D12ComparisonFunc(descriptor->compare);
} else {
// Still set the function so it's not garbage.
mSamplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
}
mSamplerDesc.MinLOD = descriptor->lodMinClamp;
mSamplerDesc.MaxLOD = descriptor->lodMaxClamp;
}

View File

@ -20,22 +20,22 @@ namespace dawn_native { namespace d3d12 {
D3D12_COMPARISON_FUNC ToD3D12ComparisonFunc(wgpu::CompareFunction func) {
switch (func) {
case wgpu::CompareFunction::Always:
return D3D12_COMPARISON_FUNC_ALWAYS;
case wgpu::CompareFunction::Equal:
return D3D12_COMPARISON_FUNC_EQUAL;
case wgpu::CompareFunction::Greater:
return D3D12_COMPARISON_FUNC_GREATER;
case wgpu::CompareFunction::GreaterEqual:
return D3D12_COMPARISON_FUNC_GREATER_EQUAL;
case wgpu::CompareFunction::Never:
return D3D12_COMPARISON_FUNC_NEVER;
case wgpu::CompareFunction::Less:
return D3D12_COMPARISON_FUNC_LESS;
case wgpu::CompareFunction::LessEqual:
return D3D12_COMPARISON_FUNC_LESS_EQUAL;
case wgpu::CompareFunction::Never:
return D3D12_COMPARISON_FUNC_NEVER;
case wgpu::CompareFunction::Greater:
return D3D12_COMPARISON_FUNC_GREATER;
case wgpu::CompareFunction::GreaterEqual:
return D3D12_COMPARISON_FUNC_GREATER_EQUAL;
case wgpu::CompareFunction::Equal:
return D3D12_COMPARISON_FUNC_EQUAL;
case wgpu::CompareFunction::NotEqual:
return D3D12_COMPARISON_FUNC_NOT_EQUAL;
case wgpu::CompareFunction::Always:
return D3D12_COMPARISON_FUNC_ALWAYS;
default:
UNREACHABLE();
}

View File

@ -52,7 +52,7 @@ namespace dawn_native { namespace metal {
// static
ResultOrError<Sampler*> Sampler::Create(Device* device, const SamplerDescriptor* descriptor) {
if (descriptor->compare != wgpu::CompareFunction::Never &&
if (descriptor->compare != wgpu::CompareFunction::Undefined &&
device->IsToggleEnabled(Toggle::MetalDisableSamplerCompare)) {
return DAWN_VALIDATION_ERROR("Sampler compare function not supported.");
}
@ -75,10 +75,12 @@ namespace dawn_native { namespace metal {
mtlDesc.lodMinClamp = descriptor->lodMinClamp;
mtlDesc.lodMaxClamp = descriptor->lodMaxClamp;
if (descriptor->compare != wgpu::CompareFunction::Never) {
// Anything other than Never is unsupported before A9, which we validate in
if (descriptor->compare != wgpu::CompareFunction::Undefined) {
// Sampler compare is unsupported before A9, which we validate in
// Sampler::Create.
mtlDesc.compareFunction = ToMetalCompareFunction(descriptor->compare);
// The value is default-initialized in the else-case, and we don't set it or the
// Metal debug device errors.
}
mMtlSamplerState = [device->GetMTLDevice() newSamplerStateWithDescriptor:mtlDesc];

View File

@ -14,6 +14,8 @@
#include "dawn_native/metal/UtilsMetal.h"
#include "common/Assert.h"
namespace dawn_native { namespace metal {
MTLCompareFunction ToMetalCompareFunction(wgpu::CompareFunction compareFunction) {
@ -34,6 +36,8 @@ namespace dawn_native { namespace metal {
return MTLCompareFunctionEqual;
case wgpu::CompareFunction::Always:
return MTLCompareFunctionAlways;
default:
UNREACHABLE();
}
}

View File

@ -110,7 +110,7 @@ namespace dawn_native { namespace opengl {
gl.SamplerParameterf(sampler, GL_TEXTURE_MIN_LOD, descriptor->lodMinClamp);
gl.SamplerParameterf(sampler, GL_TEXTURE_MAX_LOD, descriptor->lodMaxClamp);
if (ToOpenGLCompareFunction(descriptor->compare) != GL_NEVER) {
if (descriptor->compare != wgpu::CompareFunction::Undefined) {
gl.SamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
gl.SamplerParameteri(sampler, GL_TEXTURE_COMPARE_FUNC,
ToOpenGLCompareFunction(descriptor->compare));

View File

@ -79,8 +79,14 @@ namespace dawn_native { namespace vulkan {
createInfo.mipLodBias = 0.0f;
createInfo.anisotropyEnable = VK_FALSE;
createInfo.maxAnisotropy = 1.0f;
createInfo.compareOp = ToVulkanCompareOp(descriptor->compare);
createInfo.compareEnable = createInfo.compareOp == VK_COMPARE_OP_NEVER ? VK_FALSE : VK_TRUE;
if (descriptor->compare != wgpu::CompareFunction::Undefined) {
createInfo.compareOp = ToVulkanCompareOp(descriptor->compare);
createInfo.compareEnable = VK_TRUE;
} else {
// Still set the compareOp so it's not garbage.
createInfo.compareOp = VK_COMPARE_OP_NEVER;
createInfo.compareEnable = VK_FALSE;
}
createInfo.minLod = descriptor->lodMinClamp;
createInfo.maxLod = descriptor->lodMaxClamp;
createInfo.unnormalizedCoordinates = VK_FALSE;

View File

@ -23,22 +23,22 @@ namespace dawn_native { namespace vulkan {
VkCompareOp ToVulkanCompareOp(wgpu::CompareFunction op) {
switch (op) {
case wgpu::CompareFunction::Always:
return VK_COMPARE_OP_ALWAYS;
case wgpu::CompareFunction::Equal:
return VK_COMPARE_OP_EQUAL;
case wgpu::CompareFunction::Greater:
return VK_COMPARE_OP_GREATER;
case wgpu::CompareFunction::GreaterEqual:
return VK_COMPARE_OP_GREATER_OR_EQUAL;
case wgpu::CompareFunction::Never:
return VK_COMPARE_OP_NEVER;
case wgpu::CompareFunction::Less:
return VK_COMPARE_OP_LESS;
case wgpu::CompareFunction::LessEqual:
return VK_COMPARE_OP_LESS_OR_EQUAL;
case wgpu::CompareFunction::Never:
return VK_COMPARE_OP_NEVER;
case wgpu::CompareFunction::Greater:
return VK_COMPARE_OP_GREATER;
case wgpu::CompareFunction::GreaterEqual:
return VK_COMPARE_OP_GREATER_OR_EQUAL;
case wgpu::CompareFunction::Equal:
return VK_COMPARE_OP_EQUAL;
case wgpu::CompareFunction::NotEqual:
return VK_COMPARE_OP_NOT_EQUAL;
case wgpu::CompareFunction::Always:
return VK_COMPARE_OP_ALWAYS;
default:
UNREACHABLE();
}