BOOL CImage::Create() { // if a command list was not passed in then create one if (!lpCmdList) { // if we don't have a command list, create one lpCmdList = CreateCommandList(); if ( !lpCmdList) return(FALSE); } // link command list back to image lpCmdList->ThreadData.lpImage = this; // setup image information for easy access LPFRAME lpFrame = GetBaseEditFrame(); npix = FrameXSize(lpFrame); nlin = FrameYSize(lpFrame); // if using threading and no command list already existence // create the command thread #ifdef WIN32 if (Control.UseThreading) { lstrcpy(lpCmdList->ThreadData.ThreadInfo.szThreadName, filename(CurFile)); } #endif return(TRUE); }
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."); } }
// -------------------------------------------------------------------------------------------------------------------- bool DynamicStreamingD3D12Bundle::Init(size_t _maxVertexCount) { m_VertexData = 0; if (!CreatePSO()) return false; if (!CreateGeometryBuffer(_maxVertexCount)) return false; if (!CreateCommandList()) return false; return true; }
void CubeObject::OnCreate() { CreateBuffers(); m_Scale = Vec3(1.0f, 1.0f, 1.0f); m_Qt.identity(); m_Pos = Vec3(0, 0, 0.0); ///ルートシグネチャ作成 CreateRootSignature(); ///デスクプリタヒープ作成 CreateDescriptorHeap(); ///コンスタントバッファ作成 CreateConstantBuffer(); ///パイプラインステート作成 CreatePipelineState(); ///コマンドリスト作成 CreateCommandList(); //コンスタントバッファの更新 UpdateConstantBuffer(); }
void Renderer::Initialize() { if (TargetWindow.GetHandle() == nullptr) { Utility::Throw(L"Window Handle is invalid!"); } CreateSwapChain(); CreateRTVHeap(); CreateDSVHeap(); CreateDepthStencilView(); InitializeRenderTargets(); CreateCommandList(); const Window::WindowSize & WindowSize = TargetWindow.GetWindowSize(); Camera.UpdateCamera(WindowSize); UpdateViewportAndScissorRect(WindowSize); Fence.Initialize(DeviceContext.GetDevice()); }
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; }
void SampleRenderer::Initialize() { m_RenderQueue = new ::Dispatch::WorkQueue("RenderQueue", ::Concurrency::ThreadPriority::High); m_RenderQueue->Loop(); isInitialized = false; float aspectRatio = 1900.f/700; float fovAngleY = 70.0f * XM_PI / 180.0f; if (aspectRatio < 1.0f) { fovAngleY *= 2.0f; } XMMATRIX perspectiveMatrix = XMMatrixPerspectiveFovRH(fovAngleY, aspectRatio, 0.01f, 100.0f); XMStoreFloat4x4(&m_MVP.projection, XMMatrixTranspose(perspectiveMatrix)); static const XMVECTORF32 eye = { 0.0f, 0.7f, 1.5f, 0.0f }; static const XMVECTORF32 at = { 0.0f, -0.1f, 0.0f, 0.0f }; static const XMVECTORF32 up = { 0.0f, 1.0f, 0.0f, 0.0f }; XMStoreFloat4x4(&m_MVP.model, XMMatrixTranspose(XMMatrixRotationY(1.57))); XMStoreFloat4x4(&m_MVP.view, XMMatrixTranspose(XMMatrixLookAtRH(eye, at, up))); auto d3dDevice = gD3DDevice->GetD3DDevice(); CD3DX12_ROOT_PARAMETER parameter[3]; CD3DX12_DESCRIPTOR_RANGE range; range.Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0); parameter[0].InitAsDescriptorTable(1, &range, D3D12_SHADER_VISIBILITY_VERTEX); CD3DX12_DESCRIPTOR_RANGE range2; range2.Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0); parameter[1].InitAsDescriptorTable(1, &range2, D3D12_SHADER_VISIBILITY_PIXEL); CD3DX12_DESCRIPTOR_RANGE range3; range3.Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0); parameter[2].InitAsDescriptorTable(1, &range3, D3D12_SHADER_VISIBILITY_PIXEL); D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | 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 descRootSignature; descRootSignature.Init(3, parameter, 0, nullptr, rootSignatureFlags); PtrBlob pSignature, pError; ThrowIfFailed(D3D12SerializeRootSignature(&descRootSignature, D3D_ROOT_SIGNATURE_VERSION_1, pSignature.GetInitReference(), pError.GetInitReference())); ThrowIfFailed(d3dDevice->CreateRootSignature(0, pSignature->GetBufferPointer(), pSignature->GetBufferSize(), IID_PPV_ARGS(m_RootSignature.GetInitReference()))); m_CopyQueue = new CopyQueue_tr(d3dDevice); m_CopyQueue->StartLoop(); m_RenderQueue->Queue(::Dispatch::Bind([this, d3dDevice]() { m_VS.Load("/Data/Test/Test.vso"); m_PS.Load("/Data/Test/Test.pso"); static const D3D12_INPUT_ELEMENT_DESC inputLayout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, }; D3D12_GRAPHICS_PIPELINE_STATE_DESC state = {}; state.InputLayout = { inputLayout, _countof(inputLayout) }; state.pRootSignature = m_RootSignature; state.VS = { m_VS.GetBlob()->GetBufferPointer(), m_VS.GetBlob()->GetBufferSize() }; state.PS = { m_PS.GetBlob()->GetBufferPointer(), m_PS.GetBlob()->GetBufferSize() }; state.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); state.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); state.DepthStencilState.DepthEnable = FALSE; state.DepthStencilState.StencilEnable = FALSE; state.SampleMask = UINT_MAX; state.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; state.NumRenderTargets = 1; state.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; state.SampleDesc.Count = 1; ThrowIfFailed(d3dDevice->CreateGraphicsPipelineState(&state, IID_PPV_ARGS(m_PipeLineState.GetInitReference()))); LogUtil::Out("Renderer", ::Concurrency::Thread::GetCurrentThreadName()); })); m_RenderQueue->Queue(::Dispatch::Bind([this, d3dDevice]() { ThrowIfFailed(d3dDevice->CreateCommandList(1, D3D12_COMMAND_LIST_TYPE_DIRECT, gD3DDevice->GetCommandAllocator(), m_PipeLineState, IID_PPV_ARGS(m_CmdList.GetInitReference()))); D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {}; heapDesc.NumDescriptors = DeviceManager::GetFrameCount(); heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; ThrowIfFailed(d3dDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(m_CBVHeap.GetInitReference()))); m_CBVHeap->SetName(L"Constant Buffer Heap"); m_samplerHeap.Create(d3dDevice, D3D12_DESCRIPTOR_HEAP_TYPE::D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, 1, true); D3D12_SAMPLER_DESC samplerDesc = {}; samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 1; samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = D3D12_FLOAT32_MAX; d3dDevice->CreateSampler(&samplerDesc, m_samplerHeap.hCPU(0)); m_CubeMesh = new CubeMesh(d3dDevice, m_CmdList); this->m_CopyQueue->SubmitTexture(L"\\Data\\Test\\seafloor2bc1.dds", m_CubeMesh); m_CBO = new UniformBuffer<ModelViewProjectionConstantBuffer>("ModeViewMatrix", d3dDevice, 1U); m_CBO->CreateOnHeap(m_CBVHeap, d3dDevice); m_ConstantBuffer = m_CBO->Map(); ZeroMemory(m_ConstantBuffer, DeviceManager::GetFrameCount() * m_CBO->sAlignedConstantBufferSize); ThrowIfFailed(m_CmdList->Close()); ID3D12CommandList* ppCommandLists[] = { m_CmdList }; gD3DDevice->GetCommandQueue()->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists); gD3DDevice->WaitForGPU(); isInitialized = true; })); }
BOOL PlayMacro(LPCMDLIST lpCmdList, LPTSTR lpFileName, int nRepeat, BOOL fSequenceAll, LPLIST lpMacroList, HWND hParent, int PhotoCDResOverride, LPTSTR lpMacroName) /***********************************************************************/ { LPIMAGE lpImage; LPCMDLIST lpNewList; int nActivates, iCount; ITEMID idCommand; STRING szString, szAppName; BOOL fError; BOOL fSequence, fCmdSequence, fCopyPackets; LIST MacroList; LPCMDPKT lpCmdPkt, lpNextPkt; MACROSETUP Setup; COMMAND_TYPE CommandType; HWND hDlg = NULL; lpAbortProc = NULL; if (!hParent) hParent = PictPubApp.Get_hWndAstral(); // see if we need to copy our packets fCopyPackets = nRepeat > 1; if (!lpMacroList) { // read in the entire macro file for faster processing if (!ReadMacro(lpFileName, &MacroList)) return(FALSE); lpMacroList = &MacroList; } // count the number of activates in the macro file // because it affects sequencing nActivates = CountType(lpMacroList, CT_ACTIVATE); // turn of macro play mode and tell the world MacroMode = MM_PLAY; if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) ) { if ( AstralStrEx( IDS_MACROPLAY, szString, sizeof(szString) ) ) { lstrcat( szAppName, szString ); SetWindowText( PictPubApp.Get_hWndAstral(), szAppName ); } } // reset untitled number so that if a macro is played it // can deal with untitled images the same Control.UntitledNo = 0; // If no command list passed in to work on (Macro Batch Mode) // then get command list for active image if (!lpCmdList) { if (lpImage = GetActiveImage()) lpCmdList = lpImage->lpCmdList; else lpCmdList = NULL; } // See if the macro contains any low res loads and // if so ask to user if he'd like to convert them // to hi res loads and if so do the convert if (FindCommand(lpMacroList, IDS_CMD_LOWRESLOAD)) if (AstralAffirm(IDS_CONVERTLOWRES)) if (!ConvertLowResLoad(lpMacroList)) { DestroyPacketList(lpMacroList); return(FALSE); } // disable all mouse and keyboard input during macro play EnableWindow(hParent, FALSE); // if not in a threading environment and caller wants us // to display a progress dialog, then set it up and do it if (!Control.UseThreading) { iCount = ListGetCount(lpMacroList) - nActivates; iCount *= nRepeat; Setup.iTotal = iCount; Setup.idDialog = IDD_MACRO_STATUS; Setup.lpFileName = NULL; hDlg = AstralDlgParam( YES, PictPubApp.GetResourceHandle(), hParent, IDD_MACRO_STATUS, DlgMacroStatusProc, (LPARAM)(LPVOID)&Setup ); if (hDlg) { if (lpMacroName) { STRING szString; GetWindowText(hDlg, szString, sizeof(szString)); lstrcat(szString, _T(" - ")); lstrcat(szString, lpMacroName); SetWindowText(hDlg, szString); } UpdateWindow(hDlg); } } // Repeat macro nRepeat number of times fError = FALSE; while (--nRepeat >= 0 && !fError) { if (lpAbortProc && (*lpAbortProc)()) break; // back to beginning of macro file lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList); // initialize sequencing fSequence = fSequenceAll; while (!fError && lpNextPkt) { if (lpAbortProc && (*lpAbortProc)()) { fError = TRUE; break; } // get the packet to work on if (fCopyPackets) { lpCmdPkt = CopyPacket(lpNextPkt); if (!lpCmdPkt) { fError = TRUE; break; } } else { ListUnlink(lpMacroList, lpNextPkt); lpCmdPkt = lpNextPkt; } // get command id and parms for this command idCommand = lpCmdPkt->idCommand; // Find out whether this command requires sequencing // set it here, so command can change it if needed before // we actually set fSequence fCmdSequence = GetCommandSequence(idCommand); CommandType = GetCommandType(idCommand); // Handle the different types of commands switch (CommandType) { case CT_LOAD: // create new command list for load lpNewList = CreateCommandList(); if (lpNewList) { ListAddTail(&lpNewList->PacketList, lpCmdPkt); // if we already have a command list containing commands, // kick off the execution of those commands before we // switch to the new command list if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); // if some command in the command list affects // sequencing force the whole command list to // be processed if (fSequence) { FlushCommands(lpCmdList); fSequence = fSequenceAll; } } // setup new command list for us to work with lpCmdList = lpNewList; lpCmdList->PhotoCDResOverride = PhotoCDResOverride; // If there are any activates in this macro make sure a // command that creates an image processes immediately if (nActivates) { PlaybackCommands(lpCmdList); FlushCommands(lpCmdList); fSequence = fSequenceAll; fCmdSequence = NO; // already sequenced } } break; case CT_COPY: // Make sure we have a command list to work with if (!lpCmdList) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } // Just add this command to the command list ListAddTail(&lpCmdList->PacketList, lpCmdPkt); // If there are any activates in this macro make sure a // command that creates an image processes immediately if (nActivates) { PlaybackCommands(lpCmdList); FlushCommands(lpCmdList); fSequence = fSequenceAll; fCmdSequence = NO; // already sequenced } break; case CT_SAVE: case CT_EDIT: case CT_MASK: case CT_MODE: case CT_EDITUNDO: case CT_MASKUNDO: case CT_EDITOBJ: case CT_CLOSE: // Make sure we have a command list to work with if (!lpCmdList) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } if (CommandType == CT_SAVE) { PlaybackCommands(lpCmdList); if (!lpCmdList->ThreadData.lpImage) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } } // Just add this command to the command list ListAddTail(&lpCmdList->PacketList, lpCmdPkt); if (CommandType != CT_CLOSE) break; case CT_ACTIVATE: // Program or commands that affect window activation // are processed here switch (idCommand) { case IDS_CMD_CLOSE: case IDS_CMD_ACTIVATEWINDOW: { // if we already have a command list containing commands, // kick of the execution of those commands before we // switch to the new command list if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); // if some command in the command list affects // sequencing force the whole command list to // be processed if (fSequence) { FlushCommands(lpCmdList); fSequence = fSequenceAll; } } // if this was a close command, then wack the command list pointer if (idCommand == IDS_CMD_CLOSE) lpCmdList = NULL; else { // now process the activate and get a new command list lpNewList = ProgActivateWindow( (LPACTIVATEWINDOW_PARMS)lpCmdPkt->lpParms); // setup the new command list if we got one if (lpNewList) lpCmdList = lpNewList; else { CommandError(idCommand); fError = TRUE; } // activate don't go through command processing // so we have to free it up here FreeUpPacket(lpCmdPkt); } } break; default: break; } break; default: break; } // if command just handled requires sequencing // set sequencing flag if (fCmdSequence) fSequence = YES; if (fCopyPackets) // get next command packet in macro list lpNextPkt = (LPCMDPKT)ListGetNext(lpNextPkt); else // head of list will be next one if we're not copying lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList); } } // get rid of macro list DestroyPacketList(lpMacroList); // if we already have a command list containing commands, // kick off the execution of those commands if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); if (fSequenceAll) FlushCommands(lpCmdList); } // turn off the macro mode EnableWindow(hParent, TRUE); if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) ) SetWindowText( PictPubApp.Get_hWndAstral(), szAppName ); // if we have a progress dialog, nuke it if (hDlg) AstralDlgEnd(hDlg, TRUE); // if we are display the macro status for another modal dialog // make sure the main app stuff is still disabled if (hParent != PictPubApp.Get_hWndAstral()) { EnableOverlappedWindow( PictPubApp.Get_hWndAstral(), FALSE ); EnableWindow(PictPubApp.Get_hWndAstral(), FALSE); } MacroMode = MM_NONE; return(TRUE); }