Change Sampler creation to use a descriptor instead of a builder

This commit is contained in:
Corentin Wallez 2018-05-17 17:09:07 -04:00 committed by Corentin Wallez
parent a6416543a4
commit 1ae19e8276
29 changed files with 152 additions and 214 deletions

View File

@ -56,9 +56,16 @@ void initTextures() {
.SetAllowedUsage(nxt::TextureUsageBit::TransferDst | nxt::TextureUsageBit::Sampled)
.GetResult();
sampler = device.CreateSamplerBuilder()
.SetFilterMode(nxt::FilterMode::Linear, nxt::FilterMode::Linear, nxt::FilterMode::Linear)
.GetResult();
{
nxt::SamplerDescriptor desc;
desc.minFilter = nxt::FilterMode::Linear;
desc.magFilter = nxt::FilterMode::Linear;
desc.mipmapFilter = nxt::FilterMode::Linear;
desc.addressModeU = nxt::AddressMode::Repeat;
desc.addressModeV = nxt::AddressMode::Repeat;
desc.addressModeW = nxt::AddressMode::Repeat;
sampler = device.CreateSampler(&desc);
}
// Initialize the texture with arbitrary data until we can load images
std::vector<uint8_t> data(4 * 1024 * 1024, 0);

View File

@ -64,9 +64,16 @@ void initTextures() {
.GetResult();
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();
samplerPost = device.CreateSamplerBuilder()
.SetFilterMode(nxt::FilterMode::Linear, nxt::FilterMode::Linear, nxt::FilterMode::Linear)
.GetResult();
{
nxt::SamplerDescriptor desc;
desc.minFilter = nxt::FilterMode::Linear;
desc.magFilter = nxt::FilterMode::Linear;
desc.mipmapFilter = nxt::FilterMode::Linear;
desc.addressModeU = nxt::AddressMode::Repeat;
desc.addressModeV = nxt::AddressMode::Repeat;
desc.addressModeW = nxt::AddressMode::Repeat;
samplerPost = device.CreateSampler(&desc);
}
}
void initPipeline() {

View File

@ -336,15 +336,21 @@ namespace {
const auto& iSamplerID = s.first;
const auto& iSampler = s.second;
auto magFilter = nxt::FilterMode::Nearest;
auto minFilter = nxt::FilterMode::Nearest;
auto mipmapFilter = nxt::FilterMode::Nearest;
nxt::SamplerDescriptor desc;
desc.magFilter = nxt::FilterMode::Nearest;
desc.minFilter = nxt::FilterMode::Nearest;
desc.mipmapFilter = nxt::FilterMode::Nearest;
// TODO: wrap modes
desc.addressModeU = nxt::AddressMode::Repeat;
desc.addressModeV = nxt::AddressMode::Repeat;
desc.addressModeW = nxt::AddressMode::Repeat;
switch (iSampler.magFilter) {
case gl::Nearest:
magFilter = nxt::FilterMode::Nearest;
desc.magFilter = nxt::FilterMode::Nearest;
break;
case gl::Linear:
magFilter = nxt::FilterMode::Linear;
desc.magFilter = nxt::FilterMode::Linear;
break;
default:
fprintf(stderr, "unsupported magFilter %d\n", iSampler.magFilter);
@ -354,12 +360,12 @@ namespace {
case gl::Nearest:
case gl::NearestMipmapNearest:
case gl::NearestMipmapLinear:
minFilter = nxt::FilterMode::Nearest;
desc.minFilter = nxt::FilterMode::Nearest;
break;
case gl::Linear:
case gl::LinearMipmapNearest:
case gl::LinearMipmapLinear:
minFilter = nxt::FilterMode::Linear;
desc.minFilter = nxt::FilterMode::Linear;
break;
default:
fprintf(stderr, "unsupported minFilter %d\n", iSampler.magFilter);
@ -368,20 +374,15 @@ namespace {
switch (iSampler.minFilter) {
case gl::NearestMipmapNearest:
case gl::LinearMipmapNearest:
mipmapFilter = nxt::FilterMode::Nearest;
desc.mipmapFilter = nxt::FilterMode::Nearest;
break;
case gl::NearestMipmapLinear:
case gl::LinearMipmapLinear:
mipmapFilter = nxt::FilterMode::Linear;
desc.mipmapFilter = nxt::FilterMode::Linear;
break;
}
auto oSampler = device.CreateSamplerBuilder()
.SetFilterMode(magFilter, minFilter, mipmapFilter)
// TODO: wrap modes
.GetResult();
samplers[iSamplerID] = std::move(oSampler);
samplers[iSamplerID] = device.CreateSampler(&desc);
}
}

View File

@ -616,8 +616,11 @@
"returns": "queue builder"
},
{
"name": "create sampler builder",
"returns": "sampler builder"
"name": "create sampler",
"returns": "sampler",
"args": [
{"name": "descriptor", "type": "sampler descriptor", "annotation": "const*"}
]
},
{
"name": "create shader module builder",
@ -936,30 +939,17 @@
"sampler": {
"category": "object"
},
"sampler builder": {
"category": "object",
"methods": [
{
"name": "get result",
"returns": "sampler"
},
{
"name": "set filter mode",
"args": [
"sampler descriptor": {
"category": "structure",
"extensible": true,
"members": [
{"name": "mag filter", "type": "filter mode"},
{"name": "min filter", "type": "filter mode"},
{"name": "mipmap filter", "type": "filter mode"}
]
},
{
"name": "set address mode",
"args": [
{"name": "mipmap filter", "type": "filter mode"},
{"name": "address mode u", "type": "address mode"},
{"name": "address mode v", "type": "address mode"},
{"name": "address mode w", "type": "address mode"}
]
}
]
},
"shader module": {
"category": "object"

View File

@ -130,8 +130,11 @@ namespace backend {
RenderPipelineBuilder* DeviceBase::CreateRenderPipelineBuilder() {
return new RenderPipelineBuilder(this);
}
SamplerBuilder* DeviceBase::CreateSamplerBuilder() {
return new SamplerBuilder(this);
SamplerBase* DeviceBase::CreateSampler(const nxt::SamplerDescriptor* descriptor) {
if (!ValidateSamplerDescriptor(this, descriptor)) {
return nullptr;
}
return CreateSamplerImpl(descriptor);
}
ShaderModuleBuilder* DeviceBase::CreateShaderModuleBuilder() {
return new ShaderModuleBuilder(this);

View File

@ -49,7 +49,6 @@ namespace backend {
virtual RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) = 0;
virtual RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) = 0;
virtual SamplerBase* CreateSampler(SamplerBuilder* builder) = 0;
virtual ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) = 0;
virtual SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) = 0;
virtual TextureBase* CreateTexture(TextureBuilder* builder) = 0;
@ -88,7 +87,7 @@ namespace backend {
QueueBuilder* CreateQueueBuilder();
RenderPassDescriptorBuilder* CreateRenderPassDescriptorBuilder();
RenderPipelineBuilder* CreateRenderPipelineBuilder();
SamplerBuilder* CreateSamplerBuilder();
SamplerBase* CreateSampler(const nxt::SamplerDescriptor* descriptor);
ShaderModuleBuilder* CreateShaderModuleBuilder();
SwapChainBuilder* CreateSwapChainBuilder();
TextureBuilder* CreateTextureBuilder();
@ -99,6 +98,8 @@ namespace backend {
void Release();
private:
virtual SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) = 0;
// The object caches aren't exposed in the header as they would require a lot of
// additional includes.
struct Caches;

View File

@ -46,7 +46,6 @@ namespace backend {
class RenderPipelineBase;
class RenderPipelineBuilder;
class SamplerBase;
class SamplerBuilder;
class ShaderModuleBase;
class ShaderModuleBuilder;
class SwapChainBase;

View File

@ -15,77 +15,22 @@
#include "backend/Sampler.h"
#include "backend/Device.h"
#include "backend/ValidationUtils_autogen.h"
namespace backend {
bool ValidateSamplerDescriptor(DeviceBase*, const nxt::SamplerDescriptor* descriptor) {
return descriptor->nextInChain == nullptr && IsValidFilterMode(descriptor->magFilter) &&
IsValidFilterMode(descriptor->minFilter) &&
IsValidFilterMode(descriptor->mipmapFilter) &&
IsValidAddressMode(descriptor->addressModeU) &&
IsValidAddressMode(descriptor->addressModeV) &&
IsValidAddressMode(descriptor->addressModeW);
}
// SamplerBase
SamplerBase::SamplerBase(SamplerBuilder*) {
}
// SamplerBuilder
enum SamplerSetProperties {
SAMPLER_PROPERTY_FILTER = 0x1,
SAMPLER_PROPERTY_ADDRESS = 0x2,
};
SamplerBuilder::SamplerBuilder(DeviceBase* device) : Builder(device) {
}
nxt::FilterMode SamplerBuilder::GetMagFilter() const {
return mMagFilter;
}
nxt::FilterMode SamplerBuilder::GetMinFilter() const {
return mMinFilter;
}
nxt::FilterMode SamplerBuilder::GetMipMapFilter() const {
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,
nxt::FilterMode minFilter,
nxt::FilterMode mipMapFilter) {
if ((mPropertiesSet & SAMPLER_PROPERTY_FILTER) != 0) {
HandleError("Sampler filter property set multiple times");
return;
}
mMagFilter = magFilter;
mMinFilter = minFilter;
mMipMapFilter = mipMapFilter;
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() {
return mDevice->CreateSampler(this);
SamplerBase::SamplerBase(DeviceBase*, const nxt::SamplerDescriptor*) {
}
} // namespace backend

View File

@ -15,54 +15,19 @@
#ifndef BACKEND_SAMPLER_H_
#define BACKEND_SAMPLER_H_
#include "backend/Buffer.h"
#include "backend/Forward.h"
#include "backend/RefCounted.h"
#include "nxt/nxtcpp.h"
namespace backend {
class DeviceBase;
bool ValidateSamplerDescriptor(DeviceBase* device, const nxt::SamplerDescriptor* descriptor);
class SamplerBase : public RefCounted {
public:
SamplerBase(SamplerBuilder* builder);
};
class SamplerBuilder : public Builder<SamplerBase> {
public:
SamplerBuilder(DeviceBase* device);
nxt::FilterMode GetMagFilter() const;
nxt::FilterMode GetMinFilter() const;
nxt::FilterMode GetMipMapFilter() const;
nxt::AddressMode GetAddressModeU() const;
nxt::AddressMode GetAddressModeV() const;
nxt::AddressMode GetAddressModeW() const;
// NXT API
void SetFilterMode(nxt::FilterMode magFilter,
nxt::FilterMode minFilter,
nxt::FilterMode mipMapFilter);
void SetAddressMode(nxt::AddressMode addressModeU,
nxt::AddressMode addressModeV,
nxt::AddressMode addressModeW);
private:
friend class SamplerBase;
SamplerBase* GetResultImpl() override;
int mPropertiesSet = 0;
nxt::FilterMode mMagFilter = nxt::FilterMode::Nearest;
nxt::FilterMode mMinFilter = 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;
SamplerBase(DeviceBase* device, const nxt::SamplerDescriptor* descriptor);
};
} // namespace backend

View File

@ -298,8 +298,8 @@ namespace backend { namespace d3d12 {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSampler(SamplerBuilder* builder) {
return new Sampler(builder);
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
return new ShaderModule(this, builder);

View File

@ -100,7 +100,6 @@ namespace backend { namespace d3d12 {
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureBase* CreateTexture(TextureBuilder* builder) override;
@ -129,6 +128,8 @@ namespace backend { namespace d3d12 {
void ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists);
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
uint64_t mSerial = 0;
ComPtr<ID3D12Fence> mFence;
HANDLE mFenceEvent;

View File

@ -57,7 +57,7 @@ namespace backend { namespace d3d12 {
RenderPassDescriptor::GetSubpassOMSetRenderTargetArgs() {
OMSetRenderTargetArgs args = {};
size_t rtvIndex = 0;
unsigned int rtvIndex = 0;
for (uint32_t i : IterateBitSet(GetColorAttachmentMask())) {
args.RTVs[rtvIndex] = GetRTVDescriptor(i);
rtvIndex++;

View File

@ -33,7 +33,8 @@ namespace backend { namespace d3d12 {
}
} // namespace
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
Sampler::Sampler(Device* device, const nxt::SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) {
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn770367(v=vs.85).aspx
// hex value, decimal value, min linear, mag linear, mip linear
// D3D12_FILTER_MIN_MAG_MIP_POINT = 0 0 0 0 0
@ -51,7 +52,7 @@ namespace backend { namespace d3d12 {
uint8_t mode = 0;
switch (builder->GetMinFilter()) {
switch (descriptor->minFilter) {
case nxt::FilterMode::Nearest:
break;
case nxt::FilterMode::Linear:
@ -59,7 +60,7 @@ namespace backend { namespace d3d12 {
break;
}
switch (builder->GetMagFilter()) {
switch (descriptor->magFilter) {
case nxt::FilterMode::Nearest:
break;
case nxt::FilterMode::Linear:
@ -67,7 +68,7 @@ namespace backend { namespace d3d12 {
break;
}
switch (builder->GetMipMapFilter()) {
switch (descriptor->mipmapFilter) {
case nxt::FilterMode::Nearest:
break;
case nxt::FilterMode::Linear:
@ -76,9 +77,9 @@ namespace backend { namespace d3d12 {
}
mSamplerDesc.Filter = static_cast<D3D12_FILTER>(mode);
mSamplerDesc.AddressU = AddressMode(builder->GetAddressModeU());
mSamplerDesc.AddressV = AddressMode(builder->GetAddressModeV());
mSamplerDesc.AddressW = AddressMode(builder->GetAddressModeW());
mSamplerDesc.AddressU = AddressMode(descriptor->addressModeU);
mSamplerDesc.AddressV = AddressMode(descriptor->addressModeV);
mSamplerDesc.AddressW = AddressMode(descriptor->addressModeW);
mSamplerDesc.MipLODBias = 0.f;
mSamplerDesc.MaxAnisotropy = 1;
mSamplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;

View File

@ -21,9 +21,11 @@
namespace backend { namespace d3d12 {
class Device;
class Sampler : public SamplerBase {
public:
Sampler(SamplerBuilder* builder);
Sampler(Device* device, const nxt::SamplerDescriptor* descriptor);
const D3D12_SAMPLER_DESC& GetSamplerDescriptor() const;

View File

@ -101,7 +101,6 @@ namespace backend { namespace metal {
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureBase* CreateTexture(TextureBuilder* builder) override;
@ -119,6 +118,8 @@ namespace backend { namespace metal {
ResourceUploader* GetResourceUploader() const;
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
void OnCompletedHandler();
id<MTLDevice> mMtlDevice = nil;

View File

@ -117,8 +117,8 @@ namespace backend { namespace metal {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSampler(SamplerBuilder* builder) {
return new Sampler(builder);
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
return new ShaderModule(builder);

View File

@ -21,9 +21,11 @@
namespace backend { namespace metal {
class Device;
class Sampler : public SamplerBase {
public:
Sampler(SamplerBuilder* builder);
Sampler(Device* device, const nxt::SamplerDescriptor* descriptor);
~Sampler();
id<MTLSamplerState> GetMTLSamplerState();

View File

@ -49,19 +49,19 @@ namespace backend { namespace metal {
}
}
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
auto desc = [MTLSamplerDescriptor new];
[desc autorelease];
desc.minFilter = FilterModeToMinMagFilter(builder->GetMinFilter());
desc.magFilter = FilterModeToMinMagFilter(builder->GetMagFilter());
desc.mipFilter = FilterModeToMipFilter(builder->GetMipMapFilter());
Sampler::Sampler(Device* device, const nxt::SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) {
MTLSamplerDescriptor* mtlDesc = [MTLSamplerDescriptor new];
[mtlDesc autorelease];
mtlDesc.minFilter = FilterModeToMinMagFilter(descriptor->minFilter);
mtlDesc.magFilter = FilterModeToMinMagFilter(descriptor->magFilter);
mtlDesc.mipFilter = FilterModeToMipFilter(descriptor->mipmapFilter);
desc.sAddressMode = AddressMode(builder->GetAddressModeU());
desc.tAddressMode = AddressMode(builder->GetAddressModeV());
desc.rAddressMode = AddressMode(builder->GetAddressModeW());
mtlDesc.sAddressMode = AddressMode(descriptor->addressModeU);
mtlDesc.tAddressMode = AddressMode(descriptor->addressModeV);
mtlDesc.rAddressMode = AddressMode(descriptor->addressModeW);
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
mMtlSamplerState = [mtlDevice newSamplerStateWithDescriptor:desc];
mMtlSamplerState = [device->GetMTLDevice() newSamplerStateWithDescriptor:mtlDesc];
}
Sampler::~Sampler() {

View File

@ -76,8 +76,8 @@ namespace backend { namespace null {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSampler(SamplerBuilder* builder) {
return new Sampler(builder);
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
auto module = new ShaderModule(builder);

View File

@ -109,7 +109,6 @@ namespace backend { namespace null {
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureBase* CreateTexture(TextureBuilder* builder) override;
@ -121,6 +120,8 @@ namespace backend { namespace null {
std::vector<std::unique_ptr<PendingOperation>> AcquirePendingOperations();
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
std::vector<std::unique_ptr<PendingOperation>> mPendingOperations;
};

View File

@ -86,8 +86,8 @@ namespace backend { namespace opengl {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSampler(SamplerBuilder* builder) {
return new Sampler(builder);
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
return new ShaderModule(builder);

View File

@ -97,13 +97,15 @@ namespace backend { namespace opengl {
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureBase* CreateTexture(TextureBuilder* builder) override;
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
void TickImpl() override;
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
};
class BindGroup : public BindGroupBase {

View File

@ -14,6 +14,7 @@
#include "backend/opengl/SamplerGL.h"
#include "backend/opengl/OpenGLBackend.h"
#include "common/Assert.h"
namespace backend { namespace opengl {
@ -70,14 +71,15 @@ namespace backend { namespace opengl {
} // namespace
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
Sampler::Sampler(Device* device, const nxt::SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) {
glGenSamplers(1, &mHandle);
glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(descriptor->magFilter));
glSamplerParameteri(mHandle, GL_TEXTURE_MIN_FILTER,
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()));
MinFilterMode(descriptor->minFilter, descriptor->mipmapFilter));
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_R, WrapMode(descriptor->addressModeW));
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_S, WrapMode(descriptor->addressModeU));
glSamplerParameteri(mHandle, GL_TEXTURE_WRAP_T, WrapMode(descriptor->addressModeV));
}
GLuint Sampler::GetHandle() const {

View File

@ -25,7 +25,7 @@ namespace backend { namespace opengl {
class Sampler : public SamplerBase {
public:
Sampler(SamplerBuilder* builder);
Sampler(Device* device, const nxt::SamplerDescriptor* descriptor);
GLuint GetHandle() const;

View File

@ -56,18 +56,18 @@ namespace backend { namespace vulkan {
}
} // anonymous namespace
Sampler::Sampler(SamplerBuilder* builder)
: SamplerBase(builder), mDevice(ToBackend(builder->GetDevice())) {
Sampler::Sampler(Device* device, const nxt::SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor), mDevice(device) {
VkSamplerCreateInfo createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
createInfo.pNext = nullptr;
createInfo.flags = 0;
createInfo.magFilter = VulkanSamplerFilter(builder->GetMagFilter());
createInfo.minFilter = VulkanSamplerFilter(builder->GetMinFilter());
createInfo.mipmapMode = VulkanMipMapMode(builder->GetMipMapFilter());
createInfo.addressModeU = VulkanSamplerAddressMode(builder->GetAddressModeU());
createInfo.addressModeV = VulkanSamplerAddressMode(builder->GetAddressModeV());
createInfo.addressModeW = VulkanSamplerAddressMode(builder->GetAddressModeW());
createInfo.magFilter = VulkanSamplerFilter(descriptor->magFilter);
createInfo.minFilter = VulkanSamplerFilter(descriptor->minFilter);
createInfo.mipmapMode = VulkanMipMapMode(descriptor->mipmapFilter);
createInfo.addressModeU = VulkanSamplerAddressMode(descriptor->addressModeU);
createInfo.addressModeV = VulkanSamplerAddressMode(descriptor->addressModeV);
createInfo.addressModeW = VulkanSamplerAddressMode(descriptor->addressModeW);
createInfo.mipLodBias = 0.0f;
createInfo.anisotropyEnable = VK_FALSE;
createInfo.maxAnisotropy = 1.0f;
@ -78,7 +78,7 @@ namespace backend { namespace vulkan {
createInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
createInfo.unnormalizedCoordinates = VK_FALSE;
if (mDevice->fn.CreateSampler(mDevice->GetVkDevice(), &createInfo, nullptr, &mHandle) !=
if (device->fn.CreateSampler(device->GetVkDevice(), &createInfo, nullptr, &mHandle) !=
VK_SUCCESS) {
ASSERT(false);
}

View File

@ -24,7 +24,7 @@ namespace backend { namespace vulkan {
class Sampler : public SamplerBase {
public:
Sampler(SamplerBuilder* builder);
Sampler(Device* device, const nxt::SamplerDescriptor* descriptor);
~Sampler();
VkSampler GetHandle() const;

View File

@ -253,8 +253,8 @@ namespace backend { namespace vulkan {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
SamplerBase* Device::CreateSampler(SamplerBuilder* builder) {
return new Sampler(builder);
SamplerBase* Device::CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
return new ShaderModule(builder);

View File

@ -125,7 +125,6 @@ namespace backend { namespace vulkan {
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureBase* CreateTexture(TextureBuilder* builder) override;
@ -134,6 +133,8 @@ namespace backend { namespace vulkan {
void TickImpl() override;
private:
SamplerBase* CreateSamplerImpl(const nxt::SamplerDescriptor* descriptor) override;
bool CreateInstance(VulkanGlobalKnobs* usedKnobs,
const std::vector<const char*>& requiredExtensions);
bool CreateDevice(VulkanDeviceKnobs* usedKnobs);

View File

@ -110,10 +110,17 @@ protected:
}
void TestAddressModes(AddressModeTestCase u, AddressModeTestCase v, AddressModeTestCase w) {
nxt::Sampler sampler = device.CreateSamplerBuilder()
.SetAddressMode(u.mMode, v.mMode, w.mMode)
.GetResult();
nxt::Sampler sampler;
{
nxt::SamplerDescriptor descriptor;
descriptor.minFilter = nxt::FilterMode::Nearest;
descriptor.magFilter = nxt::FilterMode::Nearest;
descriptor.mipmapFilter = nxt::FilterMode::Nearest;
descriptor.addressModeU = u.mMode;
descriptor.addressModeV = v.mMode;
descriptor.addressModeW = w.mMode;
sampler = device.CreateSampler(&descriptor);
}
auto bindGroup = device.CreateBindGroupBuilder()
.SetLayout(mBindGroupLayout)