Пример #1
0
    public void Scatter(DeviceContext context, ImageBasedLightingEnvironment lightingEnvironment, ShaderResourceView controlVertexInfosView)
    {
        context.WithEvent("Scatterer::Scatter", () => {
            context.ClearState();

            context.ComputeShader.Set(samplingShader);
            lightingEnvironment.Apply(context.ComputeShader);
            context.ComputeShader.SetShaderResources(ShaderSlots.MaterialTextureStart,
                                                     stencilSegments,
                                                     stencilElems,
                                                     controlVertexInfosView);
            context.ComputeShader.SetUnorderedAccessView(0, sampledIrrandiancesBufferManager.OutView);
            context.Dispatch(IntegerUtils.RoundUp(vertexCount, ShaderNumThreads), 1, 1);

            context.ClearState();

            context.ComputeShader.Set(scatteringShader);
            context.ComputeShader.SetShaderResources(0,
                                                     sampledIrrandiancesBufferManager.InView,
                                                     formFactorSegments,
                                                     formFactorElements);
            context.ComputeShader.SetUnorderedAccessView(0, scatteredIrrandiancesBufferManager.OutView);
            context.Dispatch(IntegerUtils.RoundUp(vertexCount, ShaderNumThreads), 1, 1);

            context.ClearState();
        });
    }
        public void WriteHermiteSigns(int size, Vector3 offset, Vector3 scaling, string density, GPUTexture3D tx)
        {
            //var tx = GPUTexture3D.CreateUAV(game, size, size, size, Format.R32_Typeless, Format.R32_Float);
            //var tx = CreateDensitySignsTexture(size);//GPUTexture3D.CreateUAV(game, size, size, size, Format.R8G8B8A8_UNorm, Format.R8G8B8A8_UNorm);

            var width   = tx.Resource.Description.Width;
            int groupsX = (int)Math.Ceiling(width / (double)ThreadGroupSize);
            var height  = tx.Resource.Description.Height;
            int groupsY = (int)Math.Ceiling(height / (double)ThreadGroupSize);


            context.ClearState();
            context.ComputeShader.Set(csX);
            context.ComputeShader.SetShaderResource(perlin.View, 0);
            context.ComputeShader.SetUnorderedAccessView(tx.UnorderedAccessView, 0);
            context.ComputeShader.SetSampler(trilinearSampler, 0);

            context.Dispatch(groupsX, groupsX, groupsX);

            /* context.ClearState();
             * context.ComputeShader.Set(csY);
             * context.ComputeShader.SetShaderResource(buffer.View, 0);
             * context.ComputeShader.SetUnorderedAccessView(output, 0);
             *
             * context.Dispatch(width, groupsY, 1);*/

            //context.GenerateMips(tx.View);
        }
 private void UpdateCS(string csName, UnorderedAccessView append, UnorderedAccessView consume)
 {  // Compile the shader if it isn't already
     if (!computeShaders.ContainsKey(csName))
     {
         CompileComputeShader(csName);
     }
     // Set the shader to run
     context.ComputeShader.Set(computeShaders[csName]);
     // Dispatch the compute shader thread groups
     context.Dispatch((int)Math.Ceiling(Constants.MaxParticles / (double)ThreadsX), 1, 1);
 }
    private void SetupRasterTable(Device device, ShaderCache shaderCache)
    {
        DeviceContext context = device.ImmediateContext;

        BufferDescription desc = new BufferDescription {
            SizeInBytes         = RasterTableElementCount * RasterSizeInBytes,
            Usage               = ResourceUsage.Default,
            BindFlags           = BindFlags.UnorderedAccess | BindFlags.ShaderResource,
            OptionFlags         = ResourceOptionFlags.BufferStructured,
            StructureByteStride = RasterSizeInBytes
        };

        var buildTableShader = shaderCache.GetComputeShader <GpuOcclusionCalculator>("occlusion/BuildHemisphericalRasterizingTable");

        using (Buffer buffer = new Buffer(device, desc))
            using (UnorderedAccessView view = new UnorderedAccessView(device, buffer)) {
                context.ComputeShader.Set(buildTableShader);
                context.ComputeShader.SetUnorderedAccessView(0, view);
                context.ComputeShader.SetConstantBuffer(0, hemispherePointsAndWeightsConstantBuffer);
                context.Dispatch(RasterTableDim / BuildTableShaderNumThreads, RasterTableDim, RasterTableFaceCount);
                context.ClearState();

                rasterCacheView = new ShaderResourceView(device, buffer);
            }
    }
    public OcclusionInfo[] Run(DeviceContext context, ShaderResourceView vertexInfos)
    {
        context.ClearState();
        context.ComputeShader.Set(shader);
        context.ComputeShader.SetConstantBuffer(0, hemispherePointsAndWeightsConstantBuffer);
        context.ComputeShader.SetShaderResources(0,
                                                 rasterCacheView,
                                                 facesView,
                                                 transparenciesView,
                                                 vertexMasksView,
                                                 faceMasksView,
                                                 vertexInfos);
        context.ComputeShader.SetUnorderedAccessView(0, outputBufferManager.View);

        for (int baseVertexIdx = 0; baseVertexIdx < vertexCount; baseVertexIdx += BatchSize)
        {
            ArraySegment segment = new ArraySegment(baseVertexIdx, Math.Max(vertexCount - baseVertexIdx, BatchSize));
            segmentBufferManager.Update(context, segment);
            context.ComputeShader.SetConstantBuffer(1, segmentBufferManager.Buffer);
            context.Dispatch(1, IntegerUtils.RoundUp(BatchSize, ShaderNumThreads / RasterRowCount), 1);
            context.Flush();
        }

        return(outputBufferManager.ReadContents(context));
    }
