summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan/vk_compute_pass.h
blob: 1b7502a4ffe915e3df74e0e09530e114e185443e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <optional>
#include <span>
#include <utility>

#include "common/common_types.h"
#include "video_core/engines/maxwell_3d.h"
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
#include "video_core/vulkan_common/vulkan_wrapper.h"

namespace Vulkan {

class VKDevice;
class VKScheduler;
class VKStagingBufferPool;
class VKUpdateDescriptorQueue;

class VKComputePass {
public:
    explicit VKComputePass(const VKDevice& device, VKDescriptorPool& descriptor_pool,
                           vk::Span<VkDescriptorSetLayoutBinding> bindings,
                           vk::Span<VkDescriptorUpdateTemplateEntryKHR> templates,
                           vk::Span<VkPushConstantRange> push_constants, std::span<const u32> code);
    ~VKComputePass();

protected:
    VkDescriptorSet CommitDescriptorSet(VKUpdateDescriptorQueue& update_descriptor_queue);

    vk::DescriptorUpdateTemplateKHR descriptor_template;
    vk::PipelineLayout layout;
    vk::Pipeline pipeline;

private:
    vk::DescriptorSetLayout descriptor_set_layout;
    std::optional<DescriptorAllocator> descriptor_allocator;
    vk::ShaderModule module;
};

class QuadArrayPass final : public VKComputePass {
public:
    explicit QuadArrayPass(const VKDevice& device_, VKScheduler& scheduler_,
                           VKDescriptorPool& descriptor_pool_,
                           VKStagingBufferPool& staging_buffer_pool_,
                           VKUpdateDescriptorQueue& update_descriptor_queue_);
    ~QuadArrayPass();

    std::pair<VkBuffer, VkDeviceSize> Assemble(u32 num_vertices, u32 first);

private:
    VKScheduler& scheduler;
    VKStagingBufferPool& staging_buffer_pool;
    VKUpdateDescriptorQueue& update_descriptor_queue;
};

class Uint8Pass final : public VKComputePass {
public:
    explicit Uint8Pass(const VKDevice& device_, VKScheduler& scheduler_,
                       VKDescriptorPool& descriptor_pool_,
                       VKStagingBufferPool& staging_buffer_pool_,
                       VKUpdateDescriptorQueue& update_descriptor_queue_);
    ~Uint8Pass();

    std::pair<VkBuffer, u64> Assemble(u32 num_vertices, VkBuffer src_buffer, u64 src_offset);

private:
    VKScheduler& scheduler;
    VKStagingBufferPool& staging_buffer_pool;
    VKUpdateDescriptorQueue& update_descriptor_queue;
};

class QuadIndexedPass final : public VKComputePass {
public:
    explicit QuadIndexedPass(const VKDevice& device_, VKScheduler& scheduler_,
                             VKDescriptorPool& descriptor_pool_,
                             VKStagingBufferPool& staging_buffer_pool_,
                             VKUpdateDescriptorQueue& update_descriptor_queue_);
    ~QuadIndexedPass();

    std::pair<VkBuffer, u64> Assemble(Tegra::Engines::Maxwell3D::Regs::IndexFormat index_format,
                                      u32 num_vertices, u32 base_vertex, VkBuffer src_buffer,
                                      u64 src_offset);

private:
    VKScheduler& scheduler;
    VKStagingBufferPool& staging_buffer_pool;
    VKUpdateDescriptorQueue& update_descriptor_queue;
};

} // namespace Vulkan