mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 00:47:13 +00:00
Destroy frontend and backend for Textures
Same idea as for buffers, Destroy can be used to free GPU memory associated with resources without waiting for javascript garbage collection to occur. Bug: dawn:46 Change-Id: Ia796b06b5228cbec4cfe8d78a500f967181d8c1f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5540 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Natasha Lee <natlee@microsoft.com>
This commit is contained in:
committed by
Commit Bot service account
parent
889d743baa
commit
cae68ff846
@@ -15,35 +15,39 @@
|
||||
#include "tests/unittests/validation/ValidationTest.h"
|
||||
|
||||
#include "common/Constants.h"
|
||||
#include "utils/ComboRenderPipelineDescriptor.h"
|
||||
#include "utils/DawnHelpers.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class TextureValidationTest : public ValidationTest {
|
||||
protected:
|
||||
dawn::TextureDescriptor CreateDefaultTextureDescriptor() {
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.size.width = kWidth;
|
||||
descriptor.size.height = kHeight;
|
||||
descriptor.size.depth = 1;
|
||||
descriptor.arrayLayerCount = kDefaultArraySize;
|
||||
descriptor.mipLevelCount = kDefaultMipLevels;
|
||||
descriptor.sampleCount = kDefaultSampleCount;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.format = kDefaultTextureFormat;
|
||||
descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::Sampled;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
dawn::Queue queue = device.CreateQueue();
|
||||
|
||||
private:
|
||||
static constexpr uint32_t kWidth = 32;
|
||||
static constexpr uint32_t kHeight = 32;
|
||||
static constexpr uint32_t kDefaultArraySize = 1;
|
||||
static constexpr uint32_t kDefaultMipLevels = 1;
|
||||
static constexpr uint32_t kDefaultSampleCount = 1;
|
||||
|
||||
static constexpr dawn::TextureFormat kDefaultTextureFormat = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
};
|
||||
|
||||
constexpr uint32_t kWidth = 32;
|
||||
constexpr uint32_t kHeight = 32;
|
||||
constexpr uint32_t kDefaultArraySize = 1;
|
||||
constexpr uint32_t kDefaultMipLevels = 1;
|
||||
constexpr uint32_t kDefaultSampleCount = 1;
|
||||
|
||||
constexpr dawn::TextureFormat kDefaultTextureFormat = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
|
||||
dawn::TextureDescriptor CreateDefaultTextureDescriptor() {
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.size.width = kWidth;
|
||||
descriptor.size.height = kHeight;
|
||||
descriptor.size.depth = 1;
|
||||
descriptor.arrayLayerCount = kDefaultArraySize;
|
||||
descriptor.mipLevelCount = kDefaultMipLevels;
|
||||
descriptor.sampleCount = kDefaultSampleCount;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.format = kDefaultTextureFormat;
|
||||
descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::Sampled;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
// Test the validation of sample count
|
||||
TEST_F(TextureValidationTest, SampleCount) {
|
||||
dawn::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
|
||||
@@ -81,4 +85,65 @@ TEST_F(TextureValidationTest, SampleCount) {
|
||||
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
// Test that it is valid to destroy a texture
|
||||
TEST_F(TextureValidationTest, DestroyTexture) {
|
||||
dawn::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
|
||||
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||
texture.Destroy();
|
||||
}
|
||||
|
||||
// Test that it's valid to destroy a destroyed texture
|
||||
TEST_F(TextureValidationTest, DestroyDestroyedTexture) {
|
||||
dawn::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
|
||||
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||
texture.Destroy();
|
||||
texture.Destroy();
|
||||
}
|
||||
|
||||
// Test that it's invalid to submit a destroyed texture in a queue
|
||||
// in the case of destroy, encode, submit
|
||||
TEST_F(TextureValidationTest, DestroyEncodeSubmit) {
|
||||
dawn::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
|
||||
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||
dawn::TextureView textureView = texture.CreateDefaultTextureView();
|
||||
|
||||
utils::ComboRenderPassDescriptor renderPass({textureView});
|
||||
|
||||
// Destroy the texture
|
||||
texture.Destroy();
|
||||
|
||||
dawn::CommandEncoder encoder_post_destroy = device.CreateCommandEncoder();
|
||||
{
|
||||
dawn::RenderPassEncoder pass = encoder_post_destroy.BeginRenderPass(&renderPass);
|
||||
pass.EndPass();
|
||||
}
|
||||
dawn::CommandBuffer commands = encoder_post_destroy.Finish();
|
||||
|
||||
// Submit should fail due to destroyed texture
|
||||
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
|
||||
}
|
||||
|
||||
// Test that it's invalid to submit a destroyed texture in a queue
|
||||
// in the case of encode, destroy, submit
|
||||
TEST_F(TextureValidationTest, EncodeDestroySubmit) {
|
||||
dawn::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
|
||||
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||
dawn::TextureView textureView = texture.CreateDefaultTextureView();
|
||||
|
||||
utils::ComboRenderPassDescriptor renderPass({textureView});
|
||||
|
||||
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
{
|
||||
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
|
||||
pass.EndPass();
|
||||
}
|
||||
dawn::CommandBuffer commands = encoder.Finish();
|
||||
|
||||
// Destroy the texture
|
||||
texture.Destroy();
|
||||
|
||||
// Submit should fail due to destroyed texture
|
||||
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -242,4 +242,12 @@ TEST_F(TextureViewValidationTest, TextureViewFormatCompatibility) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test that it's invalid to create a texture view from a destroyed texture
|
||||
TEST_F(TextureViewValidationTest, DestroyCreateTextureView) {
|
||||
dawn::Texture texture = Create2DArrayTexture(device, 1);
|
||||
dawn::TextureViewDescriptor descriptor =
|
||||
CreateDefaultTextureViewDescriptor(dawn::TextureViewDimension::e2D);
|
||||
texture.Destroy();
|
||||
ASSERT_DEVICE_ERROR(texture.CreateTextureView(&descriptor));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user