private unsafe void CreateDeviceDependentResourcesInternal()
        {
            ID3D12Device *d3dDevice = _deviceResources.D3DDevice;

            {
                D3D12_DESCRIPTOR_RANGE range =
                    CD3DX12_DESCRIPTOR_RANGE.Create(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0);
                CD3DX12_ROOT_PARAMETER.InitAsDescriptorTable(out D3D12_ROOT_PARAMETER parameter, 1, &range, D3D12_SHADER_VISIBILITY_VERTEX);

                D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
                    D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | // Only the input assembler stage needs access to the constant buffer.
                    D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
                    D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
                    D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS |
                    D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS;

                CD3DX12_ROOT_SIGNATURE_DESC.Init(out D3D12_ROOT_SIGNATURE_DESC descRootSignature, 1, &parameter, 0, null, rootSignatureFlags);

                var pSignature = new ComPtr <ID3DBlob>();
                var pError     = new ComPtr <ID3DBlob>();

                ThrowIfFailed(D3D12SerializeRootSignature(&descRootSignature, D3D_ROOT_SIGNATURE_VERSION_1, pSignature.GetAddressOf(), pError.GetAddressOf()));

                Guid iid = IID_ID3D12RootSignature;
                ID3D12RootSignature *rootSignature;
                ThrowIfFailed(d3dDevice->CreateRootSignature(0, pSignature.Ptr->GetBufferPointer(), pSignature.Ptr->GetBufferSize(), &iid, (void **)&rootSignature));
                _rootSignature = rootSignature;
                NameD3D12Object(_rootSignature.Ptr, nameof(_rootSignature));
            }
        }
Пример #2
0
 public static void Init([NativeTypeName("D3D12_ROOT_SIGNATURE_DESC1 &")] out D3D12_ROOT_SIGNATURE_DESC1 desc, uint numParameters, [NativeTypeName("const D3D12_ROOT_PARAMETER1 *")] D3D12_ROOT_PARAMETER1 *_pParameters, uint numStaticSamplers = 0, [NativeTypeName("const D3D12_STATIC_SAMPLER_DESC *")] D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = null, D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
 {
     desc.NumParameters     = numParameters;
     desc.pParameters       = _pParameters;
     desc.NumStaticSamplers = numStaticSamplers;
     desc.pStaticSamplers   = _pStaticSamplers;
     desc.Flags             = flags;
 }
Пример #3
0
 public void Init(uint numParameters, [NativeTypeName("const D3D12_ROOT_PARAMETER1 *")] D3D12_ROOT_PARAMETER1 *_pParameters, uint numStaticSamplers = 0, [NativeTypeName("const D3D12_STATIC_SAMPLER_DESC *")] D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = null, D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)
 {
     Init(out this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
 }
Пример #4
0
        private async void CreateDeviceDependentResources()
        {
            unsafe
            {
                ID3D12Device *d3dDevice = _deviceResources.D3DDevice;

                {
                    D3D12_DESCRIPTOR_RANGE range =
                        CD3DX12_DESCRIPTOR_RANGE.Create(D3D12_DESCRIPTOR_RANGE_TYPE.D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0);
                    CD3DX12_ROOT_PARAMETER.InitAsDescriptorTable(out D3D12_ROOT_PARAMETER parameter, 1, &range,
                                                                 D3D12_SHADER_VISIBILITY.D3D12_SHADER_VISIBILITY_VERTEX);

                    D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
                        D3D12_ROOT_SIGNATURE_FLAGS
                        .D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |     // Only the input assembler stage needs access to the constant buffer.
                        D3D12_ROOT_SIGNATURE_FLAGS.D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
                        D3D12_ROOT_SIGNATURE_FLAGS.D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
                        D3D12_ROOT_SIGNATURE_FLAGS.D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS |
                        D3D12_ROOT_SIGNATURE_FLAGS.D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS;

                    CD3DX12_ROOT_SIGNATURE_DESC.Init(out D3D12_ROOT_SIGNATURE_DESC descRootSignature, 1, &parameter, 0,
                                                     null, rootSignatureFlags);

                    var pSignature = new ComPtrField <ID3DBlob>();
                    var pError     = new ComPtrField <ID3DBlob>();

                    ThrowIfFailed(D3D12.D3D12SerializeRootSignature(&descRootSignature,
                                                                    D3D_ROOT_SIGNATURE_VERSION.D3D_ROOT_SIGNATURE_VERSION_1, pSignature.DangerousGetAddressOf(),
                                                                    pError.DangerousGetAddressOf()));

                    Guid iid = D3D12.IID_ID3D12RootSignature;
                    ID3D12RootSignature *rootSignature;
                    ThrowIfFailed(d3dDevice->CreateRootSignature(0, pSignature.Ptr->GetBufferPointer(),
                                                                 pSignature.Ptr->GetBufferSize(), &iid, (void **)&rootSignature));
                    _rootSignature = rootSignature;
                    DX.NameD3D12Object(_rootSignature.Ptr, nameof(_rootSignature));
                }
            }

            Task vertexShaderRead = ((Func <Task>)(async() =>
            {
                const string fileName = "Content/SampleVertexShader.cso";

                var size = (UIntPtr) new FileInfo(fileName).Length;
                byte[] shader = await File.ReadAllBytesAsync(fileName);

                unsafe
                {
                    CopyBytesToBlob(out _vertexShader.GetPinnableReference(), size, shader);
                }
            }))();

            Task pixelShaderRead = ((Func <Task>)(async() =>
            {
                const string fileName = "Content/SamplePixelShader.cso";

                var size = (UIntPtr) new FileInfo(fileName).Length;
                byte[] shader = await File.ReadAllBytesAsync(fileName);

                unsafe
                {
                    CopyBytesToBlob(out _pixelShader.GetPinnableReference(), size, shader);
                }
            }))();

            await CreatePipelineState(vertexShaderRead, pixelShaderRead).ContinueWith(CreateRendererAssets);
        }