Пример #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="threadGroupCountX"></param>
 /// <param name="threadGroupCountY"></param>
 /// <param name="threadGroupCountZ"></param>
 public void Dispatch(int threadGroupCountX, int threadGroupCountY = 1, int threadGroupCountZ = 1)
 {
     lock (deviceContext) {
         ApplyGpuState();
         deviceContext.Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
     }
 }
Пример #7
0
    public void CalculateOcclusion(DeviceContext context)
    {
        if (unmorphedWithChildrenOcclusionInfosToUpload != null)
        {
            unmorphedWithChildrenOcclusionInfosBufferManager.Update(context, unmorphedWithChildrenOcclusionInfosToUpload);
            unmorphedWithChildrenOcclusionInfosToUpload = null;
        }

        if (parametersResources == null)
        {
            return;
        }

        context.WithEvent("Occluder::CalculateOcclusion", () => {
            context.ClearState();

            context.ComputeShader.Set(shader);
            context.ComputeShader.SetShaderResources(0,
                                                     unmorphedWithoutChildrenOcclusionInfosView,
                                                     unmorphedWithChildrenOcclusionInfosBufferManager.View,
                                                     parametersResources.baseOcclusionView,
                                                     parametersResources.channelWeightsBufferManager.View,
                                                     parametersResources.occlusionDeltaWeightSegmentsView,
                                                     parametersResources.occlusionDeltaWeightElemsView);
            context.ComputeShader.SetUnorderedAccessView(0, parametersResources.calculatedInfosBuffersBufferManager.OutView);

            context.Dispatch(IntegerUtils.RoundUp(parametersResources.vertexCount, ShaderNumThreads), 1, 1);

            context.ClearState();
        });
    }
Пример #8
0
        public override void Dispatch(uint groupCountX, uint groupCountY, uint groupCountZ)
        {
            PreDispatchCommand();

            ShaderResourceView[] srvs = _context.PixelShader.GetShaderResources(0, 10);

            _context.Dispatch((int)groupCountX, (int)groupCountY, (int)groupCountZ);
        }
Пример #9
0
 public void Refine(DeviceContext context, ShaderResourceView vertexPositionsView, UnorderedAccessView resultsView)
 {
     context.ClearState();
     context.ComputeShader.Set(refinerShader);
     context.ComputeShader.SetShaderResources(0, stencilSegmentsView, stencilElemsView, vertexPositionsView);
     context.ComputeShader.SetUnorderedAccessView(0, resultsView);
     context.Dispatch(IntegerUtils.RoundUp(refinedVertexCount, ShaderNumThreads), 1, 1);
     context.ClearState();
 }
