render-by-index-meshid #8

Merged
kidrigger merged 6 commits from render-by-index-meshid into canon 2025-01-11 20:51:48 +01:00
12 changed files with 61 additions and 15 deletions
Showing only changes of commit c6987a9d5d - Show all commits

View File

@ -21,6 +21,7 @@ void
Buffer::Allocate(const Device *device, usize size, vk::BufferUsageFlags bufferUsage, Buffer::Allocate(const Device *device, usize size, vk::BufferUsageFlags bufferUsage,
VmaAllocationCreateFlags allocationFlags, VmaMemoryUsage memoryUsage, cstr name) VmaAllocationCreateFlags allocationFlags, VmaMemoryUsage memoryUsage, cstr name)
{ {
assert(!IsValid());
assert(size <= SIZE_MASK); assert(size <= SIZE_MASK);
vk::BufferCreateInfo bufferCreateInfo = { vk::BufferCreateInfo bufferCreateInfo = {
@ -104,7 +105,7 @@ StorageBuffer::Init(const Device *device, usize size, bool hostVisible, cstr nam
else else
{ {
Allocate(device, size, vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferDst, Allocate(device, size, vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferDst,
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, VMA_MEMORY_USAGE_AUTO, name); 0, VMA_MEMORY_USAGE_AUTO, name);
} }
} }
@ -112,14 +113,14 @@ void
VertexBuffer::Init(const Device *device, usize size, cstr name) VertexBuffer::Init(const Device *device, usize size, cstr name)
{ {
Allocate(device, size, vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eTransferDst, Allocate(device, size, vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eTransferDst,
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, VMA_MEMORY_USAGE_AUTO, name); 0, VMA_MEMORY_USAGE_AUTO, name);
} }
void void
IndexBuffer::Init(const Device *device, usize size, cstr name) IndexBuffer::Init(const Device *device, usize size, cstr name)
{ {
Allocate(device, size, vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eTransferDst, Allocate(device, size, vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eTransferDst,
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, VMA_MEMORY_USAGE_AUTO, name); 0, VMA_MEMORY_USAGE_AUTO, name);
} }
void void

View File

@ -8,6 +8,7 @@
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE #define GLM_FORCE_DEPTH_ZERO_TO_ONE
#define GLM_FORCE_QUATERNIONS_XYZW #define GLM_FORCE_QUATERNIONS_XYZW
#define GLM_ENABLE_EXPERIMENTAL
#define GLFW_INCLUDE_VULKAN #define GLFW_INCLUDE_VULKAN
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 #define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1

View File

@ -11,6 +11,7 @@
#include <cstdio> #include <cstdio>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
using c8 = char; using c8 = char;
using u8 = uint8_t; using u8 = uint8_t;
@ -57,22 +58,26 @@ Recast(TFrom &&in)
return reinterpret_cast<TType>(std::forward<TFrom>(in)); return reinterpret_cast<TType>(std::forward<TFrom>(in));
} }
constexpr f32 operator""_deg(long double degrees) constexpr f32
operator""_deg(long double degrees)
{ {
return glm::radians<f32>(Cast<f32>(degrees)); return glm::radians<f32>(Cast<f32>(degrees));
} }
constexpr f32 operator""_deg(unsigned long long int degrees) constexpr f32
operator""_deg(unsigned long long int degrees)
{ {
return glm::radians<f32>(Cast<f32>(degrees)); return glm::radians<f32>(Cast<f32>(degrees));
} }
constexpr f32 operator""_rad(long double rads) constexpr f32
operator""_rad(long double rads)
{ {
return Cast<f32>(rads); return Cast<f32>(rads);
} }
constexpr f32 operator""_rad(unsigned long long int rads) constexpr f32
operator""_rad(unsigned long long int rads)
{ {
return Cast<f32>(rads); return Cast<f32>(rads);
} }
@ -110,6 +115,36 @@ constexpr Version VERSION = {
.m_Patch = 0, .m_Patch = 0,
}; };
constexpr u32
Kilobyte(const u32 in)
{
return in * 1024;
}
constexpr usize
Kilobyte(const usize in)
{
return in * 1024;
}
constexpr u32
Megabyte(const u32 in)
{
return in * 1024 * 1024;
}
constexpr usize
Megabyte(const usize in)
{
return in * 1024 * 1024;
}
constexpr usize
Gigabyte(const usize in)
{
return in * 1024 * 1024 * 1024;
}
template <typename T> template <typename T>
constexpr T MaxValue = std::numeric_limits<T>::max(); constexpr T MaxValue = std::numeric_limits<T>::max();

