Пример #1
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();
        });
    }
        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);
        }
Пример #3
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();
        });
    }
Пример #4
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();
 }
Пример #5
0
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    Util.ReleaseCom(ref RenderTargetView);
                    Util.ReleaseCom(ref DepthStencilView);
                    Util.ReleaseCom(ref _screenQuadIB);
                    Util.ReleaseCom(ref _screenQuadVB);

                    Util.ReleaseCom(ref DepthStencilBuffer);
                    if (ImmediateContext != null)
                    {
                        ImmediateContext.ClearState();
                    }

                    if (SwapChain.IsFullScreen)
                    {
                        SwapChain.SetFullScreenState(false, null);
                    }
                    Util.ReleaseCom(ref SwapChain);
                    Util.ReleaseCom(ref ImmediateContext);
                    Util.ReleaseCom(ref Device);

                    Util.ReleaseCom(ref _progressUpdate);

                    Util.ReleaseCom(ref _dxWRT);
                    Util.ReleaseCom(ref Sprite);
                    Util.ReleaseCom(ref FontCache);
                }
                _disposed = true;
            }
            base.Dispose(disposing);
        }
    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);
            }
    }
Пример #7
0
        public void Dispose()
        {
            Debug.WriteLine("DeviceContextHolder.Dispose()");

            DisposeHelper.Dispose(ref _states);
            Debug.WriteLine("_states disposed");

            DisposeHelper.Dispose(ref _quadBuffers);
            Debug.WriteLine("_quadBuffers disposed");

            _effects.DisposeEverything();
            Debug.WriteLine("_effects disposed");

            _helpers.DisposeEverything();
            Debug.WriteLine("_helpers disposed");

            _randomTextures.DisposeEverything();
            Debug.WriteLine("_randomTextures disposed");

            DisposeHelper.Dispose(ref _flatNmView);
            Debug.WriteLine("_flatNm disposed");

            _something.Values.OfType <IDisposable>().DisposeEverything();
            _something.Clear();
            Debug.WriteLine("_something disposed");

            DeviceContext.ClearState();
            DeviceContext.Flush();
            // we don’t need to dispose deviceContext — it’s the same as device

            Device.Dispose();
            Debug.WriteLine("Device disposed");
        }
Пример #8
0
        protected override void OnClosed(EventArgs e)
        {
            // dispose all the DirectX bits

            deviceContext.ClearState();
            deviceContext.Flush();


            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
            }

            if (vertexShader != null)
            {
                vertexShader.Dispose();
            }

            if (pixelShader != null)
            {
                pixelShader.Dispose();
            }

            if (renderTargetView != null)
            {
                renderTargetView.Dispose();
            }

            if (device != null)
            {
                device.Dispose();
            }

            base.OnClosed(e);
        }
Пример #9
0
        public void Dispose()
        {
            System.Console.WriteLine("Renderer3d.Dispose");
            if (context != null)
            {
                DiscardDeviceResources();

                textureCollection?.Dispose();
                textureLoader?.Dispose();

                cb_shader_flags?.Dispose();
                cb_mat?.Dispose();
                cb_wvp?.Dispose();

                foreach (NiFile nif in nifs)
                {
                    foreach (Mesh mesh in nif.meshes)
                    {
                        mesh.Dispose();
                    }
                }

                context.ClearState();
                context.Flush();
                context.Dispose();
                context = null;
            }
            skeleton = null;
            device   = null;
        }
        void UpdateCubeFace(DeviceContext context, int index, int mip)
        {
            // Prepare pipeline
            context.ClearState();

            context.Rasterizer.SetViewport(Viewport);
            context.InputAssembler.InputLayout = CustomInputLayout;
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(null, 0, 0));
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;

            if (CurrentState == RenderState.IntegrateBRDF)
            {
                context.OutputMerger.SetRenderTargets(null, IntegrateBRDFxRTV);
                context.ClearRenderTargetView(IntegrateBRDFxRTV, Color.CornflowerBlue);
                context.VertexShader.Set(IntegrateQuadVS);
                context.PixelShader.Set(IntegrateBRDFxPS);
                context.Draw(4, 0);
                UnbindContextRTV(context);
                return;
            }

            int rtvIndex = mip < 0 ? index : (index * PreFilteredMipsCount + mip);

            context.OutputMerger.SetRenderTargets(null, OutputRTVs[rtvIndex]);
            // Render the scene using the view, projection, RTV and DSV of this cube face
            context.ClearRenderTargetView(OutputRTVs[rtvIndex], Color.CornflowerBlue);


            Matrix[] ViewProj = new Matrix[]
            {
                Cameras[index].View,
                Cameras[index].Projection,
            };
            context.UpdateSubresource(ViewProj, ConstantsBuffer);
            context.VertexShader.Set(SphereToCubeMapVS);
            context.VertexShader.SetConstantBuffer(0, ConstantsBuffer);
            context.PixelShader.SetConstantBuffer(1, BRDFParamsBuffer);
            context.PixelShader.SetSampler(0, Sampler);

            switch (CurrentState)
            {
            case RenderState.CubeMap:
                context.PixelShader.Set(SphereToCubeMapPS);
                context.PixelShader.SetShaderResource(0, InputSRV);
                break;

            case RenderState.IrradianceMap:
                context.PixelShader.Set(IrradiancePS);
                context.PixelShader.SetShaderResource(1, ConvertedCubeSRV);
                break;

            case RenderState.PreFilteredMap:
                context.PixelShader.Set(PreFilteredPS);
                context.PixelShader.SetShaderResource(1, ConvertedCubeSRV);
                break;
            }

            context.Draw(14, 0);
            UnbindContextRTV(context);
        }
