Add Device.CreateErrorExternalTexture()

Creating GPUExternalTexture from destroyed device should return
an error external texture instead of a valid one. Adding this API
for such usage.

Bug: 1336713, 1338182
Change-Id: Ie7d13811a9c1e8890ba91045c88af63f3fb09687
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94534
Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Yan,Shaobo 2022-06-27 02:57:40 +00:00 committed by Dawn LUCI CQ
parent 54b3da95f8
commit 7ce3c2da35
5 changed files with 37 additions and 1 deletions

View File

@ -1022,6 +1022,11 @@
{"name": "external texture descriptor", "type": "external texture descriptor", "annotation": "const*"}
]
},
{
"name": "create error external texture",
"returns": "external texture",
"tags": ["dawn"]
},
{
"name": "create pipeline layout",
"returns": "pipeline layout",

View File

@ -1222,6 +1222,10 @@ BufferBase* DeviceBase::APICreateErrorBuffer() {
return BufferBase::MakeError(this, &desc);
}
ExternalTextureBase* DeviceBase::APICreateErrorExternalTexture() {
return ExternalTextureBase::MakeError(this);
}
// Other Device API methods
// Returns true if future ticking is needed.

View File

@ -264,6 +264,8 @@ class DeviceBase : public RefCountedWithExternalCount {
// For Dawn Wire
BufferBase* APICreateErrorBuffer();
ExternalTextureBase* APICreateErrorExternalTexture();
QueueBase* APIGetQueue();
bool APIGetLimits(SupportedLimits* limits) const;

View File

@ -123,8 +123,9 @@ ExternalTextureBase::ExternalTextureBase(DeviceBase* device)
TrackInDevice();
}
// Error external texture cannot be used in bind group.
ExternalTextureBase::ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag) {}
: ApiObjectBase(device, tag), mState(ExternalTextureState::Destroyed) {}
ExternalTextureBase::~ExternalTextureBase() = default;

View File

@ -541,4 +541,28 @@ TEST_F(ExternalTextureTest, BindGroupDoesNotMatchLayout) {
}
}
// Ensure that bind group validation catches error external textures.
TEST_F(ExternalTextureTest, UseErrorExternalTextureInBindGroup) {
// Control case should succeed.
{
wgpu::TextureDescriptor textureDescriptor = CreateTextureDescriptor();
wgpu::Texture texture = device.CreateTexture(&textureDescriptor);
wgpu::ExternalTextureDescriptor externalDesc = CreateDefaultExternalTextureDescriptor();
externalDesc.plane0 = texture.CreateView();
wgpu::ExternalTexture externalTexture = device.CreateExternalTexture(&externalDesc);
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, &utils::kExternalTextureBindingLayout}});
utils::MakeBindGroup(device, bgl, {{0, externalTexture}});
}
// Bind group creation should fail when an error external texture is present.
{
wgpu::ExternalTexture errorExternalTexture = device.CreateErrorExternalTexture();
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, &utils::kExternalTextureBindingLayout}});
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, bgl, {{0, errorExternalTexture}}));
}
}
} // namespace