summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhivulkan_p_p.h
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2019-06-12 14:22:33 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2019-06-17 10:32:57 +0200
commit6f4aa5413183f3f18dd1b15dbc90bcee9ef85bdd (patch)
tree4e0d3d98de98f7a77cc9c52d4b11682093d94958 /src/gui/rhi/qrhivulkan_p_p.h
parent4c297bdca8da543c582d129f12413d29a2a520eb (diff)
rhi: Add compute api and implement for Vulkan and Metal
D3D11 and GL (4.3+, ES 3.1+) will come separately at a later time. Change-Id: If30f2f3d062fa27e57e9912674669225b82a7b93 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhivulkan_p_p.h')
-rw-r--r--src/gui/rhi/qrhivulkan_p_p.h71
1 files changed, 63 insertions, 8 deletions
diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h
index afb0cc1d5a..cec9016603 100644
--- a/src/gui/rhi/qrhivulkan_p_p.h
+++ b/src/gui/rhi/qrhivulkan_p_p.h
@@ -61,6 +61,8 @@ static const int QVK_FRAMES_IN_FLIGHT = 2;
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;
+static const int QVK_STORAGE_BUFFERS_PER_POOL = 128;
+static const int QVK_STORAGE_IMAGES_PER_POOL = 128;
static const int QVK_MAX_ACTIVE_TIMESTAMP_PAIRS = 16;
@@ -123,12 +125,14 @@ struct QVkTexture : public QRhiTexture
bool prepareBuild(QSize *adjustedSize = nullptr);
bool finishBuild();
+ VkImageView imageViewForLevel(int level);
VkImage image = VK_NULL_HANDLE;
VkImageView imageView = VK_NULL_HANDLE;
QVkAlloc imageAlloc = nullptr;
VkBuffer stagingBuffers[QVK_FRAMES_IN_FLIGHT];
QVkAlloc stagingAllocations[QVK_FRAMES_IN_FLIGHT];
+ VkImageView perLevelImageViews[QRhi::MAX_LEVELS];
bool owns = true;
QRhiVulkanTextureNativeHandles nativeHandlesStruct;
struct UsageState {
@@ -246,10 +250,20 @@ struct QVkShaderResourceBindings : public QRhiShaderResourceBindings
quint64 samplerId;
uint samplerGeneration;
};
+ struct BoundStorageImageData {
+ quint64 id;
+ uint generation;
+ };
+ struct BoundStorageBufferData {
+ quint64 id;
+ uint generation;
+ };
struct BoundResourceData {
union {
BoundUniformBufferData ubuf;
BoundSampledTextureData stex;
+ BoundStorageImageData simage;
+ BoundStorageBufferData sbuf;
};
};
QVector<BoundResourceData> boundResourceData[QVK_FRAMES_IN_FLIGHT];
@@ -273,6 +287,20 @@ struct QVkGraphicsPipeline : public QRhiGraphicsPipeline
friend class QRhiVulkan;
};
+struct QVkComputePipeline : public QRhiComputePipeline
+{
+ QVkComputePipeline(QRhiImplementation *rhi);
+ ~QVkComputePipeline();
+ void release() override;
+ bool build() override;
+
+ VkPipelineLayout layout = VK_NULL_HANDLE;
+ VkPipeline pipeline = VK_NULL_HANDLE;
+ int lastActiveFrameSlot = -1;
+ uint generation = 0;
+ friend class QRhiVulkan;
+};
+
struct QVkCommandBuffer : public QRhiCommandBuffer
{
QVkCommandBuffer(QRhiImplementation *rhi);
@@ -287,16 +315,25 @@ struct QVkCommandBuffer : public QRhiCommandBuffer
return &nativeHandlesStruct;
}
+ enum PassType {
+ NoPass,
+ RenderPass,
+ ComputePass
+ };
+
void resetState() {
resetCommands();
+ recordingPass = NoPass;
currentTarget = nullptr;
resetCachedState();
}
void resetCachedState() {
- currentPipeline = nullptr;
+ currentGraphicsPipeline = nullptr;
+ currentComputePipeline = nullptr;
currentPipelineGeneration = 0;
- currentSrb = nullptr;
+ currentGraphicsSrb = nullptr;
+ currentComputeSrb = nullptr;
currentSrbGeneration = 0;
currentDescSetSlot = -1;
currentIndexBuffer = VK_NULL_HANDLE;
@@ -306,10 +343,13 @@ struct QVkCommandBuffer : public QRhiCommandBuffer
memset(currentVertexOffsets, 0, sizeof(currentVertexOffsets));
}
+ PassType recordingPass;
QRhiRenderTarget *currentTarget;
- QRhiGraphicsPipeline *currentPipeline;
+ QRhiGraphicsPipeline *currentGraphicsPipeline;
+ QRhiComputePipeline *currentComputePipeline;
uint currentPipelineGeneration;
- QRhiShaderResourceBindings *currentSrb;
+ QRhiShaderResourceBindings *currentGraphicsSrb;
+ QRhiShaderResourceBindings *currentComputeSrb;
uint currentSrbGeneration;
int currentDescSetSlot;
VkBuffer currentIndexBuffer;
@@ -343,7 +383,8 @@ struct QVkCommandBuffer : public QRhiCommandBuffer
DebugMarkerBegin,
DebugMarkerEnd,
DebugMarkerInsert,
- TransitionPassResources
+ TransitionPassResources,
+ Dispatch
};
Cmd cmd;
@@ -456,6 +497,9 @@ struct QVkCommandBuffer : public QRhiCommandBuffer
struct {
int trackerIndex;
} transitionResources;
+ struct {
+ int x, y, z;
+ } dispatch;
} args;
};
QVector<Command> commands;
@@ -532,7 +576,12 @@ struct QVkSwapChain : public QRhiSwapChain
VkFramebuffer fb = VK_NULL_HANDLE;
VkImage msaaImage = VK_NULL_HANDLE;
VkImageView msaaImageView = VK_NULL_HANDLE;
- bool transferSource = false;
+ enum LastUse {
+ ScImageUseNone,
+ ScImageUseRender,
+ ScImageUseTransferSource
+ };
+ LastUse lastUse = ScImageUseNone;
} imageRes[MAX_BUFFER_COUNT];
struct FrameResources {
@@ -565,6 +614,7 @@ public:
void destroy() override;
QRhiGraphicsPipeline *createGraphicsPipeline() override;
+ QRhiComputePipeline *createComputePipeline() override;
QRhiShaderResourceBindings *createShaderResourceBindings() override;
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
QRhiBuffer::UsageFlags usage,
@@ -629,6 +679,11 @@ public:
void debugMarkEnd(QRhiCommandBuffer *cb) override;
void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override;
+ void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
+ void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
+ void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override;
+ void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override;
+
const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override;
void beginExternal(QRhiCommandBuffer *cb) override;
void endExternal(QRhiCommandBuffer *cb) override;
@@ -722,6 +777,7 @@ public:
VkCommandPool cmdPool = VK_NULL_HANDLE;
int gfxQueueFamilyIdx = -1;
VkQueue gfxQueue = VK_NULL_HANDLE;
+ bool hasCompute = false;
quint32 timestampValidBits = 0;
bool importedAllocator = false;
QVkAllocator allocator = nullptr;
@@ -765,8 +821,6 @@ public:
VkFormat optimalDsFormat = VK_FORMAT_UNDEFINED;
QMatrix4x4 clipCorrectMatrix;
- bool inFrame = false;
- bool inPass = false;
QVkSwapChain *currentSwapChain = nullptr;
QSet<QVkSwapChain *> swapchains;
QRhiVulkanNativeHandles nativeHandlesStruct;
@@ -830,6 +884,7 @@ public:
QVkAlloc allocation;
VkBuffer stagingBuffers[QVK_FRAMES_IN_FLIGHT];
QVkAlloc stagingAllocations[QVK_FRAMES_IN_FLIGHT];
+ VkImageView extraImageViews[QRhi::MAX_LEVELS];
} texture;
struct {
VkSampler sampler;