示例#1
0
        public MainPage()
        {
            this.InitializeComponent();

            m_ctx       = new ResourceCreateContext();
            m_swapChain = new CompositionSwapChainResources(m_ctx, m_swapChainPanel);

            var display = DisplayInformation.GetForCurrentView();

            display.DpiChanged += new TypedEventHandler <DisplayInformation, object>(OnDpiChanged);
            m_triangle          = makeTriangle(m_ctx);
            m_compute           = makeCompute(m_ctx);

            m_buffer  = m_ctx.CreateByteAddressBuffer(4096, ResourceState.CopyDestination);
            m_texture = m_ctx.CreateTexture2D(256, 256, 1, GraphicsFormat.R8_UNORM, ResourceState.CopyDestination);

            var ctx = m_swapChain.CreateGraphicsComputeCommandContext();

            {
                float[] positions =
                {
                    0.0f,  0.5f, 0.5f, 1.0f,
                    -0.5f, 0.0f, 0.5f, 1.0f,
                    0.5f,  0.0f, 0.5f, 1.0f
                };

                byte[] b0 = new byte[positions.Length * 4];
                Buffer.BlockCopy(positions, 0, b0, 0, b0.Length);

                float[] colors =
                {
                    1.0f, 0.0f, 0.0f,
                    0.0f, 1.0f, 0.0f,
                    0.0f, 0.0f, 1.0f
                };

                byte[] b1 = new byte[colors.Length * 4];
                Buffer.BlockCopy(colors, 0, b1, 0, b1.Length);

                ctx.UpdateBuffer(m_buffer, 0, b0);
                ctx.UpdateBuffer(m_buffer, (uint)b0.Length, b1);
            }

            {
                var subResourceData = new SubresourceData();

                subResourceData.Data       = GenerateTextureData();
                subResourceData.RowPitch   = 256;
                subResourceData.SlicePitch = 256 * 256;

                SubresourceData[] datas = { subResourceData };

                ctx.UploadResource(m_texture, 0, 1, datas);
            }

            ctx.TransitionResource(m_texture, ResourceState.CopyDestination, ResourceState.PixelShaderResource | ResourceState.NonPixelShaderResource);
            ctx.TransitionResource(m_buffer, ResourceState.CopyDestination, ResourceState.NonPixelShaderResource);

            ctx.SubmitAndWaitToExecute();
        }
示例#2
0
        ComputePipelineState makeCompute(ResourceCreateContext ctx)
        {
            var code        = UniqueCreator.Graphics.Gpu.Shaders.compute_cs.Factory.Create();
            var description = new ComputePipelineStateDescription();

            description.CS = code;
            return(new ComputePipelineState(m_ctx, description));
        }
        public MainPage()
        {
            this.InitializeComponent();

            m_ctx       = new ResourceCreateContext();
            m_swapChain = new CompositionSwapChainResources(m_ctx, m_swapChainPanel);

            var display = DisplayInformation.GetForCurrentView();

            display.DpiChanged += new TypedEventHandler <DisplayInformation, object>(OnDpiChanged);

            var ctx = m_swapChain.CreateGraphicsComputeCommandContext();

            m_mechanicMaterial = new DerivativesSkinnedMaterial(m_ctx, ctx, "");
            m_mechanicModel    = new DerivativesSkinnedModel(m_mechanicMaterial, m_ctx, ctx, @"Assets\\models\\military_mechanic.derivatives_skinned_model.model");
            m_mechanicInstance = new DerivativesSkinnedModelInstance(m_mechanicModel, identity());

            ctx.SubmitAndWaitToExecute();

            m_lighting = makeLighting(m_ctx);
        }
示例#4
0
        GraphicsPipelineState makeTriangle(ResourceCreateContext ctx)
        {
            var triangleVertex = UniqueCreator.Graphics.Gpu.Shaders.triangle_vertex.Factory.Create();
            var trianglePixel  = UniqueCreator.Graphics.Gpu.Shaders.triangle_pixel.Factory.Create();

            var description2 = new GraphicsPipelineStateDescription();

            var rasterizerState = new RasterizerDescription();

            var samples = new SampleDescription
            {
                Count   = 1,
                Quality = 0
            };

            var depthStencil = new DepthStencilDescription
            {
                DepthEnable    = true,
                StencilEnable  = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthFunc      = ComparisonFunction.Less
            };

            depthStencil.BackFace.StencilFailOperation      = StencilOperation.Keep;
            depthStencil.BackFace.StencilPassOperation      = StencilOperation.Keep;
            depthStencil.BackFace.StencilFunction           = ComparisonFunction.Always;
            depthStencil.BackFace.StencilDepthFailOperation = StencilOperation.Keep;
            depthStencil.FrontFace        = depthStencil.BackFace;
            depthStencil.StencilReadMask  = 0xff;
            depthStencil.StencilWriteMask = 0xff;


            rasterizerState.CullMode = CullMode.Back;
            rasterizerState.FillMode = FillMode.Solid;
            rasterizerState.FrontCounterClockwise = true;
            rasterizerState.AntialiasedLineEnable = false;
            rasterizerState.ConservativeRaster    = ConservativeRasterizationMode.Off;
            rasterizerState.DepthBias             = 0;
            rasterizerState.DepthBiasClamp        = 0.0f;
            rasterizerState.SlopeScaledDepthBias  = 0.0f;
            rasterizerState.DepthClipEnable       = true;
            rasterizerState.ForcedSampleCount     = 0;
            rasterizerState.MultisampleEnable     = false;

            var blendState = new BlendDescription
            {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false
            };

            var blend = new RenderTargetBlendDescription
            {
                BlendEnable           = false,
                LogicOperationEnable  = false,
                BlendOperation        = BlendOperation.Add,
                BlendOperationAlpha   = BlendOperation.Add,
                LogicOperation        = LogicOperation.Clear,
                DestinationBlend      = Blend.DestinationColor,
                DestinationBlendAlpha = Blend.DestinationAlpha,
                SourceBlend           = Blend.SourceColor,
                SourceBlendAlpha      = Blend.SourceAlpha,
                RenderTargetWriteMask = 0xF
            };

            blendState.RenderTargets = new RenderTargetBlendDescription[] { blend };

            description2.VS                = triangleVertex;
            description2.PS                = trianglePixel;
            description2.SampleMask        = 0xFFFFFFFF;
            description2.RasterizerState   = rasterizerState;
            description2.PrimitiveTopology = PrimitiveTopologyType.Triangle;
            description2.Samples           = samples;
            description2.DepthStencilState = depthStencil;
            description2.DsvFormat         = GraphicsFormat.D32_Single;
            description2.IbStripCutValue   = IndexBufferStripCut.ValueDisabled;
            description2.BlendState        = blendState;
            description2.RtvFormats.Add(GraphicsFormat.R8G8B8A8_UNORM);

            return(new GraphicsPipelineState(ctx, description2));
        }