Пример #10
0
        public static void ExecuteComputeForSize(DeviceContext context, int x, int y, int z, string shader)
        {
            ShaderWrapper wrapper = m_Shaders[shader];

            context.ComputeShader.Set(wrapper.m_ComputeShader);
            context.Dispatch(
                (x + wrapper.m_ThreadsX - 1) / wrapper.m_ThreadsX,
                (y + wrapper.m_ThreadsY - 1) / wrapper.m_ThreadsY,
                (z + wrapper.m_ThreadsZ - 1) / wrapper.m_ThreadsZ);
        }
Пример #11
0
        public static void ExecuteComputeForResource(DeviceContext context, TextureObject textureResource, string shader)
        {
            ShaderWrapper wrapper = m_Shaders[shader];

            context.ComputeShader.Set(wrapper.m_ComputeShader);
            context.Dispatch(
                (textureResource.m_Width + wrapper.m_ThreadsX - 1) / wrapper.m_ThreadsX,
                (textureResource.m_Height + wrapper.m_ThreadsY - 1) / wrapper.m_ThreadsY,
                (textureResource.m_Depth + wrapper.m_ThreadsZ - 1) / wrapper.m_ThreadsZ);
        }
        public void Blur(ShaderResourceView input, GPUTexture buffer, UnorderedAccessView output)
        {
            var width   = buffer.Resource.Description.Width;
            int groupsX = (int)Math.Ceiling(width / (double)ThreadGroupSize);
            var height  = buffer.Resource.Description.Height;
            int groupsY = (int)Math.Ceiling(height / (double)ThreadGroupSize);


            context.ClearState();
            context.ComputeShader.Set(csX);
            context.ComputeShader.SetShaderResource(input, 0);
            context.ComputeShader.SetUnorderedAccessView(buffer.UnorderedAccessView, 0);

            context.Dispatch(groupsX, height, 1);

            context.ClearState();
            context.ComputeShader.Set(csY);
            context.ComputeShader.SetShaderResource(buffer.View, 0);
            context.ComputeShader.SetUnorderedAccessView(output, 0);

            context.Dispatch(width, groupsY, 1);
        }
    public void Run()
    {
        Device      device      = new Device(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug);
        ShaderCache shaderCache = new ShaderCache(device);

        var stamdardSamplers = new StandardSamplers(device);

        var dataDir     = UnpackedArchiveDirectory.Make(CommonPaths.WorkDir);
        var environment = new ImageBasedLightingEnvironment(device, stamdardSamplers, dataDir, "ruins", 0);

        DeviceContext context = device.ImmediateContext;

        Vector4[] samplePositions =
        {
            new Vector4(+1,  0,  0, 0),
            new Vector4(-1,  0,  0, 0),
            new Vector4(0,  +1,  0, 0),
            new Vector4(0,  -1,  0, 0),
            new Vector4(0,   0, +1, 0),
            new Vector4(0,   0, -1, 0),
        };

        var inBufferView = BufferUtilities.ToStructuredBufferView(device, samplePositions);

        ComputeShader shader = shaderCache.GetComputeShader <SampleCubeMapApp>("demos/cubemapsampler/SampleCubeMap");

        var outBuffer = new StageableStructuredBufferManager <Vector4>(device, samplePositions.Length);

        context.ComputeShader.Set(shader);
        environment.Apply(context.ComputeShader);
        context.ComputeShader.SetShaderResource(1, inBufferView);
        context.ComputeShader.SetUnorderedAccessView(0, outBuffer.View);

        context.Dispatch(samplePositions.Length, 1, 1);
        context.ClearState();

        Vector4[] results = outBuffer.ReadContents(context);

        for (int i = 0; i < samplePositions.Length; ++i)
        {
            Console.WriteLine(samplePositions[i]);
            Console.WriteLine("\t" + results[i].X);
            Console.WriteLine("\t" + results[i].Y);
            Console.WriteLine("\t" + results[i].Z);
            Console.WriteLine("\t" + results[i].W);
        }
    }
