Skip to content

Commit d389cea

Browse files
committed
Fixed bug with creating non-debug instances
1 parent 9adc7e9 commit d389cea

File tree

16 files changed

+82
-109
lines changed

16 files changed

+82
-109
lines changed

engine/render/assets/shaders/frag.frag

Whitespace-only changes.

engine/render/assets/shaders/simpleShader2D.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ layout(location = 1) in vec3 color;
66

77
layout(location = 0) out vec3 fragColor;
88

9-
layout (std140, set = 0, binding = 0) readonly buffer Transforms{
9+
layout (std140, binding = 0) readonly buffer Transforms{
1010
mat4 transforms[];
1111
} transforms;
1212

@@ -16,7 +16,7 @@ struct CameraData
1616
mat4 viewMatrix;
1717
};
1818

19-
layout (set = 1, binding = 1) uniform GlobalData {
19+
layout (binding = 1) uniform GlobalData {
2020
CameraData cameraData;
2121
} globalData;
2222

engine/render/assets/shaders/vert.vert

Whitespace-only changes.

engine/render/renderer/buffer/Buffer.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,19 @@ void DestroyBuffer(Buffer& buffer)
8989
size_t PadUniformBufferSize(size_t originalSize)
9090
{
9191
// Calculate required alignment based on minimum device offset alignment
92-
size_t minUboAlignment = Vulkan::Context::GetPhysicalDevice()->GetMinDeviceAlignment();
92+
size_t minUboAlignment = Vulkan::Context::GetPhysicalDevice()->GetMinUniformDeviceAlignment();
93+
size_t alignedSize = originalSize;
94+
if (minUboAlignment > 0)
95+
{
96+
alignedSize = (alignedSize + minUboAlignment - 1) & ~(minUboAlignment - 1);
97+
}
98+
return alignedSize;
99+
}
100+
101+
size_t PadStorageBufferSize(size_t originalSize)
102+
{
103+
// Calculate required alignment based on minimum device offset alignment
104+
size_t minUboAlignment = Vulkan::Context::GetPhysicalDevice()->GetMinStorageDeviceAlignment();
93105
size_t alignedSize = originalSize;
94106
if (minUboAlignment > 0)
95107
{

engine/render/renderer/buffer/Buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void CopyBuffer(VkBuffer& srcBuffer, VkBuffer& dstBuffer, VkDeviceSize size);
7979
void DestroyBuffer(Buffer& buffer);
8080

8181
size_t PadUniformBufferSize(size_t originalSize);
82+
size_t PadStorageBufferSize(size_t originalSize);
8283
} // namespace Siege::Buffer
8384

8485
#endif

engine/render/renderer/descriptor/DescriptorPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DescriptorPool
2828

2929
private:
3030

31-
static constexpr size_t MAX_DESCRIPTOR_POOL_SIZES = 10;
31+
static constexpr size_t MAX_DESCRIPTOR_POOL_SIZES = 1024;
3232

3333
static VkDescriptorPool descriptorPool;
3434
static Utils::MSArray<VkDescriptorPoolSize, MAX_DESCRIPTOR_POOL_SIZES> sizes;

engine/render/renderer/material/Material.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void Material::CreateDescriptors()
176176
OUT binding.layout,
177177
&layoutBinding,
178178
1),
179-
"Failed to create descriptor set!");
179+
"Failed to create descriptor set!")
180180

181181
uint64_t offset = property.offset;
182182

engine/render/renderer/platform/vulkan/Material.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ namespace Siege::Vulkan
2222
Material::Material(Shader vertShader, Shader fragShader)
2323
: vertexShader{std::move(vertShader)}, fragmentShader{std::move(fragShader)}
2424
{
25-
bufferSize += (Buffer::PadUniformBufferSize(vertexShader.GetTotalUniformSize()) +
26-
Buffer::PadUniformBufferSize(fragmentShader.GetTotalUniformSize()));
25+
// Separate uniforms into unique properties
26+
27+
uint64_t offset {0};
28+
29+
AddShader(vertexShader, OUT offset);
30+
AddShader(fragmentShader, OUT offset);
2731

2832
// TODO: Make a standalone buffer class
2933
// Allocate buffer which can store all the data we need
@@ -33,13 +37,6 @@ Material::Material(Shader vertShader, Shader fragShader)
3337
OUT buffer.buffer,
3438
OUT buffer.bufferMemory);
3539

36-
// Separate uniforms into unique properties
37-
38-
uint64_t offset {0};
39-
40-
AddShader(vertexShader, OUT offset);
41-
AddShader(fragmentShader, OUT offset);
42-
4340
// Create Descriptor Set Layout for Sets
4441

