Skip to content

Commit 533b6e0

Browse files
committed
Move macros to vulkan.c and shader_vulkan.cpp
1 parent 9224cea commit 533b6e0

3 files changed

Lines changed: 134 additions & 132 deletions

File tree

gfx/common/vulkan_common.h

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,6 @@
4646
#include "../drivers_shader/shader_vulkan.h"
4747
#include "../include/vulkan/vulkan.h"
4848

49-
#define VK_BUFFER_CHAIN_DISCARD(chain) \
50-
{ \
51-
chain->current = chain->head; \
52-
chain->offset = 0; \
53-
}
54-
55-
#define VULKAN_SYNC_TEXTURE_TO_GPU(device, tex_memory) \
56-
{ \
57-
VkMappedMemoryRange range; \
58-
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; \
59-
range.pNext = NULL; \
60-
range.memory = tex_memory; \
61-
range.offset = 0; \
62-
range.size = VK_WHOLE_SIZE; \
63-
vkFlushMappedMemoryRanges(device, 1, &range); \
64-
}
65-
66-
#define VULKAN_SYNC_TEXTURE_TO_CPU(device, tex_memory) \
67-
{ \
68-
VkMappedMemoryRange range; \
69-
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; \
70-
range.pNext = NULL; \
71-
range.memory = tex_memory; \
72-
range.offset = 0; \
73-
range.size = VK_WHOLE_SIZE; \
74-
vkInvalidateMappedMemoryRanges(device, 1, &range); \
75-
}
76-
7749
#define VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, img, levels, old_layout, new_layout, src_access, dst_access, src_stages, dst_stages, src_queue_family_idx, dst_queue_family_idx) \
7850
{ \
7951
VkImageMemoryBarrier barrier; \
@@ -94,38 +66,8 @@
9466
vkCmdPipelineBarrier(cmd, src_stages, dst_stages, 0, 0, NULL, 0, NULL, 1, &barrier); \
9567
}
9668

97-
#define VULKAN_TRANSFER_IMAGE_OWNERSHIP(cmd, img, layout, src_stages, dst_stages, src_queue_family, dst_queue_family) VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, img, VK_REMAINING_MIP_LEVELS, layout, layout, 0, 0, src_stages, dst_stages, src_queue_family, dst_queue_family)
98-
9969
#define VULKAN_IMAGE_LAYOUT_TRANSITION(cmd, img, old_layout, new_layout, src_access, dst_access, src_stages, dst_stages) VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, img, VK_REMAINING_MIP_LEVELS, old_layout, new_layout, src_access, dst_access, src_stages, dst_stages, VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED)
10070

101-
#define VK_DESCRIPTOR_MANAGER_RESTART(manager) \
102-
{ \
103-
manager->current = manager->head; \
104-
manager->count = 0; \
105-
}
106-
107-
#define VK_MAP_PERSISTENT_TEXTURE(device, texture) vkMapMemory(device, texture->memory, texture->offset, texture->size, 0, &texture->mapped)
108-
109-
#define VULKAN_PASS_SET_TEXTURE(device, set, _sampler, binding, image_view, image_layout) \
110-
{ \
111-
VkDescriptorImageInfo image_info; \
112-
VkWriteDescriptorSet write; \
113-
image_info.sampler = _sampler; \
114-
image_info.imageView = image_view; \
115-
image_info.imageLayout = image_layout; \
116-
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; \
117-
write.pNext = NULL; \
118-
write.dstSet = set; \
119-
write.dstBinding = binding; \
120-
write.dstArrayElement = 0; \
121-
write.descriptorCount = 1; \
122-
write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; \
123-
write.pImageInfo = &image_info; \
124-
write.pBufferInfo = NULL; \
125-
write.pTexelBufferView = NULL; \
126-
vkUpdateDescriptorSets(device, 1, &write, 0, NULL); \
127-
}
128-
12971
#define VULKAN_SET_UNIFORM_BUFFER(_device, _set, _binding, _buffer, _offset, _range) \
13072
{ \
13173
VkWriteDescriptorSet write; \
@@ -146,79 +88,6 @@
14688
vkUpdateDescriptorSets(_device, 1, &write, 0, NULL); \
14789
}
14890

