1
0
forked from joey/godottest

cpu v gpu

This commit is contained in:
Joey Eamigh 2025-10-11 01:31:51 -04:00
parent 9732bf52ff
commit 007a45d543
No known key found for this signature in database
GPG Key ID: CE8C05DFFC53C9CB
2 changed files with 84 additions and 6 deletions

View File

@ -66,6 +66,6 @@ reloadable = true
"windows.editor.x86_64" = "res://../rust/target/x86_64-pc-windows-msvc/debug/godottest_rs.dll" "windows.editor.x86_64" = "res://../rust/target/x86_64-pc-windows-msvc/debug/godottest_rs.dll"
[icons] [icons]
Mappy = "res://addons/rust/NodeRustFerris.svg"
Player = "res://addons/rust/NodeRustFerris.svg" Player = "res://addons/rust/NodeRustFerris.svg"
AsyncRuntime = "res://addons/rust/NodeRustFerris.svg" AsyncRuntime = "res://addons/rust/NodeRustFerris.svg"
Mappy = "res://addons/rust/NodeRustFerris.svg"

View File

@ -987,7 +987,7 @@ mod gd_rehearse_tests {
(data, tile_size, tile_size) (data, tile_size, tile_size)
} }
fn run_tilemap_for_size(map_width: u32, map_height: u32, tile_size: u32) -> PackedByteArray { fn run_tilemap_gpu_for_size(map_width: u32, map_height: u32, tile_size: u32) -> PackedByteArray {
godot_print!( godot_print!(
"Testing map {}x{} tiles at tile_size {} ({}x{} px output)", "Testing map {}x{} tiles at tile_size {} ({}x{} px output)",
map_width, map_width,
@ -1028,6 +1028,52 @@ mod gd_rehearse_tests {
result result
} }
fn run_tilemap_cpu_for_size(map_width: u32, map_height: u32, tile_size: u32) -> PackedByteArray {
godot_print!(
"Testing CPU map {}x{} tiles at tile_size {} ({}x{} px output)",
map_width,
map_height,
tile_size,
map_width * tile_size,
map_height * tile_size
);
let (atlas_bytes, atlas_w, atlas_h) = make_uniform_atlas(tile_size, [0u8, 0u8, 255u8, 255u8]);
let atlas_data = PackedByteArray::from(atlas_bytes);
let atlas_image = Image::create_from_data(atlas_w as i32, atlas_h as i32, false, Format::RGBA8, &atlas_data)
.expect("Failed to create atlas image for CPU tilemap test");
let tile_count = (map_width as usize)
.checked_mul(map_height as usize)
.expect("Tile count overflow in CPU benchmark");
let mut map_array: Array<i32> = Array::new();
for _ in 0..tile_count {
map_array.push(0);
}
let start = Instant::now();
let cpu_image = Mappy::create_texture_cpu(
&map_array,
map_width as i32,
map_height as i32,
tile_size,
&atlas_image,
Format::RGBA8,
)
.expect("CPU tilemap generation failed during size sweep benchmark");
let elapsed_ms = start.elapsed().as_secs_f64() * 1000.0;
let data = cpu_image.get_data();
godot_print!(
"Tilemap CPU path finished in {:.2} ms for {} tiles ({} bytes output)",
elapsed_ms,
tile_count,
data.len()
);
data
}
fn expected_output_bytes(map_width: u32, map_height: u32, tile_size: u32) -> usize { fn expected_output_bytes(map_width: u32, map_height: u32, tile_size: u32) -> usize {
let out_width = map_width let out_width = map_width
.checked_mul(tile_size) .checked_mul(tile_size)
@ -1101,7 +1147,7 @@ mod gd_rehearse_tests {
#[gditest(scene_path = "res://tests/test_runner.tscn")] #[gditest(scene_path = "res://tests/test_runner.tscn")]
fn gpu_tilemap_generation_small() { fn gpu_tilemap_generation_small() {
let output = run_tilemap_for_size(128, 128, TILE_SIZE); let output = run_tilemap_gpu_for_size(128, 128, TILE_SIZE);
let expected = expected_output_bytes(128, 128, TILE_SIZE); let expected = expected_output_bytes(128, 128, TILE_SIZE);
assert_eq!(output.len(), expected, "Small tilemap output byte size mismatch"); assert_eq!(output.len(), expected, "Small tilemap output byte size mismatch");
godot_print!("Small tilemap test validated {} bytes", output.len()); godot_print!("Small tilemap test validated {} bytes", output.len());
@ -1109,7 +1155,7 @@ mod gd_rehearse_tests {
#[gditest(scene_path = "res://tests/test_runner.tscn")] #[gditest(scene_path = "res://tests/test_runner.tscn")]
fn gpu_tilemap_generation_medium() { fn gpu_tilemap_generation_medium() {
let output = run_tilemap_for_size(256, 256, TILE_SIZE); let output = run_tilemap_gpu_for_size(256, 256, TILE_SIZE);
let expected = expected_output_bytes(256, 256, TILE_SIZE); let expected = expected_output_bytes(256, 256, TILE_SIZE);
assert_eq!(output.len(), expected, "Medium tilemap output byte size mismatch"); assert_eq!(output.len(), expected, "Medium tilemap output byte size mismatch");
godot_print!("Medium tilemap test validated {} bytes", output.len()); godot_print!("Medium tilemap test validated {} bytes", output.len());
@ -1117,7 +1163,7 @@ mod gd_rehearse_tests {
#[gditest(scene_path = "res://tests/test_runner.tscn")] #[gditest(scene_path = "res://tests/test_runner.tscn")]
fn gpu_tilemap_generation_large() { fn gpu_tilemap_generation_large() {
let output = run_tilemap_for_size(512, 512, TILE_SIZE); let output = run_tilemap_gpu_for_size(512, 512, TILE_SIZE);
let expected = expected_output_bytes(512, 512, TILE_SIZE); let expected = expected_output_bytes(512, 512, TILE_SIZE);
assert_eq!(output.len(), expected, "Large tilemap output byte size mismatch"); assert_eq!(output.len(), expected, "Large tilemap output byte size mismatch");
godot_print!("Large tilemap test validated {} bytes", output.len()); godot_print!("Large tilemap test validated {} bytes", output.len());
@ -1125,7 +1171,39 @@ mod gd_rehearse_tests {
#[gditest(scene_path = "res://tests/test_runner.tscn")] #[gditest(scene_path = "res://tests/test_runner.tscn")]
fn gpu_tilemap_generation_xlarge() { fn gpu_tilemap_generation_xlarge() {
let output = run_tilemap_for_size(1024, 1024, TILE_SIZE); let output = run_tilemap_gpu_for_size(1024, 1024, TILE_SIZE);
let expected = expected_output_bytes(1024, 1024, TILE_SIZE);
assert_eq!(output.len(), expected, "XL tilemap output byte size mismatch");
godot_print!("XL tilemap test validated {} bytes", output.len());
}
#[gditest(scene_path = "res://tests/test_runner.tscn")]
fn cpu_tilemap_generation_small() {
let output = run_tilemap_cpu_for_size(128, 128, TILE_SIZE);
let expected = expected_output_bytes(128, 128, TILE_SIZE);
assert_eq!(output.len(), expected, "Small tilemap output byte size mismatch");
godot_print!("Small tilemap test validated {} bytes", output.len());
}
#[gditest(scene_path = "res://tests/test_runner.tscn")]
fn cpu_tilemap_generation_medium() {
let output = run_tilemap_cpu_for_size(256, 256, TILE_SIZE);
let expected = expected_output_bytes(256, 256, TILE_SIZE);
assert_eq!(output.len(), expected, "Medium tilemap output byte size mismatch");
godot_print!("Medium tilemap test validated {} bytes", output.len());
}
#[gditest(scene_path = "res://tests/test_runner.tscn")]
fn cpu_tilemap_generation_large() {
let output = run_tilemap_cpu_for_size(512, 512, TILE_SIZE);
let expected = expected_output_bytes(512, 512, TILE_SIZE);
assert_eq!(output.len(), expected, "Large tilemap output byte size mismatch");
godot_print!("Large tilemap test validated {} bytes", output.len());
}
#[gditest(scene_path = "res://tests/test_runner.tscn")]
fn cpu_tilemap_generation_xlarge() {
let output = run_tilemap_cpu_for_size(1024, 1024, TILE_SIZE);
let expected = expected_output_bytes(1024, 1024, TILE_SIZE); let expected = expected_output_bytes(1024, 1024, TILE_SIZE);
assert_eq!(output.len(), expected, "XL tilemap output byte size mismatch"); assert_eq!(output.len(), expected, "XL tilemap output byte size mismatch");
godot_print!("XL tilemap test validated {} bytes", output.len()); godot_print!("XL tilemap test validated {} bytes", output.len());