From aeca59d9abe91adfeb0fa052976b7b65af60055f Mon Sep 17 00:00:00 2001 From: ahbejarano Date: Sat, 9 Dec 2023 08:22:31 +0100 Subject: [PATCH] Second batch of changes to solve #76 --- bookcontents/chapter-14/chapter-14.md | 125 ++++-------------- bookcontents/chapter-16/chapter-16.md | 6 +- .../resources/shaders/animations_comp.glsl | 42 +++--- .../shaders/animations_comp.glsl.spv | Bin 9476 -> 9408 bytes .../org/vulkanb/eng/graph/VulkanModel.java | 2 +- .../animation/AnimationComputeActivity.java | 16 +-- .../animation/AnimationSpecConstants.java | 42 ------ .../resources/shaders/animations_comp.glsl | 42 +++--- .../shaders/animations_comp.glsl.spv | Bin 9476 -> 9416 bytes .../animation/AnimationComputeActivity.java | 16 +-- .../animation/AnimationSpecConstants.java | 42 ------ 11 files changed, 76 insertions(+), 257 deletions(-) delete mode 100644 booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/animation/AnimationSpecConstants.java delete mode 100644 booksamples/chapter-15/src/main/java/org/vulkanb/eng/graph/animation/AnimationSpecConstants.java diff --git a/bookcontents/chapter-14/chapter-14.md b/bookcontents/chapter-14/chapter-14.md index 3431c6f5..52e12631 100644 --- a/bookcontents/chapter-14/chapter-14.md +++ b/bookcontents/chapter-14/chapter-14.md @@ -823,7 +823,6 @@ public class AnimationComputeActivity { // Key is the model id private final Map modelDescriptorSetsMap; private final Scene scene; - private final AnimationSpecConstants animationSpecConstants; private CommandBuffer commandBuffer; private ComputePipeline computePipeline; @@ -832,13 +831,11 @@ public class AnimationComputeActivity { private Fence fence; private ShaderProgram shaderProgram; private DescriptorSetLayout.StorageDescriptorSetLayout storageDescriptorSetLayout; - private DescriptorSetLayout.UniformDescriptorSetLayout uniformDescriptorSetLayout; public AnimationComputeActivity(CommandPool commandPool, PipelineCache pipelineCache, Scene scene) { this.scene = scene; device = pipelineCache.getDevice(); computeQueue = new Queue.ComputeQueue(device, 0); - animationSpecConstants = new AnimationSpecConstants(); createDescriptorPool(); createDescriptorSets(); createShaders(); @@ -852,65 +849,16 @@ public class AnimationComputeActivity { } ``` -We create an instance of `AnimationSpecConstants` which will be used to set specialization constants. Specifically, it will hold the maximum number of joint matrices lists which will be used in the compute shader. It is defined liked this: - -```java -package org.vulkanb.eng.graph.animation; - -import org.lwjgl.system.MemoryUtil; -import org.lwjgl.vulkan.*; -import org.vulkanb.eng.EngineProperties; -import org.vulkanb.eng.graph.vk.GraphConstants; - -import java.nio.ByteBuffer; - -public class AnimationSpecConstants { - - private final ByteBuffer data; - private final VkSpecializationMapEntry.Buffer specEntryMap; - private final VkSpecializationInfo specInfo; - - public AnimationSpecConstants() { - EngineProperties engineProperties = EngineProperties.getInstance(); - data = MemoryUtil.memAlloc(GraphConstants.INT_LENGTH); - data.putInt(engineProperties.getMaxJointsMatricesLists()); - data.flip(); - - specEntryMap = VkSpecializationMapEntry.calloc(1); - specEntryMap.get(0) - .constantID(0) - .size(GraphConstants.INT_LENGTH) - .offset(0); - - specInfo = VkSpecializationInfo.calloc(); - specInfo.pData(data) - .pMapEntries(specEntryMap); - } - - public void cleanup() { - MemoryUtil.memFree(specEntryMap); - specInfo.free(); - MemoryUtil.memFree(data); - } - - public VkSpecializationInfo getSpecInfo() { - return specInfo; - } -} -``` - -Back to the `AnimationComputeActivity` class, in the `cleanup` method, as usual, we just free the resources: +In the `cleanup` method, as usual, we just free the resources: ```java public class AnimationComputeActivity { ... public void cleanup() { computePipeline.cleanup(); - animationSpecConstants.cleanup(); shaderProgram.cleanup(); commandBuffer.cleanup(); descriptorPool.cleanup(); storageDescriptorSetLayout.cleanup(); - uniformDescriptorSetLayout.cleanup(); fence.cleanup(); for (Map.Entry> entry : entityAnimationsBuffers.entrySet()) { entry.getValue().forEach(EntityAnimationBuffer::cleanup); @@ -935,19 +883,17 @@ public class AnimationComputeActivity { int maxStorageBuffers = engineProperties.getMaxStorageBuffers(); int maxJointsMatricesLists = engineProperties.getMaxJointsMatricesLists(); List descriptorTypeCounts = new ArrayList<>(); - descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxStorageBuffers, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)); - descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxJointsMatricesLists, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)); + descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxStorageBuffers + maxJointsMatricesLists, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)); descriptorPool = new DescriptorPool(device, descriptorTypeCounts); } private void createDescriptorSets() { storageDescriptorSetLayout = new DescriptorSetLayout.StorageDescriptorSetLayout(device, 0, VK_SHADER_STAGE_COMPUTE_BIT); - uniformDescriptorSetLayout = new DescriptorSetLayout.UniformDescriptorSetLayout(device, 0, VK_SHADER_STAGE_COMPUTE_BIT); descriptorSetLayouts = new DescriptorSetLayout[]{ storageDescriptorSetLayout, storageDescriptorSetLayout, storageDescriptorSetLayout, - uniformDescriptorSetLayout, + storageDescriptorSetLayout, }; } @@ -1148,8 +1094,6 @@ The next step is to write the compute shader which performs the calculations. Th ```glsl #version 450 -layout (constant_id = 0) const int MAX_JOINTS = 150; - layout (std430, set=0, binding=0) readonly buffer srcBuf { float data[]; } srcVector; @@ -1162,15 +1106,15 @@ layout (std430, set=2, binding=0) buffer dstBuf { float data[]; } dstVector; -layout (local_size_x=1, local_size_y=1, local_size_z=1) in; +layout (std430, set=3, binding=0) readonly buffer jointBuf { + mat4 data[]; +} jointMatrices; -layout(set = 3, binding = 0) uniform JointMatricesUniform { - mat4 jointMatrices[MAX_JOINTS]; -} jointMatricesUniform; +layout (local_size_x=32, local_size_y=1, local_size_z=1) in; ... ``` -The `srcVector` is the storage buffer that contains binding pose data (positions, texture coordinates, normals, bitangents and tangents). It is a readonly buffer since we will not writing to it. The `weightsVector` is also a readonly buffer that contains the weights associated to each vertex. The `dstVector` is the storage buffer that will hold our results, it will contain the positions, texture coordinates, normals, bitangents and tangents transformed according to the animation. Finally, the `jointMatricesUniform`, holds the list of transformation matrices applicable to each joint for a specific frame. Going back to the shaders, the `main` method starts like this: +The `srcVector` is the storage buffer that contains binding pose data (positions, texture coordinates, normals, bitangents and tangents). It is a readonly buffer since we will not writing to it. The `weightsVector` is also a readonly buffer that contains the weights associated to each vertex. The `dstVector` is the storage buffer that will hold our results, it will contain the positions, texture coordinates, normals, bitangents and tangents transformed according to the animation. Finally, the `jointMatrices` storage buffer, holds the list of transformation matrices applicable to each joint for a specific frame. Going back to the shaders, the `main` method starts like this: ```glsl void main() { @@ -1189,38 +1133,21 @@ Now we will examine how the vertex positions are transformed: void main() { ... - int baseIdxSrcBuf = int(gl_GlobalInvocationID.x) * 14; + int baseIdxSrcBuf = int(gl_GlobalInvocationID.x) * 14; vec4 position = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 1); position = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * position + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * position + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * position + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * position; + weights.x * jointMatrices.data[joints.x] * position + + weights.y * jointMatrices.data[joints.y] * position + + weights.z * jointMatrices.data[joints.z] * position + + weights.w * jointMatrices.data[joints.w] * position; dstVector.data[baseIdxSrcBuf] = position.x / position.w; dstVector.data[baseIdxSrcBuf + 1] = position.y / position.w; dstVector.data[baseIdxSrcBuf + 2] = position.z / position.w; - ... + ... } ``` After that, we get the vertex positions form the storage buffer that contains the vertex data for the bind position. That buffer can be split into slices of 14 floats: 3 floats for vertex positions, 3 for normal coordinates, 3 for tangent coordinates, 3 for bitangent coordinates and 2 for texture coordinates. Once we get the vertex position, we modify those coordinates by applying a modulation factor which is derived from multiplying the weight factor by the joint transformation matrix of the associated matrix. -```glsl -void main() -{ - ... - int baseIdxSrcBuf = int(gl_GlobalInvocationID.x) * 14; - vec4 position = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 1); - position = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * position + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * position + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * position + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * position; - dstVector.data[baseIdxSrcBuf] = position.x / position.w; - dstVector.data[baseIdxSrcBuf + 1] = position.y / position.w; - dstVector.data[baseIdxSrcBuf + 2] = position.z / position.w; - ... -} -``` The same process is applied to the normal, tangent and bitangent. ```glsl @@ -1230,10 +1157,10 @@ void main() baseIdxSrcBuf += 3; vec4 normal = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); normal = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * normal + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * normal + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * normal + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * normal; + weights.x * jointMatrices.data[joints.x] * normal + + weights.y * jointMatrices.data[joints.y] * normal + + weights.z * jointMatrices.data[joints.z] * normal + + weights.w * jointMatrices.data[joints.w] * normal; dstVector.data[baseIdxSrcBuf] = normal.x / normal.w; dstVector.data[baseIdxSrcBuf + 1] = normal.y / normal.w; dstVector.data[baseIdxSrcBuf + 2] = normal.z / normal.w; @@ -1241,10 +1168,10 @@ void main() baseIdxSrcBuf += 3; vec4 tangent = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); tangent = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * tangent + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * tangent + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * tangent + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * tangent; + weights.x * jointMatrices.data[joints.x] * tangent + + weights.y * jointMatrices.data[joints.y] * tangent + + weights.z * jointMatrices.data[joints.z] * tangent + + weights.w * jointMatrices.data[joints.w] * tangent; dstVector.data[baseIdxSrcBuf] = tangent.x / tangent.w; dstVector.data[baseIdxSrcBuf + 1] = tangent.y / tangent.w; dstVector.data[baseIdxSrcBuf + 2] = tangent.z / tangent.w; @@ -1252,10 +1179,10 @@ void main() baseIdxSrcBuf += 3; vec4 bitangent = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); bitangent = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * bitangent + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * bitangent + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * bitangent + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * bitangent; + weights.x * jointMatrices.data[joints.x] * bitangent + + weights.y * jointMatrices.data[joints.y] * bitangent + + weights.z * jointMatrices.data[joints.z] * bitangent + + weights.w * jointMatrices.data[joints.w] * bitangent; dstVector.data[baseIdxSrcBuf] = bitangent.x / bitangent.w; dstVector.data[baseIdxSrcBuf + 1] = bitangent.y / bitangent.w; dstVector.data[baseIdxSrcBuf + 2] = bitangent.z / bitangent.w; diff --git a/bookcontents/chapter-16/chapter-16.md b/bookcontents/chapter-16/chapter-16.md index 315a8d76..d9e7e80a 100644 --- a/bookcontents/chapter-16/chapter-16.md +++ b/bookcontents/chapter-16/chapter-16.md @@ -1905,7 +1905,7 @@ public class AnimationComputeActivity { ... } ``` -Instead of having multiple descriptor sets and buffers per model, we will have all that data in combined storage buffers. Therefore, we need to create the new descriptor sets for them, as storage descriptor sets. We will not need also specialization constants since everything will by handled by storage buffers (no more uniforms). Those descriptor sets are created when the animated entities are loaded. This will be done in the `onAnimatedEntitiesLoaded` which will be called from the `Render` instance. +Instead of having multiple descriptor sets and buffers per model, we will have all that data in combined storage buffers. Therefore, we need to create the new descriptor sets for them, as storage descriptor sets. Those descriptor sets are created when the animated entities are loaded. This will be done in the `onAnimatedEntitiesLoaded` which will be called from the `Render` instance. ```java public class AnimationComputeActivity { ... @@ -1983,10 +1983,6 @@ public class AnimationComputeActivity { In order to access the proper offset in the global buffers, we pass all that information through a push constant structure. This is used in the compute shader which calculates the animations and dumps the results into a buffer. ```glsl ... -layout (std430, set=3, binding=0) readonly buffer jointBuf { - mat4 data[]; -} jointMatrices; -... layout(push_constant) uniform pushConstants { uint srcOffset; uint srcSize; diff --git a/booksamples/chapter-14/resources/shaders/animations_comp.glsl b/booksamples/chapter-14/resources/shaders/animations_comp.glsl index 20a9550b..1385cd15 100644 --- a/booksamples/chapter-14/resources/shaders/animations_comp.glsl +++ b/booksamples/chapter-14/resources/shaders/animations_comp.glsl @@ -1,7 +1,5 @@ #version 450 -layout (constant_id = 0) const int MAX_JOINTS = 150; - layout (std430, set=0, binding=0) readonly buffer srcBuf { float data[]; } srcVector; @@ -14,11 +12,11 @@ layout (std430, set=2, binding=0) buffer dstBuf { float data[]; } dstVector; -layout (local_size_x=32, local_size_y=1, local_size_z=1) in; +layout (std430, set=3, binding=0) readonly buffer jointBuf { + mat4 data[]; +} jointMatrices; -layout(set = 3, binding = 0) uniform JointMatricesUniform { - mat4 jointMatrices[MAX_JOINTS]; -} jointMatricesUniform; +layout (local_size_x=32, local_size_y=1, local_size_z=1) in; void main() { @@ -29,10 +27,10 @@ void main() int baseIdxSrcBuf = int(gl_GlobalInvocationID.x) * 14; vec4 position = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 1); position = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * position + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * position + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * position + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * position; + weights.x * jointMatrices.data[joints.x] * position + + weights.y * jointMatrices.data[joints.y] * position + + weights.z * jointMatrices.data[joints.z] * position + + weights.w * jointMatrices.data[joints.w] * position; dstVector.data[baseIdxSrcBuf] = position.x / position.w; dstVector.data[baseIdxSrcBuf + 1] = position.y / position.w; dstVector.data[baseIdxSrcBuf + 2] = position.z / position.w; @@ -40,10 +38,10 @@ void main() baseIdxSrcBuf += 3; vec4 normal = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); normal = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * normal + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * normal + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * normal + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * normal; + weights.x * jointMatrices.data[joints.x] * normal + + weights.y * jointMatrices.data[joints.y] * normal + + weights.z * jointMatrices.data[joints.z] * normal + + weights.w * jointMatrices.data[joints.w] * normal; dstVector.data[baseIdxSrcBuf] = normal.x / normal.w; dstVector.data[baseIdxSrcBuf + 1] = normal.y / normal.w; dstVector.data[baseIdxSrcBuf + 2] = normal.z / normal.w; @@ -51,10 +49,10 @@ void main() baseIdxSrcBuf += 3; vec4 tangent = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); tangent = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * tangent + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * tangent + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * tangent + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * tangent; + weights.x * jointMatrices.data[joints.x] * tangent + + weights.y * jointMatrices.data[joints.y] * tangent + + weights.z * jointMatrices.data[joints.z] * tangent + + weights.w * jointMatrices.data[joints.w] * tangent; dstVector.data[baseIdxSrcBuf] = tangent.x / tangent.w; dstVector.data[baseIdxSrcBuf + 1] = tangent.y / tangent.w; dstVector.data[baseIdxSrcBuf + 2] = tangent.z / tangent.w; @@ -62,10 +60,10 @@ void main() baseIdxSrcBuf += 3; vec4 bitangent = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); bitangent = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * bitangent + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * bitangent + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * bitangent + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * bitangent; + weights.x * jointMatrices.data[joints.x] * bitangent + + weights.y * jointMatrices.data[joints.y] * bitangent + + weights.z * jointMatrices.data[joints.z] * bitangent + + weights.w * jointMatrices.data[joints.w] * bitangent; dstVector.data[baseIdxSrcBuf] = bitangent.x / bitangent.w; dstVector.data[baseIdxSrcBuf + 1] = bitangent.y / bitangent.w; dstVector.data[baseIdxSrcBuf + 2] = bitangent.z / bitangent.w; diff --git a/booksamples/chapter-14/resources/shaders/animations_comp.glsl.spv b/booksamples/chapter-14/resources/shaders/animations_comp.glsl.spv index 4385353932ff906baf9778df999e8da556bd9c41..ed5010528dae52526a5d5a6b22824f73443800f7 100644 GIT binary patch literal 9408 zcmZ9R2Y8lM5{17&0ygY`1(Bj+K`e+38@7Ogps2B92oa(o!6YE|U{~xNd+&AK-gMpG zdv9*jE&gR){ZU%8(|y_O`x`747D&Q{;7YwRJ9ER3t02a332Ie&{<`&u2FSnt-1^?4_vy}M_CZ>**=p55Ki)z@3g zn}c81HovDWx|*u_@XNY;I}`(?W@B{%V{bjlzWV;w_HC+K@X0B9HdSZC4fL#)AJ`>1 ze{1Ist2*%q^5(Sm^>nngBXOYbUFP-ny}e$2e{1J9RcrKn`-;Ae)hlpa-91ZNDXjhm z_PMXMYjJy5AAVDH4F1B7Fy=H>_nXtcvhT3&?w&;mXl9;!v_3Wl)8B$|80J3DACf1{#Zt1)=GQ=xS{YTfy?=m@%;ws+=DUuX1zV})hVBP)4;AH z{&cWsEB*|yHR3metr7oNu;0#gAJ3R|d&c$cdm^J6sem^+6jIYN0p7!+~ zWPP4@ee2%M=o~rw>U-u>$2qTJ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ii+&K&pTN__d`Tvf{{*M2peeBP&Pz|NC*t-kZug7ZGvS3Pp( zM$dI%_2iwu9$&6}=hxt?u{`rP;LAtjjkTOo<4th#(Ref1dGgVC3pg6>twuR>qw!X7 zsqr>^x$>RA9bb)o#do{|Up^Y|1e;T8ybE7G8t(=>Pd*y&0Y{^~)hK6fG_D1g8t=uI zn}i8dkWv22DsFG8ecx^cm|wr<$UYPnU}iHg3C2Lhc8#2x##ii dRi3#Q@a5C%MR0mq!(MXcy;&K=|DPIE`9IFrG%NrB diff --git a/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/VulkanModel.java b/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/VulkanModel.java index c9d1e5a2..6fe93c2a 100644 --- a/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/VulkanModel.java +++ b/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/VulkanModel.java @@ -49,7 +49,7 @@ private static TransferBuffers createJointMatricesBuffers(Device device, ModelDa VulkanBuffer srcBuffer = new VulkanBuffer(device, bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); VulkanBuffer dstBuffer = new VulkanBuffer(device, bufferSize, - VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0); long mappedMemory = srcBuffer.map(); diff --git a/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/animation/AnimationComputeActivity.java b/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/animation/AnimationComputeActivity.java index 1e4cf019..5c5c3b1b 100644 --- a/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/animation/AnimationComputeActivity.java +++ b/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/animation/AnimationComputeActivity.java @@ -28,7 +28,6 @@ public class AnimationComputeActivity { // Key is the model id private final Map modelDescriptorSetsMap; private final Scene scene; - private final AnimationSpecConstants animationSpecConstants; private CommandBuffer commandBuffer; private ComputePipeline computePipeline; @@ -37,13 +36,11 @@ public class AnimationComputeActivity { private Fence fence; private ShaderProgram shaderProgram; private DescriptorSetLayout.StorageDescriptorSetLayout storageDescriptorSetLayout; - private DescriptorSetLayout.UniformDescriptorSetLayout uniformDescriptorSetLayout; public AnimationComputeActivity(CommandPool commandPool, PipelineCache pipelineCache, Scene scene) { this.scene = scene; device = pipelineCache.getDevice(); computeQueue = new Queue.ComputeQueue(device, 0); - animationSpecConstants = new AnimationSpecConstants(); createDescriptorPool(); createDescriptorSets(); createShaders(); @@ -56,12 +53,10 @@ public AnimationComputeActivity(CommandPool commandPool, PipelineCache pipelineC public void cleanup() { computePipeline.cleanup(); - animationSpecConstants.cleanup(); shaderProgram.cleanup(); commandBuffer.cleanup(); descriptorPool.cleanup(); storageDescriptorSetLayout.cleanup(); - uniformDescriptorSetLayout.cleanup(); fence.cleanup(); for (Map.Entry> entry : entityAnimationsBuffers.entrySet()) { entry.getValue().forEach(EntityAnimationBuffer::cleanup); @@ -79,19 +74,17 @@ private void createDescriptorPool() { int maxStorageBuffers = engineProperties.getMaxStorageBuffers(); int maxJointsMatricesLists = engineProperties.getMaxJointsMatricesLists(); List descriptorTypeCounts = new ArrayList<>(); - descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxStorageBuffers, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)); - descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxJointsMatricesLists, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)); + descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxStorageBuffers + maxJointsMatricesLists, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)); descriptorPool = new DescriptorPool(device, descriptorTypeCounts); } private void createDescriptorSets() { storageDescriptorSetLayout = new DescriptorSetLayout.StorageDescriptorSetLayout(device, 0, VK_SHADER_STAGE_COMPUTE_BIT); - uniformDescriptorSetLayout = new DescriptorSetLayout.UniformDescriptorSetLayout(device, 0, VK_SHADER_STAGE_COMPUTE_BIT); descriptorSetLayouts = new DescriptorSetLayout[]{ storageDescriptorSetLayout, storageDescriptorSetLayout, storageDescriptorSetLayout, - uniformDescriptorSetLayout, + storageDescriptorSetLayout, }; } @@ -108,8 +101,7 @@ private void createShaders() { } shaderProgram = new ShaderProgram(device, new ShaderProgram.ShaderModuleData[] { - new ShaderProgram.ShaderModuleData(VK_SHADER_STAGE_COMPUTE_BIT, ANIM_COMPUTE_SHADER_FILE_SPV, - animationSpecConstants.getSpecInfo()), + new ShaderProgram.ShaderModuleData(VK_SHADER_STAGE_COMPUTE_BIT, ANIM_COMPUTE_SHADER_FILE_SPV), }); } @@ -199,7 +191,7 @@ public void registerModels(List vulkanModels) { for (VulkanModel.VulkanAnimation animation : vulkanModel.getAnimationList()) { List animationFrames = new ArrayList<>(); for (VulkanBuffer jointsMatricesBuffer : animation.frameBufferList()) { - animationFrames.add(new DescriptorSet.UniformDescriptorSet(descriptorPool, uniformDescriptorSetLayout, + animationFrames.add(new DescriptorSet.StorageDescriptorSet(descriptorPool, storageDescriptorSetLayout, jointsMatricesBuffer, 0)); } jointMatricesBufferDescriptorSets.add(animationFrames); diff --git a/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/animation/AnimationSpecConstants.java b/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/animation/AnimationSpecConstants.java deleted file mode 100644 index a6e1d970..00000000 --- a/booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/animation/AnimationSpecConstants.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.vulkanb.eng.graph.animation; - -import org.lwjgl.system.MemoryUtil; -import org.lwjgl.vulkan.*; -import org.vulkanb.eng.EngineProperties; -import org.vulkanb.eng.graph.vk.GraphConstants; - -import java.nio.ByteBuffer; - -public class AnimationSpecConstants { - - private final ByteBuffer data; - private final VkSpecializationMapEntry.Buffer specEntryMap; - private final VkSpecializationInfo specInfo; - - public AnimationSpecConstants() { - EngineProperties engineProperties = EngineProperties.getInstance(); - data = MemoryUtil.memAlloc(GraphConstants.INT_LENGTH); - data.putInt(engineProperties.getMaxJointsMatricesLists()); - data.flip(); - - specEntryMap = VkSpecializationMapEntry.calloc(1); - specEntryMap.get(0) - .constantID(0) - .size(GraphConstants.INT_LENGTH) - .offset(0); - - specInfo = VkSpecializationInfo.calloc(); - specInfo.pData(data) - .pMapEntries(specEntryMap); - } - - public void cleanup() { - MemoryUtil.memFree(specEntryMap); - specInfo.free(); - MemoryUtil.memFree(data); - } - - public VkSpecializationInfo getSpecInfo() { - return specInfo; - } -} diff --git a/booksamples/chapter-15/resources/shaders/animations_comp.glsl b/booksamples/chapter-15/resources/shaders/animations_comp.glsl index 20a9550b..1385cd15 100644 --- a/booksamples/chapter-15/resources/shaders/animations_comp.glsl +++ b/booksamples/chapter-15/resources/shaders/animations_comp.glsl @@ -1,7 +1,5 @@ #version 450 -layout (constant_id = 0) const int MAX_JOINTS = 150; - layout (std430, set=0, binding=0) readonly buffer srcBuf { float data[]; } srcVector; @@ -14,11 +12,11 @@ layout (std430, set=2, binding=0) buffer dstBuf { float data[]; } dstVector; -layout (local_size_x=32, local_size_y=1, local_size_z=1) in; +layout (std430, set=3, binding=0) readonly buffer jointBuf { + mat4 data[]; +} jointMatrices; -layout(set = 3, binding = 0) uniform JointMatricesUniform { - mat4 jointMatrices[MAX_JOINTS]; -} jointMatricesUniform; +layout (local_size_x=32, local_size_y=1, local_size_z=1) in; void main() { @@ -29,10 +27,10 @@ void main() int baseIdxSrcBuf = int(gl_GlobalInvocationID.x) * 14; vec4 position = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 1); position = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * position + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * position + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * position + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * position; + weights.x * jointMatrices.data[joints.x] * position + + weights.y * jointMatrices.data[joints.y] * position + + weights.z * jointMatrices.data[joints.z] * position + + weights.w * jointMatrices.data[joints.w] * position; dstVector.data[baseIdxSrcBuf] = position.x / position.w; dstVector.data[baseIdxSrcBuf + 1] = position.y / position.w; dstVector.data[baseIdxSrcBuf + 2] = position.z / position.w; @@ -40,10 +38,10 @@ void main() baseIdxSrcBuf += 3; vec4 normal = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); normal = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * normal + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * normal + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * normal + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * normal; + weights.x * jointMatrices.data[joints.x] * normal + + weights.y * jointMatrices.data[joints.y] * normal + + weights.z * jointMatrices.data[joints.z] * normal + + weights.w * jointMatrices.data[joints.w] * normal; dstVector.data[baseIdxSrcBuf] = normal.x / normal.w; dstVector.data[baseIdxSrcBuf + 1] = normal.y / normal.w; dstVector.data[baseIdxSrcBuf + 2] = normal.z / normal.w; @@ -51,10 +49,10 @@ void main() baseIdxSrcBuf += 3; vec4 tangent = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); tangent = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * tangent + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * tangent + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * tangent + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * tangent; + weights.x * jointMatrices.data[joints.x] * tangent + + weights.y * jointMatrices.data[joints.y] * tangent + + weights.z * jointMatrices.data[joints.z] * tangent + + weights.w * jointMatrices.data[joints.w] * tangent; dstVector.data[baseIdxSrcBuf] = tangent.x / tangent.w; dstVector.data[baseIdxSrcBuf + 1] = tangent.y / tangent.w; dstVector.data[baseIdxSrcBuf + 2] = tangent.z / tangent.w; @@ -62,10 +60,10 @@ void main() baseIdxSrcBuf += 3; vec4 bitangent = vec4(srcVector.data[baseIdxSrcBuf], srcVector.data[baseIdxSrcBuf + 1], srcVector.data[baseIdxSrcBuf + 2], 0); bitangent = - weights.x * jointMatricesUniform.jointMatrices[joints.x] * bitangent + - weights.y * jointMatricesUniform.jointMatrices[joints.y] * bitangent + - weights.z * jointMatricesUniform.jointMatrices[joints.z] * bitangent + - weights.w * jointMatricesUniform.jointMatrices[joints.w] * bitangent; + weights.x * jointMatrices.data[joints.x] * bitangent + + weights.y * jointMatrices.data[joints.y] * bitangent + + weights.z * jointMatrices.data[joints.z] * bitangent + + weights.w * jointMatrices.data[joints.w] * bitangent; dstVector.data[baseIdxSrcBuf] = bitangent.x / bitangent.w; dstVector.data[baseIdxSrcBuf + 1] = bitangent.y / bitangent.w; dstVector.data[baseIdxSrcBuf + 2] = bitangent.z / bitangent.w; diff --git a/booksamples/chapter-15/resources/shaders/animations_comp.glsl.spv b/booksamples/chapter-15/resources/shaders/animations_comp.glsl.spv index 4385353932ff906baf9778df999e8da556bd9c41..1de886ef709fc3b543aee11f589cd6f13620572e 100644 GIT binary patch literal 9416 zcmZvh2XvKH7KQ&nBDUB83nE3uf>;n6Hf#X}MNwnNkVJ^a1WB+v2D@VKz4z`oz3Di; z_uib|dvl62^L_8VEq7(ja~3wwL|x)*l!EbHzZ>^ZyJyw!`mp1#iBQMheoM8KN>BY+=2dF*fEMi}wCyHNLr;&Uku%Pv77` zJ#QXyn?JJ; z^0TQCe=@$mHqM)zC)WAy(IkvkZ}}6!{)`{ZSk}+?PW||0eYwE-v@XJ|k;fG`N>)DE(5y?Zj5Cv8A@hP*r+Z&wb8(_t$z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q!g+B@F`R==@m?*^;A z53`o{bs3y|w4Vze_|7kflaKZuaI_nX_Fk~DXkP)Avq!YA1ee;+!#7Vp+E;tKV48 zxtuk8=Pw60F=ky?;9Ii+&K&pTN__d`Tvf{{*M2peeBP&Pz|NC*t-kZug7ZGvS3Pp( zM$dI%_2iwu9$&6}=hxt?u{`rP;LAtjjkTOo<4th#(Ref1dGgVC3pg6>twuR>qw!X7 zsqr>^x$>RA9bb)o#do{|Up^Y|1e;T8ybE7G8t(=>Pd*y&0Y{^~)hK6fG_D1g8t=uI zn}i8dkWv22DsFG8ecx^cm|wr<$UYPnU}iHg3C2Lhc8#2x##ii dRi3#Q@a5C%MR0mq!(MXcy;&K=|DPIE`9IFrG%NrB diff --git a/booksamples/chapter-15/src/main/java/org/vulkanb/eng/graph/animation/AnimationComputeActivity.java b/booksamples/chapter-15/src/main/java/org/vulkanb/eng/graph/animation/AnimationComputeActivity.java index 1e4cf019..5c5c3b1b 100644 --- a/booksamples/chapter-15/src/main/java/org/vulkanb/eng/graph/animation/AnimationComputeActivity.java +++ b/booksamples/chapter-15/src/main/java/org/vulkanb/eng/graph/animation/AnimationComputeActivity.java @@ -28,7 +28,6 @@ public class AnimationComputeActivity { // Key is the model id private final Map modelDescriptorSetsMap; private final Scene scene; - private final AnimationSpecConstants animationSpecConstants; private CommandBuffer commandBuffer; private ComputePipeline computePipeline; @@ -37,13 +36,11 @@ public class AnimationComputeActivity { private Fence fence; private ShaderProgram shaderProgram; private DescriptorSetLayout.StorageDescriptorSetLayout storageDescriptorSetLayout; - private DescriptorSetLayout.UniformDescriptorSetLayout uniformDescriptorSetLayout; public AnimationComputeActivity(CommandPool commandPool, PipelineCache pipelineCache, Scene scene) { this.scene = scene; device = pipelineCache.getDevice(); computeQueue = new Queue.ComputeQueue(device, 0); - animationSpecConstants = new AnimationSpecConstants(); createDescriptorPool(); createDescriptorSets(); createShaders(); @@ -56,12 +53,10 @@ public AnimationComputeActivity(CommandPool commandPool, PipelineCache pipelineC public void cleanup() { computePipeline.cleanup(); - animationSpecConstants.cleanup(); shaderProgram.cleanup(); commandBuffer.cleanup(); descriptorPool.cleanup(); storageDescriptorSetLayout.cleanup(); - uniformDescriptorSetLayout.cleanup(); fence.cleanup(); for (Map.Entry> entry : entityAnimationsBuffers.entrySet()) { entry.getValue().forEach(EntityAnimationBuffer::cleanup); @@ -79,19 +74,17 @@ private void createDescriptorPool() { int maxStorageBuffers = engineProperties.getMaxStorageBuffers(); int maxJointsMatricesLists = engineProperties.getMaxJointsMatricesLists(); List descriptorTypeCounts = new ArrayList<>(); - descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxStorageBuffers, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)); - descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxJointsMatricesLists, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)); + descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(maxStorageBuffers + maxJointsMatricesLists, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)); descriptorPool = new DescriptorPool(device, descriptorTypeCounts); } private void createDescriptorSets() { storageDescriptorSetLayout = new DescriptorSetLayout.StorageDescriptorSetLayout(device, 0, VK_SHADER_STAGE_COMPUTE_BIT); - uniformDescriptorSetLayout = new DescriptorSetLayout.UniformDescriptorSetLayout(device, 0, VK_SHADER_STAGE_COMPUTE_BIT); descriptorSetLayouts = new DescriptorSetLayout[]{ storageDescriptorSetLayout, storageDescriptorSetLayout, storageDescriptorSetLayout, - uniformDescriptorSetLayout, + storageDescriptorSetLayout, }; } @@ -108,8 +101,7 @@ private void createShaders() { } shaderProgram = new ShaderProgram(device, new ShaderProgram.ShaderModuleData[] { - new ShaderProgram.ShaderModuleData(VK_SHADER_STAGE_COMPUTE_BIT, ANIM_COMPUTE_SHADER_FILE_SPV, - animationSpecConstants.getSpecInfo()), + new ShaderProgram.ShaderModuleData(VK_SHADER_STAGE_COMPUTE_BIT, ANIM_COMPUTE_SHADER_FILE_SPV), }); } @@ -199,7 +191,7 @@ public void registerModels(List vulkanModels) { for (VulkanModel.VulkanAnimation animation : vulkanModel.getAnimationList()) { List animationFrames = new ArrayList<>(); for (VulkanBuffer jointsMatricesBuffer : animation.frameBufferList()) { - animationFrames.add(new DescriptorSet.UniformDescriptorSet(descriptorPool, uniformDescriptorSetLayout, + animationFrames.add(new DescriptorSet.StorageDescriptorSet(descriptorPool, storageDescriptorSetLayout, jointsMatricesBuffer, 0)); } jointMatricesBufferDescriptorSets.add(animationFrames); diff --git a/booksamples/chapter-15/src/main/java/org/vulkanb/eng/graph/animation/AnimationSpecConstants.java b/booksamples/chapter-15/src/main/java/org/vulkanb/eng/graph/animation/AnimationSpecConstants.java deleted file mode 100644 index a6e1d970..00000000 --- a/booksamples/chapter-15/src/main/java/org/vulkanb/eng/graph/animation/AnimationSpecConstants.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.vulkanb.eng.graph.animation; - -import org.lwjgl.system.MemoryUtil; -import org.lwjgl.vulkan.*; -import org.vulkanb.eng.EngineProperties; -import org.vulkanb.eng.graph.vk.GraphConstants; - -import java.nio.ByteBuffer; - -public class AnimationSpecConstants { - - private final ByteBuffer data; - private final VkSpecializationMapEntry.Buffer specEntryMap; - private final VkSpecializationInfo specInfo; - - public AnimationSpecConstants() { - EngineProperties engineProperties = EngineProperties.getInstance(); - data = MemoryUtil.memAlloc(GraphConstants.INT_LENGTH); - data.putInt(engineProperties.getMaxJointsMatricesLists()); - data.flip(); - - specEntryMap = VkSpecializationMapEntry.calloc(1); - specEntryMap.get(0) - .constantID(0) - .size(GraphConstants.INT_LENGTH) - .offset(0); - - specInfo = VkSpecializationInfo.calloc(); - specInfo.pData(data) - .pMapEntries(specEntryMap); - } - - public void cleanup() { - MemoryUtil.memFree(specEntryMap); - specInfo.free(); - MemoryUtil.memFree(data); - } - - public VkSpecializationInfo getSpecInfo() { - return specInfo; - } -}