Commit e1f3ad4d by Jamie Madill Committed by Commit Bot

Vulkan: Add vk::GetImpl helper.

Using reflection helpers, we can avoid having to pass the return type to the GetImpl method. BUG=angleproject:2200 Change-Id: Id160fbdf0ea8b3de2f219d3cc92394c678189a48 Reviewed-on: https://chromium-review.googlesource.com/742371 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 7bd16666
...@@ -257,10 +257,10 @@ gl::Error ContextVk::initPipeline(const gl::Context *context) ...@@ -257,10 +257,10 @@ gl::Error ContextVk::initPipeline(const gl::Context *context)
const auto &state = mState.getState(); const auto &state = mState.getState();
const auto &programGL = state.getProgram(); const auto &programGL = state.getProgram();
const auto &vao = state.getVertexArray(); const auto &vao = state.getVertexArray();
const auto &programVk = GetImplAs<ProgramVk>(programGL);
const auto *drawFBO = state.getDrawFramebuffer(); const auto *drawFBO = state.getDrawFramebuffer();
FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO); ProgramVk *programVk = vk::GetImpl(programGL);
VertexArrayVk *vkVAO = GetImplAs<VertexArrayVk>(vao); FramebufferVk *vkFBO = vk::GetImpl(drawFBO);
VertexArrayVk *vkVAO = vk::GetImpl(vao);
// Ensure the attribs and bindings are updated. // Ensure the attribs and bindings are updated.
vkVAO->updateVertexDescriptions(context); vkVAO->updateVertexDescriptions(context);
...@@ -309,11 +309,11 @@ gl::Error ContextVk::setupDraw(const gl::Context *context, GLenum mode) ...@@ -309,11 +309,11 @@ gl::Error ContextVk::setupDraw(const gl::Context *context, GLenum mode)
const auto &state = mState.getState(); const auto &state = mState.getState();
const auto &programGL = state.getProgram(); const auto &programGL = state.getProgram();
ProgramVk *programVk = GetImplAs<ProgramVk>(programGL); ProgramVk *programVk = vk::GetImpl(programGL);
const auto &vao = state.getVertexArray(); const auto &vao = state.getVertexArray();
VertexArrayVk *vkVAO = GetImplAs<VertexArrayVk>(vao); VertexArrayVk *vkVAO = vk::GetImpl(vao);
const auto *drawFBO = state.getDrawFramebuffer(); const auto *drawFBO = state.getDrawFramebuffer();
FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO); FramebufferVk *vkFBO = vk::GetImpl(drawFBO);
Serial queueSerial = mRenderer->getCurrentQueueSerial(); Serial queueSerial = mRenderer->getCurrentQueueSerial();
uint32_t maxAttrib = programGL->getState().getMaxActiveAttribLocation(); uint32_t maxAttrib = programGL->getState().getMaxActiveAttribLocation();
...@@ -336,7 +336,7 @@ gl::Error ContextVk::setupDraw(const gl::Context *context, GLenum mode) ...@@ -336,7 +336,7 @@ gl::Error ContextVk::setupDraw(const gl::Context *context, GLenum mode)
vkVAO->updateCurrentBufferSerials(programGL->getActiveAttribLocationsMask(), queueSerial); vkVAO->updateCurrentBufferSerials(programGL->getActiveAttribLocationsMask(), queueSerial);
// TODO(jmadill): Can probably use more dirty bits here. // TODO(jmadill): Can probably use more dirty bits here.
ContextVk *contextVk = GetImplAs<ContextVk>(context); ContextVk *contextVk = vk::GetImpl(context);
ANGLE_TRY(programVk->updateUniforms(contextVk)); ANGLE_TRY(programVk->updateUniforms(contextVk));
programVk->updateTexturesDescriptorSet(contextVk); programVk->updateTexturesDescriptorSet(contextVk);
...@@ -406,7 +406,7 @@ gl::Error ContextVk::drawElements(const gl::Context *context, ...@@ -406,7 +406,7 @@ gl::Error ContextVk::drawElements(const gl::Context *context,
mState.getState().getVertexArray()->getElementArrayBuffer().get(); mState.getState().getVertexArray()->getElementArrayBuffer().get();
ASSERT(elementArrayBuffer); ASSERT(elementArrayBuffer);
BufferVk *elementArrayBufferVk = GetImplAs<BufferVk>(elementArrayBuffer); BufferVk *elementArrayBufferVk = vk::GetImpl(elementArrayBuffer);
commandBuffer->bindIndexBuffer(elementArrayBufferVk->getVkBuffer(), 0, GetVkIndexType(type)); commandBuffer->bindIndexBuffer(elementArrayBufferVk->getVkBuffer(), 0, GetVkIndexType(type));
commandBuffer->drawIndexed(count, 1, 0, 0, 0); commandBuffer->drawIndexed(count, 1, 0, 0, 0);
...@@ -707,12 +707,12 @@ void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits ...@@ -707,12 +707,12 @@ void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits
case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE: case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE:
{ {
// { vertex, fragment } // { vertex, fragment }
ProgramVk *programVk = GetImplAs<ProgramVk>(glState.getProgram()); ProgramVk *programVk = vk::GetImpl(glState.getProgram());
mCurrentShaderStages[0].module = programVk->getLinkedVertexModule().getHandle(); mCurrentShaderStages[0].module = programVk->getLinkedVertexModule().getHandle();
mCurrentShaderStages[1].module = programVk->getLinkedFragmentModule().getHandle(); mCurrentShaderStages[1].module = programVk->getLinkedFragmentModule().getHandle();
// Also invalidate the vertex descriptions cache in the Vertex Array. // Also invalidate the vertex descriptions cache in the Vertex Array.
VertexArrayVk *vaoVk = GetImplAs<VertexArrayVk>(glState.getVertexArray()); VertexArrayVk *vaoVk = vk::GetImpl(glState.getVertexArray());
vaoVk->invalidateVertexDescriptions(); vaoVk->invalidateVertexDescriptions();
dirtyTextures = true; dirtyTextures = true;
...@@ -761,7 +761,7 @@ void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits ...@@ -761,7 +761,7 @@ void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits
if (dirtyTextures) if (dirtyTextures)
{ {
ProgramVk *programVk = GetImplAs<ProgramVk>(glState.getProgram()); ProgramVk *programVk = vk::GetImpl(glState.getProgram());
programVk->invalidateTextures(); programVk->invalidateTextures();
} }
} }
......
...@@ -96,7 +96,7 @@ FramebufferVk::~FramebufferVk() ...@@ -96,7 +96,7 @@ FramebufferVk::~FramebufferVk()
void FramebufferVk::destroy(const gl::Context *context) void FramebufferVk::destroy(const gl::Context *context)
{ {
RendererVk *renderer = GetImplAs<ContextVk>(context)->getRenderer(); RendererVk *renderer = vk::GetImpl(context)->getRenderer();
renderer->releaseResource(*this, &mRenderPass); renderer->releaseResource(*this, &mRenderPass);
renderer->releaseResource(*this, &mFramebuffer); renderer->releaseResource(*this, &mFramebuffer);
...@@ -104,7 +104,7 @@ void FramebufferVk::destroy(const gl::Context *context) ...@@ -104,7 +104,7 @@ void FramebufferVk::destroy(const gl::Context *context)
void FramebufferVk::destroyDefault(const egl::Display *display) void FramebufferVk::destroyDefault(const egl::Display *display)
{ {
VkDevice device = GetImplAs<DisplayVk>(display)->getRenderer()->getDevice(); VkDevice device = vk::GetImpl(display)->getRenderer()->getDevice();
mRenderPass.destroy(device); mRenderPass.destroy(device);
mFramebuffer.destroy(device); mFramebuffer.destroy(device);
...@@ -137,7 +137,7 @@ gl::Error FramebufferVk::invalidateSub(const gl::Context *context, ...@@ -137,7 +137,7 @@ gl::Error FramebufferVk::invalidateSub(const gl::Context *context,
gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask) gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
{ {
ContextVk *contextVk = GetImplAs<ContextVk>(context); ContextVk *contextVk = vk::GetImpl(context);
if (mState.getDepthAttachment() && (mask & GL_DEPTH_BUFFER_BIT) != 0) if (mState.getDepthAttachment() && (mask & GL_DEPTH_BUFFER_BIT) != 0)
{ {
...@@ -266,7 +266,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context, ...@@ -266,7 +266,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
RenderTargetVk *renderTarget = nullptr; RenderTargetVk *renderTarget = nullptr;
ANGLE_TRY(readAttachment->getRenderTarget(context, &renderTarget)); ANGLE_TRY(readAttachment->getRenderTarget(context, &renderTarget));
ContextVk *contextVk = GetImplAs<ContextVk>(context); ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
VkDevice device = renderer->getDevice(); VkDevice device = renderer->getDevice();
...@@ -355,7 +355,7 @@ bool FramebufferVk::checkStatus(const gl::Context *context) const ...@@ -355,7 +355,7 @@ bool FramebufferVk::checkStatus(const gl::Context *context) const
void FramebufferVk::syncState(const gl::Context *context, void FramebufferVk::syncState(const gl::Context *context,
const gl::Framebuffer::DirtyBits &dirtyBits) const gl::Framebuffer::DirtyBits &dirtyBits)
{ {
ContextVk *contextVk = GetImplAs<ContextVk>(context); ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
ASSERT(dirtyBits.any()); ASSERT(dirtyBits.any());
......
...@@ -62,7 +62,7 @@ gl::Error InitDefaultUniformBlock(const gl::Context *context, ...@@ -62,7 +62,7 @@ gl::Error InitDefaultUniformBlock(const gl::Context *context,
ANGLE_TRY(storageOut->buffer.init(device, uniformBufferInfo)); ANGLE_TRY(storageOut->buffer.init(device, uniformBufferInfo));
ANGLE_TRY(AllocateBufferMemory(GetImplAs<ContextVk>(context), blockSize, &storageOut->buffer, ANGLE_TRY(AllocateBufferMemory(vk::GetImpl(context), blockSize, &storageOut->buffer,
&storageOut->memory, requiredSizeOut)); &storageOut->memory, requiredSizeOut));
return gl::NoError(); return gl::NoError();
...@@ -145,7 +145,7 @@ ProgramVk::~ProgramVk() ...@@ -145,7 +145,7 @@ ProgramVk::~ProgramVk()
void ProgramVk::destroy(const gl::Context *contextImpl) void ProgramVk::destroy(const gl::Context *contextImpl)
{ {
VkDevice device = GetImplAs<ContextVk>(contextImpl)->getDevice(); VkDevice device = vk::GetImpl(contextImpl)->getDevice();
reset(device); reset(device);
} }
...@@ -202,7 +202,7 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext, ...@@ -202,7 +202,7 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext,
const gl::VaryingPacking &packing, const gl::VaryingPacking &packing,
gl::InfoLog &infoLog) gl::InfoLog &infoLog)
{ {
ContextVk *contextVk = GetImplAs<ContextVk>(glContext); ContextVk *contextVk = vk::GetImpl(glContext);
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
GlslangWrapper *glslangWrapper = renderer->getGlslangWrapper(); GlslangWrapper *glslangWrapper = renderer->getGlslangWrapper();
VkDevice device = renderer->getDevice(); VkDevice device = renderer->getDevice();
...@@ -250,7 +250,7 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext, ...@@ -250,7 +250,7 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext,
gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext) gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext)
{ {
ContextVk *contextVk = GetImplAs<ContextVk>(glContext); ContextVk *contextVk = vk::GetImpl(glContext);
VkDevice device = contextVk->getDevice(); VkDevice device = contextVk->getDevice();
// Process vertex and fragment uniforms into std140 packing. // Process vertex and fragment uniforms into std140 packing.
...@@ -836,7 +836,7 @@ void ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk) ...@@ -836,7 +836,7 @@ void ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk)
// TODO(jmadill): Incomplete textures handling. // TODO(jmadill): Incomplete textures handling.
ASSERT(texture); ASSERT(texture);
TextureVk *textureVk = GetImplAs<TextureVk>(texture); TextureVk *textureVk = vk::GetImpl(texture);
const vk::Image &image = textureVk->getImage(); const vk::Image &image = textureVk->getImage();
VkDescriptorImageInfo &imageInfo = descriptorImageInfo[imageCount]; VkDescriptorImageInfo &imageInfo = descriptorImageInfo[imageCount];
......
...@@ -183,7 +183,7 @@ WindowSurfaceVk::~WindowSurfaceVk() ...@@ -183,7 +183,7 @@ WindowSurfaceVk::~WindowSurfaceVk()
void WindowSurfaceVk::destroy(const egl::Display *display) void WindowSurfaceVk::destroy(const egl::Display *display)
{ {
const DisplayVk *displayVk = GetImplAs<DisplayVk>(display); const DisplayVk *displayVk = vk::GetImpl(display);
RendererVk *rendererVk = displayVk->getRenderer(); RendererVk *rendererVk = displayVk->getRenderer();
VkDevice device = rendererVk->getDevice(); VkDevice device = rendererVk->getDevice();
VkInstance instance = rendererVk->getInstance(); VkInstance instance = rendererVk->getInstance();
...@@ -218,7 +218,7 @@ void WindowSurfaceVk::destroy(const egl::Display *display) ...@@ -218,7 +218,7 @@ void WindowSurfaceVk::destroy(const egl::Display *display)
egl::Error WindowSurfaceVk::initialize(const egl::Display *display) egl::Error WindowSurfaceVk::initialize(const egl::Display *display)
{ {
const DisplayVk *displayVk = GetImplAs<DisplayVk>(display); const DisplayVk *displayVk = vk::GetImpl(display);
return initializeImpl(displayVk->getRenderer()).toEGL(EGL_BAD_SURFACE); return initializeImpl(displayVk->getRenderer()).toEGL(EGL_BAD_SURFACE);
} }
...@@ -419,7 +419,7 @@ FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::Framebuffer ...@@ -419,7 +419,7 @@ FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::Framebuffer
egl::Error WindowSurfaceVk::swap(const gl::Context *context) egl::Error WindowSurfaceVk::swap(const gl::Context *context)
{ {
const DisplayVk *displayVk = GetImplAs<DisplayVk>(context->getCurrentDisplay()); const DisplayVk *displayVk = vk::GetImpl(context->getCurrentDisplay());
RendererVk *renderer = displayVk->getRenderer(); RendererVk *renderer = displayVk->getRenderer();
vk::CommandBuffer *currentCB = nullptr; vk::CommandBuffer *currentCB = nullptr;
......
...@@ -28,7 +28,7 @@ TextureVk::~TextureVk() ...@@ -28,7 +28,7 @@ TextureVk::~TextureVk()
gl::Error TextureVk::onDestroy(const gl::Context *context) gl::Error TextureVk::onDestroy(const gl::Context *context)
{ {
ContextVk *contextVk = GetImplAs<ContextVk>(context); ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
renderer->releaseResource(*this, &mImage); renderer->releaseResource(*this, &mImage);
...@@ -49,7 +49,7 @@ gl::Error TextureVk::setImage(const gl::Context *context, ...@@ -49,7 +49,7 @@ gl::Error TextureVk::setImage(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
const uint8_t *pixels) const uint8_t *pixels)
{ {
ContextVk *contextVk = GetImplAs<ContextVk>(context); ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
// TODO(jmadill): support multi-level textures. // TODO(jmadill): support multi-level textures.
......
...@@ -40,7 +40,7 @@ void VertexArrayVk::syncState(const gl::Context *context, ...@@ -40,7 +40,7 @@ void VertexArrayVk::syncState(const gl::Context *context,
// Invalidate current pipeline. // Invalidate current pipeline.
// TODO(jmadill): Use pipeline cache. // TODO(jmadill): Use pipeline cache.
auto contextVk = GetImplAs<ContextVk>(context); auto contextVk = vk::GetImpl(context);
contextVk->invalidateCurrentPipeline(); contextVk->invalidateCurrentPipeline();
// Invalidate the vertex descriptions. // Invalidate the vertex descriptions.
...@@ -67,7 +67,7 @@ void VertexArrayVk::syncState(const gl::Context *context, ...@@ -67,7 +67,7 @@ void VertexArrayVk::syncState(const gl::Context *context,
if (bufferGL) if (bufferGL)
{ {
BufferVk *bufferVk = GetImplAs<BufferVk>(bufferGL); BufferVk *bufferVk = vk::GetImpl(bufferGL);
mCurrentVkBuffersCache[attribIndex] = bufferVk; mCurrentVkBuffersCache[attribIndex] = bufferVk;
mCurrentVertexBufferHandlesCache[attribIndex] = bufferVk->getVkBuffer().getHandle(); mCurrentVertexBufferHandlesCache[attribIndex] = bufferVk->getVkBuffer().getHandle();
} }
......
...@@ -19,17 +19,38 @@ ...@@ -19,17 +19,38 @@
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/renderer/renderer_utils.h" #include "libANGLE/renderer/renderer_utils.h"
#define ANGLE_GL_OBJECTS_X(PROC) \
PROC(Buffer) \
PROC(Context) \
PROC(Framebuffer) \
PROC(Program) \
PROC(Texture) \
PROC(VertexArray)
#define ANGLE_PRE_DECLARE_OBJECT(OBJ) class OBJ;
namespace egl
{
class Display;
}
namespace gl namespace gl
{ {
struct Box; struct Box;
struct Extents; struct Extents;
struct RasterizerState; struct RasterizerState;
struct Rectangle; struct Rectangle;
ANGLE_GL_OBJECTS_X(ANGLE_PRE_DECLARE_OBJECT);
} }
#define ANGLE_PRE_DECLARE_VK_OBJECT(OBJ) class OBJ##Vk;
namespace rx namespace rx
{ {
class ContextVk; class DisplayVk;
ANGLE_GL_OBJECTS_X(ANGLE_PRE_DECLARE_VK_OBJECT);
const char *VulkanResultString(VkResult result); const char *VulkanResultString(VkResult result);
bool HasStandardValidationLayer(const std::vector<VkLayerProperties> &layerProps); bool HasStandardValidationLayer(const std::vector<VkLayerProperties> &layerProps);
...@@ -66,6 +87,35 @@ class ResourceVk ...@@ -66,6 +87,35 @@ class ResourceVk
namespace vk namespace vk
{ {
template <typename T>
struct ImplTypeHelper;
// clang-format off
#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
template<> \
struct ImplTypeHelper<gl::OBJ> \
{ \
using ImplType = OBJ##Vk; \
};
// clang-format on
ANGLE_GL_OBJECTS_X(ANGLE_IMPL_TYPE_HELPER_GL)
template <>
struct ImplTypeHelper<egl::Display>
{
using ImplType = DisplayVk;
};
template <typename T>
using GetImplType = typename ImplTypeHelper<T>::ImplType;
template <typename T>
GetImplType<T> *GetImpl(const T *glObject)
{
return GetImplAs<GetImplType<T>>(glObject);
}
class MemoryProperties final : angle::NonCopyable class MemoryProperties final : angle::NonCopyable
{ {
public: public:
......
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