Commit 021ce202 authored by Laszlo Agocs's avatar Laszlo Agocs

RHIify

parent 0036be4c
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt RHI module
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qrhi.h"
#include "qrhivulkan_p.h"
QT_BEGIN_NAMESPACE
QRhiResource::QRhiResource(QRhi *rhi_)
: rhi(rhi_)
{
}
QRhiResource::~QRhiResource()
{
}
QRhiBuffer::QRhiBuffer(QRhi *rhi, Type type_, UsageFlags usage_, int size_)
: QRhiResource(rhi),
type(type_), usage(usage_), size(size_)
{
}
QRhiRenderBuffer::QRhiRenderBuffer(QRhi *rhi, Type type_, const QSize &pixelSize_, int sampleCount_)
: QRhiResource(rhi),
type(type_), pixelSize(pixelSize_), sampleCount(sampleCount_)
{
}
QRhiTexture::QRhiTexture(QRhi *rhi, Format format_, const QSize &pixelSize_, Flags flags_)
: QRhiResource(rhi),
format(format_), pixelSize(pixelSize_), flags(flags_)
{
}
QRhiSampler::QRhiSampler(QRhi *rhi,
Filter magFilter_, Filter minFilter_, Filter mipmapMode_, AddressMode u_, AddressMode v_)
: QRhiResource(rhi),
magFilter(magFilter_), minFilter(minFilter_), mipmapMode(mipmapMode_),
addressU(u_), addressV(v_)
{
}
QRhiRenderPass::QRhiRenderPass(QRhi *rhi)
: QRhiResource(rhi)
{
}
QRhiRenderTarget::QRhiRenderTarget(QRhi *rhi)
: QRhiResource(rhi)
{
}
QRhiReferenceRenderTarget::QRhiReferenceRenderTarget(QRhi *rhi)
: QRhiRenderTarget(rhi)
{
}
QRhiTextureRenderTarget::QRhiTextureRenderTarget(QRhi *rhi,
QRhiTexture *texture_, Flags flags_)
: QRhiRenderTarget(rhi),
texture(texture_), depthTexture(nullptr), depthStencilBuffer(nullptr), flags(flags_)
{
}
QRhiTextureRenderTarget::QRhiTextureRenderTarget(QRhi *rhi,
QRhiTexture *texture_, QRhiRenderBuffer *depthStencilBuffer_, Flags flags_)
: QRhiRenderTarget(rhi),
texture(texture_), depthTexture(nullptr), depthStencilBuffer(depthStencilBuffer_), flags(flags_)
{
}
QRhiTextureRenderTarget::QRhiTextureRenderTarget(QRhi *rhi,
QRhiTexture *texture_, QRhiTexture *depthTexture_, Flags flags_)
: QRhiRenderTarget(rhi),
texture(texture_), depthTexture(depthTexture_), depthStencilBuffer(nullptr), flags(flags_)
{
}
QRhiShaderResourceBindings::QRhiShaderResourceBindings(QRhi *rhi)
: QRhiResource(rhi)
{
}
QRhiGraphicsPipeline::QRhiGraphicsPipeline(QRhi *rhi)
: QRhiResource(rhi)
{
}
QRhiSwapChain::QRhiSwapChain(QRhi *rhi)
: QRhiResource(rhi)
{
}
QRhiCommandBuffer::QRhiCommandBuffer(QRhi *rhi)
: QRhiResource(rhi)
{
}
QRhi::QRhi()
{
}
QRhi::~QRhi()
{
}
QRhi *QRhi::create(Implementation impl, QRhiInitParams *params)
{
switch (impl) {
case Vulkan:
return new QRhiVulkan(params);
default:
break;
}
return nullptr;
}
int QRhi::ubufAligned(int v) const
{
const int byteAlign = ubufAlignment();
return (v + byteAlign - 1) & ~(byteAlign - 1);
}
QMatrix4x4 QRhi::openGLCorrectionMatrix() const
{
static QMatrix4x4 m;
if (m.isIdentity()) {
// NB the ctor takes row-major
m = QMatrix4x4(1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f);
}
return m;
}
QT_END_NAMESPACE
......@@ -3,7 +3,7 @@
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt VkRender module
** This file is part of the Qt RHI module
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
......@@ -34,10 +34,10 @@
**
****************************************************************************/
#ifndef QVKRENDER_H
#define QVKRENDER_H
#ifndef QRHI_H
#define QRHI_H
#include <QtVkRender/qtvkrglobal.h>
#include <QtRhi/qtrhiglobal.h>
#include <QVector4D>
#include <QVector2D>
#include <QSize>
......@@ -47,10 +47,9 @@
QT_BEGIN_NAMESPACE
class QRhiPrivate;
class QVulkanWindow;
class QWindow;
struct Q_VKR_EXPORT QRhiClearValue
struct Q_RHI_EXPORT QRhiClearValue
{
QRhiClearValue() { }
QRhiClearValue(const QVector4D &rgba_) : rgba(rgba_), isDepthStencil(false) { }
......@@ -61,7 +60,7 @@ struct Q_VKR_EXPORT QRhiClearValue
bool isDepthStencil;
};
struct Q_VKR_EXPORT QRhiViewport
struct Q_RHI_EXPORT QRhiViewport
{
QRhiViewport() { }
QRhiViewport(float x, float y, float w, float h, float minDepth_ = 0.0f, float maxDepth_ = 1.0f)
......@@ -72,7 +71,7 @@ struct Q_VKR_EXPORT QRhiViewport
float maxDepth;
};
struct Q_VKR_EXPORT QRhiScissor
struct Q_RHI_EXPORT QRhiScissor
{
QRhiScissor() { }
QRhiScissor(float x, float y, float w, float h)
......@@ -82,7 +81,7 @@ struct Q_VKR_EXPORT QRhiScissor
};
// should be mappable to D3D12_INPUT_ELEMENT_DESC + D3D12_VERTEX_BUFFER_VIEW...
struct Q_VKR_EXPORT QRhiVertexInputLayout
struct Q_RHI_EXPORT QRhiVertexInputLayout
{
struct Binding {
enum Classification {
......@@ -125,7 +124,7 @@ struct Q_VKR_EXPORT QRhiVertexInputLayout
QVector<Attribute> attributes;
};
struct Q_VKR_EXPORT QRhiGraphicsShaderStage
struct Q_RHI_EXPORT QRhiGraphicsShaderStage
{
enum Type {
Vertex,
......@@ -147,7 +146,7 @@ struct Q_VKR_EXPORT QRhiGraphicsShaderStage
class QRhi;
class Q_VKR_EXPORT QRhiResource
class Q_RHI_EXPORT QRhiResource
{
public:
virtual ~QRhiResource();
......@@ -159,7 +158,7 @@ protected:
Q_DISABLE_COPY(QRhiResource)
};
class Q_VKR_EXPORT QRhiBuffer : public QRhiResource
class Q_RHI_EXPORT QRhiBuffer : public QRhiResource
{
public:
enum Type {
......@@ -188,7 +187,7 @@ protected:
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
class Q_VKR_EXPORT QRhiRenderBuffer : public QRhiResource
class Q_RHI_EXPORT QRhiRenderBuffer : public QRhiResource
{
public:
enum Type {
......@@ -205,7 +204,7 @@ protected:
QRhiRenderBuffer(QRhi *rhi, Type type_, const QSize &pixelSize_, int sampleCount_);
};
class Q_VKR_EXPORT QRhiTexture : public QRhiResource
class Q_RHI_EXPORT QRhiTexture : public QRhiResource
{
public:
enum Flag {
......@@ -241,7 +240,7 @@ protected:
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags)
class Q_VKR_EXPORT QRhiSampler : public QRhiResource
class Q_RHI_EXPORT QRhiSampler : public QRhiResource
{
public:
enum Filter {
......@@ -270,13 +269,13 @@ protected:
Filter magFilter_, Filter minFilter_, Filter mipmapMode_, AddressMode u_, AddressMode v_);
};
class Q_VKR_EXPORT QRhiRenderPass : public QRhiResource
class Q_RHI_EXPORT QRhiRenderPass : public QRhiResource
{
protected:
QRhiRenderPass(QRhi *rhi);
};
class Q_VKR_EXPORT QRhiRenderTarget : public QRhiResource
class Q_RHI_EXPORT QRhiRenderTarget : public QRhiResource
{
public:
enum Type {
......@@ -292,13 +291,13 @@ protected:
QRhiRenderTarget(QRhi *rhi);
};
class Q_VKR_EXPORT QRhiReferenceRenderTarget : public QRhiRenderTarget
class Q_RHI_EXPORT QRhiReferenceRenderTarget : public QRhiRenderTarget
{
protected:
QRhiReferenceRenderTarget(QRhi *rhi);
};
class Q_VKR_EXPORT QRhiTextureRenderTarget : public QRhiRenderTarget
class Q_RHI_EXPORT QRhiTextureRenderTarget : public QRhiRenderTarget
{
public:
enum Flag {
......@@ -324,7 +323,7 @@ protected:
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags)
class Q_VKR_EXPORT QRhiShaderResourceBindings : public QRhiResource
class Q_RHI_EXPORT QRhiShaderResourceBindings : public QRhiResource
{
public:
struct Binding {
......@@ -393,7 +392,7 @@ protected:
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::Binding::StageFlags)
class Q_VKR_EXPORT QRhiGraphicsPipeline : public QRhiResource
class Q_RHI_EXPORT QRhiGraphicsPipeline : public QRhiResource
{
public:
enum Flag {
......@@ -532,13 +531,13 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::CullMode)
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
class Q_VKR_EXPORT QRhiCommandBuffer : public QRhiResource
class Q_RHI_EXPORT QRhiCommandBuffer : public QRhiResource
{
protected:
QRhiCommandBuffer(QRhi *rhi);
};
class Q_VKR_EXPORT QRhiSwapChain : public QRhiResource
class Q_RHI_EXPORT QRhiSwapChain : public QRhiResource
{
public:
enum SurfaceImportFlag {
......@@ -564,20 +563,11 @@ protected:
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::SurfaceImportFlags)
struct Q_VKR_EXPORT QRhiInitParams
struct Q_RHI_EXPORT QRhiInitParams
{
};
struct Q_VKR_EXPORT QVulkanRhiInitParams : public QRhiInitParams
{
QVulkanInstance *inst = nullptr;
VkPhysicalDevice physDev = VK_NULL_HANDLE;
VkDevice dev = VK_NULL_HANDLE;
VkCommandPool cmdPool = VK_NULL_HANDLE;
VkQueue gfxQueue = VK_NULL_HANDLE;
};
class Q_VKR_EXPORT QRhi
class Q_RHI_EXPORT QRhi
{
public:
enum Implementation {
......
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt RHI module
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QRHIVULKAN_H
#define QRHIVULKAN_H
#include <QtRhi/qrhi.h>
#include <QtGui/qvulkaninstance.h> // this is where vulkan.h gets pulled in
QT_BEGIN_NAMESPACE
struct Q_RHI_EXPORT QRhiVulkanInitParams : public QRhiInitParams
{
QVulkanInstance *inst = nullptr;
VkPhysicalDevice physDev = VK_NULL_HANDLE;
VkDevice dev = VK_NULL_HANDLE;
VkCommandPool cmdPool = VK_NULL_HANDLE;
VkQueue gfxQueue = VK_NULL_HANDLE;
};
QT_END_NAMESPACE
#endif
......@@ -3,7 +3,7 @@
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt VkRender module
** This file is part of the Qt RHI module
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
......@@ -27,8 +27,8 @@
**
****************************************************************************/
#ifndef QVKRENDER_P_H
#define QVKRENDER_P_H
#ifndef QRHIVULKAN_P_H
#define QRHIVULKAN_P_H
//
// W A R N I N G
......@@ -41,14 +41,15 @@
// We mean it.
//
#include "qvkrender.h"
#include "qrhivulkan.h"
#include "qtrhiglobal_p.h"
#include <QVector>
QT_BEGIN_NAMESPACE
class QVulkanFunctions;
class QVulkanDeviceFunctions;
class QWindow;
class QVulkanWindow;
static const int QVK_FRAMES_IN_FLIGHT = 2;
......@@ -56,7 +57,9 @@ static const int QVK_DESC_SETS_PER_POOL = 128;
static const int QVK_UNIFORM_BUFFERS_PER_POOL = 256;
static const int QVK_COMBINED_IMAGE_SAMPLERS_PER_POOL = 256;
// no vk_mem_alloc.h available here, void* is good enough
typedef void * QVkAlloc;
typedef void * QVkAllocator;
struct QVkBuffer : public QRhiBuffer
{
......@@ -269,7 +272,7 @@ struct QVkSwapChain : public QRhiSwapChain
quint32 currentFrame = 0; // index in frameRes
};
class Q_VKR_EXPORT QRhiVulkan : public QRhi
class QRhiVulkan : public QRhi
{
public:
QRhiVulkan(QRhiInitParams *params);
......@@ -379,7 +382,7 @@ public:
VkDevice dev;
VkCommandPool cmdPool;
VkQueue gfxQueue;
VmaAllocator allocator;
QVkAllocator allocator;
QVulkanFunctions *f = nullptr;
QVulkanDeviceFunctions *df = nullptr;
VkPhysicalDeviceProperties physDevProperties;
......
......@@ -3,7 +3,7 @@
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt VkRender module
** This file is part of the Qt RHI module
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
......@@ -34,23 +34,22 @@
**
****************************************************************************/
#ifndef QTVKRGLOBAL_H
#define QTVKRGLOBAL_H
#ifndef QTRHIGLOBAL_H
#define QTRHIGLOBAL_H
#include <QtCore/qglobal.h>
#include <QtGui/qvulkaninstance.h> // this is where vulkan.h gets pulled in
QT_BEGIN_NAMESPACE
#ifndef Q_VKR_EXPORT
#ifndef Q_RHI_EXPORT
# if !defined(QT_STATIC)
# if defined(QT_BUILD_VKR_LIB)
# define Q_VKR_EXPORT Q_DECL_EXPORT
# if defined(QT_BUILD_RHI_LIB)
# define Q_RHI_EXPORT Q_DECL_EXPORT
# else
# define Q_VKR_EXPORT Q_DECL_IMPORT
# define Q_RHI_EXPORT Q_DECL_IMPORT
# endif
# else
# define Q_VKR_EXPORT
# define Q_RHI_EXPORT
# endif
#endif
......
......@@ -3,7 +3,7 @@
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt VkRender module
** This file is part of the Qt RHI module
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
......@@ -27,8 +27,8 @@
**
****************************************************************************/
#ifndef QTVKRGLOBAL_P_H
#define QTVKRGLOBAL_P_H
#ifndef QTRHIGLOBAL_P_H
#define QTRHIGLOBAL_P_H
//
// W A R N I N G
......@@ -41,8 +41,8 @@
// We mean it.
//
#include "qtvkrglobal.h"
#include "qtrhiglobal.h"
#define Q_VKR_PRIVATE_EXPORT Q_VKR_EXPORT
#define Q_RHI_PRIVATE_EXPORT Q_RHI_EXPORT
#endif
TARGET = QtVkRender
TARGET = QtRhi
load(qt_module)
!qtConfig(vulkan): error(This module requires Vulkan support)
DEFINES += QT_BUILD_VKR_LIB
DEFINES += QT_BUILD_RHI_LIB
HEADERS += \
qtvkrglobal.h \
qtvkrglobal_p.h \
qvkrender.h
qtrhiglobal.h \
qtrhiglobal_p.h \
qrhi.h \
qrhivulkan.h \
qrhivulkan_p.h
SOURCES += \
qvkrender.cpp
qrhi.cpp \
qrhivulkan.cpp
include($$PWD/../3rdparty/VulkanMemoryAllocator.pri)
TEMPLATE = subdirs
SUBDIRS += \
vkrender
rhi
%modules = ( # path to module name map
"QtVkRender" => "$basedir/src/vkrender",
"QtRhi" => "$basedir/src/rhi",
);
%moduleheaders = ( # restrict the module headers to those found in relative path
);
......
......@@ -32,6 +32,9 @@
#include <QVulkanInstance>
#include <QVulkanFunctions>
#include <QPlatformSurfaceEvent>
#include <QRhiVulkanInitParams>
#include "trianglerenderer.h"
#include "texturedcuberenderer.h"
#include "triangleoncuberenderer.h"
......@@ -193,7 +196,7 @@ void VWindow::init()
if (err != VK_SUCCESS)
qFatal("Failed to create command pool: %d", err);
QVulkanRhiInitParams params;
QRhiVulkanInitParams params;
params.inst = vulkanInstance();
params.physDev = m_vkPhysDev;
params.dev = m_vkDev;
......
TEMPLATE = app
QT += shadertools vkrender
QT += shadertools rhi
SOURCES = \
main.cpp \
......
......@@ -29,7 +29,7 @@
#ifndef TEXTUREDCUBERENDERER_H
#define TEXTUREDCUBERENDERER_H
#include <QVkRender>
#include <QRhi>
class TexturedCubeRenderer
{
......
......@@ -29,7 +29,7 @@
#ifndef TRIANGLERENDERER_H
#define TRIANGLERENDERER_H
#include <QVkRender>
#include <QRhi>
class TriangleRenderer
{
......
......@@ -50,6 +50,7 @@
#include "renderer.h"
#include <QVulkanFunctions>
#include <QRhiVulkanInitParams>
Renderer::Renderer(QVulkanWindow *w)
: m_window(w)
......@@ -59,7 +60,7 @@ Renderer::Renderer(QVulkanWindow *w)
void Renderer::initResources()
{
QVulkanRhiInitParams params;
QRhiVulkanInitParams params;
params.inst = m_window->vulkanInstance();
params.physDev = m_window->physicalDevice();
params.dev = m_window->device();
......
TEMPLATE = app
QT += shadertools vkrender
QT += shadertools rhi
SOURCES = \
main.cpp \
......
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