149-
#define VULKAN_WRITE_QUAD_VBO(pv, _x, _y, _width, _height, _tex_x, _tex_y, _tex_width, _tex_height, vulkan_color) \
150-
{ \
151-
float r = (vulkan_color)->r; \
152-
float g = (vulkan_color)->g; \
153-
float b = (vulkan_color)->b; \
154-
float a = (vulkan_color)->a; \
155-
pv[0].x = (_x) + 0.0f * (_width); \
156-
pv[0].y = (_y) + 0.0f * (_height); \
157-
pv[0].tex_x = (_tex_x) + 0.0f * (_tex_width); \
158-
pv[0].tex_y = (_tex_y) + 0.0f * (_tex_height); \
159-
pv[0].color.r = r; \
160-
pv[0].color.g = g; \
161-
pv[0].color.b = b; \
162-
pv[0].color.a = a; \
163-
pv[1].x = (_x) + 0.0f * (_width); \
164-
pv[1].y = (_y) + 1.0f * (_height); \
165-
pv[1].tex_x = (_tex_x) + 0.0f * (_tex_width); \
166-
pv[1].tex_y = (_tex_y) + 1.0f * (_tex_height); \
167-
pv[1].color.r = r; \
168-
pv[1].color.g = g; \
169-
pv[1].color.b = b; \
170-
pv[1].color.a = a; \
171-
pv[2].x = (_x) + 1.0f * (_width); \
172-
pv[2].y = (_y) + 0.0f * (_height); \
173-
pv[2].tex_x = (_tex_x) + 1.0f * (_tex_width); \
174-
pv[2].tex_y = (_tex_y) + 0.0f * (_tex_height); \
175-
pv[2].color.r = r; \
176-
pv[2].color.g = g; \
177-
pv[2].color.b = b; \
178-
pv[2].color.a = a; \
179-
pv[3].x = (_x) + 1.0f * (_width); \
180-
pv[3].y = (_y) + 1.0f * (_height); \
181-
pv[3].tex_x = (_tex_x) + 1.0f * (_tex_width); \
182-
pv[3].tex_y = (_tex_y) + 1.0f * (_tex_height); \
183-
pv[3].color.r = r; \
184-
pv[3].color.g = g; \
185-
pv[3].color.b = b; \
186-
pv[3].color.a = a; \
187-
pv[4].x = (_x) + 1.0f * (_width); \
188-
pv[4].y = (_y) + 0.0f * (_height); \
189-
pv[4].tex_x = (_tex_x) + 1.0f * (_tex_width); \
190-
pv[4].tex_y = (_tex_y) + 0.0f * (_tex_height); \
191-
pv[4].color.r = r; \
192-
pv[4].color.g = g; \
193-
pv[4].color.b = b; \
194-
pv[4].color.a = a; \
195-
pv[5].x = (_x) + 0.0f * (_width); \
196-
pv[5].y = (_y) + 1.0f * (_height); \
197-
pv[5].tex_x = (_tex_x) + 0.0f * (_tex_width); \
198-
pv[5].tex_y = (_tex_y) + 1.0f * (_tex_height); \
199-
pv[5].color.r = r; \
200-
pv[5].color.g = g; \
201-
pv[5].color.b = b; \
202-
pv[5].color.a = a; \
203-
}
204-
205-
/* We don't have to sync against previous TRANSFER,
206-
* since we observed the completion by fences.
207-
*
208-
* If we have a single texture_optimal, we would need to sync against
209-
* previous transfers to avoid races.
210-
*
211-
* We would also need to optionally maintain extra textures due to
212-
* changes in resolution, so this seems like the sanest and
213-
* simplest solution. */
214-
#define VULKAN_SYNC_TEXTURE_TO_GPU_COND_PTR(vk, tex) \
215-
if (((tex)->flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) && (tex)->memory != VK_NULL_HANDLE) \
216-
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, (tex)->memory) \
217-
218-
#define VULKAN_SYNC_TEXTURE_TO_GPU_COND_OBJ(vk, tex) \
219-
if (((tex).flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) && (tex).memory != VK_NULL_HANDLE) \
220-
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, (tex).memory) \
221-
22291
RETRO_BEGIN_DECLS
22392

