some work

This commit is contained in:
matthew 2025-07-12 08:15:48 +10:00
parent 6c66d0211f
commit f604b9a5ca
13 changed files with 130 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@
"sourcePaths": ["src/gears", "src/shared", "src/generated"], "sourcePaths": ["src/gears", "src/shared", "src/generated"],
"libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++"], "libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++"],
"libs-windows": [], "libs-windows": [],
"preGenerateCommands-linux": ["./build-vma.sh", "build/Packer"], "preGenerateCommands-linux": ["./build-vma.sh", "build/Codegen", "dub main:packer", "build/Packer"],
"preGenerateCommands-windows": [], "preGenerateCommands-windows": [],
}, },
{ {
@ -26,6 +26,7 @@
"sourceFiles-linux": ["build/libxxhash.a", "build/libstb_image.a", "build/libm3d.a"], "sourceFiles-linux": ["build/libxxhash.a", "build/libstb_image.a", "build/libm3d.a"],
"preGenerateCommands-linux": ["./build-vma.sh"], "preGenerateCommands-linux": ["./build-vma.sh"],
"preGenerateCommands-windows": [], "preGenerateCommands-windows": [],
"dflags-dmd": ["-P=-DXXH_VECTOR=0", "-P=-DSTBI_NO_SIMD", "-P=-DXXH_NO_PREFTECH"],
}, },
{ {
"name": "codegen", "name": "codegen",
@ -38,6 +39,7 @@
"preGenerateCommands-linux": ["./build-vma.sh"], "preGenerateCommands-linux": ["./build-vma.sh"],
"preGenerateCommands-windows": [], "preGenerateCommands-windows": [],
"versions": ["codegen"], "versions": ["codegen"],
"dflags-dmd": ["-P=-DXXH_VECTOR=0", "-P=-DSTBI_NO_SIMD", "-P=-DXXH_NO_PREFTECH"],
} }
] ]
} }

View File

@ -35,5 +35,21 @@ void main()
auto pipeline = vk.CreateGraphicsPipeline(&vulkan, &pipeline_info); auto pipeline = vk.CreateGraphicsPipeline(&vulkan, &pipeline_info);
u8[] comp_bytes = ap.LoadAssetData("shaders/gradient.comp");
assert(comp_bytes != null, "Unable to load compute shader data");
auto comp_module = vk.BuildShader(&vulkan, comp_bytes);
assert(comp_module.ok, "Unable to build compute shader");
auto comp_pipeline = vk.CreateComputePipeline(&vulkan, comp_module.value);
vk.Destroy(&vulkan, comp_module.value);
vk.Destroy(&vulkan, comp_pipeline);
vk.Destroy(&vulkan, vert_module.value);
vk.Destroy(&vulkan, frag_module.value);
vk.Destroy(&vulkan, pipeline);
vk.Destroy(&vulkan); vk.Destroy(&vulkan);
} }

View File

@ -28,3 +28,5 @@ struct GfxPipelineInfo
u32 input_rate_stride; u32 input_rate_stride;
Attribute[] vertex_attributes; Attribute[] vertex_attributes;
} }

View File

