// Copyright (C) 2004 Id Software, Inc.
//

#ifndef __MODERN_GL_EXECUTOR_H__
#define __MODERN_GL_EXECUTOR_H__

#include "RendererCaps.h"
#include "RenderGraph.h"

typedef struct modernGLExecutorStats_s {
	bool	available;
	bool	enabled;
	bool	initialized;
	bool	vaoReady;
	bool	frameUBOReady;
	bool	shaderLibraryReady;
	bool	gpuDrivenReady;
	bool	lowOverheadReady;
	bool	sceneSSBOReady;
	bool	indirectBufferReady;
	bool	drawRecordBufferReady;
	bool	drawRecordIndexBufferReady;
	bool	gpuDrivenBucketBufferReady;
	bool	validationSSBOReady;
	bool	computeValidationReady;
	bool	gpuDrivenRequested;
	bool	gpuDrivenExecuted;
	bool	gpuDrivenValidationRequested;
	bool	gpuDrivenValidationReadbackReady;
	bool	gpuDrivenIndirectExecuted;
	bool	gpuDrivenIndirectMultiDrawReady;
	bool	gpuDrivenHiZCullingReady;
	bool	gpuDrivenIndirectCompactionReady;
	bool	frameUBOStreamed;
	bool	gpuDrivenStreamedBuffersReady;
	bool	tierUsesDSA;
	bool	tierUsesMultiBind;
	bool	vertexInputCacheReady;
	bool	vertexInputVertexBindingReady;
	bool	vertexInputFormatReady;
	bool	lowOverheadSamplerReady;
	bool	lowOverheadBindlessRequested;
	bool	lowOverheadBindlessAvailable;
	bool	materialTextureTableReady;
	bool	materialTextureTableUsed;
	bool	legacyFallback;
	bool	drawPlanReady;
	bool	drawPlanOverflow;
	bool	submitPlanReady;
	bool	submitPlanOverflow;
	bool	visibleDepthRequested;
	bool	visibleDepthExecuted;
	bool	visibleDepthResourceReady;
	bool	visibleShadowResourceReady;
	bool	visibleDepthDebugOverlayReady;
	bool	opaqueGBufferRequested;
	bool	opaqueGBufferExecuted;
	bool	opaqueGBufferResourcesReady;
	bool	opaqueGBufferMRTReady;
	bool	opaqueGBufferDebugOverlayReady;
	bool	deferredResolveRequested;
	bool	deferredResolveExecuted;
	bool	deferredResolveResourcesReady;
	bool	deferredResolveOutputReady;
	bool	deferredResolveProgramReady;
	bool	deferredResolveClusterReady;
	bool	deferredResolveDebugOverlayReady;
	bool	forwardPlusRequested;
	bool	forwardPlusDecalOnlyRequested;
	bool	forwardPlusExecuted;
	bool	forwardPlusResourcesReady;
	bool	forwardPlusSceneColorReady;
	bool	forwardPlusSceneDepthReady;
	bool	forwardPlusProgramReady;
	bool	forwardPlusClusterReady;
	bool	shadowTextureUnitsReady;
	bool	shadowTextureBindingsReady;
	bool	shadowTextureProjectedAtlasReady;
	bool	shadowTexturePointAtlasReady;
	bool	shadowTextureProjectedMomentsReady;
	bool	shadowTexturePointMomentsReady;
	bool	modernVisibleRequested;
	bool	modernVisibleCanReplaceFrame;
	bool	modernVisibleHandoffReady;
	bool	modernVisibleExecuted;
	bool	modernVisibleResourcesReady;
	bool	modernVisibleProgramReady;
	bool	modernVisibleSourceReady;
	bool	modernVisibleBackBufferReady;
	bool	modernVisibleHybridTargetReady;
	bool	modernVisibleShadowReady;
	bool	modernVisibleHDRTargetReady;
	bool	modernVisibleSceneComposited;
	bool	modernVisiblePostProcessHandoff;
	bool	modernVisibleBlockedByLegacy;
	bool	modernVisibleCompatibilityReady;
	bool	modernVisibleGuiProgramReady;
	bool	modernVisibleGuiExecuted;
	bool	modernVisibleRenderDemoDeterministic;
	bool	modernVisibleCinematicTimingReady;
	bool	modernVisibleLightingReady;
	bool	modernVisibleLightGridReady;
	bool	modernVisibleShadowOwnershipReady;
	bool	pipelinePlanReady;
	bool	pipelineStableLayoutReady;
	bool	pipelineMinimumPassesReady;
	bool	pipelineGBufferNeeded;
	bool	pipelineDeferredNeeded;
	bool	pipelineForwardPlusNeeded;
	bool	pipelineCompositionSingleSource;
	bool	pipelineNoHotStateQueries;
	bool	pipelineValidationReadbacksOptIn;
	bool	pipelineGL33CpuBounded;
	bool	pipelineGL43GpuDrivenFit;
	bool	pipelineGL45LowOverheadFit;
	int		frameMode;
	int		pipelineDepthCommands;
	int		pipelineShadowDepthCommands;
	int		pipelineGBufferCommands;
	int		pipelineDeferredCommands;
	int		pipelineForwardPlusCommands;
	int		pipelineForwardPlusTransparentCommands;
	int		pipelineForwardPlusDecalCommands;
	int		pipelineGuiCommands;
	int		pipelineBatches;
	int		pipelineGeometryBatches;
	int		pipelineTextureSetBatches;
	int		pipelineScissorBatches;
	int		pipelineSkippedEmptyPasses;
	int		pipelineFramebufferAttachmentUpdates;
	int		pipelineFramebufferCacheHits;
	int		visibleDepthWouldExecute;
	int		visibleDepthSkippedBlocked;
	int		visibleDepthSkippedNoConsumer;
	int		visibleDepthDuplicatedWithLegacy;
	int		opaqueGBufferWouldExecute;
	int		opaqueGBufferSkippedBlocked;
	int		opaqueGBufferSkippedNoConsumer;
	int		opaqueGBufferDuplicatedWithLegacy;
	int		deferredResolveWouldExecute;
	int		deferredResolveSkippedBlocked;
	int		deferredResolveSkippedNoConsumer;
	int		deferredResolveDuplicatedWithLegacy;
	int		forwardPlusWouldExecute;
	int		forwardPlusSkippedBlocked;
	int		forwardPlusSkippedNoConsumer;
	int		forwardPlusDuplicatedWithLegacy;
	int		passOwnerTablePasses;
	int		passOwnerLegacyPasses;
	int		passOwnerModernPasses;
	int		passOwnerMixedPasses;
	int		passOwnerDisabledPasses;
	int		passOwnerBlockedPasses;
	int		passOwnerLegacySkipsArmed;
	int		passOwnerLegacySkipsIssued;
	int		passOwnerDuplicateHazards;
	int		passOwnerDroppedByModern;
	int		passOwnerFailClosedRestores;
	int		passOwnerShadowModernPasses;
	int		passOwnerShadowLegacyPasses;
	int		passOwnerGuiModernPasses;
	int		passOwnerPostLegacyPasses;
	int		graphPasses;
	int		preparedPasses;
	int		fallbackPasses;
	int		drawPackets;
	int		preparedDrawPackets;
	int		materialDrawPackets;
	int		resourceDrawPackets;
	int		geometryDrawPackets;
	int		guiDrawPackets;
	int		worldDrawPackets;
	int		shaderProgramCount;
	int		shaderFailureCount;
	int		highestGLSLVersion;
	int		gpuDrivenSceneRecords;
	int		gpuDrivenIndirectRecords;
	int		gpuDrivenDrawRecords;
	int		gpuDrivenSceneBytes;
	int		gpuDrivenIndirectBytes;
	int		gpuDrivenDrawRecordBytes;
	int		gpuDrivenDrawRecordIndexBytes;
	int		gpuDrivenBucketRecordBytes;
	int		gpuDrivenValidationBytes;
	int		uploadManagerFrameUBOBytes;
	int		uploadManagerGpuDrivenBytes;
	int		uploadManagerGpuDrivenBuffers;
	int		uploadManagerFallbackBytes;
	int		uploadManagerFallbackBuffers;
	int		gpuDrivenComputeDispatches;
	int		gpuDrivenSourceCommands;
	int		gpuDrivenEligibleCommands;
	int		gpuDrivenGeneratedCommands;
	int		gpuDrivenCulledCommands;
	int		gpuDrivenVisibleInstances;
	int		gpuDrivenCpuGeneratedCommands;
	int		gpuDrivenCpuCulledCommands;
	int		gpuDrivenCpuVisibleInstances;
	int		gpuDrivenGpuGeneratedCommands;
	int		gpuDrivenGpuCulledCommands;
	int		gpuDrivenGpuVisibleInstances;
	int		gpuDrivenValidationReadbacks;
	int		gpuDrivenValidationDeferredReadbacks;
	int		gpuDrivenValidationSkippedReadbacks;
	int		gpuDrivenValidationMismatches;
	int		gpuDrivenIndirectDrawCalls;
	int		gpuDrivenMultiDrawBatches;
	int		gpuDrivenIndirectBuckets;
	int		gpuDrivenIndirectBucketedCommands;
	int		gpuDrivenIndirectCompactedCommands;
	int		gpuDrivenHiZCandidates;
	int		gpuDrivenHiZRejected;
	int		gpuDrivenIndirectFallbacks;
	int		gpuDrivenInvalidBucketIds;
	int		gpuDrivenIndirectOverflow;
	int		gpuDrivenClusterBins;
	int		gpuDrivenCpuClusterBins;
	int		gpuDrivenGpuClusterBins;
	bool	visibilityRequested;
	bool	visibilityEnabled;
	bool	visibilityPortalPVSPreserved;
	bool	visibilityCpuCullingReady;
	bool	visibilityGpuCullingReady;
	bool	visibilityHiZRequested;
	bool	visibilityHiZResourceReady;
	bool	visibilityHiZBuilt;
	bool	visibilityTemporalCoherenceReady;
	bool	visibilityNoQueryStall;
	bool	visibilityShadowCasterReady;
	bool	visibilityScreenBoundsReady;
	int		visibilityScenes;
	int		visibilityPortalVisibleAreas;
	int		visibilityPortalRejectedAreas;
	int		visibilityCpuTested;
	int		visibilityCpuRejected;
	int		visibilityGpuTested;
	int		visibilityGpuRejected;
	int		visibilityScissorRejected;
	int		visibilityFrustumRejected;
	int		visibilityScreenRectRejected;
	int		visibilityScreenRectClipped;
	int		visibilityNearPlaneConservative;
	int		visibilityDynamicConservative;
	int		visibilityHiZCandidates;
	int		visibilityHiZRejected;
	int		visibilitySavedDraws;
	int		visibilitySavedTriangles;
	int		visibilityFalsePositiveFallbacks;
	int		visibilityTemporalReused;
	int		visibilityHiZLevels;
	int		visibilityHiZBuildMsec;
	int		visibilityShadowCasterTested;
	int		visibilityShadowCasterRejected;
	int		visibilityShadowCasterSavedDraws;
	int		visibilityShadowCasterSavedTriangles;
	int		lowOverheadDSAUpdates;
	int		lowOverheadFramebufferDSAUpdates;
	int		lowOverheadSamplerDSACreations;
	int		lowOverheadSamplerDSAUpdates;
	int		lowOverheadMultiBindBatches;
	int		lowOverheadTextureMultiBindBatches;
	int		lowOverheadSamplerMultiBindBatches;
	int		lowOverheadClassicTextureBinds;
	int		lowOverheadCompactedBatches;
	int		modernSoftRestores;
	int		modernFullRestores;
	int		materialTextureTableCapacity;
	int		materialTextureTableTextures;
	int		materialTextureTableDescriptors;
	int		materialTextureTableDraws;
	int		materialTextureTableUniforms;
	int		materialTextureTableFallbacks;
	int		vertexInputFormatSetups;
	int		vertexInputSourceBinds;
	int		vertexInputLegacyLayoutUpdates;
	int		vertexInputCacheHits;
	int		drawPlanDraws;
	int		drawPlanDepthDraws;
	int		drawPlanMaterialDraws;
	int		drawPlanFallbackDraws;
	int		drawPlanGeometryFallbackDraws;
	int		drawPlanGeometryDeformFallbackDraws;
	int		drawPlanGeometrySkinnedFallbackDraws;
	int		drawPlanIndexedDraws;
	int		drawPlanVertexOnlyDraws;
	int		drawPlanStateBatches;
	int		drawPlanProgramSwitches;
	int		drawPlanMaterialSwitches;
	int		submitPlanDraws;
	int		submitPlanFallbackDraws;
	int		submitPlanDepthDraws;
	int		submitPlanMaterialDraws;
	int		submitPlanMissingAmbientDraws;
	int		submitPlanMissingIndexDraws;
	int		submitPlanIndexUploadDraws;
	int		submitPlanProgramBatches;
	int		submitPlanVertexBufferBatches;
	int		submitPlanIndexBufferBatches;
	int		submitPlanScissorBatches;
	int		submitPlanMaterialBatches;
	int		submitPlanSortEligibleDraws;
	int		submitPlanSortLockedDraws;
	int		submitPlanSortSpans;
	int		submitPlanSortBuckets;
	int		submitPlanSortReorderedDraws;
	int		submitPlanUnsortedStateBuckets;
	int		submitPlanSortedStateBuckets;
	int		submitPlanSortStateBucketSavings;
	int		submitPlanSortProgramBatchSavings;
	int		submitPlanSortMaterialBatchSavings;
	int		submitPlanSortVertexBufferBatchSavings;
	int		submitPlanUniformUpdates;
	int		submitPlanFrameUBOBinds;
	bool	submitExecuted;
	int		submittedDraws;
	int		submittedDepthDraws;
	int		submittedMaterialDraws;
	int		submittedIndexUploadDraws;
	int		submittedFallbackDraws;
	int		visibleDepthDraws;
	int		visibleDepthFallbackDraws;
	int		visibleDepthAlphaTestDraws;
	int		visibleDepthSkinnedDraws;
	int		visibleShadowDepthDraws;
	int		visibleShadowFallbackDraws;
	int		visibleStencilShadowFallbackDraws;
	int		visibleDepthMaterialFallbackDraws;
	int		visibleDepthAlphaTestFallbackDraws;
	int		visibleDepthDeformFallbackDraws;
	int		visibleDepthSkinnedFallbackDraws;
	int		visibleDepthGeometryFallbackDraws;
	int		visibleDepthResourceFallbackDraws;
	int		visibleDepthMismatchDraws;
	int		visibleDepthClearOps;
	int		visibleDepthResolveOps;
	int		visibleDepthDebugOverlayDraws;
	int		opaqueGBufferDraws;
	int		opaqueGBufferFallbackDraws;
	int		opaqueGBufferMaterialFallbackDraws;
	int		opaqueGBufferAlphaTestDraws;
	int		opaqueGBufferAlphaTestFallbackDraws;
	int		opaqueGBufferSkinnedDraws;
	int		opaqueGBufferSkinnedFallbackDraws;
	int		opaqueGBufferDeformFallbackDraws;
	int		opaqueGBufferGeometryFallbackDraws;
	int		opaqueGBufferTextureFallbackDraws;
	int		opaqueGBufferResourceFallbackDraws;
	int		opaqueGBufferLightGridDraws;
	int		opaqueGBufferClearOps;
	int		opaqueGBufferDepthReuseOps;
	int		opaqueGBufferDepthClearOps;
	int		opaqueGBufferAttachmentCount;
	int		opaqueGBufferBytesPerPixel;
	int		opaqueGBufferBandwidthKB;
	int		opaqueGBufferDebugOverlayDraws;
	int		deferredResolvePixels;
	int		deferredResolveActiveLights;
	int		deferredResolvePointLights;
	int		deferredResolveProjectedLights;
	int		deferredResolveShadowMappedLights;
	int		deferredResolveShadowFallbackLights;
	int		deferredResolveShadowSkippedLights;
	int		deferredResolveShadowDescriptors;
	int		deferredResolveLightGridContributions;
	int		deferredResolveClusterReads;
	int		deferredResolveResourceFallbacks;
	int		deferredResolveUnsupportedLightFallbacks;
	int		deferredResolveFogFallbackLights;
	int		deferredResolveSpecialFallbackLights;
	int		deferredResolveOverflowClusters;
	int		deferredResolveClearOps;
	int		deferredResolveDebugMode;
	int		deferredResolveDebugOverlayDraws;
	int		forwardPlusDraws;
	int		forwardPlusOpaqueDraws;
	int		forwardPlusAlphaTestDraws;
	int		forwardPlusTransparentDraws;
	int		forwardPlusViewModelDraws;
	int		forwardPlusFogBlendDraws;
	int		forwardPlusSortedBatches;
	int		forwardPlusFallbackDraws;
	int		forwardPlusResourceFallbackDraws;
	int		forwardPlusMaterialFallbackDraws;
	int		forwardPlusGeometryFallbackDraws;
	int		forwardPlusTextureFallbackDraws;
	int		forwardPlusUnsupportedBlendFallbackDraws;
	int		forwardPlusSpecialEffectFallbacks;
	int		forwardPlusSortFallbackDraws;
	int		forwardPlusOverdrawEstimate;
	int		forwardPlusClusterReads;
	int		forwardPlusActiveLights;
	int		forwardPlusPointLights;
	int		forwardPlusProjectedLights;
	int		forwardPlusShadowMappedLights;
	int		forwardPlusShadowFallbackLights;
	int		forwardPlusShadowSkippedLights;
	int		forwardPlusShadowDescriptors;
	int		shadowTextureBaseUnit;
	int		shadowTextureBoundTextures;
	int		shadowTextureActualTextures;
	int		shadowTextureRequiredUnits;
	int		forwardPlusLightGridContributions;
	int		forwardPlusClearOps;
	int		modernVisibleCompositions;
	int		modernVisiblePixels;
	int		modernVisibleCompositeCopies;
	int		modernVisiblePostProcessCompositions;
	int		modernVisibleDepthCopies;
	int		modernVisibleModernPasses;
	int		modernVisibleLegacyPasses;
	int		modernVisibleDisabledPasses;
	int		modernVisibleFallbackPasses;
	int		modernVisibleOwnerFallbacks;
	int		modernVisibleResourceFallbacks;
	int		modernVisibleMaterialFallbackDraws;
	int		modernVisibleGeometryFallbackDraws;
	int		modernVisibleLightingFallbackPasses;
	int		modernVisibleLightGridFallbackPasses;
	int		modernVisibleShadowOwnershipFallbackPasses;
	int		modernVisibleDroppedByModern;
	int		modernVisibleGuiLegacyPasses;
	int		modernVisiblePostLegacyPasses;
	int		modernVisibleSpecialLegacyPasses;
	int		modernVisibleSubviewLegacyPasses;
	int		modernVisiblePresentPasses;
	int		modernVisibleClearOps;
	int		modernVisibleCompatibilityPasses;
	int		modernVisibleCompatibilityModernPasses;
	int		modernVisibleCompatibilityLegacyPasses;
	int		modernVisibleLightGridModernPasses;
	int		modernVisibleShadowMappedLights;
	int		modernVisibleShadowFallbackLights;
	int		modernVisibleShadowSkippedLights;
	int		modernVisibleShadowDescriptors;
	// per-light gating (5c): lights that would visibly lose shadows in a
	// modern-composed frame, and the consumable counts backing the verdict
	int		modernVisibleShadowBlockedLights;
	int		modernVisibleShadowConsumableLights;
	int		modernVisibleShadowPointConstraintLights;
	int		modernVisibleGuiModernPasses;
	int		modernVisibleGuiDraws;
	int		modernVisibleGuiReadyDraws;
	int		modernVisibleGuiFallbackDraws;
	int		modernVisiblePostGraphPasses;
	int		modernVisiblePostFallbackPasses;
	int		modernVisibleSubviewGraphPasses;
	int		modernVisibleSubviewFallbackPasses;
	int		modernVisibleRemoteCameraFallbackPasses;
	int		modernVisibleRenderDemoFallbackPasses;
	int		modernVisibleBSEFallbackPasses;
	int		modernVisibleBSEParticleFallbacks;
	int		modernVisibleBSETrailFallbacks;
	int		modernVisibleBSEBeamFallbacks;
	int		modernVisibleBSEDecalFallbacks;
	int		modernVisibleBSEMaterialFallbacks;
	int		modernVisibleCopyRenderFallbackPasses;
	int		modernVisibleCinematicCompatibilityPasses;
	char	modernVisibleOwnershipBlocker[160];
	char	status[96];
} modernGLExecutorStats_t;

