Foundation
Loading...
Searching...
No Matches
PipelineState.hpp
Go to the documentation of this file.
1#pragma once
2#include "Common.hpp"
3#include "Shader.hpp"
4#include "Descriptor.hpp"
5namespace Foundation::RHI {
6 class RHIDevice;
7 enum class RHIPipelineStateCacheBackend : uint32_t
8 {
9 Unknown = 0,
10 Vulkan = 1,
11 };
16
18 {
19 uint64_t high{};
20 uint64_t low{};
21 };
41
43 {
44 protected:
46 public:
47 static constexpr uint32_t kSerializedDataMagic = 0x43535046; // FPSC
48 static constexpr uint32_t kSerializedDataVersion = 1;
50 {
52 };
53 RHIPipelineStateCache(RHIDevice const& device, PipelineStateCacheDesc const&) : mDevice(device) {}
54
55 [[nodiscard]] virtual RHIPipelineStateCacheImportStatus GetImportStatus() const = 0;
56 [[nodiscard]] virtual size_t GetSerializedDataSize() const = 0;
57 [[nodiscard]] virtual size_t WriteSerializedData(Span<unsigned char> dstBuffer) const = 0;
58 virtual void DebugSetObjectName(const char* name) = 0;
59 };
60 class RHIPipelineState : public RHIObject {
61 protected:
63 public:
66 RHIDevicePipelineType type{ RHIDevicePipelineType::Graphics };
67 // [Graphics] Vertex Input
68 struct VertexInput {
69 struct Binding {
70 uint32_t stride; // In bytes
71 bool perInstance{ false }; // If true, this binding is per-instance data
72 };
76 // [Graphics] Input Assembly
83 // [Graphics] Viewport
84 struct Viewport {
85 float x = 0, y = 0, width, height;
86 float minDepth = 0.0, maxDepth = 1.0;
88 // [Graphics] Scissor
89 struct Scissor {
90 int32_t x = 0, y = 0, width, height;
92 // [Graphics] Rasterizer
111 // [Graphics] MSAA
116 // [Graphics] Depth Stencil
133 struct Attachment {
134 struct Blending {
135 bool enabled{ false };
153 const static Blending GetNoBlending() { return {}; }
154 const static Blending GetAlphaBlending() {
155 return {
156 .enabled = true,
157 .srcColorBlendFactor = SrcAlpha,
158 .dstColorBlendFactor = OneMinusSrcAlpha,
159 .srcAlphaBlendFactor = One,
160 .dstAlphaBlendFactor = OneMinusSrcAlpha,
161 .colorBlendOp = Add,
162 .alphaBlendOp = Add
163 };
164 }
166 {
167 return {
168 .enabled = true,
169 .srcColorBlendFactor = SrcAlpha,
170 .dstColorBlendFactor = One,
171 .srcAlphaBlendFactor = One,
172 .dstAlphaBlendFactor = One,
173 .colorBlendOp = Add,
174 .alphaBlendOp = Add
175 };
176 }
181 };
182 // [Graphics] Attachments/Alpha Blending
184 // Stages
186 {
187 Triangles,
189 };
190 struct ShaderStage {
191 struct StageDesc {
192 // Stage this shader participates in
193 // You can only specify one stage per shader module.
194 RHIShaderStage stage;
195 const char* entryPoint;
196 // Only one specialization info per stage for simplicity
198 // For ray tracing shaders - which hit group index this shader belongs to
199 const uint32_t raytracingHitGroupIndex{0};
203 };
205 // Descriptors
207 // Push Constants
209 RHIShaderStage stage;
210 size_t offset;
211 size_t size;
212 };
214 };
216
217 RHIPipelineState(RHIDevice const& device, PipelineStateDesc const& desc) : mDevice(device), mDesc(desc) {}
218
219 virtual void DebugSetObjectName(const char* name) = 0;
220 };
221
222}
#define ENUM_NAME_CONV_BEGIN(T)
Defines convince to_string() method and format_as() [fmt] for the respective enum class Example usage...
Definition Enums.hpp:82
#define ENUM_NAME(E)
Definition Enums.hpp:93
Definition Device.hpp:246
Base class for all RHI objects.
Definition Details.hpp:17
Definition PipelineState.hpp:43
virtual size_t GetSerializedDataSize() const =0
RHIPipelineStateCache(RHIDevice const &device, PipelineStateCacheDesc const &)
Definition PipelineState.hpp:53
virtual void DebugSetObjectName(const char *name)=0
virtual RHIPipelineStateCacheImportStatus GetImportStatus() const =0
virtual size_t WriteSerializedData(Span< unsigned char > dstBuffer) const =0
const RHIDevice & mDevice
Definition PipelineState.hpp:45
Definition PipelineState.hpp:60
const RHIDevice & mDevice
Definition PipelineState.hpp:62
RHIPipelineState(RHIDevice const &device, PipelineStateDesc const &desc)
Definition PipelineState.hpp:217
const PipelineStateDesc mDesc
Definition PipelineState.hpp:215
virtual void DebugSetObjectName(const char *name)=0
Definition Shader.hpp:5
std::span< T > Span
Alias for std::span
Definition Container.hpp:62
Low-level Rendering Hardware Interface (RHI) abstractions.
Definition Application.hpp:3
RHIPipelineStateCacheImportStatus
Definition PipelineState.hpp:23
RHIPipelineStateCacheBackend
Definition PipelineState.hpp:8
RHIResourceFormat
Definition Common.hpp:34
RHIMultisampleCount
Definition Common.hpp:273
Definition PipelineState.hpp:18
static const Blending GetAdditiveBlending()
Definition PipelineState.hpp:165
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Attachment::Blending::BlendFactor dstAlphaBlendFactor
static const Blending GetAlphaBlending()
Definition PipelineState.hpp:154
static const Blending GetNoBlending()
Definition PipelineState.hpp:153
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Attachment::Blending::BlendFactor dstColorBlendFactor
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Attachment::Blending::BlendFactor srcAlphaBlendFactor
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Attachment::Blending::BlendOp colorBlendOp
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Attachment::Blending::BlendFactor srcColorBlendFactor
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Attachment::Blending::BlendOp alphaBlendOp
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::Attachment::RenderTarget renderTarget
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::Attachment::Blending blending
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::DepthStencil::CompareOp Greater
RHIResourceFormat stencilFormat
Definition PipelineState.hpp:119
RHIResourceFormat depthFormat
Definition PipelineState.hpp:118
RHIMultisampleCount sampleCount
Definition PipelineState.hpp:114
RHIShaderStage stage
Definition PipelineState.hpp:209
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Rasterizer::FrontFace FFCounterClockwise
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Rasterizer::FillMode FillSolid
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Rasterizer::CullMode CullBack
const uint32_t raytracingHitGroupIndex
Definition PipelineState.hpp:199
RayTracingHitGroupType raytracingHitGroupType
Definition PipelineState.hpp:200
Span< const char > specializationData
Definition PipelineState.hpp:197
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::ShaderStage::StageDesc desc
RHIShaderModule * shaderModule
Definition PipelineState.hpp:202
Span< const Binding > bindings
Definition PipelineState.hpp:73
Span< const RHIVertexAttribute > attributes
Definition PipelineState.hpp:74
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::Viewport viewport
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::DepthStencil depthStencil
Span< RHIDeviceDescriptorSetLayout *const > descriptorSetLayouts
Definition PipelineState.hpp:206
Span< const Attachment > attachments
Definition PipelineState.hpp:183
Span< const ShaderStage > shaderStages
Definition PipelineState.hpp:204
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::VertexInput vertexInput
Span< const PushConstant > pushConstants
Definition PipelineState.hpp:213
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::Rasterizer rasterizer
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::Scissor scissor
struct Foundation::RHI::RHIPipelineState::PipelineStateDesc::Multisample multisample
RHIPipelineStateCache * psoCache
Definition PipelineState.hpp:65
enum Foundation::RHI::RHIPipelineState::PipelineStateDesc::Topology TriangleList
@ TriangleStrip
Definition PipelineState.hpp:81
@ PointList
Definition PipelineState.hpp:79
@ TriangleList
Definition PipelineState.hpp:80
RHIDevicePipelineType type
Definition PipelineState.hpp:66
RayTracingHitGroupType
Definition PipelineState.hpp:186