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);
r.Renderer rd = r.Init(&window);
scope(exit) r.Destroy(&rd);
//scope(exit) r.Destroy(&rd);
while (true)
{
@ -21,5 +21,7 @@ void main()
r.Cycle(&rd);
}
writefln("exiting");
}

View File

@ -115,6 +115,7 @@ struct Camera
struct GlobalUniforms
{
Mat4 world_matrix;
Vec2 res;
}
@ -236,13 +237,21 @@ Cycle(Renderer* rd)
{
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);
Bind(rd, &rd.compute_pipeline);
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);
@ -258,7 +267,7 @@ Cycle(Renderer* rd)
Bind(rd, &rd.triangle_pipeline);
Draw(rd, 3, 1);
//Draw(rd, 3, 1);
Bind(rd, &rd.pbr_pipeline);

View File

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

View File

@ -22,7 +22,7 @@ mat4 y_matrix = mat4(
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)
{

View File

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

View File

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

View File

@ -359,3 +359,30 @@ Hash(string str)
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;
}