Пример #11
0
        /*-----------------------------------------------------------------------------------------
        *
        *   State control
        *
        *  -----------------------------------------------------------------------------------------*/

        /// <summary>
        /// Resets all devices states including RTs and DS
        /// </summary>
        public void ResetStates()
        {
            lock (this.DeviceContext) {
                deviceContext.ClearState();

                SetTargets(null);
                SetupVertexInput(null, null);
                SetupVertexOutput(null, 0);

                PixelShaderResources.Clear();
                VertexShaderResources.Clear();
                GeometryShaderResources.Clear();
                ComputeShaderResources.Clear();
                DomainShaderResources.Clear();
                HullShaderResources.Clear();

                PixelShaderSamplers.Clear();
                VertexShaderSamplers.Clear();
                GeometryShaderSamplers.Clear();
                ComputeShaderSamplers.Clear();
                DomainShaderSamplers.Clear();
                HullShaderSamplers.Clear();

                PixelShaderConstants.Clear();
                VertexShaderConstants.Clear();
                GeometryShaderConstants.Clear();
                ComputeShaderConstants.Clear();
                DomainShaderConstants.Clear();
                HullShaderConstants.Clear();

                PipelineState = null;
            }
        }
    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));
    }
Пример #13
0
        public void UpdateShadowMap(Action renderScene)
        {
            context.ClearState();
            context.ClearDepthStencilView(shadowMapDSV, DepthStencilClearFlags.Depth, 1, 0);
            context.Rasterizer.SetViewports(new Viewport(0, 0, shadowMapSize, shadowMapSize));
            context.OutputMerger.SetTargets(shadowMapDSV);

            renderScene();
        }
 protected virtual void EndPhase1()
 {
     mDeviceContext.ClearState();
     mDeviceContext.Flush();
     mDevice.Dispose();
     mDeviceContext.Dispose();
     mSwapChain.Dispose();
     mFactory.Dispose();
 }
Пример #15
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();
        });
    }
Пример #16
0
 public void Dispose()
 {
     renderView.Dispose();
     backBuffer.Dispose();
     context.ClearState();
     context.Flush();
     device.Dispose();
     context.Dispose();
     swapChain.Dispose();
 }
        public void DrawUpdatedLogLuminance()
        {
            context.ClearState();
            context.OutputMerger.SetTargets(luminanceRTV);
            context.Rasterizer.SetViewports(new Viewport(0, 0, luminanceMap.Description.Width,
                                                         luminanceMap.Description.Height));
            shader.SetTechnique("CalculateLuminance");

            shader.Effect.GetVariableByName("hdrImage").AsResource().SetResource(hdrImage);

            shader.Apply();
            quad.Draw(layout);

            shader.Effect.GetVariableByName("hdrImage").AsResource().SetResource(null);
            shader.Apply();

            //TODO: Do not use GenerateMips, generate the manually. This might solve the NAN problem
            generateMips();
        }