Пример #14
0
        public void OnRender(DeviceContext context)
        {
            context.InputAssembler.InputLayout = vertexLayout;
            context.InputAssembler.PrimitiveTopology
                = PrimitiveTopology.TriangleList;

            context.InputAssembler.SetVertexBuffers(
                0,
                new VertexBufferBinding(
                    vertexBuffer,
                    VertexDefinition.SizeInBytes,
                    0
                    )
                );



            try
            {
                ComputeShader cs = engine.Load(csPath);
                context.ComputeShader.Set(cs);

                context.ComputeShader.SetUnorderedAccessView(statusUAV, 2);

                context.Dispatch(100, 1, 1);

                //context.CopyResource(bufferUA, bufferSR);

                context.ComputeShader.SetUnorderedAccessView(null, 2);// Slot2 をリセット


                effectPass.Apply(context);
                context.PixelShader.SetSampler(sampler, 0);
                context.PixelShader.SetShaderResource(textureView, 0);
                context.VertexShader.SetShaderResource(statusSRV, 1);
            }
            catch (Exception e)
            {
                return;
            }


            context.DrawInstanced(faces.Length, statusArray.Count, 0, 0);

            //context.VertexShader.SetShaderResource(null, 1);
        }
Пример #15
0
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device        device = context.Device;
            DeviceContext ctx    = context.CurrentDeviceContext;

            if (!this.FOutLinkBuffer[0].Contains(context) || !this.FOutOffsetBuffer[0].Contains(context) || FInGridcellCount.IsChanged)
            {
                this.FOutLinkBuffer[0].Dispose(context);
                this.FOutOffsetBuffer[0].Dispose(context);
                DX11RWStructuredBuffer lb = new DX11RWStructuredBuffer(device, FInEleCount[0], 8, eDX11BufferMode.Counter);
                DX11RWStructuredBuffer ob = new DX11RWStructuredBuffer(device, FInGridcellCount[0] * FInGridcellCount[0] * FInGridcellCount[0], 4, eDX11BufferMode.Counter);
                this.FOutLinkBuffer[0][context]   = lb;
                this.FOutOffsetBuffer[0][context] = ob;
            }

            // clear offsetbuffer
            int[] mask = new int[4] {
                -1, -1, -1, -1
            };
            ctx.ClearUnorderedAccessView(FOutOffsetBuffer[0][context].UAV, mask);

            // load shader
            if (this.shader == null)
            {
                string     basepath = "LinkedList.effects.LinkedList.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);
                this.shader = new DX11ShaderInstance(context, effect);
            }

            if (this.FInPcBuffer.PluginIO.IsConnected)
            {
                shader.SelectTechnique("BuildHash");
                shader.SetBySemantic("POINTCLOUDBUFFER", FInPcBuffer[0][context].SRV);
                shader.SetBySemantic("POINTTRANSFORM", FInTransform[0]);
                shader.SetBySemantic("RWLINKBUFFER", FOutLinkBuffer[0][context].UAV, 0);
                shader.SetBySemantic("RWOFFSETBUFFER", FOutOffsetBuffer[0][context].UAV);
                shader.SetBySemantic("GRIDCELLSIZE", FInGridcellCount[0]);

                shader.ApplyPass(0);
                ctx.Dispatch((FInEleCount[0] + 63) / 64, 1, 1);
                context.CleanUp();
                context.CleanUpCS();
            }
        }
