// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Types/BaseTypes.h"
#include "Shaders/GPUShaderProgram.h"
#include "Enums.h"
#include "GPUResource.h"
///
/// Describes full graphics pipeline state within single object.
///
API_CLASS(Sealed) class FLAXENGINE_API GPUPipelineState : public GPUResource
{
DECLARE_SCRIPTING_TYPE_NO_SPAWN(GPUPipelineState);
static GPUPipelineState* Spawn(const SpawnParams& params);
static GPUPipelineState* New();
public:
///
/// Pipeline state description
///
API_STRUCT() struct FLAXENGINE_API Description
{
DECLARE_SCRIPTING_TYPE_NO_SPAWN(Description);
///
/// Enable/disable depth (DepthFunc and DepthWriteEnable)
///
API_FIELD() bool DepthEnable;
///
/// Enable/disable depth write
///
API_FIELD() bool DepthWriteEnable;
///
/// Enable/disable depth clipping
///
API_FIELD() bool DepthClipEnable;
///
/// A function that compares depth data against existing depth data
///
API_FIELD() ComparisonFunc DepthFunc;
///
/// Vertex shader program
///
API_FIELD() GPUShaderProgramVS* VS;
///
/// Hull shader program
///
API_FIELD() GPUShaderProgramHS* HS;
///
/// Domain shader program
///
API_FIELD() GPUShaderProgramDS* DS;
///
/// Geometry shader program
///
API_FIELD() GPUShaderProgramGS* GS;
///
/// Pixel shader program
///
API_FIELD() GPUShaderProgramPS* PS;
///
/// Input primitives topology
///
API_FIELD() PrimitiveTopologyType PrimitiveTopologyType;
///
/// True if use wireframe rendering, otherwise false
///
API_FIELD() bool Wireframe;
///
/// Primitives culling mode
///
API_FIELD() CullMode CullMode;
///
/// Colors blending mode
///
API_FIELD() BlendingMode BlendMode;
public:
///
/// Default description
///
API_FIELD(ReadOnly) static Description Default;
///
/// Default description without using depth buffer at all
///
API_FIELD(ReadOnly) static Description DefaultNoDepth;
///
/// Default description for fullscreen triangle rendering
///
API_FIELD(ReadOnly) static Description DefaultFullscreenTriangle;
};
protected:
ShaderBindings _meta;
GPUPipelineState();
public:
#if BUILD_DEBUG
///
/// The description of the pipeline state cached on creation in debug builds. Can be used to help with rendering crashes or issues and validation.
///
Description DebugDesc;
#endif
#if USE_EDITOR
int32 Complexity;
#endif
public:
///
/// Gets constant buffers usage mask (each set bit marks usage of the constant buffer at the bit index slot). Combined from all the used shader stages.
///
FORCE_INLINE uint32 GetUsedCBsMask() const
{
return _meta.UsedCBsMask;
}
///
/// Gets shader resources usage mask (each set bit marks usage of the shader resource slot at the bit index slot). Combined from all the used shader stages.
///
FORCE_INLINE uint32 GetUsedSRsMask() const
{
return _meta.UsedSRsMask;
}
///
/// Gets unordered access usage mask (each set bit marks usage of the unordered access slot at the bit index slot). Combined from all the used shader stages.
///
FORCE_INLINE uint32 GetUsedUAsMask() const
{
return _meta.UsedUAsMask;
}
public:
///
/// Returns true if pipeline state is valid and ready to use
///
API_PROPERTY() virtual bool IsValid() const = 0;
///
/// Create new state data
///
/// Full pipeline state description
/// True if cannot create state, otherwise false
API_FUNCTION() virtual bool Init(API_PARAM(Ref) const Description& desc);
public:
// [GPUResource]
GPUResourceType GetResourceType() const final override;
};