Skip to content

Commit 27715c0

Browse files
committed
address several comments (more still need to be addressed). And fix the install_dependencies_windows.bat to be more user friendly.
1 parent dd9713a commit 27715c0

File tree

9 files changed

+369
-362
lines changed

9 files changed

+369
-362
lines changed

attachments/simple_engine/audio_system.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class OpenALAudioOutputDevice : public AudioOutputDevice {
385385
std::vector<int16_t> pcmBuffer(samplesProcessed);
386386
for (uint32_t i = 0; i < samplesProcessed; i++) {
387387
// Clamp and convert to 16-bit PCM
388-
float sample = std::max(-1.0f, std::min(1.0f, audioBuffer[i]));
388+
float sample = std::clamp( -1.0f, 1.0f, audioBuffer[i] );
389389
pcmBuffer[i] = static_cast<int16_t>(sample * 32767.0f);
390390
}
391391

attachments/simple_engine/debug_system.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ class DebugSystem {
193193
* @brief End a performance measurement and log the result.
194194
* @param name The name of the measurement.
195195
*/
196-
void EndMeasurement(const std::string& name) {
197-
std::lock_guard<std::mutex> lock(mutex);
198-
196+
void StopMeasurement(const std::string& name) {
199197
auto now = std::chrono::high_resolution_clock::now();
200198
auto it = measurements.find(name);
201199

attachments/simple_engine/descriptor_manager.cpp

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "descriptor_manager.h"
22
#include <iostream>
33
#include <array>
4-
#include <string.h>
4+
#include <cstring>
55
#include "transform_component.h"
66
#include "camera_component.h"
77

@@ -11,9 +11,7 @@ DescriptorManager::DescriptorManager(VulkanDevice& device)
1111
}
1212

1313
// Destructor
14-
DescriptorManager::~DescriptorManager() {
15-
// RAII will handle destruction
16-
}
14+
DescriptorManager::~DescriptorManager() = default;
1715

1816
// Create descriptor pool
1917
bool DescriptorManager::createDescriptorPool(uint32_t maxSets) {
@@ -88,9 +86,58 @@ bool DescriptorManager::createUniformBuffers(Entity* entity, uint32_t maxFramesI
8886
}
8987
}
9088

89+
bool DescriptorManager::update_descriptor_sets(Entity* entity, uint32_t maxFramesInFlight, bool& value1) {
90+
assert(entityResources[entity].uniformBuffers.size() == maxFramesInFlight);
91+
// Update descriptor sets
92+
for (size_t i = 0; i < maxFramesInFlight; i++) {
93+
// Create descriptor buffer info
94+
vk::DescriptorBufferInfo bufferInfo{
95+
.buffer = *entityResources[entity].uniformBuffers[i],
96+
.offset = 0,
97+
.range = sizeof(UniformBufferObject)
98+
};
99+
100+
// Create descriptor image info
101+
vk::DescriptorImageInfo imageInfo{
102+
// These would be set based on the texture resources
103+
// .sampler = textureSampler,
104+
// .imageView = textureImageView,
105+
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal
106+
};
107+
108+
// Create descriptor writes
109+
std::array<vk::WriteDescriptorSet, 2> descriptorWrites = {
110+
vk::WriteDescriptorSet{
111+
.dstSet = entityResources[entity].descriptorSets[i],
112+
.dstBinding = 0,
113+
.dstArrayElement = 0,
114+
.descriptorCount = 1,
115+
.descriptorType = vk::DescriptorType::eUniformBuffer,
116+
.pImageInfo = nullptr,
117+
.pBufferInfo = &bufferInfo,
118+
.pTexelBufferView = nullptr
119+
},
120+
vk::WriteDescriptorSet{
121+
.dstSet = entityResources[entity].descriptorSets[i],
122+
.dstBinding = 1,
123+
.dstArrayElement = 0,
124+
.descriptorCount = 1,
125+
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
126+
.pImageInfo = &imageInfo,
127+
.pBufferInfo = nullptr,
128+
.pTexelBufferView = nullptr
129+
}
130+
};
131+
132+
// Update descriptor sets
133+
device.getDevice().updateDescriptorSets(descriptorWrites, nullptr);
134+
}
135+
return false;
136+
}
91137
// Create descriptor sets for an entity
92138
bool DescriptorManager::createDescriptorSets(Entity* entity, const std::string& texturePath, vk::DescriptorSetLayout descriptorSetLayout, uint32_t maxFramesInFlight) {
93139
try {
140+
assert(entityResources.find(entity) != entityResources.end());
94141
// Create descriptor sets for each frame in flight
95142
std::vector<vk::DescriptorSetLayout> layouts(maxFramesInFlight, descriptorSetLayout);
96143

@@ -101,61 +148,10 @@ bool DescriptorManager::createDescriptorSets(Entity* entity, const std::string&
101148
.pSetLayouts = layouts.data()
102149
};
103150

104-
// Allocate descriptor sets
105-
auto descriptorSets = device.getDevice().allocateDescriptorSets(allocInfo);
151+
entityResources[entity].descriptorSets = device.getDevice().allocateDescriptorSets(allocInfo);
106152

107-
// Store descriptor sets
108-
// Convert from vk::raii::DescriptorSet to vk::DescriptorSet
109-
std::vector<vk::DescriptorSet> nonRaiiDescriptorSets;
110-
for (const auto& ds : descriptorSets) {
111-
nonRaiiDescriptorSets.push_back(*ds);
112-
}
113-
entityResources[entity].descriptorSets = nonRaiiDescriptorSets;
114-
115-
// Update descriptor sets
116-
for (size_t i = 0; i < maxFramesInFlight; i++) {
117-
// Create descriptor buffer info
118-
vk::DescriptorBufferInfo bufferInfo{
119-
.buffer = *entityResources[entity].uniformBuffers[i],
120-
.offset = 0,
121-
.range = sizeof(UniformBufferObject)
122-
};
123-
124-
// Create descriptor image info
125-
vk::DescriptorImageInfo imageInfo{
126-
// These would be set based on the texture resources
127-
// .sampler = textureSampler,
128-
// .imageView = textureImageView,
129-
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal
130-
};
131-
132-
// Create descriptor writes
133-
std::array<vk::WriteDescriptorSet, 2> descriptorWrites = {
134-
vk::WriteDescriptorSet{
135-
.dstSet = descriptorSets[i],
136-
.dstBinding = 0,
137-
.dstArrayElement = 0,
138-
.descriptorCount = 1,
139-
.descriptorType = vk::DescriptorType::eUniformBuffer,
140-
.pImageInfo = nullptr,
141-
.pBufferInfo = &bufferInfo,
142-
.pTexelBufferView = nullptr
143-
},
144-
vk::WriteDescriptorSet{
145-
.dstSet = descriptorSets[i],
146-
.dstBinding = 1,
147-
.dstArrayElement = 0,
148-
.descriptorCount = 1,
149-
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
150-
.pImageInfo = &imageInfo,
151-
.pBufferInfo = nullptr,
152-
.pTexelBufferView = nullptr
153-
}
154-
};
155-
156-
// Update descriptor sets
157-
device.getDevice().updateDescriptorSets(descriptorWrites, nullptr);
158-
}
153+
bool value1;
154+
if (update_descriptor_sets(entity, maxFramesInFlight, value1)) return value1;
159155

160156
return true;
161157
} catch (const std::exception& e) {
@@ -192,6 +188,8 @@ void DescriptorManager::updateUniformBuffer(uint32_t currentImage, Entity* entit
192188
ubo.lightPos = glm::vec4(0.0f, 5.0f, 0.0f, 1.0f);
193189
ubo.lightColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
194190

191+
assert(entityResources.find(entity) != entityResources.end());
192+
assert(entityResources[entity].uniformBuffers.size() > currentImage);
195193
// Copy data to uniform buffer
196194
memcpy(entityResources[entity].uniformBuffersMapped[currentImage], &ubo, sizeof(ubo));
197195
}

attachments/simple_engine/descriptor_manager.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DescriptorManager {
3434
std::vector<vk::raii::Buffer> uniformBuffers;
3535
std::vector<vk::raii::DeviceMemory> uniformBuffersMemory;
3636
std::vector<void*> uniformBuffersMapped;
37-
std::vector<vk::DescriptorSet> descriptorSets;
37+
std::vector<vk::raii::DescriptorSet> descriptorSets;
3838
};
3939

4040
/**
@@ -62,6 +62,7 @@ class DescriptorManager {
6262
* @return True if the uniform buffers were created successfully, false otherwise.
6363
*/
6464
bool createUniformBuffers(Entity* entity, uint32_t maxFramesInFlight);
65+
bool update_descriptor_sets(Entity* entity, uint32_t maxFramesInFlight, bool& value1);
6566

6667
/**
6768
* @brief Create descriptor sets for an entity.
@@ -91,14 +92,14 @@ class DescriptorManager {
9192
* @brief Get the entity resources.
9293
* @return The entity resources.
9394
*/
94-
std::unordered_map<Entity*, EntityResources>& getEntityResources() { return entityResources; }
95+
const std::unordered_map<Entity*, EntityResources>& getEntityResources() { return entityResources; }
9596

9697
/**
9798
* @brief Get the resources for an entity.
9899
* @param entity The entity.
99100
* @return The entity resources.
100101
*/
101-
EntityResources& getEntityResources(Entity* entity) { return entityResources[entity]; }
102+
const EntityResources& getEntityResources(Entity* entity) { return entityResources[entity]; }
102103

103104
private:
104105
// Vulkan device

0 commit comments

Comments
 (0)