Пример #16
0
    private void CalculatePositionsCommon(
        DeviceContext context,
        UnorderedAccessView vertexInfosOutView,
        ShaderResourceView occlusionInfosView,
        ShaderResourceView parentDeltasInView,
        UnorderedAccessView deltasOutView)
    {
        context.WithEvent("GpuShaper::CalculatePositions", () => {
            context.ClearState();

            if (deltasOutView != null)
            {
                context.ComputeShader.Set(withDeltasShader);
            }
            else
            {
                context.ComputeShader.Set(withoutDeltasShader);
            }

            context.ComputeShader.SetShaderResources(0,
                                                     initialPositionsView,
                                                     deltaSegmentsView,
                                                     deltaElemsView,
                                                     morphWeightsBufferManager.View,
                                                     baseDeltaWeightSegmentsView,
                                                     baseDeltaWeightElemsView,
                                                     boneWeightSegmentsView,
                                                     boneWeightElemsView,
                                                     boneTransformsBufferManager.View,
                                                     occlusionInfosView,
                                                     occlusionSurrogateMapView,
                                                     occlusionSurrogateFacesView,
                                                     occlusionSurrogateInfosBufferManager.View,
                                                     parentDeltasInView);

            context.ComputeShader.SetUnorderedAccessViews(0,
                                                          vertexInfosOutView,
                                                          deltasOutView);

            context.Dispatch(IntegerUtils.RoundUp(vertexCount, ShaderNumThreads), 1, 1);

            context.ClearState();
        });
    }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device        device = context.Device;
            DeviceContext ctx    = context.CurrentDeviceContext;

            if (!this.FOutPointcloudBuffer[0].Contains(context) || !this.FOutIndexBuffer[0].Contains(context) || this.FInEleCount.IsChanged)
            {
                this.FOutPointcloudBuffer[0].Dispose(context);
                this.FOutIndexBuffer[0].Dispose(context);
                DX11RWStructuredBuffer pcBuffer = new DX11RWStructuredBuffer(device, FInEleCount[0], FInStride[0], eDX11BufferMode.Counter);
                DX11RWStructuredBuffer idBuffer = new DX11RWStructuredBuffer(device, FInEleCount[0], 4, eDX11BufferMode.Counter);
                this.FOutPointcloudBuffer[0][context] = pcBuffer;
                this.FOutIndexBuffer[0][context]      = idBuffer;
            }

            // clear offsetbuffer
            int[] mask = new int[4] {
                -1, -1, -1, -1
            };
            ctx.ClearUnorderedAccessView(FOutIndexBuffer[0][context].UAV, mask);

            // load shader
            if (this.shader == null)
            {
                string     basepath = "RingBufferIndexing.effects.RingBufferIndexing.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);
                this.shader = new DX11ShaderInstance(context, effect);
            }

            if (this.FInPointcloudBuffer.PluginIO.IsConnected /* && currentFrame != FHDEHost.FrameTime*/)
            {
                currentFrame = FHDEHost.FrameTime; // prevents to execute this a second time

                shader.SelectTechnique("BuildHash");
                shader.SetBySemantic("POINTCLOUDBUFFERIN", FInPointcloudBuffer[0][context].SRV);
                shader.SetBySemantic("POINTCLOUDBUFFEROUT", FOutPointcloudBuffer[0][context].UAV, 0);
                shader.SetBySemantic("INDEXBUFFER", FOutIndexBuffer[0][context].UAV);

                shader.ApplyPass(0);
                ctx.Dispatch((FInEleCount[0] + 63) / 64, 1, 1);
                context.CleanUp();
                context.CleanUpCS();
            }
        }
Пример #18
0
        internal void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            if (!MyRenderProxy.Settings.EnableShadows)
            {
                return;
            }

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            MyRenderContext renderContext = MyRenderContext.Immediate;
            DeviceContext   deviceContext = renderContext.DeviceContext;

            renderContext.SetCS(m_gatherCS);
            ComputeShaderId.TmpUav[0] = postprocessTarget.Uav;
            deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);

            deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth);
            deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState);
            deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants);
            deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.ShaderView);

            deviceContext.Dispatch(m_threadGroupCountX, m_threadGroupCountY, 1);

            ComputeShaderId.TmpUav[0] = null;
            renderContext.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            deviceContext.ComputeShader.SetShaderResource(0, null);

            if (MyRender11.Settings.EnableShadowBlur)
            {
                MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.ShaderView, postprocessTarget.ShaderView, depthDiscardThreshold: 0.2f);
            }

            MyGpuProfiler.IC_EndBlock();
        }
Пример #19
0
        private void Compute(DeviceContext context, ComputeShader cs, Buffer constantBuffer, UnorderedAccessView unorderedAccessView, int X, int Y, int Z, params ShaderResourceView[] resourceViews)
        {
            context.ComputeShader.Set(cs);
            context.ComputeShader.SetShaderResources(0, resourceViews);
            context.ComputeShader.SetUnorderedAccessView(0, unorderedAccessView);

            if (constantBuffer != null)
            {
                //make sure buffer is updated first...
                //D3D11_MAPPED_SUBRESOURCE mappedResource;
                //dc->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
                //memcpy(mappedResource.pData, constantData, constantDataSize);
                //dc->Unmap(constantBuffer, 0);
                context.ComputeShader.SetConstantBuffer(0, constantBuffer); //dc->CSSetConstantBuffers(0, 1, &constantBuffer);
            }

            context.Dispatch(X, Y, Z);

            ShaderResourceView[] ppSRVNULL = { null, null, null };
            context.ComputeShader.SetUnorderedAccessView(0, null);
            context.ComputeShader.SetShaderResources(0, 3, ppSRVNULL);
            context.ComputeShader.SetConstantBuffer(0, null);
        }