22493
enum vk_flags
@@ -241,7 +110,6 @@ enum vk_flags
241110
VK_FLAG_OVERLAY_FULLSCREEN = (1 << 15)
242111
};
243112

244-
245113
enum vk_texture_type
246114
{
247115
/* We will use the texture as a sampled linear texture. */

gfx/drivers/vulkan.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,119 @@
5555
#include "../../retroarch.h"
5656
#include "../../verbosity.h"
5757

58+
#define VK_BUFFER_CHAIN_DISCARD(chain) \
59+
{ \
60+
chain->current = chain->head; \
61+
chain->offset = 0; \
62+
}
63+
64+
#define VK_DESCRIPTOR_MANAGER_RESTART(manager) \
65+
{ \
66+
manager->current = manager->head; \
67+
manager->count = 0; \
68+
}
69+
70+
#define VULKAN_TRANSFER_IMAGE_OWNERSHIP(cmd, img, layout, src_stages, dst_stages, src_queue_family, dst_queue_family) VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, img, VK_REMAINING_MIP_LEVELS, layout, layout, 0, 0, src_stages, dst_stages, src_queue_family, dst_queue_family)
71+
72+
#define VK_MAP_PERSISTENT_TEXTURE(device, texture) vkMapMemory(device, texture->memory, texture->offset, texture->size, 0, &texture->mapped)
73+
74+
#define VULKAN_WRITE_QUAD_VBO(pv, _x, _y, _width, _height, _tex_x, _tex_y, _tex_width, _tex_height, vulkan_color) \
75+
{ \
76+
float r = (vulkan_color)->r; \
77+
float g = (vulkan_color)->g; \
78+
float b = (vulkan_color)->b; \
79+
float a = (vulkan_color)->a; \
80+
pv[0].x = (_x) + 0.0f * (_width); \
81+
pv[0].y = (_y) + 0.0f * (_height); \
82+
pv[0].tex_x = (_tex_x) + 0.0f * (_tex_width); \
83+
pv[0].tex_y = (_tex_y) + 0.0f * (_tex_height); \
84+
pv[0].color.r = r; \
85+
pv[0].color.g = g; \
86+
pv[0].color.b = b; \
87+
pv[0].color.a = a; \
88+
pv[1].x = (_x) + 0.0f * (_width); \
89+
pv[1].y = (_y) + 1.0f * (_height); \
90+
pv[1].tex_x = (_tex_x) + 0.0f * (_tex_width); \
91+
pv[1].tex_y = (_tex_y) + 1.0f * (_tex_height); \
92+
pv[1].color.r = r; \
93+
pv[1].color.g = g; \
94+
pv[1].color.b = b; \
95+
pv[1].color.a = a; \
96+
pv[2].x = (_x) + 1.0f * (_width); \
97+
pv[2].y = (_y) + 0.0f * (_height); \
98+
pv[2].tex_x = (_tex_x) + 1.0f * (_tex_width); \
99+
pv[2].tex_y = (_tex_y) + 0.0f * (_tex_height); \
100+
pv[2].color.r = r; \
101+
pv[2].color.g = g; \
102+
pv[2].color.b = b; \
103+
pv[2].color.a = a; \
104+
pv[3].x = (_x) + 1.0f * (_width); \
105+
pv[3].y = (_y) + 1.0f * (_height); \
106+
pv[3].tex_x = (_tex_x) + 1.0f * (_tex_width); \
107+
pv[3].tex_y = (_tex_y) + 1.0f * (_tex_height); \
108+
pv[3].color.r = r; \
109+
pv[3].color.g = g; \
110+
pv[3].color.b = b; \
111+
pv[3].color.a = a; \
112+
pv[4].x = (_x) + 1.0f * (_width); \
113+
pv[4].y = (_y) + 0.0f * (_height); \
114+
pv[4].tex_x = (_tex_x) + 1.0f * (_tex_width); \
115+
pv[4].tex_y = (_tex_y) + 0.0f * (_tex_height); \
116+
pv[4].color.r = r; \
117+
pv[4].color.g = g; \
118+
pv[4].color.b = b; \
119+
pv[4].color.a = a; \
120+
pv[5].x = (_x) + 0.0f * (_width); \
121+
pv[5].y = (_y) + 1.0f * (_height); \
122+
pv[5].tex_x = (_tex_x) + 0.0f * (_tex_width); \
123+
pv[5].tex_y = (_tex_y) + 1.0f * (_tex_height); \
124+
pv[5].color.r = r; \
125+
pv[5].color.g = g; \
126+
pv[5].color.b = b; \
127+
pv[5].color.a = a; \
128+
}
129+
130+
131+
#define VULKAN_SYNC_TEXTURE_TO_GPU(device, tex_memory) \
132+
{ \
133+
VkMappedMemoryRange range; \
134+
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; \
135+
range.pNext = NULL; \
136+
range.memory = tex_memory; \
137+
range.offset = 0; \
138+
range.size = VK_WHOLE_SIZE; \
139+
vkFlushMappedMemoryRanges(device, 1, &range); \
140+
}
141+
142+
#define VULKAN_SYNC_TEXTURE_TO_CPU(device, tex_memory) \
143+
{ \
144+
VkMappedMemoryRange range; \
145+
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; \
146+
range.pNext = NULL; \
147+
range.memory = tex_memory; \
148+
range.offset = 0; \
149+
range.size = VK_WHOLE_SIZE; \
150+
vkInvalidateMappedMemoryRanges(device, 1, &range); \
151+
}
152+
153+
/* We don't have to sync against previous TRANSFER,
154+
* since we observed the completion by fences.
155+
*
156+
* If we have a single texture_optimal, we would need to sync against
157+
* previous transfers to avoid races.
158+
*
159+
* We would also need to optionally maintain extra textures due to
160+
* changes in resolution, so this seems like the sanest and
161+
* simplest solution. */
162+
#define VULKAN_SYNC_TEXTURE_TO_GPU_COND_PTR(vk, tex) \
163+
if (((tex)->flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) && (tex)->memory != VK_NULL_HANDLE) \
164+
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, (tex)->memory) \
165+
166+
#define VULKAN_SYNC_TEXTURE_TO_GPU_COND_OBJ(vk, tex) \
167+
if (((tex).flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) && (tex).memory != VK_NULL_HANDLE) \
168+
VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, (tex).memory) \
169+
170+
58171
#define VK_REMAP_TO_TEXFMT(fmt) ((fmt == VK_FORMAT_R5G6B5_UNORM_PACK16) ? VK_FORMAT_R8G8B8A8_UNORM : fmt)
59172

60173
#ifdef VULKAN_HDR_SWAPCHAIN

gfx/drivers_shader/shader_vulkan.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@
3737
#include "../../msg_hash.h"
3838
#include "../../input/input_driver.h"
3939

40+
#define VULKAN_PASS_SET_TEXTURE(device, set, _sampler, binding, image_view, image_layout) \
41+
{ \
42+
VkDescriptorImageInfo image_info; \
43+
VkWriteDescriptorSet write; \
44+
image_info.sampler = _sampler; \
45+
image_info.imageView = image_view; \
46+
image_info.imageLayout = image_layout; \
47+
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; \
48+
write.pNext = NULL; \
49+
write.dstSet = set; \
50+
write.dstBinding = binding; \
51+
write.dstArrayElement = 0; \
52+
write.descriptorCount = 1; \
53+
write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; \
54+
write.pImageInfo = &image_info; \
55+
write.pBufferInfo = NULL; \
56+
write.pTexelBufferView = NULL; \
57+
vkUpdateDescriptorSets(device, 1, &write, 0, NULL); \
58+
}
59+
60+
4061
static const uint32_t opaque_vert[] =
4162
#include "../drivers/vulkan_shaders/opaque.vert.inc"
4263
;

0 commit comments

Comments
 (0)