Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HRESULT LILY_API DxApplication::LoadPipeLine()
- {
- HRESULT Result;
- #ifdef DEBUG
- ID3D12Debug* DebugController;
- Result = D3D12GetDebugInterface(IID_PPV_ARGS(&DebugController));
- if (FAILED(Result))
- return Result;
- DebugController->EnableDebugLayer();
- #endif
- Result = CreateDXGIFactory(IID_PPV_ARGS(&m_Factory));
- if (FAILED(Result))
- return Result;
- Result = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_12_1, IID_PPV_ARGS(&m_Device));
- if (FAILED(Result))
- return Result;
- D3D12_COMMAND_QUEUE_DESC CommandQueueDesc = {};
- CommandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
- CommandQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
- Result = m_Device->CreateCommandQueue(&CommandQueueDesc, IID_PPV_ARGS(&m_CommandQueue));
- if(FAILED(Result))
- return Result;
- DXGI_SWAP_CHAIN_DESC1 SwapChainDesc = {};
- SwapChainDesc.SampleDesc.Count = 1;
- SwapChainDesc.SampleDesc.Quality = 0;
- SwapChainDesc.BufferCount = g_BufferCount;
- SwapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
- SwapChainDesc.Width = m_ClientWidth;
- SwapChainDesc.Height = m_ClientHeight;
- IDXGISwapChain1* OldSwapChain;
- Result = m_Factory->CreateSwapChainForHwnd(m_CommandQueue.Get(), m_hAppWindow, &SwapChainDesc, NULL, NULL, &OldSwapChain);
- if (FAILED(Result))
- return Result;
- Result = OldSwapChain->QueryInterface(IID_PPV_ARGS(&m_SwapChain));
- if (FAILED(Result))
- return Result;
- /* aaaaaaaaaaaaaaaa */
- ID3DBlob* VertexShader;
- ID3DBlob* PixelShader;
- Result = D3DCompileFromFile(L"Shaders\\DefaultShader.hlsl", 0, 0, "vs_main", "vs_5_0", D3DCOMPILE_DEBUG, NULL, &VertexShader, nullptr);
- if (FAILED(Result))
- return Result;
- Result = D3DCompileFromFile(L"Shaders\\DefaultShader.hlsl", 0, 0, "ps_main", "ps_5_0", D3DCOMPILE_DEBUG, NULL, &PixelShader, nullptr);
- if (FAILED(Result))
- return Result;
- /* aaaaaaaaaaaaaaaa */
- CD3DX12_ROOT_SIGNATURE_DESC RootSignatureDesc = {};
- RootSignatureDesc.Init(NULL, nullptr, NULL, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
- ID3DBlob* RootSignatureBlob;
- ID3DBlob* RootSignatureBlobError;
- Result = D3D12SerializeRootSignature(&RootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &RootSignatureBlob, &RootSignatureBlobError);
- if (FAILED(Result))
- return Result;
- Result = m_Device->CreateRootSignature(NULL, RootSignatureBlob->GetBufferPointer(), RootSignatureBlob->GetBufferSize(), IID_PPV_ARGS(&m_RootSignature));
- if (FAILED(Result))
- return Result;
- D3D12_GRAPHICS_PIPELINE_STATE_DESC PipeLineDesc = {0};
- PipeLineDesc.VS.pShaderBytecode = VertexShader->GetBufferPointer();
- PipeLineDesc.VS.BytecodeLength = VertexShader->GetBufferSize();
- PipeLineDesc.pRootSignature = m_RootSignature.Get();
- PipeLineDesc.SampleMask = UINT_MAX;
- PipeLineDesc.NumRenderTargets = 1;
- PipeLineDesc.SampleDesc.Count = 1;
- PipeLineDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
- PipeLineDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
- PipeLineDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
- PipeLineDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
- PipeLineDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
- Result = m_Device->CreateGraphicsPipelineState(&PipeLineDesc, IID_PPV_ARGS(&m_PipelineState));
- if (FAILED(Result))
- return Result;
- D3D12_DESCRIPTOR_HEAP_DESC DescriptorHeadDesc = {};
- DescriptorHeadDesc.NumDescriptors = g_BufferCount;
- DescriptorHeadDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
- Result = m_Device->CreateDescriptorHeap(&DescriptorHeadDesc, IID_PPV_ARGS(&m_DescriptorHeap));
- if (FAILED(Result))
- return Result;
- D3D12_CPU_DESCRIPTOR_HANDLE RtvHandleDesc = m_DescriptorHeap->GetCPUDescriptorHandleForHeapStart();
- for (int Buffer = 0; Buffer < g_BufferCount; Buffer++)
- {
- //ID3D12Resource* BufferResource;
- Result = m_SwapChain->GetBuffer(Buffer, IID_PPV_ARGS(&m_RenderTarget[Buffer]));
- if (FAILED(Result))
- return Result;
- m_Device->CreateRenderTargetView(m_RenderTarget[Buffer].Get(), nullptr, RtvHandleDesc);
- m_DescriptorHandle[Buffer] = RtvHandleDesc;
- RtvHandleDesc.ptr += m_Device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
- Result = m_Device->CreateCommandAllocator(CommandQueueDesc.Type, IID_PPV_ARGS(&m_CommandAllocator[Buffer]));
- if (FAILED(Result))
- return Result;
- }
- return Result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement