Esempio n. 1
0
        public void CreateDeviceObjects(GraphicsDevice gd, CommandList cl)
        {
            var factory = new DisposingResourceFactoryFacade(gd.ResourceFactory, _disposer);

            DeviceBuffer MakeBuffer(uint size, string name)
            {
                var buffer = factory.CreateBuffer(
                    new BufferDescription(size, BufferUsage.UniformBuffer | BufferUsage.Dynamic));

                buffer.Name = name;
                return(buffer);
            }

            ProjectionMatrixBuffer = MakeBuffer(64, "M_Projection");
            ModelViewMatrixBuffer  = MakeBuffer(64, "M_View");
            IdentityMatrixBuffer   = MakeBuffer(64, "M_Id");
            DepthLimitsBuffer      = MakeBuffer((uint)Unsafe.SizeOf <DepthCascadeLimits>(), "B_DepthLimits");
            CameraInfoBuffer       = MakeBuffer((uint)Unsafe.SizeOf <CameraInfo>(), "B_CameraInfo");

            cl.UpdateBuffer(IdentityMatrixBuffer, 0, Matrix4x4.Identity);

            var commonLayoutDescription = new ResourceLayoutDescription(
                ResourceLayoutHelper.Uniform("vdspv_1_0"),  // CameraInfo / common data buffer
                ResourceLayoutHelper.UniformV("vdspv_1_1"), // Perspective Matrix
                ResourceLayoutHelper.UniformV("vdspv_1_2"), // View Matrix
                ResourceLayoutHelper.Texture("vdspv_1_3")); // PaletteTexture

            CommonResourceLayout      = factory.CreateResourceLayout(commonLayoutDescription);
            CommonResourceLayout.Name = "RL_Common";

            _windowSized = new WindowSizedSceneContext(gd, MainSceneSampleCount);
            _disposer.Add(_windowSized, CommonResourceLayout);
        }
Esempio n. 2
0
        public WindowSizedSceneContext(GraphicsDevice gd, TextureSampleCount sampleCount)
        {
            _disposer.DisposeAll();
            ResourceFactory factory = new DisposingResourceFactoryFacade(gd.ResourceFactory, _disposer);

            TextureSamplerResourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription(
                                                                            new ResourceLayoutElementDescription(
                                                                                "SourceTexture",
                                                                                ResourceKind.TextureReadOnly,
                                                                                ShaderStages.Fragment),

                                                                            new ResourceLayoutElementDescription(
                                                                                "SourceSampler",
                                                                                ResourceKind.Sampler,
                                                                                ShaderStages.Fragment)));

            TextureSamplerResourceLayout.Name = "RL_TextureSampler";

            gd.GetPixelFormatSupport(
                PixelFormat.R16_G16_B16_A16_Float,
                TextureType.Texture2D,
                TextureUsage.RenderTarget,
                out PixelFormatProperties properties);

            while (!properties.IsSampleCountSupported(sampleCount))
            {
                sampleCount--;
            }

            TextureDescription mainColorDesc = TextureDescription.Texture2D(
                gd.SwapchainFramebuffer.Width,
                gd.SwapchainFramebuffer.Height,
                1,
                1,
                PixelFormat.R16_G16_B16_A16_Float,
                TextureUsage.RenderTarget | TextureUsage.Sampled,
                sampleCount);

            MainSceneColorTexture      = factory.CreateTexture(ref mainColorDesc);
            MainSceneColorTexture.Name = "T_MainSceneColor";

            if (sampleCount != TextureSampleCount.Count1)
            {
                mainColorDesc.SampleCount          = TextureSampleCount.Count1;
                MainSceneResolvedColorTexture      = factory.CreateTexture(ref mainColorDesc);
                MainSceneResolvedColorTexture.Name = "T_MainSceneResolvedColor";
            }
            else
            {
                MainSceneResolvedColorTexture = MainSceneColorTexture;
            }

            MainSceneResolvedColorView = factory.CreateTextureView(MainSceneResolvedColorTexture);
            MainSceneDepthTexture      = factory.CreateTexture(TextureDescription.Texture2D(
                                                                   gd.SwapchainFramebuffer.Width,
                                                                   gd.SwapchainFramebuffer.Height,
                                                                   1,
                                                                   1,
                                                                   PixelFormat.R32_Float,
                                                                   TextureUsage.DepthStencil,
                                                                   sampleCount));
            MainSceneFramebuffer     = factory.CreateFramebuffer(new FramebufferDescription(MainSceneDepthTexture, MainSceneColorTexture));
            MainSceneViewResourceSet = factory.CreateResourceSet(
                new ResourceSetDescription(
                    TextureSamplerResourceLayout,
                    MainSceneResolvedColorView, gd.PointSampler));

            MainSceneResolvedColorView.Name = "TV_MainSceneResolvedColor";
            MainSceneDepthTexture.Name      = "T_MainSceneDepth";
            MainSceneFramebuffer.Name       = "FB_MainFrame";
            MainSceneViewResourceSet.Name   = "RS_MainFrame";

            TextureDescription colorTargetDesc = TextureDescription.Texture2D(
                gd.SwapchainFramebuffer.Width,
                gd.SwapchainFramebuffer.Height,
                1,
                1,
                PixelFormat.R16_G16_B16_A16_Float,
                TextureUsage.RenderTarget | TextureUsage.Sampled);

            DuplicatorTarget0     = factory.CreateTexture(ref colorTargetDesc);
            DuplicatorTargetView0 = factory.CreateTextureView(DuplicatorTarget0);
            DuplicatorTargetSet0  = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView0, gd.PointSampler));

            DuplicatorTarget0.Name     = "T_DuplicatorTarget";
            DuplicatorTargetView0.Name = "TV_DuplicatorTarget";
            DuplicatorTargetSet0.Name  = "RS_DuplicatorTarget";

            FramebufferDescription fbDesc = new FramebufferDescription(null, DuplicatorTarget0);

            DuplicatorFramebuffer      = factory.CreateFramebuffer(ref fbDesc);
            DuplicatorFramebuffer.Name = "FB_Duplicator";
        }