Пример #20
0
 /// <summary>
 ///     スキニングを実行する。
 /// </summary>
 /// <remarks>
 ///     このメソッドの呼び出し前に、<paramref name="d3ddc"/> には以下の設定が行われている。
 ///     - ComputeShader
 ///         - slot( b1 ) …… ボーンのモデルボーズ行列の配列
 ///         - slot( b2 ) …… ボーンのローカル位置の配列
 ///         - slot( b3 ) …… ボーンの回転の配列
 ///         - slot( t0 ) …… 変化前頂点データ CS_BDEF_INPUT の配列
 ///         - slot( u0 ) …… 頂点バッファの UAV
 /// </remarks>
 public void Run(DeviceContext d3ddc, int 入力頂点数)
 {
     d3ddc.ComputeShader.Set(this.ComputeShader);
     d3ddc.Dispatch((入力頂点数 / 64) + 1, 1, 1);
 }
Пример #21
0
        public override void Dispatch(uint groupCountX, uint groupCountY, uint groupCountZ)
        {
            PreDispatchCommand();

            _context.Dispatch((int)groupCountX, (int)groupCountY, (int)groupCountZ);
        }
 public void Start(int threadGroupCountX, int threadGroupCountY, int threadGroupCountZ)
 {
     _d3dContext.Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
 }
Пример #23
0
 public void Run(int groupNumber = 1)
 {
     ctx.Dispatch(groupNumber, 1, 1);
     ctx.Flush();
 }
        internal static void RunComputeShader(DeviceContext context, ComputeShader shader, ShaderResourceView[] views, UnorderedAccessView[] unordered, SharpDX.Direct3D11.Buffer constParams, int x, int y)
        {
            ComputeShaderStage cs = context.ComputeShader;

            cs.Set(shader);
            cs.SetShaderResources(0, views);
            cs.SetUnorderedAccessViews(0, unordered);
            cs.SetConstantBuffer(0, constParams);
            context.Dispatch(x, y, 1);
        }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device device = context.Device;
            DeviceContext ctx = context.CurrentDeviceContext;

            if ( !this.FOutPointcloudRingBuffer[0].Contains(context) || !this.FOutUpdatedBuffer[0].Contains(context) || !this.bCounter.Contains(context) || !this.bOffset.Contains(context) || this.FInPointcloudRingBufferSize.IsChanged || this.FInEleCount.IsChanged)
            {

                this.FOutPointcloudRingBuffer[0].Dispose(context);
                DX11RWStructuredBuffer brPointcloud = new DX11RWStructuredBuffer(device, FInPointcloudRingBufferSize[0], FInStride[0], eDX11BufferMode.Counter);
                this.FOutPointcloudRingBuffer[0][context] = brPointcloud;

                this.FOutUpdatedBuffer[0].Dispose(context);
                DX11RWStructuredBuffer brUpdated = new DX11RWStructuredBuffer(device, FInPointcloudRingBufferSize[0], 4, eDX11BufferMode.Counter);
                this.FOutUpdatedBuffer[0][context] = brUpdated;

                this.bOffset.Dispose(context);
                this.bOffset[context] = new DX11RawBuffer(device, 16);

                this.bCounter.Dispose(context);
                this.bCounter[context] = new DX11RWStructuredBuffer(device, FInEleCount[0], 4, eDX11BufferMode.Counter);

            }

            // load shader
            if (this.shader == null)
            {
                string basepath = "RingBuffer.effects.RingBuffer.fx";
                DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);
                this.shader = new DX11ShaderInstance(context, effect);
            }

            if (this.FInPointcloudBuffer.PluginIO.IsConnected && FInSet[0] && currentFrame != FHDEHost.FrameTime)
            {

                currentFrame = FHDEHost.FrameTime; // prevents to execute this a second time

                int[] mask = new int[4] { 0, 0, 0, 0 };
                ctx.ClearUnorderedAccessView(FOutUpdatedBuffer[0][context].UAV, mask);

                shader.SelectTechnique("AddPoints");
                shader.SetBySemantic("POINTCLOUDBUFFER", FInPointcloudBuffer[0][context].SRV);
                shader.SetBySemantic("POINTCLOUDCOUNTBUFFER", FInCountBuffer[0][context].SRV);
                shader.SetBySemantic("POINTCLOUDRINGBUFFER", FOutPointcloudRingBuffer[0][context].UAV, FInPointcloudRingBufferSize[0]);
                shader.SetBySemantic("UPDATEDRINGBUFFER", FOutUpdatedBuffer[0][context].UAV, FInPointcloudRingBufferSize[0]);
                shader.SetBySemantic("POINTCLOUDRINGBUFFERSIZE", FInPointcloudRingBufferSize[0]);
                shader.SetBySemantic("OFFSETBUFFER", this.bOffset[context].SRV);
                shader.SetBySemantic("COUNTERBUFFER", this.bCounter[context].UAV, 0);
                shader.ApplyPass(0);
                ctx.Dispatch((FInEleCount[0] + 63) / 64, 1, 1);

                ctx.CopyStructureCount(this.bCounter[context].UAV, this.bOffset[context].Buffer, 0);
                shader.SelectTechnique("CalcOffset");
                shader.ApplyPass(0);
                ctx.Dispatch(1, 1, 1);

                context.CleanUp();
                context.CleanUpCS();
                
            }

        }
