mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-13 10:51:35 +00:00
Descriptorize Texture
This patch introduces texture descriptor for texture creation instead of texture builders. This patch also adds "arrayLayer" to texture descriptor and removes mDevice in TextureD3D12.
This commit is contained in:
parent
75559bf1be
commit
425428f97b
54
dawn.json
54
dawn.json
@ -604,8 +604,11 @@
|
|||||||
"returns": "swap chain builder"
|
"returns": "swap chain builder"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "create texture builder",
|
"name": "create texture",
|
||||||
"returns": "texture builder"
|
"returns": "texture",
|
||||||
|
"args": [
|
||||||
|
{"name": "descriptor", "type": "texture descriptor", "annotation": "const*"}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "tick"
|
"name": "tick"
|
||||||
@ -996,45 +999,18 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"texture builder": {
|
"texture descriptor": {
|
||||||
"category": "object",
|
"category": "structure",
|
||||||
"methods": [
|
"extensible": true,
|
||||||
{
|
"members": [
|
||||||
"name": "get result",
|
{"name": "usage", "type": "texture usage bit"},
|
||||||
"returns": "texture"
|
{"name": "dimension", "type": "texture dimension"},
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set dimension",
|
|
||||||
"args": [
|
|
||||||
{"name": "dimension", "type": "texture dimension"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set extent",
|
|
||||||
"args": [
|
|
||||||
{"name": "width", "type": "uint32_t"},
|
{"name": "width", "type": "uint32_t"},
|
||||||
{"name": "height", "type": "uint32_t"},
|
{"name": "height", "type": "uint32_t"},
|
||||||
{"name": "depth", "type": "uint32_t"}
|
{"name": "depth", "type": "uint32_t"},
|
||||||
]
|
{"name": "arrayLayer", "type": "uint32_t"},
|
||||||
},
|
{"name": "format", "type": "texture format"},
|
||||||
{
|
{"name": "mipLevel", "type": "uint32_t"}
|
||||||
"name": "set format",
|
|
||||||
"args": [
|
|
||||||
{"name": "format", "type": "texture format"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set mip levels",
|
|
||||||
"args": [
|
|
||||||
{"name": "num mip levels", "type": "uint32_t"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set allowed usage",
|
|
||||||
"args": [
|
|
||||||
{"name": "usage", "type": "texture usage bit"}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"texture dimension": {
|
"texture dimension": {
|
||||||
|
@ -48,13 +48,16 @@ void initBuffers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initTextures() {
|
void initTextures() {
|
||||||
texture = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(1024, 1024, 1)
|
descriptor.width = 1024;
|
||||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
descriptor.height = 1024;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled;
|
||||||
|
texture = device.CreateTexture(&descriptor);
|
||||||
|
|
||||||
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
|
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
|
||||||
sampler = device.CreateSampler(&samplerDesc);
|
sampler = device.CreateSampler(&samplerDesc);
|
||||||
|
@ -136,13 +136,16 @@ dawn::SwapChain GetSwapChain(const dawn::Device &device) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device) {
|
dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device) {
|
||||||
auto depthStencilTexture = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(640, 480, 1)
|
descriptor.width = 640;
|
||||||
.SetFormat(dawn::TextureFormat::D32FloatS8Uint)
|
descriptor.height = 480;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = dawn::TextureFormat::D32FloatS8Uint;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||||
|
auto depthStencilTexture = device.CreateTexture(&descriptor);
|
||||||
return depthStencilTexture.CreateTextureViewBuilder()
|
return depthStencilTexture.CreateTextureViewBuilder()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
}
|
}
|
||||||
|
@ -382,13 +382,16 @@ namespace {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto oTexture = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(iImage.width, iImage.height, 1)
|
descriptor.width = iImage.width;
|
||||||
.SetFormat(format)
|
descriptor.height = iImage.height;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = format;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled;
|
||||||
|
auto oTexture = device.CreateTexture(&descriptor);
|
||||||
// TODO: release this texture
|
// TODO: release this texture
|
||||||
|
|
||||||
const uint8_t* origData = iImage.image.data();
|
const uint8_t* origData = iImage.image.data();
|
||||||
|
@ -178,8 +178,13 @@ namespace dawn_native {
|
|||||||
SwapChainBuilder* DeviceBase::CreateSwapChainBuilder() {
|
SwapChainBuilder* DeviceBase::CreateSwapChainBuilder() {
|
||||||
return new SwapChainBuilder(this);
|
return new SwapChainBuilder(this);
|
||||||
}
|
}
|
||||||
TextureBuilder* DeviceBase::CreateTextureBuilder() {
|
TextureBase* DeviceBase::CreateTexture(const TextureDescriptor* descriptor) {
|
||||||
return new TextureBuilder(this);
|
TextureBase* result = nullptr;
|
||||||
|
|
||||||
|
if (ConsumedError(CreateTextureInternal(&result, descriptor))) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other Device API methods
|
// Other Device API methods
|
||||||
@ -245,6 +250,13 @@ namespace dawn_native {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaybeError DeviceBase::CreateTextureInternal(TextureBase** result,
|
||||||
|
const TextureDescriptor* descriptor) {
|
||||||
|
DAWN_TRY(ValidateTextureDescriptor(this, descriptor));
|
||||||
|
DAWN_TRY_ASSIGN(*result, CreateTextureImpl(descriptor));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
// Other implementation details
|
// Other implementation details
|
||||||
|
|
||||||
void DeviceBase::ConsumeError(ErrorData* error) {
|
void DeviceBase::ConsumeError(ErrorData* error) {
|
||||||
|
@ -55,7 +55,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 TextureBase* CreateTexture(TextureBuilder* builder) = 0;
|
|
||||||
virtual TextureViewBase* CreateTextureView(TextureViewBuilder* builder) = 0;
|
virtual TextureViewBase* CreateTextureView(TextureViewBuilder* builder) = 0;
|
||||||
|
|
||||||
virtual void TickImpl() = 0;
|
virtual void TickImpl() = 0;
|
||||||
@ -94,7 +93,7 @@ namespace dawn_native {
|
|||||||
SamplerBase* CreateSampler(const SamplerDescriptor* descriptor);
|
SamplerBase* CreateSampler(const SamplerDescriptor* descriptor);
|
||||||
ShaderModuleBase* CreateShaderModule(const ShaderModuleDescriptor* descriptor);
|
ShaderModuleBase* CreateShaderModule(const ShaderModuleDescriptor* descriptor);
|
||||||
SwapChainBuilder* CreateSwapChainBuilder();
|
SwapChainBuilder* CreateSwapChainBuilder();
|
||||||
TextureBuilder* CreateTextureBuilder();
|
TextureBase* CreateTexture(const TextureDescriptor* descriptor);
|
||||||
|
|
||||||
void Tick();
|
void Tick();
|
||||||
void SetErrorCallback(dawn::DeviceErrorCallback callback, dawn::CallbackUserdata userdata);
|
void SetErrorCallback(dawn::DeviceErrorCallback callback, dawn::CallbackUserdata userdata);
|
||||||
@ -116,6 +115,8 @@ namespace dawn_native {
|
|||||||
const SamplerDescriptor* descriptor) = 0;
|
const SamplerDescriptor* descriptor) = 0;
|
||||||
virtual ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
virtual ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
||||||
const ShaderModuleDescriptor* descriptor) = 0;
|
const ShaderModuleDescriptor* descriptor) = 0;
|
||||||
|
virtual ResultOrError<TextureBase*> CreateTextureImpl(
|
||||||
|
const TextureDescriptor* descriptor) = 0;
|
||||||
|
|
||||||
MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result,
|
MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result,
|
||||||
const BindGroupLayoutDescriptor* descriptor);
|
const BindGroupLayoutDescriptor* descriptor);
|
||||||
@ -126,6 +127,7 @@ namespace dawn_native {
|
|||||||
MaybeError CreateSamplerInternal(SamplerBase** result, const SamplerDescriptor* descriptor);
|
MaybeError CreateSamplerInternal(SamplerBase** result, const SamplerDescriptor* descriptor);
|
||||||
MaybeError CreateShaderModuleInternal(ShaderModuleBase** result,
|
MaybeError CreateShaderModuleInternal(ShaderModuleBase** result,
|
||||||
const ShaderModuleDescriptor* descriptor);
|
const ShaderModuleDescriptor* descriptor);
|
||||||
|
MaybeError CreateTextureInternal(TextureBase** result, const TextureDescriptor* descriptor);
|
||||||
|
|
||||||
void ConsumeError(ErrorData* error);
|
void ConsumeError(ErrorData* error);
|
||||||
|
|
||||||
|
@ -50,7 +50,6 @@ namespace dawn_native {
|
|||||||
class SwapChainBase;
|
class SwapChainBase;
|
||||||
class SwapChainBuilder;
|
class SwapChainBuilder;
|
||||||
class TextureBase;
|
class TextureBase;
|
||||||
class TextureBuilder;
|
|
||||||
class TextureViewBase;
|
class TextureViewBase;
|
||||||
class TextureViewBuilder;
|
class TextureViewBuilder;
|
||||||
|
|
||||||
|
@ -59,16 +59,18 @@ namespace dawn_native {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* builder = mDevice->CreateTextureBuilder();
|
TextureDescriptor descriptor;
|
||||||
builder->SetDimension(dawn::TextureDimension::e2D);
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
builder->SetExtent(mWidth, mHeight, 1);
|
descriptor.width = mWidth;
|
||||||
builder->SetFormat(mFormat);
|
descriptor.height = mHeight;
|
||||||
builder->SetMipLevels(1);
|
descriptor.depth = 1;
|
||||||
builder->SetAllowedUsage(mAllowedUsage);
|
descriptor.arrayLayer = 1;
|
||||||
|
descriptor.format = mFormat;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = mAllowedUsage;
|
||||||
|
|
||||||
auto* texture = GetNextTextureImpl(builder);
|
auto* texture = GetNextTextureImpl(&descriptor);
|
||||||
mLastNextTexture = texture;
|
mLastNextTexture = texture;
|
||||||
builder->Release();
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ namespace dawn_native {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
const dawnSwapChainImplementation& GetImplementation();
|
const dawnSwapChainImplementation& GetImplementation();
|
||||||
virtual TextureBase* GetNextTextureImpl(TextureBuilder* builder) = 0;
|
virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0;
|
||||||
virtual void OnBeforePresent(TextureBase* texture) = 0;
|
virtual void OnBeforePresent(TextureBase* texture) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -16,8 +16,23 @@
|
|||||||
|
|
||||||
#include "common/Assert.h"
|
#include "common/Assert.h"
|
||||||
#include "dawn_native/Device.h"
|
#include "dawn_native/Device.h"
|
||||||
|
#include "dawn_native/ValidationUtils_autogen.h"
|
||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
MaybeError ValidateTextureDescriptor(DeviceBase*, const TextureDescriptor* descriptor) {
|
||||||
|
DAWN_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
|
||||||
|
DAWN_TRY(ValidateTextureUsageBit(descriptor->usage));
|
||||||
|
DAWN_TRY(ValidateTextureDimension(descriptor->dimension));
|
||||||
|
DAWN_TRY(ValidateTextureFormat(descriptor->format));
|
||||||
|
|
||||||
|
// TODO(jiawei.shao@intel.com): check stuff based on the dimension
|
||||||
|
if (descriptor->width == 0 || descriptor->height == 0 || descriptor->depth == 0 ||
|
||||||
|
descriptor->arrayLayer == 0 || descriptor->mipLevel == 0) {
|
||||||
|
DAWN_RETURN_ERROR("Cannot create an empty texture");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t TextureFormatPixelSize(dawn::TextureFormat format) {
|
uint32_t TextureFormatPixelSize(dawn::TextureFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
@ -67,15 +82,16 @@ namespace dawn_native {
|
|||||||
|
|
||||||
// TextureBase
|
// TextureBase
|
||||||
|
|
||||||
TextureBase::TextureBase(TextureBuilder* builder)
|
TextureBase::TextureBase(DeviceBase* device, const TextureDescriptor* descriptor)
|
||||||
: mDevice(builder->mDevice),
|
: mDevice(device),
|
||||||
mDimension(builder->mDimension),
|
mDimension(descriptor->dimension),
|
||||||
mFormat(builder->mFormat),
|
mFormat(descriptor->format),
|
||||||
mWidth(builder->mWidth),
|
mWidth(descriptor->width),
|
||||||
mHeight(builder->mHeight),
|
mHeight(descriptor->height),
|
||||||
mDepth(builder->mDepth),
|
mDepth(descriptor->depth),
|
||||||
mNumMipLevels(builder->mNumMipLevels),
|
mArrayLayers(descriptor->arrayLayer),
|
||||||
mUsage(builder->mAllowedUsage) {
|
mNumMipLevels(descriptor->mipLevel),
|
||||||
|
mUsage(descriptor->usage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceBase* TextureBase::GetDevice() const {
|
DeviceBase* TextureBase::GetDevice() const {
|
||||||
@ -97,6 +113,9 @@ namespace dawn_native {
|
|||||||
uint32_t TextureBase::GetDepth() const {
|
uint32_t TextureBase::GetDepth() const {
|
||||||
return mDepth;
|
return mDepth;
|
||||||
}
|
}
|
||||||
|
uint32_t TextureBase::GetArrayLayers() const {
|
||||||
|
return mArrayLayers;
|
||||||
|
}
|
||||||
uint32_t TextureBase::GetNumMipLevels() const {
|
uint32_t TextureBase::GetNumMipLevels() const {
|
||||||
return mNumMipLevels;
|
return mNumMipLevels;
|
||||||
}
|
}
|
||||||
@ -108,90 +127,6 @@ namespace dawn_native {
|
|||||||
return new TextureViewBuilder(mDevice, this);
|
return new TextureViewBuilder(mDevice, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextureBuilder
|
|
||||||
|
|
||||||
enum TextureSetProperties {
|
|
||||||
TEXTURE_PROPERTY_DIMENSION = 0x1,
|
|
||||||
TEXTURE_PROPERTY_EXTENT = 0x2,
|
|
||||||
TEXTURE_PROPERTY_FORMAT = 0x4,
|
|
||||||
TEXTURE_PROPERTY_MIP_LEVELS = 0x8,
|
|
||||||
TEXTURE_PROPERTY_ALLOWED_USAGE = 0x10,
|
|
||||||
};
|
|
||||||
|
|
||||||
TextureBuilder::TextureBuilder(DeviceBase* device) : Builder(device) {
|
|
||||||
}
|
|
||||||
|
|
||||||
TextureBase* TextureBuilder::GetResultImpl() {
|
|
||||||
constexpr int allProperties = TEXTURE_PROPERTY_DIMENSION | TEXTURE_PROPERTY_EXTENT |
|
|
||||||
TEXTURE_PROPERTY_FORMAT | TEXTURE_PROPERTY_MIP_LEVELS |
|
|
||||||
TEXTURE_PROPERTY_ALLOWED_USAGE;
|
|
||||||
if ((mPropertiesSet & allProperties) != allProperties) {
|
|
||||||
HandleError("Texture missing properties");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(cwallez@chromium.org): check stuff based on the dimension
|
|
||||||
|
|
||||||
return mDevice->CreateTexture(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureBuilder::SetDimension(dawn::TextureDimension dimension) {
|
|
||||||
if ((mPropertiesSet & TEXTURE_PROPERTY_DIMENSION) != 0) {
|
|
||||||
HandleError("Texture dimension property set multiple times");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPropertiesSet |= TEXTURE_PROPERTY_DIMENSION;
|
|
||||||
mDimension = dimension;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureBuilder::SetExtent(uint32_t width, uint32_t height, uint32_t depth) {
|
|
||||||
if ((mPropertiesSet & TEXTURE_PROPERTY_EXTENT) != 0) {
|
|
||||||
HandleError("Texture extent property set multiple times");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (width == 0 || height == 0 || depth == 0) {
|
|
||||||
HandleError("Cannot create an empty texture");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPropertiesSet |= TEXTURE_PROPERTY_EXTENT;
|
|
||||||
mWidth = width;
|
|
||||||
mHeight = height;
|
|
||||||
mDepth = depth;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureBuilder::SetFormat(dawn::TextureFormat format) {
|
|
||||||
if ((mPropertiesSet & TEXTURE_PROPERTY_FORMAT) != 0) {
|
|
||||||
HandleError("Texture format property set multiple times");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPropertiesSet |= TEXTURE_PROPERTY_FORMAT;
|
|
||||||
mFormat = format;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureBuilder::SetMipLevels(uint32_t numMipLevels) {
|
|
||||||
if ((mPropertiesSet & TEXTURE_PROPERTY_MIP_LEVELS) != 0) {
|
|
||||||
HandleError("Texture mip levels property set multiple times");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPropertiesSet |= TEXTURE_PROPERTY_MIP_LEVELS;
|
|
||||||
mNumMipLevels = numMipLevels;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureBuilder::SetAllowedUsage(dawn::TextureUsageBit usage) {
|
|
||||||
if ((mPropertiesSet & TEXTURE_PROPERTY_ALLOWED_USAGE) != 0) {
|
|
||||||
HandleError("Texture allowed usage property set multiple times");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPropertiesSet |= TEXTURE_PROPERTY_ALLOWED_USAGE;
|
|
||||||
mAllowedUsage = usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TextureViewBase
|
// TextureViewBase
|
||||||
|
|
||||||
TextureViewBase::TextureViewBase(TextureViewBuilder* builder) : mTexture(builder->mTexture) {
|
TextureViewBase::TextureViewBase(TextureViewBuilder* builder) : mTexture(builder->mTexture) {
|
||||||
|
@ -16,12 +16,14 @@
|
|||||||
#define DAWNNATIVE_TEXTURE_H_
|
#define DAWNNATIVE_TEXTURE_H_
|
||||||
|
|
||||||
#include "dawn_native/Builder.h"
|
#include "dawn_native/Builder.h"
|
||||||
|
#include "dawn_native/Error.h"
|
||||||
#include "dawn_native/Forward.h"
|
#include "dawn_native/Forward.h"
|
||||||
#include "dawn_native/RefCounted.h"
|
#include "dawn_native/RefCounted.h"
|
||||||
|
|
||||||
#include "dawn_native/dawn_platform.h"
|
#include "dawn_native/dawn_platform.h"
|
||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
MaybeError ValidateTextureDescriptor(DeviceBase* device, const TextureDescriptor* descriptor);
|
||||||
|
|
||||||
uint32_t TextureFormatPixelSize(dawn::TextureFormat format);
|
uint32_t TextureFormatPixelSize(dawn::TextureFormat format);
|
||||||
bool TextureFormatHasDepth(dawn::TextureFormat format);
|
bool TextureFormatHasDepth(dawn::TextureFormat format);
|
||||||
@ -38,13 +40,14 @@ namespace dawn_native {
|
|||||||
|
|
||||||
class TextureBase : public RefCounted {
|
class TextureBase : public RefCounted {
|
||||||
public:
|
public:
|
||||||
TextureBase(TextureBuilder* builder);
|
TextureBase(DeviceBase* device, const TextureDescriptor* descriptor);
|
||||||
|
|
||||||
dawn::TextureDimension GetDimension() const;
|
dawn::TextureDimension GetDimension() const;
|
||||||
dawn::TextureFormat GetFormat() const;
|
dawn::TextureFormat GetFormat() const;
|
||||||
uint32_t GetWidth() const;
|
uint32_t GetWidth() const;
|
||||||
uint32_t GetHeight() const;
|
uint32_t GetHeight() const;
|
||||||
uint32_t GetDepth() const;
|
uint32_t GetDepth() const;
|
||||||
|
uint32_t GetArrayLayers() const;
|
||||||
uint32_t GetNumMipLevels() const;
|
uint32_t GetNumMipLevels() const;
|
||||||
dawn::TextureUsageBit GetUsage() const;
|
dawn::TextureUsageBit GetUsage() const;
|
||||||
DeviceBase* GetDevice() const;
|
DeviceBase* GetDevice() const;
|
||||||
@ -58,36 +61,11 @@ namespace dawn_native {
|
|||||||
dawn::TextureDimension mDimension;
|
dawn::TextureDimension mDimension;
|
||||||
dawn::TextureFormat mFormat;
|
dawn::TextureFormat mFormat;
|
||||||
uint32_t mWidth, mHeight, mDepth;
|
uint32_t mWidth, mHeight, mDepth;
|
||||||
|
uint32_t mArrayLayers;
|
||||||
uint32_t mNumMipLevels;
|
uint32_t mNumMipLevels;
|
||||||
dawn::TextureUsageBit mUsage = dawn::TextureUsageBit::None;
|
dawn::TextureUsageBit mUsage = dawn::TextureUsageBit::None;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextureBuilder : public Builder<TextureBase> {
|
|
||||||
public:
|
|
||||||
TextureBuilder(DeviceBase* device);
|
|
||||||
|
|
||||||
// Dawn API
|
|
||||||
void SetDimension(dawn::TextureDimension dimension);
|
|
||||||
void SetExtent(uint32_t width, uint32_t height, uint32_t depth);
|
|
||||||
void SetFormat(dawn::TextureFormat format);
|
|
||||||
void SetMipLevels(uint32_t numMipLevels);
|
|
||||||
void SetAllowedUsage(dawn::TextureUsageBit usage);
|
|
||||||
void SetInitialUsage(dawn::TextureUsageBit usage);
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class TextureBase;
|
|
||||||
|
|
||||||
TextureBase* GetResultImpl() override;
|
|
||||||
|
|
||||||
int mPropertiesSet = 0;
|
|
||||||
|
|
||||||
dawn::TextureDimension mDimension;
|
|
||||||
uint32_t mWidth, mHeight, mDepth;
|
|
||||||
dawn::TextureFormat mFormat;
|
|
||||||
uint32_t mNumMipLevels;
|
|
||||||
dawn::TextureUsageBit mAllowedUsage = dawn::TextureUsageBit::None;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TextureViewBase : public RefCounted {
|
class TextureViewBase : public RefCounted {
|
||||||
public:
|
public:
|
||||||
TextureViewBase(TextureViewBuilder* builder);
|
TextureViewBase(TextureViewBuilder* builder);
|
||||||
|
@ -311,8 +311,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
||||||
return new SwapChain(builder);
|
return new SwapChain(builder);
|
||||||
}
|
}
|
||||||
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
|
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
return new Texture(builder);
|
return new Texture(this, descriptor);
|
||||||
}
|
}
|
||||||
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
||||||
return new TextureView(builder);
|
return new TextureView(builder);
|
||||||
|
@ -49,7 +49,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;
|
||||||
TextureBase* CreateTexture(TextureBuilder* builder) override;
|
|
||||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||||
|
|
||||||
void TickImpl() override;
|
void TickImpl() override;
|
||||||
@ -84,6 +83,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
||||||
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
||||||
const ShaderModuleDescriptor* descriptor) override;
|
const ShaderModuleDescriptor* descriptor) override;
|
||||||
|
ResultOrError<TextureBase*> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
|
|
||||||
uint64_t mSerial = 0;
|
uint64_t mSerial = 0;
|
||||||
ComPtr<ID3D12Fence> mFence;
|
ComPtr<ID3D12Fence> mFence;
|
||||||
|
@ -34,7 +34,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
SwapChain::~SwapChain() {
|
SwapChain::~SwapChain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
|
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
const auto& im = GetImplementation();
|
const auto& im = GetImplementation();
|
||||||
dawnSwapChainNextTexture next = {};
|
dawnSwapChainNextTexture next = {};
|
||||||
dawnSwapChainError error = im.GetNextTexture(im.userData, &next);
|
dawnSwapChainError error = im.GetNextTexture(im.userData, &next);
|
||||||
@ -44,7 +44,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ID3D12Resource* nativeTexture = reinterpret_cast<ID3D12Resource*>(next.texture.ptr);
|
ID3D12Resource* nativeTexture = reinterpret_cast<ID3D12Resource*>(next.texture.ptr);
|
||||||
return new Texture(builder, nativeTexture);
|
return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapChain::OnBeforePresent(TextureBase* texture) {
|
void SwapChain::OnBeforePresent(TextureBase* texture) {
|
||||||
|
@ -25,7 +25,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
~SwapChain();
|
~SwapChain();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
void OnBeforePresent(TextureBase* texture) override;
|
void OnBeforePresent(TextureBase* texture) override;
|
||||||
|
|
||||||
dawn::TextureUsageBit mTextureUsage;
|
dawn::TextureUsageBit mTextureUsage;
|
||||||
|
@ -107,8 +107,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(TextureBuilder* builder)
|
Texture::Texture(Device* device, const TextureDescriptor* descriptor)
|
||||||
: TextureBase(builder), mDevice(ToBackend(builder->GetDevice())) {
|
: TextureBase(device, descriptor) {
|
||||||
D3D12_RESOURCE_DESC resourceDescriptor;
|
D3D12_RESOURCE_DESC resourceDescriptor;
|
||||||
resourceDescriptor.Dimension = D3D12TextureDimension(GetDimension());
|
resourceDescriptor.Dimension = D3D12TextureDimension(GetDimension());
|
||||||
resourceDescriptor.Alignment = 0;
|
resourceDescriptor.Alignment = 0;
|
||||||
@ -122,22 +122,24 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
resourceDescriptor.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
resourceDescriptor.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||||
resourceDescriptor.Flags = D3D12ResourceFlags(GetUsage(), GetFormat());
|
resourceDescriptor.Flags = D3D12ResourceFlags(GetUsage(), GetFormat());
|
||||||
|
|
||||||
mResource = mDevice->GetResourceAllocator()->Allocate(
|
mResource = ToBackend(GetDevice())
|
||||||
D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor, D3D12_RESOURCE_STATE_COMMON);
|
->GetResourceAllocator()
|
||||||
|
->Allocate(D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor,
|
||||||
|
D3D12_RESOURCE_STATE_COMMON);
|
||||||
mResourcePtr = mResource.Get();
|
mResourcePtr = mResource.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// With this constructor, the lifetime of the ID3D12Resource is externally managed.
|
// With this constructor, the lifetime of the ID3D12Resource is externally managed.
|
||||||
Texture::Texture(TextureBuilder* builder, ID3D12Resource* nativeTexture)
|
Texture::Texture(Device* device,
|
||||||
: TextureBase(builder),
|
const TextureDescriptor* descriptor,
|
||||||
mDevice(ToBackend(builder->GetDevice())),
|
ID3D12Resource* nativeTexture)
|
||||||
mResourcePtr(nativeTexture) {
|
: TextureBase(device, descriptor), mResourcePtr(nativeTexture) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::~Texture() {
|
Texture::~Texture() {
|
||||||
if (mResource) {
|
if (mResource) {
|
||||||
// If we own the resource, release it.
|
// If we own the resource, release it.
|
||||||
mDevice->GetResourceAllocator()->Release(mResource);
|
ToBackend(GetDevice())->GetResourceAllocator()->Release(mResource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
class Texture : public TextureBase {
|
class Texture : public TextureBase {
|
||||||
public:
|
public:
|
||||||
Texture(TextureBuilder* builder);
|
Texture(Device* device, const TextureDescriptor* descriptor);
|
||||||
Texture(TextureBuilder* builder, ID3D12Resource* nativeTexture);
|
Texture(Device* device, const TextureDescriptor* descriptor, ID3D12Resource* nativeTexture);
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
DXGI_FORMAT GetD3D12Format() const;
|
DXGI_FORMAT GetD3D12Format() const;
|
||||||
@ -38,7 +38,6 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
dawn::TextureUsageBit usage);
|
dawn::TextureUsageBit usage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device* mDevice;
|
|
||||||
ComPtr<ID3D12Resource> mResource = {};
|
ComPtr<ID3D12Resource> mResource = {};
|
||||||
ID3D12Resource* mResourcePtr = nullptr;
|
ID3D12Resource* mResourcePtr = nullptr;
|
||||||
dawn::TextureUsageBit mLastUsage = dawn::TextureUsageBit::None;
|
dawn::TextureUsageBit mLastUsage = dawn::TextureUsageBit::None;
|
||||||
|
@ -46,7 +46,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;
|
||||||
TextureBase* CreateTexture(TextureBuilder* builder) override;
|
|
||||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||||
|
|
||||||
void TickImpl() override;
|
void TickImpl() override;
|
||||||
@ -70,6 +69,7 @@ namespace dawn_native { namespace metal {
|
|||||||
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
||||||
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
||||||
const ShaderModuleDescriptor* descriptor) override;
|
const ShaderModuleDescriptor* descriptor) override;
|
||||||
|
ResultOrError<TextureBase*> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
|
|
||||||
void OnCompletedHandler();
|
void OnCompletedHandler();
|
||||||
|
|
||||||
|
@ -130,8 +130,8 @@ namespace dawn_native { namespace metal {
|
|||||||
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
||||||
return new SwapChain(builder);
|
return new SwapChain(builder);
|
||||||
}
|
}
|
||||||
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
|
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
return new Texture(builder);
|
return new Texture(this, descriptor);
|
||||||
}
|
}
|
||||||
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
||||||
return new TextureView(builder);
|
return new TextureView(builder);
|
||||||
|
@ -27,7 +27,7 @@ namespace dawn_native { namespace metal {
|
|||||||
~SwapChain();
|
~SwapChain();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
void OnBeforePresent(TextureBase* texture) override;
|
void OnBeforePresent(TextureBase* texture) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace dawn_native { namespace metal {
|
|||||||
SwapChain::~SwapChain() {
|
SwapChain::~SwapChain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
|
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
const auto& im = GetImplementation();
|
const auto& im = GetImplementation();
|
||||||
dawnSwapChainNextTexture next = {};
|
dawnSwapChainNextTexture next = {};
|
||||||
dawnSwapChainError error = im.GetNextTexture(im.userData, &next);
|
dawnSwapChainError error = im.GetNextTexture(im.userData, &next);
|
||||||
@ -41,7 +41,7 @@ namespace dawn_native { namespace metal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
id<MTLTexture> nativeTexture = reinterpret_cast<id<MTLTexture>>(next.texture.ptr);
|
id<MTLTexture> nativeTexture = reinterpret_cast<id<MTLTexture>>(next.texture.ptr);
|
||||||
return new Texture(builder, nativeTexture);
|
return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapChain::OnBeforePresent(TextureBase*) {
|
void SwapChain::OnBeforePresent(TextureBase*) {
|
||||||
|
@ -21,12 +21,14 @@
|
|||||||
|
|
||||||
namespace dawn_native { namespace metal {
|
namespace dawn_native { namespace metal {
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
|
||||||
MTLPixelFormat MetalPixelFormat(dawn::TextureFormat format);
|
MTLPixelFormat MetalPixelFormat(dawn::TextureFormat format);
|
||||||
|
|
||||||
class Texture : public TextureBase {
|
class Texture : public TextureBase {
|
||||||
public:
|
public:
|
||||||
Texture(TextureBuilder* builder);
|
Texture(Device* device, const TextureDescriptor* descriptor);
|
||||||
Texture(TextureBuilder* builder, id<MTLTexture> mtlTexture);
|
Texture(Device* device, const TextureDescriptor* descriptor, id<MTLTexture> mtlTexture);
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
id<MTLTexture> GetMTLTexture();
|
id<MTLTexture> GetMTLTexture();
|
||||||
|
@ -66,7 +66,8 @@ namespace dawn_native { namespace metal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(TextureBuilder* builder) : TextureBase(builder) {
|
Texture::Texture(Device* device, const TextureDescriptor* descriptor)
|
||||||
|
: TextureBase(device, descriptor) {
|
||||||
auto desc = [MTLTextureDescriptor new];
|
auto desc = [MTLTextureDescriptor new];
|
||||||
[desc autorelease];
|
[desc autorelease];
|
||||||
desc.textureType = MetalTextureType(GetDimension());
|
desc.textureType = MetalTextureType(GetDimension());
|
||||||
@ -79,12 +80,12 @@ namespace dawn_native { namespace metal {
|
|||||||
desc.arrayLength = 1;
|
desc.arrayLength = 1;
|
||||||
desc.storageMode = MTLStorageModePrivate;
|
desc.storageMode = MTLStorageModePrivate;
|
||||||
|
|
||||||
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
|
auto mtlDevice = device->GetMTLDevice();
|
||||||
mMtlTexture = [mtlDevice newTextureWithDescriptor:desc];
|
mMtlTexture = [mtlDevice newTextureWithDescriptor:desc];
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(TextureBuilder* builder, id<MTLTexture> mtlTexture)
|
Texture::Texture(Device* device, const TextureDescriptor* descriptor, id<MTLTexture> mtlTexture)
|
||||||
: TextureBase(builder), mMtlTexture(mtlTexture) {
|
: TextureBase(device, descriptor), mMtlTexture(mtlTexture) {
|
||||||
[mMtlTexture retain];
|
[mMtlTexture retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ namespace dawn_native { namespace null {
|
|||||||
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
||||||
return new SwapChain(builder);
|
return new SwapChain(builder);
|
||||||
}
|
}
|
||||||
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
|
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
return new Texture(builder);
|
return new Texture(this, descriptor);
|
||||||
}
|
}
|
||||||
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
||||||
return new TextureView(builder);
|
return new TextureView(builder);
|
||||||
@ -207,8 +207,8 @@ namespace dawn_native { namespace null {
|
|||||||
SwapChain::~SwapChain() {
|
SwapChain::~SwapChain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
|
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
return GetDevice()->CreateTexture(builder);
|
return GetDevice()->CreateTexture(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapChain::OnBeforePresent(TextureBase*) {
|
void SwapChain::OnBeforePresent(TextureBase*) {
|
||||||
|
@ -106,7 +106,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;
|
||||||
TextureBase* CreateTexture(TextureBuilder* builder) override;
|
|
||||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||||
|
|
||||||
void TickImpl() override;
|
void TickImpl() override;
|
||||||
@ -124,6 +123,7 @@ namespace dawn_native { namespace null {
|
|||||||
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
||||||
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
||||||
const ShaderModuleDescriptor* descriptor) override;
|
const ShaderModuleDescriptor* descriptor) override;
|
||||||
|
ResultOrError<TextureBase*> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<PendingOperation>> mPendingOperations;
|
std::vector<std::unique_ptr<PendingOperation>> mPendingOperations;
|
||||||
};
|
};
|
||||||
@ -170,7 +170,7 @@ namespace dawn_native { namespace null {
|
|||||||
~SwapChain();
|
~SwapChain();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
void OnBeforePresent(TextureBase*) override;
|
void OnBeforePresent(TextureBase*) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -98,8 +98,8 @@ namespace dawn_native { namespace opengl {
|
|||||||
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
||||||
return new SwapChain(builder);
|
return new SwapChain(builder);
|
||||||
}
|
}
|
||||||
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
|
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
return new Texture(builder);
|
return new Texture(this, descriptor);
|
||||||
}
|
}
|
||||||
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
||||||
return new TextureView(builder);
|
return new TextureView(builder);
|
||||||
|
@ -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;
|
||||||
TextureBase* CreateTexture(TextureBuilder* builder) override;
|
|
||||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||||
|
|
||||||
void TickImpl() override;
|
void TickImpl() override;
|
||||||
@ -58,6 +57,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
||||||
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
||||||
const ShaderModuleDescriptor* descriptor) override;
|
const ShaderModuleDescriptor* descriptor) override;
|
||||||
|
ResultOrError<TextureBase*> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}} // namespace dawn_native::opengl
|
}} // namespace dawn_native::opengl
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "dawn_native/opengl/SwapChainGL.h"
|
#include "dawn_native/opengl/SwapChainGL.h"
|
||||||
|
|
||||||
#include "dawn_native/Device.h"
|
#include "dawn_native/Device.h"
|
||||||
|
#include "dawn_native/opengl/Forward.h"
|
||||||
#include "dawn_native/opengl/TextureGL.h"
|
#include "dawn_native/opengl/TextureGL.h"
|
||||||
|
|
||||||
#include <dawn/dawn_wsi.h>
|
#include <dawn/dawn_wsi.h>
|
||||||
@ -29,7 +30,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
SwapChain::~SwapChain() {
|
SwapChain::~SwapChain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
|
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
const auto& im = GetImplementation();
|
const auto& im = GetImplementation();
|
||||||
dawnSwapChainNextTexture next = {};
|
dawnSwapChainNextTexture next = {};
|
||||||
dawnSwapChainError error = im.GetNextTexture(im.userData, &next);
|
dawnSwapChainError error = im.GetNextTexture(im.userData, &next);
|
||||||
@ -38,7 +39,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
GLuint nativeTexture = next.texture.u32;
|
GLuint nativeTexture = next.texture.u32;
|
||||||
return new Texture(builder, nativeTexture);
|
return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapChain::OnBeforePresent(TextureBase*) {
|
void SwapChain::OnBeforePresent(TextureBase*) {
|
||||||
|
@ -29,7 +29,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
~SwapChain();
|
~SwapChain();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
void OnBeforePresent(TextureBase* texture) override;
|
void OnBeforePresent(TextureBase* texture) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "dawn_native/opengl/TextureGL.h"
|
#include "dawn_native/opengl/TextureGL.h"
|
||||||
|
#include "dawn_native/opengl/DeviceGL.h"
|
||||||
|
|
||||||
#include "common/Assert.h"
|
#include "common/Assert.h"
|
||||||
|
|
||||||
@ -67,11 +68,12 @@ namespace dawn_native { namespace opengl {
|
|||||||
|
|
||||||
// Texture
|
// Texture
|
||||||
|
|
||||||
Texture::Texture(TextureBuilder* builder) : Texture(builder, GenTexture()) {
|
Texture::Texture(Device* device, const TextureDescriptor* descriptor)
|
||||||
|
: Texture(device, descriptor, GenTexture()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(TextureBuilder* builder, GLuint handle)
|
Texture::Texture(Device* device, const TextureDescriptor* descriptor, GLuint handle)
|
||||||
: TextureBase(builder), mHandle(handle) {
|
: TextureBase(device, descriptor), mHandle(handle) {
|
||||||
mTarget = TargetForDimension(GetDimension());
|
mTarget = TargetForDimension(GetDimension());
|
||||||
|
|
||||||
uint32_t width = GetWidth();
|
uint32_t width = GetWidth();
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
namespace dawn_native { namespace opengl {
|
namespace dawn_native { namespace opengl {
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
|
||||||
struct TextureFormatInfo {
|
struct TextureFormatInfo {
|
||||||
GLenum internalFormat;
|
GLenum internalFormat;
|
||||||
GLenum format;
|
GLenum format;
|
||||||
@ -29,8 +31,8 @@ namespace dawn_native { namespace opengl {
|
|||||||
|
|
||||||
class Texture : public TextureBase {
|
class Texture : public TextureBase {
|
||||||
public:
|
public:
|
||||||
Texture(TextureBuilder* builder);
|
Texture(Device* device, const TextureDescriptor* descriptor);
|
||||||
Texture(TextureBuilder* builder, GLuint handle);
|
Texture(Device* device, const TextureDescriptor* descriptor, GLuint handle);
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
GLuint GetHandle() const;
|
GLuint GetHandle() const;
|
||||||
|
@ -269,8 +269,8 @@ namespace dawn_native { namespace vulkan {
|
|||||||
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
||||||
return new SwapChain(builder);
|
return new SwapChain(builder);
|
||||||
}
|
}
|
||||||
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
|
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
return new Texture(builder);
|
return new Texture(this, descriptor);
|
||||||
}
|
}
|
||||||
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
||||||
return new TextureView(builder);
|
return new TextureView(builder);
|
||||||
|
@ -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;
|
||||||
TextureBase* CreateTexture(TextureBuilder* builder) override;
|
|
||||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||||
|
|
||||||
void TickImpl() override;
|
void TickImpl() override;
|
||||||
@ -89,6 +88,7 @@ namespace dawn_native { namespace vulkan {
|
|||||||
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
ResultOrError<SamplerBase*> CreateSamplerImpl(const SamplerDescriptor* descriptor) override;
|
||||||
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
ResultOrError<ShaderModuleBase*> CreateShaderModuleImpl(
|
||||||
const ShaderModuleDescriptor* descriptor) override;
|
const ShaderModuleDescriptor* descriptor) override;
|
||||||
|
ResultOrError<TextureBase*> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
|
|
||||||
bool CreateInstance(VulkanGlobalKnobs* usedKnobs,
|
bool CreateInstance(VulkanGlobalKnobs* usedKnobs,
|
||||||
const std::vector<const char*>& requiredExtensions);
|
const std::vector<const char*>& requiredExtensions);
|
||||||
|
@ -31,7 +31,7 @@ namespace dawn_native { namespace vulkan {
|
|||||||
SwapChain::~SwapChain() {
|
SwapChain::~SwapChain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
|
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
|
||||||
const auto& im = GetImplementation();
|
const auto& im = GetImplementation();
|
||||||
dawnSwapChainNextTexture next = {};
|
dawnSwapChainNextTexture next = {};
|
||||||
dawnSwapChainError error = im.GetNextTexture(im.userData, &next);
|
dawnSwapChainError error = im.GetNextTexture(im.userData, &next);
|
||||||
@ -42,7 +42,7 @@ namespace dawn_native { namespace vulkan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VkImage nativeTexture = VkImage::CreateFromU64(next.texture.u64);
|
VkImage nativeTexture = VkImage::CreateFromU64(next.texture.u64);
|
||||||
return new Texture(builder, nativeTexture);
|
return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapChain::OnBeforePresent(TextureBase* texture) {
|
void SwapChain::OnBeforePresent(TextureBase* texture) {
|
||||||
|
@ -27,7 +27,7 @@ namespace dawn_native { namespace vulkan {
|
|||||||
~SwapChain();
|
~SwapChain();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
|
||||||
void OnBeforePresent(TextureBase* texture) override;
|
void OnBeforePresent(TextureBase* texture) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -235,9 +235,8 @@ namespace dawn_native { namespace vulkan {
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(TextureBuilder* builder) : TextureBase(builder) {
|
Texture::Texture(Device* device, const TextureDescriptor* descriptor)
|
||||||
Device* device = ToBackend(GetDevice());
|
: TextureBase(device, descriptor) {
|
||||||
|
|
||||||
// Create the Vulkan image "container". We don't need to check that the format supports the
|
// Create the Vulkan image "container". We don't need to check that the format supports the
|
||||||
// combination of sample, usage etc. because validation should have been done in the Dawn
|
// combination of sample, usage etc. because validation should have been done in the Dawn
|
||||||
// frontend already based on the minimum supported formats in the Vulkan spec
|
// frontend already based on the minimum supported formats in the Vulkan spec
|
||||||
@ -278,8 +277,8 @@ namespace dawn_native { namespace vulkan {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(TextureBuilder* builder, VkImage nativeImage)
|
Texture::Texture(Device* device, const TextureDescriptor* descriptor, VkImage nativeImage)
|
||||||
: TextureBase(builder), mHandle(nativeImage) {
|
: TextureBase(device, descriptor), mHandle(nativeImage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::~Texture() {
|
Texture::~Texture() {
|
||||||
|
@ -27,8 +27,8 @@ namespace dawn_native { namespace vulkan {
|
|||||||
|
|
||||||
class Texture : public TextureBase {
|
class Texture : public TextureBase {
|
||||||
public:
|
public:
|
||||||
Texture(TextureBuilder* builder);
|
Texture(Device* device, const TextureDescriptor* descriptor);
|
||||||
Texture(TextureBuilder* builder, VkImage nativeImage);
|
Texture(Device* device, const TextureDescriptor* descriptor, VkImage nativeImage);
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
VkImage GetHandle() const;
|
VkImage GetHandle() const;
|
||||||
|
@ -690,14 +690,18 @@ TEST_P(BlendStateTest, IndependentBlendState) {
|
|||||||
std::array<dawn::Texture, 4> renderTargets;
|
std::array<dawn::Texture, 4> renderTargets;
|
||||||
std::array<dawn::TextureView, 4> renderTargetViews;
|
std::array<dawn::TextureView, 4> renderTargetViews;
|
||||||
|
|
||||||
|
dawn::TextureDescriptor descriptor;
|
||||||
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
|
descriptor.width = kRTSize;
|
||||||
|
descriptor.height = kRTSize;
|
||||||
|
descriptor.depth = 1;
|
||||||
|
descriptor.arrayLayer = 1;
|
||||||
|
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 4; ++i) {
|
for (uint32_t i = 0; i < 4; ++i) {
|
||||||
renderTargets[i] = device.CreateTextureBuilder()
|
renderTargets[i] = device.CreateTexture(&descriptor);
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
|
||||||
.SetExtent(kRTSize, kRTSize, 1)
|
|
||||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
|
||||||
.SetMipLevels(1)
|
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc)
|
|
||||||
.GetResult();
|
|
||||||
renderTargetViews[i] = renderTargets[i].CreateTextureViewBuilder().GetResult();
|
renderTargetViews[i] = renderTargets[i].CreateTextureViewBuilder().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,13 +72,16 @@ class CopyTests_T2B : public CopyTests {
|
|||||||
|
|
||||||
void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
|
void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
|
||||||
// Create a texture that is `width` x `height` with (`level` + 1) mip levels.
|
// Create a texture that is `width` x `height` with (`level` + 1) mip levels.
|
||||||
dawn::Texture texture = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(textureSpec.width, textureSpec.height, 1)
|
descriptor.width = textureSpec.width;
|
||||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
descriptor.height = textureSpec.height;
|
||||||
.SetMipLevels(textureSpec.level + 1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
descriptor.mipLevel = textureSpec.level + 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc;
|
||||||
|
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||||
|
|
||||||
uint32_t width = textureSpec.width >> textureSpec.level;
|
uint32_t width = textureSpec.width >> textureSpec.level;
|
||||||
uint32_t height = textureSpec.height >> textureSpec.level;
|
uint32_t height = textureSpec.height >> textureSpec.level;
|
||||||
@ -158,13 +161,16 @@ protected:
|
|||||||
buffer.SetSubData(0, static_cast<uint32_t>(bufferData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(bufferData.data()));
|
buffer.SetSubData(0, static_cast<uint32_t>(bufferData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(bufferData.data()));
|
||||||
|
|
||||||
// Create a texture that is `width` x `height` with (`level` + 1) mip levels.
|
// Create a texture that is `width` x `height` with (`level` + 1) mip levels.
|
||||||
dawn::Texture texture = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(textureSpec.width, textureSpec.height, 1)
|
descriptor.width = textureSpec.width;
|
||||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
descriptor.height = textureSpec.height;
|
||||||
.SetMipLevels(textureSpec.level + 1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
descriptor.mipLevel = textureSpec.level + 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc;
|
||||||
|
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||||
|
|
||||||
dawn::CommandBuffer commands[2];
|
dawn::CommandBuffer commands[2];
|
||||||
|
|
||||||
|
@ -24,23 +24,29 @@ class DepthStencilStateTest : public DawnTest {
|
|||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
DawnTest::SetUp();
|
DawnTest::SetUp();
|
||||||
|
|
||||||
renderTarget = device.CreateTextureBuilder()
|
dawn::TextureDescriptor renderTargetDescriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
renderTargetDescriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(kRTSize, kRTSize, 1)
|
renderTargetDescriptor.width = kRTSize;
|
||||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
renderTargetDescriptor.height = kRTSize;
|
||||||
.SetMipLevels(1)
|
renderTargetDescriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc)
|
renderTargetDescriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
renderTargetDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
renderTargetDescriptor.mipLevel = 1;
|
||||||
|
renderTargetDescriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;
|
||||||
|
renderTarget = device.CreateTexture(&renderTargetDescriptor);
|
||||||
|
|
||||||
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();
|
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();
|
||||||
|
|
||||||
depthTexture = device.CreateTextureBuilder()
|
dawn::TextureDescriptor depthDescriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
depthDescriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(kRTSize, kRTSize, 1)
|
depthDescriptor.width = kRTSize;
|
||||||
.SetFormat(dawn::TextureFormat::D32FloatS8Uint)
|
depthDescriptor.height = kRTSize;
|
||||||
.SetMipLevels(1)
|
depthDescriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
depthDescriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
depthDescriptor.format = dawn::TextureFormat::D32FloatS8Uint;
|
||||||
|
depthDescriptor.mipLevel = 1;
|
||||||
|
depthDescriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||||
|
depthTexture = device.CreateTexture(&depthDescriptor);
|
||||||
|
|
||||||
depthTextureView = depthTexture.CreateTextureViewBuilder().GetResult();
|
depthTextureView = depthTexture.CreateTextureViewBuilder().GetResult();
|
||||||
|
|
||||||
|
@ -55,13 +55,16 @@ class RenderPassLoadOpTests : public DawnTest {
|
|||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
DawnTest::SetUp();
|
DawnTest::SetUp();
|
||||||
|
|
||||||
renderTarget = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(kRTSize, kRTSize, 1)
|
descriptor.width = kRTSize;
|
||||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
descriptor.height = kRTSize;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;
|
||||||
|
renderTarget = device.CreateTexture(&descriptor);
|
||||||
|
|
||||||
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();
|
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();
|
||||||
|
|
||||||
|
@ -80,13 +80,16 @@ protected:
|
|||||||
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
auto texture = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(2, 2, 1)
|
descriptor.width = 2;
|
||||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
descriptor.height = 2;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled;
|
||||||
|
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||||
|
|
||||||
// Create a 2x2 checkerboard texture, with black in the top left and bottom right corners.
|
// Create a 2x2 checkerboard texture, with black in the top left and bottom right corners.
|
||||||
const uint32_t rowPixels = kTextureRowPitchAlignment / sizeof(RGBA8);
|
const uint32_t rowPixels = kTextureRowPitchAlignment / sizeof(RGBA8);
|
||||||
|
@ -28,13 +28,16 @@ class CopyCommandTest : public ValidationTest {
|
|||||||
|
|
||||||
dawn::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels,
|
dawn::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels,
|
||||||
dawn::TextureFormat format, dawn::TextureUsageBit usage) {
|
dawn::TextureFormat format, dawn::TextureUsageBit usage) {
|
||||||
dawn::Texture tex = AssertWillBeSuccess(device.CreateTextureBuilder())
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(width, height, 1)
|
descriptor.width = width;
|
||||||
.SetFormat(format)
|
descriptor.height = height;
|
||||||
.SetMipLevels(levels)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(usage)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = format;
|
||||||
|
descriptor.mipLevel = levels;
|
||||||
|
descriptor.usage = usage;
|
||||||
|
dawn::Texture tex = device.CreateTexture(&descriptor);
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,13 +22,16 @@ class RenderPassDescriptorValidationTest : public ValidationTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
dawn::TextureView Create2DAttachment(dawn::Device& device, uint32_t width, uint32_t height, dawn::TextureFormat format) {
|
dawn::TextureView Create2DAttachment(dawn::Device& device, uint32_t width, uint32_t height, dawn::TextureFormat format) {
|
||||||
dawn::Texture attachment = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(width, height, 1)
|
descriptor.width = width;
|
||||||
.SetFormat(format)
|
descriptor.height = height;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = format;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||||
|
dawn::Texture attachment = device.CreateTexture(&descriptor);
|
||||||
|
|
||||||
return attachment.CreateTextureViewBuilder()
|
return attachment.CreateTextureViewBuilder()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
@ -71,13 +71,17 @@ bool ValidationTest::EndExpectDeviceError() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dawn::RenderPassDescriptor ValidationTest::CreateSimpleRenderPass() {
|
dawn::RenderPassDescriptor ValidationTest::CreateSimpleRenderPass() {
|
||||||
auto colorBuffer = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(640, 480, 1)
|
descriptor.width = 640;
|
||||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
descriptor.height = 480;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||||
|
|
||||||
|
auto colorBuffer = device.CreateTexture(&descriptor);
|
||||||
auto colorView = colorBuffer.CreateTextureViewBuilder()
|
auto colorView = colorBuffer.CreateTextureViewBuilder()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
@ -119,13 +123,16 @@ ValidationTest::DummyRenderPass ValidationTest::CreateDummyRenderPass() {
|
|||||||
dummy.height = 400;
|
dummy.height = 400;
|
||||||
dummy.attachmentFormat = dawn::TextureFormat::R8G8B8A8Unorm;
|
dummy.attachmentFormat = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
|
|
||||||
dummy.attachment = AssertWillBeSuccess(device.CreateTextureBuilder())
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(dummy.width, dummy.height, 1)
|
descriptor.width = dummy.width;
|
||||||
.SetFormat(dummy.attachmentFormat)
|
descriptor.height = dummy.height;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
descriptor.arrayLayer = 1;
|
||||||
.GetResult();
|
descriptor.format = dummy.attachmentFormat;
|
||||||
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||||
|
dummy.attachment = device.CreateTexture(&descriptor);
|
||||||
|
|
||||||
dawn::TextureView view = AssertWillBeSuccess(dummy.attachment.CreateTextureViewBuilder()).GetResult();
|
dawn::TextureView view = AssertWillBeSuccess(dummy.attachment.CreateTextureViewBuilder()).GetResult();
|
||||||
|
|
||||||
|
@ -115,14 +115,17 @@ namespace utils {
|
|||||||
result.height = height;
|
result.height = height;
|
||||||
|
|
||||||
result.colorFormat = dawn::TextureFormat::R8G8B8A8Unorm;
|
result.colorFormat = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||||
result.color = device.CreateTextureBuilder()
|
dawn::TextureDescriptor descriptor;
|
||||||
.SetDimension(dawn::TextureDimension::e2D)
|
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||||
.SetExtent(width, height, 1)
|
descriptor.width = width;
|
||||||
.SetFormat(result.colorFormat)
|
descriptor.height = height;
|
||||||
.SetMipLevels(1)
|
descriptor.depth = 1;
|
||||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment |
|
descriptor.arrayLayer = 1;
|
||||||
dawn::TextureUsageBit::TransferSrc)
|
descriptor.format = result.colorFormat;
|
||||||
.GetResult();
|
descriptor.mipLevel = 1;
|
||||||
|
descriptor.usage =
|
||||||
|
dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;
|
||||||
|
result.color = device.CreateTexture(&descriptor);
|
||||||
|
|
||||||
dawn::TextureView colorView = result.color.CreateTextureViewBuilder().GetResult();
|
dawn::TextureView colorView = result.color.CreateTextureViewBuilder().GetResult();
|
||||||
result.renderPassInfo = device.CreateRenderPassDescriptorBuilder()
|
result.renderPassInfo = device.CreateRenderPassDescriptorBuilder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user