예제 #1
0
    inline void ID3D12DeviceEx::createCommandContext(CommandContext<T, N, L>* commandContext,
                                                     const bool isHighPriority,
                                                     const bool disableGpuTimeout) {
        static_assert(N > 0 && L > 0, "Invalid command context parameters.");
        assert(commandContext);
        // Fill out the command queue description.
        const D3D12_COMMAND_QUEUE_DESC queueDesc = {
            /* Type */     static_cast<D3D12_COMMAND_LIST_TYPE>(T),
            /* Priority */ isHighPriority ? D3D12_COMMAND_QUEUE_PRIORITY_HIGH
                                          : D3D12_COMMAND_QUEUE_PRIORITY_NORMAL,
            /* Flags */    disableGpuTimeout ? D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT
                                             : D3D12_COMMAND_QUEUE_FLAG_NONE,
            /* NodeMask */ nodeMask
        };
        // Create a command queue.
        CHECK_CALL(CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&commandContext->m_commandQueue)),
                   "Failed to create a command queue.");
        // Create command allocators.
        for (size_t i = 0; i < N; ++i) {
            for (size_t j = 0; j < L; ++j) {
                CHECK_CALL(CreateCommandAllocator(static_cast<D3D12_COMMAND_LIST_TYPE>(T),
                           IID_PPV_ARGS(&commandContext->m_commandAllocators[i][j])),
                           "Failed to create a command list allocator.");
            }
        }
        // Set the initial frame allocator set index to 0.
        commandContext->m_frameAllocatorSet = 0;
        // Create command lists in the closed, NULL state using the initial allocator.
        for (size_t i = 0; i < L; ++i) {
            CHECK_CALL(CreateCommandList(nodeMask, static_cast<D3D12_COMMAND_LIST_TYPE>(T),
                                         commandContext->m_commandAllocators[0][i].Get(), nullptr,
                                         IID_PPV_ARGS(&commandContext->m_commandLists[i])),
                       "Failed to create a command list.");
            CHECK_CALL(commandContext->m_commandLists[i]->Close(),
                       "Failed to close the command list.");

        }
        // Create a 0-initialized fence object.
        commandContext->m_fenceValue = 0;
        CHECK_CALL(CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&commandContext->m_fence)),
                   "Failed to create a fence object.");
        // Set the last fence value for each command allocator to 0.
        for (size_t i = 0; i < N; ++i) {
            commandContext->m_lastFenceValues[i] = 0;
        }
        // Create a synchronization event.
        commandContext->m_syncEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
        if (!commandContext->m_syncEvent) {
            CHECK_CALL(HRESULT_FROM_WIN32(GetLastError()),
                       "Failed to create a synchronization event.");
        }
    }
예제 #2
0
bool DXManager::InitDX12(HWND hWnd, int windowHeight, int windowWidth)
{
	HRESULT hr = S_FALSE;

	hr = CreateFactory();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Factory.");
		return false;
	}

	hr = CreateAdapter();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Adapter.");
		return false;
	}

	hr = CreateAdapterOutput();
	if (FAILED(hr))
	{
		Log::LogError("DXManager Can't Create Adapter Output.");
		return false;
	}

	hr = CreateDisplayModList();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Display Mod List.");
		return false;
	}

	hr = CreateAdapterDesc();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Adapter Desc.");
		return false;
	}

	hr = CreateDivice();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Device.");
		return false;
	}

	hr = CreateComandQueue();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Command Queue.");
		return false;
	}

	hr = CreateSwapChain();
	if (FAILED(hr))
	{
		Log::LogError("DXManager Can't Create Swap Chain.");
		return false;
	}

	hr = CreateCommandAllocator();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Command Allocator.");
		return false;
	}

	hr = CreateCommandList();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Command List.");
		return false;
	}
	
	hr = CreateFence();
	if (FAILED(hr))
	{
		Log::LogError("DXManager::Can't Create Fence.");
		return false;
	}

	return true;
}