Support BC formats as the first extension in Dawn

This patch refactors the current implementation of BC formats to treat
it as the first extension in Dawn and adds all the related tests.

Note that in Dawn all the extensions are disabled unless we enable them
when we create the device, which means the BC formats can only be used
when we enable the related extension on the creation of the device, and
the creation of the device will fail if the adapter does not support the
extension

BUG=dawn:42
TEST=dawn_end2end_tests
TEST=dawn_unittests

Change-Id: I04d818b0218ebb3b1b7a70a4fea71779f308f85f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9520
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Jiawei Shao
2019-08-02 00:06:38 +00:00
committed by Commit Bot service account
parent 56f3a7b90d
commit 574b951188
28 changed files with 566 additions and 43 deletions

View File

@@ -1155,6 +1155,11 @@ TEST_F(CopyCommandTest_T2T, CopyToMipmapOfNonSquareTexture) {
}
class CopyCommandTest_CompressedTextureFormats : public CopyCommandTest {
public:
CopyCommandTest_CompressedTextureFormats() : CopyCommandTest() {
device = CreateDeviceFromAdapter(adapter, {"texture_compression_bc"});
}
protected:
dawn::Texture Create2DTexture(dawn::TextureFormat format,
uint32_t mipmapLevels = 1,

View File

@@ -250,10 +250,14 @@ TEST_F(TextureValidationTest, NonRenderableAndOutputAttachment) {
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// TODO(jiawei.shao@intel.com): use compressed texture formats as extensions.
// TODO(jiawei.shao@intel.com): add tests to verify we cannot create 1D or 3D textures with
// compressed texture formats.
class CompressedTextureFormatsValidationTests : public TextureValidationTest {
public:
CompressedTextureFormatsValidationTests() : TextureValidationTest() {
device = CreateDeviceFromAdapter(adapter, {"texture_compression_bc"});
}
protected:
dawn::TextureDescriptor CreateDefaultTextureDescriptor() {
dawn::TextureDescriptor descriptor =
@@ -309,6 +313,18 @@ TEST_F(CompressedTextureFormatsValidationTests, TextureSize) {
}
}
// Test the creation of a texture with BC format will fail when the extension textureCompressionBC
// is not enabled.
TEST_F(CompressedTextureFormatsValidationTests, UseBCFormatWithoutEnablingExtension) {
const std::vector<const char*> kEmptyVector;
dawn::Device deviceWithoutExtension = CreateDeviceFromAdapter(adapter, kEmptyVector);
for (dawn::TextureFormat format : kBCFormats) {
dawn::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = format;
ASSERT_DEVICE_ERROR(deviceWithoutExtension.CreateTexture(&descriptor));
}
}
// Test the validation of texture usages when creating textures in compressed texture formats.
TEST_F(CompressedTextureFormatsValidationTests, TextureUsage) {
// Test that only CopySrc, CopyDst and Sampled are accepted as the texture usage of the

View File

@@ -35,12 +35,29 @@ ValidationTest::ValidationTest() {
}
ASSERT(foundNullAdapter);
device = dawn::Device::Acquire(adapter.CreateDevice());
DawnProcTable procs = dawn_native::GetProcs();
dawnSetProcs(&procs);
device.SetErrorCallback(ValidationTest::OnDeviceError, this);
device = CreateDeviceFromAdapter(adapter, std::vector<const char*>());
}
dawn::Device ValidationTest::CreateDeviceFromAdapter(
dawn_native::Adapter adapterToTest,
const std::vector<const char*>& requiredExtensions) {
dawn::Device deviceToTest;
// Always keep the code path to test creating a device without a device descriptor.
if (requiredExtensions.empty()) {
deviceToTest = dawn::Device::Acquire(adapterToTest.CreateDevice());
} else {
dawn_native::DeviceDescriptor descriptor;
descriptor.requiredExtensions = requiredExtensions;
deviceToTest = dawn::Device::Acquire(adapterToTest.CreateDevice(&descriptor));
}
deviceToTest.SetErrorCallback(ValidationTest::OnDeviceError, this);
return deviceToTest;
}
ValidationTest::~ValidationTest() {

View File

@@ -29,6 +29,9 @@ class ValidationTest : public testing::Test {
ValidationTest();
~ValidationTest();
dawn::Device CreateDeviceFromAdapter(dawn_native::Adapter adapter,
const std::vector<const char*>& requiredExtensions);
void TearDown() override;
void StartExpectDeviceError();