tangled
alpha
login
or
join now
matrixfurry.com
/
monado
0
fork
atom
The open source OpenXR runtime
0
fork
atom
overview
issues
pulls
pipelines
a/ogl: Add helper to import native images
Jakob Bornecrantz
2 years ago
95e1c9c8
1a543cb0
+115
2 changed files
expand all
collapse all
unified
split
src
xrt
auxiliary
ogl
ogl_helpers.c
ogl_helpers.h
+83
src/xrt/auxiliary/ogl/ogl_helpers.c
···
7
7
* @ingroup aux_ogl
8
8
*/
9
9
10
10
+
#include "util/u_handles.h"
10
11
#include "util/u_logging.h"
11
12
12
13
#include "ogl_helpers.h"
···
14
15
15
16
#include <inttypes.h>
16
17
18
18
+
/*!
19
19
+
* Check for OpenGL errors, context needs to be current.
20
20
+
*
21
21
+
* @ingroup sdl_test
22
22
+
*/
23
23
+
#define CHECK_GL() \
24
24
+
do { \
25
25
+
GLint err = glGetError(); \
26
26
+
if (err != 0) { \
27
27
+
U_LOG_RAW("%s:%u: error: 0x%04x", __func__, __LINE__, err); \
28
28
+
} \
29
29
+
} while (false)
30
30
+
31
31
+
32
32
+
/*
33
33
+
*
34
34
+
* 'Exported' functions.
35
35
+
*
36
36
+
*/
17
37
18
38
void
19
39
ogl_texture_target_for_swapchain_info(const struct xrt_swapchain_create_info *info,
···
72
92
default: U_LOG_W("Cannot convert VK format %" PRIu64 " to GL format!", vk_format); return 0;
73
93
}
74
94
}
95
95
+
96
96
+
XRT_CHECK_RESULT bool
97
97
+
ogl_import_from_native(struct xrt_image_native *natives,
98
98
+
uint32_t native_count,
99
99
+
const struct xrt_swapchain_create_info *info,
100
100
+
struct ogl_import_results *results)
101
101
+
{
102
102
+
// Setup fields.
103
103
+
results->width = info->width;
104
104
+
results->height = info->height;
105
105
+
results->image_count = native_count;
106
106
+
107
107
+
GLuint binding_enum = 0;
108
108
+
GLuint tex_target = 0;
109
109
+
ogl_texture_target_for_swapchain_info(info, &tex_target, &binding_enum);
110
110
+
111
111
+
GLuint gl_format = ogl_vk_format_to_gl(info->format);
112
112
+
113
113
+
glCreateTextures(tex_target, native_count, results->textures);
114
114
+
CHECK_GL();
115
115
+
glCreateMemoryObjectsEXT(native_count, results->memories);
116
116
+
CHECK_GL();
117
117
+
118
118
+
for (uint32_t i = 0; i < native_count; i++) {
119
119
+
GLint dedicated = natives[i].use_dedicated_allocation ? GL_TRUE : GL_FALSE;
120
120
+
glMemoryObjectParameterivEXT(results->memories[i], GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated);
121
121
+
CHECK_GL();
122
122
+
123
123
+
// The below function consumes the handle, need to reference it.
124
124
+
xrt_graphics_buffer_handle_t handle = u_graphics_buffer_ref(natives[i].handle);
125
125
+
126
126
+
glImportMemoryFdEXT( //
127
127
+
results->memories[i], //
128
128
+
natives[i].size, //
129
129
+
GL_HANDLE_TYPE_OPAQUE_FD_EXT, //
130
130
+
(GLint)handle); //
131
131
+
CHECK_GL();
132
132
+
133
133
+
if (info->array_size == 1) {
134
134
+
glTextureStorageMem2DEXT( //
135
135
+
results->textures[i], //
136
136
+
info->mip_count, //
137
137
+
gl_format, //
138
138
+
info->width, //
139
139
+
info->height, //
140
140
+
results->memories[i], //
141
141
+
0); //
142
142
+
} else {
143
143
+
glTextureStorageMem3DEXT( //
144
144
+
results->textures[i], //
145
145
+
info->mip_count, //
146
146
+
gl_format, //
147
147
+
info->width, //
148
148
+
info->height, //
149
149
+
info->array_size, //
150
150
+
results->memories[i], //
151
151
+
0); //
152
152
+
}
153
153
+
CHECK_GL();
154
154
+
}
155
155
+
156
156
+
return true;
157
157
+
}
+32
src/xrt/auxiliary/ogl/ogl_helpers.h
···
16
16
extern "C" {
17
17
#endif
18
18
19
19
+
20
20
+
/*!
21
21
+
* Results from a import, nicer then having to pass in multiple arrays.
22
22
+
*
23
23
+
* @ingroup aux_ogl
24
24
+
*/
25
25
+
struct ogl_import_results
26
26
+
{
27
27
+
//! Imported textures.
28
28
+
uint32_t textures[XRT_MAX_SWAPCHAIN_IMAGES];
29
29
+
30
30
+
//! Memory objects for imported textures.
31
31
+
uint32_t memories[XRT_MAX_SWAPCHAIN_IMAGES];
32
32
+
33
33
+
//! The count of textures and memories.
34
34
+
uint32_t image_count;
35
35
+
36
36
+
//! Dimensions.
37
37
+
uint32_t width, height;
38
38
+
};
39
39
+
19
40
/*!
20
41
* Determine the texture target and the texture binding parameter to
21
42
* save/restore for creation/use of an OpenGL texture from the given info.
···
35
56
*/
36
57
XRT_CHECK_RESULT uint32_t
37
58
ogl_vk_format_to_gl(int64_t vk_format);
59
59
+
60
60
+
/*!
61
61
+
* Import native images, a context needs to be current when called.
62
62
+
*
63
63
+
* @ingroup aux_ogl
64
64
+
*/
65
65
+
XRT_CHECK_RESULT bool
66
66
+
ogl_import_from_native(struct xrt_image_native *natives,
67
67
+
uint32_t native_count,
68
68
+
const struct xrt_swapchain_create_info *info,
69
69
+
struct ogl_import_results *results);
38
70
39
71
40
72
#ifdef __cplusplus