Rename local parameter variables to use p_ prefix

This commit is contained in:
2025-04-13 10:04:53 +10:00
parent 8efa200e9e
commit 859547570b
8 changed files with 81 additions and 74 deletions

View File

@@ -38,6 +38,6 @@ namespace Nova {
virtual void set_window_position(WindowID window, i32 x, i32 y) = 0; virtual void set_window_position(WindowID window, i32 x, i32 y) = 0;
[[nodiscard]] virtual const char* get_surface_extension() const = 0; [[nodiscard]] virtual const char* get_surface_extension() const = 0;
[[nodiscard]] virtual SurfaceID create_surface(WindowID window, RenderDriver* render_driver) = 0; [[nodiscard]] virtual SurfaceID create_surface(WindowID window, RenderDriver* driver) = 0;
}; };
} // namespace Nova } // namespace Nova

View File

@@ -26,13 +26,13 @@ bool Debug::is_debug() {
#endif #endif
} }
void Internals::_assert_fail(std::string_view assertion, std::string_view file, std::string_view func, int line) { void Internals::_assert_fail(std::string_view p_assertion, std::string_view p_file, std::string_view p_func, int p_line) {
Debug::get_logger()->critical( Debug::get_logger()->critical(
"ASSERTION FAILED\n Assertion: \"{}\"\n File: \"{}\" (line {})\n Function: {}()", "ASSERTION FAILED\n Assertion: \"{}\"\n File: \"{}\" (line {})\n Function: {}()",
assertion, p_assertion,
file, p_file,
line, p_line,
func p_func
); );
std::abort(); std::abort();
} }

View File

