Skip to content

Commit 67d4d84

Browse files
committed
clang tidy 4 and documentation
1 parent b20e571 commit 67d4d84

18 files changed

+82
-40
lines changed

Intern/rayx-ui/src/Application.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,22 @@ Application::Application(uint32_t width, uint32_t height, const char* name)
2626
.build();
2727
}
2828

29-
Application::~Application() {}
29+
Application::~Application() = default;
3030

3131
void Application::run() {
32-
// UBOs
32+
// Create UBOs (Uniform Buffer Object)
3333
std::vector<std::unique_ptr<Buffer>> uboBuffers(SwapChain::MAX_FRAMES_IN_FLIGHT);
34-
for (int i = 0; i < uboBuffers.size(); i++) {
35-
uboBuffers[i] =
36-
std::make_unique<Buffer>(m_Device, sizeof(Camera), 1, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
37-
uboBuffers[i]->map();
34+
for (auto& uboBuffer : uboBuffers) {
35+
uboBuffer = std::make_unique<Buffer>(m_Device, sizeof(Camera), 1, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
36+
uboBuffer->map();
3837
}
3938

4039
// Descriptor set layout
4140
auto setLayout = DescriptorSetLayout::Builder(m_Device)
4241
.addBinding(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT) //
4342
.build(); //
4443
std::vector<VkDescriptorSet> descriptorSets(SwapChain::MAX_FRAMES_IN_FLIGHT);
45-
for (int i = 0; i < descriptorSets.size(); i++) {
44+
for (unsigned long i = 0; i < descriptorSets.size(); i++) {
4645
auto bufferInfo = uboBuffers[i]->descriptorInfo();
4746
DescriptorWriter(*setLayout, *m_DescriptorPool).writeBuffer(0, &bufferInfo).build(descriptorSets[i]);
4847
}
@@ -95,7 +94,7 @@ void Application::run() {
9594
rObjects = triangulateObjects(beamline.m_OpticalElements, m_Device, true);
9695
rays = getRays(bundleHist, beamline.m_OpticalElements);
9796

98-
if (rays.size() > 0) {
97+
if (!rays.empty()) {
9998
// Temporarily aggregate all vertices, then create a single RenderObject
10099
std::vector<Vertex> rayVertices(rays.size() * 2);
101100
std::vector<uint32_t> rayIndices(rays.size() * 2);
@@ -109,7 +108,7 @@ void Application::run() {
109108
}
110109
}
111110

112-
// Update ubo
111+
// Update UBO
113112
uboBuffers[frameIndex]->writeToBuffer(&cam);
114113
uboBuffers[frameIndex]->flush();
115114

Intern/rayx-ui/src/Application.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class Device;
2020

2121
class Application {
2222
public:
23+
/**
24+
* @brief Constructs a new rayx-ui application.
25+
*
26+
* @param width The width of the application window.
27+
* @param height The height of the application window.
28+
* @param name The name of the application.
29+
*/
2330
Application(uint32_t width, uint32_t height, const char* name);
2431
~Application();
2532

@@ -30,9 +37,9 @@ class Application {
3037

3138
private:
3239
// --- Order matters ---
33-
Window m_Window;
34-
Device m_Device;
35-
Renderer m_Renderer;
40+
Window m_Window; // Application window
41+
Device m_Device; // Vulkan device
42+
Renderer m_Renderer; // Vulkan renderer
3643

3744
std::unique_ptr<DescriptorPool> m_DescriptorPool{nullptr};
3845
};

Intern/rayx-ui/src/Camera.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "Camera.h"
22

3-
#include <vulkan/vulkan.h>
4-
53
#include <fstream>
64
#include <glm/gtc/matrix_transform.hpp>
75
#include <sstream>

Intern/rayx-ui/src/GraphicsCore/Buffer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
#include <cstring>
44

5-
VkDeviceSize Buffer::getAlignment(VkDeviceSize instanceSize, VkDeviceSize minOffsetAlignment) {
6-
if (minOffsetAlignment > 0) {
7-
return (instanceSize + minOffsetAlignment - 1) & ~(minOffsetAlignment - 1);
8-
}
9-
return instanceSize;
10-
}
11-
125
/**
136
* Allocates buffer memory using given parameters and associates it with a Device.
147
* Also calculates memory alignment.
@@ -31,6 +24,13 @@ Buffer::~Buffer() {
3124
vkFreeMemory(m_Device.device(), m_Memory, nullptr);
3225
}
3326

27+
VkDeviceSize Buffer::getAlignment(VkDeviceSize instanceSize, VkDeviceSize minOffsetAlignment) {
28+
if (minOffsetAlignment > 0) {
29+
return (instanceSize + minOffsetAlignment - 1) & ~(minOffsetAlignment - 1);
30+
}
31+
return instanceSize;
32+
}
33+
3434
/**
3535
* This function maps a range of the buffer's memory into the application's address space (making it accessible).
3636
* The mapped range starts from the given `offset` and extends for `size` bytes.

Intern/rayx-ui/src/GraphicsCore/Descriptors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ std::unique_ptr<DescriptorSetLayout> DescriptorSetLayout::Builder::build() const
2323
DescriptorSetLayout::DescriptorSetLayout(Device& Device, std::unordered_map<uint32_t, VkDescriptorSetLayoutBinding> bindings)
2424
: m_Device{Device}, m_bindings{bindings} {
2525
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings{};
26+
setLayoutBindings.reserve(bindings.size());
2627
for (auto kv : bindings) {
2728
setLayoutBindings.push_back(kv.second);
2829
}

Intern/rayx-ui/src/GraphicsCore/Descriptors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class DescriptorSetLayout {
1010
public:
1111
class Builder {
1212
public:
13-
Builder(Device& Device) : m_Device{Device} {}
13+
explicit Builder(Device& Device) : m_Device{Device} {}
1414

1515
Builder& addBinding(uint32_t binding, VkDescriptorType descriptorType, VkShaderStageFlags stageFlags, uint32_t count = 1);
1616
std::unique_ptr<DescriptorSetLayout> build() const;
@@ -39,7 +39,7 @@ class DescriptorPool {
3939
public:
4040
class Builder {
4141
public:
42-
Builder(Device& Device) : m_Device{Device} {}
42+
explicit Builder(Device& Device) : m_Device{Device} {}
4343

4444
Builder& addPoolSize(VkDescriptorType descriptorType, uint32_t count);
4545
Builder& setPoolFlags(VkDescriptorPoolCreateFlags flags);

Intern/rayx-ui/src/GraphicsCore/Device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ void Device::createInstance() {
6161
VkApplicationInfo appInfo = {};
6262
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
6363
appInfo.pApplicationName = "RAYX-UI";
64-
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
64+
appInfo.applicationVersion = VK_MAKE_API_VERSION(1, 0, 0, 0);
6565
appInfo.pEngineName = "RAYX-Core";
66-
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
66+
appInfo.engineVersion = VK_MAKE_API_VERSION(1, 0, 0, 0);
6767
appInfo.apiVersion = VK_API_VERSION_1_0;
6868

6969
VkInstanceCreateInfo createInfo = {};

Intern/rayx-ui/src/GraphicsCore/Device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Device {
2626
const bool enableValidationLayers = true;
2727
#endif
2828

29-
Device(Window& window);
29+
explicit Device(Window& window);
3030
~Device();
3131

3232
// Not copyable or movable

Intern/rayx-ui/src/GraphicsCore/GraphicsPipeline.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void GraphicsPipeline::createGraphicsPipeline(const std::string& vertFilepath, c
6666
shaderStages[0].flags = 0;
6767
shaderStages[0].pNext = nullptr;
6868
shaderStages[0].pSpecializationInfo = nullptr;
69+
6970
shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
7071
shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
7172
shaderStages[1].module = m_FragShaderModule;

Intern/rayx-ui/src/GraphicsCore/GraphicsPipeline.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ struct PipelineConfigInfo {
2020
VkPipelineDepthStencilStateCreateInfo depthStencilInfo;
2121
std::vector<VkDynamicState> dynamicStateEnables;
2222
VkPipelineDynamicStateCreateInfo dynamicStateInfo;
23+
2324
VkPipelineLayout pipelineLayout = nullptr;
2425
VkRenderPass renderPass = nullptr;
2526
VkPrimitiveTopology topology;
2627
VkPolygonMode polygonMode;
2728
uint32_t subpass = 0;
2829
};
2930

31+
/**
32+
* @brief The GraphicsPipeline class encapsulates a Vulkan graphics pipeline.
33+
*
34+
* It handles the creation and destruction of the pipeline, including shader modules, etc.
35+
*/
3036
class GraphicsPipeline {
3137
public:
3238
GraphicsPipeline(Device& device, const std::string& vertFilepath, const std::string& fragFilepath, const PipelineConfigInfo& createInfo);
@@ -36,6 +42,12 @@ class GraphicsPipeline {
3642
GraphicsPipeline& operator=(const GraphicsPipeline&) = delete;
3743

3844
void bind(VkCommandBuffer commandBuffer);
45+
46+
/**
47+
* @brief Provides default configuration information for a graphics pipeline.
48+
*
49+
* @param configInfo The configuration information to be filled with default values.
50+
*/
3951
static void defaultPipelineConfigInfo(PipelineConfigInfo& configInfo);
4052
VkPipeline getHandle() const { return m_Pipeline; }
4153

0 commit comments

Comments
 (0)