// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Types/BaseTypes.h" #include "Shaders/GPUShaderProgram.h" #include "Enums.h" #include "GPUResource.h" /// /// Stencil operation modes. /// API_ENUM() enum class StencilOperation : byte { // Keep the existing stencil data. Keep, // Set the stencil data to 0. Zero, // Set the stencil data to the reference value (set via GPUContext::SetStencilRef). Replace, // Increment the stencil value by 1, and clamp the result. IncrementSaturated, // Decrement the stencil value by 1, and clamp the result. DecrementSaturated, // Invert the stencil data. Invert, // Increment the stencil value by 1, and wrap the result if necessary. Increment, // Decrement the stencil value by 1, and wrap the result if necessary. Decrement, API_ENUM(Attributes="HideInEditor") MAX }; /// /// 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; /// /// Enable/disable stencil buffer usage /// API_FIELD() bool StencilEnable; /// /// The read mask applied to the reference value and each stencil buffer entry to determine the significant bits for the stencil test. /// API_FIELD() uint8 StencilReadMask; /// /// The write mask applied to values written into the stencil buffer. /// API_FIELD() uint8 StencilWriteMask; /// /// The comparison function for the stencil test. /// API_FIELD() ComparisonFunc StencilFunc; /// /// The stencil operation to perform when stencil testing fails. /// API_FIELD() StencilOperation StencilFailOp; /// /// The stencil operation to perform when stencil testing passes and depth testing fails. /// API_FIELD() StencilOperation StencilDepthFailOp; /// /// The stencil operation to perform when stencil testing and depth testing both pass. /// API_FIELD() StencilOperation StencilPassOp; /// /// 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 PrimitiveTopology; /// /// 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; };