From 133790c4476289bd77240c6c785a585ec057c847 Mon Sep 17 00:00:00 2001 From: Daniel Krupka Date: Tue, 15 Nov 2016 16:02:52 -0500 Subject: [PATCH 1/2] commit --- data/shaders/computeparticles/particle.comp | 33 +++++++++++++++++ .../computeparticles/particle.comp.spv | Bin 3132 -> 5760 bytes vulkanBoids/vulkanBoids.cpp | 34 +++++++++++++++--- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/data/shaders/computeparticles/particle.comp b/data/shaders/computeparticles/particle.comp index b7dc2f7..4f97312 100644 --- a/data/shaders/computeparticles/particle.comp +++ b/data/shaders/computeparticles/particle.comp @@ -58,6 +58,39 @@ void main() vec2 vPos = particlesA[index].pos.xy; vec2 vVel = particlesA[index].vel.xy; + vec2 ctr, v1, v2, v3; + float k1=0.0, k2=0.0, k3=0.0; + for (int i = 0; i < ubo.particleCount; i++) { + if (i == index) + continue; + + float dist = length(particlesA[i].pos.xy - vPos); + + if (dist < ubo.rule1Distance) { + ctr += particlesA[i].pos.xy; + k1++; + } + + if (dist < ubo.rule2Distance) { + v2 += vPos - particlesA[i].pos.xy; + k2++; + } + + if (dist < ubo.rule3Distance) { + v3 += particlesA[i].vel.xy; + k3++; + } + } + + vec2 dVel; + if (k1 > 0) + dVel += ubo.rule1Scale * (ctr/k1 - vPos); + if (k2 > 0) + dVel += ubo.rule2Scale * v2; + if (k3 > 0) + dVel += ubo.rule3Scale * (v3/k3 - vVel); + vVel += dVel; + // clamp velocity for a more pleasing simulation. vVel = normalize(vVel) * clamp(length(vVel), 0.0, 0.1); diff --git a/data/shaders/computeparticles/particle.comp.spv b/data/shaders/computeparticles/particle.comp.spv index 059ab599d41ce7153cc2508dcfae81d358f32589..a0cc2cf619bee1f356334496c4aa5dceb6f71967 100644 GIT binary patch literal 5760 zcmZ{niFaL96~=GL&>|JA1&RY*udUijp|t5>u@p!s#zK{r0(B(3CeIN1NNVyDtD+Xs zf(keS&I8VCYx(=VcfWd@rKfAJ{q1k>v(Mi9ocr2#9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590,6 +612,8 @@ class VulkanExample : public VulkanExampleBase // We also want to flip what SSBO we draw with in the next // pass through the graphics pipeline. // Feel free to use std::swap here. You should need it twice. + std::swap(compute.descriptorSets[0], compute.descriptorSets[1]); + std::swap(compute.storageBufferA, compute.storageBufferB); } // Record command buffers for drawing using the graphics pipeline @@ -671,7 +695,7 @@ class VulkanExample : public VulkanExampleBase bufferBarrier.size = compute.storageBufferA.descriptor.range; bufferBarrier.srcAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; // Vertex shader invocations have finished reading from the buffer bufferBarrier.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT; // Compute shader wants to write to the buffer - + // Compute and graphics queue may have different queue families (see VulkanDevice::createLogicalDevice) // For the barrier to work across different queues, we need to set their family indices bufferBarrier.srcQueueFamilyIndex = vulkanDevice->queueFamilyIndices.graphics; // Required as compute and graphics queue may have different families From 870b4280bb441ab392c8b5b9a61701f2fff856c1 Mon Sep 17 00:00:00 2001 From: Daniel Krupka Date: Tue, 15 Nov 2016 20:42:02 -0800 Subject: [PATCH 2/2] readme --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bec6ca4..3cfb144 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,18 @@ Vulkan Flocking: compute and shading in one pipeline! **University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 6** -* (TODO) YOUR NAME HERE - Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab) +* Daniel Krupka + Debian testing (stretch), Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz 8GB, GTX 850M - ### (TODO: Your README) - - Include screenshots, analysis, etc. (Remember, this is public, so don't put - anything here that you don't want to share with the world.) +* Questions: +** Vulkan requires explicit descriptors for most things as, like memory, pipelines and commands and the like +are pre-allocated or pre-registered in order to guarantee that on-the-fly resource allocation/validation/controls +do not occur and cause unexpected latencies. +** Instancing, e.g. changing textures and parameters without changing shaders. +** Resources must be properly fenced to ensure that they are not invalidly in flight (e.g. being overwritten while being +used) in multiple contexts (e.g. different GPUs, different command queues). +** The largest benefit is more efficient visualization of compute results, e.g. displaying path tracer results without +much copying framebuffers from CUDA to GL. ### Credits