Mercurial > games > semicongine
comparison test1.nim @ 1198:96a094cd0c78 compiletime-tests
sync to notebook in bedroom
author | sam <sam@basx.dev> |
---|---|
date | Sat, 13 Jul 2024 19:26:03 +0700 |
parents | f6a0dc7ad052 |
children | ba1af13233ee |
comparison
equal
deleted
inserted
replaced
1197:f6a0dc7ad052 | 1198:96a094cd0c78 |
---|---|
39 uniforms: DescriptorSet[UniformsA, MaterialSet] | 39 uniforms: DescriptorSet[UniformsA, MaterialSet] |
40 # code | 40 # code |
41 vertexCode: string = "void main() {}" | 41 vertexCode: string = "void main() {}" |
42 fragmentCode: string = "void main() {}" | 42 fragmentCode: string = "void main() {}" |
43 | 43 |
44 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") | |
45 | |
46 let frameWidth = 100'u32 | 44 let frameWidth = 100'u32 |
47 let frameHeight = 100'u32 | 45 let frameHeight = 100'u32 |
48 | 46 |
49 var myMesh1 = MeshA( | 47 var myMesh1 = MeshA( |
50 position: GPUArray[Vec3f, VertexBuffer](data: @[NewVec3f(0, 0, ), NewVec3f(0, 0, ), NewVec3f(0, 0, )]), | 48 position: GPUArray[Vec3f, VertexBuffer](data: @[NewVec3f(0, 0, ), NewVec3f(0, 0, ), NewVec3f(0, 0, )]), |
74 settings: GPUValue[ShaderSettings, UniformBuffer](data: ShaderSettings(gamma: 1.0)) | 72 settings: GPUValue[ShaderSettings, UniformBuffer](data: ShaderSettings(gamma: 1.0)) |
75 ) | 73 ) |
76 ) | 74 ) |
77 | 75 |
78 let renderpass = CreatePresentationRenderPass() | 76 let renderpass = CreatePresentationRenderPass() |
79 var swapchainResult = InitSwapchain(renderpass) | 77 var swapchainResult = InitSwapchain(renderpass = renderpass) |
80 assert swapchainResult.isSome() | 78 assert swapchainResult.isSome() |
81 var swapchain = swapchainResult.get() | 79 var swapchain = swapchainResult.get() |
82 | 80 |
83 # shaders | 81 # shaders |
84 var pipeline1 = CreatePipeline[ShaderA](renderPass = renderpass) | 82 var pipeline1 = CreatePipeline[ShaderA](renderPass = renderpass) |
102 UpdateAllGPUBuffers(instances1) | 100 UpdateAllGPUBuffers(instances1) |
103 UpdateAllGPUBuffers(uniforms1) | 101 UpdateAllGPUBuffers(uniforms1) |
104 UpdateAllGPUBuffers(myGlobals) | 102 UpdateAllGPUBuffers(myGlobals) |
105 renderdata.FlushAllMemory() | 103 renderdata.FlushAllMemory() |
106 | 104 |
107 | |
108 # descriptors | 105 # descriptors |
109 echo "Writing descriptors" | 106 echo "Writing descriptors" |
110 InitDescriptorSet(renderdata, pipeline1.GetLayoutFor(GlobalSet), myGlobals) | 107 InitDescriptorSet(renderdata, pipeline1.GetLayoutFor(GlobalSet), myGlobals) |
111 InitDescriptorSet(renderdata, pipeline1.GetLayoutFor(MaterialSet), uniforms1) | 108 InitDescriptorSet(renderdata, pipeline1.GetLayoutFor(MaterialSet), uniforms1) |
112 | 109 |
113 | 110 |
114 | |
115 | |
116 | |
117 | |
118 # command buffer | |
119 var | |
120 commandBufferPool: VkCommandPool | |
121 createInfo = VkCommandPoolCreateInfo( | |
122 sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, | |
123 flags: toBits [VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT], | |
124 queueFamilyIndex: vulkan.graphicsQueueFamily, | |
125 ) | |
126 checkVkResult vkCreateCommandPool(vulkan.device, addr createInfo, nil, addr commandBufferPool) | |
127 var | |
128 cmdBuffers: array[INFLIGHTFRAMES.int, VkCommandBuffer] | |
129 allocInfo = VkCommandBufferAllocateInfo( | |
130 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, | |
131 commandPool: commandBufferPool, | |
132 level: VK_COMMAND_BUFFER_LEVEL_PRIMARY, | |
133 commandBufferCount: INFLIGHTFRAMES, | |
134 ) | |
135 checkVkResult vkAllocateCommandBuffers(vulkan.device, addr allocInfo, cmdBuffers.ToCPointer) | |
136 | |
137 | |
138 | |
139 # start command buffer | 111 # start command buffer |
140 block: | 112 while true: |
141 let | 113 RecordRenderingCommands(swapchain, framebuffer, commandbuffer): |
142 currentFramebuffer = VkFramebuffer(0) # TODO | |
143 currentFrameInFlight = 1 | |
144 cmd = cmdBuffers[currentFrameInFlight] | |
145 beginInfo = VkCommandBufferBeginInfo( | |
146 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, | |
147 flags: VkCommandBufferUsageFlags(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT), | |
148 ) | |
149 checkVkResult cmd.vkResetCommandBuffer(VkCommandBufferResetFlags(0)) | |
150 checkVkResult cmd.vkBeginCommandBuffer(addr(beginInfo)) | |
151 | |
152 # start renderpass | |
153 block: | |
154 var | 114 var |
155 clearColors = [VkClearValue(color: VkClearColorValue(float32: [0, 0, 0, 0]))] | 115 clearColors = [VkClearValue(color: VkClearColorValue(float32: [0, 0, 0, 0]))] |
156 renderPassInfo = VkRenderPassBeginInfo( | 116 renderPassInfo = VkRenderPassBeginInfo( |
157 sType: VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, | 117 sType: VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, |
158 renderPass: renderpass, | 118 renderPass: renderpass, |
159 framebuffer: currentFramebuffer, # TODO | 119 framebuffer: framebuffer, |
160 renderArea: VkRect2D( | 120 renderArea: VkRect2D( |
161 offset: VkOffset2D(x: 0, y: 0), | 121 offset: VkOffset2D(x: 0, y: 0), |
162 extent: VkExtent2D(width: frameWidth, height: frameHeight), | 122 extent: VkExtent2D(width: frameWidth, height: frameHeight), |
163 ), | 123 ), |
164 clearValueCount: uint32(clearColors.len), | 124 clearValueCount: uint32(clearColors.len), |
174 ) | 134 ) |
175 scissor = VkRect2D( | 135 scissor = VkRect2D( |
176 offset: VkOffset2D(x: 0, y: 0), | 136 offset: VkOffset2D(x: 0, y: 0), |
177 extent: VkExtent2D(width: frameWidth, height: frameHeight) | 137 extent: VkExtent2D(width: frameWidth, height: frameHeight) |
178 ) | 138 ) |
179 vkCmdBeginRenderPass(cmd, addr(renderPassInfo), VK_SUBPASS_CONTENTS_INLINE) | 139 vkCmdBeginRenderPass(commandbuffer, addr(renderPassInfo), VK_SUBPASS_CONTENTS_INLINE) |
180 | 140 |
181 # setup viewport | 141 # setup viewport |
182 vkCmdSetViewport(cmd, firstViewport = 0, viewportCount = 1, addr(viewport)) | 142 vkCmdSetViewport(commandbuffer, firstViewport = 0, viewportCount = 1, addr(viewport)) |
183 vkCmdSetScissor(cmd, firstScissor = 0, scissorCount = 1, addr(scissor)) | 143 vkCmdSetScissor(commandbuffer, firstScissor = 0, scissorCount = 1, addr(scissor)) |
184 | 144 |
185 # bind pipeline, will be loop | 145 # bind pipeline, will be loop |
186 # block: | 146 # block: |
187 # Bind(pipeline1, cmd, currentFrameInFlight = currentFrameInFlight) | 147 # Bind(pipeline1, commandbuffer, currentFrameInFlight = currentFrameInFlight) |
188 | 148 |
189 # render object, will be loop | 149 # render object, will be loop |
190 # block: | 150 # block: |
191 # Render(cmd, pipeline1, myGlobals, uniforms1, myMesh1, instances1) | 151 # Render(commandbuffer, pipeline1, myGlobals, uniforms1, myMesh1, instances1) |
192 | 152 |
193 vkCmdEndRenderPass(cmd) | 153 vkCmdEndRenderPass(commandbuffer) |
194 checkVkResult cmd.vkEndCommandBuffer() |