summaryrefslogtreecommitdiffstats
path: root/spa/plugins/vulkan/vulkan-utils.h
blob: c818322d9564d74e6a50dd4156997cf67393f1e1 (plain)
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
#include <vulkan/vulkan.h>

#include <spa/buffer/buffer.h>
#include <spa/node/node.h>

#define MAX_STREAMS 2
#define MAX_BUFFERS 16
#define WORKGROUP_SIZE 32

struct pixel {
	float r, g, b, a;
};

struct push_constants {
	float time;
	int frame;
	int width;
	int height;
};

struct vulkan_buffer {
	int fd;
	VkImage image;
	VkImageView view;
	VkDeviceMemory memory;
};

struct vulkan_stream {
	enum spa_direction direction;

	uint32_t pending_buffer_id;
	uint32_t current_buffer_id;
	uint32_t busy_buffer_id;
	uint32_t ready_buffer_id;

	struct vulkan_buffer buffers[MAX_BUFFERS];
	uint32_t n_buffers;
};

struct vulkan_state {
	struct spa_log *log;

	struct push_constants constants;

	VkInstance instance;

	VkPhysicalDevice physicalDevice;
	VkDevice device;

	VkPipeline pipeline;
	VkPipelineLayout pipelineLayout;
	const char *shaderName;
	VkShaderModule computeShaderModule;

	VkCommandPool commandPool;
	VkCommandBuffer commandBuffer;

	VkQueue queue;
	uint32_t queueFamilyIndex;
	VkFence fence;
	unsigned int prepared:1;
	unsigned int started:1;

	VkDescriptorPool descriptorPool;
	VkDescriptorSetLayout descriptorSetLayout;

	VkSampler sampler;

	uint32_t n_streams;
	VkDescriptorSet descriptorSet;
	struct vulkan_stream streams[MAX_STREAMS];
};

int spa_vulkan_init_stream(struct vulkan_state *s, struct vulkan_stream *stream, enum spa_direction,
		struct spa_dict *props);

int spa_vulkan_prepare(struct vulkan_state *s);
int spa_vulkan_use_buffers(struct vulkan_state *s, struct vulkan_stream *stream, uint32_t flags,
		uint32_t n_buffers, struct spa_buffer **buffers);
int spa_vulkan_unprepare(struct vulkan_state *s);

int spa_vulkan_start(struct vulkan_state *s);
int spa_vulkan_stop(struct vulkan_state *s);
int spa_vulkan_ready(struct vulkan_state *s);
int spa_vulkan_process(struct vulkan_state *s);
int spa_vulkan_cleanup(struct vulkan_state *s);