Add reflection APIs for wgpu::Texture.
This requires adding a custom implementation of DeviceCreateTexture and the Texture object in the wire client. In dawn::native this requires the format enum separately from mFormat which is a `const Format&` so that garbage format values can be reflected correctly for error textures. Bug: dawn:1451 Change-Id: I75b5635f36647f6f04dae54e92154f2b552beb64 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92661 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Loko Kung <lokokung@google.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org> Auto-Submit: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
bd30d9e594
commit
736e97c5e0
32
dawn.json
32
dawn.json
|
@ -2519,6 +2519,38 @@
|
||||||
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
|
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "get width",
|
||||||
|
"returns": "uint32_t"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get height",
|
||||||
|
"returns": "uint32_t"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get depth or array layers",
|
||||||
|
"returns": "uint32_t"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get mip level count",
|
||||||
|
"returns": "uint32_t"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get sample count",
|
||||||
|
"returns": "uint32_t"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get dimension",
|
||||||
|
"returns": "texture dimension"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get format",
|
||||||
|
"returns": "texture format"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get usage",
|
||||||
|
"returns": "texture usage"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "destroy"
|
"name": "destroy"
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,12 +205,21 @@
|
||||||
"ShaderModuleGetCompilationInfo",
|
"ShaderModuleGetCompilationInfo",
|
||||||
"QueueOnSubmittedWorkDone",
|
"QueueOnSubmittedWorkDone",
|
||||||
"QueueWriteBuffer",
|
"QueueWriteBuffer",
|
||||||
"QueueWriteTexture"
|
"QueueWriteTexture",
|
||||||
|
"TextureGetWidth",
|
||||||
|
"TextureGetHeight",
|
||||||
|
"TextureGetDepthOrArrayLayers",
|
||||||
|
"TextureGetMipLevelCount",
|
||||||
|
"TextureGetSampleCount",
|
||||||
|
"TextureGetDimension",
|
||||||
|
"TextureGetFormat",
|
||||||
|
"TextureGetUsage"
|
||||||
],
|
],
|
||||||
"client_handwritten_commands": [
|
"client_handwritten_commands": [
|
||||||
"BufferDestroy",
|
"BufferDestroy",
|
||||||
"BufferUnmap",
|
"BufferUnmap",
|
||||||
"DeviceCreateErrorBuffer",
|
"DeviceCreateErrorBuffer",
|
||||||
|
"DeviceCreateTexture",
|
||||||
"DeviceGetQueue",
|
"DeviceGetQueue",
|
||||||
"DeviceInjectError"
|
"DeviceInjectError"
|
||||||
],
|
],
|
||||||
|
@ -220,7 +229,8 @@
|
||||||
"Device",
|
"Device",
|
||||||
"Instance",
|
"Instance",
|
||||||
"Queue",
|
"Queue",
|
||||||
"ShaderModule"
|
"ShaderModule",
|
||||||
|
"Texture"
|
||||||
],
|
],
|
||||||
"server_custom_pre_handler_commands": [
|
"server_custom_pre_handler_commands": [
|
||||||
"BufferDestroy",
|
"BufferDestroy",
|
||||||
|
|
|
@ -1209,7 +1209,7 @@ TextureBase* DeviceBase::APICreateTexture(const TextureDescriptor* descriptor) {
|
||||||
Ref<TextureBase> result;
|
Ref<TextureBase> result;
|
||||||
if (ConsumedError(CreateTexture(descriptor), &result, "calling %s.CreateTexture(%s).", this,
|
if (ConsumedError(CreateTexture(descriptor), &result, "calling %s.CreateTexture(%s).", this,
|
||||||
descriptor)) {
|
descriptor)) {
|
||||||
return TextureBase::MakeError(this);
|
return TextureBase::MakeError(this, descriptor);
|
||||||
}
|
}
|
||||||
return result.Detach();
|
return result.Detach();
|
||||||
}
|
}
|
||||||
|
|
|
@ -529,7 +529,8 @@ TextureBase::TextureBase(DeviceBase* device,
|
||||||
mSampleCount(descriptor->sampleCount),
|
mSampleCount(descriptor->sampleCount),
|
||||||
mUsage(descriptor->usage),
|
mUsage(descriptor->usage),
|
||||||
mInternalUsage(mUsage),
|
mInternalUsage(mUsage),
|
||||||
mState(state) {
|
mState(state),
|
||||||
|
mFormatEnumForReflection(descriptor->format) {
|
||||||
uint32_t subresourceCount = mMipLevelCount * GetArrayLayers() * GetAspectCount(mFormat.aspects);
|
uint32_t subresourceCount = mMipLevelCount * GetArrayLayers() * GetAspectCount(mFormat.aspects);
|
||||||
mIsSubresourceContentInitializedAtIndex = std::vector<bool>(subresourceCount, false);
|
mIsSubresourceContentInitializedAtIndex = std::vector<bool>(subresourceCount, false);
|
||||||
|
|
||||||
|
@ -559,16 +560,25 @@ TextureBase::TextureBase(DeviceBase* device, TextureState state)
|
||||||
TrackInDevice();
|
TrackInDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureBase::TextureBase(DeviceBase* device, ObjectBase::ErrorTag tag)
|
TextureBase::TextureBase(DeviceBase* device,
|
||||||
: ApiObjectBase(device, tag), mFormat(kUnusedFormat) {}
|
const TextureDescriptor* descriptor,
|
||||||
|
ObjectBase::ErrorTag tag)
|
||||||
|
: ApiObjectBase(device, tag),
|
||||||
|
mDimension(descriptor->dimension),
|
||||||
|
mFormat(kUnusedFormat),
|
||||||
|
mSize(descriptor->size),
|
||||||
|
mMipLevelCount(descriptor->mipLevelCount),
|
||||||
|
mSampleCount(descriptor->sampleCount),
|
||||||
|
mUsage(descriptor->usage),
|
||||||
|
mFormatEnumForReflection(descriptor->format) {}
|
||||||
|
|
||||||
void TextureBase::DestroyImpl() {
|
void TextureBase::DestroyImpl() {
|
||||||
mState = TextureState::Destroyed;
|
mState = TextureState::Destroyed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
TextureBase* TextureBase::MakeError(DeviceBase* device) {
|
TextureBase* TextureBase::MakeError(DeviceBase* device, const TextureDescriptor* descriptor) {
|
||||||
return new TextureBase(device, ObjectBase::kError);
|
return new TextureBase(device, descriptor, ObjectBase::kError);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectType TextureBase::GetType() const {
|
ObjectType TextureBase::GetType() const {
|
||||||
|
@ -767,6 +777,37 @@ void TextureBase::APIDestroy() {
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t TextureBase::APIGetWidth() const {
|
||||||
|
return mSize.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t TextureBase::APIGetHeight() const {
|
||||||
|
return mSize.height;
|
||||||
|
}
|
||||||
|
uint32_t TextureBase::APIGetDepthOrArrayLayers() const {
|
||||||
|
return mSize.depthOrArrayLayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t TextureBase::APIGetMipLevelCount() const {
|
||||||
|
return mMipLevelCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t TextureBase::APIGetSampleCount() const {
|
||||||
|
return mSampleCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
wgpu::TextureDimension TextureBase::APIGetDimension() const {
|
||||||
|
return mDimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
wgpu::TextureFormat TextureBase::APIGetFormat() const {
|
||||||
|
return mFormatEnumForReflection;
|
||||||
|
}
|
||||||
|
|
||||||
|
wgpu::TextureUsage TextureBase::APIGetUsage() const {
|
||||||
|
return mUsage;
|
||||||
|
}
|
||||||
|
|
||||||
MaybeError TextureBase::ValidateDestroy() const {
|
MaybeError TextureBase::ValidateDestroy() const {
|
||||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TextureBase : public ApiObjectBase {
|
||||||
enum class TextureState { OwnedInternal, OwnedExternal, Destroyed };
|
enum class TextureState { OwnedInternal, OwnedExternal, Destroyed };
|
||||||
enum class ClearValue { Zero, NonZero };
|
enum class ClearValue { Zero, NonZero };
|
||||||
|
|
||||||
static TextureBase* MakeError(DeviceBase* device);
|
static TextureBase* MakeError(DeviceBase* device, const TextureDescriptor* descriptor);
|
||||||
|
|
||||||
ObjectType GetType() const override;
|
ObjectType GetType() const override;
|
||||||
|
|
||||||
|
@ -96,6 +96,14 @@ class TextureBase : public ApiObjectBase {
|
||||||
// Dawn API
|
// Dawn API
|
||||||
TextureViewBase* APICreateView(const TextureViewDescriptor* descriptor = nullptr);
|
TextureViewBase* APICreateView(const TextureViewDescriptor* descriptor = nullptr);
|
||||||
void APIDestroy();
|
void APIDestroy();
|
||||||
|
uint32_t APIGetWidth() const;
|
||||||
|
uint32_t APIGetHeight() const;
|
||||||
|
uint32_t APIGetDepthOrArrayLayers() const;
|
||||||
|
uint32_t APIGetMipLevelCount() const;
|
||||||
|
uint32_t APIGetSampleCount() const;
|
||||||
|
wgpu::TextureDimension APIGetDimension() const;
|
||||||
|
wgpu::TextureFormat APIGetFormat() const;
|
||||||
|
wgpu::TextureUsage APIGetUsage() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TextureBase(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state);
|
TextureBase(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state);
|
||||||
|
@ -106,7 +114,7 @@ class TextureBase : public ApiObjectBase {
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextureBase(DeviceBase* device, ObjectBase::ErrorTag tag);
|
TextureBase(DeviceBase* device, const TextureDescriptor* descriptor, ObjectBase::ErrorTag tag);
|
||||||
|
|
||||||
MaybeError ValidateDestroy() const;
|
MaybeError ValidateDestroy() const;
|
||||||
wgpu::TextureDimension mDimension;
|
wgpu::TextureDimension mDimension;
|
||||||
|
@ -118,6 +126,7 @@ class TextureBase : public ApiObjectBase {
|
||||||
wgpu::TextureUsage mUsage = wgpu::TextureUsage::None;
|
wgpu::TextureUsage mUsage = wgpu::TextureUsage::None;
|
||||||
wgpu::TextureUsage mInternalUsage = wgpu::TextureUsage::None;
|
wgpu::TextureUsage mInternalUsage = wgpu::TextureUsage::None;
|
||||||
TextureState mState;
|
TextureState mState;
|
||||||
|
wgpu::TextureFormat mFormatEnumForReflection;
|
||||||
|
|
||||||
// TODO(crbug.com/dawn/845): Use a more optimized data structure to save space
|
// TODO(crbug.com/dawn/845): Use a more optimized data structure to save space
|
||||||
std::vector<bool> mIsSubresourceContentInitializedAtIndex;
|
std::vector<bool> mIsSubresourceContentInitializedAtIndex;
|
||||||
|
|
|
@ -204,6 +204,24 @@ TEST_F(TextureInternalUsageValidationTest, DeprecatedCommandValidation) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that the internal usages aren't reflected with wgpu::Texture::GetUsage.
|
||||||
|
TEST_F(TextureInternalUsageValidationTest, InternalUsagesAreNotReflected) {
|
||||||
|
wgpu::DawnTextureInternalUsageDescriptor internalDesc = {};
|
||||||
|
internalDesc.internalUsage = wgpu::TextureUsage::StorageBinding;
|
||||||
|
|
||||||
|
wgpu::TextureDescriptor textureDesc = {};
|
||||||
|
textureDesc.size = {1, 1};
|
||||||
|
textureDesc.usage = wgpu::TextureUsage::CopySrc;
|
||||||
|
textureDesc.format = wgpu::TextureFormat::RGBA8Unorm;
|
||||||
|
textureDesc.nextInChain = &internalDesc;
|
||||||
|
|
||||||
|
wgpu::Texture texture = device.CreateTexture(&textureDesc);
|
||||||
|
ASSERT_EQ(texture.GetUsage(), wgpu::TextureUsage::CopySrc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Test the validation of internal usages against command encoders with and without
|
||||||
|
// useInternalUsages.
|
||||||
TEST_F(TextureInternalUsageValidationTest, CommandValidation) {
|
TEST_F(TextureInternalUsageValidationTest, CommandValidation) {
|
||||||
wgpu::TextureDescriptor textureDesc = {};
|
wgpu::TextureDescriptor textureDesc = {};
|
||||||
textureDesc.size = {1, 1};
|
textureDesc.size = {1, 1};
|
||||||
|
|
|
@ -906,4 +906,64 @@ TEST_F(CompressedTextureFormatsValidationTests, TextureSize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void CheckTextureMatchesDescriptor(const wgpu::Texture& tex,
|
||||||
|
const wgpu::TextureDescriptor& desc) {
|
||||||
|
EXPECT_EQ(desc.size.width, tex.GetWidth());
|
||||||
|
EXPECT_EQ(desc.size.height, tex.GetHeight());
|
||||||
|
EXPECT_EQ(desc.size.depthOrArrayLayers, tex.GetDepthOrArrayLayers());
|
||||||
|
EXPECT_EQ(desc.mipLevelCount, tex.GetMipLevelCount());
|
||||||
|
EXPECT_EQ(desc.sampleCount, tex.GetSampleCount());
|
||||||
|
EXPECT_EQ(desc.dimension, tex.GetDimension());
|
||||||
|
EXPECT_EQ(desc.usage, tex.GetUsage());
|
||||||
|
EXPECT_EQ(desc.format, tex.GetFormat());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that the texture creation parameters are correctly reflected for succesfully created
|
||||||
|
// textures.
|
||||||
|
TEST_F(TextureValidationTest, CreationParameterReflectionForValidTextures) {
|
||||||
|
// Test reflection on two succesfully created but different textures.
|
||||||
|
{
|
||||||
|
wgpu::TextureDescriptor desc;
|
||||||
|
desc.size = {3, 2, 1};
|
||||||
|
desc.mipLevelCount = 1;
|
||||||
|
desc.sampleCount = 4;
|
||||||
|
desc.dimension = wgpu::TextureDimension::e2D;
|
||||||
|
desc.usage = wgpu::TextureUsage::RenderAttachment;
|
||||||
|
desc.format = wgpu::TextureFormat::RGBA8Unorm;
|
||||||
|
wgpu::Texture tex = device.CreateTexture(&desc);
|
||||||
|
|
||||||
|
CheckTextureMatchesDescriptor(tex, desc);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
wgpu::TextureDescriptor desc;
|
||||||
|
desc.size = {47, 32, 19};
|
||||||
|
desc.mipLevelCount = 3;
|
||||||
|
desc.sampleCount = 1;
|
||||||
|
desc.dimension = wgpu::TextureDimension::e3D;
|
||||||
|
desc.usage = wgpu::TextureUsage::TextureBinding;
|
||||||
|
desc.format = wgpu::TextureFormat::R32Float;
|
||||||
|
wgpu::Texture tex = device.CreateTexture(&desc);
|
||||||
|
|
||||||
|
CheckTextureMatchesDescriptor(tex, desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that the texture creation parameters are correctly reflected for error textures.
|
||||||
|
TEST_F(TextureValidationTest, CreationParameterReflectionForErrorTextures) {
|
||||||
|
// Fill a descriptor with a bunch of garbage values.
|
||||||
|
wgpu::TextureDescriptor desc;
|
||||||
|
desc.size = {0, 0xFFFF'FFFF, 1};
|
||||||
|
desc.mipLevelCount = 0;
|
||||||
|
desc.sampleCount = 42;
|
||||||
|
desc.dimension = static_cast<wgpu::TextureDimension>(0xFFFF'FF00);
|
||||||
|
desc.usage = static_cast<wgpu::TextureUsage>(0xFFFF'FFFF);
|
||||||
|
desc.format = static_cast<wgpu::TextureFormat>(0xFFFF'FFF0);
|
||||||
|
|
||||||
|
// Error! Because the texture width is 0.
|
||||||
|
wgpu::Texture tex;
|
||||||
|
ASSERT_DEVICE_ERROR(tex = device.CreateTexture(&desc));
|
||||||
|
|
||||||
|
CheckTextureMatchesDescriptor(tex, desc);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -96,6 +96,8 @@ dawn_component("wire") {
|
||||||
"client/RequestTracker.h",
|
"client/RequestTracker.h",
|
||||||
"client/ShaderModule.cpp",
|
"client/ShaderModule.cpp",
|
||||||
"client/ShaderModule.h",
|
"client/ShaderModule.h",
|
||||||
|
"client/Texture.cpp",
|
||||||
|
"client/Texture.h",
|
||||||
"server/ObjectStorage.h",
|
"server/ObjectStorage.h",
|
||||||
"server/Server.cpp",
|
"server/Server.cpp",
|
||||||
"server/Server.h",
|
"server/Server.h",
|
||||||
|
|
|
@ -69,6 +69,8 @@ target_sources(dawn_wire PRIVATE
|
||||||
"client/RequestTracker.h"
|
"client/RequestTracker.h"
|
||||||
"client/ShaderModule.cpp"
|
"client/ShaderModule.cpp"
|
||||||
"client/ShaderModule.h"
|
"client/ShaderModule.h"
|
||||||
|
"client/Texture.cpp"
|
||||||
|
"client/Texture.h"
|
||||||
"server/ObjectStorage.h"
|
"server/ObjectStorage.h"
|
||||||
"server/Server.cpp"
|
"server/Server.cpp"
|
||||||
"server/Server.h"
|
"server/Server.h"
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "dawn/wire/client/Instance.h"
|
#include "dawn/wire/client/Instance.h"
|
||||||
#include "dawn/wire/client/Queue.h"
|
#include "dawn/wire/client/Queue.h"
|
||||||
#include "dawn/wire/client/ShaderModule.h"
|
#include "dawn/wire/client/ShaderModule.h"
|
||||||
|
#include "dawn/wire/client/Texture.h"
|
||||||
|
|
||||||
#include "dawn/wire/client/ApiObjects_autogen.h"
|
#include "dawn/wire/client/ApiObjects_autogen.h"
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,10 @@ WGPUBuffer Device::CreateErrorBuffer() {
|
||||||
return Buffer::CreateError(this, &fakeDescriptor);
|
return Buffer::CreateError(this, &fakeDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WGPUTexture Device::CreateTexture(const WGPUTextureDescriptor* descriptor) {
|
||||||
|
return Texture::Create(this, descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
WGPUQueue Device::GetQueue() {
|
WGPUQueue Device::GetQueue() {
|
||||||
// The queue is lazily created because if a Device is created by
|
// The queue is lazily created because if a Device is created by
|
||||||
// Reserve/Inject, we cannot send the GetQueue message until
|
// Reserve/Inject, we cannot send the GetQueue message until
|
||||||
|
|
|
@ -50,6 +50,7 @@ class Device final : public ObjectBase {
|
||||||
void CreateRenderPipelineAsync(WGPURenderPipelineDescriptor const* descriptor,
|
void CreateRenderPipelineAsync(WGPURenderPipelineDescriptor const* descriptor,
|
||||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||||
void* userdata);
|
void* userdata);
|
||||||
|
WGPUTexture CreateTexture(const WGPUTextureDescriptor* descriptor);
|
||||||
|
|
||||||
void HandleError(WGPUErrorType errorType, const char* message);
|
void HandleError(WGPUErrorType errorType, const char* message);
|
||||||
void HandleLogging(WGPULoggingType loggingType, const char* message);
|
void HandleLogging(WGPULoggingType loggingType, const char* message);
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
// Copyright 2022 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/wire/client/Texture.h"
|
||||||
|
|
||||||
|
#include "dawn/wire/client/Client.h"
|
||||||
|
#include "dawn/wire/client/Device.h"
|
||||||
|
|
||||||
|
namespace dawn::wire::client {
|
||||||
|
|
||||||
|
// static
|
||||||
|
WGPUTexture Texture::Create(Device* device, const WGPUTextureDescriptor* descriptor) {
|
||||||
|
Client* wireClient = device->client;
|
||||||
|
auto* textureObjectAndSerial = wireClient->TextureAllocator().New(wireClient);
|
||||||
|
|
||||||
|
// Copy over descriptor data for reflection.
|
||||||
|
Texture* texture = textureObjectAndSerial->object.get();
|
||||||
|
texture->mSize = descriptor->size;
|
||||||
|
texture->mMipLevelCount = descriptor->mipLevelCount;
|
||||||
|
texture->mSampleCount = descriptor->sampleCount;
|
||||||
|
texture->mDimension = descriptor->dimension;
|
||||||
|
texture->mFormat = descriptor->format;
|
||||||
|
texture->mUsage = static_cast<WGPUTextureUsage>(descriptor->usage);
|
||||||
|
|
||||||
|
// Send the Device::CreateTexture command without modifications.
|
||||||
|
DeviceCreateTextureCmd cmd;
|
||||||
|
cmd.self = ToAPI(device);
|
||||||
|
cmd.selfId = device->id;
|
||||||
|
cmd.descriptor = descriptor;
|
||||||
|
cmd.result = ObjectHandle{texture->id, textureObjectAndSerial->generation};
|
||||||
|
wireClient->SerializeCommand(cmd);
|
||||||
|
|
||||||
|
return ToAPI(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture::Texture(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
|
||||||
|
Texture::~Texture() = default;
|
||||||
|
|
||||||
|
uint32_t Texture::GetWidth() const {
|
||||||
|
return mSize.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Texture::GetHeight() const {
|
||||||
|
return mSize.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Texture::GetDepthOrArrayLayers() const {
|
||||||
|
return mSize.depthOrArrayLayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Texture::GetMipLevelCount() const {
|
||||||
|
return mMipLevelCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Texture::GetSampleCount() const {
|
||||||
|
return mSampleCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
WGPUTextureDimension Texture::GetDimension() const {
|
||||||
|
return mDimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
WGPUTextureFormat Texture::GetFormat() const {
|
||||||
|
return mFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
WGPUTextureUsage Texture::GetUsage() const {
|
||||||
|
return mUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dawn::wire::client
|
|
@ -0,0 +1,54 @@
|
||||||
|
// Copyright 2022 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 SRC_DAWN_WIRE_CLIENT_TEXTURE_H_
|
||||||
|
#define SRC_DAWN_WIRE_CLIENT_TEXTURE_H_
|
||||||
|
|
||||||
|
#include "dawn/webgpu.h"
|
||||||
|
|
||||||
|
#include "dawn/wire/client/ObjectBase.h"
|
||||||
|
|
||||||
|
namespace dawn::wire::client {
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
|
||||||
|
class Texture final : public ObjectBase {
|
||||||
|
public:
|
||||||
|
static WGPUTexture Create(Device* device, const WGPUTextureDescriptor* descriptor);
|
||||||
|
|
||||||
|
Texture(Client* client, uint32_t refcount, uint32_t id);
|
||||||
|
~Texture();
|
||||||
|
|
||||||
|
// Note that these values can be arbitrary since they aren't validated in the wire client.
|
||||||
|
uint32_t GetWidth() const;
|
||||||
|
uint32_t GetHeight() const;
|
||||||
|
uint32_t GetDepthOrArrayLayers() const;
|
||||||
|
uint32_t GetMipLevelCount() const;
|
||||||
|
uint32_t GetSampleCount() const;
|
||||||
|
WGPUTextureDimension GetDimension() const;
|
||||||
|
WGPUTextureFormat GetFormat() const;
|
||||||
|
WGPUTextureUsage GetUsage() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
WGPUExtent3D mSize;
|
||||||
|
uint32_t mMipLevelCount;
|
||||||
|
uint32_t mSampleCount;
|
||||||
|
WGPUTextureDimension mDimension;
|
||||||
|
WGPUTextureFormat mFormat;
|
||||||
|
WGPUTextureUsage mUsage;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dawn::wire::client
|
||||||
|
|
||||||
|
#endif // SRC_DAWN_WIRE_CLIENT_TEXTURE_H_
|
Loading…
Reference in New Issue