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
@@ -19,7 +19,7 @@
|
||||
|
||||
constexpr uint32_t kRTSize = 4;
|
||||
|
||||
class DestroyBufferTest : public DawnTest {
|
||||
class DestroyTest : public DawnTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
DawnTest::SetUp();
|
||||
@@ -96,7 +96,7 @@ class DestroyBufferTest : public DawnTest {
|
||||
};
|
||||
|
||||
// Destroy before submit will result in error, and nothing drawn
|
||||
TEST_P(DestroyBufferTest, DestroyBeforeSubmit) {
|
||||
TEST_P(DestroyTest, BufferDestroyBeforeSubmit) {
|
||||
RGBA8 notFilled(0, 0, 0, 0);
|
||||
|
||||
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
|
||||
@@ -107,7 +107,7 @@ TEST_P(DestroyBufferTest, DestroyBeforeSubmit) {
|
||||
}
|
||||
|
||||
// Destroy after submit will draw successfully
|
||||
TEST_P(DestroyBufferTest, DestroyAfterSubmit) {
|
||||
TEST_P(DestroyTest, BufferDestroyAfterSubmit) {
|
||||
RGBA8 filled(0, 255, 0, 255);
|
||||
|
||||
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
|
||||
@@ -119,7 +119,7 @@ TEST_P(DestroyBufferTest, DestroyAfterSubmit) {
|
||||
|
||||
// First submit succeeds, draws triangle, second submit fails
|
||||
// after destroy is called on the buffer, pixel does not change
|
||||
TEST_P(DestroyBufferTest, SubmitDestroySubmit) {
|
||||
TEST_P(DestroyTest, BufferSubmitDestroySubmit) {
|
||||
RGBA8 filled(0, 255, 0, 255);
|
||||
|
||||
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
|
||||
@@ -135,4 +135,37 @@ TEST_P(DestroyBufferTest, SubmitDestroySubmit) {
|
||||
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(DestroyBufferTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);
|
||||
// Destroy texture before submit should fail submit
|
||||
TEST_P(DestroyTest, TextureDestroyBeforeSubmit) {
|
||||
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
|
||||
renderPass.color.Destroy();
|
||||
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
|
||||
}
|
||||
|
||||
// Destroy after submit will draw successfully
|
||||
TEST_P(DestroyTest, TextureDestroyAfterSubmit) {
|
||||
RGBA8 filled(0, 255, 0, 255);
|
||||
|
||||
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
|
||||
queue.Submit(1, &commands);
|
||||
|
||||
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
|
||||
renderPass.color.Destroy();
|
||||
}
|
||||
|
||||
// First submit succeeds, draws triangle, second submit fails
|
||||
// after destroy is called on the texture
|
||||
TEST_P(DestroyTest, TextureSubmitDestroySubmit) {
|
||||
RGBA8 filled(0, 255, 0, 255);
|
||||
|
||||
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
|
||||
queue.Submit(1, &commands);
|
||||
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
|
||||
|
||||
renderPass.color.Destroy();
|
||||
|
||||
// Submit fails because texture was destroyed
|
||||
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(DestroyTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);
|
||||
@@ -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