@@ -21,7 +21,7 @@
using namespace Nova; using namespace Nova;
VulkanRenderDriver::VulkanRenderDriver(WindowDriver* window_driver) : m_window_driver(window_driver) { VulkanRenderDriver::VulkanRenderDriver(WindowDriver* p_driver) : m_window_driver(p_driver) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
_check_version(); _check_version();
_check_extensions(); _check_extensions();
@@ -69,34 +69,39 @@ u32 VulkanRenderDriver::get_device_count() const {
return static_cast<u32>(m_devices.size()); return static_cast<u32>(m_devices.size());
} }
const RenderDevice& VulkanRenderDriver::get_device(const u32 index) const { const RenderDevice& VulkanRenderDriver::get_device(const u32 p_index) const {
NOVA_ASSERT(index < m_devices.size()); NOVA_ASSERT(p_index < m_devices.size());
return m_devices[index]; return m_devices[p_index];
} }
bool VulkanRenderDriver::get_device_supports_surface(const u32 index, const SurfaceID surface) const { bool VulkanRenderDriver::get_device_supports_surface(const u32 p_index, const SurfaceID p_surface) const {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(index < m_devices.size()); NOVA_ASSERT(p_index < m_devices.size());
NOVA_ASSERT(surface); NOVA_ASSERT(p_surface);
// TODO: Check other queue families? // TODO: Check other queue families?
SurfaceData* data = reinterpret_cast<SurfaceData*>(surface); SurfaceData* data = reinterpret_cast<SurfaceData*>(p_surface);
VkBool32 supported = false; VkBool32 supported = false;
if (vkGetPhysicalDeviceSurfaceSupportKHR(static_cast<VkPhysicalDevice>(m_devices[index].handle), 0, data->handle, &supported) if (vkGetPhysicalDeviceSurfaceSupportKHR(
static_cast<VkPhysicalDevice>(m_devices[p_index].handle),
0,
data->handle,
&supported
)
!= VK_SUCCESS) { != VK_SUCCESS) {
return false; return false;
} }
return supported; return supported;
} }
void VulkanRenderDriver::select_device(u32 index) { void VulkanRenderDriver::select_device(u32 p_index) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(!m_device); NOVA_ASSERT(!m_device);
NOVA_ASSERT(index < m_devices.size()); NOVA_ASSERT(p_index < m_devices.size());
NOVA_LOG("Using device: {}", m_devices[index].name); NOVA_LOG("Using device: {}", m_devices[p_index].name);
m_physical_device = static_cast<VkPhysicalDevice>(m_devices[index].handle); m_physical_device = static_cast<VkPhysicalDevice>(m_devices[p_index].handle);
_check_device_extensions(); _check_device_extensions();
_check_device_features(); _check_device_features();
@@ -107,15 +112,15 @@ void VulkanRenderDriver::select_device(u32 index) {
_init_device(queues); _init_device(queues);
} }
SurfaceID VulkanRenderDriver::create_surface(const WindowID window) { SurfaceID VulkanRenderDriver::create_surface(const WindowID p_window) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(m_window_driver); NOVA_ASSERT(m_window_driver);
return m_window_driver->create_surface(window, this); return m_window_driver->create_surface(p_window, this);
} }
void VulkanRenderDriver::destroy_surface(const SurfaceID surface) { void VulkanRenderDriver::destroy_surface(const SurfaceID p_surface) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
SurfaceData* data = reinterpret_cast<SurfaceData*>(surface); SurfaceData* data = reinterpret_cast<SurfaceData*>(p_surface);
vkDestroySurfaceKHR(m_instance, data->handle, get_allocator(VK_OBJECT_TYPE_SURFACE_KHR)); vkDestroySurfaceKHR(m_instance, data->handle, get_allocator(VK_OBJECT_TYPE_SURFACE_KHR));
delete data; delete data;
} }
@@ -124,9 +129,9 @@ VkInstance VulkanRenderDriver::get_instance() const {
return m_instance; return m_instance;
} }
VkAllocationCallbacks* VulkanRenderDriver::get_allocator(const VkObjectType type) const { VkAllocationCallbacks* VulkanRenderDriver::get_allocator(const VkObjectType p_type) const {
// TODO: Add custom allocator // TODO: Add custom allocator
(void)type; (void)p_type;
return nullptr; return nullptr;
} }
@@ -331,7 +336,7 @@ void VulkanRenderDriver::_check_device_capabilities() {
// TODO: Check device capabilities // TODO: Check device capabilities
} }
void VulkanRenderDriver::_init_queues(std::vector<VkDeviceQueueCreateInfo>& queues) const { void VulkanRenderDriver::_init_queues(std::vector<VkDeviceQueueCreateInfo>& p_queues) const {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
u32 count; u32 count;
@@ -339,12 +344,12 @@ void VulkanRenderDriver::_init_queues(std::vector<VkDeviceQueueCreateInfo>& queu
std::vector<VkQueueFamilyProperties> available(count); std::vector<VkQueueFamilyProperties> available(count);
vkGetPhysicalDeviceQueueFamilyProperties(m_physical_device, &count, available.data()); vkGetPhysicalDeviceQueueFamilyProperties(m_physical_device, &count, available.data());
constexpr VkQueueFlags mask = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT; constexpr VkQueueFlags QUEUE_MASK = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT;
static float priority = 1.0f; static float s_priority = 1.0f;
VkQueueFlags found = 0; VkQueueFlags found = 0;
for (u32 i = 0; i < count; i++) { for (u32 i = 0; i < count; i++) {
if ((available[i].queueFlags & mask) == 0) { if ((available[i].queueFlags & QUEUE_MASK) == 0) {
continue; continue;
} }
if (!available[i].queueCount) { if (!available[i].queueCount) {
@@ -354,19 +359,21 @@ void VulkanRenderDriver::_init_queues(std::vector<VkDeviceQueueCreateInfo>& queu
NOVA_LOG("Using queue family: {}", i); NOVA_LOG("Using queue family: {}", i);
found |= available[i].queueFlags; found |= available[i].queueFlags;
queues.emplace_back(); VkDeviceQueueCreateInfo queue {};
queues.back().sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; queue.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queues.back().queueFamilyIndex = i; queue.queueFamilyIndex = i;
queues.back().queueCount = 1; // TODO: Does it make sense to have more than one queue? queue.queueCount = 1;
queues.back().pQueuePriorities = &priority; queue.pQueuePriorities = &s_priority;
p_queues.push_back(queue);
} }
if ((found & mask) != mask) { if ((found & QUEUE_MASK) != QUEUE_MASK) {
throw std::runtime_error("Failed to find required queue family"); throw std::runtime_error("Failed to find all required queue families");
} }
} }
void VulkanRenderDriver::_init_device(const std::vector<VkDeviceQueueCreateInfo>& queues) { void VulkanRenderDriver::_init_device(const std::vector<VkDeviceQueueCreateInfo>& p_queues) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
VkDeviceCreateInfo create {}; VkDeviceCreateInfo create {};
@@ -375,8 +382,8 @@ void VulkanRenderDriver::_init_device(const std::vector<VkDeviceQueueCreateInfo>
create.ppEnabledLayerNames = m_layers.data(); create.ppEnabledLayerNames = m_layers.data();
create.enabledExtensionCount = static_cast<u32>(m_device_extensions.size()); create.enabledExtensionCount = static_cast<u32>(m_device_extensions.size());
create.ppEnabledExtensionNames = m_device_extensions.data(); create.ppEnabledExtensionNames = m_device_extensions.data();
create.queueCreateInfoCount = static_cast<u32>(queues.size()); create.queueCreateInfoCount = static_cast<u32>(p_queues.size());
create.pQueueCreateInfos = queues.data(); create.pQueueCreateInfos = p_queues.data();
create.pEnabledFeatures = &m_features; create.pEnabledFeatures = &m_features;
// TODO: pNext for additional features // TODO: pNext for additional features

View File

@@ -98,48 +98,48 @@ u32 X11WindowDriver::get_window_count() const {
return static_cast<u32>(m_windows.size()); return static_cast<u32>(m_windows.size());
} }
WindowID X11WindowDriver::create_window(const std::string_view title, const u32 width, const u32 height) { WindowID X11WindowDriver::create_window(const std::string_view p_title, const u32 p_width, const u32 p_height) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
const WindowID window = XCreateSimpleWindow(m_display, DefaultRootWindow(m_display), 0, 0, width, height, 0, 0, 0); const WindowID window = XCreateSimpleWindow(m_display, DefaultRootWindow(m_display), 0, 0, p_width, p_height, 0, 0, 0);
WindowData& data = m_windows[window]; WindowData& data = m_windows[window];
data.width = width; data.width = p_width;
data.height = height; data.height = p_height;
XSetWMProtocols(m_display, window, &m_window_close_atom, 1); XSetWMProtocols(m_display, window, &m_window_close_atom, 1);
XSelectInput(m_display, window, StructureNotifyMask); XSelectInput(m_display, window, StructureNotifyMask);
XStoreName(m_display, window, title.data()); XStoreName(m_display, window, p_title.data());
XMapWindow(m_display, window); XMapWindow(m_display, window);
XFlush(m_display); XFlush(m_display);
return window; return window;
} }
void X11WindowDriver::destroy_window(const WindowID window) { void X11WindowDriver::destroy_window(const WindowID p_window) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
if (!m_windows.contains(window)) { if (!m_windows.contains(p_window)) {
return; return;
} }
XDestroyWindow(m_display, window); XDestroyWindow(m_display, p_window);
m_windows.erase(window); m_windows.erase(p_window);
} }
void X11WindowDriver::set_window_title(const WindowID window, const std::string_view title) { void X11WindowDriver::set_window_title(const WindowID p_window, const std::string_view p_title) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(m_windows.contains(window)); NOVA_ASSERT(m_windows.contains(p_window));
XStoreName(m_display, window, title.data()); XStoreName(m_display, p_window, p_title.data());
} }
void X11WindowDriver::set_window_size(const WindowID window, const u32 width, const u32 height) { void X11WindowDriver::set_window_size(const WindowID p_window, const u32 p_width, const u32 p_height) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(m_windows.contains(window)); NOVA_ASSERT(m_windows.contains(p_window));
XResizeWindow(m_display, window, width, height); XResizeWindow(m_display, p_window, p_width, p_height);
} }
void X11WindowDriver::set_window_position(const WindowID window, const i32 x, const i32 y) { void X11WindowDriver::set_window_position(const WindowID p_window, const i32 p_x, const i32 p_y) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(m_windows.contains(window)); NOVA_ASSERT(m_windows.contains(p_window));
XMoveWindow(m_display, window, x, y); XMoveWindow(m_display, p_window, p_x, p_y);
} }
const char* X11WindowDriver::get_surface_extension() const { const char* X11WindowDriver::get_surface_extension() const {
@@ -150,19 +150,19 @@ const char* X11WindowDriver::get_surface_extension() const {
#endif #endif
} }
SurfaceID X11WindowDriver::create_surface(const WindowID window, RenderDriver* render_driver) { SurfaceID X11WindowDriver::create_surface(const WindowID p_window, RenderDriver* p_driver) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(m_windows.contains(window)); NOVA_ASSERT(m_windows.contains(p_window));
NOVA_ASSERT(render_driver); NOVA_ASSERT(p_driver);
NOVA_ASSERT(render_driver->get_api() == RenderAPI::VULKAN); NOVA_ASSERT(p_driver->get_api() == RenderAPI::VULKAN);
#ifdef NOVA_VULKAN #ifdef NOVA_VULKAN
VkXlibSurfaceCreateInfoKHR create {}; VkXlibSurfaceCreateInfoKHR create {};
create.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; create.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
create.dpy = m_display; create.dpy = m_display;
create.window = static_cast<Window>(window); create.window = static_cast<Window>(p_window);
const auto vkrd = static_cast<VulkanRenderDriver*>(render_driver); const auto vkrd = static_cast<VulkanRenderDriver*>(p_driver);
SurfaceData* surface = new SurfaceData(); SurfaceData* surface = new SurfaceData();
if (vkCreateXlibSurfaceKHR(vkrd->get_instance(), &create, vkrd->get_allocator(VK_OBJECT_TYPE_SURFACE_KHR), &surface->handle) if (vkCreateXlibSurfaceKHR(vkrd->get_instance(), &create, vkrd->get_allocator(VK_OBJECT_TYPE_SURFACE_KHR), &surface->handle)

View File

@@ -39,7 +39,7 @@ namespace Nova {
void set_window_position(WindowID window, i32 x, i32 y) override; void set_window_position(WindowID window, i32 x, i32 y) override;
[[nodiscard]] const char* get_surface_extension() const override; [[nodiscard]] const char* get_surface_extension() const override;
[[nodiscard]] SurfaceID create_surface(WindowID window, RenderDriver* render_driver) override; [[nodiscard]] SurfaceID create_surface(WindowID window, RenderDriver* driver) override;
private: private:
Display* m_display = nullptr; Display* m_display = nullptr;

View File

@@ -10,18 +10,18 @@
using namespace Nova; using namespace Nova;
u32 RenderDevice::choose_device(RenderDriver* driver, std::span<const SurfaceID> surfaces) { u32 RenderDevice::choose_device(RenderDriver* p_driver, std::span<const SurfaceID> p_surfaces) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
u32 best_index = -1; u32 best_index = -1;
u32 best_score = 0; u32 best_score = 0;
for (u32 i = 0; i < driver->get_device_count(); i++) { for (u32 i = 0; i < p_driver->get_device_count(); i++) {
auto& device = driver->get_device(i); auto& device = p_driver->get_device(i);
u32 score = 1; u32 score = 1;
for (SurfaceID surface : surfaces) { for (SurfaceID surface : p_surfaces) {
if (!driver->get_device_supports_surface(i, surface)) { if (!p_driver->get_device_supports_surface(i, surface)) {
score = 0; score = 0;
break; break;
} }

View File

@@ -12,16 +12,16 @@
using namespace Nova; using namespace Nova;
RenderDriver* RenderDriver::create(const RenderAPI api, WindowDriver* window_driver) { RenderDriver* RenderDriver::create(const RenderAPI p_api, WindowDriver* p_driver) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
switch (api) { switch (p_api) {
#ifdef NOVA_DX12 #ifdef NOVA_DX12
case RenderAPI::DX12: case RenderAPI::DX12:
return new DX12RenderDriver(); return new DX12RenderDriver();
#endif #endif
#ifdef NOVA_VULKAN #ifdef NOVA_VULKAN
case RenderAPI::VULKAN: case RenderAPI::VULKAN:
return new VulkanRenderDriver(window_driver); return new VulkanRenderDriver(p_driver);
#endif #endif
default: default:
throw std::runtime_error("Unsupported render API"); throw std::runtime_error("Unsupported render API");

View File

@@ -13,11 +13,11 @@ using namespace Nova;
static std::unique_ptr<RenderDriver> s_driver; static std::unique_ptr<RenderDriver> s_driver;
void Renderer::init(const RenderAPI api) { void Renderer::init(const RenderAPI p_api) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(!s_driver); NOVA_ASSERT(!s_driver);
s_driver = std::unique_ptr<RenderDriver>(RenderDriver::create(api, nullptr)); s_driver = std::unique_ptr<RenderDriver>(RenderDriver::create(p_api, nullptr));
} }
void Renderer::shutdown() { void Renderer::shutdown() {