This interface need to be overwritten by specific material. It defines how we build texture and descriptor set.
Registry to renderer if already build.
Create PipelineLayout.
Registry ShaderModule.
If ReBuild, need clear old descripotrset first.
Iter the constantParams and fill it's data to memoryblock.
Return if not valid textureParameter or constantParameter.
Instance a VkWriteDescriptorSet.
Update DescriptorSet.
Not supported format.
Create ConstantParameter Buffer .
Fill in data to memory block.
Create PipelineLayout.
Registry to renderer if already build.
Create PipelineLayout.
Registry ShaderModule.
If ReBuild, need clear old descripotrset first.
Iter the constantParams and fill it's data to memoryblock.
Return if not valid textureParameter or constantParameter.
Instance a VkWriteDescriptorSet.
Update DescriptorSet.
Not supported format.
Create ConstantParameter Buffer .
Fill in data to memory block.
Create PipelineLayout.
137 {
139
140 std::unique_lock<std::mutex> lock(
m_Mutex);
141
145 {
147
149 {
153 {
157 }
158
159 return;
160 }
161
163 }
164
168 {
170
172 {
173 for (int i = 0; i < pair.second.size(); i++)
174 {
175 std::stringstream ss;
176 ss << pair.second[i] << "." << pair.first;
177
178 ResourcePool<Shader>::Load<Shader>(ss.str(), pair.second[i], pair.first);
179 }
180 }
181 }
182
186 {
188
191 }
192
196 {
198
199 m_ConstantParams.for_each([&](
const std::string& k,
const ConstantParams& v) {
201 return false;
202 });
203
205 }
206
211 if (size == 0)
212 {
213 if (isAutoRegistry)
214 {
218 }
219
220 return;
221 }
222
226 {
228
231 "MaterialParameterBuffer",
232 size,
233 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
234 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
235 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
236 );
237 }
238
242 {
244
245 int tindex = 0;
247
252 if (v.textureType == "Texture2D")
253 {
254 if(v.texturePath == "")
255 {
256 v.index = -1;
257 }
258 else
259 {
260 const std::shared_ptr<Texture> texture = ResourcePool<Texture>::Load<Texture2D>(v.texturePath, v.texturePath);
261 v.index = BindLessTextureManager::Registry(v.texturePath);
262
263 const auto descriptorSet = DescriptorSetManager::Registry("PreRenderer", SpicesShader::BINDLESS_TEXTURE_SET);
264
268 VkWriteDescriptorSet write {};
269 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
270 write.dstBinding = SpicesShader::BINDLESS_TEXTURE_BINDING;
271 write.dstSet = descriptorSet->Get();
272 write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
273 write.pImageInfo = texture->GetResource<VulkanImage>()->GetImageInfo();
274 write.descriptorCount = 1;
275 write.dstArrayElement = v.index;
276
281 }
282
285 }
286
290 else
291 {
292 SPICES_CORE_ERROR("Material::BuildMaterial(): Invalid textureType.");
293 }
294
295 tindex++;
296 return false;
297 });
298 }
299
303 {
305
309
313 if (ref.paramType == "float4")
314 {
315 *static_cast<glm::vec4*>(pt) = std::any_cast<glm::vec4>(ref.paramValue);
318 }
319 else if (ref.paramType == "float3")
320 {
321 *static_cast<glm::vec3*>(pt) = std::any_cast<glm::vec3>(ref.paramValue);
324 }
325 else if (ref.paramType == "float2")
326 {
327 *static_cast<glm::vec2*>(pt) = std::any_cast<glm::vec2>(ref.paramValue);
330 }
331 else if (ref.paramType == "float")
332 {
333 *static_cast<float*>(pt) = std::any_cast<float>(ref.paramValue);
336 }
337 else if (ref.paramType == "int")
338 {
339 *static_cast<int*>(pt) = std::any_cast<int>(ref.paramValue);
342 }
343 else if (ref.paramType == "bool")
344 {
345 *static_cast<bool*>(pt) = std::any_cast<bool>(ref.paramValue);
348 }
349 else
350 {
351 SPICES_CORE_ERROR("Material::BuildMaterial(): Invalid paramType.")
352 }
353
354 return false;
355 });
356 }
357
361 if (isAutoRegistry)
362 {
366 }
367 }
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
scl::linked_unordered_map< std::string, ConstantParams > m_ConstantParams
Constant parameters. Key: parameter name, Value: parameter value.
bool m_AlreadyBuild
True if this material already build a buffer.
std::unordered_map< std::string, std::vector< std::string > > m_Shaders
Shader path Key: shader usage, Value: shader file name.
scl::runtime_memory_block m_Buffermemoryblocks
m_Buffers's c++ data container. Key: set, Value: scl::runtime_memory_block.
scl::linked_unordered_map< std::string, TextureParam > m_TextureParams
Texture parameters. Key: parameter name, Value: parameter value.
std::mutex m_Mutex
Mutex of this material.
std::unique_ptr< VulkanBuffer > m_MaterialParameterBuffer
std::string m_MaterialPath
static std::shared_ptr< Renderer > GetRenderer(const std::string &name)
static std::vector< std::string > SplitString(const std::string &input, char delimiter)
Split a string to a string vector container use a char.
static VulkanState & GetState()
Get VulkanState in use.
void for_each(const std::function< bool(const std::string &name, void *pt)> &fn) const
Iter the object_ and call explain_element() to filling data.
void build()
Malloc a memory to begin_.
void add_element(const std::string &name, const std::string &type)
Add a element to object_, means a memory block will be occupied with given param type.
size_t item_location(const std::string &name)
Get item location in blocks.
size_t get_bytes() const
Get the bytes_.
The container is wrapper of a continue memory block. Used in Material::BuildMaterial(),...