public void OnAcceleratedPaint(CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr sharedHandle) { try { if (sharedHandle == IntPtr.Zero) { return; } var d3dDevice = SharpDXInterop.GetNativeDevice(GraphicsDevice) as Device; if (d3dDevice is null) { return; } var d3dTexture = d3dDevice.OpenSharedResource <Texture2D>(sharedHandle); if (d3dTexture is null) { return; } var strideTexture = SharpDXInterop.CreateTextureFromNative(GraphicsDevice, d3dTexture, takeOwnership: true); lock (syncRoot) { surface?.Dispose(); surface = strideTexture; } needsConversion = true; } catch (Exception e) { RuntimeGraph.ReportException(e); } }
EffectInstance IEffect.SetParameters(RenderView renderView, RenderDrawContext renderDrawContext) { try { // TODO1: PerFrame could be done in Update if we'd have access to frame time // TODO2: This code can be optimized by using parameter accessors and not parameter keys parameters.SetPerFrameParameters(perFrameParams, renderDrawContext.RenderContext); parameters.SetPerViewParameters(perViewParams, renderView); if (worldPin != null) { var world = worldPin.ShaderValue; parameters.SetPerDrawParameters(perDrawParams, renderView, ref world); } customParameterSetterPin?.Value?.Invoke(parameters, renderView, renderDrawContext); } catch (Exception e) { var re = new RuntimeException(e.InnermostException(), this); RuntimeGraph.ReportException(re); } return(instance); }
public override void Draw(RenderDrawContext context, RenderView renderView, RenderViewStage renderViewStage, int startIndex, int endIndex) { // Do not call into VL if not running var renderContext = context.RenderContext; var runtime = this.runtime ?? (this.runtime = renderContext.Services.GetService <IVLRuntime>()); if (runtime != null && !runtime.IsRunning) { return; } // Build the list of layers to render singleCallLayers.Clear(); layers.Clear(); for (var index = startIndex; index < endIndex; index++) { var renderNodeReference = renderViewStage.SortedRenderNodes[index].RenderNode; var renderNode = GetRenderNode(renderNodeReference); var renderElement = (RenderLayer)renderNode.RenderObject; if (renderElement.Enabled) { if (renderElement.SingleCallPerFrame) { singleCallLayers.Add(renderElement.Layer); } else { layers.Add(renderElement.Layer); } } } // Call layers which want to get invoked only once per frame first var currentFrameNr = renderContext.Time.FrameCount; if (lastFrameNr != currentFrameNr) { lastFrameNr = currentFrameNr; foreach (var layer in singleCallLayers) { try { layer?.Draw(Context, context, renderView, renderViewStage, context.CommandList); } catch (Exception e) { RuntimeGraph.ReportException(e); } } } // Call layers which can get invoked twice per frame (for each eye) foreach (var layer in layers) { try { layer?.Draw(Context, context, renderView, renderViewStage, context.CommandList); } catch (Exception e) { RuntimeGraph.ReportException(e); } } }
void ILowLevelAPIRender.Draw(RenderContext renderContext, RenderDrawContext drawContext, RenderView renderView, RenderViewStage renderViewStage, CommandList commandList) { if (!enabledPin.Value) { return; } try { var pipelineState = this.pipelineState ?? (this.pipelineState = new MutablePipelineState(renderContext.GraphicsDevice)); // TODO1: PerFrame could be done in Update if we'd have access to frame time // TODO2: This code can be optimized by using parameter accessors and not parameter keys parameters.SetPerFrameParameters(perFrameParams, drawContext.RenderContext); parameters.SetPerViewParameters(perViewParams, renderView); if (worldPin != null) { var world = worldPin.ShaderValue; parameters.SetPerDrawParameters(perDrawParams, renderView, ref world); } // Set permutation parameters before updating the effect (needed by compiler) parameters.Set(ComputeEffectShaderKeys.ThreadNumbers, threadNumbersPin.Value); // Give user chance to override parameterSetterPin?.Value.Invoke(parameters, renderView, drawContext); if (instance.UpdateEffect(renderContext.GraphicsDevice) || pipelineStateDirty) { threadGroupCountAccessor = parameters.GetAccessor(ComputeShaderBaseKeys.ThreadGroupCountGlobal); foreach (var p in Inputs.OfType <ParameterPin>()) { p.Update(parameters); } pipelineState.State.SetDefaults(); pipelineState.State.RootSignature = instance.RootSignature; pipelineState.State.EffectBytecode = instance.Effect.Bytecode; pipelineState.Update(); pipelineStateDirty = false; } // Apply pipeline state commandList.SetPipelineState(pipelineState.CurrentState); // Set thread group count as provided by input pin var threadGroupCount = dispatchCountPin.Value; parameters.Set(ComputeShaderBaseKeys.ThreadGroupCountGlobal, threadGroupCount); // TODO: This can be optimized by uploading only parameters from the PerDispatch groups - look in Xenkos RootEffectRenderFeature var iterationCount = Math.Max(iterationCountPin.Value, 1); for (int i = 0; i < iterationCount; i++) { // Give user chance to override iterationParameterSetterPin.Value?.Invoke(parameters, renderView, drawContext, i); // The thread group count can be set for each dispatch threadGroupCount = parameters.Get(threadGroupCountAccessor); // Upload the parameters instance.Apply(drawContext.GraphicsContext); // Draw a full screen quad commandList.Dispatch(threadGroupCount.X, threadGroupCount.Y, threadGroupCount.Z); } } catch (Exception e) { var re = new RuntimeException(e.InnermostException(), this); RuntimeGraph.ReportException(re); } }