Plasma Engine  2.0
Loading...
Searching...
No Matches
ShaderPermutationResource.h
1#pragma once
2
3#include <Core/ResourceManager/Resource.h>
4#include <Core/ResourceManager/ResourceTypeLoader.h>
5#include <Foundation/Time/Timestamp.h>
6#include <RendererCore/RendererCoreDLL.h>
7#include <RendererCore/Shader/ShaderPermutationBinary.h>
8#include <RendererCore/ShaderCompiler/PermutationGenerator.h>
9
12
16
17class PL_RENDERERCORE_DLL plShaderPermutationResource : public plResource
18{
19 PL_ADD_DYNAMIC_REFLECTION(plShaderPermutationResource, plResource);
20 PL_RESOURCE_DECLARE_COMMON_CODE(plShaderPermutationResource);
22
23public:
25
26 plGALShaderHandle GetGALShader() const { return m_hShader; }
27 const plGALShaderByteCode* GetShaderByteCode(plGALShaderStage::Enum stage) const { return m_ByteCodes[stage]; }
28
29 plGALBlendStateHandle GetBlendState() const { return m_hBlendState; }
30 plGALDepthStencilStateHandle GetDepthStencilState() const { return m_hDepthStencilState; }
31 plGALRasterizerStateHandle GetRasterizerState() const { return m_hRasterizerState; }
32
33 bool IsShaderValid() const { return m_bShaderPermutationValid; }
34
35 plArrayPtr<const plPermutationVar> GetPermutationVars() const { return m_PermutationVars; }
36
37private:
38 virtual plResourceLoadDesc UnloadData(Unload WhatToUnload) override;
39 virtual plResourceLoadDesc UpdateContent(plStreamReader* Stream) override;
40 virtual void UpdateMemoryUsage(MemoryUsage& out_NewMemoryUsage) override;
41 virtual plResourceTypeLoader* GetDefaultResourceTypeLoader() const override;
42
43private:
44 friend class plShaderManager;
45
46 plSharedPtr<const plGALShaderByteCode> m_ByteCodes[plGALShaderStage::ENUM_COUNT];
47
48 bool m_bShaderPermutationValid;
49 plGALShaderHandle m_hShader;
50
51 plGALBlendStateHandle m_hBlendState;
52 plGALDepthStencilStateHandle m_hDepthStencilState;
53 plGALRasterizerStateHandle m_hRasterizerState;
54
56};
57
58
60{
61public:
62 virtual plResourceLoadData OpenDataStream(const plResource* pResource) override;
63 virtual void CloseDataStream(const plResource* pResource, const plResourceLoadData& loaderData) override;
64
65 virtual bool IsResourceOutdated(const plResource* pResource) const override;
66
67private:
68 plResult RunCompiler(const plResource* pResource, plShaderPermutationBinary& BinaryInfo, bool bForce);
69};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition RendererFoundationDLL.h:467
Definition RendererFoundationDLL.h:460
Definition RendererFoundationDLL.h:474
This class wraps shader byte code storage. Since byte code can have different requirements for alignm...
Definition ShaderByteCode.h:96
Definition RendererFoundationDLL.h:404
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
The base class for all resources.
Definition Resource.h:10
virtual plResourceLoadDesc UnloadData(Unload WhatToUnload)=0
Requests the resource to unload another quality level. If bFullUnload is true, the resource should un...
virtual plResourceLoadDesc UpdateContent(plStreamReader *pStream)=0
Called whenever more data for the resource is available. The resource must read the stream to update ...
virtual plResourceTypeLoader * GetDefaultResourceTypeLoader() const
Returns the resource type loader that should be used for this type of resource, unless it has been ov...
Definition Resource.cpp:245
virtual void UpdateMemoryUsage(MemoryUsage &out_NewMemoryUsage)=0
This function must be overridden by all resource types.
Base class for all resource loaders.
Definition ResourceTypeLoader.h:29
Definition ShaderManager.h:9
Serialized state of a shader permutation used by plShaderPermutationResourceLoader to convert into a ...
Definition ShaderPermutationBinary.h:23
Definition ShaderPermutationResource.h:18
Definition ShaderPermutationResource.h:60
virtual void CloseDataStream(const plResource *pResource, const plResourceLoadData &loaderData) override
This function is called when the resource has been updated with the data from the resource loader and...
Definition ShaderPermutationResource.cpp:356
virtual plResourceLoadData OpenDataStream(const plResource *pResource) override
Override this function to implement the resource loading.
Definition ShaderPermutationResource.cpp:254
virtual bool IsResourceOutdated(const plResource *pResource) const override
If this function returns true, a resource is unloaded and loaded again to update its content.
Definition ShaderPermutationResource.cpp:227
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Interface for binary in (read) streams.
Definition Stream.h:22
Definition Resource.h:34
Data returned by plResourceTypeLoader implementations.
Definition ResourceTypeLoader.h:10
Describes in which loading state a resource currently is, and how many different quality levels there...
Definition Declarations.h:102
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition ShaderPermutationResource.h:14