Commit b79e7bb6 by Jamie Madill

Vulkan: Implement simple render-to-texture.

This was mostly working already, just needed to set up a few entry points. BUG=angleproject:2200 Change-Id: I9c13d6d4dd42f23c69a58e42e07e3e28877671a1 Reviewed-on: https://chromium-review.googlesource.com/734237Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent 971f8508
......@@ -359,8 +359,7 @@ gl::Error FramebufferVk::blit(const gl::Context *context,
bool FramebufferVk::checkStatus(const gl::Context *context) const
{
UNIMPLEMENTED();
return bool();
return true;
}
void FramebufferVk::syncState(const gl::Context *context,
......@@ -618,7 +617,6 @@ gl::Error FramebufferVk::ensureInRenderPass(const gl::Context *context,
// Updated the cached image layout of the attachments in this FBO.
// For a default FBO, we need to call through to the WindowSurfaceVk
// TODO(jmadill): Iterate over all attachments.
ASSERT(mBackbuffer);
RenderTargetVk *renderTarget = nullptr;
ANGLE_TRY(mState.getFirstColorAttachment()->getRenderTarget(context, &renderTarget));
renderTarget->image->updateLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
......
......@@ -533,6 +533,7 @@ void RendererVk::generateCaps(gl::Caps *outCaps,
outCaps->maxElementIndex = std::numeric_limits<GLuint>::max() - 1;
outCaps->maxFragmentUniformVectors = 8;
outCaps->maxVertexUniformVectors = 8;
outCaps->maxColorAttachments = 1;
// Enable this for simple buffer readback testing, but some functionality is missing.
// TODO(jmadill): Support full mapBufferRange extension.
......
......@@ -150,6 +150,13 @@ gl::Error TextureVk::setImage(const gl::Context *context,
ANGLE_TRY(mSampler.init(device, samplerInfo));
mRenderTarget.image = &mImage;
mRenderTarget.imageView = &mImageView;
mRenderTarget.format = &vkFormat;
mRenderTarget.extents = size;
mRenderTarget.samples = VK_SAMPLE_COUNT_1_BIT;
mRenderTarget.resource = this;
// Handle initial data.
// TODO(jmadill): Consider re-using staging texture.
if (pixels)
......@@ -336,8 +343,10 @@ gl::Error TextureVk::getAttachmentRenderTarget(const gl::Context *context,
const gl::ImageIndex &imageIndex,
FramebufferAttachmentRenderTarget **rtOut)
{
UNIMPLEMENTED();
return gl::InternalError();
ASSERT(imageIndex.type == GL_TEXTURE_2D);
ASSERT(imageIndex.mipIndex == 0 && imageIndex.layerIndex == gl::ImageIndex::ENTIRE_LEVEL);
*rtOut = &mRenderTarget;
return gl::NoError();
}
void TextureVk::syncState(const gl::Texture::DirtyBits &dirtyBits)
......
......@@ -11,6 +11,7 @@
#define LIBANGLE_RENDERER_VULKAN_TEXTUREVK_H_
#include "libANGLE/renderer/TextureImpl.h"
#include "libANGLE/renderer/vulkan/RenderTargetVk.h"
#include "libANGLE/renderer/vulkan/renderervk_utils.h"
namespace rx
......@@ -120,6 +121,8 @@ class TextureVk : public TextureImpl, public ResourceVk
vk::DeviceMemory mDeviceMemory;
vk::ImageView mImageView;
vk::Sampler mSampler;
RenderTargetVk mRenderTarget;
};
} // namespace rx
......
......@@ -494,6 +494,41 @@ TEST_P(SimpleOperationTest, DrawWithTexture)
EXPECT_PIXEL_COLOR_EQ(w, h, GLColor::yellow);
}
// Tests rendering to a user framebuffer.
TEST_P(SimpleOperationTest, RenderToTexture)
{
constexpr int kSize = 16;
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
ASSERT_GL_NO_ERROR();
GLFramebuffer framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
ASSERT_GL_NO_ERROR();
ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
glViewport(0, 0, kSize, kSize);
const std::string &vertexShader =
"attribute vec3 position;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(position, 1);\n"
"}";
const std::string &fragmentShader =
"void main()\n"
"{\n"
" gl_FragColor = vec4(0, 1, 0, 1);\n"
"}";
ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
drawQuad(program, "position", 0.5f, 1.0f, true);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(SimpleOperationTest,
ES2_D3D9(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment