Skip to content

Commit 587efdb

Browse files
committed
-Dev: headless rendering support + test. Caputuring of attachments and save to CPU done
1 parent 537291a commit 587efdb

File tree

33 files changed

+2345
-382
lines changed

33 files changed

+2345
-382
lines changed

include/engine/core/passes/tonemapping_pass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum TonemappingType
2525
/*
2626
Tonemapping Pass.
2727
*/
28-
class TonemappingPass final : public PostProcessPass<1, 0>
28+
class TonemappingPass final : public PostProcessPass<1, 1>
2929
{
3030
protected:
3131
float m_exposure = 1.0f;
@@ -45,7 +45,7 @@ class TonemappingPass final : public PostProcessPass<1, 0>
4545
- Tonemapped Color
4646
4747
*/
48-
TonemappingPass(Graphics::Device* device, const PassLinkage<1, 0>& config, Extent2D extent, ColorFormatType colorFormat, bool isDefault = true)
48+
TonemappingPass(Graphics::Device* device, const PassLinkage<1, 1>& config, Extent2D extent, ColorFormatType colorFormat, bool isDefault = true)
4949
: PostProcessPass(device, config, extent, colorFormat, ENGINE_RESOURCES_PATH "shaders/misc/tonemapping.glsl", "TONEMAPPING", isDefault) {
5050
m_interAttachments.resize(1);
5151
}

include/engine/core/resource_manager.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,13 @@ class ResourceManager
5454
static void update_global_data(Graphics::Device* const device,
5555
Graphics::Frame* const currentFrame,
5656
Core::Scene* const scene,
57-
Core::IWindow* const window,
57+
Extent2D displayExtent,
5858
bool jitterCamera);
5959
/*
6060
Object descriptor layouts uniforms buffer upload to GPU
6161
*/
62-
static void update_object_data(Graphics::Device* const device,
63-
Graphics::Frame* const currentFrame,
64-
Core::Scene* const scene,
65-
Core::IWindow* const window,
66-
bool enableRT);
62+
static void
63+
update_object_data(Graphics::Device* const device, Graphics::Frame* const currentFrame, Core::Scene* const scene, Extent2D displayExtent, bool enableRT);
6764
/*
6865
Initialize and setup texture IMAGE
6966
*/
@@ -72,8 +69,7 @@ class ResourceManager
7269
/*
7370
Upload geometry vertex buffers to the GPU
7471
*/
75-
static void
76-
upload_geometry_data(Graphics::Device* const device, Core::Geometry* const g, bool createAccelStructure = true);
72+
static void upload_geometry_data(Graphics::Device* const device, Core::Geometry* const g, bool createAccelStructure = true);
7773
static void destroy_geometry_data(Core::Geometry* const g);
7874
/*
7975
Uploads scene's skybox resources (cube mesh and panorama texture)

include/engine/core/textures/textureLDR.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class TextureLDR : public ITexture
3636
, m_tmpCache(data) {
3737
m_image.loadedOnCPU = true;
3838
}
39+
~TextureLDR(){
40+
free(m_tmpCache);
41+
}
3942

4043
inline void set_image_cache(void* cache, Extent3D extent, uint16_t channels) {
4144
m_tmpCache = static_cast<unsigned char*>(cache);

include/engine/graphics/buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct Buffer {
3131

3232
void upload_data(const void* bufferData, size_t size);
3333
void upload_data(const void* bufferData, size_t size, size_t offset);
34+
void copy_to(void* data);
3435
uint64_t get_device_address();
3536
void cleanup();
3637
};

include/engine/graphics/command_buffer.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,16 @@ struct CommandBuffer {
3434
void begin(VkCommandBufferUsageFlags flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
3535
void end();
3636
void reset();
37-
void
38-
submit(Fence fence = {}, std::vector<Semaphore> waitSemaphores = {}, std::vector<Semaphore> signalSemaphores = {});
37+
void submit(Fence fence = {}, std::vector<Semaphore> waitSemaphores = {}, std::vector<Semaphore> signalSemaphores = {});
3938
void cleanup();
4039

4140
/****************************************** */
4241
/* COMMANDS */
4342
/****************************************** */
4443

45-
void begin_renderpass(RenderPass& renderpass,
46-
Framebuffer& fbo,
47-
VkSubpassContents subpassContents = VK_SUBPASS_CONTENTS_INLINE);
44+
void begin_renderpass(RenderPass& renderpass, Framebuffer& fbo, VkSubpassContents subpassContents = VK_SUBPASS_CONTENTS_INLINE);
4845
void end_renderpass(RenderPass& renderpass, Framebuffer& fbo);
49-
void draw_geometry(VertexArrays& vao,
50-
uint32_t instanceCount = 1,
51-
uint32_t firstOcurrence = 0,
52-
int32_t offset = 0,
53-
uint32_t firstInstance = 0);
46+
void draw_geometry(VertexArrays& vao, uint32_t instanceCount = 1, uint32_t firstOcurrence = 0, int32_t offset = 0, uint32_t firstInstance = 0);
5447
void draw_gui_data();
5548
void bind_shaderpass(ShaderPass& pass);
5649
void bind_descriptor_set(DescriptorSet descriptor,
@@ -82,10 +75,7 @@ struct CommandBuffer {
8275
PipelineStage srcStage = STAGE_COLOR_ATTACHMENT_OUTPUT,
8376
PipelineStage dstStage = STAGE_FRAGMENT_SHADER);
8477

85-
void clear_image(Image& img,
86-
ImageLayout layout,
87-
ImageAspect aspect = ASPECT_COLOR,
88-
Vec4 clearColor = Vec4(0.0f, 0.0f, 0.0f, 1.0f));
78+
void clear_image(Image& img, ImageLayout layout, ImageAspect aspect = ASPECT_COLOR, Vec4 clearColor = Vec4(0.0f, 0.0f, 0.0f, 1.0f));
8979

9080
/*Copy the entire extent of the image*/
9181
void blit_image(Image& srcImage,
@@ -117,13 +107,13 @@ struct CommandBuffer {
117107
Expected layout is LAYOUT_UNDEFINED
118108
*/
119109
void copy_buffer_to_image(Image& img, Buffer& buffer);
110+
111+
void copy_image_to_buffer(Image& img, Buffer& buffer);
120112

121113
/*
122114
Generates mipmaps for a given image following a downsampling by 2 strategy
123115
*/
124-
void generate_mipmaps(Image& img,
125-
ImageLayout initialLayout = LAYOUT_TRANSFER_DST_OPTIMAL,
126-
ImageLayout finalLayout = LAYOUT_SHADER_READ_ONLY_OPTIMAL);
116+
void generate_mipmaps(Image& img, ImageLayout initialLayout = LAYOUT_TRANSFER_DST_OPTIMAL, ImageLayout finalLayout = LAYOUT_SHADER_READ_ONLY_OPTIMAL);
127117
};
128118
struct CommandPool {
129119
VkCommandPool handle = VK_NULL_HANDLE;

include/engine/graphics/device.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class Device
9595
uint32_t framesPerFlight,
9696
ColorFormatType presentFormat,
9797
SyncType presentMode);
98+
99+
void init_headless();
100+
98101
void update_swapchain(Extent2D surfaceExtent, uint32_t framesPerFlight, ColorFormatType presentFormat, SyncType presentMode);
99102
void cleanup();
100103

@@ -167,12 +170,13 @@ class Device
167170
void upload_texture_image(Image& img, ImageConfig config, SamplerConfig samplerConfig, const void* imgCache, size_t bytesPerPixel);
168171
void upload_BLAS(BLAS& accel, VAO& vao);
169172
void upload_TLAS(TLAS& accel, std::vector<BLASInstance>& BLASinstances);
173+
void download_texture_image(Image& img, void*& imgCache, size_t& outSize);
170174
/*
171175
MISC
172176
-----------------------------------------------
173177
*/
174-
void wait();
175-
void wait_queue(QueueType queueType);
178+
void wait_idle();
179+
void wait_queue_idle(QueueType queueType);
176180
void init_imgui(void* windowHandle, WindowingSystem windowingSystem, RenderPass renderPass, uint16_t samples);
177181
void destroy_imgui();
178182
uint32_t get_memory_type(uint32_t typeBits, MemoryPropertyFlags properties, uint32_t* memTypeFound = nullptr);

include/engine/graphics/image.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct Image {
5252
VkSampler sampler = VK_NULL_HANDLE;
5353
VkDescriptorSet GUIReadHandle = VK_NULL_HANDLE;
5454

55-
/*State parameters*/
55+
/*Config parameters*/
5656
Extent3D extent = {0, 0, 1}; // Depth for 3D Textures
5757
ImageLayout currentLayout = LAYOUT_UNDEFINED;
5858
uint32_t layers = 1; // Layers for Cubemaps and Arrays

include/engine/graphics/swapchain.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ VULKAN_ENGINE_NAMESPACE_BEGIN
1919
namespace Graphics {
2020
class Swapchain
2121
{
22-
VkSwapchainKHR m_handle;
23-
VkDevice m_device;
24-
VkSurfaceKHR m_surface;
25-
VkFormat m_presentFormat;
26-
VkPresentModeKHR m_presentMode;
27-
std::vector<Image> m_presentImages;
22+
VkSwapchainKHR m_handle = VK_NULL_HANDLE;
23+
VkDevice m_device = VK_NULL_HANDLE;
24+
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
25+
VkFormat m_presentFormat;
26+
VkPresentModeKHR m_presentMode;
27+
std::vector<Image> m_presentImages;
2828

2929
bool m_initialized{false};
3030

31-
VkSurfaceFormatKHR choose_swap_surface_format(const std::vector<VkSurfaceFormatKHR>& availableFormats,
32-
VkFormat desiredFormat);
33-
VkPresentModeKHR choose_swap_present_mode(const std::vector<VkPresentModeKHR>& availablePresentModes,
34-
VkPresentModeKHR desiredMode);
31+
VkSurfaceFormatKHR choose_swap_surface_format(const std::vector<VkSurfaceFormatKHR>& availableFormats, VkFormat desiredFormat);
32+
VkPresentModeKHR choose_swap_present_mode(const std::vector<VkPresentModeKHR>& availablePresentModes, VkPresentModeKHR desiredMode);
3533
VkExtent2D choose_swap_extent(const VkSurfaceCapabilitiesKHR& capabilities, VkExtent2D actualExtent);
3634

3735
void create_image_views(VkDevice& device);

include/engine/graphics/utilities/bootstrap.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ namespace Graphics {
1818
namespace Booter {
1919
#pragma region Instance
2020
// Instance
21-
VkInstance create_instance(const char* appName,
22-
const char* engineName,
23-
bool validation,
24-
std::vector<const char*> validationLayers);
21+
VkInstance create_instance(const char* appName, const char* engineName, bool validation, std::vector<const char*> validationLayers);
2522

2623
#pragma region Validation
2724
// Validation Logger
28-
VkDebugUtilsMessengerEXT create_debug_messenger(VkInstance instance);
29-
void populate_debug_messenger_create_info(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
25+
VkDebugUtilsMessengerEXT create_debug_messenger(VkInstance instance);
26+
void populate_debug_messenger_create_info(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
3027
inline static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
3128
VkDebugUtilsMessageTypeFlagsEXT messageType,
3229
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
@@ -40,15 +37,12 @@ VkResult create_debug_utils_messenger_EXT(VkInstance
4037
const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
4138
const VkAllocationCallbacks* pAllocator,
4239
VkDebugUtilsMessengerEXT* pDebugMessenger);
43-
void destroy_debug_utils_messenger_EXT(VkInstance instance,
44-
VkDebugUtilsMessengerEXT debugMessenger,
45-
const VkAllocationCallbacks* pAllocator);
40+
void destroy_debug_utils_messenger_EXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator);
4641
#pragma region GPU
4742
// GPU
48-
VkPhysicalDevice
49-
pick_graphics_card_device(VkInstance instance, VkSurfaceKHR surface, std::vector<const char*> extensions);
50-
int rate_device_suitability(VkPhysicalDevice device, VkSurfaceKHR surface, std::vector<const char*> extensions);
51-
bool check_device_extension_support(VkPhysicalDevice device, std::vector<const char*> extensions);
43+
VkPhysicalDevice pick_graphics_card_device(VkInstance instance, VkSurfaceKHR surface, std::vector<const char*> extensions);
44+
int rate_device_suitability(VkPhysicalDevice device, VkSurfaceKHR surface, std::vector<const char*> extensions);
45+
bool check_device_extension_support(VkPhysicalDevice device, std::vector<const char*> extensions);
5246
struct SwapChainSupportDetails {
5347
VkSurfaceCapabilitiesKHR capabilities;
5448
std::vector<VkSurfaceFormatKHR> formats;
@@ -62,8 +56,10 @@ struct QueueFamilyIndices {
6256
std::optional<uint32_t> transferFamily;
6357
std::optional<uint32_t> sparseBindingFamily;
6458

65-
inline bool isComplete() const {
66-
return graphicsFamily.has_value() && presentFamily.has_value() && computeFamily.has_value();
59+
inline bool isComplete(bool headless = false) const {
60+
61+
return !headless ? graphicsFamily.has_value() && presentFamily.has_value() && computeFamily.has_value()
62+
: graphicsFamily.has_value() && computeFamily.has_value();
6763
}
6864
};
6965
QueueFamilyIndices find_queue_families(VkPhysicalDevice device, VkSurfaceKHR surface);

include/engine/systems/renderers/deferred.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ class DeferredRenderer : public BaseRenderer
5757
virtual void update_enviroment(Core::Skybox* const skybox);
5858

5959
public:
60+
// Headless instantiation
61+
DeferredRenderer(Extent2D displayExtent = {800, 800})
62+
: BaseRenderer(displayExtent) {
63+
}
6064
DeferredRenderer(Core::IWindow* window)
6165
: BaseRenderer(window) {
6266
}
63-
DeferredRenderer(Core::IWindow* window,
64-
ShadowResolution shadowQuality = ShadowResolution::MEDIUM,
65-
RendererSettings settings = {})
67+
DeferredRenderer(Core::IWindow* window, ShadowResolution shadowQuality = ShadowResolution::MEDIUM, RendererSettings settings = {})
6668
: BaseRenderer(window, settings)
6769
, m_shadowQuality(shadowQuality) {
6870
}

0 commit comments

Comments
 (0)