Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rendering_engine::VulkanMaterialResources Class Reference

Vulkan-specific implementation of material render resources. More...

#include <vulkan_material_resources.hpp>

Inherits rendering_engine::IMaterialRenderResources.

Public Member Functions

 VulkanMaterialResources (VulkanRenderer *renderer)
 Constructs a VulkanMaterialResources instance. More...
 
void Initialize (Material *material) override
 Initializes Vulkan-specific GPU resources for the material. More...
 
void Shutdown () override
 Releases all Vulkan GPU resources associated with this material. More...
 
VkDescriptorSetLayout GetDescriptorSetLayout () const
 Gets the Vulkan descriptor set layout for the material. More...
 
VkPipelineLayout GetPipelineLayout () const
 Gets the Vulkan pipeline layout used by the material. More...
 
VkPipeline GetPipeline () const
 Gets the Vulkan graphics pipeline used by the material. More...
 
- Public Member Functions inherited from rendering_engine::IMaterialRenderResources
virtual ~IMaterialRenderResources ()=default
 
virtual void Initialize (Material *material)=0
 Initializes the GPU-side representation of a material. More...
 
virtual void Shutdown ()=0
 Releases all GPU resources associated with this material. More...
 

Detailed Description

Vulkan-specific implementation of material render resources.

This class manages Vulkan GPU resources required to render a specific Material. It provides access to the Vulkan descriptor set layout, pipeline layout, and graphics pipeline associated with a given material. The resource creation is delegated to the owning VulkanRenderer instance.

The Material class calls Initialize and Shutdown to manage the lifecycle of these resources.

Definition at line 28 of file vulkan_material_resources.hpp.

Constructor & Destructor Documentation

◆ VulkanMaterialResources()

rendering_engine::VulkanMaterialResources::VulkanMaterialResources ( VulkanRenderer renderer)

Constructs a VulkanMaterialResources instance.

Parameters
rendererPointer to the VulkanRenderer that provides creation utilities.

Definition at line 9 of file vulkan_material_resources.cpp.

10 :
11 mRenderer(renderer)
12{}

Member Function Documentation

◆ GetDescriptorSetLayout()

VkDescriptorSetLayout rendering_engine::VulkanMaterialResources::GetDescriptorSetLayout ( ) const

Gets the Vulkan descriptor set layout for the material.

Returns
Vulkan handle to the descriptor set layout.

Definition at line 84 of file vulkan_material_resources.cpp.

85{
86 return mDescriptorSetLayout;
87}

◆ GetPipeline()

VkPipeline rendering_engine::VulkanMaterialResources::GetPipeline ( ) const

Gets the Vulkan graphics pipeline used by the material.

Returns
Vulkan handle to the pipeline.

Definition at line 94 of file vulkan_material_resources.cpp.

95{
96 return mPipelinePair.second;
97}

◆ GetPipelineLayout()

VkPipelineLayout rendering_engine::VulkanMaterialResources::GetPipelineLayout ( ) const

Gets the Vulkan pipeline layout used by the material.

Returns
Vulkan handle to the pipeline layout.

Definition at line 89 of file vulkan_material_resources.cpp.

90{
91 return mPipelinePair.first;
92}

◆ Initialize()

void rendering_engine::VulkanMaterialResources::Initialize ( Material material)
overridevirtual

Initializes Vulkan-specific GPU resources for the material.

Loads compiled SPIR-V shader binaries and creates descriptor set layout and pipeline.

Parameters
materialPointer to the owning Material instance.

Implements rendering_engine::IMaterialRenderResources.

Definition at line 14 of file vulkan_material_resources.cpp.