4542
for (size_t i = 0; i < propertiesSlots.Count(); i++)
@@ -113,13 +110,15 @@ Material& Material::operator=(Material&& other)
113110
void Material::SetUniformData(Hash::StringId id, uint64_t dataSize, const void* data)
114111
{
115112
// TODO: Clean this up.
116-
for (auto& slot : propertiesSlots)
113+
for (auto it = propertiesSlots.CreateIterator(); it; ++it)
117114
{
118-
for (auto& property : slot.properties)
115+
auto slot = *it;
116+
for (auto slotIt = slot.properties.CreateIterator(); slotIt; ++slotIt)
119117
{
120-
if (property.id == id)
118+
auto prop = *slotIt;
119+
if (prop.id == id)
121120
{
122-
Buffer::CopyData(buffer, dataSize, data, property.offset);
121+
Buffer::CopyData(buffer, dataSize, data, prop.offset);
123122
return;
124123
}
125124
}
@@ -164,6 +163,8 @@ void Material::AddShader(const Shader& shader, uint64_t& offset)
164163
property.shaderStage = (Utils::ShaderType)(property.shaderStage | shader.GetShaderType());
165164
property.offset = offset;
166165

166+
bufferSize += uniform.totalSize;
167+
167168
offset += uniform.totalSize;
168169
}
169170
}
@@ -173,8 +174,8 @@ void Material::Bind(const CommandBuffer& commandBuffer)
173174
graphicsPipeline.Bind(commandBuffer);
174175

175176
// TODO: Cache this on the material itself?
176-
StackArray<VkDescriptorSet, 10> setsToBind;
177-
for (auto property : propertiesSlots) setsToBind.Append(property.set);
177+
::Siege::Utils::MSArray<VkDescriptorSet, 10> setsToBind;
178+
for (auto it = propertiesSlots.CreateIterator(); it; ++it) setsToBind.Append((*it).set);
178179

179180
graphicsPipeline.BindSets(commandBuffer, setsToBind);
180181
}
@@ -185,8 +186,8 @@ void Material::Bind(VkCommandBuffer commandBuffer)
185186
graphicsPipeline.Bind(commandBuffer);
186187

187188
// TODO: Cache this on the material itself?
188-
StackArray<VkDescriptorSet, 10> setsToBind;
189-
for (auto property : propertiesSlots) setsToBind.Append(property.set);
189+
::Siege::Utils::MSArray<VkDescriptorSet, 10> setsToBind;
190+
for (auto it = propertiesSlots.CreateIterator(); it; ++it) setsToBind.Append((*it).set);
190191

191192
graphicsPipeline.BindSets(commandBuffer, setsToBind);
192193
}
@@ -199,19 +200,20 @@ void Material::UpdateMaterial()
199200
void Material::WriteSet(PropertiesSlot& slot)
200201
{
201202
VkWriteDescriptorSet writes[slot.properties.Count()];
203+
VkDescriptorBufferInfo bufferInfos[slot.properties.Count()];
202204

203205
for (size_t j = 0; j < slot.properties.Count(); j++)
204206
{
205207
auto& property = slot.properties[j];
206208

207-
VkDescriptorBufferInfo bufferInfo = Descriptor::CreateBufferInfo(buffer.buffer, property.offset, property.size);
209+
bufferInfos[j] = Descriptor::CreateBufferInfo(buffer.buffer, property.offset, property.size);
208210

209211
writes[j] = Descriptor::CreateWriteSet(
210212
j,
211213
slot.set,
212214
1,
213215
Utils::ToVkDescriptorType(property.type),
214-
&bufferInfo);
216+
&bufferInfos[j]);
215217
}
216218

217219
Descriptor::WriteSets(Vulkan::Context::GetVkLogicalDevice(),

engine/render/renderer/platform/vulkan/PhysicalDevice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ PhysicalDevice::PhysicalDevice(Surface surface, const Instance& vulkanInstance)
3030

3131
properties = {vkProperties.deviceName,
3232
vkProperties.limits.minUniformBufferOffsetAlignment,
33+
vkProperties.limits.minStorageBufferOffsetAlignment,
3334
FindDepthFormat()};
3435

3536
CC_LOG_INFO("Physical device found: {} with minumum buffer alignment of {}",

engine/render/renderer/platform/vulkan/PhysicalDevice.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PhysicalDevice
2222
// TODO: Add new properties as new needs are discovered.
2323
const char* deviceName;
2424
uint64_t minUniformBufferOffsetAlignment {0};
25+
uint64_t minStorageBufferOffsetAlignment {0};
2526
Utils::DepthFormat depthFormat {Utils::DEPTH_NONE};
2627
};
2728

@@ -38,11 +39,16 @@ class PhysicalDevice
3839
return device;
3940
}
4041

41-
inline constexpr size_t GetMinDeviceAlignment() const
42+
inline constexpr size_t GetMinUniformDeviceAlignment() const
4243
{
4344
return properties.minUniformBufferOffsetAlignment;
4445
}
4546

47+
inline constexpr size_t GetMinStorageDeviceAlignment() const
48+
{
49+
return properties.minStorageBufferOffsetAlignment;
50+
}
51+
4652
inline constexpr Utils::DepthFormat GetDepthFormat() const
4753
{
4854
return properties.depthFormat;

0 commit comments

Comments
 (0)