From b7718d496fab7ef61eb4d28fd382f68667b072ba Mon Sep 17 00:00:00 2001 From: Deamon Date: Tue, 15 Feb 2022 23:04:00 +0200 Subject: [PATCH 1/9] temp commit --- src/ui/FrontendUI.cpp | 3 +++ wowViewerLib/shaders/glsl/vulkan/wmoShader.frag | 2 +- wowViewerLib/src/engine/algorithms/FrameCounter.h | 8 ++++---- wowViewerLib/src/engine/objects/ViewsObjects.h | 2 +- wowViewerLib/src/engine/objects/m2/m2Object.cpp | 4 +++- wowViewerLib/src/engine/objects/m2/m2Object.h | 2 +- wowViewerLib/src/engine/objects/wmo/wmoObject.cpp | 2 +- wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp | 7 ------- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ui/FrontendUI.cpp b/src/ui/FrontendUI.cpp index 4085ae708..3262efeb4 100644 --- a/src/ui/FrontendUI.cpp +++ b/src/ui/FrontendUI.cpp @@ -590,6 +590,9 @@ void FrontendUI::showQuickLinksDialog() { if (ImGui::Button("(WMO) NPE Ship with waterfall model", ImVec2(-1, 0))) { openWMOSceneByfdid(3314067); } + if (ImGui::Button("(WMO) Gazebo 590182", ImVec2(-1, 0))) { + openWMOSceneByfdid(590182); + } if (ImGui::Button("Hearthstone Tavern", ImVec2(-1, 0))) { openWMOSceneByfdid(2756726); } diff --git a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag index 5c80d1e35..11985fd60 100644 --- a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag +++ b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag @@ -212,7 +212,7 @@ void main() { finalOpacity = 1.0; } else if (uPixelShader == 15) { //MapObjTwoLayerDiffuseMod2x vec3 layer1 = tex.rgb; - vec3 layer2 = mix(layer1, tex2.rbg, vec3(tex2.a)); + vec3 layer2 = mix(layer1, tex2.rgb, vec3(tex2.a)); vec3 layer3 = mix(layer2, layer1, vec3(vColor2.a)); matDiffuse = layer3 * tex3.rgb * 2.0; diff --git a/wowViewerLib/src/engine/algorithms/FrameCounter.h b/wowViewerLib/src/engine/algorithms/FrameCounter.h index 418ac2b47..5eced9682 100644 --- a/wowViewerLib/src/engine/algorithms/FrameCounter.h +++ b/wowViewerLib/src/engine/algorithms/FrameCounter.h @@ -19,11 +19,11 @@ class FrameCounter { return timePerFrame; } private: -//#if defined(_MSC_VER) -// std::chrono::time_point m_startTime; -//#else +#if defined(_MSC_VER) or defined(__EMSCRIPTEN__) + std::chrono::time_point m_startTime; +#else std::chrono::system_clock::time_point m_startTime; -//#endif +#endif double m_accomulatedTimeInterval = 0; int frameCounter = 0; diff --git a/wowViewerLib/src/engine/objects/ViewsObjects.h b/wowViewerLib/src/engine/objects/ViewsObjects.h index e91cb03d8..6cd16b0aa 100644 --- a/wowViewerLib/src/engine/objects/ViewsObjects.h +++ b/wowViewerLib/src/engine/objects/ViewsObjects.h @@ -54,7 +54,7 @@ class GeneralView { class InteriorView : public GeneralView { public: - int portalIndex; + int portalIndex = -1; void setM2Lights(std::shared_ptr m2Object) override; }; diff --git a/wowViewerLib/src/engine/objects/m2/m2Object.cpp b/wowViewerLib/src/engine/objects/m2/m2Object.cpp index f6ac9a93c..c76599f9c 100644 --- a/wowViewerLib/src/engine/objects/m2/m2Object.cpp +++ b/wowViewerLib/src/engine/objects/m2/m2Object.cpp @@ -1271,7 +1271,9 @@ void M2Object::createBoundingBoxMesh() { boundingBoxMesh = m_api->hDevice->createMesh(meshTemplate); boundingBoxMesh->setRenderOrder(1000); - occlusionQuery = m_api->hDevice->createQuery(boundingBoxMesh); + + for (auto &a : occlusionQueries) + a = m_api->hDevice->createQuery(boundingBoxMesh); } bool M2Object::checkifBonesAreInRange(M2SkinProfile *skinProfile, M2SkinSection *skinSection) { diff --git a/wowViewerLib/src/engine/objects/m2/m2Object.h b/wowViewerLib/src/engine/objects/m2/m2Object.h index 6b5640d4d..1c1b4b555 100644 --- a/wowViewerLib/src/engine/objects/m2/m2Object.h +++ b/wowViewerLib/src/engine/objects/m2/m2Object.h @@ -90,7 +90,7 @@ class M2Object { HGUniformBufferChunk fragmentModelWideUniformBuffer = nullptr; HGMesh boundingBoxMesh = nullptr; - HGOcclusionQuery occlusionQuery = nullptr; + std::array occlusionQueries = {nullptr}; mathfu::vec4 m_ambientColorOverride; bool m_setAmbientColor = false; diff --git a/wowViewerLib/src/engine/objects/wmo/wmoObject.cpp b/wowViewerLib/src/engine/objects/wmo/wmoObject.cpp index 6793474b8..feddd73a5 100644 --- a/wowViewerLib/src/engine/objects/wmo/wmoObject.cpp +++ b/wowViewerLib/src/engine/objects/wmo/wmoObject.cpp @@ -8,7 +8,7 @@ #include "./../../../gapi/interface/IDevice.h" #include -std::vector CreateOccluders(const HWmoGroupGeom groupGeom) +std::vector createOccluders(const HWmoGroupGeom& groupGeom) { std::vector points(0); diff --git a/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp b/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp index 0f9ba11f0..ee6c302e1 100644 --- a/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp +++ b/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp @@ -662,9 +662,6 @@ void GDeviceGL33::drawMesh(HGMesh hIMesh, HGUniformBufferChunk matrixChunk) { if (gOcclusionQuery != nullptr) { gOcclusionQuery->beginQuery(); } - if (gm2Mesh != nullptr && gm2Mesh->m_query != nullptr) { - ((GOcclusionQueryGL33 *)gm2Mesh->m_query.get())->beginConditionalRendering(); - } //#if OPENGL_DGB_MESSAGE // std::string debugMess = @@ -711,10 +708,6 @@ void GDeviceGL33::drawMesh(HGMesh hIMesh, HGUniformBufferChunk matrixChunk) { //#if OPENGL_DGB_MESSAGE // glPopDebugGroup(); //#endif - if (gm2Mesh != nullptr && gm2Mesh->m_query != nullptr) { - ((GOcclusionQueryGL33 *)gm2Mesh->m_query.get())->endConditionalRendering(); - } - if (gOcclusionQuery != nullptr) { gOcclusionQuery->endQuery(); } From 3bb186f6aac064dc33712ae1e7e3fce28918946d Mon Sep 17 00:00:00 2001 From: Deamon87 Date: Sat, 8 Oct 2022 23:56:59 +0300 Subject: [PATCH 2/9] fix error in shader --- wowViewerLib/shaders/glsl/vulkan/wmoShader.frag | 6 +++--- wowViewerLib/src/engine/objects/wmo/wmoGroupObject.cpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag index 5a1ca169b..05577f439 100644 --- a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag +++ b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag @@ -302,12 +302,12 @@ void main() { vec4 alphaVec2Normalized = alphaVec2 * (1.0 / dot(alphaVec2, vec4(1.0))); vec4 texMixed = tex_2 * alphaVec2Normalized.r + - tex_3 * alphaVec2Normalized.b + - tex_4 * alphaVec2Normalized.g + + tex_3 * alphaVec2Normalized.g + + tex_4 * alphaVec2Normalized.b + tex_5 * alphaVec2Normalized.a; emissive = (texMixed.w * tex_1.rgb) * texMixed.rgb; - vec3 diffuseColor = vec3(0.0); //Probably is taken from MOMT or somewhere else + vec3 diffuseColor = vec3(0,0,0); //<= it's unknown where this color comes from. But it's not MOMT chunk matDiffuse = (diffuseColor - texMixed.rgb) * vColorSecond.a + texMixed.rgb; } diff --git a/wowViewerLib/src/engine/objects/wmo/wmoGroupObject.cpp b/wowViewerLib/src/engine/objects/wmo/wmoGroupObject.cpp index b7124ad91..914f37a00 100644 --- a/wowViewerLib/src/engine/objects/wmo/wmoGroupObject.cpp +++ b/wowViewerLib/src/engine/objects/wmo/wmoGroupObject.cpp @@ -536,6 +536,7 @@ void WmoGroupObject::createMeshes() { blockVS.VertexShader = vertexShader; }); + hmesh->getUniformBuffer(4)->setUpdateHandler([this, isBatchA, isBatchC, &material, blendMode, pixelShader](IUniformBufferChunk *self, const HFrameDepedantData &frameDepedantData) { // mathfu::vec4 globalAmbientColor = m_api->getGlobalAmbientColor(); mathfu::vec4 localambientColor = this->getAmbientColor(); From 293bd7402f5c2c0fd6b7e8be6c9fbe54adcee8bb Mon Sep 17 00:00:00 2001 From: Deamon87 Date: Tue, 11 Oct 2022 22:24:43 +0300 Subject: [PATCH 3/9] implement "compression" of UBO for m2 matrix upload --- .../shaders/glsl/vulkan/m2Shader.vert | 11 +-- .../shaders/glsl/vulkan/waterShader.frag | 5 +- .../shaders/glsl/vulkan/wmoShader.vert | 6 +- .../src/engine/objects/m2/m2Object.cpp | 2 +- .../src/engine/shader/ShaderDefinitions.h | 82 +++++++++---------- wowViewerLib/src/gapi/interface/IDevice.h | 4 +- .../interface/buffers/IUniformBufferChunk.h | 6 +- wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp | 16 ++-- wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.h | 2 +- .../ogl3.3/buffers/GUnformBufferChunk33.h | 2 +- 10 files changed, 71 insertions(+), 65 deletions(-) diff --git a/wowViewerLib/shaders/glsl/vulkan/m2Shader.vert b/wowViewerLib/shaders/glsl/vulkan/m2Shader.vert index 0f47de6fb..b9772379c 100644 --- a/wowViewerLib/shaders/glsl/vulkan/m2Shader.vert +++ b/wowViewerLib/shaders/glsl/vulkan/m2Shader.vert @@ -67,15 +67,12 @@ void main() { vec4 lDiffuseColor = color_Transparency; - mat4 cameraMatrix = scene.uLookAtMat * placementMat * boneTransformMat ; - vec4 cameraPoint = cameraMatrix * aPositionVec4; - mat3 viewModelMatTransposed = - blizzTranspose(scene.uLookAtMat) * - blizzTranspose(placementMat) * - blizzTranspose(boneTransformMat); + mat4 viewModelMat = scene.uLookAtMat * placementMat * boneTransformMat ; + vec4 cameraPoint = viewModelMat * aPositionVec4; + mat4 viewModelMatForNormal = transpose(inverse(viewModelMat)); // vec3 normal = normalize(mat3(cameraMatrix) * aNormal); - vec3 normal = normalize(viewModelMatTransposed * aNormal); + vec3 normal = normalize(viewModelMatForNormal * vec4(aNormal, 0.0)).xyz; vec4 combinedColor = clamp(lDiffuseColor /*+ vc_matEmissive*/, 0.000000, 1.000000); vec4 combinedColorHalved = combinedColor * 0.5; diff --git a/wowViewerLib/shaders/glsl/vulkan/waterShader.frag b/wowViewerLib/shaders/glsl/vulkan/waterShader.frag index 428dc1c20..486aa3afa 100644 --- a/wowViewerLib/shaders/glsl/vulkan/waterShader.frag +++ b/wowViewerLib/shaders/glsl/vulkan/waterShader.frag @@ -27,11 +27,12 @@ layout(std140, binding=4) uniform meshWideBlockPS { }; void main() { - vec3 finalColor = color.rgb+texture(uTexture, vTextCoords).rgb; + vec3 matDiffuse = color.rgb+texture(uTexture, vTextCoords).rgb; vec3 sunDir =scene.extLight.uExteriorDirectColorDir.xyz; //BlendMode is always GxBlend_Alpha - finalColor = makeFog(fogData, vec4(finalColor, 1.0), vPosition.xyz, sunDir.xyz, 2).rgb; + vec3 finalColor = makeFog(fogData, vec4(matDiffuse, 1.0), vPosition.xyz, sunDir.xyz, 2).rgb; + outputColor = vec4(finalColor, 0.7); } diff --git a/wowViewerLib/shaders/glsl/vulkan/wmoShader.vert b/wowViewerLib/shaders/glsl/vulkan/wmoShader.vert index 433dcbc6f..631c58bfc 100644 --- a/wowViewerLib/shaders/glsl/vulkan/wmoShader.vert +++ b/wowViewerLib/shaders/glsl/vulkan/wmoShader.vert @@ -50,14 +50,12 @@ void main() { mat4 viewModelMat = scene.uLookAtMat * uPlacementMat; - mat3 viewModelMatTransposed = - blizzTranspose(scene.uLookAtMat) * - blizzTranspose(uPlacementMat); + mat4 viewModelMatForNormal = transpose(inverse(viewModelMat)); gl_Position = scene.uPMatrix * cameraPoint; vPosition = vec4(cameraPoint.xyz, 0); - vNormal = normalize(viewModelMatTransposed * aNormal); + vNormal = normalize(viewModelMatForNormal * vec4(aNormal, 0.0)).xyz; vColor = aColor.bgra; diff --git a/wowViewerLib/src/engine/objects/m2/m2Object.cpp b/wowViewerLib/src/engine/objects/m2/m2Object.cpp index 5039b0037..d0177c51f 100644 --- a/wowViewerLib/src/engine/objects/m2/m2Object.cpp +++ b/wowViewerLib/src/engine/objects/m2/m2Object.cpp @@ -1870,7 +1870,7 @@ void M2Object::createVertexBindings() { //3. Create model wide uniform buffer // vertexModelWideUniformBuffer = device->createUniformBuffer(sizeof(mathfu::mat4) * (m_m2Geom->m_m2Data->bones.size + 1)); - vertexModelWideUniformBuffer = device->createUniformBufferChunk(sizeof(M2::modelWideBlockVS)); + vertexModelWideUniformBuffer = device->createUniformBufferChunk(sizeof(M2::modelWideBlockVS), (m_m2Geom->m_m2Data->bones.size + 1) * sizeof(mathfu::mat4)); fragmentModelWideUniformBuffer = device->createUniformBufferChunk(sizeof(M2::modelWideBlockPS)); vertexModelWideUniformBuffer->setUpdateHandler([this](IUniformBufferChunk *self, const HFrameDepedantData &frameDepedantData){ diff --git a/wowViewerLib/src/engine/shader/ShaderDefinitions.h b/wowViewerLib/src/engine/shader/ShaderDefinitions.h index cb83c67bf..136c048c1 100644 --- a/wowViewerLib/src/engine/shader/ShaderDefinitions.h +++ b/wowViewerLib/src/engine/shader/ShaderDefinitions.h @@ -625,36 +625,36 @@ const std::unordered_map &meshes) { #ifdef SINGLE_BUFFER_UPLOAD void GDeviceGL33::updateBuffers(std::vector*> &bufferChunks, std::vector &frameDepedantDataVec) { int fullSize = 0; + int fullTargetSize = 0; for (int i = 0; i < bufferChunks.size(); i++) { auto &bufferVec = bufferChunks[i]; for (auto &buffer : *bufferVec) { - fullSize += buffer->getSize(); + fullTargetSize = std::max(fullTargetSize, fullSize + buffer->getSize()); + fullSize += ((buffer->getRealSize() > 0) ? buffer->getRealSize() : buffer->getSize()); int offsetDiff = fullSize % uniformBufferOffsetAlign; if (offsetDiff != 0) { int bytesToAdd = uniformBufferOffsetAlign - offsetDiff; @@ -344,6 +346,8 @@ void GDeviceGL33::updateBuffers(std::vector*> } } } + fullSize = fullTargetSize; + if (fullSize > aggregationBufferForUpload.size()) { aggregationBufferForUpload.resize(fullSize); } @@ -351,6 +355,7 @@ void GDeviceGL33::updateBuffers(std::vector*> uploadAmountInBytes = 0; //2. Create buffers and update them int currentSize = 0; + int targetSize = 0; int buffersIndex = 0; HGUniformBuffer bufferForUpload = m_UBOFrames[getUpdateFrameNumber()].m_uniformBufferForUpload; @@ -369,7 +374,8 @@ void GDeviceGL33::updateBuffers(std::vector*> for (auto &buffer : *bufferVec) { buffer->setOffset(currentSize); buffer->setPointer(&pointerForUpload[currentSize]); - currentSize += buffer->getSize(); + targetSize = std::max(targetSize, currentSize + buffer->getSize()); + currentSize += ((buffer->getRealSize() > 0) ? buffer->getRealSize() : buffer->getSize()); int offsetDiff = currentSize % uniformBufferOffsetAlign; if (offsetDiff != 0) { @@ -379,7 +385,7 @@ void GDeviceGL33::updateBuffers(std::vector*> } } } - assert(currentSize == fullSize); + assert(targetSize == fullSize); for (int i = 0; i < bufferChunks.size(); i++) { auto &bufferVec = bufferChunks[i]; @@ -790,9 +796,9 @@ HFrameBuffer GDeviceGL33::createFrameBuffer(int width, int height, std::vector attachments, ITextureFormat depthAttachment, int multiSampleCnt, int frameNumber) override; - HGUniformBufferChunk createUniformBufferChunk(size_t size) override; + HGUniformBufferChunk createUniformBufferChunk(size_t size, size_t realSize = 0) override; HGTexture createBlpTexture(HBlpTexture &texture, bool xWrapTex, bool yWrapTex) override; HGTexture createTexture(bool xWrapTex, bool yWrapTex) override; diff --git a/wowViewerLib/src/gapi/ogl3.3/buffers/GUnformBufferChunk33.h b/wowViewerLib/src/gapi/ogl3.3/buffers/GUnformBufferChunk33.h index 21c20ae44..71e7333aa 100644 --- a/wowViewerLib/src/gapi/ogl3.3/buffers/GUnformBufferChunk33.h +++ b/wowViewerLib/src/gapi/ogl3.3/buffers/GUnformBufferChunk33.h @@ -14,7 +14,7 @@ class GUniformBufferChunk33 : public IUniformBufferChunk { public: - GUniformBufferChunk33(size_t size) : IUniformBufferChunk(size) {} + GUniformBufferChunk33(size_t size, size_t realSize = -1) : IUniformBufferChunk(size, realSize) {} void setUniformBuffer(HGUniformBuffer uniformBuffer) { m_uniformBuffer = uniformBuffer; From 53b6538e888220b48cdc5ae131b15bdd48d21f4c Mon Sep 17 00:00:00 2001 From: Deamon87 Date: Mon, 17 Oct 2022 19:50:58 +0300 Subject: [PATCH 4/9] fix one wmo shader + more counters --- src/ui/FrontendUI.cpp | 68 +++++++++----- src/ui/FrontendUI.h | 14 +-- .../shaders/glsl/vulkan/wmoShader.frag | 2 +- wowViewerLib/src/engine/SceneComposer.cpp | 26 +++-- wowViewerLib/src/engine/SceneComposer.h | 5 + wowViewerLib/src/engine/objects/iScene.h | 14 +-- .../src/engine/objects/scenes/NullScene.h | 10 +- .../src/engine/objects/scenes/m2Scene.cpp | 2 +- .../src/engine/objects/scenes/m2Scene.h | 2 +- .../src/engine/objects/scenes/map.cpp | 94 +++++++++++-------- wowViewerLib/src/engine/objects/scenes/map.h | 31 ++++-- wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp | 19 ++-- wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.h | 4 +- wowViewerLib/src/include/config.h | 17 +++- 14 files changed, 196 insertions(+), 112 deletions(-) diff --git a/src/ui/FrontendUI.cpp b/src/ui/FrontendUI.cpp index ebb777a6f..221b8d482 100644 --- a/src/ui/FrontendUI.cpp +++ b/src/ui/FrontendUI.cpp @@ -160,31 +160,48 @@ void FrontendUI::showCurrentStatsDialog() { if (ImGui::CollapsingHeader("Elapsed times")) { ImGui::Text("Elapsed time on culling : %.3f ms", m_api->getConfig()->cullingTimePerFrame); + ImGui::Text("- Elapsed time on cullCreateVarsCounter: %.3f ms", m_api->getConfig()->cullCreateVarsCounter); + ImGui::Text("- Elapsed time on cullGetCurrentWMOCounter: %.3f ms", m_api->getConfig()->cullGetCurrentWMOCounter); + ImGui::Text("- Elapsed time on cullGetCurrentZoneCounter: %.3f ms", m_api->getConfig()->cullGetCurrentZoneCounter); + ImGui::Text("- Elapsed time on cullUpdateLightsFromDBCounter: %.3f ms", m_api->getConfig()->cullUpdateLightsFromDBCounter); + ImGui::Text("- Elapsed time on cullExterior: %.3f ms", m_api->getConfig()->cullExterior); + ImGui::Text("-- Elapsed time on cullExteriorWDLCull: %.3f ms", m_api->getConfig()->cullExteriorWDLCull); + ImGui::Text("-- Elapsed time on cullExteriorGetCands: %.3f ms", m_api->getConfig()->cullExteriorGetCands); + ImGui::Text("-- Elapsed time on cullExterioFrustumWMO: %.3f ms", m_api->getConfig()->cullExterioFrustumWMO); + ImGui::Text("-- Elapsed time on cullExterioFrustumM2: %.3f ms", m_api->getConfig()->cullExterioFrustumM2); + ImGui::Text("- Elapsed time on cullSkyDoms: %.3f ms", m_api->getConfig()->cullSkyDoms); + ImGui::Text("- Elapsed time on cullCombineAllObjects: %.3f ms", m_api->getConfig()->cullCombineAllObjects); + + ImGui::Text("Elapsed time on drawStageAndDepsCNT: %.3f ms", m_api->getConfig()->drawStageAndDepsCNT); + ImGui::Text("Elapsed time on update : %.3f ms", m_api->getConfig()->updateTimePerFrame); - ImGui::Text("Elapsed time on m2 update : %.3f ms", m_api->getConfig()->m2UpdateTime); + ImGui::Text("- Elapsed time on startUpdateForNexFrame: %.3f ms", m_api->getConfig()->startUpdateForNexFrame); + ImGui::Text("- Elapsed time on singleUpdateCNT: %.3f ms", m_api->getConfig()->singleUpdateCNT); + ImGui::Text("-- Elapsed time on mapProduceUpdateTime : %.3f ms", m_api->getConfig()->mapProduceUpdateTime); + ImGui::Text("--- Elapsed time on map update : %.3f ms", m_api->getConfig()->mapUpdateTime); + ImGui::Text("---- Elapsed time on m2 update : %.3f ms", m_api->getConfig()->m2UpdateTime); + ImGui::Text("---- Elapsed time on wmo group update : %.3f ms", m_api->getConfig()->wmoGroupUpdateTime); + ImGui::Text("---- Elapsed time on adtUpdate update : %.3f ms", m_api->getConfig()->adtUpdateTime); + ImGui::Text("---- Elapsed time on m2 calc distance : %.3f ms", m_api->getConfig()->m2calcDistanceTime); + ImGui::Text("---- Elapsed time on adt cleanup : %.3f ms", m_api->getConfig()->adtCleanupTime); + ImGui::Text("--- Elapsed time on interiorViewCollectMeshTime : %.3f ms", m_api->getConfig()->interiorViewCollectMeshTime); + ImGui::Text("--- Elapsed time on exteriorViewCollectMeshTime : %.3f ms", m_api->getConfig()->exteriorViewCollectMeshTime); + ImGui::Text("--- Elapsed time on m2CollectMeshTime : %.3f ms", m_api->getConfig()->m2CollectMeshTime); + ImGui::Text("--- Elapsed time on sortMeshTime : %.3f ms", m_api->getConfig()->sortMeshTime); + ImGui::Text("--- Elapsed time on collectBuffersTime : %.3f ms", m_api->getConfig()->collectBuffersTime); + ImGui::Text("--- Elapsed time on sortBuffersTime : %.3f ms", m_api->getConfig()->sortBuffersTime); + + ImGui::Text("- Elapsed time on produceDrawStage: %.3f ms", m_api->getConfig()->produceDrawStage); + ImGui::Text("- Elapsed time on meshesCollectCNT: %.3f ms", m_api->getConfig()->meshesCollectCNT); + ImGui::Text("- Elapsed time on updateBuffersCNT: %.3f ms", m_api->getConfig()->updateBuffersCNT); + ImGui::Text("- Elapsed time on updateBuffersDeviceCNT: %.3f ms", m_api->getConfig()->updateBuffersDeviceCNT); + ImGui::Text("- Elapsed time on postLoadCNT: %.3f ms", m_api->getConfig()->postLoadCNT); + ImGui::Text("- Elapsed time on textureUploadCNT: %.3f ms", m_api->getConfig()->textureUploadCNT); + ImGui::Text("- Elapsed time on endUpdateCNT: %.3f ms", m_api->getConfig()->endUpdateCNT); + ImGui::Text("Elapsed time on wait for begin update: %.3f ms", m_api->hDevice->getWaitForUpdate()); - ImGui::Text("Elapsed time on singleUpdateCNT: %.3f ms", m_api->getConfig()->singleUpdateCNT); - ImGui::Text("Elapsed time on meshesCollectCNT: %.3f ms", m_api->getConfig()->meshesCollectCNT); - ImGui::Text("Elapsed time on updateBuffersCNT: %.3f ms", m_api->getConfig()->updateBuffersCNT); - ImGui::Text("Elapsed time on updateBuffersDeviceCNT: %.3f ms", m_api->getConfig()->updateBuffersDeviceCNT); - ImGui::Text("Elapsed time on postLoadCNT: %.3f ms", m_api->getConfig()->postLoadCNT); - ImGui::Text("Elapsed time on textureUploadCNT: %.3f ms", m_api->getConfig()->textureUploadCNT); - ImGui::Text("Elapsed time on drawStageAndDepsCNT: %.3f ms", m_api->getConfig()->drawStageAndDepsCNT); - ImGui::Text("Elapsed time on endUpdateCNT: %.3f ms", m_api->getConfig()->endUpdateCNT); - - ImGui::Text("Elapsed time on cullCreateVarsCounter: %.3f ms", m_api->getConfig()->cullCreateVarsCounter); - ImGui::Text("Elapsed time on cullGetCurrentWMOCounter: %.3f ms", m_api->getConfig()->cullGetCurrentWMOCounter); - ImGui::Text("Elapsed time on cullGetCurrentZoneCounter: %.3f ms", m_api->getConfig()->cullGetCurrentZoneCounter); - ImGui::Text("Elapsed time on cullUpdateLightsFromDBCounter: %.3f ms", m_api->getConfig()->cullUpdateLightsFromDBCounter); - ImGui::Text("Elapsed time on cullExterior: %.3f ms", m_api->getConfig()->cullExterior); - ImGui::Text("Elapsed time on cullExteriorWDLCull: %.3f ms", m_api->getConfig()->cullExteriorWDLCull); - ImGui::Text("Elapsed time on cullExteriorSetDecl: %.3f ms", m_api->getConfig()->cullExteriorSetDecl); - ImGui::Text("Elapsed time on cullExteriorGetCands: %.3f ms", m_api->getConfig()->cullExteriorGetCands); - ImGui::Text("Elapsed time on cullExterioFrustumWMO: %.3f ms", m_api->getConfig()->cullExterioFrustumWMO); - ImGui::Text("Elapsed time on cullExterioFrustumM2: %.3f ms", m_api->getConfig()->cullExterioFrustumM2); - ImGui::Text("Elapsed time on cullSkyDoms: %.3f ms", m_api->getConfig()->cullSkyDoms); - ImGui::Text("Elapsed time on cullCombineAllObjects: %.3f ms", m_api->getConfig()->cullCombineAllObjects); + ImGui::Separator(); } @@ -1263,7 +1280,7 @@ void FrontendUI::showSettingsDialog() { //#define logExecution { \ // std::cout << "Passed "<<__FUNCTION__<<" line " << __LINE__ << std::endl;\ //} -void FrontendUI::produceDrawStage(HDrawStage resultDrawStage, HUpdateStage updateStage, std::vector &additionalChunks) { +void FrontendUI::produceDrawStage(HDrawStage &resultDrawStage, HUpdateStage &updateStage, std::vector &additionalChunks) { auto m_device = m_api->hDevice; logExecution @@ -1525,7 +1542,7 @@ void FrontendUI::showMakeScreenshotDialog() { } } -void FrontendUI::produceUpdateStage(HUpdateStage updateStage) { +void FrontendUI::produceUpdateStage(HUpdateStage &updateStage) { this->update(updateStage); @@ -1693,7 +1710,8 @@ HFrameScenario FrontendUI::createFrameScenario(int canvWidth, int canvHeight, do auto drawStage = createSceneDrawStage(sceneScenario, canvWidth, canvHeight, deltaTime, false, - m_api->getConfig()->doubleCameraDebug, m_api->getConfig()->swapMainAndDebug, + m_api->getConfig()->doubleCameraDebug, + m_api->getConfig()->swapMainAndDebug, *m_api, currentScene, cullStageData); if (drawStage != nullptr) { diff --git a/src/ui/FrontendUI.h b/src/ui/FrontendUI.h index c4705aded..e257cd7fd 100644 --- a/src/ui/FrontendUI.h +++ b/src/ui/FrontendUI.h @@ -54,16 +54,16 @@ class FrontendUI : public IScene, public std::enable_shared_from_this &meshIds) override {}; - void produceDrawStage(HDrawStage resultDrawStage, HUpdateStage updateStage, std::vector &additionalChunks) override; - void produceUpdateStage(HUpdateStage updateStage) override; + void produceDrawStage(HDrawStage &resultDrawStage, HUpdateStage &updateStage, std::vector &additionalChunks) override; + void produceUpdateStage(HUpdateStage &updateStage) override; - void checkCulling(HCullStage cullStage) override {}; + void checkCulling(HCullStage &cullStage) override {}; - void doPostLoad(HCullStage cullStage) override {}; + void doPostLoad(HCullStage &cullStage) override {}; - void update(HUpdateStage updateStage) {}; - void updateBuffers(HUpdateStage updateStage) override {}; + void update(HUpdateStage &updateStage) {}; + void updateBuffers(HUpdateStage &updateStage) override {}; int getCameraNum() override {return 0;}; @@ -88,7 +88,7 @@ class FrontendUI : public IScene, public std::enable_shared_from_this m_cullstages = {}; + std::array m_cullstages = {}; std::shared_ptr m_minimapDB; diff --git a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag index 05577f439..294796a83 100644 --- a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag +++ b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag @@ -159,7 +159,7 @@ void main() { finalOpacity = tex.a; } else if (uPixelShader == 7) { //MapObjTwoLayerEnvMetal - vec4 colorMix = mix(tex2, tex, vColor2.a); + vec4 colorMix = mix(tex, tex2, vColor2.a); matDiffuse = colorMix.rgb ; emissive = (colorMix.rgb * colorMix.a) * tex3.rgb * distFade; diff --git a/wowViewerLib/src/engine/SceneComposer.cpp b/wowViewerLib/src/engine/SceneComposer.cpp index e417c386b..510c48232 100644 --- a/wowViewerLib/src/engine/SceneComposer.cpp +++ b/wowViewerLib/src/engine/SceneComposer.cpp @@ -90,7 +90,6 @@ SceneComposer::SceneComposer(HApiContainer apiContainer) : m_apiContainer(apiCon updateThread = std::thread(([&]() { // try { this->m_apiContainer->hDevice->initUploadThread(); - FrameCounter frameCounter; //NOTE: Refer to comment in cullingThread code auto currIndex = getPromiseInd(); while (!this->m_isTerminating) { @@ -100,11 +99,9 @@ SceneComposer::SceneComposer(HApiContainer apiContainer) : m_apiContainer(apiCon future.wait(); auto nextIndex = getNextPromiseInd(); - frameCounter.beginMeasurement(); + updateTimePerFrame.beginMeasurement(); DoUpdate(); - frameCounter.endMeasurement(); - - m_apiContainer->getConfig()->updateTimePerFrame = frameCounter.getTimePerFrame(); + updateTimePerFrame.endMeasurement(); updateFinished.set_value(true); currIndex = nextIndex; @@ -173,7 +170,9 @@ void SceneComposer::DoUpdate() { auto frameScenario = m_frameScenarios[updateObjFrame]; if (frameScenario == nullptr) return; logExecution + startUpdateForNexFrame.beginMeasurement(); device->startUpdateForNextFrame(); + startUpdateForNexFrame.endMeasurement(); logExecution singleUpdateCNT.beginMeasurement(); logExecution @@ -183,7 +182,7 @@ void SceneComposer::DoUpdate() { logExecution singleUpdateCNT.endMeasurement(); logExecution - meshesCollectCNT.beginMeasurement(); + produceDrawStage.beginMeasurement(); logExecution std::vector additionalChunks; logExecution @@ -192,7 +191,9 @@ void SceneComposer::DoUpdate() { link.scene->produceDrawStage(link.drawStage, link.updateStage, additionalChunks); logExecution } + produceDrawStage.endMeasurement(); + meshesCollectCNT.beginMeasurement(); std::vector meshes; logExecution collectMeshes(frameScenario->getDrawStage(), meshes); @@ -239,13 +240,13 @@ void SceneComposer::DoUpdate() { logExecution textureUploadCNT.endMeasurement(); - drawStageAndDepsCNT.beginMeasurement(); if (device->getIsVulkanAxisSystem()) { + drawStageAndDepsCNT.beginMeasurement(); if (frameScenario != nullptr) { m_apiContainer->hDevice->drawStageAndDeps(frameScenario->getDrawStage()); } + drawStageAndDepsCNT.endMeasurement(); } - drawStageAndDepsCNT.endMeasurement(); logExecution endUpdateCNT.beginMeasurement(); device->endUpdateForNextFrame(); @@ -254,7 +255,10 @@ void SceneComposer::DoUpdate() { logExecution auto config = m_apiContainer->getConfig(); + config->startUpdateForNexFrame = startUpdateForNexFrame.getTimePerFrame(); + config->updateTimePerFrame = updateTimePerFrame.getTimePerFrame(); config->singleUpdateCNT = singleUpdateCNT.getTimePerFrame(); + config->produceDrawStage = produceDrawStage.getTimePerFrame();; config->meshesCollectCNT = meshesCollectCNT.getTimePerFrame();; config->updateBuffersCNT = updateBuffersCNT.getTimePerFrame();; config->updateBuffersDeviceCNT = updateBuffersDeviceCNT.getTimePerFrame();; @@ -325,7 +329,11 @@ void SceneComposer::draw(HFrameScenario frameScenario) { logExecution m_apiContainer->hDevice->beginFrame(); if (thisFrameScenario != nullptr && !m_apiContainer->hDevice->getIsVulkanAxisSystem()) { + drawStageAndDepsCNT.beginMeasurement(); + m_apiContainer->hDevice->drawStageAndDeps(thisFrameScenario->getDrawStage()); + + drawStageAndDepsCNT.endMeasurement(); } logExecution @@ -335,7 +343,9 @@ void SceneComposer::draw(HFrameScenario frameScenario) { logExecution if (!m_apiContainer->hDevice->getIsAsynBuffUploadSupported()) { logExecution + updateTimePerFrame.beginMeasurement(); DoUpdate(); + updateTimePerFrame.endMeasurement(); logExecution } logExecution diff --git a/wowViewerLib/src/engine/SceneComposer.h b/wowViewerLib/src/engine/SceneComposer.h index c2e6d2766..ede01aea8 100644 --- a/wowViewerLib/src/engine/SceneComposer.h +++ b/wowViewerLib/src/engine/SceneComposer.h @@ -27,8 +27,13 @@ class SceneComposer { bool m_supportThreads = true; bool m_isTerminating = false; + FrameCounter submitDrawCommands; + FrameCounter updateTimePerFrame; + + FrameCounter startUpdateForNexFrame; FrameCounter singleUpdateCNT; + FrameCounter produceDrawStage; FrameCounter meshesCollectCNT; FrameCounter updateBuffersCNT; FrameCounter updateBuffersDeviceCNT; diff --git a/wowViewerLib/src/engine/objects/iScene.h b/wowViewerLib/src/engine/objects/iScene.h index aaa287985..f0fc83c25 100644 --- a/wowViewerLib/src/engine/objects/iScene.h +++ b/wowViewerLib/src/engine/objects/iScene.h @@ -23,21 +23,21 @@ class IScene { virtual void setMeshIds(std::vector &meshIds) = 0; virtual void resetAnimation() = 0; - virtual void produceDrawStage(HDrawStage resultDrawStage, HUpdateStage updateStage, std::vector &additionalChunks) = 0; - virtual void produceUpdateStage(HUpdateStage updateStage) = 0; + virtual void produceDrawStage(HDrawStage &resultDrawStage, HUpdateStage &updateStage, std::vector &additionalChunks) = 0; + virtual void produceUpdateStage(HUpdateStage &updateStage) = 0; - virtual void checkCulling(HCullStage cullStage) = 0; + virtual void checkCulling(HCullStage &cullStage) = 0; - virtual void doPostLoad(HCullStage cullStage) = 0; - virtual void updateBuffers(HUpdateStage updateStage) = 0; + virtual void doPostLoad(HCullStage &cullStage) = 0; + virtual void updateBuffers(HUpdateStage &updateStage) = 0; virtual int getCameraNum() = 0; virtual std::shared_ptr createCamera(int cameraNum) = 0; virtual void exportScene(IExporter * exporter) {}; - virtual void setAdtBoundingBoxHolder(HADTBoundingBoxHolder bbHolder) {}; - virtual void setMandatoryADTs(std::vector> mandatoryADTs) {}; + virtual void setAdtBoundingBoxHolder(HADTBoundingBoxHolder &bbHolder) {}; + virtual void setMandatoryADTs(std::vector> &mandatoryADTs) {}; virtual void getAdtAreaId(const mathfu::vec4 &cameraPos, int &areaId, int &parentAreaId) {}; }; #endif //WEBWOWVIEWERCPP_IINNERSCENEAPI_H diff --git a/wowViewerLib/src/engine/objects/scenes/NullScene.h b/wowViewerLib/src/engine/objects/scenes/NullScene.h index 06c7f7479..5643e3172 100644 --- a/wowViewerLib/src/engine/objects/scenes/NullScene.h +++ b/wowViewerLib/src/engine/objects/scenes/NullScene.h @@ -15,16 +15,16 @@ class NullScene : public IScene { virtual void setAnimationId(int animationId) override {}; virtual void setMeshIds(std::vector &meshIds) override {}; - virtual void produceUpdateStage(HUpdateStage updateStage) override {}; - virtual void produceDrawStage(HDrawStage resultDrawStage, HUpdateStage updateStage, std::vector &additionalChunks) override { + virtual void produceUpdateStage(HUpdateStage &updateStage) override {}; + virtual void produceDrawStage(HDrawStage &resultDrawStage, HUpdateStage &updateStage, std::vector &additionalChunks) override { resultDrawStage->transparentMeshes = std::make_shared(); resultDrawStage->opaqueMeshes = std::make_shared(); }; - virtual void checkCulling(HCullStage cullStage) override {}; + virtual void checkCulling(HCullStage &cullStage) override {}; - virtual void doPostLoad(HCullStage cullStage) override {}; - virtual void updateBuffers(HUpdateStage updateStage) override {}; + virtual void doPostLoad(HCullStage &cullStage) override {}; + virtual void updateBuffers(HUpdateStage &updateStage) override {}; virtual void resetAnimation() override {}; virtual int getCameraNum() override {return 0;}; virtual std::shared_ptr createCamera(int cameraNum) override { return nullptr;}; diff --git a/wowViewerLib/src/engine/objects/scenes/m2Scene.cpp b/wowViewerLib/src/engine/objects/scenes/m2Scene.cpp index a9d90ba42..e5d050c2a 100644 --- a/wowViewerLib/src/engine/objects/scenes/m2Scene.cpp +++ b/wowViewerLib/src/engine/objects/scenes/m2Scene.cpp @@ -53,7 +53,7 @@ extern "C" { extern void offerFileAsDownload(std::string filename, std::string mime); } -void M2Scene::doPostLoad(HCullStage cullStage) { +void M2Scene::doPostLoad(HCullStage &cullStage) { Map::doPostLoad(cullStage); } diff --git a/wowViewerLib/src/engine/objects/scenes/m2Scene.h b/wowViewerLib/src/engine/objects/scenes/m2Scene.h index 0a566c087..b0dfab187 100644 --- a/wowViewerLib/src/engine/objects/scenes/m2Scene.h +++ b/wowViewerLib/src/engine/objects/scenes/m2Scene.h @@ -52,7 +52,7 @@ class M2Scene : public Map { void setMeshIdArray(std::vector &meshIds) override ; void setReplaceParticleColors(std::array, 3> &particleColorReplacement) override; void resetReplaceParticleColor() override; - void doPostLoad(HCullStage cullStage) override; + void doPostLoad(HCullStage &cullStage) override; int getCameraNum() override ; std::shared_ptr createCamera(int cameraNum) override; diff --git a/wowViewerLib/src/engine/objects/scenes/map.cpp b/wowViewerLib/src/engine/objects/scenes/map.cpp index 0ee986627..05ff7976d 100644 --- a/wowViewerLib/src/engine/objects/scenes/map.cpp +++ b/wowViewerLib/src/engine/objects/scenes/map.cpp @@ -349,7 +349,7 @@ HGMesh createSkyMesh(IDevice *device, HGVertexBufferBindings skyBindings, Config return hmesh; } -void Map::checkCulling(HCullStage cullStage) { +void Map::checkCulling(HCullStage &cullStage) { // std::cout << "Map::checkCulling finished called" << std::endl; // std::cout << "m_wdtfile->getIsLoaded() = " << m_wdtfile->getIsLoaded() << std::endl; cullCreateVarsCounter.beginMeasurement(); @@ -1319,7 +1319,7 @@ void Map::createAdtFreeLamdas() { } -void Map::doPostLoad(HCullStage cullStage) { +void Map::doPostLoad(HCullStage &cullStage) { int processedThisFrame = 0; int wmoProcessedThisFrame = 0; int wmoGroupsProcessedThisFrame = 0; @@ -1397,7 +1397,8 @@ void Map::doPostLoad(HCullStage cullStage) { -void Map::update(HUpdateStage updateStage) { +void Map::update(HUpdateStage &updateStage) { + mapUpdateCounter.beginMeasurement(); mathfu::vec3 cameraVec3 = updateStage->cameraMatrices->cameraPos.xyz(); mathfu::mat4 &frustumMat = updateStage->cameraMatrices->perspectiveMat; mathfu::mat4 &lookAtMat = updateStage->cameraMatrices->lookAtMat; @@ -1418,31 +1419,36 @@ void Map::update(HUpdateStage updateStage) { }, tbb::simple_partitioner()); m2UpdateframeCounter.endMeasurement(); - - m_api->getConfig()->m2UpdateTime = m2UpdateframeCounter.getTimePerFrame(); } + wmoGroupUpdate.beginMeasurement(); for (const auto &wmoGroupObject : updateStage->cullResult->wmoGroupArray.getToDraw()) { if (wmoGroupObject == nullptr) continue; wmoGroupObject->update(); } + wmoGroupUpdate.endMeasurement(); + adtUpdate.beginMeasurement(); for (const auto &adtObjectRes : updateStage->cullResult->adtArray) { adtObjectRes->adtObject->update(deltaTime); } + adtUpdate.endMeasurement(); //2. Calc distance every 100 ms - tbb::parallel_for(tbb::blocked_range(0, m2ToDraw.size(), 200), + m2calcDistanceCounter.beginMeasurement(); + tbb::parallel_for(tbb::blocked_range(0, m2ToDraw.size(), 500), [&](tbb::blocked_range r) { for (size_t i = r.begin(); i != r.end(); ++i) { auto &m2Object = m2ToDraw[i]; if (m2Object == nullptr) continue; m2Object->calcDistance(cameraVec3); } - } + }, tbb::auto_partitioner() ); + m2calcDistanceCounter.endMeasurement(); //Cleanup ADT every 10 seconds + adtCleanupCounter.beginMeasurement(); if (adtFreeLambda!= nullptr && adtFreeLambda(true, false, this->m_currentTime)) { for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { @@ -1458,12 +1464,21 @@ void Map::update(HUpdateStage updateStage) { adtFreeLambda(false, true, this->m_currentTime + updateStage->delta); } + adtCleanupCounter.endMeasurement(); this->m_currentTime += updateStage->delta; + mapUpdateCounter.endMeasurement(); + + m_api->getConfig()->mapUpdateTime = mapUpdateCounter.getTimePerFrame(); + m_api->getConfig()->m2UpdateTime = m2UpdateframeCounter.getTimePerFrame(); + m_api->getConfig()->wmoGroupUpdateTime = wmoGroupUpdate.getTimePerFrame(); + m_api->getConfig()->adtUpdateTime = adtUpdate.getTimePerFrame(); + m_api->getConfig()->m2calcDistanceTime = m2calcDistanceCounter.getTimePerFrame(); + m_api->getConfig()->adtCleanupTime = adtCleanupCounter.getTimePerFrame(); //Collect meshes } -void Map::updateBuffers(HUpdateStage updateStage) { +void Map::updateBuffers(HUpdateStage &updateStage) { auto cullStage = updateStage->cullResult; for (auto &m2Object : cullStage->m2Array.getDrawn()) { @@ -1580,7 +1595,8 @@ std::shared_ptr Map::getWmoObject(int fileDataId, SMMapObjDefObj1 &ma animTime_t Map::getCurrentSceneTime() { return m_currentTime; } -void Map::produceUpdateStage(HUpdateStage updateStage) { +void Map::produceUpdateStage(HUpdateStage &updateStage) { + mapProduceUpdateCounter.beginMeasurement(); this->update(updateStage); //Create meshes @@ -1590,6 +1606,9 @@ void Map::produceUpdateStage(HUpdateStage updateStage) { auto &opaqueMeshes = updateStage->opaqueMeshes->meshes; auto transparentMeshes = std::vector(); + opaqueMeshes.reserve(30000); + transparentMeshes.reserve(30000); + auto cullStage = updateStage->cullResult; auto fdd = cullStage->frameDepedantData; @@ -1609,14 +1628,17 @@ void Map::produceUpdateStage(HUpdateStage updateStage) { } // Put everything into one array and sort + interiorViewCollectMeshCounter.beginMeasurement(); bool renderPortals = m_api->getConfig()->renderPortals; for (auto &view : cullStage->viewsHolder.getInteriorViews()) { view->collectMeshes(opaqueMeshes, transparentMeshes); if (renderPortals) { view->produceTransformedPortalMeshes(m_api, opaqueMeshes, transparentMeshes); } - }; + } + interiorViewCollectMeshCounter.endMeasurement(); + exteriorViewCollectMeshCounter.beginMeasurement(); { auto exteriorView = cullStage->viewsHolder.getExterior(); if (exteriorView != nullptr) { @@ -1626,30 +1648,9 @@ void Map::produceUpdateStage(HUpdateStage updateStage) { } } } + exteriorViewCollectMeshCounter.endMeasurement(); - std::set> m2ObjectsRendered; - -// for (auto &view : vector) { -// (view->drawnM2s.begin(),view->drawnM2s.end(), std::back_inserter(m2ObjectsRendered)); -// } - -// M2ObjectListContainer s; -// for (auto i : m2ObjectsRendered) -// s.insert(i); -// m2ObjectsRendered.assign( s.begin(), s.end() ); - -// std::set> s; -// unsigned size = m2ObjectsRendered.size(); -// for( unsigned i = 0; i < size; ++i ) s.insert( m2ObjectsRendered[i] ); -// m2ObjectsRendered.assign( s.begin(), s.end() ); - -// if (m2ObjectsRendered.size() > 2) { -// tbb::parallel_sort(m2ObjectsRendered.begin(), m2ObjectsRendered.end(), -// [](auto &first, auto &end) { return first < end; } -// ); -// m2ObjectsRendered.erase(unique(m2ObjectsRendered.begin(), m2ObjectsRendered.end()), m2ObjectsRendered.end()); -// } - + m2CollectMeshCounter.beginMeasurement(); if (m_api->getConfig()->renderM2) { for (auto &m2Object : cullStage->m2Array.getDrawn()) { if (m2Object == nullptr) continue; @@ -1657,15 +1658,15 @@ void Map::produceUpdateStage(HUpdateStage updateStage) { m2Object->drawParticles(opaqueMeshes, transparentMeshes, m_viewRenderOrder); } } + m2CollectMeshCounter.endMeasurement(); //No need to sort array which has only one element + sortMeshCounter.beginMeasurement(); if (transparentMeshes.size() > 1) { tbb::parallel_sort(transparentMeshes.begin(), transparentMeshes.end(), #include "../../../gapi/interface/sortLambda.h" ); -// std::sort(std::execution::par_unseq, transparentMeshes.begin(), transparentMeshes.end(), -// #include "../../../gapi/interface/sortLambda.h" -// ); + updateStage->transparentMeshes->meshes = transparentMeshes; } else { @@ -1674,10 +1675,12 @@ void Map::produceUpdateStage(HUpdateStage updateStage) { targetTranspMeshes.push_back(transparentMeshes[i]); } } + sortMeshCounter.endMeasurement(); //1. Collect buffers + collectBuffersCounter.beginMeasurement(); std::vector &bufferChunks = updateStage->uniformBufferChunks; - bufferChunks.reserve((opaqueMeshes.size() + updateStage->transparentMeshes->meshes.size()) * 3); + bufferChunks.reserve((opaqueMeshes.size() + updateStage->transparentMeshes->meshes.size()) * 5); int renderIndex = 0; for (const auto &mesh : opaqueMeshes) { for (int i = 0; i < 5; i++ ) { @@ -1697,14 +1700,27 @@ void Map::produceUpdateStage(HUpdateStage updateStage) { } } } + collectBuffersCounter.endMeasurement(); + sortBuffersCounter.beginMeasurement(); tbb::parallel_sort(bufferChunks.begin(), bufferChunks.end(), [](auto &first, auto &end) { return first < end; } ); bufferChunks.erase(unique(bufferChunks.begin(), bufferChunks.end()), bufferChunks.end()); + sortBuffersCounter.endMeasurement(); + + mapProduceUpdateCounter.endMeasurement(); + + m_api->getConfig()->mapProduceUpdateTime = mapProduceUpdateCounter.getTimePerFrame(); + m_api->getConfig()->interiorViewCollectMeshTime = interiorViewCollectMeshCounter.getTimePerFrame(); + m_api->getConfig()->exteriorViewCollectMeshTime = exteriorViewCollectMeshCounter.getTimePerFrame(); + m_api->getConfig()->m2CollectMeshTime = m2CollectMeshCounter.getTimePerFrame(); + m_api->getConfig()->sortMeshTime = sortMeshCounter.getTimePerFrame(); + m_api->getConfig()->collectBuffersTime = collectBuffersCounter.getTimePerFrame(); + m_api->getConfig()->sortBuffersTime = sortBuffersCounter.getTimePerFrame(); } -void Map::produceDrawStage(HDrawStage resultDrawStage, HUpdateStage updateStage, std::vector &additionalChunks) { +void Map::produceDrawStage(HDrawStage &resultDrawStage, HUpdateStage &updateStage, std::vector &additionalChunks) { auto cullStage = updateStage->cullResult; //Create scenewide uniform @@ -1812,7 +1828,7 @@ void Map::produceDrawStage(HDrawStage resultDrawStage, HUpdateStage updateStage, } } -HDrawStage Map::doGaussBlur(const HDrawStage parentDrawStage, HUpdateStage &updateStage) const { +HDrawStage Map::doGaussBlur(const HDrawStage &parentDrawStage, HUpdateStage &updateStage) const { if (quadBindings == nullptr) return nullptr; diff --git a/wowViewerLib/src/engine/objects/scenes/map.h b/wowViewerLib/src/engine/objects/scenes/map.h index e45c729bf..17144739e 100644 --- a/wowViewerLib/src/engine/objects/scenes/map.h +++ b/wowViewerLib/src/engine/objects/scenes/map.h @@ -34,7 +34,20 @@ class Map : public IScene, public IMapApi { } } protected: + FrameCounter mapProduceUpdateCounter; + FrameCounter interiorViewCollectMeshCounter; + FrameCounter exteriorViewCollectMeshCounter; + FrameCounter m2CollectMeshCounter; + FrameCounter sortMeshCounter; + FrameCounter collectBuffersCounter; + FrameCounter sortBuffersCounter; + + FrameCounter mapUpdateCounter; FrameCounter m2UpdateframeCounter; + FrameCounter m2calcDistanceCounter; + FrameCounter adtCleanupCounter; + FrameCounter wmoGroupUpdate; + FrameCounter adtUpdate; FrameCounter cullCreateVarsCounter; @@ -209,9 +222,9 @@ class Map : public IScene, public IMapApi { void setReplaceTextureArray(std::vector &replaceTextureArray) override {}; void setMeshIdArray(std::vector &meshIds) override {}; - void checkCulling(HCullStage cullStage) override; + void checkCulling(HCullStage &cullStage) override; - void setMandatoryADTs(std::vector> mandatoryADTs) override { + void setMandatoryADTs(std::vector> &mandatoryADTs) override { m_mandatoryADT = mandatoryADTs; } void getAdtAreaId(const mathfu::vec4 &cameraPos, int &areaId, int &parentAreaId) override; @@ -221,25 +234,25 @@ class Map : public IScene, public IMapApi { void resetAnimation() override { } - void setAdtBoundingBoxHolder(HADTBoundingBoxHolder bbHolder) override { + void setAdtBoundingBoxHolder(HADTBoundingBoxHolder &bbHolder) override { m_adtBBHolder = bbHolder; } - void doPostLoad(HCullStage cullStage) override; + void doPostLoad(HCullStage &cullStage) override; - void update(HUpdateStage updateStage); - void updateBuffers(HUpdateStage updateStage) override; - void produceUpdateStage(HUpdateStage updateStage) override; - void produceDrawStage(HDrawStage resultDrawStage, HUpdateStage updateStage, std::vector &additionalChunks) override; + void update(HUpdateStage &updateStage); + void updateBuffers(HUpdateStage &updateStage) override; + void produceUpdateStage(HUpdateStage &updateStage) override; + void produceDrawStage(HDrawStage &resultDrawStage, HUpdateStage &updateStage, std::vector &additionalChunks) override; private: void checkExterior(mathfu::vec4 &cameraPos, const MathHelper::FrustumCullingData &frustumData, int viewRenderOrder, HCullStage cullStage); - HDrawStage doGaussBlur(const HDrawStage parentDrawStage, HUpdateStage &updateStage) const; + HDrawStage doGaussBlur(const HDrawStage &parentDrawStage, HUpdateStage &updateStage) const; void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, std::vector &lightResults, StateForConditions *stateForConditions) override; diff --git a/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp b/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp index c2901e418..19f39eb5d 100644 --- a/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp +++ b/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.cpp @@ -24,6 +24,7 @@ #include "shaders/GFFXGlow.h" #include "shaders/GSkyConus.h" #include "shaders/GWaterfallShaderGL33.h" +#include "oneapi/tbb/parallel_for_each.h" namespace GL33 { BlendModeDesc blendModes[(int)EGxBlendEnum::GxBlend_MAX] = { @@ -391,14 +392,20 @@ void GDeviceGL33::updateBuffers(std::vector*> auto &bufferVec = bufferChunks[i]; auto frameDepData = frameDepedantDataVec[i]; - for (auto &buffer : *bufferVec) { - buffer->update(frameDepData); - } + oneapi::tbb::parallel_for(tbb::blocked_range(0, bufferVec->size(), 400), + [&](tbb::blocked_range &r) { + for (int i = r.begin(); i < r.end(); i++) { + (*bufferVec)[i]->update(frameDepData); + } + }, tbb::auto_partitioner()); +// for (auto &buffer : *bufferVec) { +// buffer->update(frameDepData); +// } } - if (currentSize > 0) { - bufferForUploadGL->uploadData(pointerForUpload, currentSize); - uploadAmountInBytes+= currentSize; + if (targetSize > 0) { + bufferForUploadGL->uploadData(pointerForUpload, targetSize); + uploadAmountInBytes+= targetSize; } } } diff --git a/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.h b/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.h index 70812b9d4..5e1b2faaf 100644 --- a/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.h +++ b/wowViewerLib/src/gapi/ogl3.3/GDeviceGL33.h @@ -44,10 +44,10 @@ typedef std::shared_ptr HGL33Mesh; -#define OPENGL_DGB_MESSAGE 1 - #if defined(__EMSCRIPTEN__) || defined(__APPLE__) #define OPENGL_DGB_MESSAGE 0 +#else +#define OPENGL_DGB_MESSAGE 0 #endif //#define logGLError { \ diff --git a/wowViewerLib/src/include/config.h b/wowViewerLib/src/include/config.h index 46230d5ef..46f39522b 100644 --- a/wowViewerLib/src/include/config.h +++ b/wowViewerLib/src/include/config.h @@ -148,9 +148,24 @@ class Config { //Stuff to display in UI double cullingTimePerFrame = 0; double updateTimePerFrame = 0; + double mapUpdateTime = 0; double m2UpdateTime = 0; - + double wmoGroupUpdateTime = 0; + double adtUpdateTime = 0; + double m2calcDistanceTime = 0; + double adtCleanupTime = 0; + + double mapProduceUpdateTime = 0; + double interiorViewCollectMeshTime = 0; + double exteriorViewCollectMeshTime = 0; + double m2CollectMeshTime = 0; + double sortMeshTime = 0; + double collectBuffersTime = 0; + double sortBuffersTime = 0; + + double startUpdateForNexFrame = 0; double singleUpdateCNT = 0; + double produceDrawStage = 0; double meshesCollectCNT = 0; double updateBuffersCNT = 0; double updateBuffersDeviceCNT = 0; From 1c3002ebb21d08d6cbf4dd741a1f9b637af14569 Mon Sep 17 00:00:00 2001 From: Deamon Date: Mon, 17 Oct 2022 19:59:05 +0300 Subject: [PATCH 5/9] display glow in stats --- src/ui/FrontendUI.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ui/FrontendUI.cpp b/src/ui/FrontendUI.cpp index 3262efeb4..0d489dbb0 100644 --- a/src/ui/FrontendUI.cpp +++ b/src/ui/FrontendUI.cpp @@ -202,6 +202,11 @@ void FrontendUI::showCurrentStatsDialog() { cullStageData->frameDepedantData->FogHeightCoefficients.z); } } + if (ImGui::CollapsingHeader("Current light params")) { + if (cullStageData->frameDepedantData != nullptr) { + ImGui::Text("Glow: %.3f", cullStageData->frameDepedantData->currentGlow); + } + } // ImGui::Text("Current Fog scaler: %f", m_api->getConfig()->getFogScaler()); // ImGui::Text("Current Fog density: %f", m_api->getConfig()->getFogDensity()); From c0c6a8cd70d91af789f8eea584cae6826de72d18 Mon Sep 17 00:00:00 2001 From: Deamon87 Date: Thu, 20 Oct 2022 03:35:05 +0300 Subject: [PATCH 6/9] seem to work without math hacks --- src/minimapGenerator/minimapGenerator.cpp | 264 ++++++++++-------- src/minimapGenerator/minimapGenerator.h | 12 + .../storage/CMinimapDataDB.cpp | 5 +- src/ui/FrontendUI.cpp | 21 +- .../src/engine/algorithms/mathHelper.cpp | 2 + .../camera/firstPersonOrthoStaticCamera.cpp | 6 +- .../src/engine/objects/adt/adtObject.cpp | 6 +- .../src/engine/objects/scenes/map.cpp | 27 ++ .../src/engine/shader/ShaderDefinitions.h | 34 +-- 9 files changed, 235 insertions(+), 142 deletions(-) diff --git a/src/minimapGenerator/minimapGenerator.cpp b/src/minimapGenerator/minimapGenerator.cpp index de6ac4c27..9742f7409 100644 --- a/src/minimapGenerator/minimapGenerator.cpp +++ b/src/minimapGenerator/minimapGenerator.cpp @@ -490,9 +490,9 @@ void MinimapGenerator::setupCameraData() { m_currentScene->setMandatoryADTs(adtVec); } - std::cout << "(Debug) m_x = " << m_x << " m_y = " << m_y << - ", x = " << (max.x + min.x) * 0.5f << - ", y = " << (max.y + min.y) * 0.5f << std::endl; +// std::cout << "(Debug) m_x = " << m_x << " m_y = " << m_y << +// ", x = " << (max.x + min.x) * 0.5f << +// ", y = " << (max.y + min.y) * 0.5f << std::endl; setLookAtPoint( (max.x + min.x) * 0.5, @@ -505,15 +505,12 @@ void MinimapGenerator::setZoom(float zoom) { } void MinimapGenerator::setLookAtPoint(float x, float y) { - mathfu::vec3 lookAtPoint = mathfu::vec3(x, y, 0); - - lookAtPoint = lookAtPoint; - //std::cout << "lookAtPoint = (" << lookAtPoint.x << ", " << lookAtPoint.y << ", " << lookAtPoint.z << ") " << std::endl; + mathfu::vec3 lookAtPoint2D = mathfu::vec3(x, y, 0); mathfu::vec3 lookAtVec3 = getLookAtVec3(); - lookAtPoint -= (7000.0f*lookAtVec3); + mathfu::vec3 lookAtPoint = lookAtPoint2D - ((m_minZ - 10) * lookAtVec3); - mathfu::vec3 cameraPos = lookAtPoint-(3000.0f*lookAtVec3); + mathfu::vec3 cameraPos = lookAtPoint2D - ((m_maxZ + 10)*lookAtVec3); // std::cout << "cameraPos = (" << cameraPos.x << ", " << cameraPos.y << ", " << cameraPos.z << ") " << std::endl; m_apiContainer->camera->setCameraPos( @@ -525,16 +522,88 @@ void MinimapGenerator::setLookAtPoint(float x, float y) { m_apiContainer->camera->tick(0); } +void MinimapGenerator::resetCandidate() { + prepearCandidate = false; + m_candidateDS = nullptr; + m_candidateCS = nullptr; + m_candidateUS = nullptr; + framesReady = 0; +} + +void MinimapGenerator::calcBB(const HCullStage &cullStage, mathfu::vec3 &minCoord, + mathfu::vec3 &maxCoord, + const CAaBox &adtBox2d, + int adt_x, int adt_y, bool applyAdtChecks) { + minCoord = mathfu::vec3(20000, 20000, 20000); + maxCoord = mathfu::vec3(-20000, -20000, -20000); + + for (auto &m2Object: cullStage->m2Array.getDrawn()) { + auto objBB = m2Object->getAABB(); + + if (applyAdtChecks && !MathHelper::isAabbIntersect2d(objBB, adtBox2d)) continue; + + minCoord = mathfu::vec3( + std::min(minCoord.x, objBB.min.x), + std::min(minCoord.y, objBB.min.y), + std::min(minCoord.z, objBB.min.z) + ); + maxCoord = mathfu::vec3( + std::max(maxCoord.x, objBB.max.x), + std::max(maxCoord.y, objBB.max.y), + std::max(maxCoord.z, objBB.max.z) + ); + } + + for (auto &wmoObject: cullStage->wmoGroupArray.getToDraw()) { + auto objBB = wmoObject->getWorldAABB(); + + if (applyAdtChecks && !MathHelper::isAabbIntersect2d(objBB, adtBox2d)) continue; + + minCoord = mathfu::vec3( + std::min(minCoord.x, objBB.min.x), + std::min(minCoord.y, objBB.min.y), + std::min(minCoord.z, objBB.min.z) + ); + maxCoord = mathfu::vec3( + std::max(maxCoord.x, objBB.max.x), + std::max(maxCoord.y, objBB.max.y), + std::max(maxCoord.z, objBB.max.z) + ); + } + + + for (auto &adtObjectRes: cullStage->adtArray) { + auto adtObj = adtObjectRes->adtObject; + + if (applyAdtChecks && (adtObj->getAdtX() != adt_x || adtObj->getAdtY() != adt_y)) { +// std::cout << "skipping adtObj( " << +// adtObj->getAdtX() << "," << adtObj->getAdtY() << " " +// ") for adt(" << adt_x << ", " << adt_y << ")" << std::endl; + + continue; + } -const int waitQueueLen = 5; + auto objBB = adtObj->calcAABB(); + + minCoord = mathfu::vec3( + std::min(minCoord.x, objBB.min.x), + std::min(minCoord.y, objBB.min.y), + std::min(minCoord.z, objBB.min.z) + ); + maxCoord = mathfu::vec3( + std::max(maxCoord.x, objBB.max.x), + std::max(maxCoord.y, objBB.max.y), + std::max(maxCoord.z, objBB.max.z) + ); + } +} + +const int waitQueueLen = 3; void MinimapGenerator::process() { - if (m_processor->completedAllJobs() && !m_apiContainer->hDevice->wasTexturesUploaded()) { + if (m_processor->completedAllJobs()) { framesReady++; } else { - framesReady = 0; - prepearCandidate = false; - m_candidateDS = nullptr; - m_candidateCS = nullptr; + resetCandidate(); return; } @@ -542,103 +611,71 @@ void MinimapGenerator::process() { return; } - if (!prepearCandidate) { - prepearCandidate = true; - m_candidateDS = nullptr; - m_candidateCS = nullptr; - framesReady = 0; + if ( + (m_candidateCS != nullptr && ( + (m_candidateCS->m2Array.getToLoadGeom().size() != 0) || + (m_candidateCS->m2Array.getToLoadMain().size() != 0) || + (m_candidateCS->wmoGroupArray.getToLoad().size() != 0) + ) + ) || + (m_candidateUS != nullptr && m_candidateUS->texturesForUpload.size() > 0) + ) { + resetCandidate(); return; } + if (m_candidateDS == nullptr) { + prepearCandidate = true; + return; + } auto lastFrameIt = m_candidateDS; auto lastFrameCull = m_candidateCS; - m_candidateDS = nullptr; - m_candidateCS = nullptr; - prepearCandidate = false; - framesReady = 0; - - if (m_mgMode == EMGMode::eBoundingBoxCalculation) { - int adt_x = m_x; - int adt_y = m_y; + resetCandidate(); + + //Check the BB and adjust minZ-maxZ + int adt_x = m_x; + int adt_y = m_y; + + vec2 minAdt = { + AdtIndexToWorldCoordinate(adt_y + 1), + AdtIndexToWorldCoordinate(adt_x + 1) + }; + vec2 maxAdt = { + AdtIndexToWorldCoordinate(adt_y), + AdtIndexToWorldCoordinate(adt_x), + }; + mathfu::vec3 minCoord = mathfu::vec3(20000, 20000, 20000); + mathfu::vec3 maxCoord = mathfu::vec3(-20000, -20000, -20000); + { - vec2 minAdt ={ - AdtIndexToWorldCoordinate(adt_y+1), - AdtIndexToWorldCoordinate(adt_x+1) - }; - vec2 maxAdt = { - AdtIndexToWorldCoordinate(adt_y), - AdtIndexToWorldCoordinate(adt_x), - }; CAaBox adtBox2d = { mathfu::vec3_packed(mathfu::vec3(minAdt.x, minAdt.y, 0)), mathfu::vec3_packed(mathfu::vec3(maxAdt.x, maxAdt.y, 0)) }; - mathfu::vec3 minCoord = mathfu::vec3(20000, 20000, 20000); - mathfu::vec3 maxCoord = mathfu::vec3(-20000, -20000, -20000); - - for (auto &m2Object: lastFrameCull->m2Array.getCandidates()) { - auto objBB = m2Object->getAABB(); - - if (!MathHelper::isAabbIntersect2d(objBB, adtBox2d)) continue; - - minCoord = mathfu::vec3( - std::min(minCoord.x, objBB.min.x), - std::min(minCoord.y, objBB.min.y), - std::min(minCoord.z, objBB.min.z) - ); - maxCoord = mathfu::vec3( - std::max(maxCoord.x, objBB.max.x), - std::max(maxCoord.y, objBB.max.y), - std::max(maxCoord.z, objBB.max.z) - ); - } - - for (auto &wmoObject: lastFrameCull->wmoArray.getCandidates()) { - auto objBB = wmoObject->getAABB(); - if (!MathHelper::isAabbIntersect2d(objBB, adtBox2d)) continue; - - minCoord = mathfu::vec3( - std::min(minCoord.x, objBB.min.x), - std::min(minCoord.y, objBB.min.y), - std::min(minCoord.z, objBB.min.z) - ); - maxCoord = mathfu::vec3( - std::max(maxCoord.x, objBB.max.x), - std::max(maxCoord.y, objBB.max.y), - std::max(maxCoord.z, objBB.max.z) - ); - } - - - for (auto &adtObjectRes: lastFrameCull->adtArray) { - auto adtObj = adtObjectRes->adtObject; - if (adtObj->getAdtX() != adt_x || adtObj->getAdtY() != adt_y) { - std::cout << "skipping adtObj( " << - adtObj->getAdtX() << "," << adtObj->getAdtY() << " " - ") for adt(" << adt_x << ", " << adt_y << ")" << std::endl; - - continue; + this->calcBB(lastFrameCull, minCoord, maxCoord, adtBox2d, adt_x, adt_y, m_mgMode == EMGMode::eBoundingBoxCalculation); + float zFar = (minCoord - maxCoord).Length(); + float maxZ = maxCoord.z; + float minZ = minCoord.z; + + if (!lastFrameCull->m2Array.getDrawn().empty() || !lastFrameCull->adtArray.empty() || + !lastFrameCull->wmoGroupArray.getToDraw().empty()) { + if (minCoord.x < 20000 && maxCoord.x > -20000) { + if (zFar > m_zFar || maxZ > m_maxZ || minZ < m_minZ) { + m_zFar = std::max(zFar, m_zFar); + m_maxZ = std::max(maxZ, m_maxZ); + m_minZ = std::min(minZ, m_minZ); + resetCandidate(); + setupCameraData(); + return; + } } - - auto objBB = adtObj->calcAABB(); - minCoord = mathfu::vec3( - std::min(minCoord.x, objBB.min.x), - std::min(minCoord.y, objBB.min.y), - std::min(minCoord.z, objBB.min.z) - ); - maxCoord = mathfu::vec3( - std::max(maxCoord.x, objBB.max.x), - std::max(maxCoord.y, objBB.max.y), - std::max(maxCoord.z, objBB.max.z) - ); } + } - std::cout << "minCoord = (" << minCoord.x << ", " << minCoord.y << ", " << minCoord.z << ")" << std::endl; - std::cout << "maxCoord = (" << maxCoord.x << ", " << maxCoord.y << ", " << maxCoord.z << ")" << std::endl; - - //Set x-y limits according to current adt index, since bounding box counting process is done per ADT + //Conditional mode stuff + if (m_mgMode == EMGMode::eBoundingBoxCalculation) { minCoord = mathfu::vec3( minAdt.x, minAdt.y, @@ -662,17 +699,24 @@ void MinimapGenerator::process() { saveDrawStageToFile(currentScenario.folderToSave, lastFrameIt); } - m_y--; - if (m_y < 0) { - m_x++; - m_y = m_chunkHeight - 1; - } + //Apply this logic only if it's not a preview mode + if (m_mgMode != EMGMode::ePreview) { + m_y--; + if (m_y < 0) { + m_x++; + m_y = m_chunkHeight - 1; + } // std::cout << "m_x = " << m_x << " out of (" << m_chunkStartX+m_chunkWidth << ") m_y = " << m_y << " out of (" << m_chunkStartY+m_chunkHeight << ")" << std::endl; - if (m_x >= m_chunkWidth) { - startNextScenario(); - } else { - setupCameraData(); + if (m_x >= m_chunkWidth) { + startNextScenario(); + } else { + //reset + m_zFar = 10000.0f; + m_maxZ = 1000.0f; + m_minZ = -1000.0f; + setupCameraData(); + } } } @@ -751,9 +795,10 @@ HDrawStage MinimapGenerator::createSceneDrawStage(HFrameScenario sceneScenario) m_lastDraw = sceneDrawStage; //We dont need stack in preview mode - if (m_mgMode != EMGMode::ePreview && prepearCandidate && m_candidateDS == nullptr) { + if (prepearCandidate && m_candidateDS == nullptr) { m_candidateDS = sceneDrawStage; m_candidateCS = cullStage; + m_candidateUS = updateStage; } stackOfCullStages[m_apiContainer->hDevice->getDrawFrameNumber()] = cullStage; @@ -770,10 +815,11 @@ float MinimapGenerator::GetOrthoDimension() { } mathfu::mat4 MinimapGenerator::getOrthoMatrix() { - return mathfu::mat4::Ortho( + return + mathfu::mat4::Ortho( -GetOrthoDimension() / 2.0f,GetOrthoDimension() / 2.0f, -GetOrthoDimension() / 2.0f,GetOrthoDimension() / 2.0f, - 1,10000 + 1,m_zFar + 10, 1 ); } diff --git a/src/minimapGenerator/minimapGenerator.h b/src/minimapGenerator/minimapGenerator.h index 813154e42..cb89af231 100644 --- a/src/minimapGenerator/minimapGenerator.h +++ b/src/minimapGenerator/minimapGenerator.h @@ -45,14 +45,26 @@ class MinimapGenerator { std::array stackOfCullStages; + HUpdateStage m_candidateUS = nullptr; HDrawStage m_candidateDS = nullptr; HCullStage m_candidateCS = nullptr; + + float m_zFar = 3000.0f; + float m_maxZ = 1000.0f; + float m_minZ = -1000.0f; + + int framesReady = 0; bool prepearCandidate = false; mathfu::mat4 getOrthoMatrix(); mathfu::vec3 getLookAtVec3(); void startNextScenario(); + void resetCandidate(); + + void calcBB(const HCullStage &cullStage, mathfu::vec3 &minCoord, + mathfu::vec3 &maxCoord, const CAaBox &adtBox2d, + int adt_x, int adt_y, bool applyAdtChecks); mathfu::mat4 genTempProjectMatrix(); public: diff --git a/src/minimapGenerator/storage/CMinimapDataDB.cpp b/src/minimapGenerator/storage/CMinimapDataDB.cpp index d15a7c139..744acd495 100644 --- a/src/minimapGenerator/storage/CMinimapDataDB.cpp +++ b/src/minimapGenerator/storage/CMinimapDataDB.cpp @@ -27,7 +27,7 @@ CMinimapDataDB::CMinimapDataDB(std::string fileName) : m_sqliteDatabase(fileName " ocean_color_0 FLOAT,\n" " ocean_color_1 FLOAT,\n" " ocean_color_2 FLOAT,\n" - " ocean_color_3 FLOAT\n" + " ocean_color_3 FLOAT,\n" " world_coord_min_x FLOAT,\n" " world_coord_min_y FLOAT,\n" " world_coord_max_x FLOAT,\n" @@ -108,6 +108,9 @@ CMinimapDataDB::CMinimapDataDB(std::string fileName) : m_sqliteDatabase(fileName } void CMinimapDataDB::getScenarios(std::vector &scenarioList) { + if (!m_sqliteDatabase.tableExists("scenarios")) + return; + SQLite::Statement getScenarioList(m_sqliteDatabase, "select s.id, s.map_id, s.orientation, s.name, \n" " s.ocean_color_0, s.ocean_color_1, s.ocean_color_2, s.ocean_color_3,\n" diff --git a/src/ui/FrontendUI.cpp b/src/ui/FrontendUI.cpp index 5c5d8aee0..ef19c3a4d 100644 --- a/src/ui/FrontendUI.cpp +++ b/src/ui/FrontendUI.cpp @@ -1658,12 +1658,7 @@ HDrawStage createSceneDrawStage(HFrameScenario sceneScenario, int width, int hei } HFrameScenario FrontendUI::createFrameScenario(int canvWidth, int canvHeight, double deltaTime) { - if (minimapGenerator != nullptr && - ( - minimapGenerator->getCurrentMode() == EMGMode::eScreenshotGeneration || - minimapGenerator->getCurrentMode() == EMGMode::eBoundingBoxCalculation - ) - ) { + if (minimapGenerator != nullptr && minimapGenerator->getCurrentMode() != EMGMode::eNone) { minimapGenerator->process(); } @@ -2354,15 +2349,23 @@ void FrontendUI::showMinimapGenerationSettingsDialog() { const int imageSize = 512; - if (ImGui::ImageButton2(texture, "previewImage", ImVec2(imageSize, imageSize))) { + if (ImGui::ImageButton2(texture, "previewImage", + ImVec2(imageSize, imageSize), + ImVec2(0,1), + ImVec2(1,0))) + { auto mousePos = ImGui::GetMousePos(); ImGuiStyle &style = ImGui::GetStyle(); mousePos.x += -ImGui::GetWindowPos().x - style.WindowPadding.x; mousePos.y += -ImGui::GetWindowPos().y - style.WindowPadding.y; - previewX = (0.5f - (mousePos.y / (float)imageSize)) * minimapGenerator->GetOrthoDimension() + previewX; - previewY = (0.5f - (mousePos.x / (float)imageSize)) * minimapGenerator->GetOrthoDimension() + previewY; + + previewX = ((0.5f - (mousePos.y / (float)imageSize)) * minimapGenerator->GetOrthoDimension()) + previewX; + previewY = ((0.5f - (mousePos.x / (float)imageSize)) * minimapGenerator->GetOrthoDimension()) + previewY; + + + minimapGenerator->setLookAtPoint(previewX, previewY); }; diff --git a/wowViewerLib/src/engine/algorithms/mathHelper.cpp b/wowViewerLib/src/engine/algorithms/mathHelper.cpp index 266a8c73f..f43e78b5b 100644 --- a/wowViewerLib/src/engine/algorithms/mathHelper.cpp +++ b/wowViewerLib/src/engine/algorithms/mathHelper.cpp @@ -174,6 +174,8 @@ bool hullSort(mathfu::vec3 a, mathfu::vec3 b, mathfu::vec2 center) { } std::vector MathHelper::getHullPoints(std::vector &points){ + if (points.empty()) + return {}; std::stack hullPoints = grahamScan(points); if (hullPoints.size() <= 2) { return std::vector(0); diff --git a/wowViewerLib/src/engine/camera/firstPersonOrthoStaticCamera.cpp b/wowViewerLib/src/engine/camera/firstPersonOrthoStaticCamera.cpp index da1865d38..ae288a7d3 100644 --- a/wowViewerLib/src/engine/camera/firstPersonOrthoStaticCamera.cpp +++ b/wowViewerLib/src/engine/camera/firstPersonOrthoStaticCamera.cpp @@ -25,9 +25,9 @@ void FirstPersonOrthoStaticCamera::tick (animTime_t timeDelta) { // cameraRotationMat = cameraRotationMat * MathHelper::RotationX(90*M_PI/180); lookAtMat = mathfu::mat4::LookAt( - camera.xyz(), - lookAt, - mathfu::vec3(0,0,1)); + lookAt, + camera.xyz(), + mathfu::vec3(0,0,1), 1.0); mathfu::vec4 interiorSunDir = mathfu::vec4(-0.30822f, -0.30822f, -0.89999998f, 0); diff --git a/wowViewerLib/src/engine/objects/adt/adtObject.cpp b/wowViewerLib/src/engine/objects/adt/adtObject.cpp index b0a4d06ed..d35f4c45e 100644 --- a/wowViewerLib/src/engine/objects/adt/adtObject.cpp +++ b/wowViewerLib/src/engine/objects/adt/adtObject.cpp @@ -601,10 +601,10 @@ void AdtObject::calcBoundingBoxes() { float minZ = 999999; float maxZ = -999999; if (mcnkContent->mcvt != nullptr) { - for (int j = 0; j < 8 * 8 + 9 * 9; j++) { + for (int j = 0; j < (8 * 8 + 9 * 9); j++) { float heightVal = mcnkContent->mcvt->height[j]; - if (minZ > heightVal) minZ = heightVal; - if (maxZ < heightVal) maxZ = heightVal; + if (heightVal < minZ) minZ = heightVal; + if (heightVal > maxZ) maxZ = heightVal; } } diff --git a/wowViewerLib/src/engine/objects/scenes/map.cpp b/wowViewerLib/src/engine/objects/scenes/map.cpp index 05ff7976d..c75cceba2 100644 --- a/wowViewerLib/src/engine/objects/scenes/map.cpp +++ b/wowViewerLib/src/engine/objects/scenes/map.cpp @@ -564,6 +564,8 @@ void Map::checkCulling(HCullStage &cullStage) { cullCombineAllObjects.endMeasurement(); + + m_api->getConfig()->cullCreateVarsCounter = cullCreateVarsCounter.getTimePerFrame(); m_api->getConfig()->cullGetCurrentWMOCounter = cullGetCurrentWMOCounter.getTimePerFrame(); m_api->getConfig()->cullGetCurrentZoneCounter = cullGetCurrentZoneCounter.getTimePerFrame(); @@ -1677,6 +1679,29 @@ void Map::produceUpdateStage(HUpdateStage &updateStage) { } sortMeshCounter.endMeasurement(); + //Collect textures for upload + auto &textureToUpload = updateStage->texturesForUpload; + textureToUpload.reserve(10000); + for (auto &mesh: updateStage->transparentMeshes->meshes) { + for (auto &text : mesh->texture()) { + if (text != nullptr && !text->getIsLoaded()) { + textureToUpload.push_back(text); + } + } + } + for (auto &mesh: updateStage->opaqueMeshes->meshes) { + for (auto &text : mesh->texture()) { + if (text != nullptr && !text->getIsLoaded()) { + textureToUpload.push_back(text); + } + } + } + + tbb::parallel_sort(textureToUpload.begin(), textureToUpload.end(), + [](auto &first, auto &end) { return first < end; } + ); + textureToUpload.erase(unique(textureToUpload.begin(), textureToUpload.end()), textureToUpload.end()); + //1. Collect buffers collectBuffersCounter.beginMeasurement(); std::vector &bufferChunks = updateStage->uniformBufferChunks; @@ -1826,6 +1851,8 @@ void Map::produceDrawStage(HDrawStage &resultDrawStage, HUpdateStage &updateStag //Replace all data in target drawStage with new data *resultDrawStage = *prevDrawStage; } + + } HDrawStage Map::doGaussBlur(const HDrawStage &parentDrawStage, HUpdateStage &updateStage) const { diff --git a/wowViewerLib/src/engine/shader/ShaderDefinitions.h b/wowViewerLib/src/engine/shader/ShaderDefinitions.h index 136c048c1..707282043 100644 --- a/wowViewerLib/src/engine/shader/ShaderDefinitions.h +++ b/wowViewerLib/src/engine/shader/ShaderDefinitions.h @@ -922,23 +922,23 @@ const std::unordered_map Date: Sun, 11 Dec 2022 20:18:09 +0200 Subject: [PATCH 7/9] update casclib --- 3rdparty/casclib | 2 +- wowViewerLib/3rdparty/mathfu | 2 +- wowViewerLib/3rdparty/oneTbb | 2 +- .../src/engine/shader/ShaderDefinitions.h | 34 +++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/3rdparty/casclib b/3rdparty/casclib index 8ac182b2f..136c6e055 160000 --- a/3rdparty/casclib +++ b/3rdparty/casclib @@ -1 +1 @@ -Subproject commit 8ac182b2fe1197bd979b6a08cf001508bb460d6f +Subproject commit 136c6e05537bd7123620ddb28671d1f2cf060e0b diff --git a/wowViewerLib/3rdparty/mathfu b/wowViewerLib/3rdparty/mathfu index da23a1227..f3e7f0d22 160000 --- a/wowViewerLib/3rdparty/mathfu +++ b/wowViewerLib/3rdparty/mathfu @@ -1 +1 @@ -Subproject commit da23a1227bb65fbb7f2f5b6c504fbbdd1dfdab4b +Subproject commit f3e7f0d22fd1e2317c8fade8db5d85fac1fd0322 diff --git a/wowViewerLib/3rdparty/oneTbb b/wowViewerLib/3rdparty/oneTbb index a927a6bba..549f03220 160000 --- a/wowViewerLib/3rdparty/oneTbb +++ b/wowViewerLib/3rdparty/oneTbb @@ -1 +1 @@ -Subproject commit a927a6bba93b77037b8377ddef025047d0270650 +Subproject commit 549f032201ecd3dad8925d776394afafa021fe3a diff --git a/wowViewerLib/src/engine/shader/ShaderDefinitions.h b/wowViewerLib/src/engine/shader/ShaderDefinitions.h index 707282043..136c048c1 100644 --- a/wowViewerLib/src/engine/shader/ShaderDefinitions.h +++ b/wowViewerLib/src/engine/shader/ShaderDefinitions.h @@ -922,23 +922,23 @@ const std::unordered_map Date: Sun, 11 Dec 2022 20:31:28 +0200 Subject: [PATCH 8/9] update casclib --- wowViewerLib/3rdparty/mathfu | 2 +- wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/wowViewerLib/3rdparty/mathfu b/wowViewerLib/3rdparty/mathfu index f3e7f0d22..da23a1227 160000 --- a/wowViewerLib/3rdparty/mathfu +++ b/wowViewerLib/3rdparty/mathfu @@ -1 +1 @@ -Subproject commit f3e7f0d22fd1e2317c8fade8db5d85fac1fd0322 +Subproject commit da23a1227bb65fbb7f2f5b6c504fbbdd1dfdab4b diff --git a/wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag b/wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag index 34a5e34e4..1b75687e0 100644 --- a/wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag +++ b/wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag @@ -23,6 +23,7 @@ layout(std140, binding=0) uniform sceneWideBlockVSPS { layout(std140, binding=4) uniform meshWideBlockPS { vec4 uAlphaTestv; ivec4 uPixelShaderBlendModev; + vec4 uTextureTranslate; }; layout(set=1,binding=5) uniform sampler2D uTexture; From b3f4978126c2a90b38b658452604fdc9406f3bf8 Mon Sep 17 00:00:00 2001 From: Deamon87 Date: Sun, 11 Dec 2022 20:35:30 +0200 Subject: [PATCH 9/9] fix oneTBB --- wowViewerLib/3rdparty/oneTbb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wowViewerLib/3rdparty/oneTbb b/wowViewerLib/3rdparty/oneTbb index 549f03220..a927a6bba 160000 --- a/wowViewerLib/3rdparty/oneTbb +++ b/wowViewerLib/3rdparty/oneTbb @@ -1 +1 @@ -Subproject commit 549f032201ecd3dad8925d776394afafa021fe3a +Subproject commit a927a6bba93b77037b8377ddef025047d0270650