15{
16 Shutdown();
17
18 mDescriptorSetLayout = mRenderer->CreateDescriptorSetLayout(material);
19
20 std::string matName;
21 if (material->GetMaterialSettings().parentMaterialName.empty())
22 {
23 matName = material->GetMaterialSettings().materialName;
24 }
25 else
26 {
27 matName = material->GetMaterialSettings().parentMaterialName;
28 }
29
30 std::vector<char> spvVert;
31 std::vector<char> spvFrag;
32
34 {
35 const auto& entries = Utility::GetPackEntries();
36 std::string materialEntry = "Shaders/" + matName;
37
38 std::vector<uint8_t> binaryFileDataVert = Utility::ReadPackedFile(materialEntry + "/" + std::string(matName + "_vert.spv"));
39 std::vector<uint8_t> binaryFileDataFrag = Utility::ReadPackedFile(materialEntry + "/" + std::string(matName + "_frag.spv"));
40
41 spvVert.assign(binaryFileDataVert.begin(), binaryFileDataVert.end());
42 spvFrag.assign(binaryFileDataFrag.begin(), binaryFileDataFrag.end());
43 }
44 else
45 {
46 boost::filesystem::path matPath = Utility::GetShadersFolderPath() / matName;
47
48 spvVert = Utility::ReadShaderBinaryFile((matPath / std::string(matName + "_vert.spv")).string());
49 spvFrag = Utility::ReadShaderBinaryFile((matPath / std::string(matName + "_frag.spv")).string());
50 }
51
52 mPipelinePair = mRenderer->CreateGraphicsPipeline(material, mDescriptorSetLayout, spvVert, spvFrag);
53}
static boost::filesystem::path GetShadersFolderPath()
Returns absolute path to Content/Shaders.
Definition: utility.cpp:259
static std::vector< char > ReadShaderBinaryFile(std::string const &filename)
Reads a binary shader file from disk.
Definition: utility.cpp:113
static const PackEntries & GetPackEntries()
Returns the manifest of packed files.
Definition: utility.cpp:281
static std::vector< uint8_t > ReadPackedFile(const std::string &entryPath)
Reads raw bytes of a file stored inside Pack.bin.
Definition: utility.cpp:322
static bool IsPackageProvided()
Checks whether packed assets (Pack.bin / Pack.json) exist.
Definition: utility.cpp:274
void Shutdown() override
Releases all Vulkan GPU resources associated with this material.
VkDescriptorSetLayout CreateDescriptorSetLayout(Material *material)
Creates a descriptor set layout corresponding to a given material.
std::pair< VkPipelineLayout, VkPipeline > CreateGraphicsPipeline(Material *material, VkDescriptorSetLayout &descriptorSetLayout, std::vector< char > &spvVertShaderCode, std::vector< char > &spvFragShaderCode)
Creates a Vulkan graphics pipeline based on material and shader inputs.

◆ Shutdown()

void rendering_engine::VulkanMaterialResources::Shutdown ( )
overridevirtual

Releases all Vulkan GPU resources associated with this material.

This should be called when the renderer shuts down or resources are rebuilt.

Implements rendering_engine::IMaterialRenderResources.

Definition at line 55 of file vulkan_material_resources.cpp.

56{
57 if (!mRenderer)
58 return;
59
60 VkDevice device = mRenderer->GetLogicalDevice(); // or GetDevice()
61
62 // Pipeline first
63 if (mPipelinePair.second != VK_NULL_HANDLE)
64 {
65 vkDestroyPipeline(device, mPipelinePair.second, nullptr);
66 mPipelinePair.second = VK_NULL_HANDLE;
67 }
68
69 // Then pipeline layout
70 if (mPipelinePair.first != VK_NULL_HANDLE)
71 {
72 vkDestroyPipelineLayout(device, mPipelinePair.first, nullptr);
73 mPipelinePair.first = VK_NULL_HANDLE;
74 }
75
76 // Then descriptor set layout
77 if (mDescriptorSetLayout != VK_NULL_HANDLE)
78 {
79 vkDestroyDescriptorSetLayout(device, mDescriptorSetLayout, nullptr);
80 mDescriptorSetLayout = VK_NULL_HANDLE;
81 }
82}
VkDevice & GetLogicalDevice()
Returns reference to the logical Vulkan device.

The documentation for this class was generated from the following files: