diff --git a/src/xrt/compositor/CMakeLists.txt b/src/xrt/compositor/CMakeLists.txt index 3dec567f6..2a2bbda95 100644 --- a/src/xrt/compositor/CMakeLists.txt +++ b/src/xrt/compositor/CMakeLists.txt @@ -25,7 +25,6 @@ set(MAIN_SOURCE_FILES main/comp_renderer.h main/comp_settings.c main/comp_settings.h - main/comp_shaders.c main/comp_swapchain.c main/comp_sync.c main/comp_target.h @@ -41,6 +40,7 @@ set(MAIN_SOURCE_FILES render/comp_render.h render/comp_rendering.c render/comp_resources.c + render/comp_shaders.c render/comp_util.c ) diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 88b7bf79d..2fbb8e467 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -580,7 +580,7 @@ compositor_destroy(struct xrt_compositor *xc) 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. comp_shaders_close(vk, &c->shaders); @@ -1368,7 +1368,7 @@ compositor_init_shaders(struct comp_compositor *c) static bool 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; } diff --git a/src/xrt/compositor/main/comp_compositor.h b/src/xrt/compositor/main/comp_compositor.h index 69ca7be39..0f0076349 100644 --- a/src/xrt/compositor/main/comp_compositor.h +++ b/src/xrt/compositor/main/comp_compositor.h @@ -137,24 +137,6 @@ enum comp_state 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. @@ -339,18 +321,6 @@ comp_compositor_import_fence(struct xrt_compositor *xc, xrt_graphics_sync_handle_t handle, 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. * diff --git a/src/xrt/compositor/meson.build b/src/xrt/compositor/meson.build index 29674d0d0..cf6198520 100644 --- a/src/xrt/compositor/meson.build +++ b/src/xrt/compositor/meson.build @@ -20,7 +20,6 @@ compositor_srcs = [ 'main/comp_renderer.h', 'main/comp_settings.c', 'main/comp_settings.h', - 'main/comp_shaders.c', 'main/comp_swapchain.c', 'main/comp_sync.c', 'main/comp_target.h', @@ -38,6 +37,7 @@ compositor_srcs = [ 'render/comp_render.h', 'render/comp_rendering.c', 'render/comp_resources.c', + 'render/comp_shaders.c', 'render/comp_util.c', ] diff --git a/src/xrt/compositor/render/comp_render.h b/src/xrt/compositor/render/comp_render.h index 3d4f35831..77241f034 100644 --- a/src/xrt/compositor/render/comp_render.h +++ b/src/xrt/compositor/render/comp_render.h @@ -60,6 +60,47 @@ comp_calc_time_warp_matrix(const struct xrt_pose *src_pose, 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 @@ -141,6 +182,14 @@ comp_buffer_write(struct vk_bundle *vk, struct comp_buffer *buffer, void *data, */ struct comp_resources { + /* + * Loaded resources. + */ + + //! All shaders loaded. + struct comp_shaders *shaders; + + /* * Shared pools and caches. */ @@ -244,13 +293,13 @@ struct comp_resources * @ingroup comp_main */ 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. */ void -comp_resources_close(struct comp_compositor *c, struct comp_resources *r); +comp_resources_close(struct comp_resources *r, struct comp_compositor *c); /* diff --git a/src/xrt/compositor/render/comp_resources.c b/src/xrt/compositor/render/comp_resources.c index bb3bfe80a..15f0bcf32 100644 --- a/src/xrt/compositor/render/comp_resources.c +++ b/src/xrt/compositor/render/comp_resources.c @@ -634,11 +634,18 @@ create_and_file_in_distortion_buffer_for_view(struct vk_bundle *vk, */ 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 xrt_device *xdev = c->xdev; + /* + * Shaders + */ + + r->shaders = shaders; + + /* * Constants */ @@ -740,21 +747,21 @@ comp_resources_init(struct comp_compositor *c, struct comp_resources *r) C(create_compute_pipeline( // vk, // vk_bundle r->pipeline_cache, // pipeline_cache - c->shaders.clear_comp, // shader + r->shaders->clear_comp, // shader r->compute.pipeline_layout, // pipeline_layout &r->compute.clear_pipeline)); // out_compute_pipeline C(create_compute_pipeline( // vk, // vk_bundle r->pipeline_cache, // pipeline_cache - c->shaders.distortion_comp, // shader + r->shaders->distortion_comp, // shader r->compute.pipeline_layout, // pipeline_layout &r->compute.distortion_pipeline)); // out_compute_pipeline C(create_compute_pipeline( // vk, // vk_bundle 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.distortion_timewarp_pipeline)); // out_compute_pipeline @@ -818,7 +825,7 @@ comp_resources_init(struct comp_compositor *c, struct comp_resources *r) } 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; diff --git a/src/xrt/compositor/main/comp_shaders.c b/src/xrt/compositor/render/comp_shaders.c similarity index 100% rename from src/xrt/compositor/main/comp_shaders.c rename to src/xrt/compositor/render/comp_shaders.c