Add Device::CreateQueue() instead of the builder

We are changing all object creation to use descriptors but there is no
creation argument to pass for queue, so instead Device::CreateQueue
takes no argument.
This commit is contained in:
Corentin Wallez 2018-06-14 20:26:27 -04:00 committed by Corentin Wallez
parent 40e72d79ca
commit b703def640
35 changed files with 65 additions and 115 deletions

View File

@ -46,7 +46,7 @@ static std::vector<ShaderData> shaderData;
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -26,12 +26,7 @@ nxtTextureFormat swapChainFormat;
void init() {
device = CreateCppNXTDevice().Release();
{
nxtQueueBuilder builder = nxtDeviceCreateQueueBuilder(device);
queue = nxtQueueBuilderGetResult(builder);
nxtQueueBuilderRelease(builder);
}
queue = nxtDeviceCreateQueue(device);
{
nxtSwapChainBuilder builder = nxtDeviceCreateSwapChainBuilder(device);

View File

@ -286,7 +286,7 @@ nxt::CommandBuffer createCommandBuffer(const nxt::RenderPassDescriptor& renderPa
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -32,7 +32,7 @@ nxt::BindGroup computeBindGroup;
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -113,7 +113,7 @@ struct CameraData {
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -46,7 +46,7 @@ void initBuffers() {
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -49,7 +49,7 @@ void initBuffers() {
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -79,7 +79,7 @@ void initTextures() {
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -30,7 +30,7 @@ struct {uint32_t a; float b;} s;
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -40,7 +40,7 @@ void initBuffers() {
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -150,7 +150,7 @@ void initPipelinePost() {
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -458,7 +458,7 @@ namespace {
void init() {
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480);

View File

@ -612,8 +612,8 @@
"returns": "pipeline layout builder"
},
{
"name": "create queue builder",
"returns": "queue builder"
"name": "create queue",
"returns": "queue"
},
{
"name": "create sampler",
@ -808,15 +808,6 @@
}
]
},
"queue builder": {
"category": "object",
"methods": [
{
"name": "get result",
"returns": "queue"
}
]
},
"render pass descriptor builder": {
"category": "object",
"methods": [

View File

@ -122,8 +122,14 @@ namespace backend {
PipelineLayoutBuilder* DeviceBase::CreatePipelineLayoutBuilder() {
return new PipelineLayoutBuilder(this);
}
QueueBuilder* DeviceBase::CreateQueueBuilder() {
return new QueueBuilder(this);
QueueBase* DeviceBase::CreateQueue() {
ResultOrError<QueueBase*> maybeQueue = CreateQueueImpl();
if (maybeQueue.IsError()) {
// TODO(cwallez@chromium.org): Implement the WebGPU error handling mechanism.
delete maybeQueue.AcquireError();
return nullptr;
}
return maybeQueue.AcquireSuccess();
}
RenderPassDescriptorBuilder* DeviceBase::CreateRenderPassDescriptorBuilder() {
return new RenderPassDescriptorBuilder(this);
@ -142,7 +148,7 @@ namespace backend {
ResultOrError<SamplerBase*> maybeSampler = CreateSamplerImpl(descriptor);
if (maybeSampler.IsError()) {
// TODO(cwallez@chromium.org): Implement the WebGPU error handling mechanism.
delete validation.AcquireError();
delete maybeSampler.AcquireError();
return nullptr;
}
return maybeSampler.AcquireSuccess();

View File

@ -46,7 +46,6 @@ namespace backend {
DepthStencilStateBuilder* builder) = 0;
virtual InputStateBase* CreateInputState(InputStateBuilder* builder) = 0;
virtual PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) = 0;
virtual QueueBase* CreateQueue(QueueBuilder* builder) = 0;
virtual RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) = 0;
virtual RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) = 0;
@ -85,7 +84,7 @@ namespace backend {
DepthStencilStateBuilder* CreateDepthStencilStateBuilder();
InputStateBuilder* CreateInputStateBuilder();
PipelineLayoutBuilder* CreatePipelineLayoutBuilder();
QueueBuilder* CreateQueueBuilder();
QueueBase* CreateQueue();
RenderPassDescriptorBuilder* CreateRenderPassDescriptorBuilder();
RenderPipelineBuilder* CreateRenderPipelineBuilder();
SamplerBase* CreateSampler(const nxt::SamplerDescriptor* descriptor);
@ -99,6 +98,7 @@ namespace backend {
void Release();
private:
virtual ResultOrError<QueueBase*> CreateQueueImpl() = 0;
virtual ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) = 0;

View File

@ -40,7 +40,6 @@ namespace backend {
class PipelineLayoutBase;
class PipelineLayoutBuilder;
class QueueBase;
class QueueBuilder;
class RenderPassDescriptorBase;
class RenderPassDescriptorBuilder;
class RenderPipelineBase;

View File

@ -21,7 +21,7 @@ namespace backend {
// QueueBase
QueueBase::QueueBase(QueueBuilder* builder) : mDevice(builder->mDevice) {
QueueBase::QueueBase(DeviceBase* device) : mDevice(device) {
}
DeviceBase* QueueBase::GetDevice() {
@ -32,13 +32,4 @@ namespace backend {
return command->ValidateResourceUsagesImmediate();
}
// QueueBuilder
QueueBuilder::QueueBuilder(DeviceBase* device) : Builder(device) {
}
QueueBase* QueueBuilder::GetResultImpl() {
return mDevice->CreateQueue(this);
}
} // namespace backend

View File

@ -25,7 +25,7 @@ namespace backend {
class QueueBase : public RefCounted {
public:
QueueBase(QueueBuilder* builder);
QueueBase(DeviceBase* device);
DeviceBase* GetDevice();
@ -48,15 +48,6 @@ namespace backend {
DeviceBase* mDevice;
};
class QueueBuilder : public Builder<QueueBase> {
public:
QueueBuilder(DeviceBase* device);
private:
friend class QueueBase;
QueueBase* GetResultImpl() override;
};
} // namespace backend
#endif // BACKEND_QUEUE_H_

View File

@ -288,8 +288,8 @@ namespace backend { namespace d3d12 {
PipelineLayoutBase* Device::CreatePipelineLayout(PipelineLayoutBuilder* builder) {
return new PipelineLayout(this, builder);
}
QueueBase* Device::CreateQueue(QueueBuilder* builder) {
return new Queue(this, builder);
ResultOrError<QueueBase*> Device::CreateQueueImpl() {
return new Queue(this);
}
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) {

View File

@ -96,7 +96,6 @@ namespace backend { namespace d3d12 {
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
QueueBase* CreateQueue(QueueBuilder* builder) override;
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
@ -128,6 +127,7 @@ namespace backend { namespace d3d12 {
void ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists);
private:
ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;

View File

@ -19,21 +19,23 @@
namespace backend { namespace d3d12 {
Queue::Queue(Device* device, QueueBuilder* builder) : QueueBase(builder), mDevice(device) {
Queue::Queue(Device* device) : QueueBase(device) {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {
mDevice->Tick();
Device* device = ToBackend(GetDevice());
mDevice->OpenCommandList(&mCommandList);
device->Tick();
device->OpenCommandList(&mCommandList);
for (uint32_t i = 0; i < numCommands; ++i) {
commands[i]->FillCommands(mCommandList);
}
ASSERT_SUCCESS(mCommandList->Close());
mDevice->ExecuteCommandLists({mCommandList.Get()});
device->ExecuteCommandLists({mCommandList.Get()});
mDevice->NextSerial();
device->NextSerial();
}
}} // namespace backend::d3d12

View File

@ -26,14 +26,12 @@ namespace backend { namespace d3d12 {
class Queue : public QueueBase {
public:
Queue(Device* device, QueueBuilder* builder);
Queue(Device* device);
// NXT API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
private:
Device* mDevice;
ComPtr<ID3D12GraphicsCommandList> mCommandList;
};

View File

@ -97,7 +97,6 @@ namespace backend { namespace metal {
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
QueueBase* CreateQueue(QueueBuilder* builder) override;
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
@ -118,6 +117,7 @@ namespace backend { namespace metal {
ResourceUploader* GetResourceUploader() const;
private:
ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
@ -145,16 +145,10 @@ namespace backend { namespace metal {
class Queue : public QueueBase {
public:
Queue(QueueBuilder* builder);
~Queue();
id<MTLCommandQueue> GetMTLCommandQueue();
Queue(Device* device);
// NXT API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
private:
id<MTLCommandQueue> mCommandQueue = nil;
};
class RenderPassDescriptor : public RenderPassDescriptorBase {

View File

@ -107,9 +107,6 @@ namespace backend { namespace metal {
PipelineLayoutBase* Device::CreatePipelineLayout(PipelineLayoutBuilder* builder) {
return new PipelineLayout(builder);
}
QueueBase* Device::CreateQueue(QueueBuilder* builder) {
return new Queue(builder);
}
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) {
return new RenderPassDescriptor(builder);
@ -117,6 +114,9 @@ namespace backend { namespace metal {
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder);
}
ResultOrError<QueueBase*> Device::CreateQueueImpl() {
return new Queue(this);
}
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
@ -203,18 +203,7 @@ namespace backend { namespace metal {
// Queue
Queue::Queue(QueueBuilder* builder) : QueueBase(builder) {
Device* device = ToBackend(builder->GetDevice());
mCommandQueue = [device->GetMTLDevice() newCommandQueue];
}
Queue::~Queue() {
[mCommandQueue release];
mCommandQueue = nil;
}
id<MTLCommandQueue> Queue::GetMTLCommandQueue() {
return mCommandQueue;
Queue::Queue(Device* device) : QueueBase(device) {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {

View File

@ -66,8 +66,8 @@ namespace backend { namespace null {
PipelineLayoutBase* Device::CreatePipelineLayout(PipelineLayoutBuilder* builder) {
return new PipelineLayout(builder);
}
QueueBase* Device::CreateQueue(QueueBuilder* builder) {
return new Queue(builder);
ResultOrError<QueueBase*> Device::CreateQueueImpl() {
return new Queue(this);
}
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) {
@ -205,7 +205,7 @@ namespace backend { namespace null {
// Queue
Queue::Queue(QueueBuilder* builder) : QueueBase(builder) {
Queue::Queue(Device* device) : QueueBase(device) {
}
Queue::~Queue() {

View File

@ -105,7 +105,6 @@ namespace backend { namespace null {
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
QueueBase* CreateQueue(QueueBuilder* builder) override;
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
@ -120,6 +119,7 @@ namespace backend { namespace null {
std::vector<std::unique_ptr<PendingOperation>> AcquirePendingOperations();
private:
ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
@ -159,7 +159,7 @@ namespace backend { namespace null {
class Queue : public QueueBase {
public:
Queue(QueueBuilder* builder);
Queue(Device* device);
~Queue();
// NXT API

View File

@ -76,8 +76,8 @@ namespace backend { namespace opengl {
PipelineLayoutBase* Device::CreatePipelineLayout(PipelineLayoutBuilder* builder) {
return new PipelineLayout(builder);
}
QueueBase* Device::CreateQueue(QueueBuilder* builder) {
return new Queue(builder);
ResultOrError<QueueBase*> Device::CreateQueueImpl() {
return new Queue(this);
}
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) {
@ -119,7 +119,7 @@ namespace backend { namespace opengl {
// Queue
Queue::Queue(QueueBuilder* builder) : QueueBase(builder) {
Queue::Queue(Device* device) : QueueBase(device) {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {

View File

@ -93,7 +93,6 @@ namespace backend { namespace opengl {
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
QueueBase* CreateQueue(QueueBuilder* builder) override;
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
@ -105,6 +104,7 @@ namespace backend { namespace opengl {
void TickImpl() override;
private:
ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
};
@ -121,7 +121,7 @@ namespace backend { namespace opengl {
class Queue : public QueueBase {
public:
Queue(QueueBuilder* builder);
Queue(Device* device);
// NXT API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);

View File

@ -243,8 +243,8 @@ namespace backend { namespace vulkan {
PipelineLayoutBase* Device::CreatePipelineLayout(PipelineLayoutBuilder* builder) {
return new PipelineLayout(builder);
}
QueueBase* Device::CreateQueue(QueueBuilder* builder) {
return new Queue(builder);
ResultOrError<QueueBase*> Device::CreateQueueImpl() {
return new Queue(this);
}
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) {
@ -677,7 +677,7 @@ namespace backend { namespace vulkan {
// Queue
Queue::Queue(QueueBuilder* builder) : QueueBase(builder) {
Queue::Queue(Device* device) : QueueBase(device) {
}
Queue::~Queue() {

View File

@ -121,7 +121,6 @@ namespace backend { namespace vulkan {
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
QueueBase* CreateQueue(QueueBuilder* builder) override;
RenderPassDescriptorBase* CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
@ -133,6 +132,7 @@ namespace backend { namespace vulkan {
void TickImpl() override;
private:
ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override;
@ -203,7 +203,7 @@ namespace backend { namespace vulkan {
class Queue : public QueueBase {
public:
Queue(QueueBuilder* builder);
Queue(Device* device);
~Queue();
// NXT API

View File

@ -167,7 +167,7 @@ void NXTTest::SetUp() {
// deferred expectations.
nxtSetProcs(&procs);
device = nxt::Device::Acquire(cDevice);
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
// The swapchain isn't used by tests but is useful when debugging with graphics debuggers that
// capture at frame boundaries.

View File

@ -367,15 +367,9 @@ TEST_F(WireTests, ObjectsAsPointerArgument) {
}
// Create queue
nxtQueueBuilder queueBuilder = nxtDeviceCreateQueueBuilder(device);
nxtQueue queue = nxtQueueBuilderGetResult(queueBuilder);
nxtQueueBuilder apiQueueBuilder = api.GetNewQueueBuilder();
EXPECT_CALL(api, DeviceCreateQueueBuilder(apiDevice))
.WillOnce(Return(apiQueueBuilder));
nxtQueue queue = nxtDeviceCreateQueue(device);
nxtQueue apiQueue = api.GetNewQueue();
EXPECT_CALL(api, QueueBuilderGetResult(apiQueueBuilder))
EXPECT_CALL(api, DeviceCreateQueue(apiDevice))
.WillOnce(Return(apiQueue));
// Submit command buffer and check we got a call with both API-side command buffers

View File

@ -72,7 +72,7 @@ class BufferValidationTest : public ValidationTest {
mockBufferMapReadCallback = new MockBufferMapReadCallback;
mockBufferMapWriteCallback = new MockBufferMapWriteCallback;
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
}
void TearDown() override {

View File

@ -40,7 +40,7 @@ class PushConstantTest : public ValidationTest {
private:
void SetUp() override {
ValidationTest::SetUp();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
}
};

View File

@ -25,7 +25,7 @@ class UsageValidationTest : public ValidationTest {
private:
void SetUp() override {
ValidationTest::SetUp();
queue = device.CreateQueueBuilder().GetResult();
queue = device.CreateQueue();
}
};