Пример #18
0
        public void Dispose()
        {
            // Release all resources

            figures.Dispose();

            if (ctx != null)
            {
                ctx.ClearState();
                ctx.Flush();
                ctx.Dispose();
            }

            if (il != null)
            {
                il.Dispose();
            }
            if (effect != null)
            {
                effect.Dispose();
            }

            if (hmd != null)
            {
                keyboard.Dispose();
                directInput.Dispose();

                mtex.Dispose();
                layers.Dispose();

                eye_texes[0].Dispose();
                eye_texes[1].Dispose();

                default_rasterizer_state.Dispose();
                default_depth_stencil_state.Dispose();
                default_blend_state.Dispose();

                ztex_view.Dispose();
                ztex.Dispose();

                buf0_view.Dispose();
                buf0.Dispose();

                swap_chain.Dispose();
                dxgi_factory.Dispose();

                // Disposing the device, before the hmd, will cause the hmd to fail when disposing.
                // Disposing the device, after the hmd, will cause the dispose of the device to fail.
                // It looks as if the hmd steals ownership of the device and destroys it, when it's shutting down.
                // device.Dispose();

                hmd.Dispose();
            }
            oculus.Dispose();
        }
            public void Render()
            {
                angle += MathHelper.Pi * game.Elapsed;
                point.LightPosition = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), -2);

                ctx.ClearState();
                combineFinal.SetLightAccumulationStates();
                combineFinal.ClearLightAccumulation();
                point.Draw();

                ctx.ClearState();
                game.SetBackbuffer();
                ctx.Rasterizer.SetViewports(new Viewport(400, 300, 400, 300));

                combineFinal.DrawCombined();


                game.SetBackbuffer();
                GBufferTest.DrawGBuffer(game, buffer);
            }
Пример #20
0
 public void Dispose()
 {
     depthStencilView.Dispose();
     depthStencilBuffer.Dispose();
     backBuffer.Dispose();
     deviceContext.ClearState();
     deviceContext.Flush();
     deviceContext.Dispose();
     device.Dispose();
     swapChain.Dispose();
     renderTargetView.Dispose();
 }
Пример #21
0
 // Clean up DX
 public void CleanUpDX()
 {
     renderView.Dispose();
     backBuffer.Dispose();
     devCon.ClearState();
     devCon.Flush();
     dev.Dispose();
     devCon.Dispose();
     swapChain.Dispose();
     factory.Dispose();
     form.Dispose();
 }
Пример #22
0
        public virtual void Dispose()
        {
            RenderTarget.Dispose();

            if (!ImmediateContext.IsDisposed)
            {
                ImmediateContext.ClearState();
                ImmediateContext.Flush();
                ImmediateContext.Dispose();
            }

            D3DDevice.Dispose();
        }
        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);
        }
Пример #24
0
    public void RefineVertices(DeviceContext context, ShaderResourceView controlVertexInfosView, ShaderResourceView scatteredIlluminationView)
    {
        context.WithEvent("VertexRefiner::RefineVertices", () => {
            context.ClearState();

            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;

            context.VertexShader.SetShaderResources(0, shaderResources);
            context.VertexShader.SetShaderResources(shaderResources.Length,
                                                    controlVertexInfosView,
                                                    scatteredIlluminationView);
            context.VertexShader.Set(vertexRefinerShader);

            context.GeometryShader.Set(vertexRefinerGeometryShader);

            context.StreamOutput.SetTarget(refinedVertexBuffer, 0);

            context.Draw(refinedVertexCount, 0);

            context.ClearState();
        });
    }
        public void Draw()
        {
            resetDevice();

            drawGBuffer(GBuffer);
            drawLines(GBuffer);
            drawLights(combineFinalRenderer);
            updateSSAO();

            drawCombinedHdrImage(hdrImageRtv, GBuffer, combineFinalRenderer, skyColorRV, ssao.MSsaoBuffer.pSRV);
            updateTonemapLuminance(calculater);

            context.ClearState();
            game.SetBackbuffer();
            context.OutputMerger.SetTargets(postProcessRT1.RTV);

            toneMap.DrawTonemapped(hdrImageRV, calculater.CurrAverageLumRV);

            context.ClearState();
            game.SetBackbuffer();
            fogRenderer.PostProcessFog(postProcessRT1.RV, GBuffer, postProcessRT2.RTV);
            context.ClearState();
            game.SetBackbuffer();

            game.TextureRenderer.Draw(postProcessRT2.RV, new Vector2(0, 0), new Vector2(screenWidth, screenHeight));
            // TODO: currently cheat
            context.OutputMerger.SetTargets(GBuffer.DepthStencilView, game.BackBufferRTV);

            //game.TextureRenderer.Draw(hdrImageRV, new Vector2(10, 10), new Vector2(100, 100));
            //drawLines();
            //game.TextureRenderer.Draw(directionalLightRenderer.CSMRenderer.ShadowMapRV, new Vector2(10, 10), new Vector2(550, 200));


            //var currAv = readPixel<float>(calculater.CurrAverageLumRV.Resource);
            //var av = 1e-5 + (float)Math.Exp(readPixel<float>(calculater.AverageLuminanceRV.Resource));
            //var text = string.Format("Average: {0:00.000}  Curr: {1:00.000}", av, currAv);
            //game.AddToWindowTitle(" " + text);
            //Console.WriteLine(text);
        }
