Skip to content

Commit 764ce46

Browse files
Use CStrings as data members for ShaderSpecifications (#489)
- To solve the segmentation fault when moving the Specifications with `std::string` members, using Cstrings instead prevents the segmentation fault Co-authored-by: Mathew Benson <[email protected]>
1 parent 99fbb3c commit 764ce46

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

ZEngine/ZEngine/Rendering/Shaders/Shader.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace ZEngine::Rendering::Shaders
9898
LayoutBindingSpecificationMap[set].init(m_device->Arena, 10);
9999
}
100100

101-
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Name = UB_resource.name, .DescriptorTypeValue = DescriptorType::UNIFORM_BUFFER, .Flags = ShaderStageFlags::VERTEX});
101+
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Name = UB_resource.name.c_str(), .DescriptorTypeValue = DescriptorType::UNIFORM_BUFFER, .Flags = ShaderStageFlags::VERTEX});
102102
}
103103

104104
for (const auto& SB_resource : vertex_resources.storage_buffers)
@@ -111,7 +111,7 @@ namespace ZEngine::Rendering::Shaders
111111
LayoutBindingSpecificationMap[set].init(m_device->Arena, 10);
112112
}
113113

114-
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Name = SB_resource.name, .DescriptorTypeValue = DescriptorType::STORAGE_BUFFER, .Flags = ShaderStageFlags::VERTEX});
114+
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Name = SB_resource.name.c_str(), .DescriptorTypeValue = DescriptorType::STORAGE_BUFFER, .Flags = ShaderStageFlags::VERTEX});
115115
}
116116

117117
for (const auto& pushConstant_resource : vertex_resources.push_constant_buffers)
@@ -127,7 +127,7 @@ namespace ZEngine::Rendering::Shaders
127127
uint32_t memberSize = spirv_compiler->get_declared_struct_member_size(type, i);
128128
struct_total_size += memberSize;
129129
}
130-
PushConstantSpecifications.push(PushConstantSpecification{.Name = pushConstant_resource.name, .Size = struct_total_size, .Offset = struct_offset, .Flags = ShaderStageFlags::VERTEX});
130+
PushConstantSpecifications.push(PushConstantSpecification{.Name = pushConstant_resource.name.c_str(), .Size = struct_total_size, .Offset = struct_offset, .Flags = ShaderStageFlags::VERTEX});
131131
/*
132132
* We update the offset for next iteration
133133
*/
@@ -167,7 +167,7 @@ namespace ZEngine::Rendering::Shaders
167167
LayoutBindingSpecificationMap[set].init(m_device->Arena, 10);
168168
}
169169

170-
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Name = UB_resource.name, .DescriptorTypeValue = DescriptorType::UNIFORM_BUFFER, .Flags = ShaderStageFlags::FRAGMENT});
170+
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Name = UB_resource.name.c_str(), .DescriptorTypeValue = DescriptorType::UNIFORM_BUFFER, .Flags = ShaderStageFlags::FRAGMENT});
171171
}
172172

173173
for (const auto& SB_resource : fragment_resources.storage_buffers)
@@ -180,7 +180,7 @@ namespace ZEngine::Rendering::Shaders
180180
LayoutBindingSpecificationMap[set].init(m_device->Arena, 10);
181181
}
182182

183-
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Name = SB_resource.name, .DescriptorTypeValue = DescriptorType::STORAGE_BUFFER, .Flags = ShaderStageFlags::FRAGMENT});
183+
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Name = SB_resource.name.c_str(), .DescriptorTypeValue = DescriptorType::STORAGE_BUFFER, .Flags = ShaderStageFlags::FRAGMENT});
184184
}
185185

186186
for (const auto& pushConstant_resource : fragment_resources.push_constant_buffers)
@@ -196,7 +196,7 @@ namespace ZEngine::Rendering::Shaders
196196
uint32_t memberSize = spirv_compiler->get_declared_struct_member_size(type, i);
197197
struct_total_size += memberSize;
198198
}
199-
PushConstantSpecifications.push(PushConstantSpecification{.Name = pushConstant_resource.name, .Size = struct_total_size, .Offset = struct_offset, .Flags = ShaderStageFlags::FRAGMENT});
199+
PushConstantSpecifications.push(PushConstantSpecification{.Name = pushConstant_resource.name.c_str(), .Size = struct_total_size, .Offset = struct_offset, .Flags = ShaderStageFlags::FRAGMENT});
200200
/*
201201
* We update the offset for next iteration
202202
*/
@@ -225,7 +225,7 @@ namespace ZEngine::Rendering::Shaders
225225
LayoutBindingSpecificationMap[set].init(m_device->Arena, 10);
226226
}
227227

228-
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Count = count, .Name = SI_resource.name, .DescriptorTypeValue = DescriptorType::COMBINED_IMAGE_SAMPLER, .Flags = ShaderStageFlags::FRAGMENT});
228+
LayoutBindingSpecificationMap[set].push(LayoutBindingSpecification{.Set = set, .Binding = binding, .Count = count, .Name = SI_resource.name.c_str(), .DescriptorTypeValue = DescriptorType::COMBINED_IMAGE_SAMPLER, .Flags = ShaderStageFlags::FRAGMENT});
229229
}
230230
}
231231
}

ZEngine/ZEngine/Rendering/Specifications/ShaderSpecification.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <ZEngineDef.h>
23
#include <vulkan/vulkan.h>
34

45
namespace ZEngine::Rendering::Specifications
@@ -38,25 +39,25 @@ namespace ZEngine::Rendering::Specifications
3839
uint32_t Set{0xFFFFFFFF};
3940
uint32_t Binding{0xFFFFFFFF};
4041
uint32_t Count{1};
41-
std::string Name;
42+
cstring Name;
4243
DescriptorType DescriptorTypeValue;
4344
ShaderStageFlags Flags;
4445
};
4546

4647
struct PushConstantSpecification
4748
{
48-
std::string Name;
49+
cstring Name;
4950
uint32_t Size;
5051
uint32_t Offset;
5152
ShaderStageFlags Flags;
5253
};
5354

5455
struct ShaderSpecification
5556
{
56-
uint32_t OverloadMaxSet = 1;
57-
uint32_t OverloadPoolSize = 0;
58-
const char* VertexFilename = {};
59-
const char* FragmentFilename = {};
60-
const char* Name = {};
57+
uint32_t OverloadMaxSet = 1;
58+
uint32_t OverloadPoolSize = 0;
59+
cstring VertexFilename = {};
60+
cstring FragmentFilename = {};
61+
cstring Name = {};
6162
};
6263
} // namespace ZEngine::Rendering::Specifications

0 commit comments

Comments
 (0)