• 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 // VulkanFramebufferTest:
7 //   Tests to validate our Vulkan framebuffer image allocation.
8 //
9 
10 #include "test_utils/ANGLETest.h"
11 #include "test_utils/angle_test_instantiate.h"
12 // 'None' is defined as 'struct None {};' in
13 // third_party/googletest/src/googletest/include/gtest/internal/gtest-type-util.h.
14 // But 'None' is also defined as a numeric constant 0L in <X11/X.h>.
15 // So we need to include ANGLETest.h first to avoid this conflict.
16 
17 #include "libANGLE/Context.h"
18 #include "libANGLE/angletypes.h"
19 #include "libANGLE/renderer/vulkan/ContextVk.h"
20 #include "libANGLE/renderer/vulkan/ProgramVk.h"
21 #include "libANGLE/renderer/vulkan/TextureVk.h"
22 #include "test_utils/gl_raii.h"
23 #include "util/EGLWindow.h"
24 #include "util/shader_utils.h"
25 
26 using namespace angle;
27 
28 namespace
29 {
30 
31 class VulkanFramebufferTest : public ANGLETest
32 {
33   protected:
hackANGLE() const34     rx::ContextVk *hackANGLE() const
35     {
36         // Hack the angle!
37         const gl::Context *context = static_cast<gl::Context *>(getEGLWindow()->getContext());
38         return rx::GetImplAs<rx::ContextVk>(context);
39     }
40 
hackTexture(GLuint handle) const41     rx::TextureVk *hackTexture(GLuint handle) const
42     {
43         // Hack the angle!
44         const gl::Context *context = static_cast<gl::Context *>(getEGLWindow()->getContext());
45         const gl::Texture *texture = context->getTexture({handle});
46         return rx::vk::GetImpl(texture);
47     }
48 };
49 
50 // Test that framebuffer can be created from a mip-incomplete texture, and that its allocation only
51 // includes the framebuffer's attached mip.
TEST_P(VulkanFramebufferTest,TextureAttachmentMipIncomplete)52 TEST_P(VulkanFramebufferTest, TextureAttachmentMipIncomplete)
53 {
54     GLFramebuffer framebuffer;
55     glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
56 
57     GLTexture texture;
58     glBindTexture(GL_TEXTURE_2D, texture);
59 
60     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 100, 100, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
61     glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
62     glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 5, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
63 
64     // Set framebuffer to mip 0.  Framebuffer should be complete, and make the texture allocate
65     // an image of only 1 level.
66     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
67     EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
68 
69     glClearColor(0, 0, 0, 1.0f);
70     glClear(GL_COLOR_BUFFER_BIT);
71     EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
72 
73     // http://anglebug.com/4686: The Vulkan backend is allocating three mips of sizes 100x100,
74     // 50x50 and 25x25 instead of one mip of size 100x100.
75     ANGLE_SKIP_TEST_IF(IsVulkan());
76 
77     rx::TextureVk *textureVk = hackTexture(texture);
78     EXPECT_EQ(textureVk->getImage().getLevelCount(), 1u);
79 }
80 
81 ANGLE_INSTANTIATE_TEST(VulkanFramebufferTest, ES3_VULKAN());
82 
83 }  // anonymous namespace
84