Skip to content

Commit 9914323

Browse files
committed
renaming and small changes to classes
1 parent db30fe5 commit 9914323

File tree

10 files changed

+82
-100
lines changed

10 files changed

+82
-100
lines changed

Intern/RayCore/src/Tracer/Tracer.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,13 @@ Rays Tracer::trace(const Beamline& b) {
5656
{
5757
RAYX_PROFILE_SCOPE_STDOUT("Tracing");
5858
rawBatchRays = traceRaw(cfg);
59-
//assert(rawBatchRays.size() == cfg.m_maxSnapshots * batch_size);
60-
for (const auto& _events : rawBatchRays) { // Sanity Check
59+
for ([[maybe_unused]] const auto& _events : rawBatchRays) { // Sanity Check
6160
assert(batch_size == _events.size());
6261
}
6362
}
6463

6564
{
6665
RAYX_PROFILE_SCOPE_STDOUT("Snapshotting");
67-
// for (uint i = 0; i < batch_size; i++) {
68-
// Snapshots hist;
69-
// hist.reserve(maxSnapshots);
70-
// for (uint j = 0; j < maxSnapshots; j++) {
71-
// uint idx = i * maxSnapshots + j;
72-
// Ray r = rawBatchRays[idx];
73-
// if (r.m_weight != W_UNINIT) {
74-
// hist.push_back(r);
75-
// }
76-
// }
77-
// result.push_back(hist);
78-
// }
7966
auto _maxSnapshot = rawBatchRays.size();
8067
result.reserve(batch_size);
8168

Intern/RayCore/src/Tracer/VulkanTracer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Rays VulkanTracer::traceRaw(const TraceRawConfig& cfg) {
5656
uint64_t workerCounterNum = MAX_UINT64 / uint64_t(cfg.m_numRays);
5757
for (auto i = 0; i < cfg.m_numRays; i++) {
5858
rayMeta.push_back({.ctr = ((uint64_t)cfg.m_rayIdStart + (uint64_t)i) * workerCounterNum + uint64_t(cfg.m_randomSeed * MAX_UINT64),
59-
.nextElementId = -1, // Intersection element unknown / does not exist
59+
.nextElementId = -1, // Intersection element unknown / does not exist
6060
.finalized = false}); // Not started
6161
}
6262

@@ -95,8 +95,8 @@ Rays VulkanTracer::traceRaw(const TraceRawConfig& cfg) {
9595
std::string passName2 = "OldFullTracingPass";
9696

9797
// Should return only compute now. Important when mixing different shader types to chose right stage flag!
98-
auto shaderFlag = m_engine.getComputePass(passName2)->getShaderStage(0).getShaderStageFlagBits();
99-
RAYX_D_LOG << "Allocating buffers...";
98+
auto shaderFlag = m_engine.getComputePass(passName0)->getShaderStage(0).getShaderStageFlagBits();
99+
100100
// Bindings (Vulkan Buffer <- Descriptors (sets))
101101
// PS: You can also call addDescriptorSetPerPassBindings once!
102102
bufferHandler
@@ -106,7 +106,8 @@ Rays VulkanTracer::traceRaw(const TraceRawConfig& cfg) {
106106
.addDescriptorSetPerPassBinding(passName2, 0, shaderFlag);
107107

108108
bufferHandler
109-
->createBuffer({"output-buffer", VKBUFFER_OUT, numberOfRays * sizeof(Ray) * (size_t)cfg.m_maxSnapshots}) // Beamline quadric info
109+
->createBuffer(
110+
{"output-buffer", VKBUFFER_OUT, numberOfRays * sizeof(Ray) * (size_t)cfg.m_maxSnapshots}) // OUTOUT DATA only for main.comp
110111
.addDescriptorSetPerPassBinding(passName2, 1, shaderFlag);
111112

112113
bufferHandler
@@ -117,7 +118,7 @@ Rays VulkanTracer::traceRaw(const TraceRawConfig& cfg) {
117118

118119
bufferHandler
119120
->createBuffer<double>({"quadric-buffer", VKBUFFER_IN}, beamlineData) // Beamline quadric info
120-
.addDescriptorSetPerPassBinding(passName0, 2, shaderFlag) // TODO : Wrong binding number
121+
.addDescriptorSetPerPassBinding(passName0, 2, shaderFlag)
121122
.addDescriptorSetPerPassBinding(passName1, 2, shaderFlag)
122123
.addDescriptorSetPerPassBinding(passName2, 3, shaderFlag);
123124

@@ -146,27 +147,26 @@ Rays VulkanTracer::traceRaw(const TraceRawConfig& cfg) {
146147
.addDescriptorSetPerPassBinding(passName1, 6, shaderFlag)
147148
.addDescriptorSetPerPassBinding(passName2, 7, shaderFlag);
148149
#endif
149-
150150
}
151-
152-
// FIXME(OS): Weird pushConstant update
151+
// FIXME: Push Constants still support only one shader code! (If two shaders require two structs then Tracer needs to also change to carry a
152+
// vector of structs or similar)
153153
m_engine.getComputePass("singleTracePass")->updatePushConstant(0, m_engine.m_pushConstants.pushConstPtr, m_engine.m_pushConstants.size);
154154
m_engine.getComputePass("finalCollisionPass")->updatePushConstant(0, m_engine.m_pushConstants.pushConstPtr, m_engine.m_pushConstants.size);
155155
m_engine.getComputePass("OldFullTracingPass")->updatePushConstant(0, m_engine.m_pushConstants.pushConstPtr, m_engine.m_pushConstants.size);
156156

157157
// Create Pipeline layouts and Descriptor Layouts. Everytime buffer formation (not data) changes, we need to prepare again
158158
m_engine.prepareComputePipelinePasses();
159+
159160
// Run multiple bounces
160-
auto out = m_engine.run({.m_numberOfInvocations = numberOfRays, .maxBounces = (int)cfg.m_elements.size()});
161+
auto out = m_engine.runTraceComputeTask({.m_numberOfInvocations = numberOfRays, .maxBounces = (int)cfg.m_elements.size()});
161162

162163
#ifdef RAYX_DEBUG_MODE
163164
m_debugBufList = bufferHandler->readBuffer<debugBuffer_t>("debug-buffer", true);
164165
#endif
165166

166167
m_engine.cleanup();
167168

168-
// Vector of vectors
169-
169+
// 2D Data
170170
return out;
171171
}
172172

Intern/RayCore/src/VulkanEngine/Buffer/BufferHandler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ VulkanBuffer* BufferHandler::getBuffer(const std::string& name) {
157157
/// If queue -> Wait for queue to finish before reading
158158
void BufferHandler::readBufferRaw(const char* bufname, char* outdata, const VkQueue& queue) {
159159
// if (m_state != EngineStates_t::POSTRUN) {
160-
// RAYX_ERR << "you've forgotton to .run() the VulkanEngine. Thats "
160+
// RAYX_ERR << "you've forgotton to .runTraceComputeTask() the VulkanEngine. Thats "
161161
// "mandatory before reading it's output buffers.";
162162
// }
163163
VulkanBuffer* buffer = getBuffer(bufname);
@@ -234,8 +234,9 @@ void BufferHandler::updateBuffer(const char* bufname, const std::vector<T>& vec)
234234
}
235235
if (vec && m_Buffers[std::string(bufname)]->getSize() == vec.size()) {
236236
writeBufferRaw(bufname, (char*)vec.data());
237-
} else
237+
} else {
238238
RAYX_WARN << "Size mismatch";
239+
}
239240
}
240241

241242
void BufferHandler::deleteBuffer(const char* bufname) {

Intern/RayCore/src/VulkanEngine/Buffer/VulkanBuffer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ namespace RAYX {
77

88
VulkanBuffer::VulkanBuffer(const VmaAllocator& vmaAllocator, VulkanBufferCreateInfo createInfo)
99
: m_VmaAllocator(vmaAllocator), m_createInfo(createInfo) {
10-
int bufferUsageFlags = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; // Usually target storage buffer
10+
int bufferUsageFlags;
11+
// Type definition
1112
if (createInfo.bufferType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
1213
bufferUsageFlags = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
14+
} else if (createInfo.bufferType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) {
15+
bufferUsageFlags = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
1316
}
14-
17+
// Access definition
1518
if (createInfo.accessType == VKBUFFER_IN) {
1619
bufferUsageFlags |= VK_BUFFER_USAGE_TRANSFER_DST_BIT;
1720
} else if (createInfo.accessType == VKBUFFER_OUT) {
@@ -27,8 +30,6 @@ VulkanBuffer::VulkanBuffer(const VmaAllocator& vmaAllocator, VulkanBufferCreateI
2730

2831
VulkanBuffer::~VulkanBuffer() { vmaDestroyBuffer(m_VmaAllocator, m_Buffer, m_Alloca); }
2932

30-
uint32_t findMemoryType(VkPhysicalDevice& physicalDevice, uint32_t memoryTypeBits, VkMemoryPropertyFlags properties);
31-
3233
// Creates a buffer to each given object with a given size.
3334
// This also allocates memory to the buffer according the requirements of the
3435
// Physical Device. Sharing is kept to exclusive.
@@ -82,14 +83,14 @@ VulkanBuffer& VulkanBuffer::addDescriptorSetPerPassBinding(const std::string& pa
8283
return *this;
8384
}
8485

85-
VulkanBuffer& VulkanBuffer::addDescriptorSetPerPassBindings(const std::vector<PassBinding>& descriptorPassBindings) {
86+
VulkanBuffer& VulkanBuffer::addDescriptorSetPerPassBindings(const std::vector<PassBindingInfo>& descriptorPassBindings) {
8687
for (const auto& b : descriptorPassBindings) {
8788
addDescriptorSetPerPassBinding(b.passName, b.binding, b.shaderStageFlag);
8889
}
8990
return *this;
9091
}
9192

92-
VkDescriptorBufferInfo VulkanBuffer::getDescriptorInfo(VkDeviceSize offset) { return VkDescriptorBufferInfo{m_Buffer, offset, m_createInfo.size}; }
93+
VkDescriptorBufferInfo VulkanBuffer::getVkDescriptorBufferInfo(VkDeviceSize offset) { return VkDescriptorBufferInfo{m_Buffer, offset, m_createInfo.size}; }
9394

9495
uint32_t VulkanBuffer::getPassDescriptorBinding(std::string passName) {
9596
if (hasPassDescriptorBinding(passName)) {

Intern/RayCore/src/VulkanEngine/Buffer/VulkanBuffer.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,21 @@ enum BufferAccessFlags {
1616
VKBUFFER_INOUT,
1717
};
1818

19-
/**
20-
* @brief Pass to VulkanBuffer Class for buffer creation
21-
*
22-
*/
2319
struct VulkanBufferCreateInfo {
2420
const char* bufName; // Unique Buffer name
2521
BufferAccessFlags accessType; // Access type to Buffer
2622
VkDeviceSize size = 0; // Size
2723
VkDescriptorType bufferType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; // What kind of buffer is it (Storage, Image, Uniform etc.)
2824
};
2925

30-
struct PassBinding {
26+
struct PassBindingInfo {
3127
std::string passName;
3228
uint32_t binding;
3329
VkShaderStageFlags shaderStageFlag;
3430
};
3531

3632
class BufferHandler;
3733

38-
// class VulkanEngine;
3934
/**
4035
* @brief Vulkan Storage Buffer Class. Used for Buffer allocation, creation and update
4136
*
@@ -47,7 +42,7 @@ class RAYX_API VulkanBuffer {
4742
VulkanBuffer(const VmaAllocator&, VulkanBufferCreateInfo createInfo);
4843
~VulkanBuffer();
4944

50-
// Move/Copy of a VulkanBuffer is not alloawed
45+
// Move/Copy of a VulkanBuffer are not alloawed
5146
VulkanBuffer(const VulkanBuffer&) = delete;
5247
VulkanBuffer& operator=(const VulkanBuffer&) = delete;
5348

@@ -60,16 +55,18 @@ class RAYX_API VulkanBuffer {
6055
void UnmapMemory();
6156

6257
VulkanBuffer& addDescriptorSetPerPassBinding(const std::string& passName, uint32_t binding, VkShaderStageFlags shaderStageFlag);
63-
VulkanBuffer& addDescriptorSetPerPassBindings(const std::vector<PassBinding>&);
64-
VkDescriptorBufferInfo getDescriptorInfo(VkDeviceSize offset = 0);
58+
VulkanBuffer& addDescriptorSetPerPassBindings(const std::vector<PassBindingInfo>&);
59+
VkDescriptorBufferInfo getVkDescriptorBufferInfo(VkDeviceSize offset = 0);
6560
uint32_t getPassDescriptorBinding(std::string passName);
6661

6762
private:
68-
// VMA Version of createVkBuffer
63+
/**
64+
* @brief Create a Vma Buffer object (VMA version of classical Vulkan createBuffer)
65+
66+
*/
6967
void createVmaBuffer(VkDeviceSize size, VkBufferUsageFlags buffer_usage, VkBuffer& buffer, VmaAllocation& allocation,
7068
VmaAllocationInfo* allocation_info, VmaAllocationCreateFlags flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
7169
VmaMemoryUsage memory_usage = VMA_MEMORY_USAGE_AUTO, const std::vector<uint32_t>& queue_family_indices = {});
72-
7370
VmaAllocator m_VmaAllocator;
7471
VulkanBufferCreateInfo m_createInfo;
7572
VmaAllocationCreateFlags m_VmaFlags;

Intern/RayCore/src/VulkanEngine/Run/Pipeline.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ void Pass::updatePushConstant(int stage, void* data, uint32_t size) { m_pass[sta
126126

127127
// -------------------------------------------------------------------------------------------------------
128128

129-
ComputePass::ComputePass(VkDevice& device, const ComputePassCreateInfo_t& createInfo) : m_Device(device), m_name(std::string(createInfo.passName)) {
129+
ComputePass::ComputePass(VkDevice& device, const ComputePassCreateInfo_t& createInfo) : m_Device(device) {
130+
m_name = std::string(createInfo.passName);
130131
m_stagesCount = createInfo.shaderStagesCreateInfos.size();
131132
m_pass.reserve(m_stagesCount);
132-
133133
m_descriptorSets.reserve(createInfo.descriptorSetAmount);
134134

135135
// Fill compute Pipelines
@@ -188,7 +188,10 @@ void ComputePass::updateDescriptorSets(BufferHandler* bufferHandler) {
188188
auto buffers = bufferHandler->getBuffers();
189189

190190
for (auto& [name, b] : *buffers) {
191-
auto descInfo = b->getDescriptorInfo();
191+
if (!b->hasPassDescriptorBinding(m_name)) {
192+
continue;
193+
}
194+
auto descInfo = b->getVkDescriptorBufferInfo();
192195
writer.writeBuffer(b->getPassDescriptorBinding(m_name), &descInfo);
193196
}
194197

@@ -223,7 +226,7 @@ void ComputePass::simpleUpdateDescriptorSets(BufferHandler* bufferHandler) {
223226
vkUpdateDescriptorSets(m_Device, 1, &writeDescriptorSet, 0, nullptr);
224227
}
225228
// FIXME: Not working..
226-
// perform the update of the descriptor set.
229+
// perform the update of the descriptor set all at once
227230
// vkUpdateDescriptorSets(m_Device, writes.size(), writes.data(), 0, nullptr);
228231
}
229232

Intern/RayCore/src/VulkanEngine/Run/Pipeline.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace RAYX {
1414
// -------------------------------------------------------------------------------------------------------
1515
/**
1616
* @brief General Vulkan Pass (A group of Pipelines)
17-
*
17+
* Not to be used directly, look at ComputePass/GraphicsPass
1818
*/
1919
class RAYX_API Pass {
2020
public:
@@ -64,6 +64,7 @@ class RAYX_API Pass {
6464

6565
protected:
6666
uint32_t m_stagesCount;
67+
std::string m_name;
6768
Pipelines m_pass = {}; // The pass itself (Pipelines)
6869
std::unique_ptr<DescriptorPool> m_globalDescriptorPool{};
6970
};
@@ -99,7 +100,7 @@ class RAYX_API ComputePass : public Pass {
99100
void prepare(std::vector<VkDescriptorSetLayoutBinding> bindings);
100101
void createDescriptorPool(uint32_t maxSets, uint32_t bufferCount);
101102

102-
const VkPipelineBindPoint& getPipelineBindPoint() const { return m_PipelineBindPoint; }
103+
const VkPipelineBindPoint& getPipelineBindPoint() const { return m_PipelineBindPoint; }
103104
const std::vector<VkDescriptorSet>& getDescriptorSets() const { return m_descriptorSets; }
104105
const std::vector<VkDescriptorSetLayout>& getDescriptorSetLayouts() const { return m_descriptorSetLayouts; }
105106
std::string getName() const { return m_name; }
@@ -116,14 +117,12 @@ class RAYX_API ComputePass : public Pass {
116117
void createDescriptorSetLayout(std::vector<VkDescriptorSetLayoutBinding>& bindings);
117118

118119
VkDevice& m_Device;
119-
std::string m_name; // TODO(OS): Consider moving this to Pass parent class
120-
121120
VkPipelineBindPoint m_PipelineBindPoint = VK_PIPELINE_BIND_POINT_COMPUTE; // Always compute
122121

123122
std::vector<VkDescriptorSetLayout> m_descriptorSetLayouts; // TODO(OS): For now, only one [0]
124123
std::vector<VkDescriptorSet> m_descriptorSets; // TODO(OS): For now, only one [0]
125124

126-
// TODO(OS): Add missing memory barriers
125+
// TODO(OS): Add missing memory barriers, if needed
127126
};
128127
} // namespace RAYX
129128
#endif

Intern/RayCore/src/VulkanEngine/Run/RecordBuffer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ void VulkanEngine::recordSecondCommand() {
164164
pass1->bind(*cmdBuffer1, 0);
165165
pass1->bindDescriptorSet(*cmdBuffer1, 0);
166166

167-
// auto traceCommand = [](VkCOmmandBuffer & command)
168-
169167
auto requiredLocalWorkGroupNo = (uint32_t)ceil((float)m_numberOfInvocations / float(WORKGROUP_SIZE)); // number of local works groups
170168
VkPhysicalDeviceProperties deviceProperties;
171169
vkGetPhysicalDeviceProperties(m_PhysicalDevice, &deviceProperties);

0 commit comments

Comments
 (0)