Mercurial > games > semicongine
annotate test1.nim @ 1190:a3eb305bcac2 compiletime-tests
start of complete and total refactoring: the ULTIMATE
author | sam <sam@basx.dev> |
---|---|
date | Sun, 07 Jul 2024 23:36:16 +0700 |
parents | |
children | 239adab121a3 |
rev | line source |
---|---|
1190
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
1 import os |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
2 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
3 import semicongine/rendering |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
5 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
6 when isMainModule: |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
7 import semicongine/old/platform/window |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
8 import semicongine/old/vulkan/instance |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
9 import semicongine/old/vulkan/device |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
10 import semicongine/old/vulkan/physicaldevice |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
11 import std/options |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
12 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
13 type |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
14 MeshA = object |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
15 position: GPUArray[Vec3f, VertexBuffer] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
16 indices: GPUArray[uint16, IndexBuffer] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
17 InstanceA = object |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
18 rotation: GPUArray[Vec4f, VertexBuffer] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
19 objPosition: GPUArray[Vec3f, VertexBuffer] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
20 MaterialA = object |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
21 reflection: float32 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
22 baseColor: Vec3f |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
23 UniformsA = object |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
24 defaultTexture: Texture[TVec4[uint8]] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
25 defaultMaterial: GPUValue[MaterialA, UniformBuffer] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
26 materials: GPUValue[array[3, MaterialA], UniformBuffer] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
27 materialTextures: array[3, Texture[TVec4[uint8]]] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
28 ShaderSettings = object |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
29 gamma: float32 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
30 GlobalsA = object |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
31 fontAtlas: Texture[TVec4[uint8]] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
32 settings: GPUValue[ShaderSettings, UniformBuffer] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
33 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
34 ShaderA = object |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
35 # vertex input |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
36 position {.VertexAttribute.}: Vec3f |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
37 objPosition {.InstanceAttribute.}: Vec3f |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
38 rotation {.InstanceAttribute.}: Vec4f |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
39 # intermediate |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
40 test {.Pass.}: float32 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
41 test1 {.PassFlat.}: Vec3f |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
42 # output |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
43 color {.ShaderOutput.}: Vec4f |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
44 # descriptor sets |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
45 globals: DescriptorSet[GlobalsA, GlobalSet] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
46 uniforms: DescriptorSet[UniformsA, MaterialSet] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
47 # code |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
48 vertexCode: string = "void main() {}" |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
49 fragmentCode: string = "void main() {}" |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
50 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
51 let w = CreateWindow("test2") |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
52 putEnv("VK_LAYER_ENABLES", "VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_AMD,VALIDATION_CHECK_ENABLE_VENDOR_SPECIFIC_NVIDIA,VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXTVK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT,VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT") |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
53 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
54 # TODO: remove those ugly wrappers |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
55 let theInstance = w.CreateInstance( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
56 vulkanVersion = VK_MAKE_API_VERSION(0, 1, 3, 0), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
57 instanceExtensions = @[], |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
58 layers = @["VK_LAYER_KHRONOS_validation"], |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
59 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
60 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
61 let dev = theInstance.CreateDevice( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
62 theInstance.GetPhysicalDevices().FilterBestGraphics(), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
63 enabledExtensions = @[], |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
64 theInstance.GetPhysicalDevices().FilterBestGraphics().FilterForGraphicsPresentationQueues() |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
65 ).vk |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
66 let frameWidth = 100'u32 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
67 let frameHeight = 100'u32 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
68 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
69 # TODO: pack this stuff into a setup method and condense everything a bit |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
70 let pDevice = theInstance.vk.GetPhysicalDevice() |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
71 let qfi = pDevice.GetQueueFamily(VK_QUEUE_GRAPHICS_BIT) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
72 vulkan = VulkanGlobals( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
73 instance: theInstance.vk, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
74 device: dev, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
75 physicalDevice: pDevice, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
76 queueFamilyIndex: qfi, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
77 queue: svkGetDeviceQueue(dev, qfi, VK_QUEUE_GRAPHICS_BIT) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
78 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
79 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
80 var myMesh1 = MeshA( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
81 position: GPUArray[Vec3f, VertexBuffer](data: @[NewVec3f(0, 0, ), NewVec3f(0, 0, ), NewVec3f(0, 0, )]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
82 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
83 var uniforms1 = DescriptorSet[UniformsA, MaterialSet]( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
84 data: UniformsA( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
85 defaultTexture: Texture[TVec4[uint8]](width: 1, height: 1, data: @[TVec4[uint8]([0'u8, 0'u8, 0'u8, 1'u8])]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
86 materials: GPUValue[array[3, MaterialA], UniformBuffer](data: [ |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
87 MaterialA(reflection: 0, baseColor: NewVec3f(1, 0, 0)), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
88 MaterialA(reflection: 0.1, baseColor: NewVec3f(0, 1, 0)), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
89 MaterialA(reflection: 0.5, baseColor: NewVec3f(0, 0, 1)), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
90 ]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
91 materialTextures: [ |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
92 Texture[TVec4[uint8]](width: 1, height: 1, data: @[TVec4[uint8]([0'u8, 0'u8, 0'u8, 1'u8])]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
93 Texture[TVec4[uint8]](width: 1, height: 1, data: @[TVec4[uint8]([0'u8, 0'u8, 0'u8, 1'u8])]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
94 Texture[TVec4[uint8]](width: 1, height: 1, data: @[TVec4[uint8]([0'u8, 0'u8, 0'u8, 1'u8])]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
95 ] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
96 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
97 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
98 var instances1 = InstanceA( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
99 rotation: GPUArray[Vec4f, VertexBuffer](data: @[NewVec4f(1, 0, 0, 0.1), NewVec4f(0, 1, 0, 0.1)]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
100 objPosition: GPUArray[Vec3f, VertexBuffer](data: @[NewVec3f(0, 0, 0), NewVec3f(1, 1, 1)]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
101 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
102 var myGlobals = DescriptorSet[GlobalsA, GlobalSet]( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
103 data: GlobalsA( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
104 fontAtlas: Texture[TVec4[uint8]](width: 1, height: 1, data: @[TVec4[uint8]([0'u8, 0'u8, 0'u8, 1'u8])]), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
105 settings: GPUValue[ShaderSettings, UniformBuffer](data: ShaderSettings(gamma: 1.0)) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
106 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
107 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
108 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
109 # setup for rendering (TODO: swapchain & framebuffers) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
110 let renderpass = CreateRenderPass(GetSurfaceFormat()) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
111 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
112 # shaders |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
113 const shader = ShaderA() |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
114 let shaderObject = CompileShader(shader) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
115 var pipeline1 = CreatePipeline(renderPass = renderpass, shader = shaderObject) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
116 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
117 var renderdata = InitRenderData() |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
118 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
119 # buffer assignment |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
120 echo "Assigning buffers to GPUData fields" |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
121 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
122 AssignBuffers(renderdata, myMesh1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
123 AssignBuffers(renderdata, instances1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
124 AssignBuffers(renderdata, myGlobals) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
125 AssignBuffers(renderdata, uniforms1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
126 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
127 renderdata.UploadTextures(myGlobals) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
128 renderdata.UploadTextures(uniforms1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
129 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
130 # copy everything to GPU |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
131 echo "Copying all data to GPU memory" |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
132 UpdateAllGPUBuffers(myMesh1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
133 UpdateAllGPUBuffers(instances1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
134 UpdateAllGPUBuffers(uniforms1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
135 UpdateAllGPUBuffers(myGlobals) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
136 renderdata.FlushAllMemory() |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
137 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
138 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
139 # descriptors |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
140 echo "Writing descriptors" |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
141 InitDescriptorSet(renderdata, pipeline1.descriptorSetLayouts[GlobalSet], myGlobals) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
142 InitDescriptorSet(renderdata, pipeline1.descriptorSetLayouts[MaterialSet], uniforms1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
143 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
144 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
145 # command buffer |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
146 var |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
147 commandBufferPool: VkCommandPool |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
148 createInfo = VkCommandPoolCreateInfo( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
149 sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
150 flags: toBits [VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT], |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
151 queueFamilyIndex: vulkan.queueFamilyIndex, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
152 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
153 checkVkResult vkCreateCommandPool(vulkan.device, addr createInfo, nil, addr commandBufferPool) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
154 var |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
155 cmdBuffers: array[INFLIGHTFRAMES.int, VkCommandBuffer] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
156 allocInfo = VkCommandBufferAllocateInfo( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
157 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
158 commandPool: commandBufferPool, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
159 level: VK_COMMAND_BUFFER_LEVEL_PRIMARY, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
160 commandBufferCount: INFLIGHTFRAMES, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
161 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
162 checkVkResult vkAllocateCommandBuffers(vulkan.device, addr allocInfo, cmdBuffers.ToCPointer) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
163 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
164 # start command buffer |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
165 block: |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
166 let |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
167 currentFramebuffer = VkFramebuffer(0) # TODO |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
168 currentFrameInFlight = 1 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
169 cmd = cmdBuffers[currentFrameInFlight] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
170 beginInfo = VkCommandBufferBeginInfo( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
171 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
172 flags: VkCommandBufferUsageFlags(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
173 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
174 checkVkResult cmd.vkResetCommandBuffer(VkCommandBufferResetFlags(0)) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
175 checkVkResult cmd.vkBeginCommandBuffer(addr(beginInfo)) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
176 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
177 # start renderpass |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
178 block: |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
179 var |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
180 clearColors = [VkClearValue(color: VkClearColorValue(float32: [0, 0, 0, 0]))] |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
181 renderPassInfo = VkRenderPassBeginInfo( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
182 sType: VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
183 renderPass: renderpass, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
184 framebuffer: currentFramebuffer, # TODO |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
185 renderArea: VkRect2D( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
186 offset: VkOffset2D(x: 0, y: 0), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
187 extent: VkExtent2D(width: frameWidth, height: frameHeight), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
188 ), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
189 clearValueCount: uint32(clearColors.len), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
190 pClearValues: clearColors.ToCPointer(), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
191 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
192 viewport = VkViewport( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
193 x: 0.0, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
194 y: 0.0, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
195 width: frameWidth.float32, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
196 height: frameHeight.float32, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
197 minDepth: 0.0, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
198 maxDepth: 1.0, |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
199 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
200 scissor = VkRect2D( |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
201 offset: VkOffset2D(x: 0, y: 0), |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
202 extent: VkExtent2D(width: frameWidth, height: frameHeight) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
203 ) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
204 vkCmdBeginRenderPass(cmd, addr(renderPassInfo), VK_SUBPASS_CONTENTS_INLINE) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
205 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
206 # setup viewport |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
207 vkCmdSetViewport(cmd, firstViewport = 0, viewportCount = 1, addr(viewport)) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
208 vkCmdSetScissor(cmd, firstScissor = 0, scissorCount = 1, addr(scissor)) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
209 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
210 # bind pipeline, will be loop |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
211 block: |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
212 Bind(pipeline1, cmd, currentFrameInFlight = currentFrameInFlight) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
213 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
214 # render object, will be loop |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
215 block: |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
216 Render(cmd, pipeline1, myGlobals, uniforms1, myMesh1, instances1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
217 |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
218 vkCmdEndRenderPass(cmd) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff
changeset
|
219 checkVkResult cmd.vkEndCommandBuffer() |