33#ifndef DVD_HARDWARE_VIDEO_GFX_DEVICE_H_
34#define DVD_HARDWARE_VIDEO_GFX_DEVICE_H_
62struct RenderPassParams;
69class SceneGUIElements;
84class SceneRenderState;
85class KernelApplication;
86class ShaderComputeQueue;
87class CascadedShadowMapsGenerator;
89struct SizeChangeParams;
90struct ShaderBufferDescriptor;
104 class GFXDeviceKernel;
105 class GFXDeviceGraphicsResource;
106 class GFXDeviceGFXRTPool;
107 class GFXDeviceProjectManager;
108 class GFXDeviceShaderProgram;
109 class GFXDeviceShadowMap;
110 class GFXDeviceWindowManager;
111 class KernelApplication;
152template<
typename Descriptor,
size_t N>
168 [[nodiscard]]
size_t size() const noexcept;
171 void add(const
I64 ID, const Descriptor& data) noexcept;
172 void addLocked(const
I64 ID, const Descriptor& data) noexcept;
216 friend class Attorney::GFXDeviceAPI;
220 friend class Attorney::GFXDeviceShaderProgram;
254 void closeRenderingAPI();
256 void idle(
bool fast,
U64 deltaTimeUSGame,
U64 deltaTimeUSApp);
267 void validateAndUploadDescriptorSets();
291 bool setViewport(const
Rect<
I32>& viewport);
292 bool setViewport(
I32 x,
I32 y,
I32 width,
I32 height );
293 bool setScissor(const
Rect<
I32>& scissor);
295 void setDepthRange(
vec2<
F32> depthRange);
296 void setPreviousViewProjectionMatrix(
PlayerIndex player, const
mat4<
F32>& prevViewMatrix, const
mat4<
F32> prevProjectionMatrix );
302 F32 renderingAspectRatio() const noexcept;
303 vec2<
U16> renderingResolution() const noexcept;
305 void setScreenMSAASampleCount(
U8 sampleCount);
306 void setShadowMSAASampleCount(
ShadowType type,
U8 sampleCount);
309 void screenshot(
std::string_view fileName, GFX::CommandBuffer& bufferInOut ) const;
316 [[nodiscard]]
Renderer& getRenderer() const;
320 [[nodiscard]]
GFXRTPool& renderTargetPool() noexcept;
321 [[nodiscard]] const
GFXRTPool& renderTargetPool() const noexcept;
323 void registerDrawCall() noexcept;
324 void registerDrawCalls(
U32 count) noexcept;
328 void toggleDebugView(
I16 index,
bool state);
329 void toggleDebugGroup(
I16 groupID,
bool state);
330 void getDebugViewNames(
vector<
std::tuple<
string,
I16,
I16,
bool>>& namesOut);
331 [[nodiscard]]
bool getDebugGroupState(
I16 groupID) const;
336 void onThreadCreated(const
std::thread::
id& threadID,
bool isMainRenderThread) const;
338 static
void FrameInterpolationFactor(const
D64 interpolation) noexcept { s_interpolationFactor = interpolation; }
345 [[nodiscard]] static
bool IsSubmitCommand(GFX::CommandType type) noexcept;
353 [[nodiscard]]
bool destroyIMP(
IMPrimitive*& primitive);
356 [[nodiscard]] VertexBuffer_ptr newVB( const
VertexBuffer::Descriptor& descriptor );
358 [[nodiscard]] GenericVertexData_ptr newGVD(
U32 ringBufferLength,
std::string_view name);
368 void drawTextureInViewport(const
ImageView& texture,
SamplerDescriptor sampler, const
Rect<
I32>& viewport,
bool convertToSrgb,
bool drawToDepthOnly,
bool drawBlend, GFX::CommandBuffer& bufferInOut);
378 GFX::CommandBuffer& bufferInOut);
380 void updateSceneDescriptorSet(GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut ) const;
383 [[nodiscard]] const GFXDescriptorSet& descriptorSet(
DescriptorSetUsage usage) const noexcept;
397 [[nodiscard]]
bool framePreRender( const
FrameEvent& evt ) override;
398 [[nodiscard]]
bool frameStarted( const
FrameEvent& evt ) override;
399 [[nodiscard]]
bool frameEnded( const
FrameEvent& evt ) noexcept override;
403 void update(
U64 deltaTimeUSFixed,
U64 deltaTimeUSApp);
405 [[nodiscard]]
ErrorCode initDescriptorSets();
407 void setScreenMSAASampleCountInternal(
U8 sampleCount);
408 void setShadowMSAASampleCountInternal(
ShadowType type,
U8 sampleCount);
411 [[nodiscard]]
bool fitViewportInWindow(
U16 w,
U16 h);
419 void initDebugViews();
420 void renderDebugViews(
Rect<
I32> targetViewport,
I32 padding, GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut );
422 void flushCommandBufferInternal(
Handle<GFX::CommandBuffer> commandBuffer);
424 [[nodiscard]]
PipelineDescriptor& getDebugPipeline(const IM::BaseDescriptor& descriptor) noexcept;
425 void debugDrawLines( GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut);
426 void debugDrawBoxes( GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut );
427 void debugDrawOBBs( GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut );
428 void debugDrawCones( GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut );
429 void debugDrawSpheres( GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut );
430 void debugDrawFrustums( GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut );
434 void renderDebugUI(const
Rect<
I32>& targetViewport, GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut );
440 void occlusionCull(const
RenderPass::PassData& passData,
444 bool countCulledNodes,
445 GFX::CommandBuffer& bufferInOut);
455 [[nodiscard]]
bool uploadGPUBlock();
456 void resizeGPUBlocks(
size_t targetSizeCam,
size_t targetSizeCullCounter);
459 void shadowingSettings(
const F32 lightBleedBias,
const F32 minShadowVariance)
noexcept;
460 void worldAOViewProjectionMatrix(
const mat4<F32>& vpMatrix)
noexcept;
484 static constexpr U8 s_invalidQueueSampleCount = 255u;
485 U8 _queuedScreenSampleChange = s_invalidQueueSampleCount;
538 static constexpr U8 PER_FRAME_BUFFER_COUNT = 3u;
543 ShaderBuffer_uptr _camDataBuffer =
nullptr;
544 ShaderBuffer_uptr _cullCounter =
nullptr;
545 size_t _camWritesThisFrame = 0u;
546 size_t _renderWritesThisFrame = 0u;
547 } _perFrameBuffers[PER_FRAME_BUFFER_COUNT];
549 size_t _perFrameBufferIndex = 0u;
550 bool _needsResizeCam =
false;
553 [[nodiscard]] inline const
PerFrameBuffers& crtBuffers() const noexcept;
555 inline
void reset(const
bool camBuffer, const
bool cullBuffer) noexcept;
557 inline
void onEndFrame() noexcept;
564 static constexpr
U8 MAX_CAMERA_SNAPSHOTS = 32u;
599 device.
update(deltaTimeUSFixed, deltaTimeUSApp);
603 friend class Divide::KernelApplication;
618 [type, GUID, nameHash](
const auto& crtEntry) noexcept ->
bool {
619 if (std::get<1>(crtEntry) != GUID)
624 DIVIDE_ASSERT(std::get<0>(crtEntry) == type && std::get<2>(crtEntry) == nameHash);
638 return device.
newRT(descriptor);
648 device.shadowingSettings(lightBleedBias, minShadowVariance);
658 device.worldAOViewProjectionMatrix( vpMatrix );
static RenderTarget_uptr newRT(GFXDevice &device, const RenderTargetDescriptor &descriptor)
static void onResourceDestroy(GFXDevice &device, GraphicsResource::Type type, I64 GUID, U64 nameHash)
static void onResourceCreate(GFXDevice &device, GraphicsResource::Type type, I64 GUID, U64 nameHash)
static void onWindowSizeChange(GFXDevice &device, const SizeChangeParams ¶ms)
static void update(GFXDevice &device, const U64 deltaTimeUSFixed, const U64 deltaTimeUSApp)
static void onResolutionChange(GFXDevice &device, const SizeChangeParams ¶ms)
static void shadowingSettings(GFXDevice &device, const F32 lightBleedBias, const F32 minShadowVariance) noexcept
static void worldAOViewProjectionMatrix(GFXDevice &device, const mat4< F32 > &vpMatrix) noexcept
static void drawToWindow(GFXDevice &device, DisplayWindow &window)
static void flushWindow(GFXDevice &device, DisplayWindow &window)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Mutex _graphicsResourceMutex
GFX::BindPipelineCommand _blurBoxPipelineLayeredCmd
GFXDescriptorSets _descriptorSets
std::array< U8, to_base(ShadowType::COUNT)> _queuedShadowSampleChange
GFX::BindPipelineCommand _blurGaussianPipelineLayeredCmd
DebugPrimitiveHandler< IM::BoxDescriptor, 16u > _debugBoxes
static IMPrimitivePool s_IMPrimitivePool
void onResolutionChange(const SizeChangeParams ¶ms)
static DeviceInformation s_deviceInformation
static D64 FrameInterpolationFactor() noexcept
GFX::BindPipelineCommand _drawFSTexturePipelineBlendCmd
GFX::BindPipelineCommand _drawFSDepthPipelineCmd
DebugPrimitiveHandler< IM::ConeDescriptor, 16u > _debugCones
void update(U64 deltaTimeUSFixed, U64 deltaTimeUSApp)
GFX::BindPipelineCommand _blurBoxPipelineSingleCmd
RenderTarget_uptr newRT(const RenderTargetDescriptor &descriptor)
Create and return a new framebuffer.
vector< DebugView_ptr > _debugViews
PipelineDescriptor _debugGizmoPipelineNoCull
PipelineDescriptor _debugGizmoPipeline
PipelineDescriptor _debugGizmoPipelineNoCullNoDepth
DebugPrimitiveHandler< IM::FrustumDescriptor, 8u > _debugFrustums
void onWindowSizeChange(const SizeChangeParams ¶ms)
The main entry point for any resolution change request.
std::array< GFXDescriptorSet, to_base(DescriptorSetUsage::COUNT)> GFXDescriptorSets
RenderAPIWrapper_uptr _api
MemoryPool< IMPrimitive, 1<< 15 > IMPrimitivePool
FrustumClipPlanes _clippingPlanes
The interpolation factor between the current and the last frame.
std::unique_ptr< ShaderComputeQueue > _shaderComputeQueue
GFX::BindPipelineCommand _blurGaussianPipelineSingleCmd
Mutex _queuedCommandbufferLock
CameraSnapshot _activeCameraSnapshot
DebugPrimitiveHandler< IM::SphereDescriptor, 16u > _debugSpheres
void drawToWindow(DisplayWindow &window)
PipelineDescriptor _debugGizmoPipelineNoDepth
GFX::BindPipelineCommand _drawFSTexturePipelineCmd
const RenderAPIWrapper & getAPIImpl() const
void flushWindow(DisplayWindow &window)
static U64 FrameCount() noexcept
std::unique_ptr< GFXRTPool > _rtPool
DebugPrimitiveHandler< IM::LineDescriptor, 16u > _debugLines
DebugPrimitiveHandler< IM::OBBDescriptor, 16u > _debugOBBs
vector< std::tuple< GraphicsResource::Type, I64, U64 > > _graphicResources
static D64 s_interpolationFactor
vec2< U16 > _renderingResolution
Utility class that adds basic GUID management to objects.
IMPrimitive replaces immediate mode calls to VB based rendering.
The kernel is the main system that connects all of our various systems: windows, gfx,...
Renderer Programming Interface.
All the information needed for a single light's shadowmap.
An API-independent representation of a texture.
const char * RenderPassTypeToString(const RenderPassType pass) noexcept
RenderStage StringToRenderStage(const char *stage) noexcept
const char * GraphicResourceTypeToName(const GraphicsResource::Type type) noexcept
const char * RenderStageToString(const RenderStage stage) noexcept
RenderPassType StringToRenderPassType(const char *pass) noexcept
Handle console commands that start with a forward slash.
DELEGATE_STD< Ret, Args... > DELEGATE
std::lock_guard< mutex > LockGuard
SceneNodeType
ToDo: Move particle emitter to components (it will make them way more dynamic) - Ionut.
RTAttachmentType
This enum is used when creating render targets to define the channel that the texture will attach to.
eastl::vector< Type > vector
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMap
constexpr I16 to_I16(const T value)
void debugDraw(GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut) override
bool dvd_erase_if(eastl::vector< T, A > &vec, Predicate &&pred)
constexpr auto to_base(const Type value) -> Type
DebugPrimitiveHandler() noexcept
void addLocked(const I64 ID, const Descriptor &data) noexcept
eastl::fixed_vector< DataEntry, N, true > _debugData
void add(const I64 ID, const Descriptor &data) noexcept
size_t size() const noexcept
eastl::fixed_vector< IMPrimitive *, N, true > _debugPrimitives
static constexpr U8 g_maxFrameLifetime
SamplerDescriptor _sampler
DebugView(const I16 sortIndex) noexcept
Handle< ShaderProgram > _shader
Handle< Texture > _texture
BufferRange _camBufferWriteRange
PROPERTY_RW(DescriptorSet, impl)
PROPERTY_RW(bool, dirty, true)
PROPERTY_R_IW(Handle< ShaderProgram >, imWorldOITShaderNoTexture, INVALID_HANDLE< ShaderProgram >)
PROPERTY_R_IW(Handle< ShaderProgram >, imWorldShader, INVALID_HANDLE< ShaderProgram >)
PROPERTY_R_IW(Handle< ShaderProgram >, imWorldShaderNoTexture, INVALID_HANDLE< ShaderProgram >)
PROPERTY_R_IW(Handle< ShaderProgram >, imShaderNoTexture, INVALID_HANDLE< ShaderProgram >)
PROPERTY_R_IW(Handle< ShaderProgram >, imWorldOITShader, INVALID_HANDLE< ShaderProgram >)
PROPERTY_R_IW(Handle< ShaderProgram >, imShader, INVALID_HANDLE< ShaderProgram >)
static RenderTargetID HI_Z
static RenderTargetID REFLECTION_PLANAR_BLUR
static RenderTargetID OIT
static RenderTargetID BACK_BUFFER
static RenderTargetID NORMALS_RESOLVED
static RenderTargetID OIT_REFLECT
static RenderTargetID HI_Z_REFLECT
static RenderTargetID SSAO_RESULT
static RenderTargetID SCREEN
static RenderTargetID SSR_RESULT
static RenderTargetID REFLECTION_CUBE
static std::array< RenderTargetID, Config::MAX_REFRACTIVE_NODES_IN_VIEW > REFRACTION_PLANAR
static std::array< RenderTargetID, Config::MAX_REFLECTIVE_NODES_IN_VIEW > REFLECTION_PLANAR
static RenderTargetID SCREEN_PREV