diff --git a/assets/assets.sgp b/assets/assets.sgp deleted file mode 100644 index 2a7ab6e..0000000 Binary files a/assets/assets.sgp and /dev/null differ diff --git a/assets/shaders/gui.frag.spv b/assets/shaders/gui.frag.spv deleted file mode 100644 index 89e67b5..0000000 Binary files a/assets/shaders/gui.frag.spv and /dev/null differ diff --git a/assets/shaders/gui.vert.spv b/assets/shaders/gui.vert.spv deleted file mode 100644 index 0fad4d6..0000000 Binary files a/assets/shaders/gui.vert.spv and /dev/null differ diff --git a/assets/shaders/pbr.frag.spv b/assets/shaders/pbr.frag.spv deleted file mode 100644 index e2f8c2c..0000000 Binary files a/assets/shaders/pbr.frag.spv and /dev/null differ diff --git a/assets/shaders/pbr.vert.spv b/assets/shaders/pbr.vert.spv deleted file mode 100644 index 81ae640..0000000 Binary files a/assets/shaders/pbr.vert.spv and /dev/null differ diff --git a/assets/shaders/quad.frag.spv b/assets/shaders/quad.frag.spv deleted file mode 100644 index c9fb610..0000000 Binary files a/assets/shaders/quad.frag.spv and /dev/null differ diff --git a/assets/shaders/quad.vert.spv b/assets/shaders/quad.vert.spv deleted file mode 100644 index 291e27e..0000000 Binary files a/assets/shaders/quad.vert.spv and /dev/null differ diff --git a/src/gears/platform.d b/src/gears/platform.d index 8ae3f0d..5693a7d 100644 --- a/src/gears/platform.d +++ b/src/gears/platform.d @@ -1,6 +1,7 @@ import aliases; import includes; import std.stdio; +import core.memory; version(linux) { @@ -30,7 +31,7 @@ struct Function void CheckErr(Window *window, xcb_void_cookie_t *cookie, xcb_generic_error_t *err, string msg) { assert(err == null, msg); - free(err); + pureFree(err); }; Window CreateWindow(string name, u16 width, u16 height) @@ -132,9 +133,9 @@ Window CreateWindow(string name, u16 width, u16 height) window.close_event = r_close.atom; window.minimize_event = r_minimize.atom; - free(r_proto); - free(r_close); - free(r_minimize); + pureFree(r_proto); + pureFree(r_close); + pureFree(r_minimize); xcb_map_window(window.conn, window.window); diff --git a/src/gears/renderer.d b/src/gears/renderer.d index a1ef793..226df72 100644 --- a/src/gears/renderer.d +++ b/src/gears/renderer.d @@ -2,3 +2,29 @@ import aliases; import includes; alias Shader = VkShaderModule; +alias Pipeline = VkPipeline; +alias Attribute = VkVertexInputAttributeDescription; + +enum InputRate : int +{ + Vertex = VK_VERTEX_INPUT_RATE_VERTEX, + Instance = VK_VERTEX_INPUT_RATE_INSTANCE, +} + +enum Format: int +{ + UINT = VK_FORMAT_R32_UINT, + R_F32 = VK_FORMAT_R32_SFLOAT, + RG_F32 = VK_FORMAT_R32G32_SFLOAT, + RGB_F32 = VK_FORMAT_R32G32B32_SFLOAT, + RGBA_F32 = VK_FORMAT_R32G32B32A32_SFLOAT, +} + +struct GfxPipelineInfo +{ + Shader vertex_shader; + Shader frag_shader; + InputRate input_rate; + u32 input_rate_stride; + Attribute[] vertex_attributes; +} diff --git a/src/gears/vulkan.d b/src/gears/vulkan.d index d20558d..b5449f6 100644 --- a/src/gears/vulkan.d +++ b/src/gears/vulkan.d @@ -228,10 +228,109 @@ BuildShader(Vulkan* vk, u8[] bytes) return shader; } -Result!(VkPipeline) +VkPipeline +CreateGraphicsPipeline(Vulkan* vk, GfxPipelineInfo* build_info) +{ + VkDynamicState[] dyn_state = [ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR ]; + + VkPipelineDynamicStateCreateInfo dyn_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, + pDynamicStates: dyn_state.ptr, + dynamicStateCount: cast(u32)dyn_state.length, + }; + + VkPipelineInputAssemblyStateCreateInfo assembly_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, + topology: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, + primitiveRestartEnable: VK_FALSE, + }; + + VkPipelineRasterizationStateCreateInfo rasterization_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, + polygonMode: VK_POLYGON_MODE_FILL, + lineWidth: 1.0, + frontFace: VK_FRONT_FACE_COUNTER_CLOCKWISE, + }; + + VkPipelineMultisampleStateCreateInfo multisample_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, + rasterizationSamples: VK_SAMPLE_COUNT_1_BIT, + minSampleShading: 1.0, + alphaToCoverageEnable: VK_FALSE, + alphaToOneEnable: VK_FALSE, + }; + + VkPipelineDepthStencilStateCreateInfo depth_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, + depthTestEnable: VK_TRUE, + depthWriteEnable: VK_TRUE, + depthCompareOp: VK_COMPARE_OP_GREATER_OR_EQUAL, + depthBoundsTestEnable: VK_FALSE, + stencilTestEnable: VK_FALSE, + minDepthBounds: 0.0, + maxDepthBounds: 1.0, + }; + + VkPipelineRenderingCreateInfo rendering_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO, + colorAttachmentCount: 1, + }; + + VkPipelineColorBlendAttachmentState blend_state = { + colorWriteMask: VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, + blendEnable: VK_FALSE, + }; + + VkPipelineColorBlendStateCreateInfo blend_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, + logicOpEnable: VK_FALSE, + logicOp: VK_LOGIC_OP_COPY, + attachmentCount: 1, + pAttachments: &blend_state, + }; + + VkVertexInputBindingDescription vertex_input_desc = { + binding: 0, + inputRate: cast(VkVertexInputRate)build_info.input_rate, + stride: build_info.input_rate_stride, + }; + + VkPipelineVertexInputStateCreateInfo input_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, + vertexBindingDescriptionCount: 1, + pVertexBindingDescriptions: &vertex_input_desc, + vertexAttributeDescriptionCount: cast(u32)build_info.vertex_attributes.length, + pVertexAttributeDescriptions: build_info.vertex_attributes.ptr, + }; + + VkPipelineViewportStateCreateInfo viewport_info = { + sType: VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, + viewportCount: 1, + scissorCount: 1, + }; + + VkGraphicsPipelineCreateInfo create_info = { + sType: VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, + pNext: &rendering_info, + pVertexInputState: &input_info, + pInputAssemblyState: &assembly_info, + pViewportState: &viewport_info, + pRasterizationState: &rasterization_info, + pMultisampleState: &multisample_info, + pColorBlendState: &blend_info, + pDepthStencilState: &depth_info, + pDynamicState: &dyn_info, + }; + + VkPipeline pipeline; + + return pipeline; +} + +VkPipeline CreateComputePipeline(Vulkan* vk, string shader) { - Result!(VkPipeline) pipeline; + VkPipeline pipeline; diff --git a/src/shaders/triangle.frag.glsl b/src/shaders/triangle.frag.glsl new file mode 100644 index 0000000..ad91eb6 --- /dev/null +++ b/src/shaders/triangle.frag.glsl @@ -0,0 +1,10 @@ +#version 460 + +layout (location = 0) in vec3 fragColor; + +layout (location = 0) out vec4 outColor; + +void main() +{ + outColor = vec4(fragColor, 1.0); +} diff --git a/src/shaders/triangle.vert.glsl b/src/shaders/triangle.vert.glsl new file mode 100644 index 0000000..18e8b61 --- /dev/null +++ b/src/shaders/triangle.vert.glsl @@ -0,0 +1,22 @@ +#version 460 + +layout (location = 0) out vec3 fragColor; + +vec2 positions[3] = vec2[]( + vec2(0.0, -0.5), + vec2(0.5, 0.5), + vec2(-0.5, 0.5) +); + +vec3 colors[3] = vec3[]( + vec3(1.0, 0.0, 0.0), + vec3(0.0, 1.0, 0.0), + vec3(0.0, 0.0, 1.0) +); + +void main() +{ + gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); + fragColor = colors[gl_VertexIndex]; +} + diff --git a/src/shared/aliases.d b/src/shared/aliases.d index a0546ff..b6d1136 100644 --- a/src/shared/aliases.d +++ b/src/shared/aliases.d @@ -28,6 +28,3 @@ alias b32 = uint; alias intptr = intptr_t; alias uintptr = uintptr_t; -alias free = pureFree; -alias malloc = pureMalloc; -alias realloc = pureRealloc; diff --git a/src/shared/alloc.d b/src/shared/alloc.d index 7978be9..75d3579 100644 --- a/src/shared/alloc.d +++ b/src/shared/alloc.d @@ -2,6 +2,7 @@ import aliases; import m = math; import std.stdio; import core.stdc.string : memset; +import core.memory; const DEFAULT_ALIGNMENT = (void *).sizeof * 2; @@ -15,7 +16,7 @@ struct Arena T* Alloc(T)() { - void* mem = malloc(T.sizeof); + void* mem = pureMalloc(T.sizeof); memset(mem, 0, T.sizeof); return (cast(T*)mem); } @@ -23,7 +24,7 @@ Alloc(T)() T[] AllocArray(T)(u64 count) { - void* mem = malloc(T.sizeof * count); + void* mem = pureMalloc(T.sizeof * count); memset(mem, 0, T.sizeof * count); return (cast(T*)mem)[0 .. count]; } @@ -32,7 +33,7 @@ Arena CreateArena(u64 size) { Arena arena = { - mem: cast(u8 *)malloc(size), + mem: cast(u8 *)pureMalloc(size), length: size, pos: 0, }; @@ -90,5 +91,5 @@ Reset(Arena* arena) void Free(Arena* arena) { - free(arena.mem); + pureFree(arena.mem); }