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", "name": "create sampler",
"returns": "sampler", "returns": "sampler",
"args": [ "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, MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result,
const SamplerDescriptor* descriptor) { const SamplerDescriptor* descriptor) {
const SamplerDescriptor defaultDescriptor = {};
DAWN_TRY(ValidateIsAlive()); DAWN_TRY(ValidateIsAlive());
descriptor = descriptor != nullptr ? descriptor : &defaultDescriptor;
if (IsValidationEnabled()) { if (IsValidationEnabled()) {
DAWN_TRY(ValidateSamplerDescriptor(this, descriptor)); DAWN_TRY(ValidateSamplerDescriptor(this, descriptor));
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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