Put the reference to DeviceBase in a new ObjectBase

ObjectBase will contain data that all WebGPU objects have such as a
pointer back to the device, a refcount (via inheriting from RefCounted),
a name, an error status etc.

BUG=dawn:24

Change-Id: I919e1a6d4a68811ceb6e503b2a793815c92f2528
Reviewed-on: https://dawn-review.googlesource.com/c/1620
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2018-10-15 12:54:30 +00:00 committed by Commit Bot service account
parent 6329e5ad47
commit 9e4518b57e
42 changed files with 191 additions and 195 deletions

View File

@ -364,6 +364,8 @@ source_set("libdawn_native_sources") {
"src/dawn_native/Forward.h", "src/dawn_native/Forward.h",
"src/dawn_native/InputState.cpp", "src/dawn_native/InputState.cpp",
"src/dawn_native/InputState.h", "src/dawn_native/InputState.h",
"src/dawn_native/ObjectBase.cpp",
"src/dawn_native/ObjectBase.h",
"src/dawn_native/PassResourceUsage.h", "src/dawn_native/PassResourceUsage.h",
"src/dawn_native/PerStage.cpp", "src/dawn_native/PerStage.cpp",
"src/dawn_native/PerStage.h", "src/dawn_native/PerStage.h",

View File

@ -26,7 +26,8 @@ namespace dawn_native {
// BindGroup // BindGroup
BindGroupBase::BindGroupBase(BindGroupBuilder* builder) BindGroupBase::BindGroupBase(BindGroupBuilder* builder)
: mLayout(std::move(builder->mLayout)), : ObjectBase(builder->GetDevice()),
mLayout(std::move(builder->mLayout)),
mBindings(std::move(builder->mBindings)) { mBindings(std::move(builder->mBindings)) {
} }
@ -56,10 +57,6 @@ namespace dawn_native {
return reinterpret_cast<TextureViewBase*>(mBindings[binding].Get()); return reinterpret_cast<TextureViewBase*>(mBindings[binding].Get());
} }
DeviceBase* BindGroupBase::GetDevice() const {
return mLayout->GetDevice();
}
// BindGroupBuilder // BindGroupBuilder
enum BindGroupSetProperties { enum BindGroupSetProperties {
@ -81,7 +78,7 @@ namespace dawn_native {
return nullptr; return nullptr;
} }
return mDevice->CreateBindGroup(this); return GetDevice()->CreateBindGroup(this);
} }
void BindGroupBuilder::SetLayout(BindGroupLayoutBase* layout) { void BindGroupBuilder::SetLayout(BindGroupLayoutBase* layout) {
@ -130,7 +127,7 @@ namespace dawn_native {
} }
} }
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const*>(bufferViews)); SetBindingsBase(start, count, reinterpret_cast<ObjectBase* const*>(bufferViews));
} }
void BindGroupBuilder::SetSamplers(uint32_t start, void BindGroupBuilder::SetSamplers(uint32_t start,
@ -148,7 +145,7 @@ namespace dawn_native {
} }
} }
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const*>(samplers)); SetBindingsBase(start, count, reinterpret_cast<ObjectBase* const*>(samplers));
} }
void BindGroupBuilder::SetTextureViews(uint32_t start, void BindGroupBuilder::SetTextureViews(uint32_t start,
@ -171,12 +168,12 @@ namespace dawn_native {
} }
} }
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const*>(textureViews)); SetBindingsBase(start, count, reinterpret_cast<ObjectBase* const*>(textureViews));
} }
void BindGroupBuilder::SetBindingsBase(uint32_t start, void BindGroupBuilder::SetBindingsBase(uint32_t start,
uint32_t count, uint32_t count,
RefCounted* const* objects) { ObjectBase* const* objects) {
for (size_t i = start, j = 0; i < start + count; ++i, ++j) { for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
mSetMask.set(i); mSetMask.set(i);
mBindings[i] = objects[j]; mBindings[i] = objects[j];

View File

@ -19,7 +19,7 @@
#include "dawn_native/BindGroupLayout.h" #include "dawn_native/BindGroupLayout.h"
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -28,7 +28,7 @@
namespace dawn_native { namespace dawn_native {
class BindGroupBase : public RefCounted { class BindGroupBase : public ObjectBase {
public: public:
BindGroupBase(BindGroupBuilder* builder); BindGroupBase(BindGroupBuilder* builder);
@ -37,11 +37,9 @@ namespace dawn_native {
SamplerBase* GetBindingAsSampler(size_t binding); SamplerBase* GetBindingAsSampler(size_t binding);
TextureViewBase* GetBindingAsTextureView(size_t binding); TextureViewBase* GetBindingAsTextureView(size_t binding);
DeviceBase* GetDevice() const;
private: private:
Ref<BindGroupLayoutBase> mLayout; Ref<BindGroupLayoutBase> mLayout;
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings; std::array<Ref<ObjectBase>, kMaxBindingsPerGroup> mBindings;
}; };
class BindGroupBuilder : public Builder<BindGroupBase> { class BindGroupBuilder : public Builder<BindGroupBase> {
@ -59,14 +57,14 @@ namespace dawn_native {
friend class BindGroupBase; friend class BindGroupBase;
BindGroupBase* GetResultImpl() override; BindGroupBase* GetResultImpl() override;
void SetBindingsBase(uint32_t start, uint32_t count, RefCounted* const* objects); void SetBindingsBase(uint32_t start, uint32_t count, ObjectBase* const* objects);
bool SetBindingsValidationBase(uint32_t start, uint32_t count); bool SetBindingsValidationBase(uint32_t start, uint32_t count);
std::bitset<kMaxBindingsPerGroup> mSetMask; std::bitset<kMaxBindingsPerGroup> mSetMask;
int mPropertiesSet = 0; int mPropertiesSet = 0;
Ref<BindGroupLayoutBase> mLayout; Ref<BindGroupLayoutBase> mLayout;
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings; std::array<Ref<ObjectBase>, kMaxBindingsPerGroup> mBindings;
}; };
} // namespace dawn_native } // namespace dawn_native

View File

@ -79,7 +79,7 @@ namespace dawn_native {
BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device,
const BindGroupLayoutDescriptor* descriptor, const BindGroupLayoutDescriptor* descriptor,
bool blueprint) bool blueprint)
: mDevice(device), mIsBlueprint(blueprint) { : ObjectBase(device), mIsBlueprint(blueprint) {
for (uint32_t i = 0; i < descriptor->numBindings; ++i) { for (uint32_t i = 0; i < descriptor->numBindings; ++i) {
auto& binding = descriptor->bindings[i]; auto& binding = descriptor->bindings[i];
@ -95,7 +95,7 @@ namespace dawn_native {
BindGroupLayoutBase::~BindGroupLayoutBase() { BindGroupLayoutBase::~BindGroupLayoutBase() {
// Do not uncache the actual cached object if we are a blueprint // Do not uncache the actual cached object if we are a blueprint
if (!mIsBlueprint) { if (!mIsBlueprint) {
mDevice->UncacheBindGroupLayout(this); GetDevice()->UncacheBindGroupLayout(this);
} }
} }
@ -103,10 +103,6 @@ namespace dawn_native {
return mBindingInfo; return mBindingInfo;
} }
DeviceBase* BindGroupLayoutBase::GetDevice() const {
return mDevice;
}
// BindGroupLayoutCacheFuncs // BindGroupLayoutCacheFuncs
size_t BindGroupLayoutCacheFuncs::operator()(const BindGroupLayoutBase* bgl) const { size_t BindGroupLayoutCacheFuncs::operator()(const BindGroupLayoutBase* bgl) const {

View File

@ -18,7 +18,7 @@
#include "common/Constants.h" #include "common/Constants.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -30,7 +30,7 @@ namespace dawn_native {
MaybeError ValidateBindGroupLayoutDescriptor(DeviceBase*, MaybeError ValidateBindGroupLayoutDescriptor(DeviceBase*,
const BindGroupLayoutDescriptor* descriptor); const BindGroupLayoutDescriptor* descriptor);
class BindGroupLayoutBase : public RefCounted { class BindGroupLayoutBase : public ObjectBase {
public: public:
BindGroupLayoutBase(DeviceBase* device, BindGroupLayoutBase(DeviceBase* device,
const BindGroupLayoutDescriptor* descriptor, const BindGroupLayoutDescriptor* descriptor,
@ -44,10 +44,7 @@ namespace dawn_native {
}; };
const LayoutBindingInfo& GetBindingInfo() const; const LayoutBindingInfo& GetBindingInfo() const;
DeviceBase* GetDevice() const;
private: private:
DeviceBase* mDevice;
LayoutBindingInfo mBindingInfo; LayoutBindingInfo mBindingInfo;
bool mIsBlueprint = false; bool mIsBlueprint = false;
}; };

View File

@ -20,7 +20,8 @@ namespace dawn_native {
// BlendStateBase // BlendStateBase
BlendStateBase::BlendStateBase(BlendStateBuilder* builder) : mBlendInfo(builder->mBlendInfo) { BlendStateBase::BlendStateBase(BlendStateBuilder* builder)
: ObjectBase(builder->GetDevice()), mBlendInfo(builder->mBlendInfo) {
} }
const BlendStateBase::BlendInfo& BlendStateBase::GetBlendInfo() const { const BlendStateBase::BlendInfo& BlendStateBase::GetBlendInfo() const {
@ -40,7 +41,7 @@ namespace dawn_native {
} }
BlendStateBase* BlendStateBuilder::GetResultImpl() { BlendStateBase* BlendStateBuilder::GetResultImpl() {
return mDevice->CreateBlendState(this); return GetDevice()->CreateBlendState(this);
} }
void BlendStateBuilder::SetBlendEnabled(bool blendEnabled) { void BlendStateBuilder::SetBlendEnabled(bool blendEnabled) {

View File

@ -17,13 +17,13 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
namespace dawn_native { namespace dawn_native {
class BlendStateBase : public RefCounted { class BlendStateBase : public ObjectBase {
public: public:
BlendStateBase(BlendStateBuilder* builder); BlendStateBase(BlendStateBuilder* builder);

View File

@ -50,7 +50,7 @@ namespace dawn_native {
// Buffer // Buffer
BufferBase::BufferBase(DeviceBase* device, const BufferDescriptor* descriptor) BufferBase::BufferBase(DeviceBase* device, const BufferDescriptor* descriptor)
: mDevice(device), mSize(descriptor->size), mUsage(descriptor->usage) { : ObjectBase(device), mSize(descriptor->size), mUsage(descriptor->usage) {
} }
BufferBase::~BufferBase() { BufferBase::~BufferBase() {
@ -61,11 +61,7 @@ namespace dawn_native {
} }
BufferViewBuilder* BufferBase::CreateBufferViewBuilder() { BufferViewBuilder* BufferBase::CreateBufferViewBuilder() {
return new BufferViewBuilder(mDevice, this); return new BufferViewBuilder(GetDevice(), this);
}
DeviceBase* BufferBase::GetDevice() const {
return mDevice;
} }
uint32_t BufferBase::GetSize() const { uint32_t BufferBase::GetSize() const {
@ -103,7 +99,7 @@ namespace dawn_native {
} }
void BufferBase::SetSubData(uint32_t start, uint32_t count, const uint8_t* data) { void BufferBase::SetSubData(uint32_t start, uint32_t count, const uint8_t* data) {
if (mDevice->ConsumedError(ValidateSetSubData(start, count))) { if (GetDevice()->ConsumedError(ValidateSetSubData(start, count))) {
return; return;
} }
@ -114,7 +110,7 @@ namespace dawn_native {
uint32_t size, uint32_t size,
dawnBufferMapReadCallback callback, dawnBufferMapReadCallback callback,
dawnCallbackUserdata userdata) { dawnCallbackUserdata userdata) {
if (mDevice->ConsumedError(ValidateMap(start, size, dawn::BufferUsageBit::MapRead))) { if (GetDevice()->ConsumedError(ValidateMap(start, size, dawn::BufferUsageBit::MapRead))) {
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata); callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
return; return;
} }
@ -134,7 +130,7 @@ namespace dawn_native {
uint32_t size, uint32_t size,
dawnBufferMapWriteCallback callback, dawnBufferMapWriteCallback callback,
dawnCallbackUserdata userdata) { dawnCallbackUserdata userdata) {
if (mDevice->ConsumedError(ValidateMap(start, size, dawn::BufferUsageBit::MapWrite))) { if (GetDevice()->ConsumedError(ValidateMap(start, size, dawn::BufferUsageBit::MapWrite))) {
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata); callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
return; return;
} }
@ -151,7 +147,7 @@ namespace dawn_native {
} }
void BufferBase::Unmap() { void BufferBase::Unmap() {
if (mDevice->ConsumedError(ValidateUnmap())) { if (GetDevice()->ConsumedError(ValidateUnmap())) {
return; return;
} }
@ -209,7 +205,10 @@ namespace dawn_native {
// BufferViewBase // BufferViewBase
BufferViewBase::BufferViewBase(BufferViewBuilder* builder) BufferViewBase::BufferViewBase(BufferViewBuilder* builder)
: mBuffer(std::move(builder->mBuffer)), mSize(builder->mSize), mOffset(builder->mOffset) { : ObjectBase(builder->GetDevice()),
mBuffer(std::move(builder->mBuffer)),
mSize(builder->mSize),
mOffset(builder->mOffset) {
} }
BufferBase* BufferViewBase::GetBuffer() { BufferBase* BufferViewBase::GetBuffer() {
@ -241,7 +240,7 @@ namespace dawn_native {
return nullptr; return nullptr;
} }
return mDevice->CreateBufferView(this); return GetDevice()->CreateBufferView(this);
} }
void BufferViewBuilder::SetExtent(uint32_t offset, uint32_t size) { void BufferViewBuilder::SetExtent(uint32_t offset, uint32_t size) {

View File

@ -18,7 +18,7 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -34,7 +34,7 @@ namespace dawn_native {
dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferDst |
dawn::BufferUsageBit::Storage; dawn::BufferUsageBit::Storage;
class BufferBase : public RefCounted { class BufferBase : public ObjectBase {
public: public:
BufferBase(DeviceBase* device, const BufferDescriptor* descriptor); BufferBase(DeviceBase* device, const BufferDescriptor* descriptor);
~BufferBase(); ~BufferBase();
@ -42,8 +42,6 @@ namespace dawn_native {
uint32_t GetSize() const; uint32_t GetSize() const;
dawn::BufferUsageBit GetUsage() const; dawn::BufferUsageBit GetUsage() const;
DeviceBase* GetDevice() const;
// Dawn API // Dawn API
BufferViewBuilder* CreateBufferViewBuilder(); BufferViewBuilder* CreateBufferViewBuilder();
void SetSubData(uint32_t start, uint32_t count, const uint8_t* data); void SetSubData(uint32_t start, uint32_t count, const uint8_t* data);
@ -75,7 +73,6 @@ namespace dawn_native {
dawn::BufferUsageBit requiredUsage) const; dawn::BufferUsageBit requiredUsage) const;
MaybeError ValidateUnmap() const; MaybeError ValidateUnmap() const;
DeviceBase* mDevice;
uint32_t mSize; uint32_t mSize;
dawn::BufferUsageBit mUsage = dawn::BufferUsageBit::None; dawn::BufferUsageBit mUsage = dawn::BufferUsageBit::None;
@ -87,7 +84,7 @@ namespace dawn_native {
bool mIsMapped = false; bool mIsMapped = false;
}; };
class BufferViewBase : public RefCounted { class BufferViewBase : public ObjectBase {
public: public:
BufferViewBase(BufferViewBuilder* builder); BufferViewBase(BufferViewBuilder* builder);

View File

@ -23,10 +23,6 @@ namespace dawn_native {
return !mIsConsumed && !mGotStatus; return !mIsConsumed && !mGotStatus;
} }
DeviceBase* BuilderBase::GetDevice() {
return mDevice;
}
void BuilderBase::HandleError(const char* message) { void BuilderBase::HandleError(const char* message) {
SetStatus(dawn::BuilderErrorStatus::Error, message); SetStatus(dawn::BuilderErrorStatus::Error, message);
} }
@ -39,7 +35,7 @@ namespace dawn_native {
mUserdata2 = userdata2; mUserdata2 = userdata2;
} }
BuilderBase::BuilderBase(DeviceBase* device) : mDevice(device) { BuilderBase::BuilderBase(DeviceBase* device) : ObjectBase(device) {
} }
BuilderBase::~BuilderBase() { BuilderBase::~BuilderBase() {
@ -59,7 +55,7 @@ namespace dawn_native {
mStoredMessage = message; mStoredMessage = message;
} }
bool BuilderBase::HandleResult(RefCounted* result) { bool BuilderBase::HandleResult(ObjectBase* result) {
// GetResult can only be called once. // GetResult can only be called once.
ASSERT(!mIsConsumed); ASSERT(!mIsConsumed);
mIsConsumed = true; mIsConsumed = true;
@ -80,7 +76,7 @@ namespace dawn_native {
// Unhandled builder errors are promoted to device errors // Unhandled builder errors are promoted to device errors
if (!mCallback) if (!mCallback)
mDevice->HandleError(("Unhandled builder error: " + mStoredMessage).c_str()); GetDevice()->HandleError(("Unhandled builder error: " + mStoredMessage).c_str());
} else { } else {
ASSERT(mStoredStatus == dawn::BuilderErrorStatus::Success); ASSERT(mStoredStatus == dawn::BuilderErrorStatus::Success);
ASSERT(mStoredMessage.empty()); ASSERT(mStoredMessage.empty());

View File

@ -16,7 +16,7 @@
#define DAWNNATIVE_BUILDER_H_ #define DAWNNATIVE_BUILDER_H_
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -35,19 +35,18 @@ namespace dawn_native {
// builder "set" function performance validation inline. Because of this we have to store the // builder "set" function performance validation inline. Because of this we have to store the
// status in the builder and defer calling the callback to GetResult. // status in the builder and defer calling the callback to GetResult.
class BuilderBase : public RefCounted { class BuilderBase : public ObjectBase {
public: public:
// Used by the auto-generated validation to prevent usage of the builder // Used by the auto-generated validation to prevent usage of the builder
// after GetResult or an error. // after GetResult or an error.
bool CanBeUsed() const; bool CanBeUsed() const;
DeviceBase* GetDevice();
// Set the status of the builder to an error. // Set the status of the builder to an error.
void HandleError(const char* message); void HandleError(const char* message);
// Internal API, to be used by builder and BackendProcTable only. // Internal API, to be used by builder and BackendProcTable only.
// Returns true for success cases, and calls the callback with appropriate status. // Returns true for success cases, and calls the callback with appropriate status.
bool HandleResult(RefCounted* result); bool HandleResult(ObjectBase* result);
// Dawn API // Dawn API
void SetErrorCallback(dawn::BuilderErrorCallback callback, void SetErrorCallback(dawn::BuilderErrorCallback callback,
@ -58,7 +57,6 @@ namespace dawn_native {
BuilderBase(DeviceBase* device); BuilderBase(DeviceBase* device);
~BuilderBase(); ~BuilderBase();
DeviceBase* const mDevice;
bool mGotStatus = false; bool mGotStatus = false;
private: private:

View File

@ -351,8 +351,8 @@ list(APPEND DAWN_NATIVE_SOURCES
${DAWN_NATIVE_DIR}/Forward.h ${DAWN_NATIVE_DIR}/Forward.h
${DAWN_NATIVE_DIR}/InputState.cpp ${DAWN_NATIVE_DIR}/InputState.cpp
${DAWN_NATIVE_DIR}/InputState.h ${DAWN_NATIVE_DIR}/InputState.h
${DAWN_NATIVE_DIR}/RenderPipeline.cpp ${DAWN_NATIVE_DIR}/ObjectBase.cpp
${DAWN_NATIVE_DIR}/RenderPipeline.h ${DAWN_NATIVE_DIR}/ObjectBase.h
${DAWN_NATIVE_DIR}/PassResourceUsage.h ${DAWN_NATIVE_DIR}/PassResourceUsage.h
${DAWN_NATIVE_DIR}/PerStage.cpp ${DAWN_NATIVE_DIR}/PerStage.cpp
${DAWN_NATIVE_DIR}/PerStage.h ${DAWN_NATIVE_DIR}/PerStage.h
@ -364,12 +364,14 @@ list(APPEND DAWN_NATIVE_SOURCES
${DAWN_NATIVE_DIR}/ProgrammablePassEncoder.h ${DAWN_NATIVE_DIR}/ProgrammablePassEncoder.h
${DAWN_NATIVE_DIR}/Queue.cpp ${DAWN_NATIVE_DIR}/Queue.cpp
${DAWN_NATIVE_DIR}/Queue.h ${DAWN_NATIVE_DIR}/Queue.h
${DAWN_NATIVE_DIR}/RefCounted.cpp
${DAWN_NATIVE_DIR}/RefCounted.h
${DAWN_NATIVE_DIR}/RenderPassDescriptor.cpp ${DAWN_NATIVE_DIR}/RenderPassDescriptor.cpp
${DAWN_NATIVE_DIR}/RenderPassDescriptor.h ${DAWN_NATIVE_DIR}/RenderPassDescriptor.h
${DAWN_NATIVE_DIR}/RenderPassEncoder.cpp ${DAWN_NATIVE_DIR}/RenderPassEncoder.cpp
${DAWN_NATIVE_DIR}/RenderPassEncoder.h ${DAWN_NATIVE_DIR}/RenderPassEncoder.h
${DAWN_NATIVE_DIR}/RefCounted.cpp ${DAWN_NATIVE_DIR}/RenderPipeline.cpp
${DAWN_NATIVE_DIR}/RefCounted.h ${DAWN_NATIVE_DIR}/RenderPipeline.h
${DAWN_NATIVE_DIR}/Sampler.cpp ${DAWN_NATIVE_DIR}/Sampler.cpp
${DAWN_NATIVE_DIR}/Sampler.h ${DAWN_NATIVE_DIR}/Sampler.h
${DAWN_NATIVE_DIR}/ShaderModule.cpp ${DAWN_NATIVE_DIR}/ShaderModule.cpp

View File

@ -286,11 +286,7 @@ namespace dawn_native {
// CommandBuffer // CommandBuffer
CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder) CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder)
: mDevice(builder->mDevice) { : ObjectBase(builder->GetDevice()) {
}
DeviceBase* CommandBufferBase::GetDevice() {
return mDevice;
} }
// CommandBufferBuilder // CommandBufferBuilder
@ -322,7 +318,7 @@ namespace dawn_native {
mEncodingState = EncodingState::Finished; mEncodingState = EncodingState::Finished;
MoveToIterator(); MoveToIterator();
return mDevice->CreateCommandBuffer(this); return GetDevice()->CreateCommandBuffer(this);
} }
void CommandBufferBuilder::MoveToIterator() { void CommandBufferBuilder::MoveToIterator() {
@ -590,7 +586,7 @@ namespace dawn_native {
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass); mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
mEncodingState = EncodingState::ComputePass; mEncodingState = EncodingState::ComputePass;
return new ComputePassEncoderBase(mDevice, this, &mAllocator); return new ComputePassEncoderBase(GetDevice(), this, &mAllocator);
} }
RenderPassEncoderBase* CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) { RenderPassEncoderBase* CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) {
@ -599,7 +595,7 @@ namespace dawn_native {
cmd->info = info; cmd->info = info;
mEncodingState = EncodingState::RenderPass; mEncodingState = EncodingState::RenderPass;
return new RenderPassEncoderBase(mDevice, this, &mAllocator); return new RenderPassEncoderBase(GetDevice(), this, &mAllocator);
} }
void CommandBufferBuilder::CopyBufferToBuffer(BufferBase* source, void CommandBufferBuilder::CopyBufferToBuffer(BufferBase* source,

View File

@ -20,8 +20,8 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/CommandAllocator.h" #include "dawn_native/CommandAllocator.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/PassResourceUsage.h" #include "dawn_native/PassResourceUsage.h"
#include "dawn_native/RefCounted.h"
#include <memory> #include <memory>
#include <set> #include <set>
@ -39,14 +39,9 @@ namespace dawn_native {
class CommandBufferBuilder; class CommandBufferBuilder;
class CommandBufferBase : public RefCounted { class CommandBufferBase : public ObjectBase {
public: public:
CommandBufferBase(CommandBufferBuilder* builder); CommandBufferBase(CommandBufferBuilder* builder);
DeviceBase* GetDevice();
private:
DeviceBase* mDevice;
}; };
class CommandBufferBuilder : public Builder<CommandBufferBase> { class CommandBufferBuilder : public Builder<CommandBufferBase> {

View File

@ -24,7 +24,7 @@ namespace dawn_native {
MaybeError ValidateComputePipelineDescriptor(DeviceBase* device, MaybeError ValidateComputePipelineDescriptor(DeviceBase* device,
const ComputePipelineDescriptor* descriptor); const ComputePipelineDescriptor* descriptor);
class ComputePipelineBase : public RefCounted, public PipelineBase { class ComputePipelineBase : public PipelineBase {
public: public:
ComputePipelineBase(DeviceBase* device, const ComputePipelineDescriptor* descriptor); ComputePipelineBase(DeviceBase* device, const ComputePipelineDescriptor* descriptor);
}; };

View File

@ -21,7 +21,9 @@ namespace dawn_native {
// DepthStencilStateBase // DepthStencilStateBase
DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder) DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder)
: mDepthInfo(builder->mDepthInfo), mStencilInfo(builder->mStencilInfo) { : ObjectBase(builder->GetDevice()),
mDepthInfo(builder->mDepthInfo),
mStencilInfo(builder->mStencilInfo) {
} }
bool DepthStencilStateBase::StencilTestEnabled() const { bool DepthStencilStateBase::StencilTestEnabled() const {
@ -57,7 +59,7 @@ namespace dawn_native {
} }
DepthStencilStateBase* DepthStencilStateBuilder::GetResultImpl() { DepthStencilStateBase* DepthStencilStateBuilder::GetResultImpl() {
return mDevice->CreateDepthStencilState(this); return GetDevice()->CreateDepthStencilState(this);
} }
void DepthStencilStateBuilder::SetDepthCompareFunction( void DepthStencilStateBuilder::SetDepthCompareFunction(

View File

@ -17,13 +17,13 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
namespace dawn_native { namespace dawn_native {
class DepthStencilStateBase : public RefCounted { class DepthStencilStateBase : public ObjectBase {
public: public:
DepthStencilStateBase(DepthStencilStateBuilder* builder); DepthStencilStateBase(DepthStencilStateBuilder* builder);

View File

@ -17,7 +17,7 @@
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/DawnNative.h" #include "dawn_native/DawnNative.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"

View File

@ -84,7 +84,7 @@ namespace dawn_native {
// InputStateBase // InputStateBase
InputStateBase::InputStateBase(InputStateBuilder* builder) { InputStateBase::InputStateBase(InputStateBuilder* builder) : ObjectBase(builder->GetDevice()) {
mAttributesSetMask = builder->mAttributesSetMask; mAttributesSetMask = builder->mAttributesSetMask;
mAttributeInfos = builder->mAttributeInfos; mAttributeInfos = builder->mAttributeInfos;
mInputsSetMask = builder->mInputsSetMask; mInputsSetMask = builder->mInputsSetMask;
@ -123,7 +123,7 @@ namespace dawn_native {
} }
} }
return mDevice->CreateInputState(this); return GetDevice()->CreateInputState(this);
} }
void InputStateBuilder::SetAttribute(uint32_t shaderLocation, void InputStateBuilder::SetAttribute(uint32_t shaderLocation,

View File

@ -18,7 +18,7 @@
#include "common/Constants.h" #include "common/Constants.h"
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -32,7 +32,7 @@ namespace dawn_native {
size_t VertexFormatComponentSize(dawn::VertexFormat format); size_t VertexFormatComponentSize(dawn::VertexFormat format);
size_t VertexFormatSize(dawn::VertexFormat format); size_t VertexFormatSize(dawn::VertexFormat format);
class InputStateBase : public RefCounted { class InputStateBase : public ObjectBase {
public: public:
InputStateBase(InputStateBuilder* builder); InputStateBase(InputStateBuilder* builder);

View File

@ -0,0 +1,29 @@
// Copyright 2018 The Dawn Authors
//
// 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.
#include "dawn_native/ObjectBase.h"
namespace dawn_native {
ObjectBase::ObjectBase(DeviceBase* device) : mDevice(device) {
}
ObjectBase::~ObjectBase() {
}
DeviceBase* ObjectBase::GetDevice() const {
return mDevice;
}
} // namespace dawn_native

View File

@ -0,0 +1,37 @@
// Copyright 2018 The Dawn Authors
//
// 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.
#ifndef DAWNNATIVE_OBJECTBASE_H_
#define DAWNNATIVE_OBJECTBASE_H_
#include "dawn_native/RefCounted.h"
namespace dawn_native {
class DeviceBase;
class ObjectBase : public RefCounted {
public:
ObjectBase(DeviceBase* device);
virtual ~ObjectBase();
DeviceBase* GetDevice() const;
private:
DeviceBase* mDevice;
};
} // namespace dawn_native
#endif // DAWNNATIVE_OBJECTBASE_H_

View File

@ -27,16 +27,19 @@ namespace dawn_native {
PipelineBase::PipelineBase(DeviceBase* device, PipelineBase::PipelineBase(DeviceBase* device,
PipelineLayoutBase* layout, PipelineLayoutBase* layout,
dawn::ShaderStageBit stages) dawn::ShaderStageBit stages)
: mStageMask(stages), mLayout(layout), mDevice(device) { : ObjectBase(device), mStageMask(stages), mLayout(layout), mDevice(device) {
} }
PipelineBase::PipelineBase(DeviceBase* device, PipelineBuilder* builder) PipelineBase::PipelineBase(DeviceBase* device, PipelineBuilder* builder)
: mStageMask(builder->mStageMask), mLayout(std::move(builder->mLayout)), mDevice(device) { : ObjectBase(device),
mStageMask(builder->mStageMask),
mLayout(std::move(builder->mLayout)),
mDevice(device) {
if (!mLayout) { if (!mLayout) {
PipelineLayoutDescriptor descriptor; PipelineLayoutDescriptor descriptor;
descriptor.numBindGroupLayouts = 0; descriptor.numBindGroupLayouts = 0;
descriptor.bindGroupLayouts = nullptr; descriptor.bindGroupLayouts = nullptr;
mLayout = builder->GetParentBuilder()->GetDevice()->CreatePipelineLayout(&descriptor); mLayout = device->CreatePipelineLayout(&descriptor);
// Remove the external ref objects are created with // Remove the external ref objects are created with
mLayout->Release(); mLayout->Release();
} }

View File

@ -17,9 +17,9 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/PerStage.h" #include "dawn_native/PerStage.h"
#include "dawn_native/PipelineLayout.h" #include "dawn_native/PipelineLayout.h"
#include "dawn_native/RefCounted.h"
#include "dawn_native/ShaderModule.h" #include "dawn_native/ShaderModule.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -37,7 +37,7 @@ namespace dawn_native {
class PipelineBuilder; class PipelineBuilder;
class PipelineBase { class PipelineBase : public ObjectBase {
public: public:
PipelineBase(DeviceBase* device, PipelineLayoutBase* layout, dawn::ShaderStageBit stages); PipelineBase(DeviceBase* device, PipelineLayoutBase* layout, dawn::ShaderStageBit stages);
PipelineBase(DeviceBase* device, PipelineBuilder* builder); PipelineBase(DeviceBase* device, PipelineBuilder* builder);

View File

@ -42,7 +42,7 @@ namespace dawn_native {
PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device,
const PipelineLayoutDescriptor* descriptor) const PipelineLayoutDescriptor* descriptor)
: mDevice(device) { : ObjectBase(device) {
ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups); ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups);
for (uint32_t group = 0; group < descriptor->numBindGroupLayouts; ++group) { for (uint32_t group = 0; group < descriptor->numBindGroupLayouts; ++group) {
mBindGroupLayouts[group] = descriptor->bindGroupLayouts[group]; mBindGroupLayouts[group] = descriptor->bindGroupLayouts[group];
@ -73,8 +73,4 @@ namespace dawn_native {
return kMaxBindGroups + 1; return kMaxBindGroups + 1;
} }
DeviceBase* PipelineLayoutBase::GetDevice() const {
return mDevice;
}
} // namespace dawn_native } // namespace dawn_native

View File

@ -18,7 +18,7 @@
#include "common/Constants.h" #include "common/Constants.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -32,7 +32,7 @@ namespace dawn_native {
using BindGroupLayoutArray = std::array<Ref<BindGroupLayoutBase>, kMaxBindGroups>; using BindGroupLayoutArray = std::array<Ref<BindGroupLayoutBase>, kMaxBindGroups>;
class PipelineLayoutBase : public RefCounted { class PipelineLayoutBase : public ObjectBase {
public: public:
PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor); PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor);
@ -47,10 +47,7 @@ namespace dawn_native {
// [1, kMaxBindGroups + 1] // [1, kMaxBindGroups + 1]
uint32_t GroupsInheritUpTo(const PipelineLayoutBase* other) const; uint32_t GroupsInheritUpTo(const PipelineLayoutBase* other) const;
DeviceBase* GetDevice() const;
protected: protected:
DeviceBase* mDevice;
BindGroupLayoutArray mBindGroupLayouts; BindGroupLayoutArray mBindGroupLayouts;
std::bitset<kMaxBindGroups> mMask; std::bitset<kMaxBindGroups> mMask;
}; };

View File

@ -23,7 +23,7 @@ namespace dawn_native {
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device, ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
CommandBufferBuilder* topLevelBuilder, CommandBufferBuilder* topLevelBuilder,
CommandAllocator* allocator) CommandAllocator* allocator)
: mDevice(device), mTopLevelBuilder(topLevelBuilder), mAllocator(allocator) { : ObjectBase(device), mTopLevelBuilder(topLevelBuilder), mAllocator(allocator) {
} }
void ProgrammablePassEncoder::EndPass() { void ProgrammablePassEncoder::EndPass() {
@ -72,10 +72,6 @@ namespace dawn_native {
memcpy(values, data, count * sizeof(uint32_t)); memcpy(values, data, count * sizeof(uint32_t));
} }
DeviceBase* ProgrammablePassEncoder::GetDevice() const {
return mDevice;
}
MaybeError ProgrammablePassEncoder::ValidateCanRecordCommands() const { MaybeError ProgrammablePassEncoder::ValidateCanRecordCommands() const {
if (mAllocator == nullptr) { if (mAllocator == nullptr) {
return DAWN_VALIDATION_ERROR("Recording in an already ended computePassEncoder"); return DAWN_VALIDATION_ERROR("Recording in an already ended computePassEncoder");

View File

@ -16,7 +16,7 @@
#define DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_ #define DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -26,7 +26,7 @@ namespace dawn_native {
class DeviceBase; class DeviceBase;
// Base class for shared functionality between ComputePassEncoder and RenderPassEncoder. // Base class for shared functionality between ComputePassEncoder and RenderPassEncoder.
class ProgrammablePassEncoder : public RefCounted { class ProgrammablePassEncoder : public ObjectBase {
public: public:
ProgrammablePassEncoder(DeviceBase* device, ProgrammablePassEncoder(DeviceBase* device,
CommandBufferBuilder* topLevelBuilder, CommandBufferBuilder* topLevelBuilder,
@ -40,13 +40,9 @@ namespace dawn_native {
uint32_t count, uint32_t count,
const void* data); const void* data);
DeviceBase* GetDevice() const;
protected: protected:
MaybeError ValidateCanRecordCommands() const; MaybeError ValidateCanRecordCommands() const;
DeviceBase* mDevice;
// The allocator is borrowed from the top level builder. Keep a reference to the builder // The allocator is borrowed from the top level builder. Keep a reference to the builder
// to make sure the allocator isn't freed. // to make sure the allocator isn't freed.
Ref<CommandBufferBuilder> mTopLevelBuilder = nullptr; Ref<CommandBufferBuilder> mTopLevelBuilder = nullptr;

View File

@ -21,15 +21,11 @@ namespace dawn_native {
// QueueBase // QueueBase
QueueBase::QueueBase(DeviceBase* device) : mDevice(device) { QueueBase::QueueBase(DeviceBase* device) : ObjectBase(device) {
}
DeviceBase* QueueBase::GetDevice() {
return mDevice;
} }
void QueueBase::Submit(uint32_t numCommands, CommandBufferBase* const* commands) { void QueueBase::Submit(uint32_t numCommands, CommandBufferBase* const* commands) {
if (mDevice->ConsumedError(ValidateSubmit(numCommands, commands))) { if (GetDevice()->ConsumedError(ValidateSubmit(numCommands, commands))) {
return; return;
} }

View File

@ -18,18 +18,16 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
namespace dawn_native { namespace dawn_native {
class QueueBase : public RefCounted { class QueueBase : public ObjectBase {
public: public:
QueueBase(DeviceBase* device); QueueBase(DeviceBase* device);
DeviceBase* GetDevice();
// Dawn API // Dawn API
void Submit(uint32_t numCommands, CommandBufferBase* const* commands); void Submit(uint32_t numCommands, CommandBufferBase* const* commands);
@ -37,8 +35,6 @@ namespace dawn_native {
virtual void SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) = 0; virtual void SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) = 0;
MaybeError ValidateSubmit(uint32_t numCommands, CommandBufferBase* const* commands); MaybeError ValidateSubmit(uint32_t numCommands, CommandBufferBase* const* commands);
DeviceBase* mDevice;
}; };
} // namespace dawn_native } // namespace dawn_native

View File

@ -24,13 +24,13 @@ namespace dawn_native {
// RenderPassDescriptor // RenderPassDescriptor
RenderPassDescriptorBase::RenderPassDescriptorBase(RenderPassDescriptorBuilder* builder) RenderPassDescriptorBase::RenderPassDescriptorBase(RenderPassDescriptorBuilder* builder)
: mColorAttachmentsSet(builder->mColorAttachmentsSet), : ObjectBase(builder->GetDevice()),
mColorAttachmentsSet(builder->mColorAttachmentsSet),
mColorAttachments(builder->mColorAttachments), mColorAttachments(builder->mColorAttachments),
mDepthStencilAttachmentSet(builder->mDepthStencilAttachmentSet), mDepthStencilAttachmentSet(builder->mDepthStencilAttachmentSet),
mDepthStencilAttachment(builder->mDepthStencilAttachment), mDepthStencilAttachment(builder->mDepthStencilAttachment),
mWidth(builder->mWidth), mWidth(builder->mWidth),
mHeight(builder->mHeight), mHeight(builder->mHeight) {
mDevice(builder->GetDevice()) {
} }
std::bitset<kMaxColorAttachments> RenderPassDescriptorBase::GetColorAttachmentMask() const { std::bitset<kMaxColorAttachments> RenderPassDescriptorBase::GetColorAttachmentMask() const {
@ -78,10 +78,6 @@ namespace dawn_native {
return mHeight; return mHeight;
} }
DeviceBase* RenderPassDescriptorBase::GetDevice() const {
return mDevice;
}
// RenderPassDescriptorBuilder // RenderPassDescriptorBuilder
RenderPassDescriptorBuilder::RenderPassDescriptorBuilder(DeviceBase* device) : Builder(device) { RenderPassDescriptorBuilder::RenderPassDescriptorBuilder(DeviceBase* device) : Builder(device) {
@ -126,7 +122,7 @@ namespace dawn_native {
return nullptr; return nullptr;
} }
return mDevice->CreateRenderPassDescriptor(this); return GetDevice()->CreateRenderPassDescriptor(this);
} }
void RenderPassDescriptorBuilder::SetColorAttachment(uint32_t attachment, void RenderPassDescriptorBuilder::SetColorAttachment(uint32_t attachment,

View File

@ -18,7 +18,7 @@
#include "common/Constants.h" #include "common/Constants.h"
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -45,7 +45,7 @@ namespace dawn_native {
// RenderPassDescriptor contains the list of attachments for a renderpass along with data such // RenderPassDescriptor contains the list of attachments for a renderpass along with data such
// as the load operation and the clear values for the attachments. // as the load operation and the clear values for the attachments.
class RenderPassDescriptorBase : public RefCounted { class RenderPassDescriptorBase : public ObjectBase {
public: public:
RenderPassDescriptorBase(RenderPassDescriptorBuilder* builder); RenderPassDescriptorBase(RenderPassDescriptorBuilder* builder);
@ -61,8 +61,6 @@ namespace dawn_native {
uint32_t GetWidth() const; uint32_t GetWidth() const;
uint32_t GetHeight() const; uint32_t GetHeight() const;
DeviceBase* GetDevice() const;
private: private:
std::bitset<kMaxColorAttachments> mColorAttachmentsSet; std::bitset<kMaxColorAttachments> mColorAttachmentsSet;
std::array<RenderPassColorAttachmentInfo, kMaxColorAttachments> mColorAttachments; std::array<RenderPassColorAttachmentInfo, kMaxColorAttachments> mColorAttachments;
@ -72,8 +70,6 @@ namespace dawn_native {
uint32_t mWidth; uint32_t mWidth;
uint32_t mHeight; uint32_t mHeight;
DeviceBase* mDevice;
}; };
class RenderPassDescriptorBuilder : public Builder<RenderPassDescriptorBase> { class RenderPassDescriptorBuilder : public Builder<RenderPassDescriptorBase> {

View File

@ -27,7 +27,7 @@ namespace dawn_native {
// RenderPipelineBase // RenderPipelineBase
RenderPipelineBase::RenderPipelineBase(RenderPipelineBuilder* builder) RenderPipelineBase::RenderPipelineBase(RenderPipelineBuilder* builder)
: PipelineBase(builder->mDevice, builder), : PipelineBase(builder->GetDevice(), builder),
mDepthStencilState(std::move(builder->mDepthStencilState)), mDepthStencilState(std::move(builder->mDepthStencilState)),
mIndexFormat(builder->mIndexFormat), mIndexFormat(builder->mIndexFormat),
mInputState(std::move(builder->mInputState)), mInputState(std::move(builder->mInputState)),
@ -138,17 +138,18 @@ namespace dawn_native {
} }
RenderPipelineBase* RenderPipelineBuilder::GetResultImpl() { RenderPipelineBase* RenderPipelineBuilder::GetResultImpl() {
DeviceBase* device = GetDevice();
// TODO(cwallez@chromium.org): the layout should be required, and put the default objects in // TODO(cwallez@chromium.org): the layout should be required, and put the default objects in
// the device // the device
if (!mInputState) { if (!mInputState) {
auto builder = mDevice->CreateInputStateBuilder(); auto builder = device->CreateInputStateBuilder();
mInputState = builder->GetResult(); mInputState = builder->GetResult();
// Remove the external ref objects are created with // Remove the external ref objects are created with
mInputState->Release(); mInputState->Release();
builder->Release(); builder->Release();
} }
if (!mDepthStencilState) { if (!mDepthStencilState) {
auto builder = mDevice->CreateDepthStencilStateBuilder(); auto builder = device->CreateDepthStencilStateBuilder();
mDepthStencilState = builder->GetResult(); mDepthStencilState = builder->GetResult();
// Remove the external ref objects are created with // Remove the external ref objects are created with
mDepthStencilState->Release(); mDepthStencilState->Release();
@ -163,12 +164,12 @@ namespace dawn_native {
// Assign all color attachments without a blend state the default state // Assign all color attachments without a blend state the default state
// TODO(enga@google.com): Put the default objects in the device // TODO(enga@google.com): Put the default objects in the device
for (uint32_t attachmentSlot : IterateBitSet(mColorAttachmentsSet & ~mBlendStatesSet)) { for (uint32_t attachmentSlot : IterateBitSet(mColorAttachmentsSet & ~mBlendStatesSet)) {
mBlendStates[attachmentSlot] = mDevice->CreateBlendStateBuilder()->GetResult(); mBlendStates[attachmentSlot] = device->CreateBlendStateBuilder()->GetResult();
// Remove the external ref objects are created with // Remove the external ref objects are created with
mBlendStates[attachmentSlot]->Release(); mBlendStates[attachmentSlot]->Release();
} }
return mDevice->CreateRenderPipeline(this); return device->CreateRenderPipeline(this);
} }
void RenderPipelineBuilder::SetColorAttachmentFormat(uint32_t attachmentSlot, void RenderPipelineBuilder::SetColorAttachmentFormat(uint32_t attachmentSlot,

View File

@ -27,7 +27,7 @@
namespace dawn_native { namespace dawn_native {
class RenderPipelineBase : public RefCounted, public PipelineBase { class RenderPipelineBase : public PipelineBase {
public: public:
RenderPipelineBase(RenderPipelineBuilder* builder); RenderPipelineBase(RenderPipelineBuilder* builder);

View File

@ -34,7 +34,7 @@ namespace dawn_native {
// SamplerBase // SamplerBase
SamplerBase::SamplerBase(DeviceBase*, const SamplerDescriptor*) { SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor*) : ObjectBase(device) {
} }
} // namespace dawn_native } // namespace dawn_native

View File

@ -16,7 +16,7 @@
#define DAWNNATIVE_SAMPLER_H_ #define DAWNNATIVE_SAMPLER_H_
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -26,7 +26,7 @@ namespace dawn_native {
MaybeError ValidateSamplerDescriptor(DeviceBase* device, const SamplerDescriptor* descriptor); MaybeError ValidateSamplerDescriptor(DeviceBase* device, const SamplerDescriptor* descriptor);
class SamplerBase : public RefCounted { class SamplerBase : public ObjectBase {
public: public:
SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor); SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor);
}; };

View File

@ -66,14 +66,11 @@ namespace dawn_native {
// ShaderModuleBase // ShaderModuleBase
ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor*) ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor*)
: mDevice(device) { : ObjectBase(device) {
}
DeviceBase* ShaderModuleBase::GetDevice() const {
return mDevice;
} }
void ShaderModuleBase::ExtractSpirvInfo(const spirv_cross::Compiler& compiler) { void ShaderModuleBase::ExtractSpirvInfo(const spirv_cross::Compiler& compiler) {
DeviceBase* device = GetDevice();
// TODO(cwallez@chromium.org): make errors here builder-level // TODO(cwallez@chromium.org): make errors here builder-level
// currently errors here do not prevent the shadermodule from being used // currently errors here do not prevent the shadermodule from being used
const auto& resources = compiler.get_shader_resources(); const auto& resources = compiler.get_shader_resources();
@ -132,7 +129,7 @@ namespace dawn_native {
} }
if (offset + size > kMaxPushConstants) { if (offset + size > kMaxPushConstants) {
mDevice->HandleError("Push constant block too big in the SPIRV"); device->HandleError("Push constant block too big in the SPIRV");
return; return;
} }
@ -157,7 +154,7 @@ namespace dawn_native {
uint32_t set = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet); uint32_t set = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet);
if (binding >= kMaxBindingsPerGroup || set >= kMaxBindGroups) { if (binding >= kMaxBindingsPerGroup || set >= kMaxBindGroups) {
mDevice->HandleError("Binding over limits in the SPIRV"); GetDevice()->HandleError("Binding over limits in the SPIRV");
continue; continue;
} }
@ -184,7 +181,7 @@ namespace dawn_native {
uint32_t location = compiler.get_decoration(attrib.id, spv::DecorationLocation); uint32_t location = compiler.get_decoration(attrib.id, spv::DecorationLocation);
if (location >= kMaxVertexAttributes) { if (location >= kMaxVertexAttributes) {
mDevice->HandleError("Attribute location over limits in the SPIRV"); device->HandleError("Attribute location over limits in the SPIRV");
return; return;
} }
@ -195,7 +192,7 @@ namespace dawn_native {
// all the location 0, causing a compile error. // all the location 0, causing a compile error.
for (const auto& attrib : resources.stage_outputs) { for (const auto& attrib : resources.stage_outputs) {
if (!compiler.get_decoration_bitset(attrib.id).get(spv::DecorationLocation)) { if (!compiler.get_decoration_bitset(attrib.id).get(spv::DecorationLocation)) {
mDevice->HandleError("Need location qualifier on vertex output"); device->HandleError("Need location qualifier on vertex output");
return; return;
} }
} }
@ -206,7 +203,7 @@ namespace dawn_native {
// all the location 0, causing a compile error. // all the location 0, causing a compile error.
for (const auto& attrib : resources.stage_inputs) { for (const auto& attrib : resources.stage_inputs) {
if (!compiler.get_decoration_bitset(attrib.id).get(spv::DecorationLocation)) { if (!compiler.get_decoration_bitset(attrib.id).get(spv::DecorationLocation)) {
mDevice->HandleError("Need location qualifier on fragment input"); device->HandleError("Need location qualifier on fragment input");
return; return;
} }
} }

View File

@ -19,7 +19,7 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -36,12 +36,10 @@ namespace dawn_native {
MaybeError ValidateShaderModuleDescriptor(DeviceBase* device, MaybeError ValidateShaderModuleDescriptor(DeviceBase* device,
const ShaderModuleDescriptor* descriptor); const ShaderModuleDescriptor* descriptor);
class ShaderModuleBase : public RefCounted { class ShaderModuleBase : public ObjectBase {
public: public:
ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor); ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor);
DeviceBase* GetDevice() const;
void ExtractSpirvInfo(const spirv_cross::Compiler& compiler); void ExtractSpirvInfo(const spirv_cross::Compiler& compiler);
struct PushConstantInfo { struct PushConstantInfo {
@ -72,7 +70,6 @@ namespace dawn_native {
private: private:
bool IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout); bool IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout);
DeviceBase* mDevice;
PushConstantInfo mPushConstants = {}; PushConstantInfo mPushConstants = {};
ModuleBindingInfo mBindingInfo; ModuleBindingInfo mBindingInfo;
std::bitset<kMaxVertexAttributes> mUsedVertexAttributes; std::bitset<kMaxVertexAttributes> mUsedVertexAttributes;

View File

@ -22,7 +22,7 @@ namespace dawn_native {
// SwapChain // SwapChain
SwapChainBase::SwapChainBase(SwapChainBuilder* builder) SwapChainBase::SwapChainBase(SwapChainBuilder* builder)
: mDevice(builder->mDevice), mImplementation(builder->mImplementation) { : ObjectBase(builder->GetDevice()), mImplementation(builder->mImplementation) {
} }
SwapChainBase::~SwapChainBase() { SwapChainBase::~SwapChainBase() {
@ -30,16 +30,12 @@ namespace dawn_native {
im.Destroy(im.userData); im.Destroy(im.userData);
} }
DeviceBase* SwapChainBase::GetDevice() {
return mDevice;
}
void SwapChainBase::Configure(dawn::TextureFormat format, void SwapChainBase::Configure(dawn::TextureFormat format,
dawn::TextureUsageBit allowedUsage, dawn::TextureUsageBit allowedUsage,
uint32_t width, uint32_t width,
uint32_t height) { uint32_t height) {
if (width == 0 || height == 0) { if (width == 0 || height == 0) {
mDevice->HandleError("Swap chain cannot be configured to zero size"); GetDevice()->HandleError("Swap chain cannot be configured to zero size");
return; return;
} }
allowedUsage |= dawn::TextureUsageBit::Present; allowedUsage |= dawn::TextureUsageBit::Present;
@ -55,7 +51,7 @@ namespace dawn_native {
TextureBase* SwapChainBase::GetNextTexture() { TextureBase* SwapChainBase::GetNextTexture() {
if (mWidth == 0) { if (mWidth == 0) {
// If width is 0, it implies swap chain has never been configured // If width is 0, it implies swap chain has never been configured
mDevice->HandleError("Swap chain needs to be configured before GetNextTexture"); GetDevice()->HandleError("Swap chain needs to be configured before GetNextTexture");
return nullptr; return nullptr;
} }
@ -76,7 +72,7 @@ namespace dawn_native {
void SwapChainBase::Present(TextureBase* texture) { void SwapChainBase::Present(TextureBase* texture) {
if (texture != mLastNextTexture) { if (texture != mLastNextTexture) {
mDevice->HandleError("Tried to present something other than the last NextTexture"); GetDevice()->HandleError("Tried to present something other than the last NextTexture");
return; return;
} }
@ -99,7 +95,7 @@ namespace dawn_native {
HandleError("Implementation not set"); HandleError("Implementation not set");
return nullptr; return nullptr;
} }
return mDevice->CreateSwapChain(this); return GetDevice()->CreateSwapChain(this);
} }
void SwapChainBuilder::SetImplementation(uint64_t implementation) { void SwapChainBuilder::SetImplementation(uint64_t implementation) {

View File

@ -17,20 +17,18 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn/dawn_wsi.h" #include "dawn/dawn_wsi.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
namespace dawn_native { namespace dawn_native {
class SwapChainBase : public RefCounted { class SwapChainBase : public ObjectBase {
public: public:
SwapChainBase(SwapChainBuilder* builder); SwapChainBase(SwapChainBuilder* builder);
~SwapChainBase(); ~SwapChainBase();
DeviceBase* GetDevice();
// Dawn API // Dawn API
void Configure(dawn::TextureFormat format, void Configure(dawn::TextureFormat format,
dawn::TextureUsageBit allowedUsage, dawn::TextureUsageBit allowedUsage,
@ -45,7 +43,6 @@ namespace dawn_native {
virtual void OnBeforePresent(TextureBase* texture) = 0; virtual void OnBeforePresent(TextureBase* texture) = 0;
private: private:
DeviceBase* mDevice = nullptr;
dawnSwapChainImplementation mImplementation = {}; dawnSwapChainImplementation mImplementation = {};
dawn::TextureFormat mFormat = {}; dawn::TextureFormat mFormat = {};
dawn::TextureUsageBit mAllowedUsage; dawn::TextureUsageBit mAllowedUsage;

View File

@ -180,7 +180,7 @@ namespace dawn_native {
// TextureBase // TextureBase
TextureBase::TextureBase(DeviceBase* device, const TextureDescriptor* descriptor) TextureBase::TextureBase(DeviceBase* device, const TextureDescriptor* descriptor)
: mDevice(device), : ObjectBase(device),
mDimension(descriptor->dimension), mDimension(descriptor->dimension),
mFormat(descriptor->format), mFormat(descriptor->format),
mSize(descriptor->size), mSize(descriptor->size),
@ -189,10 +189,6 @@ namespace dawn_native {
mUsage(descriptor->usage) { mUsage(descriptor->usage) {
} }
DeviceBase* TextureBase::GetDevice() const {
return mDevice;
}
dawn::TextureDimension TextureBase::GetDimension() const { dawn::TextureDimension TextureBase::GetDimension() const {
return mDimension; return mDimension;
} }
@ -216,16 +212,17 @@ namespace dawn_native {
// TODO(jiawei.shao@intel.com): remove Device->CreateDefaultTextureView in all back-ends // TODO(jiawei.shao@intel.com): remove Device->CreateDefaultTextureView in all back-ends
// and implement this function by creating a TextureViewDescriptor based on the texture // and implement this function by creating a TextureViewDescriptor based on the texture
// and calling CreateTextureView(&descriptor) instead. // and calling CreateTextureView(&descriptor) instead.
return mDevice->CreateDefaultTextureView(this); return GetDevice()->CreateDefaultTextureView(this);
} }
TextureViewBase* TextureBase::CreateTextureView(const TextureViewDescriptor* descriptor) { TextureViewBase* TextureBase::CreateTextureView(const TextureViewDescriptor* descriptor) {
return mDevice->CreateTextureView(this, descriptor); return GetDevice()->CreateTextureView(this, descriptor);
} }
// TextureViewBase // TextureViewBase
TextureViewBase::TextureViewBase(TextureBase* texture) : mTexture(texture) { TextureViewBase::TextureViewBase(TextureBase* texture)
: ObjectBase(texture->GetDevice()), mTexture(texture) {
} }
const TextureBase* TextureViewBase::GetTexture() const { const TextureBase* TextureViewBase::GetTexture() const {

View File

@ -18,7 +18,7 @@
#include "dawn_native/Builder.h" #include "dawn_native/Builder.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/RefCounted.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -41,7 +41,7 @@ namespace dawn_native {
dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Storage | dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Storage |
dawn::TextureUsageBit::OutputAttachment; dawn::TextureUsageBit::OutputAttachment;
class TextureBase : public RefCounted { class TextureBase : public ObjectBase {
public: public:
TextureBase(DeviceBase* device, const TextureDescriptor* descriptor); TextureBase(DeviceBase* device, const TextureDescriptor* descriptor);
@ -51,15 +51,12 @@ namespace dawn_native {
uint32_t GetArrayLayers() const; uint32_t GetArrayLayers() const;
uint32_t GetNumMipLevels() const; uint32_t GetNumMipLevels() const;
dawn::TextureUsageBit GetUsage() const; dawn::TextureUsageBit GetUsage() const;
DeviceBase* GetDevice() const;
// Dawn API // Dawn API
TextureViewBase* CreateDefaultTextureView(); TextureViewBase* CreateDefaultTextureView();
TextureViewBase* CreateTextureView(const TextureViewDescriptor* descriptor); TextureViewBase* CreateTextureView(const TextureViewDescriptor* descriptor);
private: private:
DeviceBase* mDevice;
dawn::TextureDimension mDimension; dawn::TextureDimension mDimension;
dawn::TextureFormat mFormat; dawn::TextureFormat mFormat;
Extent3D mSize; Extent3D mSize;
@ -68,7 +65,7 @@ namespace dawn_native {
dawn::TextureUsageBit mUsage = dawn::TextureUsageBit::None; dawn::TextureUsageBit mUsage = dawn::TextureUsageBit::None;
}; };
class TextureViewBase : public RefCounted { class TextureViewBase : public ObjectBase {
public: public:
TextureViewBase(TextureBase* texture); TextureViewBase(TextureBase* texture);