Make SamplerDescriptor optional in CreateSampler

Use default SamplerDescriptor if not descriptor is passed in.
Change some createSampler calls to pass nothing in for testing.
The default values for SamplerDescriptor and that from
utils::GetDefaultSamplerDescriptor are different so we may still want to
keep it.

Bug: dawn:599
Change-Id: Ie75d9e1fde608cb19049b50f4613be63802c8719
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/38621
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shrek Shao <shrekshao@google.com>
This commit is contained in:
shrekshao 2021-01-26 02:22:58 +00:00 committed by Commit Bot service account
parent f47a14fc17
commit b3177d418e
8 changed files with 9 additions and 15 deletions

View File

@ -726,7 +726,7 @@
"name": "create sampler",
"returns": "sampler",
"args": [
{"name": "descriptor", "type": "sampler descriptor", "annotation": "const*"}
{"name": "descriptor", "type": "sampler descriptor", "annotation": "const*", "optional": true}
]
},
{

View File

@ -1067,7 +1067,9 @@ namespace dawn_native {
MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result,
const SamplerDescriptor* descriptor) {
const SamplerDescriptor defaultDescriptor = {};
DAWN_TRY(ValidateIsAlive());
descriptor = descriptor != nullptr ? descriptor : &defaultDescriptor;
if (IsValidationEnabled()) {
DAWN_TRY(ValidateSamplerDescriptor(this, descriptor));
}

View File

@ -1219,8 +1219,7 @@ TEST_P(BindGroupTests, ReallyLargeBindGroup) {
interface << "[[group(0), binding(" << binding++ << ")]] "
<< "var<uniform_constant> tex" << i << " : texture_2d<f32>;\n";
wgpu::SamplerDescriptor samplerDesc = {};
bgEntries.push_back({binding, nullptr, 0, 0, device.CreateSampler(&samplerDesc), nullptr});
bgEntries.push_back({binding, nullptr, 0, 0, device.CreateSampler(), nullptr});
interface << "[[group(0), binding(" << binding++ << ")]]"
<< "var<uniform_constant> samp" << i << " : sampler;\n";

View File

@ -192,8 +192,7 @@ TEST_P(DeviceLostTest, CreateRenderPipelineFails) {
TEST_P(DeviceLostTest, CreateSamplerFails) {
SetCallbackAndLoseForTesting();
wgpu::SamplerDescriptor descriptor = utils::GetDefaultSamplerDescriptor();
ASSERT_DEVICE_ERROR(device.CreateSampler(&descriptor));
ASSERT_DEVICE_ERROR(device.CreateSampler());
}
// Tests that CreateShaderModule fails when device is lost

View File

@ -123,8 +123,7 @@ class TextureSubresourceTest : public DawnTest {
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleList;
descriptor.cColorStates[0].format = kFormat;
wgpu::SamplerDescriptor samplerDescriptor = {};
wgpu::Sampler sampler = device.CreateSampler(&samplerDescriptor);
wgpu::Sampler sampler = device.CreateSampler();
wgpu::RenderPipeline rp = device.CreateRenderPipeline(&descriptor);
wgpu::BindGroupLayout bgl = rp.GetBindGroupLayout(0);

View File

@ -1791,8 +1791,7 @@ class CompressedTextureZeroInitTest : public TextureZeroInitTest {
device.CreateRenderPipeline(&renderPipelineDescriptor);
pass.SetPipeline(renderPipeline);
wgpu::SamplerDescriptor samplerDesc = {};
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
wgpu::Sampler sampler = device.CreateSampler();
wgpu::TextureViewDescriptor textureViewDescriptor = CreateTextureViewDescriptor(
viewMipmapLevel, baseArrayLayer, textureDescriptor.format);

View File

@ -2124,8 +2124,7 @@ TEST_F(ComparisonSamplerBindingTest, SamplerAndBindGroupMatches) {
wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::SamplerBindingType::Filtering}});
wgpu::SamplerDescriptor desc = {};
utils::MakeBindGroup(device, bindGroupLayout, {{0, device.CreateSampler(&desc)}});
utils::MakeBindGroup(device, bindGroupLayout, {{0, device.CreateSampler()}});
}
// Test that comparison sampler binding works with sampler w/ compare function.

View File

@ -96,10 +96,7 @@ namespace {
kValidAnisoSamplerDesc.minFilter = wgpu::FilterMode::Linear;
kValidAnisoSamplerDesc.magFilter = wgpu::FilterMode::Linear;
kValidAnisoSamplerDesc.mipmapFilter = wgpu::FilterMode::Linear;
{
wgpu::SamplerDescriptor samplerDesc = {};
device.CreateSampler(&samplerDesc);
}
{ device.CreateSampler(); }
{
wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc;
samplerDesc.maxAnisotropy = 16;