Skip to content

Commit c38e2b0

Browse files
committed
Support for loading 3D and Cube textures. Shadow pass auto disable handle when no lights
1 parent c19becc commit c38e2b0

31 files changed

+329
-335
lines changed

include/engine/common.h

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ typedef enum MaskType
143143

144144
typedef enum CullingMode
145145
{
146-
FRONT_CULLING = VK_CULL_MODE_FRONT_BIT,
147-
BACK_CULLING = VK_CULL_MODE_BACK_BIT,
148-
NO_CULLING = VK_CULL_MODE_NONE,
146+
FRONT_CULLING = VK_CULL_MODE_FRONT_BIT,
147+
BACK_CULLING = VK_CULL_MODE_BACK_BIT,
148+
NO_CULLING = VK_CULL_MODE_NONE,
149149
} CullingMode;
150150

151151
typedef enum BufferingType
152152
{
153-
UNIQUE_BUFFER = 1,
154-
DOUBLE_BUFFER = 2,
155-
TRIPLE_BUFFER = 3,
156-
QUAD_BUFFER = 4
153+
UNIQUE_BUFFER = 1,
154+
DOUBLE_BUFFER = 2,
155+
TRIPLE_BUFFER = 3,
156+
QUAD_BUFFER = 4
157157
} BufferingType;
158158

159159
typedef enum MSAASamples
@@ -218,12 +218,10 @@ typedef enum ColorFormatType
218218
SRGBA_16F = VK_FORMAT_R16G16B16A16_SFLOAT, // HDR precission 16
219219
SRGBA_32F = VK_FORMAT_R32G32B32A32_SFLOAT, // HDR precission 32
220220
RGBA_8U = VK_FORMAT_R8G8B8A8_UNORM,
221+
DEPTH_16F = VK_FORMAT_D16_UNORM,
222+
DEPTH_32F = VK_FORMAT_D32_SFLOAT
221223
} ColorFormatType;
222-
typedef enum DepthFormatType
223-
{
224-
D16F = VK_FORMAT_D16_UNORM,
225-
D32F = VK_FORMAT_D32_SFLOAT
226-
} DepthFormatType;
224+
227225
typedef enum TextureAdressModeType
228226
{
229227
REPEAT = VK_SAMPLER_ADDRESS_MODE_REPEAT, // Repeat the texture when going beyond the image dimensions.
@@ -397,17 +395,16 @@ enum class ImageLayoutType
397395
MAX_IMAGE_LAYOUT
398396
};
399397

