c/render: Move shaders to render

This commit is contained in:
Jakob Bornecrantz 2021-10-01 21:07:47 +01:00
parent 8c8d72647b
commit 56f4466ffa
7 changed files with 67 additions and 41 deletions

View file

@ -25,7 +25,6 @@ set(MAIN_SOURCE_FILES
main/comp_renderer.h main/comp_renderer.h
main/comp_settings.c main/comp_settings.c
main/comp_settings.h main/comp_settings.h
main/comp_shaders.c
main/comp_swapchain.c main/comp_swapchain.c
main/comp_sync.c main/comp_sync.c
main/comp_target.h main/comp_target.h
@ -41,6 +40,7 @@ set(MAIN_SOURCE_FILES
render/comp_render.h render/comp_render.h
render/comp_rendering.c render/comp_rendering.c
render/comp_resources.c render/comp_resources.c
render/comp_shaders.c
render/comp_util.c render/comp_util.c
) )

View file

@ -580,7 +580,7 @@ compositor_destroy(struct xrt_compositor *xc)
comp_renderer_destroy(&c->r); comp_renderer_destroy(&c->r);
comp_resources_close(c, &c->nr); comp_resources_close(&c->nr, c);
// As long as vk_bundle is valid it's safe to call this function. // As long as vk_bundle is valid it's safe to call this function.
comp_shaders_close(vk, &c->shaders); comp_shaders_close(vk, &c->shaders);
@ -1368,7 +1368,7 @@ compositor_init_shaders(struct comp_compositor *c)
static bool static bool
compositor_init_renderer(struct comp_compositor *c) compositor_init_renderer(struct comp_compositor *c)
{ {
if (!comp_resources_init(c, &c->nr)) { if (!comp_resources_init(&c->nr, c, &c->shaders)) {
return false; return false;
} }

View file

@ -137,24 +137,6 @@ enum comp_state
COMP_STATE_FOCUSED = 4, COMP_STATE_FOCUSED = 4,
}; };
struct comp_shaders
{
VkShaderModule clear_comp;
VkShaderModule distortion_comp;
VkShaderModule distortion_timewarp_comp;
VkShaderModule mesh_vert;
VkShaderModule mesh_frag;
VkShaderModule equirect1_vert;
VkShaderModule equirect1_frag;
VkShaderModule equirect2_vert;
VkShaderModule equirect2_frag;
VkShaderModule layer_vert;
VkShaderModule layer_frag;
};
/*! /*!
* Tracking frame state. * Tracking frame state.
@ -339,18 +321,6 @@ comp_compositor_import_fence(struct xrt_compositor *xc,
xrt_graphics_sync_handle_t handle, xrt_graphics_sync_handle_t handle,
struct xrt_compositor_fence **out_xcf); struct xrt_compositor_fence **out_xcf);
/*!
* Loads all of the shaders that the compositor uses.
*/
bool
comp_shaders_load(struct vk_bundle *vk, struct comp_shaders *s);
/*!
* Unload and cleanup shaders.
*/
void
comp_shaders_close(struct vk_bundle *vk, struct comp_shaders *s);
/*! /*!
* Spew level logging. * Spew level logging.
* *

View file

@ -20,7 +20,6 @@ compositor_srcs = [
'main/comp_renderer.h', 'main/comp_renderer.h',
'main/comp_settings.c', 'main/comp_settings.c',
'main/comp_settings.h', 'main/comp_settings.h',
'main/comp_shaders.c',
'main/comp_swapchain.c', 'main/comp_swapchain.c',
'main/comp_sync.c', 'main/comp_sync.c',
'main/comp_target.h', 'main/comp_target.h',
@ -38,6 +37,7 @@ compositor_srcs = [
'render/comp_render.h', 'render/comp_render.h',
'render/comp_rendering.c', 'render/comp_rendering.c',
'render/comp_resources.c', 'render/comp_resources.c',
'render/comp_shaders.c',
'render/comp_util.c', 'render/comp_util.c',
] ]

View file

@ -60,6 +60,47 @@ comp_calc_time_warp_matrix(const struct xrt_pose *src_pose,
bool disable_atw); bool disable_atw);
/*
*
* Shaders.
*
*/
/*!
* Holds all shaders.
*/
struct comp_shaders
{
VkShaderModule clear_comp;
VkShaderModule distortion_comp;
VkShaderModule distortion_timewarp_comp;
VkShaderModule mesh_vert;
VkShaderModule mesh_frag;
VkShaderModule equirect1_vert;
VkShaderModule equirect1_frag;
VkShaderModule equirect2_vert;
VkShaderModule equirect2_frag;
VkShaderModule layer_vert;
VkShaderModule layer_frag;
};
/*!
* Loads all of the shaders that the compositor uses.
*/
bool
comp_shaders_load(struct vk_bundle *vk, struct comp_shaders *s);
/*!
* Unload and cleanup shaders.
*/
void
comp_shaders_close(struct vk_bundle *vk, struct comp_shaders *s);
/* /*
* *
* Buffer * Buffer
@ -141,6 +182,14 @@ comp_buffer_write(struct vk_bundle *vk, struct comp_buffer *buffer, void *data,
*/ */
struct comp_resources struct comp_resources
{ {
/*
* Loaded resources.
*/
//! All shaders loaded.
struct comp_shaders *shaders;
/* /*
* Shared pools and caches. * Shared pools and caches.
*/ */
@ -244,13 +293,13 @@ struct comp_resources
* @ingroup comp_main * @ingroup comp_main
*/ */
bool bool
comp_resources_init(struct comp_compositor *c, struct comp_resources *r); comp_resources_init(struct comp_resources *r, struct comp_compositor *c, struct comp_shaders *shaders);
/*! /*!
* Free all pools and static resources, does not free the struct itself. * Free all pools and static resources, does not free the struct itself.
*/ */
void void
comp_resources_close(struct comp_compositor *c, struct comp_resources *r); comp_resources_close(struct comp_resources *r, struct comp_compositor *c);
/* /*

View file

@ -634,11 +634,18 @@ create_and_file_in_distortion_buffer_for_view(struct vk_bundle *vk,
*/ */
bool bool
comp_resources_init(struct comp_compositor *c, struct comp_resources *r) comp_resources_init(struct comp_resources *r, struct comp_compositor *c, struct comp_shaders *shaders)
{ {
struct vk_bundle *vk = &c->vk; struct vk_bundle *vk = &c->vk;
struct xrt_device *xdev = c->xdev; struct xrt_device *xdev = c->xdev;
/*
* Shaders
*/
r->shaders = shaders;
/* /*
* Constants * Constants
*/ */
@ -740,21 +747,21 @@ comp_resources_init(struct comp_compositor *c, struct comp_resources *r)
C(create_compute_pipeline( // C(create_compute_pipeline( //
vk, // vk_bundle vk, // vk_bundle
r->pipeline_cache, // pipeline_cache r->pipeline_cache, // pipeline_cache
c->shaders.clear_comp, // shader r->shaders->clear_comp, // shader
r->compute.pipeline_layout, // pipeline_layout r->compute.pipeline_layout, // pipeline_layout
&r->compute.clear_pipeline)); // out_compute_pipeline &r->compute.clear_pipeline)); // out_compute_pipeline
C(create_compute_pipeline( // C(create_compute_pipeline( //
vk, // vk_bundle vk, // vk_bundle
r->pipeline_cache, // pipeline_cache r->pipeline_cache, // pipeline_cache
c->shaders.distortion_comp, // shader r->shaders->distortion_comp, // shader
r->compute.pipeline_layout, // pipeline_layout r->compute.pipeline_layout, // pipeline_layout
&r->compute.distortion_pipeline)); // out_compute_pipeline &r->compute.distortion_pipeline)); // out_compute_pipeline
C(create_compute_pipeline( // C(create_compute_pipeline( //
vk, // vk_bundle vk, // vk_bundle
r->pipeline_cache, // pipeline_cache r->pipeline_cache, // pipeline_cache
c->shaders.distortion_timewarp_comp, // shader r->shaders->distortion_timewarp_comp, // shader
r->compute.pipeline_layout, // pipeline_layout r->compute.pipeline_layout, // pipeline_layout
&r->compute.distortion_timewarp_pipeline)); // out_compute_pipeline &r->compute.distortion_timewarp_pipeline)); // out_compute_pipeline
@ -818,7 +825,7 @@ comp_resources_init(struct comp_compositor *c, struct comp_resources *r)
} }
void void
comp_resources_close(struct comp_compositor *c, struct comp_resources *r) comp_resources_close(struct comp_resources *r, struct comp_compositor *c)
{ {
struct vk_bundle *vk = &c->vk; struct vk_bundle *vk = &c->vk;