//-------------------------------------------------------------------------- void VeFilePath::FindFileList(const VeChar8* pcDesc, VeVector<VeFixedString>& kOut) const noexcept { # ifdef VE_PLATFORM_WIN VeChar8 acBuffer[VE_MAX_PATH_LEN]; PATH_CAT(acBuffer, m_kPath, pcDesc); _finddata_t kData; VeSizeT stHandle = _findfirst(acBuffer, &kData); if (stHandle != VE_ELF) { do { if ((kData.attrib & 0xf0) == _A_ARCH) { kOut.push_back(kData.name); } } while (VE_SUCCEEDED(_findnext(stHandle, &kData))); VE_ASSERT_EQ(_findclose(stHandle), VE_S_OK); } # else const VeChar8* pcFile = VeStrrchr(pcDesc, '/'); pcFile = pcFile ? (pcFile + 1) : pcDesc; DIR* pkDir(nullptr); if (pcFile == pcDesc) { pkDir = opendir(m_kPath.GetLength() ? m_kPath : "."); } else { VeChar8 acBuffer[VE_MAX_PATH_LEN]; VeChar8* pcTemp = acBuffer; if (m_kPath.GetLength()) { pcTemp += VeSprintf(acBuffer, "%s/", m_kPath.GetStr()); } VeStrncpy(pcTemp, VE_MAX_PATH_LEN, pcDesc, pcFile - pcDesc - 1); pkDir = opendir(acBuffer); } if (pkDir) { struct dirent* pkEntry; while ((pkEntry = readdir(pkDir))) { if (pkEntry->d_type != DT_DIR) { if (VeWildNameMatch(pkEntry->d_name, pcFile)) { kOut.push_back(pkEntry->d_name); } } } VE_ASSERT_EQ(closedir(pkDir), VE_S_OK); } # endif }
//-------------------------------------------------------------------------- void VeAssetPath::FindFileList(const VeChar8* pcDesc, VeVector<VeFixedString>& kOut) const noexcept { const VeChar8* pcFile = VeStrrchr(pcDesc, '/'); pcFile = pcFile ? (pcFile + 1) : pcDesc; AAssetDir* pkDir(nullptr); if (pcFile == pcDesc) { pkDir = AAssetManager_openDir(s_pkAssetManager, m_kPath); } else { VeChar8 acBuffer[VE_MAX_PATH_LEN]; VeChar8* pcTemp = acBuffer; if (m_kPath.GetLength()) { pcTemp += VeSprintf(acBuffer, "%s/", m_kPath.GetStr()); } VeStrncpy(pcTemp, VE_MAX_PATH_LEN, pcDesc, pcFile - pcDesc - 1); pkDir = AAssetManager_openDir(s_pkAssetManager, acBuffer); } if (pkDir) { const VeChar8* pcEntry; while ((pcEntry = AAssetDir_getNextFileName(pkDir))) { if (VeWildNameMatch(pcEntry, pcFile)) { kOut.push_back(pcEntry); } } AAssetDir_close(pkDir); } }
//-------------------------------------------------------------------------- void VeRenderWindowD3D12::SetupCompositorList(const VeChar8** ppcList, VeSizeT stNum, VeUInt32 u32ThreadNum, const VeChar8* pcHint) noexcept { VeRendererD3D12& kRenderer = *VeMemberCast( &VeRendererD3D12::m_kRenderWindowList, m_kNode.get_list()); VeVector<VeRenderer::FrameTechnique*> kTechList; { for (VeSizeT i(0); i < stNum; ++i) { auto it = kRenderer.m_kCompositorMap.find(ppcList[i]); if (it != kRenderer.m_kCompositorMap.end()) { VeRenderer::FrameTechnique* pkTech = nullptr; if (pcHint) { VeFixedString kHint = pcHint; for (auto& tech : it->second->m_kTechniqueList) { if (tech.m_kName == kHint) { pkTech = &tech; break; } } } if (pkTech) { kTechList.push_back(pkTech); } else if(it->second->m_kTechniqueList.size()) { kTechList.push_back(&(it->second->m_kTechniqueList.front())); } } } } { m_kResourceMap.clear(); VeStringMap<VeFloat64> kValueMap; kValueMap["screen_w"] = (VeFloat64)GetWidth(); kValueMap["screen_h"] = (VeFloat64)GetHeight(); for (auto pTech : kTechList) { for (auto& res : pTech->m_kResourceList) { auto it = m_kResourceMap.find(res.m_kName); if (it == m_kResourceMap.end()) { VeUInt32 w = (VeUInt32)ve_parser.CalculateExpression( kValueMap, res.m_kWidth, 0); VeUInt32 h = (VeUInt32)ve_parser.CalculateExpression( kValueMap, res.m_kHeight, 0); VeUInt16 d = (VeUInt16)ve_parser.CalculateExpression( kValueMap, res.m_kDepth, 0); VeUInt16 m = (VeUInt16)ve_parser.CalculateExpression( kValueMap, res.m_kMipLevels, 0); VeUInt16 c = (VeUInt16)ve_parser.CalculateExpression( kValueMap, res.m_kCount, 0); VeUInt16 q = (VeUInt16)ve_parser.CalculateExpression( kValueMap, res.m_kQuality, 0); VeUInt32 u32Use(0); if (res.m_kSRVList.size()) u32Use |= VeRenderTexture::USEAGE_SRV; if (res.m_kRTVList.size()) u32Use |= VeRenderTexture::USEAGE_RTV; if (res.m_kDSVList.size()) u32Use |= VeRenderTexture::USEAGE_DSV; VeRenderTextureD3D12* pkTexture = VE_NEW VeRenderTextureD3D12( res.m_eDimension, (VeRenderTexture::Useage)u32Use, res.m_eFormat, w, h, d, m, c, q); pkTexture->Init(kRenderer); if (res.m_kSRVList.size()) { pkTexture->SetSRVNum((VeUInt32)res.m_kSRVList.size()); for (VeUInt32 i(0); i < res.m_kSRVList.size(); ++i) { auto& srv = res.m_kSRVList[i]; pkTexture->SetSRV(i, srv.m_eType, srv.m_eFormat, srv.m_u32Param0, srv.m_u32Param1); } } if (res.m_kRTVList.size()) { pkTexture->SetRTVNum((VeUInt32)res.m_kRTVList.size()); for (VeUInt32 i(0); i < res.m_kRTVList.size(); ++i) { auto& rtv = res.m_kRTVList[i]; pkTexture->SetRTV(i, rtv.m_eType, rtv.m_eFormat, rtv.m_u32Param0, rtv.m_u32Param1); } } if (res.m_kDSVList.size()) { pkTexture->SetDSVNum((VeUInt32)res.m_kDSVList.size()); for (VeUInt32 i(0); i < res.m_kDSVList.size(); ++i) { auto& dsv = res.m_kDSVList[i]; pkTexture->SetDSV(i, dsv.m_eType, dsv.m_eFormat, dsv.m_u32Param0, dsv.m_u32Param1); } } m_kResourceMap[res.m_kName] = pkTexture; } } } } VeVector<VeStringMap<TargetCache>> kTargets; kTargets.resize(kTechList.size()); for (VeSizeT i(kTechList.size() - 1); i < kTechList.size(); --i) { VeRenderer::FrameTechnique& kTech = *kTechList[i]; for (VeSizeT j(0); j < kTech.m_kTargetList.size(); ++j) { VeRenderer::FrameTarget& kTarget = kTech.m_kTargetList[j]; RecordRenderTargetPtr spTarget; VeVector<ViewData> kRTVList; ViewData kDSV; if (kTarget.m_eType == VeRenderer::TARGET_OUTPUT) { if (i == (kTechList.size() - 1)) { spTarget = VE_NEW RecordRenderTarget(); for (VeSizeT k(0); k < VeRendererD3D12::FRAME_COUNT; ++k) { spTarget->m_akRTVList[k].push_back(m_akFrameCache[k].m_hHandle); spTarget->m_ahDSV[k].ptr = 0; } kRTVList.resize(kRTVList.size() + 1); kRTVList.back().m_u32Width = GetWidth(); kRTVList.back().m_u32Height = GetHeight(); kRTVList.back().m_u32Depth = 1; kRTVList.back().m_u32SubResource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; } else { auto it = kTargets[i + 1].find(kTarget.m_kName); if (it != kTargets[i + 1].end() && it->second.m_pkConfig->m_eType == VeRenderer::TARGET_INPUT) { spTarget = it->second.m_spRecorder; } } } else { spTarget = VE_NEW RecordRenderTarget(); for (auto& rtv : kTarget.m_kRTVList) { auto it = m_kResourceMap.find(rtv.m_kResName); if (it != m_kResourceMap.end()) { if (rtv.m_u32Index < it->second->m_kRTVList.size()) { auto& kView = it->second->m_kRTVList[rtv.m_u32Index]; for (VeSizeT k(0); k < VeRendererD3D12::FRAME_COUNT; ++k) { spTarget->m_akRTVList[k].push_back(kView.m_hCPUHandle); } kRTVList.resize(kRTVList.size() + 1); kRTVList.back().m_pkResource = it->second->m_pkResource; kRTVList.back().m_u32Width = kView.m_u32Width; kRTVList.back().m_u32Height = kView.m_u32Height; kRTVList.back().m_u32Depth = kView.m_u32Depth; kRTVList.back().m_u32SubResource = kView.m_u32SubResource; } } } auto it = m_kResourceMap.find(kTarget.m_kDSV.m_kResName); if (it != m_kResourceMap.end()) { if (kTarget.m_kDSV.m_u32Index < it->second->m_kDSVList.size()) { auto& kView = it->second->m_kDSVList[kTarget.m_kDSV.m_u32Index]; for (VeSizeT k(0); k < VeRendererD3D12::FRAME_COUNT; ++k) { spTarget->m_ahDSV[k] = kView.m_hCPUHandle; } kDSV.m_pkResource = it->second->m_pkResource; kDSV.m_u32Width = kView.m_u32Width; kDSV.m_u32Height = kView.m_u32Height; kDSV.m_u32Depth = kView.m_u32Depth; kDSV.m_u32SubResource = kView.m_u32SubResource; } } } if (spTarget) { auto& tar = kTargets[i][kTarget.m_kName]; VE_ASSERT(!tar.m_pkConfig); tar.m_pkConfig = &kTarget; tar.m_spRecorder = spTarget; tar.m_kRTVList = std::move(kRTVList); tar.m_kDSV = kDSV; } } } RecordBarrierMap kBarriers; kBarriers.resize(kTechList.size()); BarrierPathCache kResPathCache; VeMap<ID3D12Resource*, VeMap<VeUInt32, D3D12_RESOURCE_STATES>> kClickCache; for (VeSizeT i(0); i < kTechList.size(); ++i) { auto& kMap = kTargets[i]; VeRenderer::FrameTechnique& kTech = *kTechList[i]; kBarriers[i].resize(kTech.m_kClickList.size()); for (VeSizeT j(0); j < kTech.m_kClickList.size(); ++j) { VeRenderer::FrameClick& kClick = kTech.m_kClickList[j]; auto it = kMap.find(kClick.m_kTarget); if (it == kMap.end()) continue; auto& tar = it->second; kClickCache.clear(); for (auto rtv : tar.m_kRTVList) { kClickCache[rtv.m_pkResource][rtv.m_u32SubResource] = D3D12_RESOURCE_STATE_RENDER_TARGET; } if(tar.m_kDSV.m_pkResource) { kClickCache[tar.m_kDSV.m_pkResource][tar.m_kDSV.m_u32SubResource] = D3D12_RESOURCE_STATE_DEPTH_WRITE; } for (auto& con : kClick.m_kContextList) { auto itRes = m_kResourceMap.find(con); if (itRes != m_kResourceMap.end()) { auto& cache = kClickCache[itRes->second->m_pkResource]; cache.clear(); cache[D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES] = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE; } } for (auto& cache : kClickCache) { for (auto& state : cache.second) { BarrierEvent(kBarriers, kResPathCache, i, j, cache.first, state.first, state.second); } } } } VeUInt32 u32GCLIndex(0); bool bScene = false; m_kRecorderList.resize(1); m_kRecorderList.back().m_u32CommandIndex = 0; m_kRecorderList.back().m_kTaskList.clear(); m_kProcessList.resize(1); m_kProcessList.back().m_eType = TYPE_EXCUTE; m_kProcessList.back().m_u16Start = 0; m_kProcessList.back().m_u16Num = 1; m_kCameraList.clear(); RectMap kRectMap; RecordRenderTargetPtr spCurrent; RecordViewportPtr spViewport; RecordScissorRectPtr spScissorRect; for (VeSizeT i(0); i < kTechList.size(); ++i) { VeRenderer::FrameTechnique& kTech = *kTechList[i]; auto& kMap = kTargets[i]; for (VeSizeT j(0); j < kTech.m_kClickList.size(); ++j) { VeRenderer::FrameClick& kClick = kTech.m_kClickList[j]; auto it = kMap.find(kClick.m_kTarget); if(it == kMap.end()) continue; TargetCache& kCache = it->second; auto& bar = kBarriers[i][j]; if(bar.first) { if (bScene) { if (m_kProcessList.back().m_eType == TYPE_EXCUTE) { m_kProcessList.back().m_u16Num += 1; } else { m_kProcessList.resize(m_kProcessList.size() + 1); m_kProcessList.back().m_eType = TYPE_EXCUTE; m_kProcessList.back().m_u16Start = u32GCLIndex + 1; m_kProcessList.back().m_u16Num = 1; } ++u32GCLIndex; m_kRecorderList.resize(m_kRecorderList.size() + 1); m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex; m_kRecorderList.back().m_kTaskList.clear(); bScene = false; } m_kRecorderList.back().m_kTaskList.push_back(bar.first); } for (VeSizeT k(0); k < kClick.m_kPassList.size(); ++k) { switch (kClick.m_kPassList[k]->m_eType) { case VeRenderer::PASS_CLEAR: { if (bScene) { if (m_kProcessList.back().m_eType == TYPE_EXCUTE) { m_kProcessList.back().m_u16Num += 1; } else { m_kProcessList.resize(m_kProcessList.size() + 1); m_kProcessList.back().m_eType = TYPE_EXCUTE; m_kProcessList.back().m_u16Start = u32GCLIndex + 1; m_kProcessList.back().m_u16Num = 1; } ++u32GCLIndex; m_kRecorderList.resize(m_kRecorderList.size() + 1); m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex; m_kRecorderList.back().m_kTaskList.clear(); bScene = false; } VeRenderer::FrameClear& kClear = (VeRenderer::FrameClear&)*kClick.m_kPassList[k]; if (VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_COLOR) && kClear.m_kColorArray.size()) { VeSizeT stColorNum = kCache.m_spRecorder->m_akRTVList->size(); for (VeSizeT l(0); l < stColorNum; ++l) { RecordClearRTV* pkTask = VE_NEW RecordClearRTV(); for (VeSizeT m(0); m < VeRendererD3D12::FRAME_COUNT; ++m) { pkTask->m_ahHandle[m] = kCache.m_spRecorder->m_akRTVList[m][l]; } if (l < kClear.m_kColorArray.size()) { pkTask->m_kColor = kClear.m_kColorArray[l]; } else { pkTask->m_kColor = kClear.m_kColorArray.back(); } m_kRecorderList.back().m_kTaskList.push_back(pkTask); } } if (VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_DEPTH) || VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_STENCIL)) { if (kCache.m_spRecorder->m_ahDSV->ptr) { RecordClearDSV* pkTask = VE_NEW RecordClearDSV(); pkTask->m_eFlags = VE_TMIN(D3D12_CLEAR_FLAGS); if (VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_DEPTH)) { pkTask->m_eFlags |= D3D12_CLEAR_FLAG_DEPTH; } if (VE_MASK_HAS_ANY(kClear.m_u32Flags, VeRenderer::CLEAR_STENCIL)) { pkTask->m_eFlags |= D3D12_CLEAR_FLAG_STENCIL; } pkTask->m_f32Depth = kClear.m_f32Depth; pkTask->m_u8Stencil = kClear.m_u8Stencil; for (VeSizeT m(0); m < VeRendererD3D12::FRAME_COUNT; ++m) { pkTask->m_ahHandle[m] = kCache.m_spRecorder->m_ahDSV[m]; } m_kRecorderList.back().m_kTaskList.push_back(pkTask); } } } break; case VeRenderer::PASS_QUAD: { if (bScene) { if (m_kProcessList.back().m_eType == TYPE_EXCUTE) { m_kProcessList.back().m_u16Num += 1; } else { m_kProcessList.resize(m_kProcessList.size() + 1); m_kProcessList.back().m_eType = TYPE_EXCUTE; m_kProcessList.back().m_u16Start = u32GCLIndex + 1; m_kProcessList.back().m_u16Num = 1; } ++u32GCLIndex; m_kRecorderList.resize(m_kRecorderList.size() + 1); m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex; m_kRecorderList.back().m_kTaskList.clear(); bScene = false; } if (spCurrent != kCache.m_spRecorder) { m_kRecorderList.back().m_kTaskList.push_back(kCache.m_spRecorder); spCurrent = kCache.m_spRecorder; } auto& rect = Get(kRectMap, GetResolution(kCache)); if (spViewport != rect.first) { m_kRecorderList.back().m_kTaskList.push_back(rect.first); spViewport = rect.first; } if (spScissorRect != rect.second) { m_kRecorderList.back().m_kTaskList.push_back(rect.second); spScissorRect = rect.second; } VeRenderer::FrameQuad& kQuad = (VeRenderer::FrameQuad&)*kClick.m_kPassList[k]; ID3D12RootSignature* pkRootSignature = nullptr; ID3D12PipelineState* pkPipelineState = nullptr; auto itRoot = kRenderer.m_kRootSignatureMap.find(kQuad.m_kRootSignature); if(itRoot != kRenderer.m_kRootSignatureMap.end()) { pkRootSignature = VeSmartPointerCast(VeRendererD3D12::RootSignatureD3D12, itRoot->second)->m_pkRootSignature; } auto itPSO = kRenderer.m_kPipelineStateMap.find(kQuad.m_kPipelineState); if (itPSO != kRenderer.m_kPipelineStateMap.end()) { pkPipelineState = VeSmartPointerCast(VeRendererD3D12::PipelineStateD3D12, itPSO->second)->m_pkPipelineState; } if (pkRootSignature && pkPipelineState) { RecordRenderQuad* pkQuad = VE_NEW RecordRenderQuad(); pkQuad->m_pkRootSignature = pkRootSignature; pkQuad->m_pkPipelineState = pkPipelineState; for (auto& itTab : kQuad.m_kTable) { bool bFinished = false; for (auto context : kClick.m_kContextList) { if (context == itTab.second) { auto itRTRes = m_kResourceMap.find(itTab.second); if (itRTRes != m_kResourceMap.end()) { VeRenderTextureD3D12* pkTex = itRTRes->second; if (pkTex->m_kSRVList.size()) { pkQuad->m_kTable.push_back(std::make_pair(itTab.first, pkTex->m_kSRVList.front().m_hGPUHandle)); bFinished = true; } break; } } } if(!bFinished) { auto itRes = kRenderer.m_kResourceMap.find(itTab.second); if (itRes != kRenderer.m_kResourceMap.end()) { switch (itRes->second->GetDimension()) { case VeRenderResource::DIMENSION_TEXTURE1D: case VeRenderResource::DIMENSION_TEXTURE2D: case VeRenderResource::DIMENSION_TEXTURE3D: { VeRenderTextureD3D12* pkTex = VeDynamicCast(VeRenderTextureD3D12, itRes->second.p()); if (pkTex && pkTex->m_kSRVList.size()) { pkQuad->m_kTable.push_back(std::make_pair(itTab.first, pkTex->m_kSRVList.front().m_hGPUHandle)); } } break; default: break; } } } } m_kRecorderList.back().m_kTaskList.push_back(pkQuad); } } break; case VeRenderer::PASS_SCENE: { VeRenderer::FrameScene& kScene = (VeRenderer::FrameScene&)*kClick.m_kPassList[k]; if (!bScene) { spCurrent = nullptr; spViewport = nullptr; spScissorRect = nullptr; bScene = true; } m_kCameraList.resize(m_kCameraList.size() + 1); m_kCameraList.back().m_u32CameraMask = VE_MASK(kScene.m_u32Camera); m_kCameraList.back().m_kStageList.resize(kScene.m_u32Stage); for (auto& stage : m_kCameraList.back().m_kStageList) { stage = u32GCLIndex + 1; if (m_kProcessList.back().m_eType == TYPE_EXCUTE) { m_kProcessList.back().m_u16Num += u32ThreadNum; } else { m_kProcessList.resize(m_kProcessList.size() + 1); m_kProcessList.back().m_eType = TYPE_EXCUTE; m_kProcessList.back().m_u16Start = stage; m_kProcessList.back().m_u16Num = u32ThreadNum; } u32GCLIndex += u32ThreadNum; } } break; default: break; } } if (bar.second) { if (bScene) { if (m_kProcessList.back().m_eType == TYPE_EXCUTE) { m_kProcessList.back().m_u16Num += 1; } else { m_kProcessList.resize(m_kProcessList.size() + 1); m_kProcessList.back().m_eType = TYPE_EXCUTE; m_kProcessList.back().m_u16Start = u32GCLIndex + 1; m_kProcessList.back().m_u16Num = 1; } ++u32GCLIndex; m_kRecorderList.resize(m_kRecorderList.size() + 1); m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex; m_kRecorderList.back().m_kTaskList.clear(); bScene = false; } m_kRecorderList.back().m_kTaskList.push_back(bar.second); } } } auto it = kResPathCache.find(nullptr); if (it != kResPathCache.end()) { if (it->second.size()) { D3D12_RESOURCE_STATES eResPresent = GetState(it->second.back(), D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES); RecordBarrier* pkBarrier = VE_NEW RecordBarrier(); for (VeSizeT i(0); i < VeRendererD3D12::FRAME_COUNT; ++i) { pkBarrier->m_akBarrierList[i].resize(pkBarrier->m_akBarrierList[i].size() + 1); pkBarrier->m_akBarrierList[i].back().Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; pkBarrier->m_akBarrierList[i].back().Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; pkBarrier->m_akBarrierList[i].back().Transition.pResource = m_akFrameCache[i].m_pkBufferResource; pkBarrier->m_akBarrierList[i].back().Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; pkBarrier->m_akBarrierList[i].back().Transition.StateBefore = eResPresent; pkBarrier->m_akBarrierList[i].back().Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT; } if (bScene) { if (m_kProcessList.back().m_eType == TYPE_EXCUTE) { m_kProcessList.back().m_u16Num += 1; } else { m_kProcessList.resize(m_kProcessList.size() + 1); m_kProcessList.back().m_eType = TYPE_EXCUTE; m_kProcessList.back().m_u16Start = u32GCLIndex + 1; m_kProcessList.back().m_u16Num = 1; } ++u32GCLIndex; m_kRecorderList.resize(m_kRecorderList.size() + 1); m_kRecorderList.back().m_u32CommandIndex = u32GCLIndex; m_kRecorderList.back().m_kTaskList.clear(); bScene = false; } m_kRecorderList.back().m_kTaskList.push_back(pkBarrier); } } m_u32ThreadNum = u32ThreadNum; ResizeDirectList(u32GCLIndex + 1); }