yoda spins, fix crash on suboptimal swapchain

This commit is contained in:
matthew 2025-07-20 18:15:56 +10:00
parent ba4ccad085
commit cd0dc9f99a
14 changed files with 45 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -12,7 +12,7 @@ void main()
p.Window window = p.CreateWindow("Video Game", 1920, 1080); p.Window window = p.CreateWindow("Video Game", 1920, 1080);
r.Renderer rd = r.Init(&window); r.Renderer rd = r.Init(&window);
scope(exit) r.Destroy(&rd); //scope(exit) r.Destroy(&rd);
while (true) while (true)
{ {
@ -21,5 +21,7 @@ void main()
r.Cycle(&rd); r.Cycle(&rd);
} }
writefln("exiting");
} }

View File

@ -115,6 +115,7 @@ struct Camera
struct GlobalUniforms struct GlobalUniforms
{ {
Mat4 world_matrix;
Vec2 res; Vec2 res;
} }
@ -236,13 +237,21 @@ Cycle(Renderer* rd)
{ {
rd.ui_count = 0; rd.ui_count = 0;
f32 radius = 10.0;
f32 cam_x = sin(RDTSC()) * radius * 0.000000000001;
f32 cam_z = cos(RDTSC()) * radius * 0.000000000001;
Logf("cam_x %s cam_z %s", cam_x, cam_z);
rd.globals.world_matrix = Mat4.lookAt(Vec3(cam_x, 0.0, cam_z), Vec3(0.0, 0.0, 0.0), Vec3(0.0, 1.0, 0.0));
BeginFrame(rd); BeginFrame(rd);
Bind(rd, &rd.compute_pipeline); Bind(rd, &rd.compute_pipeline);
SetUniform(rd, &rd.globals); SetUniform(rd, &rd.globals);
DrawRect(rd, 150.0, 300.0, 500.0, 700.0, Vec4(0.0, 0.0, 1.0, 1.0)); //DrawRect(rd, 150.0, 300.0, 500.0, 700.0, Vec4(0.0, 0.0, 1.0, 1.0));
PrepComputeDrawImage(rd); PrepComputeDrawImage(rd);
@ -258,7 +267,7 @@ Cycle(Renderer* rd)
Bind(rd, &rd.triangle_pipeline); Bind(rd, &rd.triangle_pipeline);
Draw(rd, 3, 1); //Draw(rd, 3, 1);
Bind(rd, &rd.pbr_pipeline); Bind(rd, &rd.pbr_pipeline);

View File

@ -492,7 +492,7 @@ BeginFrame(Vulkan* vk)
{ {
RecreateSwapchain(vk); RecreateSwapchain(vk);
} }
else else if (result != VK_SUBOPTIMAL_KHR)
{ {
VkCheckA("BeginFrame failure: vkAcquireNextImageKHR error", result); VkCheckA("BeginFrame failure: vkAcquireNextImageKHR error", result);
} }

View File

@ -22,7 +22,7 @@ mat4 y_matrix = mat4(
void main() void main()
{ {
gl_Position = in_pos * y_matrix; gl_Position = in_pos * y_matrix * G.world_matrix;
if (Materials[nonuniformEXT(PC.mat_id)].albedo_has_texture) if (Materials[nonuniformEXT(PC.mat_id)].albedo_has_texture)
{ {

View File

@ -3,6 +3,7 @@
// **************************************************************************** // ****************************************************************************
layout (set = 0, binding = 0) uniform GlobalUniforms { layout (set = 0, binding = 0) uniform GlobalUniforms {
mat4 world_matrix;
vec2 res; vec2 res;
} G; } G;

View File

@ -1,6 +1,7 @@
import core.memory; import core.memory;
import std.stdint; import std.stdint;
import dplug.math; import dplug.math;
import std.math.trigonometry;
debug debug
{ {

View File

@ -359,3 +359,30 @@ Hash(string str)
return xxh3_64bits_withSeed(str.ptr, str.length, HASH_SEED); return xxh3_64bits_withSeed(str.ptr, str.length, HASH_SEED);
} }
u64
RDTSC()
{
union u64_split
{
u64 full;
struct
{
u32 upper;
u32 lower;
};
};
u64_split val;
u64_split* valp = &val;
asm
{
cpuid;
rdtsc;
mov R8, valp;
mov valp.upper.offsetof[R8], EDX;
mov valp.lower.offsetof[R8], EAX;
}
return val.full;
}