Implement CreateDefaultTextureView by CreateTextureView

This patch removes CreateDefaultTextureView in all the back-ends of
class Device and implements this function by CreateTextureView using
a TextureViewDescriptor created from the original texture.

Note that this patch only refactors the original implementation of
creating default texture. The support of creating texture views from
a texture view descriptor will be added in the next several patches.

BUG=dawn:16

Change-Id: Iadfc1e17e1cf23a4c1fa8ff44b1fb1a765d21e3f
Reviewed-on: https://dawn-review.googlesource.com/c/1840
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2018-10-18 06:00:09 +00:00 committed by Commit Bot service account
parent 79aee9c56d
commit aef480bcfe
21 changed files with 49 additions and 45 deletions

View File

@ -57,7 +57,6 @@ namespace dawn_native {
RenderPassDescriptorBuilder* builder) = 0; RenderPassDescriptorBuilder* builder) = 0;
virtual RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) = 0; virtual RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) = 0;
virtual SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) = 0; virtual SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) = 0;
virtual TextureViewBase* CreateDefaultTextureView(TextureBase* texture) = 0;
virtual void TickImpl() = 0; virtual void TickImpl() = 0;

View File

@ -79,6 +79,30 @@ namespace dawn_native {
return {}; return {};
} }
TextureViewDescriptor MakeDefaultTextureViewDescriptor(const TextureBase* texture) {
TextureViewDescriptor descriptor;
descriptor.format = texture->GetFormat();
descriptor.baseArrayLayer = 0;
descriptor.layerCount = texture->GetArrayLayers();
descriptor.baseMipLevel = 0;
descriptor.levelCount = texture->GetNumMipLevels();
// TODO(jiawei.shao@intel.com): support all texture dimensions.
switch (texture->GetDimension()) {
case dawn::TextureDimension::e2D:
if (texture->GetArrayLayers() == 1u) {
descriptor.dimension = dawn::TextureViewDimension::e2D;
} else {
descriptor.dimension = dawn::TextureViewDimension::e2DArray;
}
break;
default:
UNREACHABLE();
}
return descriptor;
}
} // anonymous namespace } // anonymous namespace
MaybeError ValidateTextureDescriptor(DeviceBase*, const TextureDescriptor* descriptor) { MaybeError ValidateTextureDescriptor(DeviceBase*, const TextureDescriptor* descriptor) {
@ -209,10 +233,8 @@ namespace dawn_native {
} }
TextureViewBase* TextureBase::CreateDefaultTextureView() { TextureViewBase* TextureBase::CreateDefaultTextureView() {
// TODO(jiawei.shao@intel.com): remove Device->CreateDefaultTextureView in all back-ends TextureViewDescriptor descriptor = MakeDefaultTextureViewDescriptor(this);
// and implement this function by creating a TextureViewDescriptor based on the texture return GetDevice()->CreateTextureView(this, &descriptor);
// and calling CreateTextureView(&descriptor) instead.
return GetDevice()->CreateDefaultTextureView(this);
} }
TextureViewBase* TextureBase::CreateTextureView(const TextureViewDescriptor* descriptor) { TextureViewBase* TextureBase::CreateTextureView(const TextureViewDescriptor* descriptor) {
@ -221,7 +243,7 @@ namespace dawn_native {
// TextureViewBase // TextureViewBase
TextureViewBase::TextureViewBase(TextureBase* texture) TextureViewBase::TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor)
: ObjectBase(texture->GetDevice()), mTexture(texture) { : ObjectBase(texture->GetDevice()), mTexture(texture) {
} }

View File

@ -67,7 +67,7 @@ namespace dawn_native {
class TextureViewBase : public ObjectBase { class TextureViewBase : public ObjectBase {
public: public:
TextureViewBase(TextureBase* texture); TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor);
const TextureBase* GetTexture() const; const TextureBase* GetTexture() const;
TextureBase* GetTexture(); TextureBase* GetTexture();

View File

@ -334,14 +334,10 @@ namespace dawn_native { namespace d3d12 {
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return new Texture(this, descriptor); return new Texture(this, descriptor);
} }
TextureViewBase* Device::CreateDefaultTextureView(TextureBase* texture) {
return new TextureView(texture);
}
// TODO(jiawei.shao@intel.com): implement creating texture view with TextureViewDescriptor
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl( ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
TextureBase* texture, TextureBase* texture,
const TextureViewDescriptor* descriptor) { const TextureViewDescriptor* descriptor) {
return DAWN_UNIMPLEMENTED_ERROR("Creating texture view with descriptor is unimplemented."); return new TextureView(texture, descriptor);
} }
void Device::CollectPCIInfo() { void Device::CollectPCIInfo() {

View File

@ -51,7 +51,6 @@ namespace dawn_native { namespace d3d12 {
RenderPassDescriptorBuilder* builder) override; RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override; RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override; SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureViewBase* CreateDefaultTextureView(TextureBase* texture) override;
void TickImpl() override; void TickImpl() override;

View File

@ -187,7 +187,9 @@ namespace dawn_native { namespace d3d12 {
mLastUsage = usage; mLastUsage = usage;
} }
TextureView::TextureView(TextureBase* texture) : TextureViewBase(texture) { // TODO(jiawei.shao@intel.com): create texture view by TextureViewDescriptor
TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
: TextureViewBase(texture, descriptor) {
mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat()); mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat());
mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
switch (GetTexture()->GetDimension()) { switch (GetTexture()->GetDimension()) {

View File

@ -47,7 +47,7 @@ namespace dawn_native { namespace d3d12 {
class TextureView : public TextureViewBase { class TextureView : public TextureViewBase {
public: public:
TextureView(TextureBase* builder); TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
const D3D12_SHADER_RESOURCE_VIEW_DESC& GetSRVDescriptor() const; const D3D12_SHADER_RESOURCE_VIEW_DESC& GetSRVDescriptor() const;
D3D12_RENDER_TARGET_VIEW_DESC GetRTVDescriptor(); D3D12_RENDER_TARGET_VIEW_DESC GetRTVDescriptor();

View File

@ -47,7 +47,6 @@ namespace dawn_native { namespace metal {
RenderPassDescriptorBuilder* builder) override; RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override; RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override; SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureViewBase* CreateDefaultTextureView(TextureBase* texture) override;
void TickImpl() override; void TickImpl() override;

View File

@ -132,14 +132,10 @@ namespace dawn_native { namespace metal {
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return new Texture(this, descriptor); return new Texture(this, descriptor);
} }
TextureViewBase* Device::CreateDefaultTextureView(TextureBase* texture) {
return new TextureView(texture);
}
// TODO(jiawei.shao@intel.com): implement creating texture view with TextureViewDescriptor
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl( ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
TextureBase* texture, TextureBase* texture,
const TextureViewDescriptor* descriptor) { const TextureViewDescriptor* descriptor) {
return DAWN_UNIMPLEMENTED_ERROR("Creating texture view with descriptor is unimplemented."); return new TextureView(texture, descriptor);
} }
void Device::TickImpl() { void Device::TickImpl() {

View File

@ -39,7 +39,7 @@ namespace dawn_native { namespace metal {
class TextureView : public TextureViewBase { class TextureView : public TextureViewBase {
public: public:
TextureView(TextureBase* texture); TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
}; };
}} // namespace dawn_native::metal }} // namespace dawn_native::metal

View File

@ -101,7 +101,9 @@ namespace dawn_native { namespace metal {
return mMtlTexture; return mMtlTexture;
} }
TextureView::TextureView(TextureBase* texture) : TextureViewBase(texture) { // TODO(jiawei.shao@intel.com): create texture view by texture view descriptor
TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
: TextureViewBase(texture, descriptor) {
} }
}} // namespace dawn_native::metal }} // namespace dawn_native::metal

View File

@ -95,14 +95,10 @@ namespace dawn_native { namespace null {
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return new Texture(this, descriptor); return new Texture(this, descriptor);
} }
TextureViewBase* Device::CreateDefaultTextureView(TextureBase* texture) {
return new TextureView(texture);
}
// TODO(jiawei.shao@intel.com): implement creating texture view by TextureViewDescriptor
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl( ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
TextureBase* texture, TextureBase* texture,
const TextureViewDescriptor* descriptor) { const TextureViewDescriptor* descriptor) {
return new TextureView(texture); return new TextureView(texture, descriptor);
} }
void Device::InitFakePCIInfo() { void Device::InitFakePCIInfo() {

View File

@ -105,7 +105,6 @@ namespace dawn_native { namespace null {
RenderPassDescriptorBuilder* builder) override; RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override; RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override; SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureViewBase* CreateDefaultTextureView(TextureBase* texture) override;
void TickImpl() override; void TickImpl() override;

View File

@ -106,14 +106,10 @@ namespace dawn_native { namespace opengl {
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return new Texture(this, descriptor); return new Texture(this, descriptor);
} }
TextureViewBase* Device::CreateDefaultTextureView(TextureBase* texture) {
return new TextureView(texture);
}
// TODO(jiawei.shao@intel.com): implement creating texture view with TextureViewDescriptor
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl( ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
TextureBase* texture, TextureBase* texture,
const TextureViewDescriptor* descriptor) { const TextureViewDescriptor* descriptor) {
return DAWN_UNIMPLEMENTED_ERROR("Creating texture view with descriptor is unimplemented."); return new TextureView(texture, descriptor);
} }
void Device::TickImpl() { void Device::TickImpl() {

View File

@ -43,7 +43,6 @@ namespace dawn_native { namespace opengl {
RenderPassDescriptorBuilder* builder) override; RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override; RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override; SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureViewBase* CreateDefaultTextureView(TextureBase* texture) override;
void TickImpl() override; void TickImpl() override;

View File

@ -129,7 +129,9 @@ namespace dawn_native { namespace opengl {
// TextureView // TextureView
TextureView::TextureView(TextureBase* texture) : TextureViewBase(texture) { // TODO(jiawei.shao@intel.com): create texture view by TextureViewDescriptor
TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
: TextureViewBase(texture, descriptor) {
} }
}} // namespace dawn_native::opengl }} // namespace dawn_native::opengl

View File

@ -46,7 +46,7 @@ namespace dawn_native { namespace opengl {
class TextureView : public TextureViewBase { class TextureView : public TextureViewBase {
public: public:
TextureView(TextureBase* texture); TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
}; };
}} // namespace dawn_native::opengl }} // namespace dawn_native::opengl

View File

@ -270,15 +270,11 @@ namespace dawn_native { namespace vulkan {
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return new Texture(this, descriptor); return new Texture(this, descriptor);
} }
TextureViewBase* Device::CreateDefaultTextureView(TextureBase* texture) {
return new TextureView(texture);
}
// TODO(jiawei.shao@intel.com): implement creating texture view with TextureViewDescriptor
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl( ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
TextureBase* texture, TextureBase* texture,
const TextureViewDescriptor* descriptor) { const TextureViewDescriptor* descriptor) {
return DAWN_UNIMPLEMENTED_ERROR("Creating texture view with descriptor is unimplemented."); return new TextureView(texture, descriptor);
} }
void Device::TickImpl() { void Device::TickImpl() {

View File

@ -74,7 +74,6 @@ namespace dawn_native { namespace vulkan {
RenderPassDescriptorBuilder* builder) override; RenderPassDescriptorBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override; RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override; SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureViewBase* CreateDefaultTextureView(TextureBase* texture) override;
void TickImpl() override; void TickImpl() override;

View File

@ -346,7 +346,9 @@ namespace dawn_native { namespace vulkan {
mLastUsage = usage; mLastUsage = usage;
} }
TextureView::TextureView(TextureBase* texture) : TextureViewBase(texture) { // TODO(jiawei.shao@intel.com): create texture view by TextureViewDescriptor
TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
: TextureViewBase(texture, descriptor) {
Device* device = ToBackend(texture->GetDevice()); Device* device = ToBackend(texture->GetDevice());
VkImageViewCreateInfo createInfo; VkImageViewCreateInfo createInfo;

View File

@ -50,7 +50,7 @@ namespace dawn_native { namespace vulkan {
class TextureView : public TextureViewBase { class TextureView : public TextureViewBase {
public: public:
TextureView(TextureBase* texture); TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
~TextureView(); ~TextureView();
VkImageView GetHandle() const; VkImageView GetHandle() const;