400-
// ImageViewType enum: representing image view types
401-
enum class ImageViewType
402-
{
403-
TYPE_1D = 0,
404-
TYPE_2D,
405-
TYPE_3D,
406-
TYPE_CUBE,
407-
TYPE_1D_ARRAY,
408-
TYPE_2D_ARRAY,
409-
TYPE_CUBE_ARRAY,
410-
MAX_IMAGE_VIEW_TYPE
398+
// Texture type, used for image views also
399+
enum class TextureType
400+
{
401+
TEXTURE_1D = 0,
402+
TEXTURE_1D_ARRAY = 1,
403+
TEXTURE_2D = 2,
404+
TEXTURE_2D_ARRAY = 3,
405+
TEXTURE_3D = 4,
406+
TEXTURE_CUBE = 5,
407+
TEXTURE_CUBE_ARRAY = 6,
411408
};
412409

413410
// FilterType enum: for Vulkan texture filters
@@ -489,7 +486,9 @@ enum class BindingType
489486
COMPUTE_BINDING = VK_PIPELINE_BIND_POINT_COMPUTE,
490487
RAYTRACING_BINDING = VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR
491488
};
492-
489+
/*
490+
Graphic pipeline result info
491+
*/
493492
typedef enum RenderResult
494493
{
495494
SUCCESS = VK_SUCCESS,
@@ -537,18 +536,18 @@ typedef enum RenderResult
537536
OPERATION_DEFERRED_KHR = VK_OPERATION_DEFERRED_KHR,
538537
OPERATION_NOT_DEFERRED_KHR = VK_OPERATION_NOT_DEFERRED_KHR,
539538
// ERROR_INVALID_VIDEO_STD_PARAMETERS_KHR = VK_ERROR_INVALID_VIDEO_STD_PARAMETERS_KHR,
540-
ERROR_COMPRESSION_EXHAUSTED_EXT = VK_ERROR_COMPRESSION_EXHAUSTED_EXT,
539+
ERROR_COMPRESSION_EXHAUSTED_EXT = VK_ERROR_COMPRESSION_EXHAUSTED_EXT,
541540
// INCOMPATIBLE_SHADER_BINARY_EXT = VK_INCOMPATIBLE_SHADER_BINARY_EXT,
542-
ERROR_OUT_OF_POOL_MEMORY_KHR = VK_ERROR_OUT_OF_POOL_MEMORY_KHR,
543-
ERROR_INVALID_EXTERNAL_HANDLE_KHR = VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR,
544-
ERROR_FRAGMENTATION_EXT = VK_ERROR_FRAGMENTATION_EXT,
545-
ERROR_NOT_PERMITTED_EXT = VK_ERROR_NOT_PERMITTED_EXT,
546-
ERROR_INVALID_DEVICE_ADDRESS_EXT = VK_ERROR_INVALID_DEVICE_ADDRESS_EXT,
547-
ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR = VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR,
548-
PIPELINE_COMPILE_REQUIRED_EXT = VK_PIPELINE_COMPILE_REQUIRED_EXT,
549-
ERROR_PIPELINE_COMPILE_REQUIRED_EXT = VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT,
550-
ERROR_INCOMPATIBLE_SHADER_BINARY_EXT = VK_ERROR_INCOMPATIBLE_SHADER_BINARY_EXT,
551-
RESULT_MAX_ENUM = VK_RESULT_MAX_ENUM
541+
ERROR_OUT_OF_POOL_MEMORY_KHR = VK_ERROR_OUT_OF_POOL_MEMORY_KHR,
542+
ERROR_INVALID_EXTERNAL_HANDLE_KHR = VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR,
543+
ERROR_FRAGMENTATION_EXT = VK_ERROR_FRAGMENTATION_EXT,
544+
ERROR_NOT_PERMITTED_EXT = VK_ERROR_NOT_PERMITTED_EXT,
545+
ERROR_INVALID_DEVICE_ADDRESS_EXT = VK_ERROR_INVALID_DEVICE_ADDRESS_EXT,
546+
ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR = VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR,
547+
PIPELINE_COMPILE_REQUIRED_EXT = VK_PIPELINE_COMPILE_REQUIRED_EXT,
548+
ERROR_PIPELINE_COMPILE_REQUIRED_EXT = VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT,
549+
ERROR_INCOMPATIBLE_SHADER_BINARY_EXT = VK_ERROR_INCOMPATIBLE_SHADER_BINARY_EXT,
550+
RESULT_MAX_ENUM = VK_RESULT_MAX_ENUM
552551
} RenderResult;
553552

554553
VULKAN_ENGINE_NAMESPACE_END

include/engine/core/renderpasses/forward_pass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ForwardPass : public RenderPass
2020
{
2121
/*Setup*/
2222
ColorFormatType m_colorFormat;
23-
DepthFormatType m_depthFormat;
23+
ColorFormatType m_depthFormat;
2424
MSAASamples m_aa;
2525

2626
/*Descriptors*/
@@ -37,7 +37,7 @@ class ForwardPass : public RenderPass
3737
Extent2D extent,
3838
uint32_t framebufferCount,
3939
ColorFormatType colorFormat,
40-
DepthFormatType depthFormat,
40+
ColorFormatType depthFormat,
4141
MSAASamples samples,
4242
bool isDefault = true)
4343
: RenderPass(ctx, extent, framebufferCount, 1, isDefault)

