Implement sampler address modes (API, D3D, MTL, GL).
This commit is contained in:
parent
cd4f8a2e2f
commit
a9e3d7fd00
16
next.json
16
next.json
|
@ -714,6 +714,14 @@
|
||||||
{"value": 1, "name":"linear"}
|
{"value": 1, "name":"linear"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"address mode": {
|
||||||
|
"category": "enum",
|
||||||
|
"values": [
|
||||||
|
{"value": 0, "name":"repeat"},
|
||||||
|
{"value": 1, "name":"mirrored repeat"},
|
||||||
|
{"value": 2, "name":"clamp to edge"}
|
||||||
|
]
|
||||||
|
},
|
||||||
"float": {
|
"float": {
|
||||||
"category": "native"
|
"category": "native"
|
||||||
},
|
},
|
||||||
|
@ -1018,6 +1026,14 @@
|
||||||
{"name": "min filter", "type": "filter mode"},
|
{"name": "min filter", "type": "filter mode"},
|
||||||
{"name": "mipmap filter", "type": "filter mode"}
|
{"name": "mipmap filter", "type": "filter mode"}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set address mode",
|
||||||
|
"args": [
|
||||||
|
{"name": "address mode u", "type": "address mode"},
|
||||||
|
{"name": "address mode v", "type": "address mode"},
|
||||||
|
{"name": "address mode w", "type": "address mode"}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace backend {
|
||||||
|
|
||||||
enum SamplerSetProperties {
|
enum SamplerSetProperties {
|
||||||
SAMPLER_PROPERTY_FILTER = 0x1,
|
SAMPLER_PROPERTY_FILTER = 0x1,
|
||||||
|
SAMPLER_PROPERTY_ADDRESS = 0x2,
|
||||||
};
|
};
|
||||||
SamplerBuilder::SamplerBuilder(DeviceBase* device) : Builder(device) {
|
SamplerBuilder::SamplerBuilder(DeviceBase* device) : Builder(device) {
|
||||||
}
|
}
|
||||||
|
@ -43,6 +44,18 @@ namespace backend {
|
||||||
return mMipMapFilter;
|
return mMipMapFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nxt::AddressMode SamplerBuilder::GetAddressModeU() const {
|
||||||
|
return mAddressModeU;
|
||||||
|
}
|
||||||
|
|
||||||
|
nxt::AddressMode SamplerBuilder::GetAddressModeV() const {
|
||||||
|
return mAddressModeV;
|
||||||
|
}
|
||||||
|
|
||||||
|
nxt::AddressMode SamplerBuilder::GetAddressModeW() const {
|
||||||
|
return mAddressModeW;
|
||||||
|
}
|
||||||
|
|
||||||
void SamplerBuilder::SetFilterMode(nxt::FilterMode magFilter,
|
void SamplerBuilder::SetFilterMode(nxt::FilterMode magFilter,
|
||||||
nxt::FilterMode minFilter,
|
nxt::FilterMode minFilter,
|
||||||
nxt::FilterMode mipMapFilter) {
|
nxt::FilterMode mipMapFilter) {
|
||||||
|
@ -57,6 +70,20 @@ namespace backend {
|
||||||
mPropertiesSet |= SAMPLER_PROPERTY_FILTER;
|
mPropertiesSet |= SAMPLER_PROPERTY_FILTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SamplerBuilder::SetAddressMode(nxt::AddressMode addressModeU,
|
||||||
|
nxt::AddressMode addressModeV,
|
||||||
|
nxt::AddressMode addressModeW) {
|
||||||
|
if ((mPropertiesSet & SAMPLER_PROPERTY_ADDRESS) != 0) {
|
||||||
|
HandleError("Sampler address property set multiple times");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mAddressModeU = addressModeU;
|
||||||
|
mAddressModeV = addressModeV;
|
||||||
|
mAddressModeW = addressModeW;
|
||||||
|
mPropertiesSet |= SAMPLER_PROPERTY_ADDRESS;
|
||||||
|
}
|
||||||
|
|
||||||
SamplerBase* SamplerBuilder::GetResultImpl() {
|
SamplerBase* SamplerBuilder::GetResultImpl() {
|
||||||
return mDevice->CreateSampler(this);
|
return mDevice->CreateSampler(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,19 @@ namespace backend {
|
||||||
nxt::FilterMode GetMinFilter() const;
|
nxt::FilterMode GetMinFilter() const;
|
||||||
nxt::FilterMode GetMipMapFilter() const;
|
nxt::FilterMode GetMipMapFilter() const;
|
||||||
|
|
||||||
|
nxt::AddressMode GetAddressModeU() const;
|
||||||
|
nxt::AddressMode GetAddressModeV() const;
|
||||||
|
nxt::AddressMode GetAddressModeW() const;
|
||||||
|
|
||||||
// NXT API
|
// NXT API
|
||||||
void SetFilterMode(nxt::FilterMode magFilter,
|
void SetFilterMode(nxt::FilterMode magFilter,
|
||||||
nxt::FilterMode minFilter,
|
nxt::FilterMode minFilter,
|
||||||
nxt::FilterMode mipMapFilter);
|
nxt::FilterMode mipMapFilter);
|
||||||
|
|
||||||
|
void SetAddressMode(nxt::AddressMode addressModeU,
|
||||||
|
nxt::AddressMode addressModeV,
|
||||||
|
nxt::AddressMode addressModeW);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class SamplerBase;
|
friend class SamplerBase;
|
||||||
|
|
||||||
|
@ -51,6 +59,10 @@ namespace backend {
|
||||||
nxt::FilterMode mMagFilter = nxt::FilterMode::Nearest;
|
nxt::FilterMode mMagFilter = nxt::FilterMode::Nearest;
|
||||||
nxt::FilterMode mMinFilter = nxt::FilterMode::Nearest;
|
nxt::FilterMode mMinFilter = nxt::FilterMode::Nearest;
|
||||||
nxt::FilterMode mMipMapFilter = nxt::FilterMode::Nearest;
|
nxt::FilterMode mMipMapFilter = nxt::FilterMode::Nearest;
|
||||||
|
|
||||||
|
nxt::AddressMode mAddressModeU = nxt::AddressMode::ClampToEdge;
|
||||||
|
nxt::AddressMode mAddressModeV = nxt::AddressMode::ClampToEdge;
|
||||||
|
nxt::AddressMode mAddressModeW = nxt::AddressMode::ClampToEdge;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace backend
|
} // namespace backend
|
||||||
|
|
|
@ -18,6 +18,21 @@
|
||||||
|
|
||||||
namespace backend { namespace d3d12 {
|
namespace backend { namespace d3d12 {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
D3D12_TEXTURE_ADDRESS_MODE AddressMode(nxt::AddressMode mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case nxt::AddressMode::Repeat:
|
||||||
|
return D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||||
|
case nxt::AddressMode::MirroredRepeat:
|
||||||
|
return D3D12_TEXTURE_ADDRESS_MODE_MIRROR;
|
||||||
|
case nxt::AddressMode::ClampToEdge:
|
||||||
|
return D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
|
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn770367(v=vs.85).aspx
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn770367(v=vs.85).aspx
|
||||||
// hex value, decimal value, min linear, mag linear, mip linear
|
// hex value, decimal value, min linear, mag linear, mip linear
|
||||||
|
@ -61,9 +76,9 @@ namespace backend { namespace d3d12 {
|
||||||
}
|
}
|
||||||
|
|
||||||
mSamplerDesc.Filter = static_cast<D3D12_FILTER>(mode);
|
mSamplerDesc.Filter = static_cast<D3D12_FILTER>(mode);
|
||||||
mSamplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
mSamplerDesc.AddressU = AddressMode(builder->GetAddressModeU());
|
||||||
mSamplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
mSamplerDesc.AddressV = AddressMode(builder->GetAddressModeV());
|
||||||
mSamplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
mSamplerDesc.AddressW = AddressMode(builder->GetAddressModeW());
|
||||||
mSamplerDesc.MipLODBias = 0.f;
|
mSamplerDesc.MipLODBias = 0.f;
|
||||||
mSamplerDesc.MaxAnisotropy = 1;
|
mSamplerDesc.MaxAnisotropy = 1;
|
||||||
mSamplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
mSamplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
||||||
|
|
|
@ -36,6 +36,17 @@ namespace backend { namespace metal {
|
||||||
return MTLSamplerMipFilterLinear;
|
return MTLSamplerMipFilterLinear;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MTLSamplerAddressMode AddressMode(nxt::AddressMode mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case nxt::AddressMode::Repeat:
|
||||||
|
return MTLSamplerAddressModeRepeat;
|
||||||
|
case nxt::AddressMode::MirroredRepeat:
|
||||||
|
return MTLSamplerAddressModeMirrorRepeat;
|
||||||
|
case nxt::AddressMode::ClampToEdge:
|
||||||
|
return MTLSamplerAddressModeClampToEdge;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
|
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
|
||||||
|
@ -45,7 +56,10 @@ namespace backend { namespace metal {
|
||||||
desc.magFilter = FilterModeToMinMagFilter(builder->GetMagFilter());
|
desc.magFilter = FilterModeToMinMagFilter(builder->GetMagFilter());
|
||||||
desc.mipFilter = FilterModeToMipFilter(builder->GetMipMapFilter());
|
desc.mipFilter = FilterModeToMipFilter(builder->GetMipMapFilter());
|
||||||
|
|
||||||
// TODO(kainino@chromium.org): wrap modes
|
desc.sAddressMode = AddressMode(builder->GetAddressModeU());
|
||||||
|
desc.tAddressMode = AddressMode(builder->GetAddressModeV());
|
||||||
|
desc.rAddressMode = AddressMode(builder->GetAddressModeW());
|
||||||
|
|
||||||
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
|
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
|
||||||
mMtlSamplerState = [mtlDevice newSamplerStateWithDescriptor:desc];
|
mMtlSamplerState = [mtlDevice newSamplerStateWithDescriptor:desc];
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,20 @@ namespace backend { namespace opengl {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLenum WrapMode(nxt::AddressMode mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case nxt::AddressMode::Repeat:
|
||||||
|
return GL_REPEAT;
|
||||||
|
case nxt::AddressMode::MirroredRepeat:
|
||||||
|
return GL_MIRRORED_REPEAT;
|
||||||
|
case nxt::AddressMode::ClampToEdge:
|
||||||
|
return GL_CLAMP_TO_EDGE;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
|
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
|
||||||
|
@ -61,6 +75,9 @@ namespace backend { namespace opengl {
|
||||||
glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
|
glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
|
||||||
glSamplerParameteri(mHandle, GL_TEXTURE_MIN_FILTER,
|
glSamplerParameteri(mHandle, GL_TEXTURE_MIN_FILTER,
|
||||||
MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter()));
|
MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter()));
|
||||||
|
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_R, WrapMode(builder->GetAddressModeW()));
|
||||||
|
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_S, WrapMode(builder->GetAddressModeU()));
|
||||||
|
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_T, WrapMode(builder->GetAddressModeV()));
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint Sampler::GetHandle() const {
|
GLuint Sampler::GetHandle() const {
|
||||||
|
|
Loading…
Reference in New Issue