Mercurial > games > semicongine
annotate src/semicongine/vulkan/pipeline.nim @ 790:a979e5c581de
add: scene/shader compatability check, fix collision code to work with new APIs
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 29 Aug 2023 00:01:13 +0700 |
parents | 670ca93a358b |
children | 451b7ccfe722 |
rev | line source |
---|---|
583
90537a8887ae
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
575
diff
changeset
|
1 import std/tables |
727
360664dfc17d
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
712
diff
changeset
|
2 import std/sequtils |
662 | 3 import std/strformat |
583
90537a8887ae
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
575
diff
changeset
|
4 |
667
d3500ae5d235
did: small refactoring of module structure
Sam <sam@basx.dev>
parents:
662
diff
changeset
|
5 import ../core |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 import ./device |
566
cc7ba46fe3c4
add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents:
565
diff
changeset
|
7 import ./descriptor |
573
f31a9821ae1c
did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents:
572
diff
changeset
|
8 import ./shader |
588 | 9 import ./buffer |
650
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
10 import ./image |
573
f31a9821ae1c
did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents:
572
diff
changeset
|
11 |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 type |
566
cc7ba46fe3c4
add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents:
565
diff
changeset
|
13 Pipeline* = object |
569 | 14 device*: Device |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 vk*: VkPipeline |
569 | 16 layout*: VkPipelineLayout |
790
a979e5c581de
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
787
diff
changeset
|
17 shaderConfiguration*: ShaderConfiguration |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
727
diff
changeset
|
18 shaderModules*: (ShaderModule, ShaderModule) |
566
cc7ba46fe3c4
add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents:
565
diff
changeset
|
19 descriptorSetLayout*: DescriptorSetLayout |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
21 func inputs*(pipeline: Pipeline): seq[ShaderAttribute] = |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
22 pipeline.shaderConfiguration.inputs |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 |
583
90537a8887ae
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
575
diff
changeset
|
24 func uniforms*(pipeline: Pipeline): seq[ShaderAttribute] = |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
727
diff
changeset
|
25 pipeline.shaderConfiguration.uniforms |
583
90537a8887ae
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
575
diff
changeset
|
26 |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
27 func samplers*(pipeline: Pipeline): seq[ShaderAttribute] = |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
28 pipeline.shaderConfiguration.samplers |
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
29 |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
30 proc setupDescriptors*(pipeline: Pipeline, descriptorPool: DescriptorPool, buffers: seq[Buffer], textures: var Table[string, seq[VulkanTexture]], inFlightFrames: int, emptyTexture: VulkanTexture): seq[DescriptorSet] = |
588 | 31 assert pipeline.vk.valid |
658
8549373571aa
did: improve stability for configuration without uniforms and settings the engine renderer
Sam <sam@basx.dev>
parents:
653
diff
changeset
|
32 assert buffers.len == 0 or buffers.len == inFlightFrames # need to guard against this in case we have no uniforms, then we also create no buffers |
702 | 33 |
712
7a7fb1a42811
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
704
diff
changeset
|
34 result = descriptorPool.allocateDescriptorSet(pipeline.descriptorSetLayout, inFlightFrames) |
690
fe20f8013d12
add: support for struct members to be array
Sam <sam@basx.dev>
parents:
668
diff
changeset
|
35 |
588 | 36 for i in 0 ..< inFlightFrames: |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
37 var offset = 0 |
652
43240986f76d
add: texture testing, not working yet, something update un-updated descritors (even though we write the descriptors man!)
Sam <sam@basx.dev>
parents:
651
diff
changeset
|
38 # first descriptor is always uniform for globals, match should be better somehow |
702 | 39 for descriptor in result[i].layout.descriptors.mitems: |
658
8549373571aa
did: improve stability for configuration without uniforms and settings the engine renderer
Sam <sam@basx.dev>
parents:
653
diff
changeset
|
40 if descriptor.thetype == Uniform and buffers.len > 0: |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
41 let size = descriptor.size |
650
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
42 descriptor.buffer = buffers[i] |
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
43 descriptor.offset = offset |
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
44 descriptor.size = size |
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
45 offset += size |
651
164bf40c664f
add: uncomment some of the prepared texture code, nice interface for scene-global shader values (aka uniforms
Sam <sam@basx.dev>
parents:
650
diff
changeset
|
46 elif descriptor.thetype == ImageSampler: |
653
ac7dfbd56cc6
add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents:
652
diff
changeset
|
47 if not (descriptor.name in textures): |
727
360664dfc17d
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
712
diff
changeset
|
48 raise newException(Exception, &"Missing shader texture in scene: {descriptor.name}, available are {textures.keys.toSeq}") |
784
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
49 |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
50 for textureIndex in 0 ..< int(descriptor.count): |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
51 if textureIndex < textures[descriptor.name].len: |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
52 descriptor.imageviews.add textures[descriptor.name][textureIndex].imageView |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
53 descriptor.samplers.add textures[descriptor.name][textureIndex].sampler |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
54 else: |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
55 descriptor.imageviews.add emptyTexture.imageView |
fa39e67dded7
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
783
diff
changeset
|
56 descriptor.samplers.add emptyTexture.sampler |
588 | 57 |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
727
diff
changeset
|
58 proc createPipeline*(device: Device, renderPass: VkRenderPass, shaderConfiguration: ShaderConfiguration, inFlightFrames: int, subpass = 0'u32): Pipeline = |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
59 assert renderPass.valid |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
60 assert device.vk.valid |
589
b434feaf2b67
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
588
diff
changeset
|
61 |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
62 result.device = device |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
727
diff
changeset
|
63 result.shaderModules = device.createShaderModules(shaderConfiguration) |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
64 result.shaderConfiguration = shaderConfiguration |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
65 |
658
8549373571aa
did: improve stability for configuration without uniforms and settings the engine renderer
Sam <sam@basx.dev>
parents:
653
diff
changeset
|
66 var descriptors: seq[Descriptor] |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
67 if result.shaderConfiguration.uniforms.len > 0: |
658
8549373571aa
did: improve stability for configuration without uniforms and settings the engine renderer
Sam <sam@basx.dev>
parents:
653
diff
changeset
|
68 descriptors.add Descriptor( |
650
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
69 name: "Uniforms", |
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
70 thetype: Uniform, |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
71 count: 1, |
583
90537a8887ae
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
575
diff
changeset
|
72 stages: @[VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_STAGE_FRAGMENT_BIT], |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
73 size: result.shaderConfiguration.uniforms.size(), |
658
8549373571aa
did: improve stability for configuration without uniforms and settings the engine renderer
Sam <sam@basx.dev>
parents:
653
diff
changeset
|
74 ) |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
75 for sampler in result.shaderConfiguration.samplers: |
650
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
76 descriptors.add Descriptor( |
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
77 name: sampler.name, |
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
78 thetype: ImageSampler, |
787
670ca93a358b
fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents:
784
diff
changeset
|
79 count: (if sampler.arrayCount == 0: 1 else: sampler.arrayCount), |
650
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
80 stages: @[VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_STAGE_FRAGMENT_BIT], |
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
81 ) |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
82 result.descriptorSetLayout = device.createDescriptorSetLayout(descriptors) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
83 |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
84 # TODO: Push constants |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
85 # var pushConstant = VkPushConstantRange( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
86 # stageFlags: toBits shaderStage, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
87 # offset: 0, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
88 # size: 0, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
89 # ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
90 var descriptorSetLayouts: seq[VkDescriptorSetLayout] = @[result.descriptorSetLayout.vk] |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
91 # var pushConstants: seq[VkPushConstantRange] = @[pushConstant] |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
92 var pipelineLayoutInfo = VkPipelineLayoutCreateInfo( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
93 sType: VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
94 setLayoutCount: uint32(descriptorSetLayouts.len), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
95 pSetLayouts: descriptorSetLayouts.toCPointer, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
96 # pushConstantRangeCount: uint32(pushConstants.len), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
97 # pPushConstantRanges: pushConstants.toCPointer, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
98 ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
99 checkVkResult vkCreatePipelineLayout(device.vk, addr(pipelineLayoutInfo), nil, addr(result.layout)) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
100 |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
101 var |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
102 bindings: seq[VkVertexInputBindingDescription] |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
103 attributes: seq[VkVertexInputAttributeDescription] |
783
893ec0fbfd44
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
782
diff
changeset
|
104 vertexInputInfo = result.shaderConfiguration.getVertexInputInfo(bindings, attributes) |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
105 inputAssembly = VkPipelineInputAssemblyStateCreateInfo( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
106 sType: VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
107 topology: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
108 primitiveRestartEnable: VK_FALSE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
109 ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
110 viewportState = VkPipelineViewportStateCreateInfo( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
111 sType: VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
112 viewportCount: 1, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
113 scissorCount: 1, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
114 ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
115 rasterizer = VkPipelineRasterizationStateCreateInfo( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
116 sType: VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
117 depthClampEnable: VK_FALSE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
118 rasterizerDiscardEnable: VK_FALSE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
119 polygonMode: VK_POLYGON_MODE_FILL, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
120 lineWidth: 1.0, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
121 cullMode: toBits [VK_CULL_MODE_BACK_BIT], |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
122 frontFace: VK_FRONT_FACE_CLOCKWISE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
123 depthBiasEnable: VK_FALSE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
124 depthBiasConstantFactor: 0.0, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
125 depthBiasClamp: 0.0, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
126 depthBiasSlopeFactor: 0.0, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
127 ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
128 multisampling = VkPipelineMultisampleStateCreateInfo( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
129 sType: VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
130 sampleShadingEnable: VK_FALSE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
131 rasterizationSamples: VK_SAMPLE_COUNT_1_BIT, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
132 minSampleShading: 1.0, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
133 pSampleMask: nil, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
134 alphaToCoverageEnable: VK_FALSE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
135 alphaToOneEnable: VK_FALSE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
136 ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
137 colorBlendAttachment = VkPipelineColorBlendAttachmentState( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
138 colorWriteMask: toBits [VK_COLOR_COMPONENT_R_BIT, VK_COLOR_COMPONENT_G_BIT, VK_COLOR_COMPONENT_B_BIT, VK_COLOR_COMPONENT_A_BIT], |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
139 blendEnable: VK_TRUE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
140 srcColorBlendFactor: VK_BLEND_FACTOR_SRC_ALPHA, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
141 dstColorBlendFactor: VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
142 colorBlendOp: VK_BLEND_OP_ADD, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
143 srcAlphaBlendFactor: VK_BLEND_FACTOR_ONE, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
144 dstAlphaBlendFactor: VK_BLEND_FACTOR_ZERO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
145 alphaBlendOp: VK_BLEND_OP_ADD, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
146 ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
147 colorBlending = VkPipelineColorBlendStateCreateInfo( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
148 sType: VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
149 logicOpEnable: false, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
150 attachmentCount: 1, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
151 pAttachments: addr(colorBlendAttachment), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
152 ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
153 dynamicStates = @[VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR] |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
154 dynamicState = VkPipelineDynamicStateCreateInfo( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
155 sType: VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
156 dynamicStateCount: uint32(dynamicStates.len), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
157 pDynamicStates: dynamicStates.toCPointer, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
158 ) |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
727
diff
changeset
|
159 stages = @[result.shaderModules[0].getPipelineInfo(), result.shaderModules[1].getPipelineInfo()] |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
160 createInfo = VkGraphicsPipelineCreateInfo( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
161 sType: VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
162 stageCount: uint32(stages.len), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
163 pStages: stages.toCPointer, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
164 pVertexInputState: addr(vertexInputInfo), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
165 pInputAssemblyState: addr(inputAssembly), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
166 pViewportState: addr(viewportState), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
167 pRasterizationState: addr(rasterizer), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
168 pMultisampleState: addr(multisampling), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
169 pDepthStencilState: nil, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
170 pColorBlendState: addr(colorBlending), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
171 pDynamicState: addr(dynamicState), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
172 layout: result.layout, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
173 renderPass: renderPass, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
174 subpass: subpass, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
175 basePipelineHandle: VkPipeline(0), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
176 basePipelineIndex: -1, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
177 ) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
178 checkVkResult vkCreateGraphicsPipelines( |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
179 device.vk, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
180 VkPipelineCache(0), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
181 1, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
182 addr(createInfo), |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
183 nil, |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
184 addr(result.vk) |
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
185 ) |
650
be6e0f89645a
add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents:
644
diff
changeset
|
186 |
583
90537a8887ae
did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents:
575
diff
changeset
|
187 discard result.uniforms # just for assertion |
588 | 188 |
575
eaedc0369c38
yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents:
573
diff
changeset
|
189 |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
190 proc destroy*(pipeline: var Pipeline) = |
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
191 assert pipeline.device.vk.valid |
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
192 assert pipeline.vk.valid |
561
4a9fc283c3af
add: initial version of better shader-shit
Sam <sam@basx.dev>
parents:
560
diff
changeset
|
193 assert pipeline.layout.valid |
566
cc7ba46fe3c4
add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents:
565
diff
changeset
|
194 assert pipeline.descriptorSetLayout.vk.valid |
588 | 195 |
782
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
727
diff
changeset
|
196 pipeline.shaderModules[0].destroy() |
b6950ea89b37
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
727
diff
changeset
|
197 pipeline.shaderModules[1].destroy() |
566
cc7ba46fe3c4
add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents:
565
diff
changeset
|
198 pipeline.descriptorSetLayout.destroy() |
561
4a9fc283c3af
add: initial version of better shader-shit
Sam <sam@basx.dev>
parents:
560
diff
changeset
|
199 pipeline.device.vk.vkDestroyPipelineLayout(pipeline.layout, nil) |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
200 pipeline.device.vk.vkDestroyPipeline(pipeline.vk, nil) |
566
cc7ba46fe3c4
add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents:
565
diff
changeset
|
201 pipeline.descriptorSetLayout.reset() |
561
4a9fc283c3af
add: initial version of better shader-shit
Sam <sam@basx.dev>
parents:
560
diff
changeset
|
202 pipeline.layout.reset() |
560
8de8a2102071
add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents:
diff
changeset
|
203 pipeline.vk.reset() |