diff --git a/build.sh b/build.sh index ec97310..f0cb8d3 100755 --- a/build.sh +++ b/build.sh @@ -33,6 +33,18 @@ vma_compile_flags="-std=c++20 -I../external/vma" vma_out="-c -o" vma_obj="vma.o" +# glslc +glsl_compile="glslc" +glsl_flags="--target-spv=spv1.6 -std=460" +glsl_stage_vert="-fshader-stage=vert" +glsl_stage_frag="-fshader-stage=frag" +glsl_stage_tesc="-fshader-stage=tesc" +glsl_stage_tese="-fshader-stage=tese" +glsl_stage_geom="-fshader-stage=geom" +glsl_stage_comp="-fshader-stage=comp" +glsl_out="-o/build/shaders/glsl/" + + clang_common="${include_flags} -g -Xclang -flto-visibility-public-std -Wno-unknown-warning-option -fdiagnostics-absolute-paths -Wall -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Wno-for-loop-analysis -DVMA_STATIC_VULKAN_FUNCTIONS=0" clang_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${clang_common} ${auto_compile_flags}" clang_release="$compiler -g -O2 -DBUILD_DEBUG=0 ${clang_common} ${auto_compile_flags}" @@ -69,6 +81,37 @@ if [ ! -f $vma_obj ]; then $vma_ld fi + +mkdir -p ./shaders/glsl +for file in ../src/shaders/glsl/*.glsl; do + base_name=$(basename -- "$file" .glsl) + echo $base_name + echo $file + + case base_name in + *.vert) + glsl_stage="${glsl_stage_vert}" + ;; + *.frag) + glsl_stage="${glsl_stage_vert}" + ;; + *.tesc) + glsl_stage="${glsl_stage_tesc}" + ;; + *.tese) + glsl_stage="${glsl_stage_tese}" + ;; + *.geom) + glsl_stage="${glsl_stage_geom}" + ;; + *.comp) + glsl_stage="${glsl_stage_comp}" + ;; + esac + + $glsl_compile $glsl_flags $glsl_stage file "${glsl_out}${base_name}.spv" +done + $cpp_compiler $vma_compile_flags $vma_source_files $vma_out $vma_obj ar rcs libvma.a vmastdc++.o diff --git a/src/platform.h b/src/platform.h index 4c0a153..ed39ce4 100644 --- a/src/platform.h +++ b/src/platform.h @@ -63,3 +63,7 @@ b32 CreateWindow(); Window *GetWindow(); b32 GetWindowEvent(WindowEvent *event); WindowSize GetWindowSize(); + +// Directory Functions +b32 ChangeWorkingDir(const char *); +u8 *OpenFile(const char *); diff --git a/src/platform_linux.c b/src/platform_linux.c index c8b52d9..eb89370 100644 --- a/src/platform_linux.c +++ b/src/platform_linux.c @@ -288,3 +288,16 @@ b32 _GetWindowEvent(WindowEvent *event) return valid_event; } +b32 ChangeWorkingDir(const char *) +{ + b32 success = false; + + return success; +} + +u8 *OpenFile(const char *) +{ + u8 *bytes; + + return bytes; +} diff --git a/src/render_vulkan.c b/src/render_vulkan.c index e74e24b..e14eaf2 100644 --- a/src/render_vulkan.c +++ b/src/render_vulkan.c @@ -672,6 +672,18 @@ static b32 CreateDescriptors() return success; } +static b32 CreatePipelines() +{ + b32 success = true; + + return success; +} + +static VkShaderModule CreateShaderModule(const char *file_name) +{ + return NULL; +} + static void DestroyVulkan() { VkDevice device = renderer.vk.device; diff --git a/src/render_vulkan.h b/src/render_vulkan.h index 3a54c79..850575c 100644 --- a/src/render_vulkan.h +++ b/src/render_vulkan.h @@ -123,7 +123,7 @@ VK_DECLARE(vkDestroyDescriptorSetLayout); typedef enum Pipeline_e { - PIPELINE_QUAD, + PIPELINE_CUBE, PIPELINE_MAX, } PipelineHandle; @@ -256,6 +256,7 @@ static b32 CreateImmediateStructures(); static b32 CreateSwapchain(); static VkFormat GetImageFormat(); static b32 CreateDescriptors(); +static b32 CreatePipelines(); // Destroy static void DestroyVulkan(); diff --git a/src/shaders/glsl/quad.frag.glsl b/src/shaders/glsl/quad.frag.glsl new file mode 100644 index 0000000..ad91eb6 --- /dev/null +++ b/src/shaders/glsl/quad.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/glsl/quad.vert.glsl b/src/shaders/glsl/quad.vert.glsl new file mode 100644 index 0000000..dbae84a --- /dev/null +++ b/src/shaders/glsl/quad.vert.glsl @@ -0,0 +1,21 @@ +#version 460 + +layout (location = 0) out vec3 fragColor; + +vec2 triangle[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/vulkan_config.c b/src/vulkan_config.c index dc29d94..fdb9fd4 100644 --- a/src/vulkan_config.c +++ b/src/vulkan_config.c @@ -285,3 +285,105 @@ static VkPipelineLayoutCreateInfo pipeline_layout_create_info = { .pushConstantRangeCount = 1, .pPushConstantRanges = &push_const_range, }; + +// +// PIPELINES +// + +static VkDynamicState pipeline_dynamic_state[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; + +static const VkPipelineDynamicStateCreateInfo pipeline_default_dyn_state_info = { + .sType = STYPE(PIPELINE_DYNAMIC_STATE_CREATE_INFO), + .pDynamicStates = pipeline_dynamic_state, + .dynamicStateCount = Len(pipeline_dynamic_state), +}; + +const static VkPipelineInputAssemblyStateCreateInfo pipeline_default_assembly_info = { + .sType = STYPE(PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO), + .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, + .primitiveRestartEnable = VK_FALSE, +}; + +const static VkPipelineRasterizationStateCreateInfo pipeline_default_rasterization_info = { + .sType = STYPE(PIPELINE_RASTERIZATION_STATE_CREATE_INFO), + .polygonMode = VK_POLYGON_MODE_FILL, + .lineWidth = 1.0, + .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, +}; + +const static VkPipelineMultisampleStateCreateInfo pipeline_default_multisample_info = { + .sType = STYPE(PIPELINE_MULTISAMPLE_STATE_CREATE_INFO), + .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, + .minSampleShading = 1.0, + .alphaToCoverageEnable = VK_FALSE, + .alphaToOneEnable = VK_FALSE, +}; + +const static VkPipelineDepthStencilStateCreateInfo pipeline_default_depth_info = { + .sType = STYPE(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, +}; + +const static VkPipelineRenderingCreateInfo pipeline_default_rendering_info = { + .sType = STYPE(PIPELINE_RENDERING_CREATE_INFO), + .colorAttachmentCount = 1, + //.pColorAttachmentFormats = FORMAT + //.depthAttachmentFormat = DEPTH_FORMAT + // Do not forget these whatever you do +}; + +const static VkPipelineColorBlendAttachmentState pipeline_default_blend_attach_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, +}; + +const static VkPipelineColorBlendStateCreateInfo pipeline_default_blend_info = { + .sType = STYPE(PIPELINE_COLOR_BLEND_STATE_CREATE_INFO), + .logicOpEnable = VK_FALSE, + .logicOp = VK_LOGIC_OP_COPY, + .attachmentCount = 1, + .pAttachments = &pipeline_default_blend_attach_state, +}; + +const static VkPipelineVertexInputStateCreateInfo pipeline_default_vertex_info = { + .sType = STYPE(PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO), +}; + +const static VkPipelineViewportStateCreateInfo pipeline_default_viewport_info = { + .sType = STYPE(PIPELINE_VIEWPORT_STATE_CREATE_INFO), + .viewportCount = 1, + .scissorCount = 1, +}; + +#define INIT_PIPELINE_DEFAULTS(pipeline) \ +static VkPipelineDynamicStateCreateInfo pipeline##_dynamic_info = pipeline_default_dyn_state_info; \ +static VkPipelineInputAssemblyStateCreateInfo pipeline##_assembly_info = pipeline_default_assembly_info; \ +static VkPipelineRasterizationStateCreateInfo pipeline##_rasterization_info = pipeline_default_rasterization_info; \ +static VkPipelineMultisampleStateCreateInfo pipeline##_multisample_info = pipeline_default_multisample_info; \ +static VkPipelineDepthStencilStateCreateInfo pipeline##_depth_info = pipeline_default_depth_info; \ +static VkPipelineRenderingCreateInfo pipeline##_rendering_info = pipeline_default_rendering_info; \ +static VkPipelineColorBlendStateCreateInfo pipeline##_blend_info = pipeline_default_blend_info; \ +static VkPipelineVertexInputStateCreateInfo pipeline##_vertex_info = pipeline_default_vertex_info; \ +static VkPipelineViewportStateCreateInfo pipeline##_viewport_info = pipeline_default_viewport_info; \ +static VkGraphicsPipelineCreateInfo pipeline##_create_info = { \ + .sType = STYPE(GRAPHICS_PIPELINE_CREATE_INFO), \ + .pNext = &pipeline##_rendering_info, \ + .pVertexInputState = &pipeline##_vertex_info, \ + .pInputAssemblyState = &pipeline##_assembly_info, \ + .pViewportState = &pipeline##_viewport_info, \ + .pRasterizationState = &pipeline##_rasterization_info,\ + .pMultisampleState = &pipeline##_multisample_info, \ + .pColorBlendState = &pipeline##_blend_info, \ + .pDepthStencilState = &pipeline##_depth_info, \ + .pDynamicState = &pipeline##_dynamic_info, \ +}; + +INIT_PIPELINE_DEFAULTS(cube); + +