2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-06-16 18:26:26 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/d3d12/SamplerD3D12.h"
|
2017-06-16 18:26:26 +00:00
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/d3d12/DeviceD3D12.h"
|
2019-01-04 04:56:08 +00:00
|
|
|
#include "dawn_native/d3d12/UtilsD3D12.h"
|
2017-06-16 18:26:26 +00:00
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native { namespace d3d12 {
|
2017-06-16 18:26:26 +00:00
|
|
|
|
2018-03-29 18:02:52 +00:00
|
|
|
namespace {
|
2019-10-23 11:57:41 +00:00
|
|
|
D3D12_TEXTURE_ADDRESS_MODE AddressMode(wgpu::AddressMode mode) {
|
2018-03-29 18:02:52 +00:00
|
|
|
switch (mode) {
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::AddressMode::Repeat:
|
2018-03-29 18:02:52 +00:00
|
|
|
return D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::AddressMode::MirrorRepeat:
|
2018-03-29 18:02:52 +00:00
|
|
|
return D3D12_TEXTURE_ADDRESS_MODE_MIRROR;
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::AddressMode::ClampToEdge:
|
2018-03-29 18:02:52 +00:00
|
|
|
return D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2018-07-25 15:03:23 +00:00
|
|
|
Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor)
|
2018-05-17 21:09:07 +00:00
|
|
|
: SamplerBase(device, descriptor) {
|
2020-05-14 17:24:36 +00:00
|
|
|
D3D12_FILTER_TYPE minFilter;
|
2018-05-17 21:09:07 +00:00
|
|
|
switch (descriptor->minFilter) {
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::FilterMode::Nearest:
|
2020-05-14 17:24:36 +00:00
|
|
|
minFilter = D3D12_FILTER_TYPE_POINT;
|
2017-06-16 18:26:26 +00:00
|
|
|
break;
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::FilterMode::Linear:
|
2020-05-14 17:24:36 +00:00
|
|
|
minFilter = D3D12_FILTER_TYPE_LINEAR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2017-06-16 18:26:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:24:36 +00:00
|
|
|
D3D12_FILTER_TYPE magFilter;
|
2018-05-17 21:09:07 +00:00
|
|
|
switch (descriptor->magFilter) {
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::FilterMode::Nearest:
|
2020-05-14 17:24:36 +00:00
|
|
|
magFilter = D3D12_FILTER_TYPE_POINT;
|
2017-06-16 18:26:26 +00:00
|
|
|
break;
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::FilterMode::Linear:
|
2020-05-14 17:24:36 +00:00
|
|
|
magFilter = D3D12_FILTER_TYPE_LINEAR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2017-06-16 18:26:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:24:36 +00:00
|
|
|
D3D12_FILTER_TYPE mipmapFilter;
|
2018-05-17 21:09:07 +00:00
|
|
|
switch (descriptor->mipmapFilter) {
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::FilterMode::Nearest:
|
2020-05-14 17:24:36 +00:00
|
|
|
mipmapFilter = D3D12_FILTER_TYPE_POINT;
|
2017-06-16 18:26:26 +00:00
|
|
|
break;
|
2019-10-23 11:57:41 +00:00
|
|
|
case wgpu::FilterMode::Linear:
|
2020-05-14 17:24:36 +00:00
|
|
|
mipmapFilter = D3D12_FILTER_TYPE_LINEAR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2017-06-16 18:26:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:24:36 +00:00
|
|
|
D3D12_FILTER_REDUCTION_TYPE reduction =
|
|
|
|
descriptor->compare == wgpu::CompareFunction::Undefined
|
|
|
|
? D3D12_FILTER_REDUCTION_TYPE_STANDARD
|
|
|
|
: D3D12_FILTER_REDUCTION_TYPE_COMPARISON;
|
|
|
|
|
|
|
|
mSamplerDesc.Filter =
|
|
|
|
D3D12_ENCODE_BASIC_FILTER(minFilter, magFilter, mipmapFilter, reduction);
|
2018-05-17 21:09:07 +00:00
|
|
|
mSamplerDesc.AddressU = AddressMode(descriptor->addressModeU);
|
|
|
|
mSamplerDesc.AddressV = AddressMode(descriptor->addressModeV);
|
|
|
|
mSamplerDesc.AddressW = AddressMode(descriptor->addressModeW);
|
2017-11-23 19:14:03 +00:00
|
|
|
mSamplerDesc.MipLODBias = 0.f;
|
|
|
|
mSamplerDesc.MaxAnisotropy = 1;
|
2020-04-17 19:32:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-01-04 04:56:08 +00:00
|
|
|
mSamplerDesc.MinLOD = descriptor->lodMinClamp;
|
|
|
|
mSamplerDesc.MaxLOD = descriptor->lodMaxClamp;
|
2017-06-16 18:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const D3D12_SAMPLER_DESC& Sampler::GetSamplerDescriptor() const {
|
2017-11-23 19:14:03 +00:00
|
|
|
return mSamplerDesc;
|
2017-06-16 18:26:26 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
}} // namespace dawn_native::d3d12
|