void R_ModernGLExecutor_Init( const renderBackendCaps_t &caps, const renderFeatureSet_t &features );
void R_ModernGLExecutor_Shutdown( void );
void R_ModernGLExecutor_SkipFrame( void );
void R_ModernGLExecutor_InvalidatePlans( void );
void R_ModernGLExecutor_PrepareFrame( const idScenePacketFrame &packetFrame, const idRenderGraph &graph );
void R_ModernGLExecutor_DrawDepthDebugOverlay( void );
void R_ModernGLExecutor_DrawGBufferDebugOverlay( void );
void R_ModernGLExecutor_DrawDeferredDebugOverlay( void );
void R_ModernGLExecutor_SubmitForwardPlusDecalOverlay( const viewDef_t *viewDef );
void R_ModernGLExecutor_ComposeVisibleSceneForPost( void );
void R_ModernGLExecutor_ComposeVisibleFrame( void );
const modernGLExecutorStats_t &R_ModernGLExecutor_Stats( void );
bool R_ModernGLExecutor_ModernVisibleRequestedForPost( void );
bool R_ModernGLExecutor_ModernVisiblePostProcessHandoffActive( void );
bool R_ModernGLExecutor_LegacyPassCanSkip( renderPassCategory_t category );
bool R_ModernGLExecutor_LegacyPassCanSkipForView( renderPassCategory_t category, const viewDef_t *viewDef );
void R_ModernGLExecutor_RecordLegacyPassSkipped( renderPassCategory_t category );
void R_ModernGLExecutor_PrintGfxInfo( void );
bool RendererModernGLExecutor_RunSelfTest( void );
bool RendererGpuDriven_RunSelfTest( void );
bool RendererVisiblePath_RunSelfTest( void );
bool RendererGBuffer_RunSelfTest( void );
bool RendererDeferredResolve_RunSelfTest( void );
bool RendererForwardPlus_RunSelfTest( void );
bool RendererModernVisible_RunSelfTest( void );
bool RendererLowOverhead_RunSelfTest( void );
bool RendererModernCompatibility_RunSelfTest( void );
bool RendererPassOwnership_RunSelfTest( void );
bool RendererModernVisibility_RunSelfTest( void );

#endif /* !__MODERN_GL_EXECUTOR_H__ */
