author | Caleb Cornett <caleb.cornett@outlook.com> |
Tue, 07 Jul 2020 21:00:14 -0400 | |
changeset 1280 | d2a0d76469f9 |
parent 1277 | da61410edbc9 |
child 1302 | 974d2cc3558e |
permissions | -rw-r--r-- |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
1 |
/** |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
2 |
* MojoShader; generate shader programs from bytecode of compiled |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
3 |
* Direct3D shaders. |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
4 |
* |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
5 |
* Please see the file LICENSE.txt in the source's root directory. |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
6 |
* |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
7 |
* This file written by Ryan C. Gordon. |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
8 |
*/ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
9 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
10 |
#define __MOJOSHADER_INTERNAL__ 1 |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
11 |
#include "mojoshader_internal.h" |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
12 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
13 |
#if SUPPORT_PROFILE_SPIRV |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
14 |
|
1272
cddbd25553fe
Fix include path for vulkan.h
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1271
diff
changeset
|
15 |
#include "vulkan/vulkan.h" |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
16 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
17 |
#define VULKAN_INSTANCE_FUNCTION(ret, func, params) \ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
18 |
typedef ret (VKAPI_CALL *vkfntype_MOJOSHADER_##func) params; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
19 |
#define VULKAN_DEVICE_FUNCTION(ret, func, params) \ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
20 |
typedef ret (VKAPI_CALL *vkfntype_MOJOSHADER_##func) params; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
21 |
#include "mojoshader_vulkan_vkfuncs.h" |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
22 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
23 |
#define UBO_BUFFER_SIZE 8000000 // 8MB |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
24 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
25 |
// Internal struct defs... |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
26 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
27 |
typedef struct MOJOSHADER_vkShader |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
28 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
29 |
const MOJOSHADER_parseData *parseData; |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
30 |
uint16_t tag; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
31 |
uint32_t refcount; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
32 |
} MOJOSHADER_vkShader; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
33 |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
34 |
typedef struct MOJOSHADER_vkProgram |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
35 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
36 |
VkShaderModule vertexModule; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
37 |
VkShaderModule pixelModule; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
38 |
MOJOSHADER_vkShader *vertexShader; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
39 |
MOJOSHADER_vkShader *pixelShader; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
40 |
} MOJOSHADER_vkProgram; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
41 |
|
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
42 |
typedef struct MOJOSHADER_vkUniformBuffer |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
43 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
44 |
VkBuffer buffer; |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
45 |
VkDeviceMemory deviceMemory; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
46 |
VkDeviceSize bufferSize; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
47 |
VkDeviceSize dynamicOffset; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
48 |
VkDeviceSize currentBlockSize; |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
49 |
uint8_t *mapPointer; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
50 |
} MOJOSHADER_vkUniformBuffer; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
51 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
52 |
// Error state... |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
53 |
static char error_buffer[1024] = { '\0' }; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
54 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
55 |
static void set_error(const char *str) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
56 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
57 |
snprintf(error_buffer, sizeof (error_buffer), "%s", str); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
58 |
} // set_error |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
59 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
60 |
static inline void out_of_memory(void) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
61 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
62 |
set_error("out of memory"); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
63 |
} // out_of_memory |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
64 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
65 |
// Max entries for each register file type |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
66 |
#define MAX_REG_FILE_F 8192 |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
67 |
#define MAX_REG_FILE_I 2047 |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
68 |
#define MAX_REG_FILE_B 2047 |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
69 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
70 |
typedef struct MOJOSHADER_vkContext |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
71 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
72 |
VkInstance *instance; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
73 |
VkPhysicalDevice *physical_device; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
74 |
VkDevice *logical_device; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
75 |
PFN_vkGetInstanceProcAddr instance_proc_lookup; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
76 |
PFN_vkGetDeviceProcAddr device_proc_lookup; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
77 |
uint32_t graphics_queue_family_index; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
78 |
uint32_t maxUniformBufferRange; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
79 |
uint32_t minUniformBufferOffsetAlignment; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
80 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
81 |
int32_t frames_in_flight; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
82 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
83 |
MOJOSHADER_malloc malloc_fn; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
84 |
MOJOSHADER_free free_fn; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
85 |
void *malloc_data; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
86 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
87 |
// The constant register files... |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
88 |
// !!! FIXME: Man, it kills me how much memory this takes... |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
89 |
// !!! FIXME: ... make this dynamically allocated on demand. |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
90 |
float vs_reg_file_f[MAX_REG_FILE_F * 4]; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
91 |
int32_t vs_reg_file_i[MAX_REG_FILE_I * 4]; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
92 |
uint8_t vs_reg_file_b[MAX_REG_FILE_B * 4]; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
93 |
float ps_reg_file_f[MAX_REG_FILE_F * 4]; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
94 |
int32_t ps_reg_file_i[MAX_REG_FILE_I * 4]; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
95 |
uint8_t ps_reg_file_b[MAX_REG_FILE_B * 4]; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
96 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
97 |
MOJOSHADER_vkUniformBuffer *vertUboBuffer; |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
98 |
MOJOSHADER_vkUniformBuffer *fragUboBuffer; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
99 |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
100 |
MOJOSHADER_vkProgram *bound_program; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
101 |
HashTable *linker_cache; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
102 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
103 |
#define VULKAN_INSTANCE_FUNCTION(ret, func, params) \ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
104 |
vkfntype_MOJOSHADER_##func func; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
105 |
#define VULKAN_DEVICE_FUNCTION(ret, func, params) \ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
106 |
vkfntype_MOJOSHADER_##func func; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
107 |
#include "mojoshader_vulkan_vkfuncs.h" |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
108 |
} MOJOSHADER_vkContext; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
109 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
110 |
static MOJOSHADER_vkContext *ctx = NULL; |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
111 |
static uint16_t tagCounter = 1; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
112 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
113 |
static uint8_t find_memory_type( |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
114 |
MOJOSHADER_vkContext *ctx, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
115 |
uint32_t typeFilter, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
116 |
VkMemoryPropertyFlags properties, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
117 |
uint32_t *result |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
118 |
) { |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
119 |
uint32_t i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
120 |
VkPhysicalDeviceMemoryProperties memoryProperties; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
121 |
ctx->vkGetPhysicalDeviceMemoryProperties(*ctx->physical_device, &memoryProperties); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
122 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
123 |
for (i = 0; i < memoryProperties.memoryTypeCount; i++) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
124 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
125 |
if ((typeFilter & (1 << i)) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
126 |
&& (memoryProperties.memoryTypes[i].propertyFlags & properties) == properties) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
127 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
128 |
*result = i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
129 |
return 1; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
130 |
} // if |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
131 |
} // for |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
132 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
133 |
return 0; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
134 |
} // find_memory_type |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
135 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
136 |
static uint32_t next_highest_offset_alignment(uint32_t offset) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
137 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
138 |
return ( |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
139 |
(offset + ctx->minUniformBufferOffsetAlignment - 1) / |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
140 |
ctx->minUniformBufferOffsetAlignment * |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
141 |
ctx->minUniformBufferOffsetAlignment |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
142 |
); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
143 |
} // next_highest_offset_alignment |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
144 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
145 |
static MOJOSHADER_vkUniformBuffer *create_ubo(MOJOSHADER_vkContext *ctx) |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
146 |
{ |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
147 |
MOJOSHADER_vkUniformBuffer *result = (MOJOSHADER_vkUniformBuffer *) ctx->malloc_fn( |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
148 |
sizeof(MOJOSHADER_vkUniformBuffer), |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
149 |
ctx->malloc_data |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
150 |
); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
151 |
VkBufferCreateInfo bufferCreateInfo = |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
152 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
153 |
VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
154 |
}; |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
155 |
VkMemoryRequirements memoryRequirements; |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
156 |
VkMemoryAllocateInfo allocateInfo = |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
157 |
{ |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
158 |
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
159 |
}; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
160 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
161 |
bufferCreateInfo.flags = 0; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
162 |
bufferCreateInfo.size = UBO_BUFFER_SIZE; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
163 |
bufferCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
164 |
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
165 |
bufferCreateInfo.queueFamilyIndexCount = 1; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
166 |
bufferCreateInfo.pQueueFamilyIndices = &ctx->graphics_queue_family_index; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
167 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
168 |
ctx->vkCreateBuffer( |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
169 |
*ctx->logical_device, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
170 |
&bufferCreateInfo, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
171 |
NULL, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
172 |
&result->buffer |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
173 |
); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
174 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
175 |
ctx->vkGetBufferMemoryRequirements( |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
176 |
*ctx->logical_device, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
177 |
result->buffer, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
178 |
&memoryRequirements |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
179 |
); |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
180 |
|
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
181 |
allocateInfo.allocationSize = UBO_BUFFER_SIZE; |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
182 |
|
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
183 |
if (!find_memory_type(ctx, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
184 |
memoryRequirements.memoryTypeBits, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
185 |
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
186 |
&allocateInfo.memoryTypeIndex)) |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
187 |
{ |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
188 |
set_error("failed to find suitable memory type for UBO memory"); |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
189 |
return NULL; |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
190 |
} // if |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
191 |
|
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
192 |
ctx->vkAllocateMemory(*ctx->logical_device, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
193 |
&allocateInfo, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
194 |
NULL, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
195 |
&result->deviceMemory |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
196 |
); |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
197 |
|
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
198 |
ctx->vkBindBufferMemory(*ctx->logical_device, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
199 |
result->buffer, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
200 |
result->deviceMemory, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
201 |
0 |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
202 |
); |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
203 |
|
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
204 |
ctx->vkMapMemory(*ctx->logical_device, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
205 |
result->deviceMemory, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
206 |
0, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
207 |
UBO_BUFFER_SIZE, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
208 |
0, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
209 |
(void**) &result->mapPointer |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
210 |
); |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
211 |
|
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
212 |
result->bufferSize = UBO_BUFFER_SIZE; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
213 |
result->currentBlockSize = 0; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
214 |
result->dynamicOffset = 0; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
215 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
216 |
return result; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
217 |
} // create_ubo |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
218 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
219 |
static uint32_t uniform_data_size(MOJOSHADER_vkShader *shader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
220 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
221 |
int32_t i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
222 |
int32_t buflen = 0; |
1275
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
223 |
const int32_t uniformSize = 16; // Yes, even the bool registers |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
224 |
for (i = 0; i < shader->parseData->uniform_count; i++) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
225 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
226 |
const int32_t arrayCount = shader->parseData->uniforms[i].array_count; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
227 |
buflen += (arrayCount ? arrayCount : 1) * uniformSize; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
228 |
} // for |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
229 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
230 |
return buflen; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
231 |
} // uniform_data_size |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
232 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
233 |
static VkBuffer get_uniform_buffer(MOJOSHADER_vkShader *shader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
234 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
235 |
if (shader == NULL || shader->parseData->uniform_count == 0) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
236 |
return VK_NULL_HANDLE; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
237 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
238 |
if (shader->parseData->shader_type == MOJOSHADER_TYPE_VERTEX) |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
239 |
return ctx->vertUboBuffer->buffer; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
240 |
else |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
241 |
return ctx->fragUboBuffer->buffer; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
242 |
} // get_uniform_buffer |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
243 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
244 |
static VkDeviceSize get_uniform_offset(MOJOSHADER_vkShader *shader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
245 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
246 |
if (shader == NULL || shader->parseData->uniform_count == 0) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
247 |
return 0; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
248 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
249 |
if (shader->parseData->shader_type == MOJOSHADER_TYPE_VERTEX) |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
250 |
return ctx->vertUboBuffer->dynamicOffset; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
251 |
else |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
252 |
return ctx->fragUboBuffer->dynamicOffset; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
253 |
} // get_uniform_offset |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
254 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
255 |
static VkDeviceSize get_uniform_size(MOJOSHADER_vkShader *shader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
256 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
257 |
if (shader == NULL || shader->parseData->uniform_count == 0) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
258 |
return 0; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
259 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
260 |
if (shader->parseData->shader_type == MOJOSHADER_TYPE_VERTEX) |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
261 |
return ctx->vertUboBuffer->currentBlockSize; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
262 |
else |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
263 |
return ctx->fragUboBuffer->currentBlockSize; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
264 |
} // get_uniform_size |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
265 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
266 |
static void update_uniform_buffer(MOJOSHADER_vkShader *shader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
267 |
{ |
1275
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
268 |
int32_t i, j; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
269 |
int32_t offset; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
270 |
uint8_t *contents; |
1275
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
271 |
uint32_t *contentsI; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
272 |
float *regF; int *regI; uint8_t *regB; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
273 |
MOJOSHADER_vkUniformBuffer *ubo; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
274 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
275 |
if (shader == NULL || shader->parseData->uniform_count == 0) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
276 |
return; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
277 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
278 |
if (shader->parseData->shader_type == MOJOSHADER_TYPE_VERTEX) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
279 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
280 |
regF = ctx->vs_reg_file_f; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
281 |
regI = ctx->vs_reg_file_i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
282 |
regB = ctx->vs_reg_file_b; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
283 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
284 |
ubo = ctx->vertUboBuffer; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
285 |
} // if |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
286 |
else |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
287 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
288 |
regF = ctx->ps_reg_file_f; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
289 |
regI = ctx->ps_reg_file_i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
290 |
regB = ctx->ps_reg_file_b; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
291 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
292 |
ubo = ctx->fragUboBuffer; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
293 |
} // else |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
294 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
295 |
ubo->dynamicOffset += ubo->currentBlockSize; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
296 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
297 |
ubo->currentBlockSize = next_highest_offset_alignment(uniform_data_size(shader)); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
298 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
299 |
if (ubo->dynamicOffset + ubo->currentBlockSize >= ubo->bufferSize) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
300 |
{ |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
301 |
set_error("UBO overflow!!"); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
302 |
} // if |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
303 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
304 |
contents = ubo->mapPointer + ubo->dynamicOffset; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
305 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
306 |
offset = 0; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
307 |
for (i = 0; i < shader->parseData->uniform_count; i++) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
308 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
309 |
const int32_t index = shader->parseData->uniforms[i].index; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
310 |
const int32_t arrayCount = shader->parseData->uniforms[i].array_count; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
311 |
const int32_t size = arrayCount ? arrayCount : 1; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
312 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
313 |
switch (shader->parseData->uniforms[i].type) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
314 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
315 |
case MOJOSHADER_UNIFORM_FLOAT: |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
316 |
memcpy( |
1275
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
317 |
contents + offset, |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
318 |
®F[4 * index], |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
319 |
size * 16 |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
320 |
); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
321 |
break; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
322 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
323 |
case MOJOSHADER_UNIFORM_INT: |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
324 |
memcpy( |
1275
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
325 |
contents + offset, |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
326 |
®I[4 * index], |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
327 |
size * 16 |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
328 |
); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
329 |
break; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
330 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
331 |
case MOJOSHADER_UNIFORM_BOOL: |
1275
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
332 |
contentsI = (uint32_t *) (contents + offset); |
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
333 |
for (j = 0; j < size; j++) |
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
334 |
contentsI[j * 4] = regB[index + j]; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
335 |
break; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
336 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
337 |
default: |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
338 |
set_error( |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
339 |
"SOMETHING VERY WRONG HAPPENED WHEN UPDATING UNIFORMS" |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
340 |
); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
341 |
assert(0); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
342 |
break; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
343 |
} // switch |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
344 |
|
1275
7fc13cff18ff
vulkan: Fix uniform buffer copies for bools
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1272
diff
changeset
|
345 |
offset += size * 16; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
346 |
} // for |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
347 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
348 |
} // update_uniform_buffer |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
349 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
350 |
static void lookup_entry_points(MOJOSHADER_vkContext *ctx) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
351 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
352 |
#define VULKAN_INSTANCE_FUNCTION(ret, func, params) \ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
353 |
ctx->func = (vkfntype_MOJOSHADER_##func) ctx->instance_proc_lookup(*ctx->instance, #func); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
354 |
#define VULKAN_DEVICE_FUNCTION(ret, func, params) \ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
355 |
ctx->func = (vkfntype_MOJOSHADER_##func) ctx->device_proc_lookup(*ctx->logical_device, #func); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
356 |
#include "mojoshader_vulkan_vkfuncs.h" |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
357 |
} // lookup_entry_points |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
358 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
359 |
static int shader_bytecode_len(MOJOSHADER_vkShader *shader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
360 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
361 |
return shader->parseData->output_len - sizeof(SpirvPatchTable); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
362 |
} // shader_bytecode_len |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
363 |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
364 |
static VkShaderModule compile_shader(MOJOSHADER_vkShader *shader) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
365 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
366 |
VkResult result; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
367 |
VkShaderModule module; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
368 |
VkShaderModuleCreateInfo shaderModuleCreateInfo = |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
369 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
370 |
VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
371 |
}; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
372 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
373 |
shaderModuleCreateInfo.flags = 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
374 |
shaderModuleCreateInfo.codeSize = shader_bytecode_len(shader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
375 |
shaderModuleCreateInfo.pCode = (uint32_t*) shader->parseData->output; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
376 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
377 |
result = ctx->vkCreateShaderModule( |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
378 |
*ctx->logical_device, |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
379 |
&shaderModuleCreateInfo, |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
380 |
NULL, |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
381 |
&module |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
382 |
); |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
383 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
384 |
if (result != VK_SUCCESS) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
385 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
386 |
// FIXME: should display VK error code |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
387 |
set_error("Error when creating VkShaderModule"); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
388 |
ctx->vkDestroyShaderModule( |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
389 |
*ctx->logical_device, |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
390 |
module, |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
391 |
NULL |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
392 |
); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
393 |
return VK_NULL_HANDLE; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
394 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
395 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
396 |
return module; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
397 |
} // compile_shader |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
398 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
399 |
typedef struct |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
400 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
401 |
MOJOSHADER_vkShader *vertex; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
402 |
MOJOSHADER_vkShader *fragment; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
403 |
} BoundShaders; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
404 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
405 |
static uint32_t hash_shaders(const void *sym, void *data) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
406 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
407 |
(void) data; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
408 |
const BoundShaders *s = (const BoundShaders *) sym; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
409 |
const uint16_t v = (s->vertex) ? s->vertex->tag : 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
410 |
const uint16_t f = (s->fragment) ? s->fragment->tag : 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
411 |
return ((uint32_t) v << 16) | (uint32_t) f; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
412 |
} // hash_shaders |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
413 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
414 |
static int match_shaders(const void *_a, const void *_b, void *data) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
415 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
416 |
(void) data; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
417 |
const BoundShaders *a = (const BoundShaders *) _a; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
418 |
const BoundShaders *b = (const BoundShaders *) _b; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
419 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
420 |
const uint16_t av = (a->vertex) ? a->vertex->tag : 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
421 |
const uint16_t bv = (b->vertex) ? b->vertex->tag : 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
422 |
if (av != bv) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
423 |
return 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
424 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
425 |
const uint16_t af = (a->fragment) ? a->fragment->tag : 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
426 |
const uint16_t bf = (b->fragment) ? b->fragment->tag : 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
427 |
if (af != bf) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
428 |
return 0; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
429 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
430 |
return 1; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
431 |
} // match_shaders |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
432 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
433 |
static void nuke_shaders(const void *key, const void *value, void *data) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
434 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
435 |
(void) data; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
436 |
ctx->free_fn((void *) key, ctx->malloc_data); // this was a BoundShaders struct. |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
437 |
MOJOSHADER_vkDeleteProgram((MOJOSHADER_vkProgram *) value); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
438 |
} // nuke_shaders |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
439 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
440 |
// Public API |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
441 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
442 |
MOJOSHADER_vkContext *MOJOSHADER_vkCreateContext( |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
443 |
VkInstance *instance, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
444 |
VkPhysicalDevice *physical_device, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
445 |
VkDevice *logical_device, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
446 |
int frames_in_flight, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
447 |
PFN_MOJOSHADER_vkGetInstanceProcAddr instance_lookup, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
448 |
PFN_MOJOSHADER_vkGetDeviceProcAddr device_lookup, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
449 |
unsigned int graphics_queue_family_index, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
450 |
unsigned int max_uniform_buffer_range, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
451 |
unsigned int min_uniform_buffer_offset_alignment, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
452 |
MOJOSHADER_malloc m, MOJOSHADER_free f, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
453 |
void *malloc_d |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
454 |
) { |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
455 |
MOJOSHADER_vkContext* resultCtx; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
456 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
457 |
if (m == NULL) m = MOJOSHADER_internal_malloc; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
458 |
if (f == NULL) f = MOJOSHADER_internal_free; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
459 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
460 |
resultCtx = (MOJOSHADER_vkContext *) m(sizeof(MOJOSHADER_vkContext), malloc_d); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
461 |
if (resultCtx == NULL) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
462 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
463 |
out_of_memory(); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
464 |
goto init_fail; |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
465 |
} // if |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
466 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
467 |
memset(resultCtx, '\0', sizeof(MOJOSHADER_vkContext)); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
468 |
resultCtx->malloc_fn = m; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
469 |
resultCtx->free_fn = f; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
470 |
resultCtx->malloc_data = malloc_d; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
471 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
472 |
resultCtx->instance = (VkInstance*) instance; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
473 |
resultCtx->physical_device = (VkPhysicalDevice*) physical_device; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
474 |
resultCtx->logical_device = (VkDevice*) logical_device; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
475 |
resultCtx->instance_proc_lookup = (PFN_vkGetInstanceProcAddr) instance_lookup; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
476 |
resultCtx->device_proc_lookup = (PFN_vkGetDeviceProcAddr) device_lookup; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
477 |
resultCtx->frames_in_flight = frames_in_flight; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
478 |
resultCtx->graphics_queue_family_index = graphics_queue_family_index; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
479 |
resultCtx->maxUniformBufferRange = max_uniform_buffer_range; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
480 |
resultCtx->minUniformBufferOffsetAlignment = min_uniform_buffer_offset_alignment; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
481 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
482 |
lookup_entry_points(resultCtx); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
483 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
484 |
resultCtx->vertUboBuffer = create_ubo(resultCtx); |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
485 |
resultCtx->fragUboBuffer = create_ubo(resultCtx); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
486 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
487 |
return resultCtx; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
488 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
489 |
init_fail: |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
490 |
if (resultCtx != NULL) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
491 |
f(resultCtx, malloc_d); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
492 |
return NULL; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
493 |
} // MOJOSHADER_vkCreateContext |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
494 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
495 |
void MOJOSHADER_vkMakeContextCurrent(MOJOSHADER_vkContext *_ctx) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
496 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
497 |
ctx = _ctx; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
498 |
} // MOJOSHADER_vkMakeContextCurrent |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
499 |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
500 |
void MOJOSHADER_vkDestroyContext(MOJOSHADER_vkContext *_ctx) |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
501 |
{ |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
502 |
MOJOSHADER_vkContext *current_ctx = ctx; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
503 |
ctx = _ctx; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
504 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
505 |
MOJOSHADER_vkBindProgram(NULL); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
506 |
if (ctx->linker_cache) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
507 |
hash_destroy(ctx->linker_cache); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
508 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
509 |
ctx->vkDestroyBuffer(*ctx->logical_device, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
510 |
ctx->vertUboBuffer->buffer, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
511 |
NULL); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
512 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
513 |
ctx->vkDestroyBuffer(*ctx->logical_device, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
514 |
ctx->fragUboBuffer->buffer, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
515 |
NULL); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
516 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
517 |
ctx->vkFreeMemory(*ctx->logical_device, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
518 |
ctx->vertUboBuffer->deviceMemory, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
519 |
NULL); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
520 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
521 |
ctx->vkFreeMemory(*ctx->logical_device, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
522 |
ctx->fragUboBuffer->deviceMemory, |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
523 |
NULL); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
524 |
|
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
525 |
ctx->free_fn(ctx->vertUboBuffer, ctx->malloc_data); |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
526 |
ctx->free_fn(ctx->fragUboBuffer, ctx->malloc_data); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
527 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
528 |
ctx->free_fn(ctx, ctx->malloc_data); |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
529 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
530 |
ctx = ((current_ctx == _ctx) ? NULL : current_ctx); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
531 |
} // MOJOSHADER_vkDestroyContext |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
532 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
533 |
MOJOSHADER_vkShader *MOJOSHADER_vkCompileShader( |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
534 |
const char *mainfn, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
535 |
const unsigned char *tokenbuf, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
536 |
const unsigned int bufsize, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
537 |
const MOJOSHADER_swizzle *swiz, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
538 |
const unsigned int swizcount, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
539 |
const MOJOSHADER_samplerMap *smap, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
540 |
const unsigned int smapcount |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
541 |
) { |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
542 |
MOJOSHADER_vkShader *shader; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
543 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
544 |
const MOJOSHADER_parseData *pd = MOJOSHADER_parse( |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
545 |
"spirv", mainfn, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
546 |
tokenbuf, bufsize, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
547 |
swiz, swizcount, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
548 |
smap, smapcount, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
549 |
ctx->malloc_fn, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
550 |
ctx->free_fn, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
551 |
ctx->malloc_data |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
552 |
); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
553 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
554 |
if (pd->error_count > 0) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
555 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
556 |
set_error(pd->errors[0].error); |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
557 |
goto parse_shader_fail; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
558 |
} // if |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
559 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
560 |
shader = (MOJOSHADER_vkShader *) ctx->malloc_fn(sizeof(MOJOSHADER_vkShader), ctx->malloc_data); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
561 |
if (shader == NULL) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
562 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
563 |
out_of_memory(); |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
564 |
goto parse_shader_fail; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
565 |
} // if |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
566 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
567 |
shader->parseData = pd; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
568 |
shader->refcount = 1; |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
569 |
shader->tag = tagCounter++; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
570 |
return shader; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
571 |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
572 |
parse_shader_fail: |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
573 |
MOJOSHADER_freeParseData(pd); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
574 |
if (shader != NULL) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
575 |
ctx->free_fn(shader, ctx->malloc_data); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
576 |
return NULL; |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
577 |
} // MOJOSHADER_vkCompileShader |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
578 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
579 |
void MOJOSHADER_vkShaderAddRef(MOJOSHADER_vkShader *shader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
580 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
581 |
if (shader != NULL) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
582 |
shader->refcount++; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
583 |
} // MOJOShader_vkShaderAddRef |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
584 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
585 |
void MOJOSHADER_vkDeleteShader(MOJOSHADER_vkShader *shader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
586 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
587 |
if (shader != NULL) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
588 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
589 |
if (shader->refcount > 1) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
590 |
shader->refcount--; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
591 |
else |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
592 |
{ |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
593 |
// See if this was bound as an unlinked program anywhere... |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
594 |
if (ctx->linker_cache) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
595 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
596 |
const void *key = NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
597 |
void *iter = NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
598 |
int morekeys = hash_iter_keys(ctx->linker_cache, &key, &iter); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
599 |
while (morekeys) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
600 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
601 |
const BoundShaders *shaders = (const BoundShaders *) key; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
602 |
// Do this here so we don't confuse the iteration by removing... |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
603 |
morekeys = hash_iter_keys(ctx->linker_cache, &key, &iter); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
604 |
if ((shaders->vertex == shader) || (shaders->fragment == shader)) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
605 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
606 |
// Deletes the linked program |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
607 |
hash_remove(ctx->linker_cache, shaders); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
608 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
609 |
} // while |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
610 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
611 |
|
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
612 |
MOJOSHADER_freeParseData(shader->parseData); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
613 |
ctx->free_fn(shader, ctx->malloc_data); |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
614 |
} // else |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
615 |
} // if |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
616 |
} // MOJOSHADER_vkDeleteShader |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
617 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
618 |
const MOJOSHADER_parseData *MOJOSHADER_vkGetShaderParseData( |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
619 |
MOJOSHADER_vkShader *shader |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
620 |
) { |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
621 |
return (shader != NULL) ? shader->parseData : NULL; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
622 |
} // MOJOSHADER_vkGetShaderParseData |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
623 |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
624 |
void MOJOSHADER_vkDeleteProgram(MOJOSHADER_vkProgram *p) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
625 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
626 |
if (p->vertexModule != VK_NULL_HANDLE) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
627 |
ctx->vkDestroyShaderModule(*ctx->logical_device, p->vertexModule, NULL); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
628 |
if (p->pixelModule != VK_NULL_HANDLE) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
629 |
ctx->vkDestroyShaderModule(*ctx->logical_device, p->pixelModule, NULL); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
630 |
ctx->free_fn(p, ctx->malloc_data); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
631 |
} // MOJOSHADER_vkDeleteProgram |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
632 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
633 |
MOJOSHADER_vkProgram *MOJOSHADER_vkLinkProgram(MOJOSHADER_vkShader *vshader, |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
634 |
MOJOSHADER_vkShader *pshader) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
635 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
636 |
MOJOSHADER_vkProgram *result; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
637 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
638 |
if ((vshader == NULL) && (pshader == NULL)) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
639 |
return NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
640 |
|
1280 | 641 |
result = (MOJOSHADER_vkProgram *) ctx->malloc_fn(sizeof (MOJOSHADER_vkProgram), |
642 |
ctx->malloc_data); |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
643 |
if (result == NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
644 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
645 |
out_of_memory(); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
646 |
return NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
647 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
648 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
649 |
MOJOSHADER_spirv_link_attributes(vshader->parseData, pshader->parseData); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
650 |
result->vertexModule = compile_shader(vshader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
651 |
result->pixelModule = compile_shader(pshader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
652 |
result->vertexShader = vshader; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
653 |
result->pixelShader = pshader; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
654 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
655 |
if (result->vertexModule == VK_NULL_HANDLE |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
656 |
|| result->pixelModule == VK_NULL_HANDLE) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
657 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
658 |
MOJOSHADER_vkDeleteProgram(result); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
659 |
return NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
660 |
} |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
661 |
return result; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
662 |
} // MOJOSHADER_vkLinkProgram |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
663 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
664 |
void MOJOSHADER_vkBindProgram(MOJOSHADER_vkProgram *p) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
665 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
666 |
ctx->bound_program = p; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
667 |
} // MOJOSHADER_vkBindProgram |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
668 |
|
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
669 |
void MOJOSHADER_vkBindShaders(MOJOSHADER_vkShader *vshader, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
670 |
MOJOSHADER_vkShader *pshader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
671 |
{ |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
672 |
if (ctx->linker_cache == NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
673 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
674 |
ctx->linker_cache = hash_create(NULL, hash_shaders, match_shaders, |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
675 |
nuke_shaders, 0, ctx->malloc_fn, |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
676 |
ctx->free_fn, ctx->malloc_data); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
677 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
678 |
if (ctx->linker_cache == NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
679 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
680 |
out_of_memory(); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
681 |
return; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
682 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
683 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
684 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
685 |
MOJOSHADER_vkProgram *program = NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
686 |
BoundShaders shaders; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
687 |
shaders.vertex = vshader; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
688 |
shaders.fragment = pshader; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
689 |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
690 |
const void *val = NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
691 |
if (hash_find(ctx->linker_cache, &shaders, &val)) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
692 |
program = (MOJOSHADER_vkProgram *) val; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
693 |
else |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
694 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
695 |
program = MOJOSHADER_vkLinkProgram(vshader, pshader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
696 |
if (program == NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
697 |
return; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
698 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
699 |
BoundShaders *item = (BoundShaders *) ctx->malloc_fn(sizeof (BoundShaders), |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
700 |
ctx->malloc_data); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
701 |
if (item == NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
702 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
703 |
MOJOSHADER_vkDeleteProgram(program); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
704 |
return; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
705 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
706 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
707 |
memcpy(item, &shaders, sizeof (BoundShaders)); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
708 |
if (hash_insert(ctx->linker_cache, item, program) != 1) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
709 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
710 |
ctx->free_fn(item, ctx->malloc_data); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
711 |
MOJOSHADER_vkDeleteProgram(program); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
712 |
out_of_memory(); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
713 |
return; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
714 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
715 |
} // else |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
716 |
|
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
717 |
assert(program != NULL); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
718 |
ctx->bound_program = program; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
719 |
} // MOJOSHADER_vkBindShaders |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
720 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
721 |
void MOJOSHADER_vkGetBoundShaders(MOJOSHADER_vkShader **vshader, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
722 |
MOJOSHADER_vkShader **pshader) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
723 |
{ |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
724 |
if (vshader != NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
725 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
726 |
if (ctx->bound_program != NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
727 |
*vshader = ctx->bound_program->vertexShader; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
728 |
else |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
729 |
*vshader = NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
730 |
} // if |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
731 |
if (pshader != NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
732 |
{ |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
733 |
if (ctx->bound_program != NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
734 |
*pshader = ctx->bound_program->pixelShader; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
735 |
else |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
736 |
*pshader = NULL; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
737 |
} // if |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
738 |
} // MOJOSHADER_vkGetBoundShaders |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
739 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
740 |
void MOJOSHADER_vkMapUniformBufferMemory(float **vsf, int **vsi, unsigned char **vsb, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
741 |
float **psf, int **psi, unsigned char **psb) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
742 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
743 |
*vsf = ctx->vs_reg_file_f; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
744 |
*vsi = ctx->vs_reg_file_i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
745 |
*vsb = ctx->vs_reg_file_b; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
746 |
*psf = ctx->ps_reg_file_f; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
747 |
*psi = ctx->ps_reg_file_i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
748 |
*psb = ctx->ps_reg_file_b; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
749 |
} // MOJOSHADER_vkMapUniformBufferMemory |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
750 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
751 |
void MOJOSHADER_vkUnmapUniformBufferMemory() |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
752 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
753 |
/* Why is this function named unmap instead of update? |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
754 |
* the world may never know... |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
755 |
*/ |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
756 |
assert(ctx->bound_program != NULL); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
757 |
update_uniform_buffer(ctx->bound_program->vertexShader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
758 |
update_uniform_buffer(ctx->bound_program->pixelShader); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
759 |
} // MOJOSHADER_vkUnmapUniformBufferMemory |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
760 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
761 |
void MOJOSHADER_vkGetUniformBuffers(VkBuffer *vbuf, unsigned long long *voff, unsigned long long *vsize, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
762 |
VkBuffer *pbuf, unsigned long long *poff, unsigned long long *psize) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
763 |
{ |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
764 |
assert(ctx->bound_program != NULL); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
765 |
*vbuf = get_uniform_buffer(ctx->bound_program->vertexShader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
766 |
*voff = get_uniform_offset(ctx->bound_program->vertexShader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
767 |
*vsize = get_uniform_size(ctx->bound_program->vertexShader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
768 |
*pbuf = get_uniform_buffer(ctx->bound_program->pixelShader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
769 |
*poff = get_uniform_offset(ctx->bound_program->pixelShader); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
770 |
*psize = get_uniform_size(ctx->bound_program->pixelShader); |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
771 |
} // MOJOSHADER_vkGetUniformBuffers |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
772 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
773 |
void MOJOSHADER_vkEndFrame() |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
774 |
{ |
1276
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
775 |
ctx->vertUboBuffer->dynamicOffset = 0; |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
776 |
ctx->vertUboBuffer->currentBlockSize = 0; |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
777 |
ctx->fragUboBuffer->dynamicOffset = 0; |
89c389e4112f
vulkan: Rework UBO allocation to use a single monolithic buffer
Evan Hemsley <evan@moonside.games>
parents:
1275
diff
changeset
|
778 |
ctx->fragUboBuffer->currentBlockSize = 0; |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
779 |
} // MOJOSHADER_VkEndFrame |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
780 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
781 |
int MOJOSHADER_vkGetVertexAttribLocation(MOJOSHADER_vkShader *vert, |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
782 |
MOJOSHADER_usage usage, int index) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
783 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
784 |
int32_t i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
785 |
if (vert == NULL) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
786 |
return -1; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
787 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
788 |
for (i = 0; i < vert->parseData->attribute_count; i++) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
789 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
790 |
if (vert->parseData->attributes[i].usage == usage && |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
791 |
vert->parseData->attributes[i].index == index) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
792 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
793 |
return i; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
794 |
} // if |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
795 |
} // for |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
796 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
797 |
// failure |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
798 |
return -1; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
799 |
} //MOJOSHADER_vkGetVertexAttribLocation |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
800 |
|
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
801 |
void MOJOSHADER_vkGetShaderModules(VkShaderModule *vmodule, |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
802 |
VkShaderModule *pmodule) |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
803 |
{ |
1277
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
804 |
assert(ctx->bound_program != NULL); |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
805 |
if (vmodule != NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
806 |
*vmodule = ctx->bound_program->vertexModule; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
807 |
if (pmodule != NULL) |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
808 |
*pmodule = ctx->bound_program->pixelModule; |
da61410edbc9
Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1276
diff
changeset
|
809 |
} //MOJOSHADER_vkGetShaderModules |
1271
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
810 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
811 |
const char *MOJOSHADER_vkGetError(void) |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
812 |
{ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
813 |
return error_buffer; |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
814 |
} // MOJOSHADER_vkGetError |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
815 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
816 |
#endif /* SUPPORT_PROFILE_SPIRV */ |
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
817 |
|
5a67d082c55f
Add support for Vulkan rendering.
Evan Hemsley <evan@moonside.games>
parents:
diff
changeset
|
818 |
// end of mojoshader_vulkan.c ... |