@ -228,7 +228,7 @@ BuildShader(Vulkan* vk, u8[] bytes)
return shader; return shader;
} }
VkPipeline Pipeline
CreateGraphicsPipeline(Vulkan* vk, GfxPipelineInfo* build_info) CreateGraphicsPipeline(Vulkan* vk, GfxPipelineInfo* build_info)
{ {
VkDynamicState[] dyn_state = [ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR ]; VkDynamicState[] dyn_state = [ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR ];
@ -274,6 +274,8 @@ CreateGraphicsPipeline(Vulkan* vk, GfxPipelineInfo* build_info)
VkPipelineRenderingCreateInfo rendering_info = { VkPipelineRenderingCreateInfo rendering_info = {
sType: VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO, sType: VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
colorAttachmentCount: 1, colorAttachmentCount: 1,
pColorAttachmentFormats: &vk.draw_image.base.format,
depthAttachmentFormat: vk.depth_image.base.format,
}; };
VkPipelineColorBlendAttachmentState blend_state = { VkPipelineColorBlendAttachmentState blend_state = {
@ -349,16 +351,41 @@ CreateGraphicsPipeline(Vulkan* vk, GfxPipelineInfo* build_info)
return pipeline; return pipeline;
} }
VkPipeline
CreateComputePipeline(Vulkan* vk, string shader) Pipeline
CreateComputePipeline(Vulkan* vk, Shader shader)
{ {
VkComputePipelineCreateInfo info = {
sType: VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
layout: vk.pipeline_layout,
stage: {
sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
stage: VK_SHADER_STAGE_COMPUTE_BIT,
pName: "main",
},
};
__traits(getMember, &info.stage, "module") = shader;
VkPipeline pipeline; VkPipeline pipeline;
VkResult result = vkCreateComputePipelines(vk.device, null, 1, &info, null, &pipeline);
assert(VkCheck("CreateComputePipeline failure", result), "Unable to build pipeline");
return pipeline; return pipeline;
} }
void
Destroy(Vulkan* vk, Shader shader)
{
vkDestroyShaderModule(vk.device, shader, null);
}
void
Destroy(Vulkan* vk, Pipeline pipeline)
{
vkDestroyPipeline(vk.device, pipeline, null);
}
void void
Destroy(Vulkan* vk) Destroy(Vulkan* vk)
{ {

View File

@ -3,6 +3,7 @@ import std.stdio;
import vulkan : Vulkan; import vulkan : Vulkan;
import std.conv; import std.conv;
import std.string; import std.string;
import core.stdc.string : strlen;
VkBool32 VkBool32
DebugCallback( DebugCallback(
@ -59,7 +60,7 @@ DebugCallback(
break; break;
} }
string msg = to!string(callback_data.pMessage); const char[] msg = callback_data.pMessage[0 .. strlen(callback_data.pMessage)];
writefln("[%s: %s]\n%r\n", ms, mt, msg); writefln("[%s: %s]\n%r\n", ms, mt, msg);

View File

@ -27,16 +27,19 @@ static immutable u64[] MODEL_HASHES = [
static immutable string[] SHADER_FILES = [ static immutable string[] SHADER_FILES = [
"shaders/triangle.vert.spv", "shaders/triangle.vert.spv",
"shaders/gradient.comp.spv",
"shaders/triangle.frag.spv", "shaders/triangle.frag.spv",
]; ];
static immutable string[] SHADER_NAMES = [ static immutable string[] SHADER_NAMES = [
"shaders/triangle.vert", "shaders/triangle.vert",
"shaders/gradient.comp",
"shaders/triangle.frag", "shaders/triangle.frag",
]; ];
static immutable u64[] SHADER_HASHES = [ static immutable u64[] SHADER_HASHES = [
8769314645675479020, 8769314645675479020,
16130483095684998267,
6282520872716708711, 6282520872716708711,
]; ];

View File

@ -0,0 +1,27 @@
#version 460
#extension GL_EXT_buffer_reference : require
#extension GL_GOOGLE_include_directive : require
#include "structures.layout"
layout (local_size_x = 16, local_size_y = 16) in;
void main()
{
ivec2 texel_coord = ivec2(gl_GlobalInvocationID.xy);
ivec2 size = imageSize(DrawImage);
if (texel_coord.x < size. x && texel_coord.y < size.y)
{
vec4 color = vec4(0.0);
if (gl_GlobalInvocationID.x != 0 && gl_LocalInvocationID.y != 0)
{
color.x = float(texel_coord.x) / size.x;
color.y = float(texel_coord.y) / size.y;
}
imageStore(DrawImage, texel_coord, color);
}
}

View File

@ -0,0 +1,33 @@
struct Vertex {
vec4 pos;
};
layout (buffer_reference, std430) readonly buffer VertexBuffer {
Vertex vertices[];
};
layout (set = 0, binding = 0) uniform GlobalUniforms {
vec2 res;
} G;
layout (set = 0, binding = 1) uniform ShaderUniforms {
float placeholder;
} S;
layout (rgba16f, set = 0, binding = 2) uniform image2D DrawImage;
layout (set = 0, binding = 3) uniform sampler SamplerNearest;
layout (set = 1, binding = 0) uniform texture2D Textures[];
layout (set = 2, binding = 0) uniform Material {
float placeholder;
} Materials[];
layout (set = 3, binding = 0) uniform Mesh {
VertexBuffer buf;
} Meshes[];
layout (push_constant) uniform Constants {
float placeholder;
} PC;

View File

@ -1,5 +1,11 @@
#version 460 #version 460
#extension GL_EXT_buffer_reference : require
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_nonuniform_qualifier : require
#include "structures.layout"
layout (location = 0) in vec3 fragColor; layout (location = 0) in vec3 fragColor;
layout (location = 0) out vec4 outColor; layout (location = 0) out vec4 outColor;

View File

@ -1,5 +1,11 @@
#version 460 #version 460
#extension GL_EXT_buffer_reference : require
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_nonuniform_qualifier : require
#include "structures.layout"
layout (location = 0) out vec3 fragColor; layout (location = 0) out vec3 fragColor;
vec2 positions[3] = vec2[]( vec2 positions[3] = vec2[](