Пример #26
0
        internal void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            if (!MyRenderProxy.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows)
            {
                return;
            }

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            MyRenderContext renderContext = MyRenderContext.Immediate;
            DeviceContext   deviceContext = renderContext.DeviceContext;

            MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality();

            if (shadowsQuality == MyShadowsQuality.LOW)
            {
                renderContext.SetCS(m_gatherCS_LD);
            }
            else if (shadowsQuality == MyShadowsQuality.MEDIUM)
            {
                renderContext.SetCS(m_gatherCS_MD);
            }
            else if (shadowsQuality == MyShadowsQuality.HIGH)
            {
                renderContext.SetCS(m_gatherCS_HD);
            }

            ComputeShaderId.TmpUav[0] = postprocessTarget.Uav;
            deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);

            deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth);
            deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap);
            if (!MyStereoRender.Enable)
            {
                deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(renderContext);
            }
            deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.SRV);

            Vector2I threadGroups = GetThreadGroupCount();

            deviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1);

            ComputeShaderId.TmpUav[0] = null;
            renderContext.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            deviceContext.ComputeShader.SetShaderResource(0, null);
            deviceContext.ComputeShader.SetShaderResource(1, null);

            if (shadowsQuality == MyShadowsQuality.HIGH && MyRender11.Settings.EnableShadowBlur)
            {
                MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.SRV, postprocessTarget.SRV, depthDiscardThreshold: 0.2f);
            }

            MyGpuProfiler.IC_EndBlock();
        }
Пример #27
0
 public void Draw(DeviceContext ctx)
 {
     //ctx.ComputeShader.
     ctx.Dispatch(X, Y, Z);
 }
Пример #28
0
        public static void ExecuteComputeForResource(DeviceContext context, TextureObject textureResource, string shader)
        {
            BindDebugUAV(context);

            ShaderWrapper wrapper = m_Shaders[shader];
            context.ComputeShader.Set((ComputeShader)wrapper.m_ShaderObject);
            context.Dispatch(
                (textureResource.m_Width + wrapper.m_ThreadsX - 1) / wrapper.m_ThreadsX,
                (textureResource.m_Height + wrapper.m_ThreadsY - 1) / wrapper.m_ThreadsY,
                (textureResource.m_Depth + wrapper.m_ThreadsZ - 1) / wrapper.m_ThreadsZ);
        }
Пример #29
0
        public static void ExecuteComputeForSize(DeviceContext context, int x, int y, int z, string shader)
        {
            BindDebugUAV(context);

            ShaderWrapper wrapper = m_Shaders[shader];
            context.ComputeShader.Set((ComputeShader)wrapper.m_ShaderObject);
            context.Dispatch(
                (x + wrapper.m_ThreadsX - 1) / wrapper.m_ThreadsX,
                (y + wrapper.m_ThreadsY - 1) / wrapper.m_ThreadsY,
                (z + wrapper.m_ThreadsZ - 1) / wrapper.m_ThreadsZ);
        }