• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // VulkanDescriptorSetTest:
7 //   Various tests related for Vulkan descriptor sets.
8 //
9 
10 #include "test_utils/ANGLETest.h"
11 #include "test_utils/gl_raii.h"
12 
13 #include "libANGLE/Context.h"
14 #include "libANGLE/angletypes.h"
15 #include "libANGLE/renderer/vulkan/ContextVk.h"
16 #include "libANGLE/renderer/vulkan/ProgramVk.h"
17 #include "libANGLE/renderer/vulkan/vk_helpers.h"
18 
19 using namespace angle;
20 
21 namespace
22 {
23 
24 class VulkanDescriptorSetTest : public ANGLETest
25 {
26   protected:
VulkanDescriptorSetTest()27     VulkanDescriptorSetTest() {}
28 
testSetUp()29     void testSetUp() override
30     {
31         mMaxSetsPerPool = rx::vk::DynamicDescriptorPool::GetMaxSetsPerPoolForTesting();
32         mMaxSetsPerPoolMultiplier =
33             rx::vk::DynamicDescriptorPool::GetMaxSetsPerPoolMultiplierForTesting();
34     }
35 
testTearDown()36     void testTearDown() override
37     {
38         rx::vk::DynamicDescriptorPool::SetMaxSetsPerPoolForTesting(mMaxSetsPerPool);
39         rx::vk::DynamicDescriptorPool::SetMaxSetsPerPoolMultiplierForTesting(
40             mMaxSetsPerPoolMultiplier);
41     }
42 
43     static constexpr uint32_t kMaxSetsForTesting           = 1;
44     static constexpr uint32_t kMaxSetsMultiplierForTesting = 1;
45 
limitMaxSets()46     void limitMaxSets()
47     {
48         rx::vk::DynamicDescriptorPool::SetMaxSetsPerPoolForTesting(kMaxSetsForTesting);
49         rx::vk::DynamicDescriptorPool::SetMaxSetsPerPoolMultiplierForTesting(
50             kMaxSetsMultiplierForTesting);
51     }
52 
53   private:
54     uint32_t mMaxSetsPerPool;
55     uint32_t mMaxSetsPerPoolMultiplier;
56 };
57 
58 // Test atomic counter read.
TEST_P(VulkanDescriptorSetTest,AtomicCounterReadLimitedDescriptorPool)59 TEST_P(VulkanDescriptorSetTest, AtomicCounterReadLimitedDescriptorPool)
60 {
61     // Skipping test while we work on enabling atomic counter buffer support in th D3D renderer.
62     // http://anglebug.com/1729
63     ANGLE_SKIP_TEST_IF(IsD3D11());
64 
65     // Must be before program creation to limit the descriptor pool sizes when creating the pipeline
66     // layout.
67     limitMaxSets();
68 
69     constexpr char kFS[] =
70         "#version 310 es\n"
71         "precision highp float;\n"
72         "layout(binding = 0, offset = 4) uniform atomic_uint ac;\n"
73         "out highp vec4 my_color;\n"
74         "void main()\n"
75         "{\n"
76         "    my_color = vec4(0.0);\n"
77         "    uint a1 = atomicCounter(ac);\n"
78         "    if (a1 == 3u) my_color = vec4(1.0);\n"
79         "}\n";
80 
81     ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS);
82 
83     glUseProgram(program.get());
84 
85     // The initial value of counter 'ac' is 3u.
86     unsigned int bufferData[3] = {11u, 3u, 1u};
87     GLBuffer atomicCounterBuffer;
88     glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffer);
89     glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomicCounterBuffer);
90 
91     for (int i = 0; i < 5; ++i)
92     {
93         glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(bufferData), bufferData, GL_STATIC_DRAW);
94         drawQuad(program.get(), essl31_shaders::PositionAttrib(), 0.0f);
95         ASSERT_GL_NO_ERROR();
96         EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
97     }
98 }
99 
100 ANGLE_INSTANTIATE_TEST(VulkanDescriptorSetTest, ES31_VULKAN(), ES31_VULKAN_SWIFTSHADER());
101 
102 }  // namespace
103