View File

@ -142,6 +142,14 @@ Device::DumpPipelineCache() const
return pipelineCacheData; return pipelineCacheData;
} }
void
Device::WaitIdle() const
{
auto deviceIdleResult = m_Device.waitIdle();
ERROR_IF(Failed(deviceIdleResult), "Device Idling Failed. Cause: {}", deviceIdleResult)
THEN_ABORT(deviceIdleResult);
}
Device::Device(Device &&other) noexcept Device::Device(Device &&other) noexcept
: m_Name(std::move(other.m_Name)) : m_Name(std::move(other.m_Name))
, m_PhysicalDevice(Take(other.m_PhysicalDevice)) , m_PhysicalDevice(Take(other.m_PhysicalDevice))

View File

@ -37,6 +37,8 @@ struct Device final
[[nodiscard]] eastl::vector<u8> DumpPipelineCache() const; [[nodiscard]] eastl::vector<u8> DumpPipelineCache() const;
void WaitIdle() const;
// Ctor/Dtor // Ctor/Dtor
Device(const Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures, Device(const Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, NameString &&name); const eastl::vector<QueueAllocation> &queueAllocations, NameString &&name);

View File

@ -9,8 +9,6 @@ add_library(util_helper STATIC
helpers.cpp helpers.cpp
frame.cpp frame.cpp
frame.h frame.h
gpu_resource_manager.cpp
gpu_resource_manager.h
gui.cpp gui.cpp
gui.h) gui.h)

View File

@ -331,8 +331,7 @@ main(int, char **)
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT; frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
} }
auto result = device.m_Device.waitIdle(); device.WaitIdle();
ERROR_IF(Failed(result), "Wait idle failed. Cause: {}", result);
device.m_Device.destroy(copyPool, nullptr); device.m_Device.destroy(copyPool, nullptr);
vbo.Destroy(&device); vbo.Destroy(&device);

View File

@ -531,7 +531,7 @@ main(int, char **)
currentFrame->Present(commandQueue, &swapchain, &window); currentFrame->Present(commandQueue, &swapchain, &window);
} }
AbortIfFailed(device.m_Device.waitIdle()); device.WaitIdle();
for (auto &depthImage : depthImages) for (auto &depthImage : depthImages)
{ {

View File

@ -12,6 +12,8 @@ add_executable(model_render model_render.cpp
asset_loader.h asset_loader.h
light_manager.cpp light_manager.cpp
light_manager.h light_manager.h
gpu_resource_manager.cpp
gpu_resource_manager.h
nodes.cpp nodes.cpp
nodes.h nodes.h
ibl_helpers.cpp ibl_helpers.cpp

View File

@ -133,8 +133,8 @@ main(int, char **)
{ {
MIN_LOG_LEVEL(Logger::LogType::eInfo); MIN_LOG_LEVEL(Logger::LogType::eInfo);
Context context = {"ModelRender [WIP]", VERSION}; Context context = {"ModelRender", VERSION};
Window window = {"ModelRender [WIP] (Aster)", &context, {INIT_WIDTH, INIT_HEIGHT}}; Window window = {"ModelRender (Aster)", &context, {INIT_WIDTH, INIT_HEIGHT}};
PhysicalDevices physicalDevices = {&window, &context}; PhysicalDevices physicalDevices = {&window, &context};
PhysicalDevice deviceToUse = FindSuitableDevice(physicalDevices); PhysicalDevice deviceToUse = FindSuitableDevice(physicalDevices);
@ -689,7 +689,7 @@ main(int, char **)
currentFrame->Present(graphicsQueue, &swapchain, &window); currentFrame->Present(graphicsQueue, &swapchain, &window);
} }
AbortIfFailed(device.m_Device.waitIdle()); device.WaitIdle();
environment.Destroy(&resourceManager); environment.Destroy(&resourceManager);