Пример #26
0
        /// <summary>
        /// 内部objectを破棄します。
        /// </summary>
        public void Dispose()
        {
            figures.Dispose();

            if (ctx != null)
            {
                ctx.ClearState();
                ctx.Flush();
                ctx.Dispose();
            }

            default_rasterizer_state.Dispose();
            default_depth_stencil_state.Dispose();
            default_blend_state.Dispose();

            if (ztex_view != null)
            {
                ztex_view.Dispose();
            }
            if (ztex != null)
            {
                ztex.Dispose();
            }

            if (buf0_view != null)
            {
                buf0_view.Dispose();
            }
            if (buf0 != null)
            {
                buf0.Dispose();
            }

            if (swap_chain != null)
            {
                swap_chain.Dispose();
            }

            if (il != null)
            {
                il.Dispose();
            }
            if (effect != null)
            {
                effect.Dispose();
            }
            if (device != null)
            {
                device.Dispose();
            }
        }
Пример #27
0
        private static void ResizeSwapchain(int width, int height)
        {
            DeviceContext.ClearState();
            if (Backbuffer != null)
            {
                Backbuffer.Release();
                m_swapchain.ResizeBuffers(MyRender11Constants.BUFFER_COUNT, width, height, MyRender11Constants.DX11_BACKBUFFER_FORMAT, SwapChainFlags.AllowModeSwitch);
            }

            Backbuffer = new MyBackbuffer(m_swapchain.GetBackBuffer <Resource>(0));

            m_resolution = new Vector2I(width, height);
            CreateScreenResources();
            ResetShadows(MyRenderProxy.Settings.ShadowCascadeCount, RenderSettings.ShadowQuality.ShadowCascadeResolution());
        }
Пример #28
0
        private void UpdateCubeFace(DeviceContext context, int index, Action <DeviceContext, Matrix, Matrix, RenderTargetView, DepthStencilView, DynamicCubeMap> renderScene)
        {
            // Prepare pipeline
            context.ClearState();
            context.OutputMerger.SetRenderTargets(EnvMapDSVs[index], EnvMapRTVs[index]);
            context.Rasterizer.SetViewport(Viewport);

            // Render the scene using the view, projection, RTV and DSV of this cube face
            renderScene(context, Cameras[index].View, Cameras[index].Projection, EnvMapRTVs[index], EnvMapDSVs[index], this);

            // Unbind the RTV and DSV
            context.OutputMerger.ResetTargets();
            // Prepare the SRV mip levels
            context.GenerateMips(EnvMapSRV);
        }
Пример #29
0
        internal void Clear()
        {
            if (m_deviceContext != null)
            {
                m_deviceContext.ClearState();
            }

            m_inputLayout       = null;
            m_primitiveTopology = PrimitiveTopology.Undefined;
            m_indexBufferRef    = null;
            m_indexBufferFormat = 0;
            m_indexBufferOffset = 0;
            for (int i = 0; i < m_vertexBuffers.Length; i++)
            {
                m_vertexBuffers[i] = null;
            }
            for (int i = 0; i < m_vertexBuffersStrides.Length; i++)
            {
                m_vertexBuffersStrides[i] = 0;
            }
            for (int i = 0; i < m_vertexBuffersByteOffset.Length; i++)
            {
                m_vertexBuffersByteOffset[i] = 0;
            }

            m_blendState        = null;
            m_stencilRef        = 0;
            m_depthStencilState = null;
            m_rtvsCount         = 0;
            for (int i = 0; i < m_rtvs.Length; i++)
            {
                m_rtvs[i] = null;
            }
            m_dsv = null;

            m_rasterizerState    = null;
            m_scissorLeftTop     = new Vector2I(-1, -1);
            m_scissorRightBottom = new Vector2I(-1, -1);
            m_viewport           = default(RawViewportF);

            m_targetBuffer  = null;
            m_targetOffsets = 0;

            if (m_statistics != null)
            {
                m_statistics.ClearStates++;
            }
        }
    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);
        }
    }
Пример #31
0
        public void Update(Device device, DeviceContext context, RenderTargetView renderTargetView)
        {
            bool isNewDevice = false;
            if (device != _device)
            {
                _device = device;
                CreateDeviceResources();
                isNewDevice = true;
            }
            
            _deviceContext = context;
            _renderTargetview = renderTargetView;

            _deviceContext.ClearState();

            CreateWindowSizeDependentResources(isNewDevice);
        }