Skip to content

Commit

Permalink
Minor repo cleanup & improve graphics device selection
Browse files Browse the repository at this point in the history
  • Loading branch information
asbott committed Apr 26, 2024
1 parent 782e0a8 commit 62ffbc3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 366 deletions.
3 changes: 0 additions & 3 deletions gfx/gfx.odin
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ init_and_open_window :: proc(title : cstring = "JAMGINE APP by CMQV", width := 1
window = glfw.CreateWindow(cast(i32)width, cast(i32)height, title, nil, nil);
jvk_init_result := jvk.init(string(title));
assert(jvk_init_result, "Failed initializing jvk");
//devices : []jvk.Graphics_Device={{}, {}}; // #Temporary #Debug
//jvk.get_all_graphics_devices(&devices);
//device_context := jvk.make_device_context(devices[1]);
device_context := jvk.make_device_context();
jvk.set_target_device_context(device_context);
window_surface = jvk.make_draw_surface(window, enable_depth_test=enable_depth_test);
Expand Down
44 changes: 41 additions & 3 deletions gfx/justvk/graphics_device.odin
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,20 @@ query_physical_device :: proc(pdevice : vk.PhysicalDevice) -> Graphics_Device {
return gdevice;
}

// Designed to select a GPU for general purpose.
// If user needs a more sophisticated algorithm he can query devices
// and inspect them manually.
// #Portability
// This should be thoroughly tested on different computers.
rate_graphics_device :: proc(gdevice : Graphics_Device) -> int {
score := 0;

type_scores := map[vk.PhysicalDeviceType]int {
.INTEGRATED_GPU = 500,
.DISCRETE_GPU = 1000,


// Not sure what these even are
.VIRTUAL_GPU = 100,
.CPU = 50,
};
Expand All @@ -191,11 +199,41 @@ rate_graphics_device :: proc(gdevice : Graphics_Device) -> int {

score += type_scores[gdevice.props.deviceType];

score += cast(int)gdevice.props.limits.maxImageDimension2D;
// VRAM is nice, give some score per GB
for i in 0..<int(gdevice.memory_props.memoryHeapCount) {
heap := gdevice.memory_props.memoryHeaps[i];
if .DEVICE_LOCAL in heap.flags {
size_bytes := int(heap.size);

if gdevice.features.sampleRateShading do score += 100;
GB :: 1024 * 1024 * 1024;

if !gdevice.features.geometryShader do return 0;
score_factor := 0;

if gdevice.props.deviceType == .DISCRETE_GPU {
score_factor = 100;
} else {
score_factor = 10; // It's just RAM in disguise...
}

score += score_factor * size_bytes / GB;

}
}

// On modern devices probably 16k-32k maybe even 64k
max_image_dim := cast(int)gdevice.props.limits.maxImageDimension2D;
score += 50 * max_image_dim / 16384;

// 1024 on laptop RTX 3060
max_num_compute := cast(int)gdevice.props.limits.maxComputeWorkGroupInvocations;
score += 50 * max_num_compute / 512;


if gdevice.features.sampleRateShading do score += 100;

if gdevice.features.geometryShader do score += 50;

fmt.println(score);

return score;
}
Expand Down
Loading

0 comments on commit 62ffbc3

Please sign in to comment.