internal void SetVBs(Buffer[] vbs, int[] strides) { if (vbs != null && strides != null) { bool change = false; bool lastSlot = false; for (int i = 0; i < vbs.Length; i++) { if (vbs[i] != null) { lastSlot = change == false && i == (vbs.Length - 1); change = UpdateVB(i, vbs[i], strides[i]) || change; } } if (lastSlot) { int slot = vbs.Length - 1; DeviceContext.InputAssembler.SetVertexBuffers(slot, new VertexBufferBinding(State.m_VBs[slot], State.m_strides[slot], 0)); Stats.SetVB++; } else if (change) { DeviceContext.InputAssembler.SetVertexBuffers(0, State.m_VBs, State.m_strides, ZeroOffsets); Stats.SetVB++; } MyRender11.ProcessDebugOutput(); } }
internal void PSBindRawSRV(int slot, IShaderResourceBindable srv) { DeviceContext.PixelShader.SetShaderResources(0, srv.SRV); Stats.BindShaderResources++; MyRender11.ProcessDebugOutput(); }
internal void Join() { Debug.Assert(!m_joined); m_joined = true; MyRender11.GatherStats(Stats); }
internal void BindUAV(int slot, MyBindableResource UAV, int initialCount = -1) { if (UAV != null) { var ua = UAV as IUnorderedAccessBindable; Debug.Assert(ua != null); UnbindSRVRead(UAV.GetID()); //UnbindDSVReadOnly(UAVs[i].ResId); necessary? List <int> keyList = State.m_slotToBindingKeys.GetList(slot); if (keyList != null) { keyList.Sort(KeyListComparer.Comparer); State.m_bindings.Remove(keyList[0]); State.m_slotToBindingKeys.Remove(slot); } var binding = new MyBinding(MyWriteBindingEnum.UAV, slot); State.m_bindings[UAV.GetID()] = binding; State.m_slotToBindingKeys.Add(slot, UAV.GetID()); ComputeShaderId.TmpUav[0] = ua.UAV; } ComputeShaderId.TmpCount[0] = initialCount; DeviceContext.ComputeShader.SetUnorderedAccessViews(slot, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount); ComputeShaderId.TmpCount[0] = -1; MyRender11.ProcessDebugOutput(); }
public void Run() { MyRender11.GetRenderProfiler().StartProfilingBlock("DoRenderWork"); foreach (var subwork in m_subworks) { subwork.Pass.Begin(); for (int i = subwork.Begin; i < subwork.End; i++) { subwork.Pass.FeedProfiler(subwork.Renderables[i].SortKey); subwork.Pass.RecordCommands(subwork.Renderables[i].RenderProxy); } if (subwork.List2 != null) { for (int i = 0; i < subwork.List2.Length; i++) { subwork.Pass.RecordCommands(ref subwork.List2[i]); } } subwork.Pass.End(); } if (m_isDeferred && m_subworks.Count > 0) { m_subworks[0].Pass.RC.Finish(); } MyRender11.GetRenderProfiler().EndProfilingBlock(); }
internal static void DispatchFrustumCulling() { //MyPerformanceCounter.PerCameraDraw11Write.RenderableObjectsNum = MyRenderablesBoundingTree.m_tree.CountLeaves(MyRenderablesBoundingTree.m_tree.GetRoot()); MyRender11.GetRenderProfiler().StartProfilingBlock("CreateTasksAndWait"); List <Task> tasks = new List <Task>(); for (int i = 1; i < m_cullQuery.Size; i++) { m_cullQuery.FrustumQueries[i].List.Clear(); m_cullQuery.FrustumQueries[i].IsInsideList.Clear(); tasks.Add(Parallel.Start(new MyCullingWork(m_cullQuery.FrustumQueries[i]))); } if (m_cullQuery.Size > 0) { m_cullQuery.FrustumQueries[0].List.Clear(); m_cullQuery.FrustumQueries[0].IsInsideList.Clear(); new MyCullingWork(m_cullQuery.FrustumQueries[0]).DoWork(); } foreach (var task in tasks) { task.Wait(); } MyRender11.GetRenderProfiler().EndProfilingBlock(); }
internal void PSBindRawSRV(int slot, ShaderResourceView[] srvs) { DeviceContext.PixelShader.SetShaderResources(0, srvs); Stats.BindShaderResources++; MyRender11.ProcessDebugOutput(); }
internal void CSBindRawSRV(int slot, ShaderResourceView srv) { DeviceContext.ComputeShader.SetShaderResource(slot, srv); Stats.BindShaderResources++; MyRender11.ProcessDebugOutput(); }
public void DoWork() { MyRender11.GetRenderProfiler().StartProfilingBlock("DoCullWork"); var frustum = m_query.Frustum; if (m_query.SmallObjects.HasValue) { if (!MyRender11.Settings.DrawOnlyMergedMeshes) { MyScene.RenderablesDBVH.OverlapAllFrustum <MyCullProxy>(ref frustum, m_query.List, m_query.IsInsideList, m_query.SmallObjects.Value.ProjectionDir, m_query.SmallObjects.Value.ProjectionFactor, m_query.SmallObjects.Value.SkipThreshhold, 0); } MyScene.GroupsDBVH.OverlapAllFrustum <MyCullProxy_2>(ref frustum, m_query.List2, m_query.IsInsideList2, m_query.SmallObjects.Value.ProjectionDir, m_query.SmallObjects.Value.ProjectionFactor, m_query.SmallObjects.Value.SkipThreshhold, 0); } else { if (!MyRender11.Settings.DrawOnlyMergedMeshes) { MyScene.RenderablesDBVH.OverlapAllFrustum <MyCullProxy>(ref frustum, m_query.List, m_query.IsInsideList, 0); } MyScene.GroupsDBVH.OverlapAllFrustum <MyCullProxy_2>(ref frustum, m_query.List2, m_query.IsInsideList2, 0); } MyRender11.GetRenderProfiler().EndProfilingBlock(); }
internal static void UpdateRenderSettings(MyRenderSettings1 settings) { MyRender11.Log.WriteLine("UpdateRenderSettings"); MyRender11.Log.IncreaseIndent(); var prevSettings = m_renderSettings; m_renderSettings = settings; LogUpdateRenderSettings(ref settings); MyRenderProxy.Settings.EnableCameraInterpolation = settings.InterpolationEnabled; MyRenderProxy.Settings.EnableObjectInterpolation = settings.InterpolationEnabled; MyRenderProxy.Settings.GrassDensityFactor = settings.GrassDensityFactor; // if(settings.GrassDensityFactor != prevSettings.GrassDensityFactor) // MyRenderProxy.ReloadGrass(); if (settings.ShadowQuality != prevSettings.ShadowQuality) { MyShadows.ResizeCascades(); } if (settings.AntialiasingMode != prevSettings.AntialiasingMode) { GlobalShaderHeader = MyShaderHelpers.FormatMacros(MyRender11.ShaderMultisamplingDefine(), MyRender11.FxaaEnabled ? "FXAA_ENABLED" : null); MyShaders.Recompile(); MyMaterialShaders.Recompile(); MyRenderableComponent.MarkAllDirty(); if (settings.AntialiasingMode.SamplesCount() != prevSettings.AntialiasingMode.SamplesCount()) { CreateScreenResources(); } } if (settings.AnisotropicFiltering != prevSettings.AnisotropicFiltering) { UpdateTextureSampler(m_textureSamplerState, TextureAddressMode.Wrap); UpdateTextureSampler(m_alphamaskarraySamplerState, TextureAddressMode.Clamp); } if (settings.TextureQuality != prevSettings.TextureQuality) { //MyTextureManager.UnloadTextures(); MyVoxelMaterials1.InvalidateMaterials(); MyMeshMaterials1.InvalidateMaterials(); MyTextures.ReloadQualityDependantTextures(); //MyVoxelMaterials.ReloadTextures(); //MyMaterialProxyFactory.ReloadTextures(); } m_settingsChangedListeners(); MyRender11.Log.DecreaseIndent(); }
internal void Join() { Debug.Assert(!m_joined); m_joined = true; int passHash = ((int)FrustumType) << 10 | FrustumIndex; MyRender11.GatherPassStats(passHash, DebugName, Stats); }
private static void Render(ISrvBindable textureArraySRV, ISrvBindable depthRead) { RC.VertexShader.Set(m_vs); if (MyRender11.Settings.DisplayTransparencyHeatMap) { if (MyRender11.DebugOverrides.OIT) { RC.PixelShader.Set(m_psDebugUniformAccumOIT); } else { RC.PixelShader.Set(m_psDebugUniformAccum); } } else { if (MyRender11.DebugOverrides.OIT) { RC.PixelShader.Set(m_psOIT); } else { RC.PixelShader.Set(m_ps); } } RC.SetVertexBuffer(0, null); RC.SetIndexBuffer(m_ib); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.AllShaderStages.SetConstantBuffer(1, m_activeListConstantBuffer); RC.AllShaderStages.SetSrv(0, depthRead); RC.PixelShader.SetSrvs(1, textureArraySRV); RC.VertexShader.SetSrv(0, m_particleBuffer); RC.VertexShader.SetSrv(1, m_emitterStructuredBuffer); RC.VertexShader.SetSrv(2, m_aliveIndexBuffer); ISrvBindable skybox = MyRender11.IsIntelBrokenCubemapsWorkaround ? MyGeneratedTextureManager.IntelFallbackCubeTex : (ISrvBindable)MyManagers.EnvironmentProbe.Cubemap; RC.VertexShader.SetSrv(MyCommon.SKYBOX_IBL_SLOT, skybox); // bind render target? if (!MyStereoRender.Enable) { RC.DrawIndexedInstancedIndirect(m_indirectDrawArgsBuffer, 0); } else { MyStereoRender.DrawIndexedInstancedIndirectGPUParticles(RC, m_indirectDrawArgsBuffer, 0); } MyRender11.ProcessDebugOutput(); RC.VertexShader.SetSrv(MyCommon.SKYBOX_IBL_SLOT, null); RC.AllShaderStages.SetSrv(0, null); }
internal void SetVB(int slot, Buffer vb, int stride) { if (UpdateVB(slot, vb, stride)) { DeviceContext.InputAssembler.SetVertexBuffers(slot, new VertexBufferBinding(vb, stride, 0)); Stats.SetVB++; MyRender11.ProcessDebugOutput(); } }
internal void Finish() { if (!m_finished && m_deferred) { m_finished = true; m_commandList = DeviceContext.FinishCommandList(false); MyRender11.ProcessDebugOutput(); } }
internal void PSBindRawSRV(int slot, IShaderResourceBindable srv) { ShaderResourceView sharpSRV = srv != null ? srv.SRV : null; DeviceContext.PixelShader.SetShaderResources(slot, sharpSRV); Stats.BindShaderResources++; MyRender11.ProcessDebugOutput(); }
internal void BindRawSRV(int slot, ShaderResourceView srv) { DeviceContext.VertexShader.SetShaderResource(slot, srv); DeviceContext.PixelShader.SetShaderResource(slot, srv); Stats.BindShaderResources++; Stats.BindShaderResources++; MyRender11.ProcessDebugOutput(); }
internal void SetPS(PixelShader ps) { if (State.m_ps != ps) { State.m_ps = ps; DeviceContext.PixelShader.Set(ps); Stats.SetPS++; MyRender11.ProcessDebugOutput(); } }
/// <param name="handleWindow">Handle function for window billboards: decides if /// keeping it in separate storage list</param> /// <returns>True if the transparent geometry bindings must be reset</returns> public static bool Gather() { m_stats.Clear(); MyRender11.GetRenderProfiler().StartProfilingBlock("Gather"); bool resetBindings = GatherInternal(); MyRender11.GetRenderProfiler().EndProfilingBlock(); return(resetBindings); }
internal void SetDS(DepthStencilState ds, int stencilRef = 0) { if ((State.m_DS != ds) || (State.m_stencilRef != stencilRef)) { State.m_DS = ds; State.m_stencilRef = stencilRef; DeviceContext.OutputMerger.SetDepthStencilState(ds, stencilRef); MyRender11.ProcessDebugOutput(); } }
// inscatter texture // transmittance texture //static RwTexId m_transmittanceLut; //static RwTexId m_inscatterLutR; //static RwTexId m_inscatterLutM; internal static void Init() { m_ps = MyShaders.CreatePs("atmosphere.hlsl"); m_psPerSample = MyShaders.CreatePs("atmosphere.hlsl", MyRender11.ShaderSampleFrequencyDefine()); m_precomputeDensity = MyShaders.CreateCs("AtmospherePrecompute.hlsl"); m_proxyVs = MyShaders.CreateVs("atmosphere.hlsl"); m_proxyIL = MyShaders.CreateIL(m_proxyVs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION_PACKED)); }
internal void SetIB(Buffer ib, Format format) { if (State.m_IB != ib) { State.m_IB = ib; DeviceContext.InputAssembler.SetIndexBuffer(ib, format, 0); Stats.SetIB++; MyRender11.ProcessDebugOutput(); } }
internal void SetBS(BlendState bs, Color4?blendFactor = null) { if (State.m_BS != bs || blendFactor != null) { State.m_BS = bs; DeviceContext.OutputMerger.SetBlendState(bs, blendFactor); Stats.SetBlendState++; MyRender11.ProcessDebugOutput(); } }
internal void SetRS(RasterizerState rs) { if (State.m_RS != rs) { State.m_RS = rs; DeviceContext.Rasterizer.State = rs; Stats.SetRasterizerState++; MyRender11.ProcessDebugOutput(); } }
internal void SetIL(InputLayout il) { if (State.m_inputLayout != il) { State.m_inputLayout = il; DeviceContext.InputAssembler.InputLayout = il; Stats.SetIL++; MyRender11.ProcessDebugOutput(); } }
internal void SetGS(GeometryShader gs) { if (State.m_gs != gs) { State.m_gs = gs; DeviceContext.GeometryShader.Set(gs); Stats.SetGS++; MyRender11.ProcessDebugOutput(); } }
internal void SetVS(VertexShader vs) { if (State.m_vs != vs) { State.m_vs = vs; DeviceContext.VertexShader.Set(vs); Stats.SetVS++; MyRender11.ProcessDebugOutput(); } }
internal static void AddMaterialShaderFlagMacros(StringBuilder sb, MyShaderUnifiedFlags flags) { if ((flags & MyShaderUnifiedFlags.DEPTH_ONLY) > 0) { sb.AppendLine("#define DEPTH_ONLY"); } if ((flags & MyShaderUnifiedFlags.ALPHAMASK) > 0) { sb.AppendLine("#define ALPHA_MASKED"); } if ((flags & MyShaderUnifiedFlags.ALPHAMASK_ARRAY) > 0) { sb.AppendLine("#define ALPHA_MASK_ARRAY"); } if ((flags & MyShaderUnifiedFlags.TRANSPARENT) > 0) { sb.AppendLine("#define TRANSPARENT"); } if ((flags & MyShaderUnifiedFlags.DITHERED) > 0) { sb.AppendLine("#define DITHERED"); } if ((flags & MyShaderUnifiedFlags.FOLIAGE) > 0) { sb.AppendLine("#define FOLIAGE"); } if ((flags & MyShaderUnifiedFlags.USE_SKINNING) > 0) { sb.AppendLine("#define USE_SKINNING"); } if ((flags & MyShaderUnifiedFlags.USE_CUBE_INSTANCING) > 0) { sb.AppendLine("#define USE_CUBE_INSTANCING"); } if ((flags & MyShaderUnifiedFlags.USE_DEFORMED_CUBE_INSTANCING) > 0) { sb.AppendLine("#define USE_DEFORMED_CUBE_INSTANCING"); } if ((flags & MyShaderUnifiedFlags.USE_GENERIC_INSTANCING) > 0) { sb.AppendLine("#define USE_GENERIC_INSTANCING"); } if ((flags & MyShaderUnifiedFlags.USE_MERGE_INSTANCING) > 0) { sb.AppendLine("#define USE_MERGE_INSTANCING"); } if ((flags & MyShaderUnifiedFlags.USE_VOXEL_MORPHING) > 0) { sb.AppendLine("#define USE_VOXEL_MORPHING"); } if ((flags & MyShaderUnifiedFlags.USE_SHADOW_CASCADES) == MyShaderUnifiedFlags.USE_SHADOW_CASCADES) { sb.AppendLine(MyRender11.ShaderCascadesNumberHeader()); } }
private static void Render(ISrvBindable depthRead, MyBucketBatches bucketBatches, bool oit) { if (!MyRender11.DebugOverrides.BillboardsDynamic && !MyRender11.DebugOverrides.BillboardsStatic) { return; } if (m_batches.Count == 0) { return; } MyRender11.GetRenderProfiler().StartProfilingBlock("Draw"); RC.PixelShader.SetSrv(1, depthRead); BindResourcesCommon(); PixelShaderFlags basePsFlags = (MyRender11.Settings.DisplayTransparencyHeatMap ? PixelShaderFlags.DEBUG_UNIFORM_ACCUM : 0) | ((MyRender11.DebugOverrides.OIT && oit) ? PixelShaderFlags.OIT : 0) | (depthRead != null ? PixelShaderFlags.SOFT_PARTICLE : 0); for (int i = bucketBatches.StartIndex; i < bucketBatches.StartIndex + bucketBatches.Count; i++) { var ps = m_psBundle[(int)(basePsFlags | (m_batches[i].Lit ? PixelShaderFlags.LIT_PARTICLE : 0) | (m_batches[i].AlphaCutout ? PixelShaderFlags.ALPHA_CUTOUT : 0))]; RC.VertexShader.Set(m_batches[i].Lit ? m_vsLit : m_vs); RC.PixelShader.Set(ps); ISrvBindable texture = m_batches[i].Texture; RC.PixelShader.SetSrv(0, texture); if (!MyStereoRender.Enable) { RC.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } else { MyStereoRender.DrawIndexedBillboards(RC, m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } IBorrowedRtvTexture borrowedTexture = texture as IBorrowedRtvTexture; if (borrowedTexture != null) { borrowedTexture.Release(); } MyStatsUpdater.Passes.DrawBillboards++; } m_stats.Billboards += m_billboardCountSafe; RC.SetRasterizerState(null); MyRender11.GatherPassStats(1298737, "Billboards", m_stats); MyRender11.GetRenderProfiler().EndProfilingBlock(); }
internal void SetSRVs(ref MySrvTable desc) { //if (desc.BindFlag.HasFlag(MyBindFlag.BIND_VS)) //{ // var val = new MyStageSrvBinding { Stage = MyShaderStage.VS, Slot = desc.StartSlot, Length = desc.SRVs.Length, Version = desc.Version }; // int f = State.m_srvBindings1.BinarySearch(val); // var index = ~f; // bool match = f >= 0; // if yes no need to bind // bool collision = (index < State.m_srvBindings1.Count) && // State.m_srvBindings1[index].Stage == val.Stage && // (val.Slot + val.Length) >= State.m_srvBindings1[index].Slot; // if yes replace, if no add before, bind anyway // if(!match && collision) // { // State.m_srvBindings1[index] = val; // Context.VertexShader.SetShaderResources(desc.StartSlot, desc.SRVs); // } // else if(!match && !collision) // { // State.m_srvBindings1.Insert(index, val); // Context.VertexShader.SetShaderResources(desc.StartSlot, desc.SRVs); // } //} if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0 && State.m_srvTableBindings.Get(new MyStageSrvBinding { Stage = MyShaderStage.VS, Slot = desc.StartSlot }, NO_VERSION) != desc.Version) { State.m_srvTableBindings[new MyStageSrvBinding { Stage = MyShaderStage.VS, Slot = desc.StartSlot }] = desc.Version; for (int i = 0; i < desc.SRVs.Length; i++) { DeviceContext.VertexShader.SetShaderResource(desc.StartSlot + i, desc.SRVs[i].SRV); } } if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0 && State.m_srvTableBindings.Get(new MyStageSrvBinding { Stage = MyShaderStage.PS, Slot = desc.StartSlot }, NO_VERSION) != desc.Version) { State.m_srvTableBindings[new MyStageSrvBinding { Stage = MyShaderStage.PS, Slot = desc.StartSlot }] = desc.Version; for (int i = 0; i < desc.SRVs.Length; i++) { DeviceContext.PixelShader.SetShaderResource(desc.StartSlot + i, desc.SRVs[i].SRV); } } MyRender11.ProcessDebugOutput(); }
internal void Join() { Debug.Assert(!m_joined && m_deferred); m_joined = true; Finish(); MyRender11.GatherStats(Stats); MyGpuProfiler.Join(ProfilingQueries); }