include/engine/core/renderpasses/shadow_pass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Core {
1717
class ShadowPass : public RenderPass
1818
{
1919
/* Config */
20-
DepthFormatType m_depthFormat;
20+
ColorFormatType m_depthFormat;
2121

2222
/*Descriptors*/
2323
struct FrameDescriptors {
@@ -31,7 +31,7 @@ class ShadowPass : public RenderPass
3131
Extent2D extent,
3232
uint32_t framebufferCount,
3333
uint32_t numLights,
34-
DepthFormatType depthFormat)
34+
ColorFormatType depthFormat)
3535
: RenderPass(ctx, extent, framebufferCount, numLights)
3636
, m_depthFormat(depthFormat) {
3737
}

include/engine/core/renderpasses/variance_shadow_pass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class VarianceShadowPass : public RenderPass
1818
{
1919
/* Config */
2020
ColorFormatType m_format = SRG_32F;
21-
DepthFormatType m_depthFormat;
21+
ColorFormatType m_depthFormat;
2222

2323
/*Descriptors*/
2424
struct FrameDescriptors {
@@ -32,7 +32,7 @@ class VarianceShadowPass : public RenderPass
3232
Extent2D extent,
3333
uint32_t framebufferCount,
3434
uint32_t numLights,
35-
DepthFormatType depthFormat)
35+
ColorFormatType depthFormat)
3636
: RenderPass(ctx, extent, framebufferCount, numLights)
3737
, m_depthFormat(depthFormat) {
3838
}

include/engine/core/scene/light.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ class Light : public Object3D
4242
Shadow m_shadow;
4343
const LightType m_lighType;
4444

45-
public:
45+
static uint16_t m_nonRaytraceCount;
4646

47+
public:
4748
Light(std::string name, LightType type, Vec3 color = Vec3(1.0f, 1.0f, 1.0f), float intensity = 1.0f)
4849
: Object3D(name, LIGHT)
4950
, m_color(color)
5051
, m_intensity(intensity)
5152
, m_lighType(type) {
53+
if (m_shadow.type != ShadowType::RAYTRACED_SHADOW)
54+
m_nonRaytraceCount++;
5255
}
5356

5457
virtual inline Vec3 get_color() const {
@@ -75,7 +78,13 @@ class Light : public Object3D
7578
return m_shadow.type;
7679
}
7780
virtual inline void set_shadow_type(ShadowType t) {
81+
auto oldType = m_shadow.type;
7882
m_shadow.type = t;
83+
if (m_shadow.type != ShadowType::RAYTRACED_SHADOW && oldType == ShadowType::RAYTRACED_SHADOW)
84+
{
85+
m_nonRaytraceCount++;
86+
} else if (oldType != ShadowType::RAYTRACED_SHADOW)
87+
{ m_nonRaytraceCount--; }
7988
}
8089
virtual inline Vec3 get_shadow_target() const {
8190
return m_shadow.target;
@@ -156,6 +165,9 @@ class Light : public Object3D
156165
}
157166

158167
virtual Graphics::LightUniforms get_uniforms(Mat4 cameraView) const = 0;
168+
static uint16_t get_non_raytraced_count() {
169+
return m_nonRaytraceCount;
170+
}
159171
};
160172

161173
// POINT LIGHT

include/engine/core/scene/scene.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ class Scene : public Object3D
2525
std::vector<Camera*> m_cameras;
2626
std::vector<Mesh*> m_meshes;
2727
std::vector<Light*> m_lights;
28+
Skybox* m_skybox = nullptr;
2829

2930
Graphics::TLAS m_accel = {};
3031

3132
// ENVIROMENT & FOG
32-
Skybox* m_skybox = nullptr;
33-
bool m_useIBL = false;
34-
Vec3 m_ambientColor = {0.7f, 0.5f, 0.5f}; // Fallback if no skybox
35-
float m_ambientIntensity = 0.2f;
36-
bool m_fog = true;
37-
Vec3 m_fogColor = {0.2f, 0.2f, 0.2f};
38-
float m_fogIntensity = 20.0f;
39-
float m_fogExponent = 1.0f;
33+
bool m_useIBL = false;
34+
Vec3 m_ambientColor = {0.7f, 0.5f, 0.5f}; // Fallback if no skybox
35+
float m_ambientIntensity = 0.2f;
36+
bool m_fog = true;
37+
Vec3 m_fogColor = {0.2f, 0.2f, 0.2f};
38+
float m_fogIntensity = 20.0f;
39+
float m_fogExponent = 1.0f;
40+
4041

