• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "tests/DawnTest.h"
16 
17 #include "utils/ComboRenderPipelineDescriptor.h"
18 #include "utils/DawnHelpers.h"
19 
20 class NonzeroTextureCreationTests : public DawnTest {
21   protected:
SetUp()22     void SetUp() override {
23         DawnTest::SetUp();
24     }
25 
26     constexpr static uint32_t kSize = 128;
27 };
28 
29 // Test that texture clears to 1's because toggle is enabled.
TEST_P(NonzeroTextureCreationTests,TextureCreationClearsOneBits)30 TEST_P(NonzeroTextureCreationTests, TextureCreationClearsOneBits) {
31     dawn::TextureDescriptor descriptor;
32     descriptor.dimension = dawn::TextureDimension::e2D;
33     descriptor.size.width = kSize;
34     descriptor.size.height = kSize;
35     descriptor.size.depth = 1;
36     descriptor.arrayLayerCount = 1;
37     descriptor.sampleCount = 1;
38     descriptor.format = dawn::TextureFormat::RGBA8Unorm;
39     descriptor.mipLevelCount = 1;
40     descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::CopySrc;
41     dawn::Texture texture = device.CreateTexture(&descriptor);
42 
43     RGBA8 filledWithOnes(255, 255, 255, 255);
44     EXPECT_PIXEL_RGBA8_EQ(filledWithOnes, texture, 0, 0);
45 }
46 
47 // Test that non-zero mip level clears to 1's because toggle is enabled.
TEST_P(NonzeroTextureCreationTests,MipMapClears)48 TEST_P(NonzeroTextureCreationTests, MipMapClears) {
49     constexpr uint32_t mipLevels = 4;
50 
51     dawn::TextureDescriptor descriptor;
52     descriptor.dimension = dawn::TextureDimension::e2D;
53     descriptor.size.width = kSize;
54     descriptor.size.height = kSize;
55     descriptor.size.depth = 1;
56     descriptor.arrayLayerCount = 1;
57     descriptor.sampleCount = 1;
58     descriptor.format = dawn::TextureFormat::RGBA8Unorm;
59     descriptor.mipLevelCount = mipLevels;
60     descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::CopySrc;
61     dawn::Texture texture = device.CreateTexture(&descriptor);
62 
63     std::vector<RGBA8> expected;
64     RGBA8 filledWithOnes(255, 255, 255, 255);
65     for (uint32_t i = 0; i < kSize * kSize; ++i) {
66         expected.push_back(filledWithOnes);
67     }
68     uint32_t mipSize = kSize >> 2;
69     EXPECT_TEXTURE_RGBA8_EQ(expected.data(), texture, 0, 0, mipSize, mipSize, 2, 0);
70 }
71 
72 // Test that non-zero array layers clears to 1's because toggle is enabled.
TEST_P(NonzeroTextureCreationTests,ArrayLayerClears)73 TEST_P(NonzeroTextureCreationTests, ArrayLayerClears) {
74     constexpr uint32_t arrayLayers = 4;
75 
76     dawn::TextureDescriptor descriptor;
77     descriptor.dimension = dawn::TextureDimension::e2D;
78     descriptor.size.width = kSize;
79     descriptor.size.height = kSize;
80     descriptor.size.depth = 1;
81     descriptor.arrayLayerCount = arrayLayers;
82     descriptor.sampleCount = 1;
83     descriptor.format = dawn::TextureFormat::RGBA8Unorm;
84     descriptor.mipLevelCount = 1;
85     descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::CopySrc;
86     dawn::Texture texture = device.CreateTexture(&descriptor);
87 
88     std::vector<RGBA8> expected;
89     RGBA8 filledWithOnes(255, 255, 255, 255);
90     for (uint32_t i = 0; i < kSize * kSize; ++i) {
91         expected.push_back(filledWithOnes);
92     }
93 
94     EXPECT_TEXTURE_RGBA8_EQ(expected.data(), texture, 0, 0, kSize, kSize, 0, 2);
95 }
96 
97 DAWN_INSTANTIATE_TEST(NonzeroTextureCreationTests,
98                       ForceWorkarounds(D3D12Backend,
99                                        {"nonzero_clear_resources_on_creation_for_testing"},
100                                        {"lazy_clear_resource_on_first_use"}),
101                       ForceWorkarounds(OpenGLBackend,
102                                        {"nonzero_clear_resources_on_creation_for_testing"},
103                                        {"lazy_clear_resource_on_first_use"}),
104                       ForceWorkarounds(VulkanBackend,
105                                        {"nonzero_clear_resources_on_creation_for_testing"},
106                                        {"lazy_clear_resource_on_first_use"}));
107