diff --git a/.gitmodules b/.gitmodules index 0c374ed6..f6a1bc48 100644 --- a/.gitmodules +++ b/.gitmodules @@ -20,6 +20,6 @@ path = Karma/vendor/SDL url = https://github.com/ravimohan1991/SDL.git ignore = dirty -[submodule "Karma/vendor/BiosReader"] - path = Karma/vendor/BiosReader - url = https://github.com/ravimohan1991/BiosReader.git +[submodule "Karma/vendor/hwinfo"] + path = Karma/vendor/hwinfo + url = https://github.com/ravimohan1991/hwinfo.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 10c21118..f1f0793c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ set(KARMALIBRARYFOLDER "CompanionLibraries") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${REPOSITORYROOT}/KarmaBin") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${REPOSITORYROOT}/KarmaBin") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${REPOSITORYROOT}/KarmaBin") # Set the GameName @@ -75,9 +76,6 @@ add_subdirectory(Pranjal) target_link_libraries(SandBox PUBLIC KarmaEngine) target_link_libraries(Pranjal PUBLIC KarmaEngine) -# Need to find a way to give access to the resources (assets and whatnot) to the built binaries - - #[[ * /\ * / / diff --git a/Karma/CMakeLists.txt b/Karma/CMakeLists.txt index f91ae11a..c286496e 100644 --- a/Karma/CMakeLists.txt +++ b/Karma/CMakeLists.txt @@ -57,7 +57,9 @@ ENDMACRO(PRINT_LIST) # Then the checks find_package(Vulkan REQUIRED) -find_package(OpenGL REQUIRED) +if(NOT APPLE) + find_package(OpenGL REQUIRED) +endif() find_package(Threads REQUIRED) message(STATUS "Checks are satisfied, we are good to proceed!") @@ -170,17 +172,19 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_compile_definitions(KR_DEBUG) endif() +# Telling hwinfo to output library dll to our KarmaBin folder +set(HWINFO_CMAKE_BINARY_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + # Involved libraries and essentials add_subdirectory(vendor/Glad) add_subdirectory(vendor/GLFW) add_subdirectory(vendor/GLM) add_subdirectory(vendor/SDL) -# add_subdirectory(vendor/ImGui) add_subdirectory(vendor/spdlog) add_subdirectory(vendor/assimp) add_subdirectory(vendor/glslang) add_subdirectory(vendor/stb) -add_subdirectory(vendor/BiosReader) +add_subdirectory(vendor/hwinfo) list(APPEND ESSENTIAL_LIBS Glad) list(APPEND ESSENTIAL_LIBS GLFW) @@ -190,13 +194,13 @@ if(BUILD_SHARED_LIBS AND NOT MSVC) else() list(APPEND ESSENTIAL_LIBS SDL2-static) endif() -# list(APPEND ESSENTIAL_LIBS ImGUI) list(APPEND ESSENTIAL_LIBS spdlog) list(APPEND ESSENTIAL_LIBS AssImp) list(APPEND ESSENTIAL_LIBS ${Vulkan_LIBRARY}) list(APPEND ESSENTIAL_LIBS GlSlang) list(APPEND ESSENTIAL_LIBS stbimage) -list(APPEND ESSENTIAL_LIBS BiosReader) +list(APPEND ESSENTIAL_LIBS hwinfo) + # Print Karma's libraries message(STATUS "########################") @@ -250,18 +254,21 @@ if(BUILD_SHARED_LIBS AND NOT MSVC) else() target_link_libraries(KarmaEngine PUBLIC SDL2-static) endif() -# target_link_libraries(KarmaEngine PUBLIC ImGUI) target_link_libraries(KarmaEngine PUBLIC spdlogging) target_link_libraries(KarmaEngine PUBLIC AssImp) target_link_libraries(KarmaEngine PUBLIC ${Vulkan_LIBRARY}) +if(APPLE) + target_link_libraries(KarmaEngine PUBLIC "-framework OpenGL") +else() + target_link_libraries(KarmaEngine PUBLIC ${OPENGL_LIBRARIES}) +endif() target_link_libraries(KarmaEngine PUBLIC GlSlang) target_link_libraries(KarmaEngine PUBLIC stbimage) -target_link_libraries(KarmaEngine PUBLIC BiosReader) +target_link_libraries(KarmaEngine PUBLIC hwinfo) # Cluster Karma's libraries into a single folder for project/solution visualization set_property(TARGET Glad PROPERTY FOLDER "${KARMALIBRARYFOLDER}") set_property(TARGET AssImp PROPERTY FOLDER "${KARMALIBRARYFOLDER}") -# set_property(TARGET ImGUI PROPERTY FOLDER "${KARMALIBRARYFOLDER}") set_property(TARGET GlSlang PROPERTY FOLDER "${KARMALIBRARYFOLDER}") set_property(TARGET spdlogging PROPERTY FOLDER "${KARMALIBRARYFOLDER}") set_property(TARGET stbimage PROPERTY FOLDER "${KARMALIBRARYFOLDER}") @@ -278,8 +285,7 @@ else() set_property(TARGET glm_static PROPERTY FOLDER "${KARMALIBRARYFOLDER}") ]] endif() - -set_property(TARGET BiosReader PROPERTY FOLDER "${KARMALIBRARYFOLDER}") +set_property(TARGET hwinfo PROPERTY FOLDER "${KARMALIBRARYFOLDER}") # INTERFACE (Something that Consumers require but Producers don't) # Since I am a library coder here, I am the Producer @@ -292,7 +298,7 @@ target_include_directories(KarmaEngine ${CMAKE_CURRENT_SOURCE_DIR}/vendor/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/vendor/assimp/contrib ${CMAKE_CURRENT_SOURCE_DIR}/vendor/assimp/include - ${CMAKE_CURRENT_SOURCE_DIR}/vendor/BiosReader/src/public + ${CMAKE_CURRENT_SOURCE_DIR}/vendor/hwinfo/include ${Vulkan_INCLUDE_DIR} PUBLIC # where top-level project will look for the library's public headers diff --git a/Karma/src/Karma/KarmaGui/KarmaGuiRenderer.cpp b/Karma/src/Karma/KarmaGui/KarmaGuiRenderer.cpp index 0bc03a81..6dd720ca 100644 --- a/Karma/src/Karma/KarmaGui/KarmaGuiRenderer.cpp +++ b/Karma/src/Karma/KarmaGui/KarmaGuiRenderer.cpp @@ -441,8 +441,6 @@ namespace Karma result = vkWaitForFences(vulkanInfo->Device, 1, &frameOnFlightData->Fence, VK_TRUE, UINT64_MAX); KR_CORE_ASSERT(result == VK_SUCCESS, "Failed to wait"); - result = vkResetFences(vulkanInfo->Device, 1, &frameOnFlightData->Fence); - KR_CORE_ASSERT(result == VK_SUCCESS, "Failed to reset fence"); // ImageAcquiredSemaphore is m_ImageAvailableSemaphores equivalent VkSemaphore imageAcquiredSemaphore = frameOnFlightData->ImageAcquiredSemaphore; @@ -455,71 +453,69 @@ namespace Karma return; } - vkResetCommandBuffer(frameOnFlightData->CommandBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); - - // recording begins: - { - VkCommandBufferBeginInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; - - result = vkBeginCommandBuffer(frameOnFlightData->CommandBuffer, &info); - KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't begin commandbuffer recording"); - } - - for(auto it = backendData->Elements3DTo2D.begin(); it != backendData->Elements3DTo2D.end(); ++it) - { - { - VkRenderPassBeginInfo renderPassInfo{}; - renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - renderPassInfo.renderPass = it->RenderPass; - renderPassInfo.framebuffer = it->FrameBuffers[windowData->ImageFrameIndex]; - renderPassInfo.renderArea.offset = {0, 0}; - renderPassInfo.renderArea.extent.width = it->Size.x; - renderPassInfo.renderArea.extent.height = it->Size.y; - - // Define clear values for the color and depth attachments - std::vector clearValues(2); - clearValues[0].color = {{0.0f, 0.0f, 0.0f, 1.0f}}; // Clear color to black - clearValues[1].depthStencil = {1.0f, 0}; // Clear depth to 1.0 (farthest) - - renderPassInfo.clearValueCount = static_cast(clearValues.size()); - renderPassInfo.pClearValues = clearValues.data(); - - // The pass starts here and all commands until vkCmdEndRenderPass are recorded into it - vkCmdBeginRenderPass(frameOnFlightData->CommandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); - - std::shared_ptr vulkanVA = static_pointer_cast(it->Scene3D->GetRenderableVertexArray()); - - vkCmdBindPipeline(frameOnFlightData->CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkanVA->GetKarmaGuiGraphicsPipeline()); - - // Bind 3D Vertex And Index Buffers: - { - VkBuffer vertexBuffers[1] = { vulkanVA->GetVertexBuffer()->GetVertexBuffer() }; - VkDeviceSize vertexOffset[1] = { 0 }; - vkCmdBindVertexBuffers(frameOnFlightData->CommandBuffer, 0, 1, vertexBuffers, vertexOffset); - vkCmdBindIndexBuffer(frameOnFlightData->CommandBuffer, vulkanVA->GetIndexBuffer()->GetIndexBuffer(), 0, VK_INDEX_TYPE_UINT32); - } - - vulkanVA->UpdateProcessAndSetReadyForSubmission(); - vulkanVA->Bind(); + KR_CORE_ASSERT(result == VK_SUCCESS, "Failed to acquire next image"); - VulkanHolder::GetVulkanContext()->UploadUBO(windowData->SemaphoreIndex); + vkResetCommandBuffer(frameOnFlightData->CommandBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); - // Bind descriptor sets (e.g., uniforms for MVP matrices, lighting) - // Assumes layout compatibility between pipeline and descriptor set - vkCmdBindDescriptorSets(frameOnFlightData->CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkanVA->GetGraphicsPipelineLayout(), 0, 1, &vulkanVA->GetDescriptorSets()[windowData->SemaphoreIndex], 0, nullptr); - - // --- 4. Issue Draw Commands --- - - // Draw 3D scene geometry on 2D rendertarget (it->FrameBuffers) - vkCmdDrawIndexed(frameOnFlightData->CommandBuffer, vulkanVA->GetIndexBuffer()->GetCount(), 1, 0, 0, 0); - - // --- 5. End the Offscreen Render Pass --- + // recording begins: + { + VkCommandBufferBeginInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; + + result = vkBeginCommandBuffer(frameOnFlightData->CommandBuffer, &info); + KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't begin commandbuffer recording"); + } - vkCmdEndRenderPass(frameOnFlightData->CommandBuffer); - } - } + for(auto it = backendData->Elements3DTo2D.begin(); it != backendData->Elements3DTo2D.end(); ++it) + { + { + VkRenderPassBeginInfo renderPassInfo{}; + renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + renderPassInfo.renderPass = it->RenderPass; + renderPassInfo.framebuffer = it->FrameBuffers[windowData->ImageFrameIndex]; + renderPassInfo.renderArea.offset = {0, 0}; + renderPassInfo.renderArea.extent.width = it->Size.x; + renderPassInfo.renderArea.extent.height = it->Size.y; + + // Define clear values for the color and depth attachments + std::vector clearValues(2); + clearValues[0].color = {{0.0f, 0.0f, 0.0f, 0.0f}}; // Clear color to transparent + clearValues[1].depthStencil = {1.0f, 0}; // Clear depth to 1.0 (farthest) + + renderPassInfo.clearValueCount = static_cast(clearValues.size()); + renderPassInfo.pClearValues = clearValues.data(); + + // The pass starts here and all commands until vkCmdEndRenderPass are recorded into it + vkCmdBeginRenderPass(frameOnFlightData->CommandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); + std::shared_ptr vulkanVA = static_pointer_cast(it->Scene3D->GetRenderableVertexArray()); + vkCmdBindPipeline(frameOnFlightData->CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkanVA->GetKarmaGuiGraphicsPipeline()); + + // ---- Bind 3D Vertex And Index Buffers ---- + { + VkBuffer vertexBuffers[1] = { vulkanVA->GetVertexBuffer()->GetVertexBuffer() }; + VkDeviceSize vertexOffset[1] = { 0 }; + vkCmdBindVertexBuffers(frameOnFlightData->CommandBuffer, 0, 1, vertexBuffers, vertexOffset); + vkCmdBindIndexBuffer(frameOnFlightData->CommandBuffer, vulkanVA->GetIndexBuffer()->GetIndexBuffer(), 0, VK_INDEX_TYPE_UINT32); + } + + vulkanVA->UpdateProcessAndSetReadyForSubmission(); + vulkanVA->Bind(); + + VulkanHolder::GetVulkanContext()->UploadUBO(windowData->SemaphoreIndex); + + // ---- Bind descriptor sets (e.g., uniforms for MVP matrices, lighting) ---- + // Assumes layout compatibility between pipeline and descriptor set + vkCmdBindDescriptorSets(frameOnFlightData->CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkanVA->GetGraphicsPipelineLayout(), 0, 1, &vulkanVA->GetDescriptorSets()[windowData->SemaphoreIndex], 0, nullptr); + + // ---- Issue Draw Commands ---- + // Draw 3D scene geometry on 2D rendertarget (it->FrameBuffers) + vkCmdDrawIndexed(frameOnFlightData->CommandBuffer, vulkanVA->GetIndexBuffer()->GetCount(), 1, 0, 0, 0); + + // ---- End the Offscreen Render Pass ---- + vkCmdEndRenderPass(frameOnFlightData->CommandBuffer); + } + } // Render Pass VkRenderPassBeginInfo renderPassInfo = {}; @@ -540,8 +536,8 @@ namespace Karma { // Record KarmaGui primitives into command buffer - KarmaGuiVulkanHandler::KarmaGui_ImplVulkan_RenderDrawData(drawData, frameOnFlightData->CommandBuffer, VK_NULL_HANDLE, windowData->SemaphoreIndex); - } + KarmaGuiVulkanHandler::KarmaGui_ImplVulkan_RenderDrawData(drawData, frameOnFlightData->CommandBuffer, VK_NULL_HANDLE, windowData->SemaphoreIndex); + } vkCmdEndRenderPass(frameOnFlightData->CommandBuffer); @@ -553,19 +549,23 @@ namespace Karma // Submit command buffer VkPipelineStageFlags waitStage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; - VkSubmitInfo submitInfo = {}; + VkSubmitInfo submitInfo = {}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo.waitSemaphoreCount = 1; submitInfo.pWaitSemaphores = &imageAcquiredSemaphore; submitInfo.pWaitDstStageMask = &waitStage; - submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &frameOnFlightData->CommandBuffer; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &frameOnFlightData->CommandBuffer; submitInfo.signalSemaphoreCount = 1; submitInfo.pSignalSemaphores = &renderCompleteSemaphore; + // We reset the fence here or else the swapchain rebuild seemingly fails + result = vkResetFences(vulkanInfo->Device, 1, &frameOnFlightData->Fence); + KR_CORE_ASSERT(result == VK_SUCCESS, "Failed to reset fence"); + result = vkQueueSubmit(vulkanInfo->Queue, 1, &submitInfo, frameOnFlightData->Fence); KR_CORE_ASSERT(result == VK_SUCCESS, "Failed to submit queue"); - } + } void KarmaGuiRenderer::FramePresent(KarmaGui_ImplVulkanH_Window* windowData) { @@ -589,6 +589,12 @@ namespace Karma VkResult result = vkQueuePresentKHR(vulkanInfo->Queue, &info); + if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) + { + m_SwapChainRebuild = true; + return; + } + KR_CORE_ASSERT(result == VK_SUCCESS, "Failed to submit queue"); windowData->SemaphoreIndex = (windowData->SemaphoreIndex + 1) % windowData->MAX_FRAMES_IN_FLIGHT; // Now we can use the next set of semaphores @@ -605,7 +611,7 @@ namespace Karma { if(it->Scene3D == scene) { - return it->KarmaGui_Textures[m_VulkanWindowData.ImageFrameIndex]; + return it->KarmaGui_Textures[m_VulkanWindowData.ImageFrameIndex]; } } @@ -637,85 +643,85 @@ namespace Karma result = vkCreateSampler(vulkanInfo->Device, &samplerInfo, vulkanInfo->Allocator, &SceneToTexture.Sampler); KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't create sampler"); - uint32_t numberOfSwapChainImages = VulkanHolder::GetVulkanContext()->GetSwapChainImages().size(); - - SceneToTexture.Images.resize(numberOfSwapChainImages); - SceneToTexture.DeviceMemory.resize(numberOfSwapChainImages); - SceneToTexture.Image_Views.resize(numberOfSwapChainImages); - SceneToTexture.KarmaGui_Textures.resize(numberOfSwapChainImages); - - for(uint32_t i = 0; i < numberOfSwapChainImages; i++) - { - // Create images (along with appropriate memory) - { - VkImageCreateInfo imageCreateCI{}; - imageCreateCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - imageCreateCI.imageType = VK_IMAGE_TYPE_2D; - imageCreateCI.format = VK_FORMAT_R8G8B8A8_UNORM; - imageCreateCI.extent.width = dimensions.x; - imageCreateCI.extent.height = dimensions.y; - imageCreateCI.extent.depth = 1; - imageCreateCI.arrayLayers = 1; - imageCreateCI.mipLevels = 1; - imageCreateCI.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - imageCreateCI.samples = VK_SAMPLE_COUNT_1_BIT; - imageCreateCI.tiling = VK_IMAGE_TILING_OPTIMAL; - imageCreateCI.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; - imageCreateCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - - result = vkCreateImage(vulkanInfo->Device, &imageCreateCI, vulkanInfo->Allocator, &SceneToTexture.Images[i]); - KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't create a image"); - - VkMemoryRequirements req; - vkGetImageMemoryRequirements(vulkanInfo->Device, SceneToTexture.Images[i], &req); - VkMemoryAllocateInfo allocInfo = {}; - allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - allocInfo.allocationSize = req.size; - allocInfo.memoryTypeIndex = KarmaGuiVulkanHandler::KarmaGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits); - - result = vkAllocateMemory(vulkanInfo->Device, &allocInfo, vulkanInfo->Allocator, &SceneToTexture.DeviceMemory[i]); - KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't allocate memory"); - - result = vkBindImageMemory(vulkanInfo->Device, SceneToTexture.Images[i], SceneToTexture.DeviceMemory[i], 0); - KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't bind image memory"); - } - - // insert image memory barrier for VK_IMAGE_LAYOUT_UNDEFINED -> VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL? - - // Create image view: - { - VkImageViewCreateInfo viewInfo{}; - viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - viewInfo.image = SceneToTexture.Images[i]; - viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; - viewInfo.format = VK_FORMAT_R8G8B8A8_UNORM; - viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - viewInfo.subresourceRange.baseMipLevel = 0; - viewInfo.subresourceRange.levelCount = 1; - viewInfo.subresourceRange.baseArrayLayer = 0; - viewInfo.subresourceRange.layerCount = 1; - - result = vkCreateImageView(vulkanInfo->Device, &viewInfo, vulkanInfo->Allocator, &SceneToTexture.Image_Views[i]); - KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't create image view"); - } - - SceneToTexture.KarmaGui_Textures[i] = KarmaGuiVulkanHandler::KarmaGui_ImplVulkan_AddTexture(SceneToTexture.Sampler, SceneToTexture.Image_Views[i], VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - } + uint32_t numberOfSwapChainImages = VulkanHolder::GetVulkanContext()->GetSwapChainImages().size(); + + SceneToTexture.Images.resize(numberOfSwapChainImages); + SceneToTexture.DeviceMemory.resize(numberOfSwapChainImages); + SceneToTexture.Image_Views.resize(numberOfSwapChainImages); + SceneToTexture.KarmaGui_Textures.resize(numberOfSwapChainImages); + + for(uint32_t i = 0; i < numberOfSwapChainImages; i++) + { + // Create images (along with appropriate memory) + { + VkImageCreateInfo imageCreateCI{}; + imageCreateCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + imageCreateCI.imageType = VK_IMAGE_TYPE_2D; + imageCreateCI.format = VK_FORMAT_R8G8B8A8_UNORM; + imageCreateCI.extent.width = dimensions.x; + imageCreateCI.extent.height = dimensions.y; + imageCreateCI.extent.depth = 1; + imageCreateCI.arrayLayers = 1; + imageCreateCI.mipLevels = 1; + imageCreateCI.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + imageCreateCI.samples = VK_SAMPLE_COUNT_1_BIT; + imageCreateCI.tiling = VK_IMAGE_TILING_OPTIMAL; + imageCreateCI.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; + imageCreateCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + result = vkCreateImage(vulkanInfo->Device, &imageCreateCI, vulkanInfo->Allocator, &SceneToTexture.Images[i]); + KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't create a image"); + + VkMemoryRequirements req; + vkGetImageMemoryRequirements(vulkanInfo->Device, SceneToTexture.Images[i], &req); + VkMemoryAllocateInfo allocInfo = {}; + allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocInfo.allocationSize = req.size; + allocInfo.memoryTypeIndex = KarmaGuiVulkanHandler::KarmaGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits); + + result = vkAllocateMemory(vulkanInfo->Device, &allocInfo, vulkanInfo->Allocator, &SceneToTexture.DeviceMemory[i]); + KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't allocate memory"); + + result = vkBindImageMemory(vulkanInfo->Device, SceneToTexture.Images[i], SceneToTexture.DeviceMemory[i], 0); + KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't bind image memory"); + } + + // insert image memory barrier for VK_IMAGE_LAYOUT_UNDEFINED -> VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL? + + // Create image view: + { + VkImageViewCreateInfo viewInfo{}; + viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + viewInfo.image = SceneToTexture.Images[i]; + viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; + viewInfo.format = VK_FORMAT_R8G8B8A8_UNORM; + viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + viewInfo.subresourceRange.baseMipLevel = 0; + viewInfo.subresourceRange.levelCount = 1; + viewInfo.subresourceRange.baseArrayLayer = 0; + viewInfo.subresourceRange.layerCount = 1; + + result = vkCreateImageView(vulkanInfo->Device, &viewInfo, vulkanInfo->Allocator, &SceneToTexture.Image_Views[i]); + KR_CORE_ASSERT(result == VK_SUCCESS, "Couldn't create image view"); + } + + SceneToTexture.KarmaGui_Textures[i] = KarmaGuiVulkanHandler::KarmaGui_ImplVulkan_AddTexture(SceneToTexture.Sampler, SceneToTexture.Image_Views[i], VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + } backendData->Elements3DTo2D.push_back(SceneToTexture); // OffScreen texture (3D scene to 2D texture) resources like renderpass, framebuffers, and depth resources - // for the SceneToTexture element. We may be creating some resources again when not required, when new element is added - // resources for previous elements are also created. So take care of that. + // for the SceneToTexture element. We may be creating some resources again when not required, when new element is added + // resources for previous elements are also created. So take care of that. KarmaGuiVulkanHandler::CreateOffScreenTextureResources(); - // Set the renderpass for vulkanvertexarrays because graphicspipeline needs rebuilt (or be of different use) - KarmaGuiVulkanHandler::PrepareVertexArrayaForKarmaGuiWindowRendering(); + // Set the renderpass for vulkanvertexarrays because graphicspipeline needs rebuilt (or be of different use) + KarmaGuiVulkanHandler::PrepareVertexArrayaForKarmaGuiWindowRendering(); - return SceneToTexture.KarmaGui_Textures[m_VulkanWindowData.ImageFrameIndex]; + return SceneToTexture.KarmaGui_Textures[m_VulkanWindowData.ImageFrameIndex]; } - return nullptr; + return nullptr; } KGTextureID KarmaGuiBackendRendererUserData::GetTextureIDAtIndex(uint32_t index) diff --git a/Karma/src/Platform/Vulkan/KarmaGuiVulkanHandler.cpp b/Karma/src/Platform/Vulkan/KarmaGuiVulkanHandler.cpp index 2d681715..cae151c6 100644 --- a/Karma/src/Platform/Vulkan/KarmaGuiVulkanHandler.cpp +++ b/Karma/src/Platform/Vulkan/KarmaGuiVulkanHandler.cpp @@ -1489,16 +1489,16 @@ namespace Karma } } - void KarmaGuiVulkanHandler::PrepareVertexArrayaForKarmaGuiWindowRendering() - { - KarmaGui_ImplVulkan_Data* backendData = KarmaGuiRenderer::GetBackendRendererUserData(); + void KarmaGuiVulkanHandler::PrepareVertexArrayaForKarmaGuiWindowRendering() + { + KarmaGui_ImplVulkan_Data* backendData = KarmaGuiRenderer::GetBackendRendererUserData(); - for(auto textureData = backendData->Elements3DTo2D.begin(); textureData != backendData->Elements3DTo2D.end(); ++textureData) - { - std::shared_ptr vulkanVA = static_pointer_cast(textureData->Scene3D->GetRenderableVertexArray()); - vulkanVA->CreateKarmaGuiGraphicsPipeline(textureData->RenderPass, textureData->Size.x, textureData->Size.y); - } - } + for(auto textureData = backendData->Elements3DTo2D.begin(); textureData != backendData->Elements3DTo2D.end(); ++textureData) + { + std::shared_ptr vulkanVA = static_pointer_cast(textureData->Scene3D->GetRenderableVertexArray()); + vulkanVA->CreateKarmaGuiGraphicsPipeline(textureData->RenderPass, textureData->Size.x, textureData->Size.y); + } + } void KarmaGuiVulkanHandler::ShareVulkanContextResourcesOfMainWindow(KarmaGui_ImplVulkanH_Window* windowData, bool bCreateSyncronicity) { diff --git a/Karma/vendor/BiosReader b/Karma/vendor/BiosReader deleted file mode 160000 index cd54c508..00000000 --- a/Karma/vendor/BiosReader +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cd54c508c3f08ee0b6f27707dd78554981b2595e diff --git a/Karma/vendor/hwinfo b/Karma/vendor/hwinfo new file mode 160000 index 00000000..2577d97b --- /dev/null +++ b/Karma/vendor/hwinfo @@ -0,0 +1 @@ +Subproject commit 2577d97bbe62708ceb4e31bd173aebd3e9f0bfc8 diff --git a/Pranjal/CMakeLists.txt b/Pranjal/CMakeLists.txt index 516a104b..c6ef1852 100644 --- a/Pranjal/CMakeLists.txt +++ b/Pranjal/CMakeLists.txt @@ -47,8 +47,6 @@ if(MSVC) ${CMAKE_CURRENT_SOURCE_DIR}/../Karma/vendor/GLFW/include ${CMAKE_CURRENT_SOURCE_DIR}/../Karma/src/Karma/ ${CMAKE_CURRENT_SOURCE_DIR}/../Karma/vendor/SDL/include - ${CMAKE_CURRENT_SOURCE_DIR}/../Karma/vendor/ImGui/ - ${CMAKE_CURRENT_SOURCE_DIR}/../Karma/vendor/ImGui/backends ${CMAKE_CURRENT_SOURCE_DIR}/Source/Public ) endif() @@ -73,28 +71,6 @@ elseif(XCODE) XCODE_SCHEME_WORKING_DIRECTORY "${REPOSITORYROOT}/KarmaBin") endif() - -# Post build commands -#[[ -if(UNIX AND NOT APPLE) - if (BUILD_SHARED_LIBS) - set(Library_NAME "libBiosReader.so") - else() - set(Library_NAME "BiosReader") - endif() - - add_custom_command(TARGET Pranjal POST_BUILD - COMMAND cd ${REPOSITORYROOT}/KarmaBin - COMMAND mkdir temp - COMMAND cp ${Library_NAME} temp/${Library_NAME} - COMMAND cd temp - COMMAND sudo install -o root -g root -m u=rxs,g-rx,o=x -t ${REPOSITORYROOT}/KarmaBin/ ${Library_NAME} - COMMAND rm ${Library_NAME} - COMMAND cd ${REPOSITORYROOT}/KarmaBin - COMMAND sudo rmdir temp - ) -endif() -]] #[[ * /\ * / / diff --git a/Pranjal/Source/Private/KarmaGuiMesa.cpp b/Pranjal/Source/Private/KarmaGuiMesa.cpp index b5498d67..1234c503 100644 --- a/Pranjal/Source/Private/KarmaGuiMesa.cpp +++ b/Pranjal/Source/Private/KarmaGuiMesa.cpp @@ -11,7 +11,8 @@ #include "KarmaGuiMesa.h" #include "Karma/Application.h" - +#include "hwinfo/hwinfo.h" +#include "hwinfo/utils/unit.h" #include "spdlog/sinks/callback_sink.h" // Experimental @@ -523,30 +524,17 @@ namespace Karma KarmaGuiBackendRendererUserData* backendData = KarmaGuiRenderer::GetBackendRendererUserData(); backgroundImageTextureID = backendData->GetTextureIDAtIndex(1); - //width = backendData->GetTextureWidthAtIndex(1); - //height = backendData->GetTextureHeightAtIndex(1); - KGTextureID TextureID3D = KarmaGuiRenderer::Add3DSceneFor2DRendering(scene, KGVec2(window->Size.x, window->Size.y)); - KarmaGui::Image(TextureID3D, KGVec2(window->Size.x, window->Size.y)); - - //ImGui::GetCurrentWindow()->DrawList->SetWindowBackgroundColor(bgColor); - - KGDrawCallback sceneCallBack = [](const KGDrawList* parentList, const KGDrawCmd* drawCommand) - { - //KR_INFO("Scene Callback"); - }; - - //KGGuiWindow* theWindow = KarmaGuiInternal::GetCurrentWindow(); + KGTextureID textureID3D = KarmaGuiRenderer::Add3DSceneFor2DRendering(scene, KGVec2(window->Size.x, window->Size.y)); + + KGDrawList* drawList = KarmaGui::GetWindowDrawList(); + KGVec2 pos = KarmaGui::GetCursorScreenPos(); + + drawList->AddImage((void*)backgroundImageTextureID, pos, KGVec2(pos.x + window->Size.x, pos.y + window->Size.y)); + drawList->AddImage((void*)textureID3D, pos, KGVec2(pos.x + window->Size.x, pos.y + window->Size.y)); + scene->SetRenderWindow(window); - { - KGVec2 uvMin = KGVec2(0.0f, 0.0f); // Top-left - KGVec2 uvMax = KGVec2(1.0f, 1.0f); // Lower-right - KGVec4 tint_col = KGVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint - KGVec4 border_col = KGVec4(1.0f, 1.0f, 1.0f, 0.5f); // 50% opaque white - KarmaGui::Image(backgroundImageTextureID, KGVec2(window->Size.x, window->Size.y), uvMin, uvMax, tint_col, border_col); - } - if(window->Size.x != m_3DExhibitor.widthCache || window->Size.y != m_3DExhibitor.heightCache) { scene->SetWindowToRenderWithinResize(true); @@ -573,8 +561,6 @@ namespace Karma scene->SetWindowToRenderWithinResize(false); } - //KarmaGui::GetWindowDrawList()->AddCallback(sceneCallBack, (void*)scene.get()); - if (m_RefreshRenderingResources) { scene->SetWindowToRenderWithinResize(true); @@ -625,9 +611,7 @@ namespace Karma // Should be called when "about" mesa is closed, the first time if (electronicsItems.bHasQueried) { - reset_electronics_structures(); KarmaGuiMesa::SetElectronicsRamInformationToNull(); - electronicsItems.ramSoftSlots.clear(); electronicsItems.bHasQueried = false; } } @@ -750,8 +734,6 @@ namespace Karma height = backendData->GetTextureHeightAtIndex(0); { - //KGVec2 position = KarmaGui::GetCursorScreenPos(); - KGVec2 uvMin = KGVec2(0.0f, 0.0f); // Top-left KGVec2 uvMax = KGVec2(1.0f, 1.0f); // Lower-right KGVec4 tint_col = KGVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint @@ -791,7 +773,7 @@ namespace Karma KarmaGuiIO& io = KarmaGui::GetIO(); KarmaGuiStyle& style = KarmaGui::GetStyle(); - /*bool copy_to_clipboard =*/ KarmaGui::Button("Copy to clipboard"); + /*bool copy_to_clipboard =*/ KarmaGui::Button("Copy to clipboard"); } KarmaGui::Separator(); @@ -831,89 +813,50 @@ namespace Karma KarmaGui::Separator(); KarmaGui::Text("Vendor: %s", electronicsItems.biosVendorName.c_str()); - KarmaGui::Text("Supplied On: %s", electronicsItems.biosReleaseDate.c_str()); - KarmaGui::Text("ROM Size: %s", electronicsItems.biosROMSize.c_str()); - KarmaGui::Text("Current Language: %s", electronicsItems.biosCurrentSetLanguage.c_str()); - KarmaGui::Text("Supported Languages:"); - KarmaGui::Indent(); - KarmaGui::Text("%s", electronicsItems.biosRestOfTheSupportedLanguages.c_str()); - KarmaGui::Unindent(); - KarmaGui::Text("BIOS Characteristics:"); - KarmaGui::Indent(); - KarmaGui::Text("%s", electronicsItems.biosCharacteristics.c_str()); - KarmaGui::Unindent(); + KarmaGui::Text("MotherBoard: %s", electronicsItems.biosBoardName.c_str()); + KarmaGui::Text("MotherBoard Serial: %s", electronicsItems.biosSerialNumber.c_str()); + KarmaGui::Text("BIOS Version: %s", electronicsItems.biosVersion.c_str()); KarmaGui::Separator(); - KarmaGui::Text("Machine System Memory (RAM and all that)"); + KarmaGui::Text("Machine System Memory (RAM)"); KarmaGui::Separator(); - KarmaGui::Text("Supporting Area: %s", electronicsItems.supportingArea.c_str()); - KarmaGui::Text("Estimated Capacity: %s", electronicsItems.estimatedCapacity.c_str()); - KarmaGui::Text("Total such devices (est): %d", electronicsItems.numberOfMemoryDevices); - KarmaGui::Text("Physical devices present:"); + KarmaGui::Text("Total Capacity (MiB): %s", electronicsItems.memoryCapacity.c_str()); + KarmaGui::Text("Free Memory (MiB): %s", electronicsItems.freeMemory.c_str()); - for (uint32_t counter = 0; counter < electronicsItems.ramSoftSlots.size(); counter++) + KarmaGui::Text("Total modules: %d", electronicsItems.numberOfMemoryDevices); + + for(uint32_t counter = 0; counter < electronicsItems.numberOfMemoryDevices; counter++) { KarmaGui::Text("RAM %d", counter + 1); - KarmaGui::Text("Manufacturer: %s", electronicsItems.ramInformation[counter].manufacturer.c_str()); - - KarmaGui::Text("Identification Parameters"); - - KarmaGui::Indent(); - KarmaGui::Text("Ram Type: %s", electronicsItems.ramInformation[counter].ramType.c_str()); - KarmaGui::Text("Part Number: %s", electronicsItems.ramInformation[counter].partNumber.c_str()); - KarmaGui::Text("Serial Number: %s", electronicsItems.ramInformation[counter].serialNumber.c_str()); - KarmaGui::Text("(Bank | Device) Locator: %s | %s", electronicsItems.ramInformation[counter].bankLocator.c_str(), - electronicsItems.ramInformation[counter].locator.c_str()); - KarmaGui::Text("Asset Tag: %s", electronicsItems.ramInformation[counter].assetTag.c_str()); - KarmaGui::Unindent(); - - KarmaGui::Text("Ram Conditions"); KarmaGui::Indent(); - KarmaGui::Text("Size: %s", electronicsItems.ramInformation[counter].ramSize.c_str()); - KarmaGui::Text("Operating Voltage: %s", electronicsItems.ramInformation[counter].operatingVoltage.c_str()); - KarmaGui::Text("Speed (Current | Maximum): %s | %s", electronicsItems.ramInformation[counter].configuredMemorySpeed.c_str(), - electronicsItems.ramInformation[counter].memorySpeed.c_str()); - KarmaGui::Text("Form Factor: %s", electronicsItems.ramInformation[counter].formFactor.c_str()); + KarmaGui::Text("Vendor: %s", electronicsItems.ramInformation[counter].vendor.c_str()); + KarmaGui::Text("Name: %s", electronicsItems.ramInformation[counter].vendor.c_str()); + KarmaGui::Text("Model: %s", electronicsItems.ramInformation[counter].vendor.c_str()); + KarmaGui::Text("Serial Number: %s", electronicsItems.ramInformation[counter].vendor.c_str()); + KarmaGui::Text("Frequency (MHz): %s", electronicsItems.ramInformation[counter].vendor.c_str()); + KarmaGui::Text("Capacity: %s", electronicsItems.ramInformation[counter].vendor.c_str()); KarmaGui::Unindent(); } - - KarmaGui::Text("RAM Logistics"); - KarmaGui::Indent(); - KarmaGui::Text("Total Ram Size: %d %s", electronicsItems.totalRamSize, electronicsItems.ramSizeDimensions.c_str()); - KarmaGui::Unindent(); - + KarmaGui::Separator(); KarmaGui::Text("Central Processor Unit"); KarmaGui::Separator(); - KarmaGui::Text("Manufacturer: %s", electronicsItems.cpuManufacturer.c_str()); - KarmaGui::Text("Processor Family: %s", electronicsItems.cpuProcessingfamily.c_str()); - KarmaGui::Text("Version: %s", electronicsItems.cpuVersion.c_str()); + KarmaGui::Text("Manufacturer: %s", electronicsItems.cpuInformation.cpuVendor.c_str()); + KarmaGui::Text("Processor Family: %s", electronicsItems.cpuInformation.cpuModel.c_str()); KarmaGui::Text("CPU Conditions"); KarmaGui::Indent(); - KarmaGui::Text("Speed (Current | Maximum): %s | %s", electronicsItems.cpuCurrentSpeed.c_str(), electronicsItems.cpuMaximumSpeed.c_str()); - KarmaGui::Text("External Clock: %s", electronicsItems.cpuExternalClock.c_str()); - KarmaGui::Text("Cores (Current | Maximum): %s | %s", electronicsItems.cpuEnabledCoresCount.c_str(), electronicsItems.cpuCorescount.c_str()); - KarmaGui::Text("Threads Count: %s", electronicsItems.cpuThreadCount.c_str()); - KarmaGui::Text("Operating Voltage: %s", electronicsItems.cpuOperatingVoltage.c_str()); + KarmaGui::Text("Speed : %s (MHz) | %s (MHz)", electronicsItems.cpuInformation.cpuCurrentFrequency.c_str(), electronicsItems.cpuInformation.cpuMaximumFrequency.c_str()); + KarmaGui::Text("Cores (Logical | Physical): %s | %s", electronicsItems.cpuInformation.cpuLogicalCores.c_str(), electronicsItems.cpuInformation.cpuPhysicalCores.c_str()); KarmaGui::Unindent(); KarmaGui::Text("CPU Tags or Numbers"); KarmaGui::Indent(); - KarmaGui::Text("Signature: %s", electronicsItems.cpuSignature.c_str()); - KarmaGui::Text("ID: %s", electronicsItems.cpuid.c_str()); - KarmaGui::Text("Part Number: %s", electronicsItems.cpuPartNumber.c_str()); - KarmaGui::Text("Serial Number: %s", electronicsItems.cpuSerialNumber.c_str()); - KarmaGui::Text("Asset Tag: %s", electronicsItems.cpuAssettag.c_str()); - KarmaGui::Unindent(); - KarmaGui::Text("CPU Characteristics"); - KarmaGui::Indent(); - KarmaGui::Text("%s", electronicsItems.cpuTheCharacterstics.c_str()); - KarmaGui::Unindent(); - KarmaGui::Text("Flags:"); - KarmaGui::Indent(); - KarmaGui::Text("%s", electronicsItems.cpuFlags.c_str()); + KarmaGui::Text("Caches (MegaBytes)"); + KarmaGui::Text("L1 Cache : %s", electronicsItems.cpuInformation.cpuCacheSizeL1.c_str()); + KarmaGui::Text("L2 Cache: %s", electronicsItems.cpuInformation.cpuCacheSizeL2.c_str()); + KarmaGui::Text("L3 Cache: %s", electronicsItems.cpuInformation.cpuCacheSizeL3.c_str()); KarmaGui::Unindent(); KarmaGui::Separator(); @@ -923,6 +866,7 @@ namespace Karma KarmaGui::Text("Manufacturer: %s", electronicsItems.gpuVendor.c_str()); KarmaGui::Text("Model: %s", electronicsItems.gpuModelIdentification.c_str()); + KarmaGui::Text("VRam: %s", electronicsItems.gpuVMemory.c_str()); KarmaGui::Separator(); @@ -950,51 +894,49 @@ namespace Karma } // Catcher rhymes with Hatcher, the Topologist, just for information! - void* catcher = electronics_spit(ss_bios); - - if (bios_information* bInfo = static_cast(catcher)) - { - electronicsItems.biosVendorName = bInfo->vendor != nullptr ? bInfo->vendor : notAvailableText; - electronicsItems.biosVersion = bInfo->version != nullptr ? bInfo->version : notAvailableText; - electronicsItems.biosReleaseDate = bInfo->biosreleasedate != nullptr ? bInfo->biosreleasedate : notAvailableText; - electronicsItems.biosROMSize = bInfo->biosromsize != nullptr ? bInfo->biosromsize : notAvailableText; - electronicsItems.biosCharacteristics = bInfo->bioscharacteristics[0] != '\0' ? bInfo->bioscharacteristics : notAvailableText; - } - else - { - KR_WARN("BiosReader isn't behaving normally."); - } - - catcher = electronics_spit(pi_bioslanguages); - - if (mb_language_modules* mbLangModules = static_cast(catcher)) - { - electronicsItems.biosCurrentSetLanguage = mbLangModules->currentactivemodule != nullptr ? mbLangModules->currentactivemodule : notAvailableText; - electronicsItems.biosRestOfTheSupportedLanguages = mbLangModules->supportedlanguagemodules != nullptr ? mbLangModules->supportedlanguagemodules : notAvailableText; - } - else - { - KR_WARN("BiosReader isn't behaving normally."); - } - - catcher = electronics_spit(pi_systemmemory); - if (turing_machine_system_memory* tInfo = static_cast(catcher)) - { - electronicsItems.estimatedCapacity = tInfo->total_grand_capacity != nullptr ? tInfo->total_grand_capacity : notAvailableText; - electronicsItems.numberOfMemoryDevices = tInfo->number_of_ram_or_system_memory_devices != 0 ? tInfo->number_of_ram_or_system_memory_devices : 0; - electronicsItems.supportingArea = tInfo->mounting_location != nullptr ? tInfo->mounting_location : notAvailableText; - } - else - { - KR_WARN("BiosReader isn't behaving normally."); - } - - catcher = electronics_spit(ps_systemmemory); - - // Now since there may be more than one Ram type of electronics, and given that BIOS lies, we need a mechanism - // to gauge the true amount of every estimation we obtained earlier - // Please see https://github.com/ravimohan1991/BiosReader/blob/37e1179f876b940b3f483a398091f44a479692ea/src/private/dmidecode.c#L4980 - if (random_access_memory* rInfo = static_cast(catcher)) + void* catcher = nullptr;// = electronics_spit(ss_bios); + + hwinfo::MainBoard mainboard; + + electronicsItems.biosVendorName = mainboard.vendor() != "" ? mainboard.vendor() : notAvailableText; + electronicsItems.biosBoardName = mainboard.name() != "" ? mainboard.name() : notAvailableText; + electronicsItems.biosVersion = mainboard.version() != "" ? mainboard.version() : notAvailableText; + electronicsItems.biosSerialNumber = mainboard.serialNumber() != "" ? mainboard.serialNumber() : notAvailableText; + + hwinfo::Memory memory; + + electronicsItems.memoryCapacity = std::to_string(hwinfo::unit::bytes_to_MiB(memory.total_Bytes())); + electronicsItems.freeMemory = std::to_string(hwinfo::unit::bytes_to_MiB(memory.free_Bytes() > 0 ? memory.free_Bytes() : 0)); + + electronicsItems.numberOfMemoryDevices = static_cast(memory.modules().size()); + + for(const auto& module : memory.modules()) + { + KR_INFO("ID: {0}", module.id); + KR_INFO("Frequencey (Hz): {0}", module.frequency_Hz == -1 ? -1 : static_cast(module.frequency_Hz) / 1e6); + KR_INFO("Name: {0}", module.name); + KR_INFO("Serial Number: {0}", module.serial_number); + KR_INFO("Vendor: {0}", module.vendor); + KR_INFO("Model: {0}", module.model); + KR_INFO("Capacity: {0}", hwinfo::unit::bytes_to_MiB(module.total_Bytes)); + } + + electronicsItems.ramInformation = new KarmaTuringMachineElectronics::SystemRAM[memory.modules().size()]; + uint32_t counter = 0; + + for(const auto& mod : memory.modules()) + { + electronicsItems.ramInformation[counter].name = mod.name; + electronicsItems.ramInformation[counter].vendor = mod.vendor; + electronicsItems.ramInformation[counter].model = mod.model; + electronicsItems.ramInformation[counter].serialNumber = mod.serial_number; + electronicsItems.ramInformation[counter].frequency = mod.frequency_Hz == -1 ? -1 : static_cast(mod.frequency_Hz) / 1e6; + electronicsItems.ramInformation[counter].id = mod.id; + electronicsItems.ramInformation[counter].capacity = std::to_string(hwinfo::unit::bytes_to_MiB(mod.total_Bytes)); + counter++; + } + + /*if (random_access_memory* rInfo = static_cast(catcher)) { KarmaTuringMachineElectronics::GaugeSystemMemoryDevices(rInfo); @@ -1019,47 +961,52 @@ namespace Karma else { KR_WARN("BiosReader isn't behaving normally."); - } + }*/ - catcher = electronics_spit(ps_processor); + const auto cpus = hwinfo::getAllCPUs(); - if (central_processing_unit* pInfo = static_cast(catcher)) + for(const auto& cpu : cpus) { - //electronicsItems.cpuDesignation = pInfo->designation; <----- Please refer to central_processing_unit struct - electronicsItems.cpuFlags = pInfo->cpuflags != nullptr ? pInfo->cpuflags : notAvailableText; - electronicsItems.cpuid = pInfo->cpuid != nullptr ? pInfo->cpuid : notAvailableText; - electronicsItems.cpuManufacturer = pInfo->manufacturer ? pInfo->manufacturer : notAvailableText; - electronicsItems.cpuProcessingfamily = pInfo->processingfamily ? pInfo->processingfamily : notAvailableText; - electronicsItems.cpuVersion = pInfo->version ? pInfo->version : notAvailableText; - electronicsItems.cpuPartNumber = pInfo->partnumber ? pInfo->partnumber : notAvailableText; - electronicsItems.cpuSerialNumber = pInfo->serialnumber ? pInfo->serialnumber : notAvailableText; - electronicsItems.cpuAssettag = pInfo->assettag ? pInfo->assettag : notAvailableText; - electronicsItems.cpuOperatingVoltage = pInfo->operatingvoltage ? pInfo->operatingvoltage : notAvailableText; - electronicsItems.cpuCurrentSpeed = pInfo->currentspeed ? pInfo->currentspeed : notAvailableText; - electronicsItems.cpuMaximumSpeed = pInfo->maximumspeed ? pInfo->maximumspeed : notAvailableText; - electronicsItems.cpuExternalClock = pInfo->externalclock ? pInfo->externalclock : notAvailableText; - electronicsItems.cpuCorescount = pInfo->corescount ? pInfo->corescount : notAvailableText; - electronicsItems.cpuThreadCount = pInfo->threadcount ? pInfo->threadcount : notAvailableText; - electronicsItems.cpuEnabledCoresCount = pInfo->enabledcorescount ? pInfo->enabledcorescount : notAvailableText; - electronicsItems.cpuTheCharacterstics = pInfo->characterstics ? pInfo->characterstics : notAvailableText; - electronicsItems.cpuSignature = pInfo->signature ? pInfo->signature : notAvailableText; - } - else - { - KR_WARN("BiosReader isn't behaving normally"); - } + electronicsItems.cpuInformation.cpuVendor = cpu.vendor(); + electronicsItems.cpuInformation.cpuModel = cpu.modelName(); + electronicsItems.cpuInformation.cpuLogicalCores = std::to_string(cpu.numLogicalCores()); + electronicsItems.cpuInformation.cpuPhysicalCores = std::to_string(cpu.numPhysicalCores()); + + int64_t averageFrequency = 0; + for(uint32_t counter = 0; counter < cpu.numLogicalCores(); counter++) + { + averageFrequency += cpu.currentClockSpeed_MHz()[counter]; + } + + averageFrequency = averageFrequency / cpu.numLogicalCores(); + + electronicsItems.cpuInformation.cpuCurrentFrequency = std::to_string(averageFrequency); + electronicsItems.cpuInformation.cpuMaximumFrequency = std::to_string(cpu.maxClockSpeed_MHz()); + KR_INFO("CPU frequency: {0}", cpu.maxClockSpeed_MHz()); + electronicsItems.cpuInformation.cpuCacheSizeL1 = std::to_string(hwinfo::unit::bytes_to_MiB(cpu.L1CacheSize_Bytes() > 0 ? cpu.L1CacheSize_Bytes() : 0)); + electronicsItems.cpuInformation.cpuCacheSizeL2 = std::to_string(hwinfo::unit::bytes_to_MiB(cpu.L2CacheSize_Bytes() > 0 ? cpu.L2CacheSize_Bytes() : 0)); + electronicsItems.cpuInformation.cpuCacheSizeL3 = std::to_string(hwinfo::unit::bytes_to_MiB(cpu.L3CacheSize_Bytes() > 0 ? cpu.L3CacheSize_Bytes() : 0)); - catcher = electronics_spit(ps_graphicscard); + break; + } - if (graphics_processing_unit* gInfo = static_cast(catcher)) + auto gpus = hwinfo::getAllGPUs(); + + if(gpus.size() == 0) { - electronicsItems.gpuModelIdentification = gInfo->gpuModel != nullptr ? gInfo->gpuModel : notAvailableText; - electronicsItems.gpuVendor = gInfo->vendor ? gInfo->vendor : notAvailableText; - electronicsItems.gpuVMemory = gInfo->grandtotalvideomemory ? gInfo->grandtotalvideomemory : notAvailableText; + electronicsItems.gpuModelIdentification = notAvailableText; + electronicsItems.gpuVendor = notAvailableText; + + electronicsItems.gpuVMemory = notAvailableText; } - else + + for(const auto& gpu : gpus) { - KR_WARN("BiosReader isn't behaving normally"); + electronicsItems.gpuModelIdentification = gpu.name() != "" ? gpu.name() : notAvailableText; + electronicsItems.gpuVendor = gpu.vendor() != "" ? gpu.vendor() : notAvailableText; + + electronicsItems.gpuVMemory = gpu.memory_Bytes() != 0 ? std::to_string(hwinfo::unit::bytes_to_MiB(gpu.memory_Bytes())) : notAvailableText; + break; } electronicsItems.bHasQueried = true; @@ -1123,75 +1070,6 @@ namespace Karma } } - void KarmaTuringMachineElectronics::FindRealCapacityOfRam() - { - uint32_t ramSizeFound = 0; - - // Assumption dimension of memory is GB only - for (uint32_t counter = 0; counter < KarmaGuiMesa::GetGatheredElectronicsInformation().ramSoftSlots.size(); counter++) - { - ramSizeFound += KarmaGuiMesa::ChurnUint32FromString(KarmaGuiMesa::GetGatheredElectronicsInformation().ramInformation[counter].ramSize); - } - - KarmaGuiMesa::GetGatheredElectronicsInformationForModification().totalRamSize = ramSizeFound; - - // Hoping for GB only dimension - KarmaGuiMesa::GetGatheredElectronicsInformationForModification().ramSizeDimensions = KarmaGuiMesa::ChurnDimensionsFromString(KarmaGuiMesa::GetGatheredElectronicsInformation().ramInformation[0].ramSize); - } - - void KarmaTuringMachineElectronics::GaugeSystemMemoryDevices(random_access_memory* ramCluster) - { - if (ramCluster == nullptr) - { - KR_WARN("Memory devices pointer is null. No Ram(s) shall be detected and reported"); - return; - } - - KarmaTuringMachineElectronics selfRefrentialVariable = KarmaGuiMesa::GetGatheredElectronicsInformationForModification(); - - uint32_t biosReportedNumber = selfRefrentialVariable.numberOfMemoryDevices; - - for (uint32_t counter = 0; counter < biosReportedNumber; counter++) - { - random_access_memory* aMemoryBeingScanned = fetch_access_memory_members(counter); - - if (aMemoryBeingScanned != nullptr && IsPhysicalRamPresent(*aMemoryBeingScanned)) - { - KarmaGuiMesa::GetGatheredElectronicsInformationForModification().ramSoftSlots.push_back(counter); - } - } - } - - void KarmaTuringMachineElectronics::FillTheSystemRamStructure(SystemRAM& destinationStructure, random_access_memory& sourceStructure) - { - destinationStructure.assetTag = sourceStructure.assettag != nullptr ? sourceStructure.assettag : KarmaGuiMesa::notAvailableText; - destinationStructure.bankLocator = sourceStructure.banklocator != nullptr ? sourceStructure.banklocator : KarmaGuiMesa::notAvailableText; - destinationStructure.configuredMemorySpeed = sourceStructure.configuredmemoryspeed != nullptr ? sourceStructure.configuredmemoryspeed : KarmaGuiMesa::notAvailableText; - destinationStructure.memorySpeed = sourceStructure.memoryspeed != nullptr ? sourceStructure.memoryspeed : KarmaGuiMesa::notAvailableText; - destinationStructure.formFactor = sourceStructure.formfactor != nullptr ? sourceStructure.formfactor : KarmaGuiMesa::notAvailableText; - destinationStructure.locator = sourceStructure.locator != nullptr ? sourceStructure.locator : KarmaGuiMesa::notAvailableText; - destinationStructure.manufacturer = sourceStructure.manufacturer != nullptr ? sourceStructure.manufacturer : KarmaGuiMesa::notAvailableText; - destinationStructure.operatingVoltage = sourceStructure.operatingvoltage != nullptr ? sourceStructure.operatingvoltage : KarmaGuiMesa::notAvailableText; - destinationStructure.partNumber = sourceStructure.partnumber != nullptr ? sourceStructure.partnumber : KarmaGuiMesa::notAvailableText; - destinationStructure.ramSize = sourceStructure.ramsize != nullptr ? sourceStructure.ramsize : KarmaGuiMesa::notAvailableText; - destinationStructure.ramType = sourceStructure.ramtype != nullptr ? sourceStructure.ramtype : KarmaGuiMesa::notAvailableText; - //destinationStructure.rank = sourceStructure.rank; Not a big fan of rank, reminds me of my JEE AIR 4729 - destinationStructure.serialNumber = sourceStructure.serialnumber != nullptr ? sourceStructure.serialnumber : KarmaGuiMesa::notAvailableText; - } - - bool KarmaTuringMachineElectronics::IsPhysicalRamPresent(const random_access_memory& ramScam) - { - if (ramScam.memoryspeed == nullptr || ramScam.configuredmemoryspeed == nullptr || ramScam.banklocator == nullptr - || ramScam.formfactor == nullptr || ramScam.operatingvoltage == nullptr) - { - return false; - } - else - { - return true; - } - } - double KarmaGuiMesa::HexStringToDecimal(const std::string& hexString) { return (double)std::stoll(hexString, 0, 16); @@ -1240,9 +1118,7 @@ namespace Karma { if (electronicsItems.bHasQueried) { - reset_electronics_structures(); KarmaGuiMesa::SetElectronicsRamInformationToNull(); - electronicsItems.ramSoftSlots.clear(); electronicsItems.bHasQueried = false; } } diff --git a/Pranjal/Source/Public/KarmaGuiMesa.h b/Pranjal/Source/Public/KarmaGuiMesa.h index f6d1e37c..f156e232 100644 --- a/Pranjal/Source/Public/KarmaGuiMesa.h +++ b/Pranjal/Source/Public/KarmaGuiMesa.h @@ -11,10 +11,6 @@ #include "Karma.h" -extern "C" { -#include "dmidecode.h" -} - namespace Karma { struct CallbacksFromEditor @@ -186,83 +182,51 @@ namespace Karma // Bios Information std::string biosVendorName; + std::string biosSerialNumber; std::string biosVersion; - std::string biosReleaseDate; - std::string biosCharacteristics; - std::string biosROMSize; - std::string biosCurrentSetLanguage; - std::string biosRestOfTheSupportedLanguages; + std::string biosBoardName; // System Memory (RAM) overview - uint32_t numberOfMemoryDevices;// An estimation. I shall manually introduce logical checks + uint32_t numberOfMemoryDevices; - // I named estimated because of the lies - // https://github.com/ravimohan1991/BiosReader/wiki/The-Life-and-Lies-of-the-BIOS - std::string estimatedCapacity; - std::string supportingArea; + std::string memoryCapacity; + std::string freeMemory; struct SystemRAM { - std::string formFactor; - std::string ramSize; - std::string locator; - std::string ramType; - std::string bankLocator; - std::string manufacturer; - + uint32_t id; + std::string vendor; + std::string model; + std::string name; std::string serialNumber; - std::string partNumber; - std::string assetTag; - - std::string memorySpeed; - std::string configuredMemorySpeed; - - std::string operatingVoltage; - std::string rank; + std::string frequency; + std::string capacity; }; SystemRAM* ramInformation; - // Let me tell the story of naming. Since the physical slots are the ones - // present on board, the array slots in software side, getting filled on a query to BIOS, - // naturally get the name "...SoftSlots" from BiosReader's allocation POV - std::vector ramSoftSlots; - - uint32_t totalRamSize; - std::string ramSizeDimensions; // Processor information - // Asssuming only 1 processor - std::string cpuDesignation;// Socket designation - std::string cpuType; // In order to distinguish from GPU processor :) or DSP https://en.wikipedia.org/wiki/Digital_signal_processor - std::string cpuProcessingfamily; - std::string cpuManufacturer; - std::string cpuFlags; - // Kind of the most important element of this struct. eg Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz (completeprocessingunitidentifier) - std::string cpuVersion; - - std::string cpuOperatingVoltage; - std::string cpuExternalClock; - std::string cpuMaximumSpeed; - std::string cpuCurrentSpeed; - - // Some OEM specific numbers - std::string cpuSerialNumber; - std::string cpuPartNumber; - std::string cpuAssettag; - - std::string cpuCorescount; - std::string cpuEnabledCoresCount; - std::string cpuThreadCount; - std::string cpuTheCharacterstics; - - // The Cpu ID field contains processor - specific information that describes the processor’s features. - std::string cpuid; // in the context of motherboard components - std::string cpuSignature; + struct CPU + { + std::string cpuVendor; + std::string cpuModel; + std::string cpuCurrentFrequency; + std::string cpuMaximumFrequency; + std::string cpuPhysicalCores; + std::string cpuLogicalCores; + std::string cpuCacheSizeL1; + std::string cpuCacheSizeL2; + std::string cpuCacheSizeL3; + }; + CPU cpuInformation; // For now, with due respect, let there be enough content with just model number // und vendor. Would be dope to read the GPU just like RAM or CPU, from SMBIOS!! + + // Ok thanks to shadPS4 emulator, we are using dope library hwinfo std::string gpuVendor; std::string gpuModelIdentification; + std::string gpuVMemory; KarmaTuringMachineElectronics() @@ -274,17 +238,6 @@ namespace Karma ~KarmaTuringMachineElectronics(); - // Gauging Ram devices - static void GaugeSystemMemoryDevices(random_access_memory* ramCluster); - - // Obtain the real RAM information - static void FindRealCapacityOfRam(); - - // No-ram conditions. Bit'o hacky stuff - static bool IsPhysicalRamPresent(const random_access_memory& ramScam); - - // Filling the SystemRAM structure with relevant information - static void FillTheSystemRamStructure(SystemRAM& destinationStructure, random_access_memory& sourceStructure); }; struct WindowManipulationGaugeData