1 #ifndef HALIDE_HALIDERUNTIMEOPENGL_H
2 #define HALIDE_HALIDERUNTIMEOPENGL_H
3 
4 // Don't include HalideRuntime.h if the contents of it were already pasted into a generated header above this one
5 #ifndef HALIDE_HALIDERUNTIME_H
6 
7 #include "HalideRuntime.h"
8 
9 #endif
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /** \file
16  *  Routines specific to the Halide OpenGL runtime.
17  */
18 
19 #define HALIDE_RUNTIME_OPENGL
20 
21 extern const struct halide_device_interface_t *halide_opengl_device_interface();
22 
23 /** These are forward declared here to allow clients to override the
24  *  Halide Glsl runtime. Do not call them. */
25 // @{
26 extern int halide_opengl_initialize_kernels(void *user_context, void **state_ptr,
27                                             const char *src, int size);
28 
29 extern int halide_opengl_run(void *user_context,
30                              void *state_ptr,
31                              const char *entry_name,
32                              int blocksX, int blocksY, int blocksZ,
33                              int threadsX, int threadsY, int threadsZ,
34                              int shared_mem_bytes,
35                              size_t arg_sizes[],
36                              void *args[],
37                              int8_t is_buffer[],
38                              int num_attributes,
39                              float *vertex_buffer,
40                              int num_coords_dim0,
41                              int num_coords_dim1);
42 // @}
43 
44 /** Set the underlying OpenGL texture for a buffer. The texture must
45  * have an extent large enough to cover that specified by the
46  * halide_buffer_t extent fields. The dev field of the halide_buffer_t
47  * must be NULL when this routine is called. This call can fail due to
48  * being passed an invalid texture. The device and host dirty bits are
49  * left unmodified. */
50 extern int halide_opengl_wrap_texture(void *user_context, struct halide_buffer_t *buf, uint64_t texture_id);
51 
52 /** Set the underlying OpenGL texture for a buffer to refer to the
53  * current render target (e.g., the frame buffer or an FBO). The
54  * render target must have an extent large enough to cover that
55  * specified by the halide_buffer_t extent fields. The dev field of
56  * the halide_buffer_t must be NULL when this routine is called. This
57  * call can fail due to running out of memory. The device and host
58  * dirty bits are left unmodified. */
59 extern int halide_opengl_wrap_render_target(void *user_context, struct halide_buffer_t *buf);
60 
61 /** Disconnect this halide_buffer_t from the texture it was previously
62  * wrapped around. Should only be called for a halide_buffer_t that
63  * halide_opengl_wrap_texture was previously called on. Frees any
64  * storage associated with the binding of the halide_buffer_t and the
65  * device pointer, but does not free the texture.  The dev field of
66  * the halide_buffer_t will be NULL on return.
67  */
68 extern int halide_opengl_detach_texture(void *user_context, struct halide_buffer_t *buf);
69 
70 /** Return the underlying texture for a halide_buffer_t. This buffer
71  *  must be valid on an OpenGL device, or not have any associated
72  *  device memory. If there is no device memory (dev field is NULL),
73  *  or if the buffer was wrapped via
74  *  halide_opengl_wrap_render_target(), this returns 0.
75  */
76 extern uintptr_t halide_opengl_get_texture(void *user_context, struct halide_buffer_t *buf);
77 
78 /** Forget all state associated with the previous OpenGL context.  This is
79  * similar to halide_opengl_release, except that we assume that all OpenGL
80  * resources have already been reclaimed by the OS. */
81 extern void halide_opengl_context_lost(void *user_context);
82 
83 /** This functions MUST be provided by the host environment to retrieve pointers
84  *  to OpenGL API functions. */
85 void *halide_opengl_get_proc_address(void *user_context, const char *name);
86 
87 /** This functions MUST be provided by the host environment to create an OpenGL
88  *  context for use by the OpenGL backend. */
89 int halide_opengl_create_context(void *user_context);
90 
91 #ifdef __cplusplus
92 }  // End extern "C"
93 #endif
94 
95 #endif  // HALIDE_HALIDERUNTIMEOPENGL_H
96