Esempio n. 1
0
        public override void Initialize(Size outputSize, IOutputOwner output)
        {
#if DEBUG
            var debug = DebugLayerConfiguration.Debug.AddDebugFlags(DebugFlags.GpuBasedValidation);
#else
            var debug = DebugLayerConfiguration.None;
#endif

            _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null, debug);
            _output = Output.Create(OutputConfiguration.Default, _device, output);

            using (var copy = _device.BeginUploadContext())
            {
                _colors = copy.UploadBuffer(GetColors());
            }

            var @params = new RootParameter[]
            {
                RootParameter.CreateDescriptor(RootParameterType.ShaderResourceView, 0, 0, ShaderVisibility.Pixel),
                RootParameter.CreateConstants <MandelbrotConstants>(0, 0, ShaderVisibility.Pixel),
            };

            var rootSig = _device.CreateRootSignature(@params, null);

            var flags = new ShaderCompileFlag[]
            {
                ShaderCompileFlag.EnableDebugInformation,
                ShaderCompileFlag.WriteDebugInformationToFile(),
                ShaderCompileFlag.DefineMacro("ITER", IterCount.ToString()),
#if DOUBLE
                ShaderCompileFlag.DefineMacro("DOUBLE")
#endif
            };

            var psoDesc = new GraphicsPipelineDesc
            {
                RootSignature       = rootSig,
                Topology            = TopologyClass.Triangle,
                DepthStencil        = DepthStencilDesc.DisableDepthStencil,
                RenderTargetFormats = BackBufferFormat.R8G8B8A8UnsignedNormalized,
                VertexShader        = ShaderManager.CompileShader("Shaders/Mandelbrot/EntireScreenCopyVS.hlsl", ShaderType.Vertex, flags),
                PixelShader         = ShaderManager.CompileShader("Shaders/Mandelbrot/Mandelbrot.hlsl", ShaderType.Pixel, flags),
                Rasterizer          = RasterizerDesc.Default.WithFrontFaceType(FaceType.Anticlockwise)
            };

            _pso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "Mandelbrot");

            _constants = new MandelbrotConstants
            {
                Scale      = (FloatType)1,
                CenterX    = (FloatType)(-1.789169018604823106674468341188838763),
                CenterY    = (FloatType)(0.00000033936851576718256602823026614),
                ColorCount = _colors.LengthAs <Rgba128>()
            };

            OnResize(outputSize);
        }
Esempio n. 2
0
        public BasicSceneRenderer(GraphicsDevice device)
        {
            _device = device;

            _rtvs          = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1);
            _dsvs          = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1);
            _textureHandle = _device.AllocateResourceDescriptors(2);

            _texturedObjects = ModelLoader.LoadGl_Old("Assets/Gltf/Handgun_NoTangent.gltf");
            //_texturedObjects = new[] { GeometryGenerator.CreateCube(0.5f) };

            var texture = TextureLoader.LoadTextureDesc("Assets/Textures/handgun_c.dds");
            var normals = TextureLoader.LoadTextureDesc("Assets/Textures/handgun_n.dds");

            _vertexBuffer = new Buffer[_texturedObjects.Length];
            _indexBuffer  = new Buffer[_texturedObjects.Length];

            using (var list = _device.BeginUploadContext())
            {
                for (var i = 0; i < _texturedObjects.Length; i++)
                {
                    _vertexBuffer[i] = list.UploadBuffer(_texturedObjects[i].Vertices);
                    _vertexBuffer[i].SetName("VertexBuffer");

                    _indexBuffer[i] = list.UploadBuffer(_texturedObjects[i].Indices);
                    _indexBuffer[i].SetName("IndexBuffer");
                }

                _texture = list.UploadTexture(texture);
                _texture.SetName("Gun texture");
            }

            //list.UploadTexture(normals.Data.Span, normals.SubresourceData.Span, normals.Desc, ResourceState.PixelShaderResource, out _normals);
            //_normals.SetName("Gun normals");

            _device.CreateShaderResourceView(_texture, _textureHandle[0]);
            //_normalHandle = _device.CreateShaderResourceView(_normals);
            _objectConstants = new ObjectConstants[_texturedObjects.Length];

            _obj = _device.Allocator.AllocateBuffer(MathHelpers.AlignUp(sizeof(ObjectConstants), 256) * _texturedObjects.Length, MemoryAccess.CpuUpload);
            _obj.SetName("ObjectConstants buffer");

            _frame = _device.Allocator.AllocateBuffer(sizeof(FrameConstants), MemoryAccess.CpuUpload);
            _frame.SetName("FrameConstants buffer");

            _light = _device.Allocator.AllocateBuffer(sizeof(LightConstants), MemoryAccess.CpuUpload);
            _light.SetName("LightConstants buffer");

            CreatePipelines();
            InitializeConstants();
        }
Esempio n. 3
0
        public static void _Main()
        {
#if DEBUG
            var layer = DebugLayerConfiguration.Debug;
#else
            var layer = DebugLayerConfiguration.None;
#endif

            _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null, layer);

            var flags = Commit ? AllocFlags.ForceAllocateComitted : AllocFlags.ForceAllocateNotComitted;
            _sourceBuffer = _device.Allocator.AllocateBuffer(BuffLength, MemoryAccess.GpuOnly);
            _destBuffer   = _device.Allocator.AllocateBuffer(BuffLength, MemoryAccess.GpuOnly);

            var texDesc = TextureDesc.CreateShaderResourceDesc(DataFormat.R8G8B8A8UInt, TextureDimension.Tex2D, TexLength, TexLength);
            texDesc.MipCount = 1;
            _sourceTexture   = _device.Allocator.AllocateTexture(texDesc, ResourceState.CopySource, flags);
            _destTexture     = _device.Allocator.AllocateTexture(texDesc, ResourceState.Common, flags);

            var contexts = new (CopyContext, CopyContext, ulong)[]
Esempio n. 4
0
        private unsafe void SetConstants()
        {
            _frameConstants          = _device.Allocator.AllocateUploadBuffer <FrameConstants>();
            Chunks[0].Mesh.Constants = _device.Allocator.AllocateUploadBuffer <ChunkConstants>();

            FrameConstants *constants = _frameConstants.As <FrameConstants>();

            constants->View = Matrix4x4.CreateLookAt(
                new Vector3(0.0f, 0.7f, 1.5f),
                new Vector3(0.0f, -0.1f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f)
                );

            const float defaultFov = 70.0f * (float)Math.PI / 180.0f;

            constants->Projection = Matrix4x4.CreatePerspectiveFieldOfView(defaultFov, 1, 0.01f, 100f);

            ChunkConstants *chunkConstants = Chunks[0].Mesh.Constants.As <ChunkConstants>();

            chunkConstants->TexTransform = Matrix4x4.Identity;
            chunkConstants->World        = Matrix4x4.CreateTranslation(0, 0, -5);
        }