public void Initialize() { // Pipeline state. var testShaderPath = "../../../../../Resources/Engine/MipMap.hlsl"; ComputeShader = ShaderBytecode.CompileFromFile(testShaderPath, "GenerateMipMaps", "cs_5_0"); // Root parameters. var rootParameters = new RootParameter[] { new RootParameter(ShaderVisibility.All, new RootConstants(0, 0, 2)), new RootParameter(ShaderVisibility.Pixel, new DescriptorRange() { RangeType = DescriptorRangeType.ShaderResourceView, DescriptorCount = 1, OffsetInDescriptorsFromTableStart = int.MinValue, // D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND BaseShaderRegister = 0 }), new RootParameter(ShaderVisibility.Pixel, new DescriptorRange() { RangeType = DescriptorRangeType.UnorderedAccessView, BaseShaderRegister = 0, OffsetInDescriptorsFromTableStart = int.MinValue, // D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND DescriptorCount = 1 }), }; var staticSamplers = new StaticSamplerDescription[] { new StaticSamplerDescription() { Filter = Filter.MinMagLinearMipPoint, AddressUVW = TextureAddressMode.Clamp, MipLODBias = 0f, ComparisonFunc = Comparison.Never, MinLOD = 0f, MaxLOD = float.MaxValue, MaxAnisotropy = 0, BorderColor = StaticBorderColor.OpaqueBlack, ShaderRegister = 0, RegisterSpace = 0, ShaderVisibility = ShaderVisibility.All } }; var rootSignatureDescription = new RootSignatureDescription( RootSignatureFlags.AllowInputAssemblerInputLayout, rootParameters, staticSamplers); RootSignature = RootSignature.Create(Device, rootSignatureDescription); Layout = new DescriptorLayout( DescriptorLayout.EntryType.ConstantBufferShaderResourceOrUnorderedAccessView, DescriptorLayout.EntryType.ConstantBufferShaderResourceOrUnorderedAccessView); }
public void Initialize() { // Pipeline state. var testShaderPath = "../../../../../Resources/Engine/Forward/Standard.hlsl"; VertexShader = ShaderBytecode.CompileFromFile(testShaderPath, "VSMain", "vs_5_0"); PixelShader = ShaderBytecode.CompileFromFile(testShaderPath, "PSMain", "ps_5_0"); // Root parameters. var rootParameters = new RootParameter[] { new RootParameter(ShaderVisibility.All, new DescriptorRange() { RangeType = DescriptorRangeType.ConstantBufferView, BaseShaderRegister = 0, OffsetInDescriptorsFromTableStart = int.MinValue, DescriptorCount = 1, }), new RootParameter(ShaderVisibility.Pixel, new DescriptorRange() { RangeType = DescriptorRangeType.ShaderResourceView, DescriptorCount = 1, OffsetInDescriptorsFromTableStart = int.MinValue, BaseShaderRegister = 0 }), new RootParameter(ShaderVisibility.Pixel, new DescriptorRange() { RangeType = DescriptorRangeType.Sampler, BaseShaderRegister = 0, DescriptorCount = 1 }), }; var rootSignatureDescription = new RootSignatureDescription(RootSignatureFlags.AllowInputAssemblerInputLayout, rootParameters); RootSignature = RootSignature.Create(Device, rootSignatureDescription); Layout = new DescriptorLayout( DescriptorLayout.EntryType.ConstantBufferShaderResourceOrUnorderedAccessView, DescriptorLayout.EntryType.ConstantBufferShaderResourceOrUnorderedAccessView, DescriptorLayout.EntryType.SamplerState); }
public override void Init(GraphicalConfiguration config, ID3D12Device *device) { bool z = new RgbaColor() == new RgbaColor(); _pipelineManager = new PipelineManager(ComPtr <ID3D12Device> .CopyFromPointer(device)); _allocator = new GpuAllocator(ComPtr <ID3D12Device> .CopyFromPointer(device)); var verticesDesc = new GpuResourceDesc( GpuResourceFormat.Buffer((ulong)sizeof(Vertex) * 3), GpuMemoryType.CpuWriteOptimized, D3D12_RESOURCE_STATE_GENERIC_READ, GpuAllocFlags.ForceAllocateComitted ); //var triangleVertices = stackalloc Vertex[3] { // new Vertex // { // Position = new Vector3(0.0f, 0.25f, 0.0f), // Color = new Vector4(1.0f, 0.0f, 0.0f, 1.0f) // }, // new Vertex // { // Position = new Vector3(0.25f, -0.25f, 0.0f), // Color = new Vector4(0.0f, 1.0f, 0.0f, 1.0f) // }, // new Vertex // { // Position = new Vector3(-0.25f, -0.25f, 0.0f), // Color = new Vector4(0.0f, 0.0f, 1.0f, 1.0f) // }, //}; var cubeVertices = stackalloc Vertex[8] { new Vertex(new Vector3(-0.5f, -0.5f, -0.5f), new Vector4(0.0f, 0.0f, 0.0f, 1.0f)), new Vertex(new Vector3(-0.5f, -0.5f, 0.5f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)), new Vertex(new Vector3(-0.5f, 0.5f, -0.5f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f)), new Vertex(new Vector3(-0.5f, 0.5f, 0.5f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f)), new Vertex(new Vector3(0.5f, -0.5f, -0.5f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f)), new Vertex(new Vector3(0.5f, -0.5f, 0.5f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f)), new Vertex(new Vector3(0.5f, 0.5f, -0.5f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f)), new Vertex(new Vector3(0.5f, 0.5f, 0.5f), new Vector4(1.0f, 1.0f, 1.0f, 1.0f)) }; var cubeIndices = stackalloc ushort[36] { 0, 2, 1, // -x 1, 2, 3, 4, 5, 6, // +x 5, 7, 6, 0, 1, 5, // -y 0, 5, 4, 2, 6, 7, // +y 2, 7, 3, 0, 4, 6, // -z 0, 6, 2, 1, 3, 7, // +z 1, 7, 5, }; var vertices = _allocator.AllocateVertexBuffer <Vertex>(8, GpuMemoryType.CpuWriteOptimized, GpuAllocFlags.ForceAllocateComitted); var indices = _allocator.AllocateIndexBuffer <ushort>(36, GpuMemoryType.CpuWriteOptimized, GpuAllocFlags.ForceAllocateComitted); vertices.Resource.Map(0); Unsafe.CopyBlock(vertices.Resource.CpuAddress, cubeVertices, (uint)sizeof(Vertex) * 8); vertices.Resource.Unmap(0); indices.Resource.Map(0); Unsafe.CopyBlock(indices.Resource.CpuAddress, cubeIndices, (uint)sizeof(ushort) * 36); indices.Resource.Unmap(0); _vertexBuffer = vertices; _indexBuffer = indices; _rootSig = RootSignature.Create(device, default, default);