4142
inline void classify_object(Object3D* obj) {
4243
switch (obj->get_type())

include/engine/core/textures/texture.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ VULKAN_ENGINE_NAMESPACE_BEGIN
1717
namespace Core {
1818

1919
struct TextureSettings {
20-
ColorFormatType format = SRGBA_8;
21-
TextureFilterType filter = LINEAR;
22-
TextureAdressModeType adressMode = REPEAT;
23-
bool useMipmaps = true;
24-
bool anisotropicFilter = true;
25-
int anisotropicFilterPower = 16;
26-
int minMipLevel = 1;
27-
int maxMipLevel = 1;
20+
TextureType type = TextureType::TEXTURE_2D;
21+
ColorFormatType format = SRGBA_8;
22+
TextureFilterType filter = LINEAR;
23+
TextureAdressModeType adressMode = REPEAT;
24+
bool useMipmaps = true;
25+
uint16_t anisotropicFilter = 16;
26+
int minMipLevel = 0;
27+
int maxMipLevel = 12;
2828
};
2929

3030
/*

include/engine/graphics/command_buffer.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ struct CommandBuffer {
2828
VkCommandBuffer handle = VK_NULL_HANDLE;
2929
VkDevice device = VK_NULL_HANDLE;
3030
VkCommandPool pool = VK_NULL_HANDLE;
31+
VkQueue queue = VK_NULL_HANDLE;
3132
bool isRecording = false;
3233

3334
void begin(VkCommandBufferUsageFlags flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
3435
void end();
3536
void reset();
36-
void submit(VkQueue queue,
37-
Fence fence,
38-
std::vector<Semaphore> waitSemaphores = {},
39-
std::vector<Semaphore> signalSemaphores = {});
37+
void submit(Fence fence, std::vector<Semaphore> waitSemaphores = {}, std::vector<Semaphore> signalSemaphores = {});
4038
void cleanup();
4139

4240
/****************************************** */
@@ -69,10 +67,7 @@ struct CommandBuffer {
6967
struct CommandPool {
7068
VkCommandPool handle = VK_NULL_HANDLE;
7169
VkDevice device = VK_NULL_HANDLE;
72-
73-
void init(VkDevice device,
74-
uint32_t queueFamilyIndex,
75-
VkCommandPoolCreateFlags flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
70+
VkQueue queue = VK_NULL_HANDLE;
7671

7772
CommandBuffer allocate_command_buffer(uint32_t count, VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY);
7873

include/engine/graphics/device.h

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Device
3636
VkPhysicalDevice m_gpu = VK_NULL_HANDLE;
3737
VmaAllocator m_allocator = VK_NULL_HANDLE;
3838
Swapchain m_swapchain = {};
39-
Utils::QueueFamilyIndices m_queueFamilies = {};
4039
DescriptorPool m_guiPool = {};
4140
std::unordered_map<QueueType, VkQueue> m_queues;
4241
// GPU Properties
@@ -56,6 +55,7 @@ class Device
5655
VK_KHR_RAY_QUERY_EXTENSION_NAME};
5756
// Utils
5857
Utils::UploadContext m_uploadContext = {};
58+
Utils::QueueFamilyIndices m_queueFamilies = {};
5959
#ifdef NDEBUG
6060
const bool m_enableValidationLayers{false};
6161
#else
@@ -67,22 +67,15 @@ class Device
6767
GETTERS
6868
-----------------------------------------------
6969
*/
70-
inline VkDevice& get_handle() {
70+
inline VkDevice get_handle() {
7171
return m_handle;
7272
};
73-
inline VmaAllocator& get_memory_allocator() {
74-
return m_allocator;
75-
}
76-
inline VkPhysicalDevice& get_GPU() {
77-
return m_gpu;
78-
}
73+
74+
7975
inline Swapchain get_swapchain() const {
8076
return m_swapchain;
8177
}
82-
inline std::unordered_map<QueueType, VkQueue>& get_queues() {
83-
return m_queues;
84-
}
85-
78+
8679
/*
8780
INIT AND SHUTDOWN
8881
-----------------------------------------------
@@ -93,7 +86,7 @@ class Device
9386
uint32_t framesPerFlight,
9487
ColorFormatType presentFormat,
9588
SyncType presentMode);
96-
void update_swapchain(Extent2D surfaceExtent,
89+
void update_swapchain(Extent2D surfaceExtent,
9790
uint32_t framesPerFlight,
9891
ColorFormatType presentFormat,
9992
SyncType presentMode);
@@ -154,20 +147,19 @@ class Device
154147
DRAWING
155148
-----------------------------------------------
156149
*/
157-
RenderResult prepare_frame(Frame& frame, uint32_t& imageIndex) {
158-
}
159-
RenderResult submit_frame(Frame& frame, uint32_t imageIndex) {
160-
}
150+
/*Setups frame for new rendering cicle, waits for the last one to finish and starts the command buffer*/
151+
RenderResult prepare_frame(Frame& frame, uint32_t& imageIndex);
152+
/*Submits the frame to the graphic queue for presenting into the swapchain*/
153+
RenderResult submit_frame(Frame& frame, uint32_t imageIndex);
161154
RenderResult aquire_present_image(Semaphore& waitSemahpore, uint32_t& imageIndex);
162155
RenderResult present_image(Semaphore& signalSemaphore, uint32_t imageIndex);
163-
164156
/*
165157
DATA TRANSFER
166158
-----------------------------------------------
167159
*/
168160
void
169161
upload_vertex_arrays(VertexArrays& vao, size_t vboSize, const void* vboData, size_t iboSize, const void* iboData);
170-
void upload_texture_image(Image* const img,
162+
void upload_texture_image(Image& img,
171163
ImageConfig config,
172164
SamplerConfig samplerConfig,
173165
const void* imgCache,
@@ -183,7 +175,7 @@ class Device
183175
void init_imgui(void* windowHandle,
184176
WindowingSystem windowingSystem,
185177
VulkanRenderPass renderPass,
186-
VkSampleCountFlagBits samples);
178+
uint16_t samples);
187179
void destroy_imgui();
188180
uint32_t get_memory_type(uint32_t typeBits, VkMemoryPropertyFlags properties, VkBool32* memTypeFound = nullptr);
189181
/*

0 commit comments

Comments
 (0)