@@ -827,10 +827,12 @@ func getVulkanGPUMemory() []GPUMemoryInfo {
827827}
828828
829829type vulkanGPUTextInfo struct {
830- index int
831- name string
832- deviceType string
833- totalVRAM uint64
830+ index int
831+ name string
832+ deviceType string
833+ totalVRAM uint64
834+ budgetVRAM uint64
835+ usageVRAM uint64
834836}
835837
836838func parseVulkanGPUMemoryText (r io.Reader ) []GPUMemoryInfo {
@@ -841,13 +843,19 @@ func parseVulkanGPUMemoryText(r io.Reader) []GPUMemoryInfo {
841843 inMemoryHeaps := false
842844 inHeap := false
843845 heapSize := uint64 (0 )
846+ heapBudget := uint64 (0 )
847+ heapUsage := uint64 (0 )
844848 heapDeviceLocal := false
845849
846850 flushHeap := func () {
847851 if current != nil && inHeap && heapDeviceLocal {
848852 current .totalVRAM += heapSize
853+ current .usageVRAM += heapUsage
854+ current .budgetVRAM += heapBudget
849855 }
850856 heapSize = 0
857+ heapBudget = 0
858+ heapUsage = 0
851859 heapDeviceLocal = false
852860 inHeap = false
853861 }
@@ -857,14 +865,25 @@ func parseVulkanGPUMemoryText(r io.Reader) []GPUMemoryInfo {
857865 return
858866 }
859867
868+ if current .usageVRAM == 0 && current .budgetVRAM != 0 {
869+ current .usageVRAM = current .totalVRAM - current .budgetVRAM
870+ } else if current .usageVRAM != 0 && current .budgetVRAM == 0 {
871+ current .budgetVRAM = current .totalVRAM - current .usageVRAM
872+ } else if current .usageVRAM == 0 && current .budgetVRAM == 0 {
873+ current .usageVRAM = 0
874+ current .budgetVRAM = current .totalVRAM
875+ }
876+
877+ usagePercent := float64 (current .usageVRAM ) / float64 (current .totalVRAM ) * float64 (100.0 )
878+
860879 gpus = append (gpus , GPUMemoryInfo {
861880 Index : current .index ,
862881 Name : current .name ,
863882 Vendor : VendorVulkan ,
864883 TotalVRAM : current .totalVRAM ,
865- UsedVRAM : 0 , // Vulkan heap size is capacity, not real-time usage.
866- FreeVRAM : current .totalVRAM ,
867- UsagePercent : 0 ,
884+ UsedVRAM : current . usageVRAM ,
885+ FreeVRAM : current .budgetVRAM ,
886+ UsagePercent : usagePercent ,
868887 })
869888 }
870889
@@ -942,6 +961,20 @@ func parseVulkanGPUMemoryText(r io.Reader) []GPUMemoryInfo {
942961 continue
943962 }
944963
964+ if strings .HasPrefix (line , "budget" ) {
965+ if budget , ok := parseVulkanUintValue (line ); ok {
966+ heapBudget = budget
967+ }
968+ continue
969+ }
970+
971+ if strings .HasPrefix (line , "usage" ) {
972+ if usage , ok := parseVulkanUintValue (line ); ok {
973+ heapUsage = usage
974+ }
975+ continue
976+ }
977+
945978 if strings .Contains (line , "MEMORY_HEAP_DEVICE_LOCAL_BIT" ) {
946979 heapDeviceLocal = true
947980 }
0 commit comments