/// <summary> /// Creates a new instance of the shader specialization state. /// </summary> /// <param name="state">Current 3D engine state</param> /// <param name="pipelineState">Current program pipeline state</param> /// <param name="descriptors">Optional transform feedback buffers in use, if any</param> public ShaderSpecializationState( ref GpuChannelGraphicsState state, ProgramPipelineState?pipelineState, TransformFeedbackDescriptor[] descriptors) : this(ref state, descriptors) { PipelineState = pipelineState; }
/// <summary> /// Creates a new instance of the shader specialization state. /// </summary> /// <param name="state">Current 3D engine state</param> /// <param name="descriptors">Optional transform feedback buffers in use, if any</param> public ShaderSpecializationState(GpuChannelGraphicsState state, TransformFeedbackDescriptor[] descriptors) : this() { GraphicsState = state; _compute = false; if (descriptors != null) { TransformFeedbackDescriptors = descriptors; _queriedState |= QueriedStateFlags.TransformFeedback; } }
/// <summary> /// Tries to find an existing 3D program on the cache. /// </summary> /// <param name="channel">GPU channel</param> /// <param name="poolState">Texture pool state</param> /// <param name="graphicsState">Graphics state</param> /// <param name="program">Cached program, if found</param> /// <returns>True if a compatible program is found, false otherwise</returns> public bool TryFindForGraphics( GpuChannel channel, GpuChannelPoolState poolState, GpuChannelGraphicsState graphicsState, out CachedShaderProgram program) { foreach (var entry in _entries) { if (entry.SpecializationState.MatchesGraphics(channel, poolState, graphicsState, true)) { program = entry; return(true); } } program = default; return(false); }
/// <summary> /// Checks if the recorded state matches the current GPU 3D engine state. /// </summary> /// <param name="channel">GPU channel</param> /// <param name="poolState">Texture pool state</param> /// <param name="graphicsState">Graphics state</param> /// <param name="checkTextures">Indicates whether texture descriptors should be checked</param> /// <returns>True if the state matches, false otherwise</returns> public bool MatchesGraphics(GpuChannel channel, GpuChannelPoolState poolState, GpuChannelGraphicsState graphicsState, bool checkTextures) { if (graphicsState.ViewportTransformDisable != GraphicsState.ViewportTransformDisable) { return(false); } bool thisA2cDitherEnable = GraphicsState.AlphaToCoverageEnable && GraphicsState.AlphaToCoverageDitherEnable; bool otherA2cDitherEnable = graphicsState.AlphaToCoverageEnable && graphicsState.AlphaToCoverageDitherEnable; if (otherA2cDitherEnable != thisA2cDitherEnable) { return(false); } return(Matches(channel, poolState, checkTextures, isCompute: false)); }
/// <summary> /// Checks if the recorded state matches the current GPU 3D engine state. /// </summary> /// <param name="channel">GPU channel</param> /// <param name="poolState">Texture pool state</param> /// <param name="graphicsState">Graphics state</param> /// <param name="checkTextures">Indicates whether texture descriptors should be checked</param> /// <returns>True if the state matches, false otherwise</returns> public bool MatchesGraphics(GpuChannel channel, GpuChannelPoolState poolState, GpuChannelGraphicsState graphicsState, bool checkTextures) { if (graphicsState.ViewportTransformDisable != GraphicsState.ViewportTransformDisable) { return(false); } bool thisA2cDitherEnable = GraphicsState.AlphaToCoverageEnable && GraphicsState.AlphaToCoverageDitherEnable; bool otherA2cDitherEnable = graphicsState.AlphaToCoverageEnable && graphicsState.AlphaToCoverageDitherEnable; if (otherA2cDitherEnable != thisA2cDitherEnable) { return(false); } if (graphicsState.DepthMode != GraphicsState.DepthMode) { return(false); } if (graphicsState.AlphaTestEnable != GraphicsState.AlphaTestEnable) { return(false); } if (graphicsState.AlphaTestEnable && (graphicsState.AlphaTestCompare != GraphicsState.AlphaTestCompare || graphicsState.AlphaTestReference != GraphicsState.AlphaTestReference)) { return(false); } if (!graphicsState.AttributeTypes.AsSpan().SequenceEqual(GraphicsState.AttributeTypes.AsSpan())) { return(false); } return(Matches(channel, poolState, checkTextures, isCompute: false)); }