From 5f1aac61ca2842af99c9598a2e8ef11e84de103f Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sun, 26 Dec 2021 18:42:03 +0100 Subject: [PATCH 1/9] Started working on sample showing comparing separate/interleaved vertex attributes --- base/VulkanUIOverlay.cpp | 7 + base/VulkanUIOverlay.h | 1 + data/shaders/glsl/vertexattributes/scene.frag | 43 ++ .../glsl/vertexattributes/scene.frag.spv | Bin 0 -> 3624 bytes data/shaders/glsl/vertexattributes/scene.vert | 39 ++ .../glsl/vertexattributes/scene.vert.spv | Bin 0 -> 3156 bytes examples/CMakeLists.txt | 1 + examples/vertexattributes/README.md | 5 + .../vertexattributes/vertexattributes.cpp | 657 ++++++++++++++++++ examples/vertexattributes/vertexattributes.h | 176 +++++ 10 files changed, 929 insertions(+) create mode 100644 data/shaders/glsl/vertexattributes/scene.frag create mode 100644 data/shaders/glsl/vertexattributes/scene.frag.spv create mode 100644 data/shaders/glsl/vertexattributes/scene.vert create mode 100644 data/shaders/glsl/vertexattributes/scene.vert.spv create mode 100644 examples/vertexattributes/README.md create mode 100644 examples/vertexattributes/vertexattributes.cpp create mode 100644 examples/vertexattributes/vertexattributes.h diff --git a/base/VulkanUIOverlay.cpp b/base/VulkanUIOverlay.cpp index 60c9226c..b18e2a5a 100644 --- a/base/VulkanUIOverlay.cpp +++ b/base/VulkanUIOverlay.cpp @@ -434,6 +434,13 @@ namespace vks return res; } + bool UIOverlay::radioButton(const char* caption, bool value) + { + bool res = ImGui::RadioButton(caption, value); + if (res) { updated = true; }; + return res; + } + bool UIOverlay::inputFloat(const char *caption, float *value, float step, uint32_t precision) { bool res = ImGui::InputFloat(caption, value, step, step * 10.0f, precision); diff --git a/base/VulkanUIOverlay.h b/base/VulkanUIOverlay.h index afb46ed6..7d45179b 100644 --- a/base/VulkanUIOverlay.h +++ b/base/VulkanUIOverlay.h @@ -81,6 +81,7 @@ namespace vks bool header(const char* caption); bool checkBox(const char* caption, bool* value); bool checkBox(const char* caption, int32_t* value); + bool radioButton(const char* caption, bool value); bool inputFloat(const char* caption, float* value, float step, uint32_t precision); bool sliderFloat(const char* caption, float* value, float min, float max); bool sliderInt(const char* caption, int32_t* value, int32_t min, int32_t max); diff --git a/data/shaders/glsl/vertexattributes/scene.frag b/data/shaders/glsl/vertexattributes/scene.frag new file mode 100644 index 00000000..c736fd31 --- /dev/null +++ b/data/shaders/glsl/vertexattributes/scene.frag @@ -0,0 +1,43 @@ +#version 450 + +layout (set = 1, binding = 0) uniform sampler2D samplerColorMap; +layout (set = 1, binding = 1) uniform sampler2D samplerNormalMap; + +layout (location = 0) in vec3 inNormal; +layout (location = 1) in vec2 inUV; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; +layout (location = 4) in vec4 inTangent; + +layout (location = 0) out vec4 outFragColor; + +layout(push_constant) uniform PushConsts { + mat4 model; + uint alphaMask; + float alphaMaskCuttoff; +} pushConsts; + +void main() +{ + vec4 color = texture(samplerColorMap, inUV); + + if (pushConsts.alphaMask == 1) { + if (color.a < pushConsts.alphaMaskCuttoff) { + discard; + } + } + + vec3 N = normalize(inNormal); + vec3 T = normalize(inTangent.xyz); + vec3 B = cross(inNormal, inTangent.xyz) * inTangent.w; + mat3 TBN = mat3(T, B, N); + N = TBN * normalize(texture(samplerNormalMap, inUV).xyz * 2.0 - vec3(1.0)); + + const float ambient = 0.1; + vec3 L = normalize(inLightVec); + vec3 V = normalize(inViewVec); + vec3 R = reflect(-L, N); + vec3 diffuse = max(dot(N, L), ambient).rrr; + float specular = pow(max(dot(R, V), 0.0), 32.0); + outFragColor = vec4(diffuse * color.rgb + specular, color.a); +} \ No newline at end of file diff --git a/data/shaders/glsl/vertexattributes/scene.frag.spv b/data/shaders/glsl/vertexattributes/scene.frag.spv new file mode 100644 index 0000000000000000000000000000000000000000..300acdbbe9e02e1cce98d3645523922a6234340a GIT binary patch literal 3624 zcmZ9OX>(Ln5QZ;=N!TPHi!2I(sGuN=0-^|HL4q2>7J|DB$s`#_W@2U{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+qXU)VYmpFX|oe zPoX7H?9!ctiF>T)F5OAH@ENi>^fQOE_#CoM-2aP&iA%Rq?3c*KYma{uzCyNsHx&84 uMi!6n_8VklJ%N3TEM|X!-A!2QTkgp3_Z^t=`fE40bD4*0`v9xT6h=E45+W#q$VJ6CNxY*G4Iqj@Adv(OBoGqs;t-mob<&f{bky<}Rlb1w zNIsQ+sB*3D-eb#|`s(cc?dv&b_q2wm_9w|uav&K?Hj-)`NrqvPVO!uiG8iMz{~}$mLll+1IWuuWqDyop-e4wD0WpeoQyYR>)cT+RM*b`ipk^Hr^h( z+2&S3=M`W1T3=sjYrTrTcfU8NCHD^8%3gnKu9x=;Z;%N@i21@<;@ zov!s4k+q*fe~I0Ca^pzOe)OPC*vHH4*3@nv>hTWNc?G=<%xj&{QInJC6YS>oT-KRn zmkVB-b*9+8OYPQCcOK(@U#n%~qRyMhLtwm~J8hoZbD8s9cHh*wGN-!#O>)}bt7YS~ z`^Gb12w1~B=RlG?y5de>nEF*JdFQVK z-=Pik_paUm^5OFqvOc~?_`HoQ{}*|TISq`HH_p311ALD*h`9HW|z>&VWQcVoW`KwtToH@Ucn&yb(IhtJ{UBj*xw^Br%Z%eg$a zZ+i>K*=KOeHRrkF9aoTz*I#?{9dDysTOWJ%yOFb3zsWV={H_9f^NrSleB9d?H7D6Pv0Tilm7=%<9lTJsBsTjPPn2*`2PUc c?5Tq;CtTqlJ>7>hr+)V2f0Nu}JTHKM0R(o>bpQYW literal 0 HcmV?d00001 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1a4e49c5..7f20749d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -136,6 +136,7 @@ set(EXAMPLES texturesparseresidency triangle variablerateshading + vertexattributes viewportarray vulkanscene ) diff --git a/examples/vertexattributes/README.md b/examples/vertexattributes/README.md new file mode 100644 index 00000000..2900bf26 --- /dev/null +++ b/examples/vertexattributes/README.md @@ -0,0 +1,5 @@ +# Vertex attributes + +## Synopsis + +This sample demonstrates how to pass vertex attributes using interleaved or separate buffers. \ No newline at end of file diff --git a/examples/vertexattributes/vertexattributes.cpp b/examples/vertexattributes/vertexattributes.cpp new file mode 100644 index 00000000..be405b67 --- /dev/null +++ b/examples/vertexattributes/vertexattributes.cpp @@ -0,0 +1,657 @@ +/* + * Vulkan Example - Passing vertex attributes using interleaved and separate buffers + * + * Copyright (C) 2021 by Sascha Willems - www.saschawillems.de + * + * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + */ + +#include "vertexattributes.h" + +/* + Vulkan glTF scene class +*/ + +VulkanglTFScene::~VulkanglTFScene() +{ + // Release all Vulkan resources allocated for the model + vertices.destroy(); + indices.destroy(); + for (Image image : images) { + vkDestroyImageView(vulkanDevice->logicalDevice, image.texture.view, nullptr); + vkDestroyImage(vulkanDevice->logicalDevice, image.texture.image, nullptr); + vkDestroySampler(vulkanDevice->logicalDevice, image.texture.sampler, nullptr); + vkFreeMemory(vulkanDevice->logicalDevice, image.texture.deviceMemory, nullptr); + } +} + +/* + glTF loading functions + + The following functions take a glTF input model loaded via tinyglTF and convert all required data into our own structure +*/ + +void VulkanglTFScene::loadImages(tinygltf::Model& input) +{ + // POI: The textures for the glTF file used in this sample are stored as external ktx files, so we can directly load them from disk without the need for conversion + images.resize(input.images.size()); + for (size_t i = 0; i < input.images.size(); i++) { + tinygltf::Image& glTFImage = input.images[i]; + images[i].texture.loadFromFile(path + "/" + glTFImage.uri, VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, copyQueue); + } +} + +void VulkanglTFScene::loadTextures(tinygltf::Model& input) +{ + textures.resize(input.textures.size()); + for (size_t i = 0; i < input.textures.size(); i++) { + textures[i].imageIndex = input.textures[i].source; + } +} + +void VulkanglTFScene::loadMaterials(tinygltf::Model& input) +{ + materials.resize(input.materials.size()); + for (size_t i = 0; i < input.materials.size(); i++) { + // We only read the most basic properties required for our sample + tinygltf::Material glTFMaterial = input.materials[i]; + // Get the base color factor + if (glTFMaterial.values.find("baseColorFactor") != glTFMaterial.values.end()) { + materials[i].baseColorFactor = glm::make_vec4(glTFMaterial.values["baseColorFactor"].ColorFactor().data()); + } + // Get base color texture index + if (glTFMaterial.values.find("baseColorTexture") != glTFMaterial.values.end()) { + materials[i].baseColorTextureIndex = glTFMaterial.values["baseColorTexture"].TextureIndex(); + } + // Get the normal map texture index + if (glTFMaterial.additionalValues.find("normalTexture") != glTFMaterial.additionalValues.end()) { + materials[i].normalTextureIndex = glTFMaterial.additionalValues["normalTexture"].TextureIndex(); + } + // Get some additional material parameters that are used in this sample + materials[i].alphaMode = glTFMaterial.alphaMode; + materials[i].alphaCutOff = (float)glTFMaterial.alphaCutoff; + materials[i].doubleSided = glTFMaterial.doubleSided; + } +} + +void VulkanglTFScene::loadNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, VulkanglTFScene::Node* parent, std::vector& indexBuffer, std::vector& vertexBuffer) +{ + VulkanglTFScene::Node node{}; + node.name = inputNode.name; + + // Get the local node matrix + // It's either made up from translation, rotation, scale or a 4x4 matrix + node.matrix = glm::mat4(1.0f); + if (inputNode.translation.size() == 3) { + node.matrix = glm::translate(node.matrix, glm::vec3(glm::make_vec3(inputNode.translation.data()))); + } + if (inputNode.rotation.size() == 4) { + glm::quat q = glm::make_quat(inputNode.rotation.data()); + node.matrix *= glm::mat4(q); + } + if (inputNode.scale.size() == 3) { + node.matrix = glm::scale(node.matrix, glm::vec3(glm::make_vec3(inputNode.scale.data()))); + } + if (inputNode.matrix.size() == 16) { + node.matrix = glm::make_mat4x4(inputNode.matrix.data()); + }; + + // Load node's children + if (inputNode.children.size() > 0) { + for (size_t i = 0; i < inputNode.children.size(); i++) { + loadNode(input.nodes[inputNode.children[i]], input, &node, indexBuffer, vertexBuffer); + } + } + + // If the node contains mesh data, we load vertices and indices from the buffers + // In glTF this is done via accessors and buffer views + if (inputNode.mesh > -1) { + const tinygltf::Mesh mesh = input.meshes[inputNode.mesh]; + // Iterate through all primitives of this node's mesh + for (size_t i = 0; i < mesh.primitives.size(); i++) { + const tinygltf::Primitive& glTFPrimitive = mesh.primitives[i]; + uint32_t firstIndex = static_cast(indexBuffer.size()); + uint32_t vertexStart = static_cast(vertexBuffer.size()); + uint32_t indexCount = 0; + + // Vertex attributes + const float* positionBuffer = nullptr; + const float* normalsBuffer = nullptr; + const float* texCoordsBuffer = nullptr; + const float* tangentsBuffer = nullptr; + size_t vertexCount = 0; + + // Get buffer data for vertex positions + if (glTFPrimitive.attributes.find("POSITION") != glTFPrimitive.attributes.end()) { + const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("POSITION")->second]; + const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; + positionBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); + vertexCount = accessor.count; + } + // Get buffer data for vertex normals + if (glTFPrimitive.attributes.find("NORMAL") != glTFPrimitive.attributes.end()) { + const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("NORMAL")->second]; + const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; + normalsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); + } + // Get buffer data for vertex texture coordinates + // glTF supports multiple sets, we only load the first one + if (glTFPrimitive.attributes.find("TEXCOORD_0") != glTFPrimitive.attributes.end()) { + const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("TEXCOORD_0")->second]; + const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; + texCoordsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); + } + // POI: This sample uses normal mapping, so we also need to load the tangents from the glTF file + if (glTFPrimitive.attributes.find("TANGENT") != glTFPrimitive.attributes.end()) { + const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("TANGENT")->second]; + const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; + tangentsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); + } + + // Append data to model's vertex buffer + for (size_t v = 0; v < vertexCount; v++) { + + // Append interleaved attributes + Vertex vert{}; + vert.pos = glm::vec4(glm::make_vec3(&positionBuffer[v * 3]), 1.0f); + vert.normal = glm::normalize(glm::vec3(normalsBuffer ? glm::make_vec3(&normalsBuffer[v * 3]) : glm::vec3(0.0f))); + vert.uv = texCoordsBuffer ? glm::make_vec2(&texCoordsBuffer[v * 2]) : glm::vec3(0.0f); + vert.tangent = tangentsBuffer ? glm::make_vec4(&tangentsBuffer[v * 4]) : glm::vec4(0.0f); + vertexBuffer.push_back(vert); + + // Append separate attributes + vertexAttributes.pos.push_back(glm::make_vec3(&positionBuffer[v * 3])); + vertexAttributes.normal.push_back(glm::normalize(glm::vec3(normalsBuffer ? glm::make_vec3(&normalsBuffer[v * 3]) : glm::vec3(0.0f)))); + vertexAttributes.tangent.push_back(tangentsBuffer ? glm::make_vec4(&tangentsBuffer[v * 4]) : glm::vec4(0.0f)); + vertexAttributes.uv.push_back(texCoordsBuffer ? glm::make_vec2(&texCoordsBuffer[v * 2]) : glm::vec3(0.0f)); + + } + + // Indices + const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.indices]; + const tinygltf::BufferView& bufferView = input.bufferViews[accessor.bufferView]; + const tinygltf::Buffer& buffer = input.buffers[bufferView.buffer]; + + indexCount += static_cast(accessor.count); + + // glTF supports different component types of indices + switch (accessor.componentType) { + case TINYGLTF_PARAMETER_TYPE_UNSIGNED_INT: { + const uint32_t* buf = reinterpret_cast(&buffer.data[accessor.byteOffset + bufferView.byteOffset]); + for (size_t index = 0; index < accessor.count; index++) { + indexBuffer.push_back(buf[index] + vertexStart); + } + break; + } + case TINYGLTF_PARAMETER_TYPE_UNSIGNED_SHORT: { + const uint16_t* buf = reinterpret_cast(&buffer.data[accessor.byteOffset + bufferView.byteOffset]); + for (size_t index = 0; index < accessor.count; index++) { + indexBuffer.push_back(buf[index] + vertexStart); + } + break; + } + case TINYGLTF_PARAMETER_TYPE_UNSIGNED_BYTE: { + const uint8_t* buf = reinterpret_cast(&buffer.data[accessor.byteOffset + bufferView.byteOffset]); + for (size_t index = 0; index < accessor.count; index++) { + indexBuffer.push_back(buf[index] + vertexStart); + } + break; + } + default: + std::cerr << "Index component type " << accessor.componentType << " not supported!" << std::endl; + return; + } + + Primitive primitive{}; + primitive.firstIndex = firstIndex; + primitive.indexCount = indexCount; + primitive.materialIndex = glTFPrimitive.material; + node.mesh.primitives.push_back(primitive); + } + } + + if (parent) { + parent->children.push_back(node); + } + else { + nodes.push_back(node); + } +} + +VkDescriptorImageInfo VulkanglTFScene::getTextureDescriptor(const size_t index) +{ + return images[index].texture.descriptor; +} + +/* + glTF rendering functions +*/ + +// Draw a single node including child nodes (if present) +void VulkanglTFScene::drawNode(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout, VulkanglTFScene::Node node, bool separate) +{ + if (!node.visible) { + return; + } + if (node.mesh.primitives.size() > 0) { + // Pass the node's matrix via push constants + // Traverse the node hierarchy to the top-most parent to get the final matrix of the current node + + PushConstBlock pushConstBlock; + + glm::mat4 nodeMatrix = node.matrix; + VulkanglTFScene::Node* currentParent = node.parent; + while (currentParent) { + nodeMatrix = currentParent->matrix * nodeMatrix; + currentParent = currentParent->parent; + } + for (VulkanglTFScene::Primitive& primitive : node.mesh.primitives) { + if (primitive.indexCount > 0) { + VulkanglTFScene::Material& material = materials[primitive.materialIndex]; + pushConstBlock.nodeMatrix = nodeMatrix; + pushConstBlock.alphaMask = (material.alphaMode == "MASK"); + pushConstBlock.alphaMaskCutoff = material.alphaCutOff; + vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(PushConstBlock), &pushConstBlock); + vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1, 1, &material.descriptorSet, 0, nullptr); + vkCmdDrawIndexed(commandBuffer, primitive.indexCount, 1, primitive.firstIndex, 0, 0); + } + } + } + for (auto& child : node.children) { + drawNode(commandBuffer, pipelineLayout, child, separate); + } +} + +/* + Vulkan Example class +*/ + +VulkanExample::VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) +{ + title = "Separate vertex attribute buffers"; + camera.type = Camera::CameraType::firstperson; + camera.flipY = true; + camera.setPosition(glm::vec3(0.0f, 1.0f, 0.0f)); + camera.setRotation(glm::vec3(0.0f, -90.0f, 0.0f)); + camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); +} + +VulkanExample::~VulkanExample() +{ + vkDestroyPipelineLayout(device, pipelineLayout, nullptr); + vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.matrices, nullptr); + vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.textures, nullptr); + shaderData.buffer.destroy(); +} + +void VulkanExample::getEnabledFeatures() +{ + enabledFeatures.samplerAnisotropy = deviceFeatures.samplerAnisotropy; +} + +void VulkanExample::buildCommandBuffers() +{ + VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); + + VkClearValue clearValues[2]; + clearValues[0].color = defaultClearColor; + clearValues[0].color = { { 0.25f, 0.25f, 0.25f, 1.0f } };; + clearValues[1].depthStencil = { 1.0f, 0 }; + + VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); + renderPassBeginInfo.renderPass = renderPass; + renderPassBeginInfo.renderArea.offset.x = 0; + renderPassBeginInfo.renderArea.offset.y = 0; + renderPassBeginInfo.renderArea.extent.width = width; + renderPassBeginInfo.renderArea.extent.height = height; + renderPassBeginInfo.clearValueCount = 2; + renderPassBeginInfo.pClearValues = clearValues; + + const VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f); + const VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0); + + for (int32_t i = 0; i < drawCmdBuffers.size(); ++i) + { + renderPassBeginInfo.framebuffer = frameBuffers[i]; + VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); + vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); + vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); + vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor); + + // Select the separate or interleaved vertex binding pipeline + vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, vertexAttributeSettings == VertexAttributeSettings::separate ? pipelines.vertexAttributesSeparate : pipelines.vertexAttributesInterleaved); + + // Bind scene matrices descriptor to set 0 + vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr); + + // Use the same index buffer, no matter how vertex attributes are passed + vkCmdBindIndexBuffer(drawCmdBuffers[i], glTFScene.indices.buffer, 0, VK_INDEX_TYPE_UINT32); + + if (vertexAttributeSettings == VertexAttributeSettings::separate) { + // Using separate vertex attribute bindings requires binding all attribute buffers + VkDeviceSize offsets[4] = { 0, 0, 0, 0 }; + std::array buffers = { vertexAttibuteBuffers.pos.buffer, vertexAttibuteBuffers.normal.buffer, vertexAttibuteBuffers.uv.buffer, vertexAttibuteBuffers.tangent.buffer }; + vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, static_cast(buffers.size()), buffers.data(), offsets); + } else { + // Using interleaved attribute bindings only requires one buffer bind + VkDeviceSize offsets[1] = { 0 }; + vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &glTFScene.vertices.buffer, offsets); + } + // Render all nodes starting at top-level + for (auto& node : glTFScene.nodes) { + glTFScene.drawNode(drawCmdBuffers[i], pipelineLayout, node, vertexAttributeSettings == VertexAttributeSettings::separate); + } + + drawUI(drawCmdBuffers[i]); + vkCmdEndRenderPass(drawCmdBuffers[i]); + VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i])); + } +} + +void VulkanExample::loadglTFFile(std::string filename) +{ + tinygltf::Model glTFInput; + tinygltf::TinyGLTF gltfContext; + std::string error, warning; + + this->device = device; + +#if defined(__ANDROID__) + // On Android all assets are packed with the apk in a compressed form, so we need to open them using the asset manager + // We let tinygltf handle this, by passing the asset manager of our app + tinygltf::asset_manager = androidApp->activity->assetManager; +#endif + bool fileLoaded = gltfContext.LoadASCIIFromFile(&glTFInput, &error, &warning, filename); + + // Pass some Vulkan resources required for setup and rendering to the glTF model loading class + glTFScene.vulkanDevice = vulkanDevice; + glTFScene.copyQueue = queue; + + size_t pos = filename.find_last_of('/'); + glTFScene.path = filename.substr(0, pos); + + std::vector indexBuffer; + std::vector vertexBuffer; + + if (!fileLoaded) { + vks::tools::exitFatal("Could not open the glTF file.\n\nThe file is part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1); + return; + } + glTFScene.loadImages(glTFInput); + glTFScene.loadMaterials(glTFInput); + glTFScene.loadTextures(glTFInput); + const tinygltf::Scene& scene = glTFInput.scenes[0]; + for (size_t i = 0; i < scene.nodes.size(); i++) { + const tinygltf::Node node = glTFInput.nodes[scene.nodes[i]]; + glTFScene.loadNode(node, glTFInput, nullptr, indexBuffer, vertexBuffer); + } + + /* Upload vertex and index buffers */ + + /* Anonymous functions to simplify buffer creation */ + /* Create a staging buffer used as a source for copies */ + auto createStagingBuffer = [this](vks::Buffer& buffer, void* data, VkDeviceSize size) { + VK_CHECK_RESULT(vulkanDevice->createBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &buffer, size, data)); + }; + /* Create a device local buffer used as a target for copies*/ + auto createDeviceBuffer = [this](vks::Buffer& buffer, VkDeviceSize size, VkBufferUsageFlags usageFlags = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) { + VK_CHECK_RESULT(vulkanDevice->createBuffer(usageFlags | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &buffer, size)); + }; + + size_t vertexBufferSize = vertexBuffer.size() * sizeof(VulkanglTFScene::Vertex); + size_t indexBufferSize = indexBuffer.size() * sizeof(uint32_t); + + vks::Buffer vertexStaging, indexStaging; + + createStagingBuffer(indexStaging, indexBuffer.data(), indexBufferSize); + createStagingBuffer(vertexStaging, vertexBuffer.data(), vertexBufferSize); + + createDeviceBuffer(glTFScene.indices, indexStaging.size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT); + createDeviceBuffer(glTFScene.vertices, vertexStaging.size); + + // Copy data from staging buffers (host) do device local buffer (gpu) + VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); + VkBufferCopy copyRegion = {}; + + copyRegion.size = vertexBufferSize; + vkCmdCopyBuffer(copyCmd, vertexStaging.buffer, glTFScene.vertices.buffer, 1, ©Region); + + copyRegion.size = indexBufferSize; + vkCmdCopyBuffer(copyCmd, indexStaging.buffer, glTFScene.indices.buffer, 1, ©Region); + + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); + + // Free staging resources + vkDestroyBuffer(device, vertexStaging.buffer, nullptr); + vkFreeMemory(device, vertexStaging.memory, nullptr); + vkDestroyBuffer(device, indexStaging.buffer, nullptr); + vkFreeMemory(device, indexStaging.memory, nullptr); + + /* + Interleaved vertex attributes + We create one single buffer containing the interleaved vertex attributes + */ + + /* + Separate vertex attributes + We create a separate buffer for each of the vertex attributes (position, normals, etc.) + */ + + std::array stagingBuffers; + createStagingBuffer(stagingBuffers[0], glTFScene.vertexAttributes.pos.data(), glTFScene.vertexAttributes.pos.size() * sizeof(glTFScene.vertexAttributes.pos[0])); + createStagingBuffer(stagingBuffers[1], glTFScene.vertexAttributes.normal.data(), glTFScene.vertexAttributes.normal.size() * sizeof(glTFScene.vertexAttributes.normal[0])); + createStagingBuffer(stagingBuffers[2], glTFScene.vertexAttributes.uv.data(), glTFScene.vertexAttributes.uv.size() * sizeof(glTFScene.vertexAttributes.uv[0])); + createStagingBuffer(stagingBuffers[3], glTFScene.vertexAttributes.tangent.data(), glTFScene.vertexAttributes.tangent.size() * sizeof(glTFScene.vertexAttributes.tangent[0])); + + createDeviceBuffer(vertexAttibuteBuffers.pos, stagingBuffers[0].size); + createDeviceBuffer(vertexAttibuteBuffers.normal, stagingBuffers[1].size); + createDeviceBuffer(vertexAttibuteBuffers.uv, stagingBuffers[2].size); + createDeviceBuffer(vertexAttibuteBuffers.tangent, stagingBuffers[3].size); + + // Stage + std::vector attributeBuffers = { + vertexAttibuteBuffers.pos, + vertexAttibuteBuffers.normal, + vertexAttibuteBuffers.uv, + vertexAttibuteBuffers.tangent, + }; + + // Copy data from staging buffers (host) do device local buffer (gpu) + copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); + copyRegion = {}; + for (size_t i = 0; i < attributeBuffers.size(); i++) { + copyRegion.size = attributeBuffers[i].size; + vkCmdCopyBuffer(copyCmd, stagingBuffers[i].buffer, attributeBuffers[i].buffer, 1, ©Region); + } + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); + + /* + Index buffer + The index buffer is always the same, no matter how we pass the vertex attributes + */ + + + // @todo: clear +} + +void VulkanExample::loadAssets() +{ + loadglTFFile(getAssetPath() + "models/sponza/sponza.gltf"); +} + +void VulkanExample::setupDescriptors() +{ + // One ubo to pass dynamic data to the shader + // Two combined image samplers per material as each material uses color and normal maps + std::vector poolSizes = { + vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1), + vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, static_cast(glTFScene.materials.size()) * 2), + }; + // One set for matrices and one per model image/texture + const uint32_t maxSetCount = static_cast(glTFScene.images.size()) + 1; + VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(poolSizes, maxSetCount); + VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool)); + // Descriptor set layout for passing matrices + std::vector setLayoutBindings = { + vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0) + }; + VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast(setLayoutBindings.size())); + VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.matrices)); + // Descriptor set layout for passing material textures + setLayoutBindings = { + // Color map + vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0), + // Normal map + vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 1), + }; + descriptorSetLayoutCI.pBindings = setLayoutBindings.data(); + descriptorSetLayoutCI.bindingCount = 2; + VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.textures)); + + // Pipeline layout using both descriptor sets (set 0 = matrices, set 1 = material) + std::array setLayouts = { descriptorSetLayouts.matrices, descriptorSetLayouts.textures }; + VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(setLayouts.data(), static_cast(setLayouts.size())); + // We will use push constants to push the local matrices of a primitive to the vertex shader + VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(PushConstBlock), 0); + // Push constant ranges are part of the pipeline layout + pipelineLayoutCI.pushConstantRangeCount = 1; + pipelineLayoutCI.pPushConstantRanges = &pushConstantRange; + VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout)); + + // Descriptor set for scene matrices + VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.matrices, 1); + VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); + VkWriteDescriptorSet writeDescriptorSet = vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &shaderData.buffer.descriptor); + vkUpdateDescriptorSets(device, 1, &writeDescriptorSet, 0, nullptr); + + // Descriptor sets for the materials + for (auto& material : glTFScene.materials) { + const VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.textures, 1); + VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &material.descriptorSet)); + VkDescriptorImageInfo colorMap = glTFScene.getTextureDescriptor(material.baseColorTextureIndex); + VkDescriptorImageInfo normalMap = glTFScene.getTextureDescriptor(material.normalTextureIndex); + std::vector writeDescriptorSets = { + vks::initializers::writeDescriptorSet(material.descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &colorMap), + vks::initializers::writeDescriptorSet(material.descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &normalMap), + }; + vkUpdateDescriptorSets(device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr); + } +} + +void VulkanExample::preparePipelines() +{ + VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE); + VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0); + VkPipelineColorBlendAttachmentState blendAttachmentStateCI = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE); + VkPipelineColorBlendStateCreateInfo colorBlendStateCI = vks::initializers::pipelineColorBlendStateCreateInfo(1, &blendAttachmentStateCI); + VkPipelineDepthStencilStateCreateInfo depthStencilStateCI = vks::initializers::pipelineDepthStencilStateCreateInfo(VK_TRUE, VK_TRUE, VK_COMPARE_OP_LESS_OR_EQUAL); + VkPipelineViewportStateCreateInfo viewportStateCI = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0); + VkPipelineMultisampleStateCreateInfo multisampleStateCI = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0); + const std::vector dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; + VkPipelineDynamicStateCreateInfo dynamicStateCI = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables.data(), static_cast(dynamicStateEnables.size()), 0); + VkPipelineVertexInputStateCreateInfo vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(); + std::array shaderStages; + + // @todo: comment + const std::vector vertexInputBindingsInterleaved = { + vks::initializers::vertexInputBindingDescription(0, sizeof(VulkanglTFScene::Vertex), VK_VERTEX_INPUT_RATE_VERTEX), + }; + const std::vector vertexInputAttributesInterleaved = { + vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFScene::Vertex, pos)), + vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFScene::Vertex, normal)), + vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFScene::Vertex, uv)), + vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFScene::Vertex, tangent)), + }; + + // @todo: comment + const std::vector vertexInputBindingsSeparate = { + vks::initializers::vertexInputBindingDescription(0, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX), + vks::initializers::vertexInputBindingDescription(1, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX), + vks::initializers::vertexInputBindingDescription(2, sizeof(glm::vec2), VK_VERTEX_INPUT_RATE_VERTEX), + vks::initializers::vertexInputBindingDescription(3, sizeof(glm::vec4), VK_VERTEX_INPUT_RATE_VERTEX), + }; + const std::vector vertexInputAttributesSeparate = { + vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), + vks::initializers::vertexInputAttributeDescription(1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0), + vks::initializers::vertexInputAttributeDescription(2, 2, VK_FORMAT_R32G32B32_SFLOAT, 0), + vks::initializers::vertexInputAttributeDescription(3, 3, VK_FORMAT_R32G32B32_SFLOAT, 0), + }; + + VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayout, renderPass, 0); + pipelineCI.pVertexInputState = &vertexInputStateCI; + pipelineCI.pInputAssemblyState = &inputAssemblyStateCI; + pipelineCI.pRasterizationState = &rasterizationStateCI; + pipelineCI.pColorBlendState = &colorBlendStateCI; + pipelineCI.pMultisampleState = &multisampleStateCI; + pipelineCI.pViewportState = &viewportStateCI; + pipelineCI.pDepthStencilState = &depthStencilStateCI; + pipelineCI.pDynamicState = &dynamicStateCI; + pipelineCI.stageCount = static_cast(shaderStages.size()); + pipelineCI.pStages = shaderStages.data(); + + shaderStages[0] = loadShader(getShadersPath() + "vertexattributes/scene.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shaderStages[1] = loadShader(getShadersPath() + "vertexattributes/scene.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + + //rasterizationStateCI.cullMode = material.doubleSided ? VK_CULL_MODE_NONE : VK_CULL_MODE_BACK_BIT; + vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsInterleaved, vertexInputAttributesInterleaved); + VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.vertexAttributesInterleaved)); + + vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsSeparate, vertexInputAttributesSeparate); + VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.vertexAttributesSeparate)); +} + +void VulkanExample::prepareUniformBuffers() +{ + VK_CHECK_RESULT(vulkanDevice->createBuffer( + VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + &shaderData.buffer, + sizeof(shaderData.values))); + VK_CHECK_RESULT(shaderData.buffer.map()); + updateUniformBuffers(); +} + +void VulkanExample::updateUniformBuffers() +{ + shaderData.values.projection = camera.matrices.perspective; + shaderData.values.view = camera.matrices.view; + shaderData.values.viewPos = camera.viewPos; + memcpy(shaderData.buffer.mapped, &shaderData.values, sizeof(shaderData.values)); +} + +void VulkanExample::prepare() +{ + VulkanExampleBase::prepare(); + loadAssets(); + prepareUniformBuffers(); + setupDescriptors(); + preparePipelines(); + buildCommandBuffers(); + prepared = true; +} + +void VulkanExample::render() +{ + renderFrame(); + if (camera.updated) { + updateUniformBuffers(); + } +} + +void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay) +{ + if (overlay->header("Vertex buffer attributes")) { + bool interleaved = (vertexAttributeSettings == VertexAttributeSettings::interleaved); + bool separate = (vertexAttributeSettings == VertexAttributeSettings::separate); + if (overlay->radioButton("Interleaved", interleaved)) { + vertexAttributeSettings = VertexAttributeSettings::interleaved; + buildCommandBuffers(); + } + if (overlay->radioButton("Separate", separate)) { + vertexAttributeSettings = VertexAttributeSettings::separate; + buildCommandBuffers(); + } + } +} + +VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/examples/vertexattributes/vertexattributes.h b/examples/vertexattributes/vertexattributes.h new file mode 100644 index 00000000..8d96ac17 --- /dev/null +++ b/examples/vertexattributes/vertexattributes.h @@ -0,0 +1,176 @@ +/* + * Vulkan Example - Passing vertex attributes using interleaved and separate buffers + * + * Copyright (C) 2021 by Sascha Willems - www.saschawillems.de + * + * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + */ + +#define TINYGLTF_IMPLEMENTATION +#define STB_IMAGE_IMPLEMENTATION +#define TINYGLTF_NO_STB_IMAGE_WRITE +#define TINYGLTF_NO_STB_IMAGE +#define TINYGLTF_NO_EXTERNAL_IMAGE +#ifdef VK_USE_PLATFORM_ANDROID_KHR +#define TINYGLTF_ANDROID_LOAD_FROM_ASSETS +#endif +#include "tiny_gltf.h" + +#include "vulkanexamplebase.h" + +#define ENABLE_VALIDATION false + +struct PushConstBlock { + glm::mat4 nodeMatrix; + uint32_t alphaMask; + float alphaMaskCutoff; +}; + + // Contains everything required to render a basic glTF scene in Vulkan + // This class is heavily simplified (compared to glTF's feature set) but retains the basic glTF structure +class VulkanglTFScene +{ +public: + // The class requires some Vulkan objects so it can create it's own resources + vks::VulkanDevice* vulkanDevice; + VkQueue copyQueue; + + // The vertex layout for the samples' model + struct Vertex { + glm::vec3 pos; + glm::vec3 normal; + glm::vec2 uv; + glm::vec4 tangent; + }; + + // Single vertex buffer for all primitives + vks::Buffer vertices; + + // Used at loading time + struct VertexAttributes { + std::vector uv; + std::vector pos, normal; + std::vector tangent; + } vertexAttributes; + + // Single index buffer for all primitives + vks::Buffer indices; + + // The following structures roughly represent the glTF scene structure + // To keep things simple, they only contain those properties that are required for this sample + struct Node; + + // A primitive contains the data for a single draw call + struct Primitive { + uint32_t firstIndex; + uint32_t indexCount; + int32_t materialIndex; + }; + + // Contains the node's (optional) geometry and can be made up of an arbitrary number of primitives + struct Mesh { + std::vector primitives; + }; + + // A node represents an object in the glTF scene graph + struct Node { + Node* parent; + std::vector children; + Mesh mesh; + glm::mat4 matrix; + std::string name; + bool visible = true; + }; + + // A glTF material stores information in e.g. the texture that is attached to it and colors + struct Material { + glm::vec4 baseColorFactor = glm::vec4(1.0f); + uint32_t baseColorTextureIndex; + uint32_t normalTextureIndex; + std::string alphaMode = "OPAQUE"; + float alphaCutOff; + bool doubleSided = false; + VkDescriptorSet descriptorSet; + }; + + // Contains the texture for a single glTF image + // Images may be reused by texture objects and are as such separated + struct Image { + vks::Texture2D texture; + }; + + // A glTF texture stores a reference to the image and a sampler + // In this sample, we are only interested in the image + struct Texture { + int32_t imageIndex; + }; + + /* + Model data + */ + std::vector images; + std::vector textures; + std::vector materials; + std::vector nodes; + + std::string path; + + ~VulkanglTFScene(); + VkDescriptorImageInfo getTextureDescriptor(const size_t index); + void loadImages(tinygltf::Model& input); + void loadTextures(tinygltf::Model& input); + void loadMaterials(tinygltf::Model& input); + void loadNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, VulkanglTFScene::Node* parent, std::vector& indexBuffer, std::vector& vertexBuffer); + void drawNode(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout, VulkanglTFScene::Node node, bool separate); +}; + +class VulkanExample : public VulkanExampleBase +{ +public: + VulkanglTFScene glTFScene; + + enum VertexAttributeSettings { interleaved, separate }; + VertexAttributeSettings vertexAttributeSettings = separate; + + // Buffers for the separate vertex attributes + struct VertexAttributeBuffers { + vks::Buffer pos, normal, uv, tangent; + } vertexAttibuteBuffers; + + struct ShaderData { + vks::Buffer buffer; + struct Values { + glm::mat4 projection; + glm::mat4 view; + glm::vec4 lightPos = glm::vec4(0.0f, 2.5f, 0.0f, 1.0f); + glm::vec4 viewPos; + } values; + } shaderData; + + struct Pipelines { + VkPipeline vertexAttributesInterleaved; + VkPipeline vertexAttributesSeparate; + } pipelines; + + VkPipelineLayout pipelineLayout; + VkDescriptorSet descriptorSet; + + struct DescriptorSetLayouts { + VkDescriptorSetLayout matrices; + VkDescriptorSetLayout textures; + } descriptorSetLayouts; + + VulkanExample(); + ~VulkanExample(); + virtual void getEnabledFeatures(); + void buildCommandBuffers(); + void loadglTFFile(std::string filename); + void loadAssets(); + void setupDescriptors(); + void preparePipelines(); + void prepareUniformBuffers(); + void updateUniformBuffers(); + void prepare(); + virtual void render(); + virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay); +}; \ No newline at end of file From 76bda56784ccb0efeebdc1c4edfe53d773050273 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Thu, 20 Jan 2022 07:29:38 +0100 Subject: [PATCH 2/9] Updated Vulkan Headers to 1.2.203 --- .../vk_video/vulkan_video_codec_h264std.h | 324 ++++++----- .../vulkan_video_codec_h264std_decode.h | 112 ++-- .../vulkan_video_codec_h264std_encode.h | 109 ++-- .../vk_video/vulkan_video_codec_h265std.h | 539 +++++++++--------- .../vulkan_video_codec_h265std_decode.h | 66 +-- .../vulkan_video_codec_h265std_encode.h | 165 +++--- .../vk_video/vulkan_video_codecs_common.h | 18 +- external/vulkan/vk_platform.h | 2 +- external/vulkan/vulkan_beta.h | 130 ++++- external/vulkan/vulkan_core.h | 148 ++++- 10 files changed, 923 insertions(+), 690 deletions(-) diff --git a/external/vk_video/vulkan_video_codec_h264std.h b/external/vk_video/vulkan_video_codec_h264std.h index 3338fe14..27e44380 100644 --- a/external/vk_video/vulkan_video_codec_h264std.h +++ b/external/vk_video/vulkan_video_codec_h264std.h @@ -1,49 +1,53 @@ +#ifndef VULKAN_VIDEO_CODEC_H264STD_H_ +#define VULKAN_VIDEO_CODEC_H264STD_H_ 1 + /* -** Copyright (c) 2019-2021 The Khronos Group Inc. +** Copyright 2015-2021 The Khronos Group Inc. ** ** SPDX-License-Identifier: Apache-2.0 */ -#ifndef VULKAN_VIDEO_CODEC_H264STD_H_ -#define VULKAN_VIDEO_CODEC_H264STD_H_ 1 +/* +** This header is generated from the Khronos Vulkan XML API Registry. +** +*/ + #ifdef __cplusplus extern "C" { #endif -#include "vk_video/vulkan_video_codecs_common.h" + +#define vulkan_video_codec_h264std 1 +#include // Vulkan 0.9 provisional Vulkan video H.264 encode and decode std specification version number #define VK_STD_VULKAN_VIDEO_CODEC_H264_API_VERSION_0_9_5 VK_MAKE_VIDEO_STD_VERSION(0, 9, 5) // Patch version should always be set to 0 -// Format must be in the form XX.XX where the first two digits are the major and the second two, the minor. -#define VK_STD_VULKAN_VIDEO_CODEC_H264_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_API_VERSION_0_9_5 -#define VK_STD_VULKAN_VIDEO_CODEC_H264_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264" - -// ************************************************* -// Video H.264 common definitions: -// ************************************************* - -#define STD_VIDEO_H264_CPB_CNT_LIST_SIZE 32 +#define STD_VIDEO_H264_CPB_CNT_LIST_SIZE 32 #define STD_VIDEO_H264_SCALING_LIST_4X4_NUM_LISTS 6 #define STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS 16 #define STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS 2 #define STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS 64 +#define VK_STD_VULKAN_VIDEO_CODEC_H264_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_API_VERSION_0_9_5 +#define VK_STD_VULKAN_VIDEO_CODEC_H264_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264" typedef enum StdVideoH264ChromaFormatIdc { - STD_VIDEO_H264_CHROMA_FORMAT_IDC_MONOCHROME = 0, - STD_VIDEO_H264_CHROMA_FORMAT_IDC_420 = 1, - STD_VIDEO_H264_CHROMA_FORMAT_IDC_422 = 2, - STD_VIDEO_H264_CHROMA_FORMAT_IDC_444 = 3, - STD_VIDEO_H264_CHROMA_FORMAT_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_CHROMA_FORMAT_IDC_MONOCHROME = 0, + STD_VIDEO_H264_CHROMA_FORMAT_IDC_420 = 1, + STD_VIDEO_H264_CHROMA_FORMAT_IDC_422 = 2, + STD_VIDEO_H264_CHROMA_FORMAT_IDC_444 = 3, + STD_VIDEO_H264_CHROMA_FORMAT_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_CHROMA_FORMAT_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH264ChromaFormatIdc; typedef enum StdVideoH264ProfileIdc { - STD_VIDEO_H264_PROFILE_IDC_BASELINE = 66, /* Only constrained baseline is supported */ - STD_VIDEO_H264_PROFILE_IDC_MAIN = 77, - STD_VIDEO_H264_PROFILE_IDC_HIGH = 100, - STD_VIDEO_H264_PROFILE_IDC_HIGH_444_PREDICTIVE = 244, - STD_VIDEO_H264_PROFILE_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_PROFILE_IDC_BASELINE = 66, + STD_VIDEO_H264_PROFILE_IDC_MAIN = 77, + STD_VIDEO_H264_PROFILE_IDC_HIGH = 100, + STD_VIDEO_H264_PROFILE_IDC_HIGH_444_PREDICTIVE = 244, + STD_VIDEO_H264_PROFILE_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_PROFILE_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH264ProfileIdc; typedef enum StdVideoH264Level { @@ -66,14 +70,16 @@ typedef enum StdVideoH264Level { STD_VIDEO_H264_LEVEL_6_0 = 16, STD_VIDEO_H264_LEVEL_6_1 = 17, STD_VIDEO_H264_LEVEL_6_2 = 18, - STD_VIDEO_H264_LEVEL_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_LEVEL_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_LEVEL_MAX_ENUM = 0x7FFFFFFF } StdVideoH264Level; typedef enum StdVideoH264PocType { STD_VIDEO_H264_POC_TYPE_0 = 0, STD_VIDEO_H264_POC_TYPE_1 = 1, STD_VIDEO_H264_POC_TYPE_2 = 2, - STD_VIDEO_H264_POC_TYPE_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_POC_TYPE_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_POC_TYPE_MAX_ENUM = 0x7FFFFFFF } StdVideoH264PocType; typedef enum StdVideoH264AspectRatioIdc { @@ -95,14 +101,16 @@ typedef enum StdVideoH264AspectRatioIdc { STD_VIDEO_H264_ASPECT_RATIO_IDC_3_2 = 15, STD_VIDEO_H264_ASPECT_RATIO_IDC_2_1 = 16, STD_VIDEO_H264_ASPECT_RATIO_IDC_EXTENDED_SAR = 255, - STD_VIDEO_H264_ASPECT_RATIO_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_ASPECT_RATIO_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_ASPECT_RATIO_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH264AspectRatioIdc; typedef enum StdVideoH264WeightedBipredIdc { - STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_DEFAULT = 0, + STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_DEFAULT = 0, STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_EXPLICIT = 1, STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_IMPLICIT = 2, - STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH264WeightedBipredIdc; typedef enum StdVideoH264ModificationOfPicNumsIdc { @@ -110,7 +118,8 @@ typedef enum StdVideoH264ModificationOfPicNumsIdc { STD_VIDEO_H264_MODIFICATION_OF_PIC_NUMS_IDC_SHORT_TERM_ADD = 1, STD_VIDEO_H264_MODIFICATION_OF_PIC_NUMS_IDC_LONG_TERM = 2, STD_VIDEO_H264_MODIFICATION_OF_PIC_NUMS_IDC_END = 3, - STD_VIDEO_H264_MODIFICATION_OF_PIC_NUMS_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_MODIFICATION_OF_PIC_NUMS_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_MODIFICATION_OF_PIC_NUMS_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH264ModificationOfPicNumsIdc; typedef enum StdVideoH264MemMgmtControlOp { @@ -121,40 +130,41 @@ typedef enum StdVideoH264MemMgmtControlOp { STD_VIDEO_H264_MEM_MGMT_CONTROL_OP_SET_MAX_LONG_TERM_INDEX = 4, STD_VIDEO_H264_MEM_MGMT_CONTROL_OP_UNMARK_ALL = 5, STD_VIDEO_H264_MEM_MGMT_CONTROL_OP_MARK_CURRENT_AS_LONG_TERM = 6, - STD_VIDEO_H264_MEM_MGMT_CONTROL_OP_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_MEM_MGMT_CONTROL_OP_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_MEM_MGMT_CONTROL_OP_MAX_ENUM = 0x7FFFFFFF } StdVideoH264MemMgmtControlOp; typedef enum StdVideoH264CabacInitIdc { STD_VIDEO_H264_CABAC_INIT_IDC_0 = 0, STD_VIDEO_H264_CABAC_INIT_IDC_1 = 1, STD_VIDEO_H264_CABAC_INIT_IDC_2 = 2, - STD_VIDEO_H264_CABAC_INIT_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_CABAC_INIT_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_CABAC_INIT_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH264CabacInitIdc; typedef enum StdVideoH264DisableDeblockingFilterIdc { STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_DISABLED = 0, STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_ENABLED = 1, STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_PARTIAL = 2, - STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH264DisableDeblockingFilterIdc; typedef enum StdVideoH264SliceType { - STD_VIDEO_H264_SLICE_TYPE_P = 0, - STD_VIDEO_H264_SLICE_TYPE_B = 1, - STD_VIDEO_H264_SLICE_TYPE_I = 2, - // reserved STD_VIDEO_H264_SLICE_TYPE_SP = 3, - // reserved STD_VIDEO_H264_SLICE_TYPE_SI = 4, - STD_VIDEO_H264_SLICE_TYPE_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_SLICE_TYPE_P = 0, + STD_VIDEO_H264_SLICE_TYPE_B = 1, + STD_VIDEO_H264_SLICE_TYPE_I = 2, + STD_VIDEO_H264_SLICE_TYPE_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_SLICE_TYPE_MAX_ENUM = 0x7FFFFFFF } StdVideoH264SliceType; typedef enum StdVideoH264PictureType { - STD_VIDEO_H264_PICTURE_TYPE_P = 0, - STD_VIDEO_H264_PICTURE_TYPE_B = 1, - STD_VIDEO_H264_PICTURE_TYPE_I = 2, - // reserved STD_VIDEO_H264_PICTURE_TYPE_SP = 3, - // reserved STD_VIDEO_H264_PICTURE_TYPE_SI = 4, + STD_VIDEO_H264_PICTURE_TYPE_P = 0, + STD_VIDEO_H264_PICTURE_TYPE_B = 1, + STD_VIDEO_H264_PICTURE_TYPE_I = 2, STD_VIDEO_H264_PICTURE_TYPE_IDR = 5, - STD_VIDEO_H264_PICTURE_TYPE_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_PICTURE_TYPE_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_PICTURE_TYPE_MAX_ENUM = 0x7FFFFFFF } StdVideoH264PictureType; typedef enum StdVideoH264NonVclNaluType { @@ -165,148 +175,134 @@ typedef enum StdVideoH264NonVclNaluType { STD_VIDEO_H264_NON_VCL_NALU_TYPE_END_OF_SEQUENCE = 4, STD_VIDEO_H264_NON_VCL_NALU_TYPE_END_OF_STREAM = 5, STD_VIDEO_H264_NON_VCL_NALU_TYPE_PRECODED = 6, - STD_VIDEO_H264_NON_VCL_NALU_TYPE_INVALID = 0x7FFFFFFF + STD_VIDEO_H264_NON_VCL_NALU_TYPE_INVALID = 0x7FFFFFFF, + STD_VIDEO_H264_NON_VCL_NALU_TYPE_MAX_ENUM = 0x7FFFFFFF } StdVideoH264NonVclNaluType; - typedef struct StdVideoH264SpsVuiFlags { - uint32_t aspect_ratio_info_present_flag : 1; - uint32_t overscan_info_present_flag : 1; - uint32_t overscan_appropriate_flag : 1; - uint32_t video_signal_type_present_flag : 1; - uint32_t video_full_range_flag : 1; - uint32_t color_description_present_flag : 1; - uint32_t chroma_loc_info_present_flag : 1; - uint32_t timing_info_present_flag : 1; - uint32_t fixed_frame_rate_flag : 1; - uint32_t bitstream_restriction_flag : 1; - uint32_t nal_hrd_parameters_present_flag : 1; - uint32_t vcl_hrd_parameters_present_flag : 1; + uint32_t aspect_ratio_info_present_flag : 1; + uint32_t overscan_info_present_flag : 1; + uint32_t overscan_appropriate_flag : 1; + uint32_t video_signal_type_present_flag : 1; + uint32_t video_full_range_flag : 1; + uint32_t color_description_present_flag : 1; + uint32_t chroma_loc_info_present_flag : 1; + uint32_t timing_info_present_flag : 1; + uint32_t fixed_frame_rate_flag : 1; + uint32_t bitstream_restriction_flag : 1; + uint32_t nal_hrd_parameters_present_flag : 1; + uint32_t vcl_hrd_parameters_present_flag : 1; } StdVideoH264SpsVuiFlags; -typedef struct StdVideoH264HrdParameters { // hrd_parameters - uint8_t cpb_cnt_minus1; - uint8_t bit_rate_scale; - uint8_t cpb_size_scale; - uint32_t bit_rate_value_minus1[STD_VIDEO_H264_CPB_CNT_LIST_SIZE]; // cpb_cnt_minus1 number of valid elements - uint32_t cpb_size_value_minus1[STD_VIDEO_H264_CPB_CNT_LIST_SIZE]; // cpb_cnt_minus1 number of valid elements - uint8_t cbr_flag[STD_VIDEO_H264_CPB_CNT_LIST_SIZE]; // cpb_cnt_minus1 number of valid elements - uint32_t initial_cpb_removal_delay_length_minus1; - uint32_t cpb_removal_delay_length_minus1; - uint32_t dpb_output_delay_length_minus1; - uint32_t time_offset_length; +typedef struct StdVideoH264HrdParameters { + uint8_t cpb_cnt_minus1; + uint8_t bit_rate_scale; + uint8_t cpb_size_scale; + uint32_t bit_rate_value_minus1[STD_VIDEO_H264_CPB_CNT_LIST_SIZE]; + uint32_t cpb_size_value_minus1[STD_VIDEO_H264_CPB_CNT_LIST_SIZE]; + uint8_t cbr_flag[STD_VIDEO_H264_CPB_CNT_LIST_SIZE]; + uint32_t initial_cpb_removal_delay_length_minus1; + uint32_t cpb_removal_delay_length_minus1; + uint32_t dpb_output_delay_length_minus1; + uint32_t time_offset_length; } StdVideoH264HrdParameters; typedef struct StdVideoH264SequenceParameterSetVui { - StdVideoH264AspectRatioIdc aspect_ratio_idc; - uint16_t sar_width; - uint16_t sar_height; - uint8_t video_format; - uint8_t color_primaries; - uint8_t transfer_characteristics; - uint8_t matrix_coefficients; - uint32_t num_units_in_tick; - uint32_t time_scale; - StdVideoH264HrdParameters* pHrdParameters; // must be a valid ptr to hrd_parameters, if nal_hrd_parameters_present_flag or vcl_hrd_parameters_present_flag are set - uint8_t max_num_reorder_frames; - uint8_t max_dec_frame_buffering; - StdVideoH264SpsVuiFlags flags; + StdVideoH264AspectRatioIdc aspect_ratio_idc; + uint16_t sar_width; + uint16_t sar_height; + uint8_t video_format; + uint8_t color_primaries; + uint8_t transfer_characteristics; + uint8_t matrix_coefficients; + uint32_t num_units_in_tick; + uint32_t time_scale; + StdVideoH264HrdParameters* pHrdParameters; + uint8_t max_num_reorder_frames; + uint8_t max_dec_frame_buffering; + StdVideoH264SpsVuiFlags flags; } StdVideoH264SequenceParameterSetVui; typedef struct StdVideoH264SpsFlags { - uint32_t constraint_set0_flag : 1; - uint32_t constraint_set1_flag : 1; - uint32_t constraint_set2_flag : 1; - uint32_t constraint_set3_flag : 1; - uint32_t constraint_set4_flag : 1; - uint32_t constraint_set5_flag : 1; - uint32_t direct_8x8_inference_flag : 1; - uint32_t mb_adaptive_frame_field_flag : 1; - uint32_t frame_mbs_only_flag : 1; - uint32_t delta_pic_order_always_zero_flag : 1; - uint32_t separate_colour_plane_flag : 1; - uint32_t gaps_in_frame_num_value_allowed_flag : 1; - uint32_t qpprime_y_zero_transform_bypass_flag : 1; - uint32_t frame_cropping_flag : 1; - uint32_t seq_scaling_matrix_present_flag : 1; - uint32_t vui_parameters_present_flag : 1; + uint32_t constraint_set0_flag : 1; + uint32_t constraint_set1_flag : 1; + uint32_t constraint_set2_flag : 1; + uint32_t constraint_set3_flag : 1; + uint32_t constraint_set4_flag : 1; + uint32_t constraint_set5_flag : 1; + uint32_t direct_8x8_inference_flag : 1; + uint32_t mb_adaptive_frame_field_flag : 1; + uint32_t frame_mbs_only_flag : 1; + uint32_t delta_pic_order_always_zero_flag : 1; + uint32_t separate_colour_plane_flag : 1; + uint32_t gaps_in_frame_num_value_allowed_flag : 1; + uint32_t qpprime_y_zero_transform_bypass_flag : 1; + uint32_t frame_cropping_flag : 1; + uint32_t seq_scaling_matrix_present_flag : 1; + uint32_t vui_parameters_present_flag : 1; } StdVideoH264SpsFlags; -typedef struct StdVideoH264ScalingLists -{ - // scaling_list_present_mask has one bit for each - // seq_scaling_list_present_flag[i] for SPS OR - // pic_scaling_list_present_flag[i] for PPS, - // bit 0 - 5 are for each entry of ScalingList4x4 - // bit 6 - 7 are for each entry plus 6 for ScalingList8x8 - uint8_t scaling_list_present_mask; - // use_default_scaling_matrix_mask has one bit for each - // UseDefaultScalingMatrix4x4Flag[ i ] and - // UseDefaultScalingMatrix8x8Flag[ i - 6 ] for SPS OR PPS - // bit 0 - 5 are for each entry of ScalingList4x4 - // bit 6 - 7 are for each entry plus 6 for ScalingList8x8 - uint8_t use_default_scaling_matrix_mask; - uint8_t ScalingList4x4[STD_VIDEO_H264_SCALING_LIST_4X4_NUM_LISTS][STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS]; - uint8_t ScalingList8x8[STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS][STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS]; +typedef struct StdVideoH264ScalingLists { + uint8_t scaling_list_present_mask; + uint8_t use_default_scaling_matrix_mask; + uint8_t ScalingList4x4[STD_VIDEO_H264_SCALING_LIST_4X4_NUM_LISTS][STD_VIDEO_H264_SCALING_LIST_4X4_NUM_ELEMENTS]; + uint8_t ScalingList8x8[STD_VIDEO_H264_SCALING_LIST_8X8_NUM_LISTS][STD_VIDEO_H264_SCALING_LIST_8X8_NUM_ELEMENTS]; } StdVideoH264ScalingLists; -typedef struct StdVideoH264SequenceParameterSet -{ - StdVideoH264ProfileIdc profile_idc; - StdVideoH264Level level_idc; - uint8_t seq_parameter_set_id; - StdVideoH264ChromaFormatIdc chroma_format_idc; - uint8_t bit_depth_luma_minus8; - uint8_t bit_depth_chroma_minus8; - uint8_t log2_max_frame_num_minus4; - StdVideoH264PocType pic_order_cnt_type; - uint8_t log2_max_pic_order_cnt_lsb_minus4; - int32_t offset_for_non_ref_pic; - int32_t offset_for_top_to_bottom_field; - uint8_t num_ref_frames_in_pic_order_cnt_cycle; - uint8_t max_num_ref_frames; - uint32_t pic_width_in_mbs_minus1; - uint32_t pic_height_in_map_units_minus1; - uint32_t frame_crop_left_offset; - uint32_t frame_crop_right_offset; - uint32_t frame_crop_top_offset; - uint32_t frame_crop_bottom_offset; - StdVideoH264SpsFlags flags; - // pOffsetForRefFrame is a pointer representing the offset_for_ref_frame array with num_ref_frames_in_pic_order_cnt_cycle number of elements - // If pOffsetForRefFrame has nullptr value, then num_ref_frames_in_pic_order_cnt_cycle must also be "0". - int32_t* pOffsetForRefFrame; - StdVideoH264ScalingLists* pScalingLists; // Must be a valid pointer if seq_scaling_matrix_present_flag is set - StdVideoH264SequenceParameterSetVui* pSequenceParameterSetVui; // Must be a valid pointer if StdVideoH264SpsFlags:vui_parameters_present_flag is set +typedef struct StdVideoH264SequenceParameterSet { + StdVideoH264ProfileIdc profile_idc; + StdVideoH264Level level_idc; + uint8_t seq_parameter_set_id; + StdVideoH264ChromaFormatIdc chroma_format_idc; + uint8_t bit_depth_luma_minus8; + uint8_t bit_depth_chroma_minus8; + uint8_t log2_max_frame_num_minus4; + StdVideoH264PocType pic_order_cnt_type; + uint8_t log2_max_pic_order_cnt_lsb_minus4; + int32_t offset_for_non_ref_pic; + int32_t offset_for_top_to_bottom_field; + uint8_t num_ref_frames_in_pic_order_cnt_cycle; + uint8_t max_num_ref_frames; + uint32_t pic_width_in_mbs_minus1; + uint32_t pic_height_in_map_units_minus1; + uint32_t frame_crop_left_offset; + uint32_t frame_crop_right_offset; + uint32_t frame_crop_top_offset; + uint32_t frame_crop_bottom_offset; + StdVideoH264SpsFlags flags; + int32_t* pOffsetForRefFrame; + StdVideoH264ScalingLists* pScalingLists; + StdVideoH264SequenceParameterSetVui* pSequenceParameterSetVui; } StdVideoH264SequenceParameterSet; typedef struct StdVideoH264PpsFlags { - uint32_t transform_8x8_mode_flag : 1; - uint32_t redundant_pic_cnt_present_flag : 1; - uint32_t constrained_intra_pred_flag : 1; - uint32_t deblocking_filter_control_present_flag : 1; - uint32_t weighted_bipred_idc_flag : 1; - uint32_t weighted_pred_flag : 1; - uint32_t pic_order_present_flag : 1; - uint32_t entropy_coding_mode_flag : 1; - uint32_t pic_scaling_matrix_present_flag : 1; + uint32_t transform_8x8_mode_flag : 1; + uint32_t redundant_pic_cnt_present_flag : 1; + uint32_t constrained_intra_pred_flag : 1; + uint32_t deblocking_filter_control_present_flag : 1; + uint32_t weighted_bipred_idc_flag : 1; + uint32_t weighted_pred_flag : 1; + uint32_t pic_order_present_flag : 1; + uint32_t entropy_coding_mode_flag : 1; + uint32_t pic_scaling_matrix_present_flag : 1; } StdVideoH264PpsFlags; -typedef struct StdVideoH264PictureParameterSet -{ - uint8_t seq_parameter_set_id; - uint8_t pic_parameter_set_id; - uint8_t num_ref_idx_l0_default_active_minus1; - uint8_t num_ref_idx_l1_default_active_minus1; - StdVideoH264WeightedBipredIdc weighted_bipred_idc; - int8_t pic_init_qp_minus26; - int8_t pic_init_qs_minus26; - int8_t chroma_qp_index_offset; - int8_t second_chroma_qp_index_offset; - StdVideoH264PpsFlags flags; - StdVideoH264ScalingLists* pScalingLists; // Must be a valid pointer if StdVideoH264PpsFlags::pic_scaling_matrix_present_flag is set. +typedef struct StdVideoH264PictureParameterSet { + uint8_t seq_parameter_set_id; + uint8_t pic_parameter_set_id; + uint8_t num_ref_idx_l0_default_active_minus1; + uint8_t num_ref_idx_l1_default_active_minus1; + StdVideoH264WeightedBipredIdc weighted_bipred_idc; + int8_t pic_init_qp_minus26; + int8_t pic_init_qs_minus26; + int8_t chroma_qp_index_offset; + int8_t second_chroma_qp_index_offset; + StdVideoH264PpsFlags flags; + StdVideoH264ScalingLists* pScalingLists; } StdVideoH264PictureParameterSet; + #ifdef __cplusplus } #endif -#endif // VULKAN_VIDEO_CODEC_H264STD_H_ +#endif diff --git a/external/vk_video/vulkan_video_codec_h264std_decode.h b/external/vk_video/vulkan_video_codec_h264std_decode.h index 6f2d6d7e..dda60097 100644 --- a/external/vk_video/vulkan_video_codec_h264std_decode.h +++ b/external/vk_video/vulkan_video_codec_h264std_decode.h @@ -1,91 +1,93 @@ +#ifndef VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ +#define VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 1 + /* -** Copyright (c) 2019-2020 The Khronos Group Inc. +** Copyright 2015-2021 The Khronos Group Inc. ** ** SPDX-License-Identifier: Apache-2.0 */ -#ifndef VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ -#define VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 1 +/* +** This header is generated from the Khronos Vulkan XML API Registry. +** +*/ + #ifdef __cplusplus extern "C" { #endif -#include "vk_video/vulkan_video_codec_h264std.h" -// ************************************************* -// Video H.264 Decode related parameters: -// ************************************************* +#define vulkan_video_codec_h264std_decode 1 +#define STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE 2 #define STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE 15 typedef enum StdVideoDecodeH264FieldOrderCount { - STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_TOP = 0, - STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_BOTTOM = 1, - STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE = 2, - STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_INVALID = 0x7FFFFFFF -} StdVideoDecodeH264FieldOrderCnt; - + STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_TOP = 0, + STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_BOTTOM = 1, + STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_INVALID = 0x7FFFFFFF, + STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_MAX_ENUM = 0x7FFFFFFF +} StdVideoDecodeH264FieldOrderCount; typedef struct StdVideoDecodeH264PictureInfoFlags { - uint32_t field_pic_flag : 1; // Is field picture - uint32_t is_intra : 1; // Is intra picture - uint32_t bottom_field_flag : 1; // bottom (true) or top (false) field if field_pic_flag is set. - uint32_t is_reference : 1; // This only applies to picture info, and not to the DPB lists. - uint32_t complementary_field_pair : 1; // complementary field pair, complementary non-reference field pair, complementary reference field pair + uint32_t field_pic_flag : 1; + uint32_t is_intra : 1; + uint32_t IdrPicFlag : 1; + uint32_t bottom_field_flag : 1; + uint32_t is_reference : 1; + uint32_t complementary_field_pair : 1; } StdVideoDecodeH264PictureInfoFlags; typedef struct StdVideoDecodeH264PictureInfo { - uint8_t seq_parameter_set_id; // Selecting SPS from the Picture Parameters - uint8_t pic_parameter_set_id; // Selecting PPS from the Picture Parameters and the SPS - uint16_t reserved; // for structure members 32-bit packing/alignment - uint16_t frame_num; // 7.4.3 Slice header semantics - uint16_t idr_pic_id; // 7.4.3 Slice header semantics - // PicOrderCnt is based on TopFieldOrderCnt and BottomFieldOrderCnt. See 8.2.1 Decoding process for picture order count type 0 - 2 - int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; // TopFieldOrderCnt and BottomFieldOrderCnt fields. - StdVideoDecodeH264PictureInfoFlags flags; + uint8_t seq_parameter_set_id; + uint8_t pic_parameter_set_id; + uint16_t reserved; + uint16_t frame_num; + uint16_t idr_pic_id; + int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; + StdVideoDecodeH264PictureInfoFlags flags; } StdVideoDecodeH264PictureInfo; typedef struct StdVideoDecodeH264ReferenceInfoFlags { - uint32_t top_field_flag : 1; // Reference is used for top field reference. - uint32_t bottom_field_flag : 1; // Reference is used for bottom field reference. - uint32_t is_long_term : 1; // this is a long term reference - uint32_t is_non_existing : 1; // Must be handled in accordance with 8.2.5.2: Decoding process for gaps in frame_num + uint32_t top_field_flag : 1; + uint32_t bottom_field_flag : 1; + uint32_t is_long_term : 1; + uint32_t is_non_existing : 1; } StdVideoDecodeH264ReferenceInfoFlags; typedef struct StdVideoDecodeH264ReferenceInfo { - // FrameNum = is_long_term ? long_term_frame_idx : frame_num - uint16_t FrameNum; // 7.4.3.3 Decoded reference picture marking semantics - uint16_t reserved; // for structure members 32-bit packing/alignment - int32_t PicOrderCnt[2]; // TopFieldOrderCnt and BottomFieldOrderCnt fields. - StdVideoDecodeH264ReferenceInfoFlags flags; + uint16_t FrameNum; + uint16_t reserved; + int32_t PicOrderCnt[2]; + StdVideoDecodeH264ReferenceInfoFlags flags; } StdVideoDecodeH264ReferenceInfo; typedef struct StdVideoDecodeH264MvcElementFlags { - uint32_t non_idr : 1; - uint32_t anchor_pic : 1; - uint32_t inter_view : 1; + uint32_t non_idr : 1; + uint32_t anchor_pic : 1; + uint32_t inter_view : 1; } StdVideoDecodeH264MvcElementFlags; typedef struct StdVideoDecodeH264MvcElement { - StdVideoDecodeH264MvcElementFlags flags; - uint16_t viewOrderIndex; - uint16_t viewId; - uint16_t temporalId; // move out? - uint16_t priorityId; // move out? - uint16_t numOfAnchorRefsInL0; - uint16_t viewIdOfAnchorRefsInL0[STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE]; - uint16_t numOfAnchorRefsInL1; - uint16_t viewIdOfAnchorRefsInL1[STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE]; - uint16_t numOfNonAnchorRefsInL0; - uint16_t viewIdOfNonAnchorRefsInL0[STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE]; - uint16_t numOfNonAnchorRefsInL1; - uint16_t viewIdOfNonAnchorRefsInL1[STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE]; + StdVideoDecodeH264MvcElementFlags flags; + uint16_t viewOrderIndex; + uint16_t viewId; + uint16_t temporalId; + uint16_t priorityId; + uint16_t numOfAnchorRefsInL0; + uint16_t viewIdOfAnchorRefsInL0[STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE]; + uint16_t numOfAnchorRefsInL1; + uint16_t viewIdOfAnchorRefsInL1[STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE]; + uint16_t numOfNonAnchorRefsInL0; + uint16_t viewIdOfNonAnchorRefsInL0[STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE]; + uint16_t numOfNonAnchorRefsInL1; + uint16_t viewIdOfNonAnchorRefsInL1[STD_VIDEO_DECODE_H264_MVC_REF_LIST_SIZE]; } StdVideoDecodeH264MvcElement; typedef struct StdVideoDecodeH264Mvc { - uint32_t viewId0; - uint32_t mvcElementCount; - StdVideoDecodeH264MvcElement* pMvcElements; + uint32_t viewId0; + uint32_t mvcElementCount; + StdVideoDecodeH264MvcElement* pMvcElements; } StdVideoDecodeH264Mvc; @@ -93,4 +95,4 @@ typedef struct StdVideoDecodeH264Mvc { } #endif -#endif // VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ +#endif diff --git a/external/vk_video/vulkan_video_codec_h264std_encode.h b/external/vk_video/vulkan_video_codec_h264std_encode.h index f3a0d3ad..4387908b 100644 --- a/external/vk_video/vulkan_video_codec_h264std_encode.h +++ b/external/vk_video/vulkan_video_codec_h264std_encode.h @@ -1,89 +1,92 @@ +#ifndef VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_ +#define VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_ 1 + /* -** Copyright (c) 2019-2021 The Khronos Group Inc. +** Copyright 2015-2021 The Khronos Group Inc. ** ** SPDX-License-Identifier: Apache-2.0 */ -#ifndef VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_ -#define VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_ 1 +/* +** This header is generated from the Khronos Vulkan XML API Registry. +** +*/ + #ifdef __cplusplus extern "C" { #endif -#include "vk_video/vulkan_video_codec_h264std.h" -// ************************************************* -// Video H.264 Encode related parameters: -// ************************************************* +#define vulkan_video_codec_h264std_encode 1 typedef struct StdVideoEncodeH264SliceHeaderFlags { - uint32_t idr_flag : 1; - uint32_t is_reference_flag : 1; - uint32_t num_ref_idx_active_override_flag : 1; - uint32_t no_output_of_prior_pics_flag : 1; - uint32_t long_term_reference_flag : 1; - uint32_t adaptive_ref_pic_marking_mode_flag : 1; - uint32_t no_prior_references_available_flag : 1; + uint32_t idr_flag : 1; + uint32_t is_reference_flag : 1; + uint32_t num_ref_idx_active_override_flag : 1; + uint32_t no_output_of_prior_pics_flag : 1; + uint32_t long_term_reference_flag : 1; + uint32_t adaptive_ref_pic_marking_mode_flag : 1; + uint32_t no_prior_references_available_flag : 1; } StdVideoEncodeH264SliceHeaderFlags; typedef struct StdVideoEncodeH264PictureInfoFlags { - uint32_t idr_flag : 1; - uint32_t is_reference_flag : 1; - uint32_t long_term_reference_flag : 1; + uint32_t idr_flag : 1; + uint32_t is_reference_flag : 1; + uint32_t long_term_reference_flag : 1; } StdVideoEncodeH264PictureInfoFlags; typedef struct StdVideoEncodeH264RefMgmtFlags { - uint32_t ref_pic_list_modification_l0_flag : 1; - uint32_t ref_pic_list_modification_l1_flag : 1; + uint32_t ref_pic_list_modification_l0_flag : 1; + uint32_t ref_pic_list_modification_l1_flag : 1; } StdVideoEncodeH264RefMgmtFlags; typedef struct StdVideoEncodeH264RefListModEntry { - StdVideoH264ModificationOfPicNumsIdc modification_of_pic_nums_idc; - uint16_t abs_diff_pic_num_minus1; - uint16_t long_term_pic_num; + StdVideoH264ModificationOfPicNumsIdc modification_of_pic_nums_idc; + uint16_t abs_diff_pic_num_minus1; + uint16_t long_term_pic_num; } StdVideoEncodeH264RefListModEntry; typedef struct StdVideoEncodeH264RefPicMarkingEntry { - StdVideoH264MemMgmtControlOp operation; - uint16_t difference_of_pic_nums_minus1; - uint16_t long_term_pic_num; - uint16_t long_term_frame_idx; - uint16_t max_long_term_frame_idx_plus1; + StdVideoH264MemMgmtControlOp operation; + uint16_t difference_of_pic_nums_minus1; + uint16_t long_term_pic_num; + uint16_t long_term_frame_idx; + uint16_t max_long_term_frame_idx_plus1; } StdVideoEncodeH264RefPicMarkingEntry; typedef struct StdVideoEncodeH264RefMemMgmtCtrlOperations { - StdVideoEncodeH264RefMgmtFlags flags; - uint8_t refList0ModOpCount; - StdVideoEncodeH264RefListModEntry* pRefList0ModOperations; - uint8_t refList1ModOpCount; - StdVideoEncodeH264RefListModEntry* pRefList1ModOperations; - uint8_t refPicMarkingOpCount; - StdVideoEncodeH264RefPicMarkingEntry* pRefPicMarkingOperations; + StdVideoEncodeH264RefMgmtFlags flags; + uint8_t refList0ModOpCount; + StdVideoEncodeH264RefListModEntry* pRefList0ModOperations; + uint8_t refList1ModOpCount; + StdVideoEncodeH264RefListModEntry* pRefList1ModOperations; + uint8_t refPicMarkingOpCount; + StdVideoEncodeH264RefPicMarkingEntry* pRefPicMarkingOperations; } StdVideoEncodeH264RefMemMgmtCtrlOperations; typedef struct StdVideoEncodeH264PictureInfo { - StdVideoEncodeH264PictureInfoFlags flags; - StdVideoH264PictureType pictureType; - uint32_t frameNum; - uint32_t pictureOrderCount; - uint16_t long_term_pic_num; - uint16_t long_term_frame_idx; + StdVideoEncodeH264PictureInfoFlags flags; + StdVideoH264PictureType pictureType; + uint32_t frameNum; + uint32_t pictureOrderCount; + uint16_t long_term_pic_num; + uint16_t long_term_frame_idx; } StdVideoEncodeH264PictureInfo; typedef struct StdVideoEncodeH264SliceHeader { - StdVideoEncodeH264SliceHeaderFlags flags; - StdVideoH264SliceType slice_type; - uint8_t seq_parameter_set_id; - uint8_t pic_parameter_set_id; - uint16_t idr_pic_id; - uint8_t num_ref_idx_l0_active_minus1; - uint8_t num_ref_idx_l1_active_minus1; - StdVideoH264CabacInitIdc cabac_init_idc; - StdVideoH264DisableDeblockingFilterIdc disable_deblocking_filter_idc; - int8_t slice_alpha_c0_offset_div2; - int8_t slice_beta_offset_div2; - StdVideoEncodeH264RefMemMgmtCtrlOperations* pMemMgmtCtrlOperations; + StdVideoEncodeH264SliceHeaderFlags flags; + StdVideoH264SliceType slice_type; + uint8_t seq_parameter_set_id; + uint8_t pic_parameter_set_id; + uint16_t idr_pic_id; + uint8_t num_ref_idx_l0_active_minus1; + uint8_t num_ref_idx_l1_active_minus1; + StdVideoH264CabacInitIdc cabac_init_idc; + StdVideoH264DisableDeblockingFilterIdc disable_deblocking_filter_idc; + int8_t slice_alpha_c0_offset_div2; + int8_t slice_beta_offset_div2; + StdVideoEncodeH264RefMemMgmtCtrlOperations* pMemMgmtCtrlOperations; } StdVideoEncodeH264SliceHeader; @@ -91,4 +94,4 @@ typedef struct StdVideoEncodeH264SliceHeader { } #endif -#endif // VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_ +#endif diff --git a/external/vk_video/vulkan_video_codec_h265std.h b/external/vk_video/vulkan_video_codec_h265std.h index 179c6b70..5690f368 100644 --- a/external/vk_video/vulkan_video_codec_h265std.h +++ b/external/vk_video/vulkan_video_codec_h265std.h @@ -1,27 +1,30 @@ +#ifndef VULKAN_VIDEO_CODEC_H265STD_H_ +#define VULKAN_VIDEO_CODEC_H265STD_H_ 1 + /* -** Copyright (c) 2019-2021 The Khronos Group Inc. +** Copyright 2015-2021 The Khronos Group Inc. ** ** SPDX-License-Identifier: Apache-2.0 */ -#ifndef VULKAN_VIDEO_CODEC_H265STD_H_ -#define VULKAN_VIDEO_CODEC_H265STD_H_ 1 +/* +** This header is generated from the Khronos Vulkan XML API Registry. +** +*/ + #ifdef __cplusplus extern "C" { #endif -#include "vk_video/vulkan_video_codecs_common.h" + +#define vulkan_video_codec_h265std 1 // Vulkan 0.5 version number WIP #define VK_STD_VULKAN_VIDEO_CODEC_H265_API_VERSION_0_9_5 VK_MAKE_VIDEO_STD_VERSION(0, 9, 5) // Patch version should always be set to 0 -// Format must be in the form XX.XX where the first two digits are the major and the second two, the minor. -#define VK_STD_VULKAN_VIDEO_CODEC_H265_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_API_VERSION_0_9_5 -#define VK_STD_VULKAN_VIDEO_CODEC_H265_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265" - -#define STD_VIDEO_H265_CPB_CNT_LIST_SIZE 32 #define STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE 7 +#define STD_VIDEO_H265_CPB_CNT_LIST_SIZE 32 #define STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS 6 #define STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS 16 #define STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS 6 @@ -30,27 +33,31 @@ extern "C" { #define STD_VIDEO_H265_SCALING_LIST_16X16_NUM_ELEMENTS 64 #define STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS 2 #define STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS 64 -#define STD_VIDEO_H265_CHROMA_QP_OFFSET_LIST_SIZE 6 -#define STD_VIDEO_H265_CHROMA_QP_OFFSET_TILE_COLS_LIST_SIZE 19 -#define STD_VIDEO_H265_CHROMA_QP_OFFSET_TILE_ROWS_LIST_SIZE 21 #define STD_VIDEO_H265_PREDICTOR_PALETTE_COMPONENTS_LIST_SIZE 3 #define STD_VIDEO_H265_PREDICTOR_PALETTE_COMP_ENTRIES_LIST_SIZE 128 +#define STD_VIDEO_H265_CHROMA_QP_OFFSET_TILE_COLS_LIST_SIZE 19 +#define STD_VIDEO_H265_CHROMA_QP_OFFSET_TILE_ROWS_LIST_SIZE 21 +#define STD_VIDEO_H265_CHROMA_QP_OFFSET_LIST_SIZE 6 +#define VK_STD_VULKAN_VIDEO_CODEC_H265_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_API_VERSION_0_9_5 +#define VK_STD_VULKAN_VIDEO_CODEC_H265_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265" typedef enum StdVideoH265ChromaFormatIdc { - STD_VIDEO_H265_CHROMA_FORMAT_IDC_MONOCHROME = 0, - STD_VIDEO_H265_CHROMA_FORMAT_IDC_420 = 1, - STD_VIDEO_H265_CHROMA_FORMAT_IDC_422 = 2, - STD_VIDEO_H265_CHROMA_FORMAT_IDC_444 = 3, - STD_VIDEO_H265_CHROMA_FORMAT_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H265_CHROMA_FORMAT_IDC_MONOCHROME = 0, + STD_VIDEO_H265_CHROMA_FORMAT_IDC_420 = 1, + STD_VIDEO_H265_CHROMA_FORMAT_IDC_422 = 2, + STD_VIDEO_H265_CHROMA_FORMAT_IDC_444 = 3, + STD_VIDEO_H265_CHROMA_FORMAT_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H265_CHROMA_FORMAT_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH265ChromaFormatIdc; typedef enum StdVideoH265ProfileIdc { - STD_VIDEO_H265_PROFILE_IDC_MAIN = 1, - STD_VIDEO_H265_PROFILE_IDC_MAIN_10 = 2, - STD_VIDEO_H265_PROFILE_IDC_MAIN_STILL_PICTURE = 3, - STD_VIDEO_H265_PROFILE_IDC_FORMAT_RANGE_EXTENSIONS = 4, - STD_VIDEO_H265_PROFILE_IDC_SCC_EXTENSIONS = 9, - STD_VIDEO_H265_PROFILE_IDC_INVALID = 0x7FFFFFFF + STD_VIDEO_H265_PROFILE_IDC_MAIN = 1, + STD_VIDEO_H265_PROFILE_IDC_MAIN_10 = 2, + STD_VIDEO_H265_PROFILE_IDC_MAIN_STILL_PICTURE = 3, + STD_VIDEO_H265_PROFILE_IDC_FORMAT_RANGE_EXTENSIONS = 4, + STD_VIDEO_H265_PROFILE_IDC_SCC_EXTENSIONS = 9, + STD_VIDEO_H265_PROFILE_IDC_INVALID = 0x7FFFFFFF, + STD_VIDEO_H265_PROFILE_IDC_MAX_ENUM = 0x7FFFFFFF } StdVideoH265ProfileIdc; typedef enum StdVideoH265Level { @@ -67,305 +74,287 @@ typedef enum StdVideoH265Level { STD_VIDEO_H265_LEVEL_6_0 = 10, STD_VIDEO_H265_LEVEL_6_1 = 11, STD_VIDEO_H265_LEVEL_6_2 = 12, - STD_VIDEO_H265_LEVEL_INVALID = 0x7FFFFFFF + STD_VIDEO_H265_LEVEL_INVALID = 0x7FFFFFFF, + STD_VIDEO_H265_LEVEL_MAX_ENUM = 0x7FFFFFFF } StdVideoH265Level; typedef enum StdVideoH265SliceType { STD_VIDEO_H265_SLICE_TYPE_B = 0, STD_VIDEO_H265_SLICE_TYPE_P = 1, STD_VIDEO_H265_SLICE_TYPE_I = 2, - STD_VIDEO_H265_SLICE_TYPE_INVALID = 0x7FFFFFFF + STD_VIDEO_H265_SLICE_TYPE_INVALID = 0x7FFFFFFF, + STD_VIDEO_H265_SLICE_TYPE_MAX_ENUM = 0x7FFFFFFF } StdVideoH265SliceType; typedef enum StdVideoH265PictureType { - STD_VIDEO_H265_PICTURE_TYPE_P = 0, - STD_VIDEO_H265_PICTURE_TYPE_B = 1, - STD_VIDEO_H265_PICTURE_TYPE_I = 2, + STD_VIDEO_H265_PICTURE_TYPE_P = 0, + STD_VIDEO_H265_PICTURE_TYPE_B = 1, + STD_VIDEO_H265_PICTURE_TYPE_I = 2, STD_VIDEO_H265_PICTURE_TYPE_IDR = 3, - STD_VIDEO_H265_PICTURE_TYPE_INVALID = 0x7FFFFFFF + STD_VIDEO_H265_PICTURE_TYPE_INVALID = 0x7FFFFFFF, + STD_VIDEO_H265_PICTURE_TYPE_MAX_ENUM = 0x7FFFFFFF } StdVideoH265PictureType; - -typedef struct StdVideoH265DecPicBufMgr -{ - uint32_t max_latency_increase_plus1[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; - uint8_t max_dec_pic_buffering_minus1[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; - uint8_t max_num_reorder_pics[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; +typedef struct StdVideoH265DecPicBufMgr { + uint32_t max_latency_increase_plus1[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; + uint8_t max_dec_pic_buffering_minus1[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; + uint8_t max_num_reorder_pics[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; } StdVideoH265DecPicBufMgr; -typedef struct StdVideoH265SubLayerHrdParameters { // sub_layer_hrd_parameters - uint32_t bit_rate_value_minus1[STD_VIDEO_H265_CPB_CNT_LIST_SIZE]; - uint32_t cpb_size_value_minus1[STD_VIDEO_H265_CPB_CNT_LIST_SIZE]; - uint32_t cpb_size_du_value_minus1[STD_VIDEO_H265_CPB_CNT_LIST_SIZE]; - uint32_t bit_rate_du_value_minus1[STD_VIDEO_H265_CPB_CNT_LIST_SIZE]; - uint32_t cbr_flag; // each bit represents a range of CpbCounts (bit 0 - cpb_cnt_minus1) per sub-layer +typedef struct StdVideoH265SubLayerHrdParameters { + uint32_t bit_rate_value_minus1[STD_VIDEO_H265_CPB_CNT_LIST_SIZE]; + uint32_t cpb_size_value_minus1[STD_VIDEO_H265_CPB_CNT_LIST_SIZE]; + uint32_t cpb_size_du_value_minus1[STD_VIDEO_H265_CPB_CNT_LIST_SIZE]; + uint32_t bit_rate_du_value_minus1[STD_VIDEO_H265_CPB_CNT_LIST_SIZE]; + uint32_t cbr_flag; } StdVideoH265SubLayerHrdParameters; typedef struct StdVideoH265HrdFlags { - uint32_t nal_hrd_parameters_present_flag : 1; - uint32_t vcl_hrd_parameters_present_flag : 1; - uint32_t sub_pic_hrd_params_present_flag : 1; - uint32_t sub_pic_cpb_params_in_pic_timing_sei_flag : 1; - uint32_t fixed_pic_rate_general_flag : 8; // each bit represents a sublayer, bit 0 - vps_max_sub_layers_minus1 - uint32_t fixed_pic_rate_within_cvs_flag : 8; // each bit represents a sublayer, bit 0 - vps_max_sub_layers_minus1 - uint32_t low_delay_hrd_flag : 8; // each bit represents a sublayer, bit 0 - vps_max_sub_layers_minus1 + uint32_t nal_hrd_parameters_present_flag : 1; + uint32_t vcl_hrd_parameters_present_flag : 1; + uint32_t sub_pic_hrd_params_present_flag : 1; + uint32_t sub_pic_cpb_params_in_pic_timing_sei_flag : 1; + uint32_t fixed_pic_rate_general_flag : 8; + uint32_t fixed_pic_rate_within_cvs_flag : 8; + uint32_t low_delay_hrd_flag : 8; } StdVideoH265HrdFlags; typedef struct StdVideoH265HrdParameters { - uint8_t tick_divisor_minus2; - uint8_t du_cpb_removal_delay_increment_length_minus1; - uint8_t dpb_output_delay_du_length_minus1; - uint8_t bit_rate_scale; - uint8_t cpb_size_scale; - uint8_t cpb_size_du_scale; - uint8_t initial_cpb_removal_delay_length_minus1; - uint8_t au_cpb_removal_delay_length_minus1; - uint8_t dpb_output_delay_length_minus1; - uint8_t cpb_cnt_minus1[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; - uint16_t elemental_duration_in_tc_minus1[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; - StdVideoH265SubLayerHrdParameters* pSubLayerHrdParametersNal[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; // NAL per layer ptr to sub_layer_hrd_parameters - StdVideoH265SubLayerHrdParameters* pSubLayerHrdParametersVcl[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; // VCL per layer ptr to sub_layer_hrd_parameters - StdVideoH265HrdFlags flags; + uint8_t tick_divisor_minus2; + uint8_t du_cpb_removal_delay_increment_length_minus1; + uint8_t dpb_output_delay_du_length_minus1; + uint8_t bit_rate_scale; + uint8_t cpb_size_scale; + uint8_t cpb_size_du_scale; + uint8_t initial_cpb_removal_delay_length_minus1; + uint8_t au_cpb_removal_delay_length_minus1; + uint8_t dpb_output_delay_length_minus1; + uint8_t cpb_cnt_minus1[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; + uint16_t elemental_duration_in_tc_minus1[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; + StdVideoH265SubLayerHrdParameters* pSubLayerHrdParametersNal[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; + StdVideoH265SubLayerHrdParameters* pSubLayerHrdParametersVcl[STD_VIDEO_H265_SUBLAYERS_MINUS1_LIST_SIZE]; + StdVideoH265HrdFlags flags; } StdVideoH265HrdParameters; typedef struct StdVideoH265VpsFlags { - uint32_t vps_temporal_id_nesting_flag : 1; - uint32_t vps_sub_layer_ordering_info_present_flag : 1; - uint32_t vps_timing_info_present_flag : 1; - uint32_t vps_poc_proportional_to_timing_flag : 1; + uint32_t vps_temporal_id_nesting_flag : 1; + uint32_t vps_sub_layer_ordering_info_present_flag : 1; + uint32_t vps_timing_info_present_flag : 1; + uint32_t vps_poc_proportional_to_timing_flag : 1; } StdVideoH265VpsFlags; -typedef struct StdVideoH265VideoParameterSet -{ - uint8_t vps_video_parameter_set_id; - uint8_t vps_max_sub_layers_minus1; - uint32_t vps_num_units_in_tick; - uint32_t vps_time_scale; - uint32_t vps_num_ticks_poc_diff_one_minus1; - StdVideoH265DecPicBufMgr* pDecPicBufMgr; - StdVideoH265HrdParameters* pHrdParameters; - StdVideoH265VpsFlags flags; +typedef struct StdVideoH265VideoParameterSet { + uint8_t vps_video_parameter_set_id; + uint8_t vps_max_sub_layers_minus1; + uint32_t vps_num_units_in_tick; + uint32_t vps_time_scale; + uint32_t vps_num_ticks_poc_diff_one_minus1; + StdVideoH265DecPicBufMgr* pDecPicBufMgr; + StdVideoH265HrdParameters* pHrdParameters; + StdVideoH265VpsFlags flags; } StdVideoH265VideoParameterSet; -typedef struct StdVideoH265ScalingLists -{ - uint8_t ScalingList4x4[STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS][STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS]; // ScalingList[ 0 ][ MatrixID ][ i ] (sizeID = 0) - uint8_t ScalingList8x8[STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS][STD_VIDEO_H265_SCALING_LIST_8X8_NUM_ELEMENTS]; // ScalingList[ 1 ][ MatrixID ][ i ] (sizeID = 1) - uint8_t ScalingList16x16[STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS][STD_VIDEO_H265_SCALING_LIST_16X16_NUM_ELEMENTS]; // ScalingList[ 2 ][ MatrixID ][ i ] (sizeID = 2) - uint8_t ScalingList32x32[STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS][STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS]; // ScalingList[ 3 ][ MatrixID ][ i ] (sizeID = 3) - uint8_t ScalingListDCCoef16x16[STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS]; // scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8, sizeID = 2 - uint8_t ScalingListDCCoef32x32[STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS]; // scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8. sizeID = 3 +typedef struct StdVideoH265ScalingLists { + uint8_t ScalingList4x4[STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS][STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS]; + uint8_t ScalingList8x8[STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS][STD_VIDEO_H265_SCALING_LIST_8X8_NUM_ELEMENTS]; + uint8_t ScalingList16x16[STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS][STD_VIDEO_H265_SCALING_LIST_16X16_NUM_ELEMENTS]; + uint8_t ScalingList32x32[STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS][STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS]; + uint8_t ScalingListDCCoef16x16[STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS]; + uint8_t ScalingListDCCoef32x32[STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS]; } StdVideoH265ScalingLists; typedef struct StdVideoH265SpsVuiFlags { - uint32_t aspect_ratio_info_present_flag : 1; - uint32_t overscan_info_present_flag : 1; - uint32_t overscan_appropriate_flag : 1; - uint32_t video_signal_type_present_flag : 1; - uint32_t video_full_range_flag : 1; - uint32_t colour_description_present_flag : 1; - uint32_t chroma_loc_info_present_flag : 1; - uint32_t neutral_chroma_indication_flag : 1; - uint32_t field_seq_flag : 1; - uint32_t frame_field_info_present_flag : 1; - uint32_t default_display_window_flag : 1; - uint32_t vui_timing_info_present_flag : 1; - uint32_t vui_poc_proportional_to_timing_flag : 1; - uint32_t vui_hrd_parameters_present_flag : 1; - uint32_t bitstream_restriction_flag : 1; - uint32_t tiles_fixed_structure_flag : 1; - uint32_t motion_vectors_over_pic_boundaries_flag : 1; - uint32_t restricted_ref_pic_lists_flag : 1; + uint32_t aspect_ratio_info_present_flag : 1; + uint32_t overscan_info_present_flag : 1; + uint32_t overscan_appropriate_flag : 1; + uint32_t video_signal_type_present_flag : 1; + uint32_t video_full_range_flag : 1; + uint32_t colour_description_present_flag : 1; + uint32_t chroma_loc_info_present_flag : 1; + uint32_t neutral_chroma_indication_flag : 1; + uint32_t field_seq_flag : 1; + uint32_t frame_field_info_present_flag : 1; + uint32_t default_display_window_flag : 1; + uint32_t vui_timing_info_present_flag : 1; + uint32_t vui_poc_proportional_to_timing_flag : 1; + uint32_t vui_hrd_parameters_present_flag : 1; + uint32_t bitstream_restriction_flag : 1; + uint32_t tiles_fixed_structure_flag : 1; + uint32_t motion_vectors_over_pic_boundaries_flag : 1; + uint32_t restricted_ref_pic_lists_flag : 1; } StdVideoH265SpsVuiFlags; typedef struct StdVideoH265SequenceParameterSetVui { - uint8_t aspect_ratio_idc; - uint16_t sar_width; - uint16_t sar_height; - uint8_t video_format; - uint8_t colour_primaries; - uint8_t transfer_characteristics; - uint8_t matrix_coeffs; - uint8_t chroma_sample_loc_type_top_field; - uint8_t chroma_sample_loc_type_bottom_field; - uint16_t def_disp_win_left_offset; - uint16_t def_disp_win_right_offset; - uint16_t def_disp_win_top_offset; - uint16_t def_disp_win_bottom_offset; - uint32_t vui_num_units_in_tick; - uint32_t vui_time_scale; - uint32_t vui_num_ticks_poc_diff_one_minus1; - StdVideoH265HrdParameters* pHrdParameters; - uint16_t min_spatial_segmentation_idc; - uint8_t max_bytes_per_pic_denom; - uint8_t max_bits_per_min_cu_denom; - uint8_t log2_max_mv_length_horizontal; - uint8_t log2_max_mv_length_vertical; - StdVideoH265SpsVuiFlags flags; + uint8_t aspect_ratio_idc; + uint16_t sar_width; + uint16_t sar_height; + uint8_t video_format; + uint8_t colour_primaries; + uint8_t transfer_characteristics; + uint8_t matrix_coeffs; + uint8_t chroma_sample_loc_type_top_field; + uint8_t chroma_sample_loc_type_bottom_field; + uint16_t def_disp_win_left_offset; + uint16_t def_disp_win_right_offset; + uint16_t def_disp_win_top_offset; + uint16_t def_disp_win_bottom_offset; + uint32_t vui_num_units_in_tick; + uint32_t vui_time_scale; + uint32_t vui_num_ticks_poc_diff_one_minus1; + StdVideoH265HrdParameters* pHrdParameters; + uint16_t min_spatial_segmentation_idc; + uint8_t max_bytes_per_pic_denom; + uint8_t max_bits_per_min_cu_denom; + uint8_t log2_max_mv_length_horizontal; + uint8_t log2_max_mv_length_vertical; + StdVideoH265SpsVuiFlags flags; } StdVideoH265SequenceParameterSetVui; -typedef struct StdVideoH265PredictorPaletteEntries -{ - uint16_t PredictorPaletteEntries[STD_VIDEO_H265_PREDICTOR_PALETTE_COMPONENTS_LIST_SIZE][STD_VIDEO_H265_PREDICTOR_PALETTE_COMP_ENTRIES_LIST_SIZE]; +typedef struct StdVideoH265PredictorPaletteEntries { + uint16_t PredictorPaletteEntries[STD_VIDEO_H265_PREDICTOR_PALETTE_COMPONENTS_LIST_SIZE][STD_VIDEO_H265_PREDICTOR_PALETTE_COMP_ENTRIES_LIST_SIZE]; } StdVideoH265PredictorPaletteEntries; typedef struct StdVideoH265SpsFlags { - uint32_t sps_temporal_id_nesting_flag : 1; - uint32_t separate_colour_plane_flag : 1; - uint32_t scaling_list_enabled_flag : 1; - uint32_t sps_scaling_list_data_present_flag : 1; - uint32_t amp_enabled_flag : 1; - uint32_t sample_adaptive_offset_enabled_flag : 1; - uint32_t pcm_enabled_flag : 1; - uint32_t pcm_loop_filter_disabled_flag : 1; - uint32_t long_term_ref_pics_present_flag : 1; - uint32_t sps_temporal_mvp_enabled_flag : 1; - uint32_t strong_intra_smoothing_enabled_flag : 1; - uint32_t vui_parameters_present_flag : 1; - uint32_t sps_extension_present_flag : 1; - uint32_t sps_range_extension_flag : 1; - - // extension SPS flags, valid when STD_VIDEO_H265_PROFILE_IDC_FORMAT_RANGE_EXTENSIONS is set - uint32_t transform_skip_rotation_enabled_flag : 1; - uint32_t transform_skip_context_enabled_flag : 1; - uint32_t implicit_rdpcm_enabled_flag : 1; - uint32_t explicit_rdpcm_enabled_flag : 1; - uint32_t extended_precision_processing_flag : 1; - uint32_t intra_smoothing_disabled_flag : 1; - uint32_t high_precision_offsets_enabled_flag : 1; - uint32_t persistent_rice_adaptation_enabled_flag : 1; - uint32_t cabac_bypass_alignment_enabled_flag : 1; - - // extension SPS flags, valid when STD_VIDEO_H265_PROFILE_IDC_SCC_EXTENSIONS is set - uint32_t sps_curr_pic_ref_enabled_flag : 1; - uint32_t palette_mode_enabled_flag : 1; - uint32_t sps_palette_predictor_initializer_present_flag : 1; - uint32_t intra_boundary_filtering_disabled_flag : 1; + uint32_t sps_temporal_id_nesting_flag : 1; + uint32_t separate_colour_plane_flag : 1; + uint32_t scaling_list_enabled_flag : 1; + uint32_t sps_scaling_list_data_present_flag : 1; + uint32_t amp_enabled_flag : 1; + uint32_t sample_adaptive_offset_enabled_flag : 1; + uint32_t pcm_enabled_flag : 1; + uint32_t pcm_loop_filter_disabled_flag : 1; + uint32_t long_term_ref_pics_present_flag : 1; + uint32_t sps_temporal_mvp_enabled_flag : 1; + uint32_t strong_intra_smoothing_enabled_flag : 1; + uint32_t vui_parameters_present_flag : 1; + uint32_t sps_extension_present_flag : 1; + uint32_t sps_range_extension_flag : 1; + uint32_t transform_skip_rotation_enabled_flag : 1; + uint32_t transform_skip_context_enabled_flag : 1; + uint32_t implicit_rdpcm_enabled_flag : 1; + uint32_t explicit_rdpcm_enabled_flag : 1; + uint32_t extended_precision_processing_flag : 1; + uint32_t intra_smoothing_disabled_flag : 1; + uint32_t high_precision_offsets_enabled_flag : 1; + uint32_t persistent_rice_adaptation_enabled_flag : 1; + uint32_t cabac_bypass_alignment_enabled_flag : 1; + uint32_t sps_curr_pic_ref_enabled_flag : 1; + uint32_t palette_mode_enabled_flag : 1; + uint32_t sps_palette_predictor_initializer_present_flag : 1; + uint32_t intra_boundary_filtering_disabled_flag : 1; } StdVideoH265SpsFlags; -typedef struct StdVideoH265SequenceParameterSet -{ - StdVideoH265ProfileIdc profile_idc; - StdVideoH265Level level_idc; - uint32_t pic_width_in_luma_samples; - uint32_t pic_height_in_luma_samples; - uint8_t sps_video_parameter_set_id; - uint8_t sps_max_sub_layers_minus1; - uint8_t sps_seq_parameter_set_id; - uint8_t chroma_format_idc; - uint8_t bit_depth_luma_minus8; - uint8_t bit_depth_chroma_minus8; - uint8_t log2_max_pic_order_cnt_lsb_minus4; - uint8_t sps_max_dec_pic_buffering_minus1; - uint8_t log2_min_luma_coding_block_size_minus3; - uint8_t log2_diff_max_min_luma_coding_block_size; - uint8_t log2_min_luma_transform_block_size_minus2; - uint8_t log2_diff_max_min_luma_transform_block_size; - uint8_t max_transform_hierarchy_depth_inter; - uint8_t max_transform_hierarchy_depth_intra; - uint8_t num_short_term_ref_pic_sets; - uint8_t num_long_term_ref_pics_sps; - uint8_t pcm_sample_bit_depth_luma_minus1; - uint8_t pcm_sample_bit_depth_chroma_minus1; - uint8_t log2_min_pcm_luma_coding_block_size_minus3; - uint8_t log2_diff_max_min_pcm_luma_coding_block_size; - uint32_t conf_win_left_offset; - uint32_t conf_win_right_offset; - uint32_t conf_win_top_offset; - uint32_t conf_win_bottom_offset; - StdVideoH265DecPicBufMgr* pDecPicBufMgr; - StdVideoH265SpsFlags flags; - StdVideoH265ScalingLists* pScalingLists; // Must be a valid pointer if sps_scaling_list_data_present_flag is set - StdVideoH265SequenceParameterSetVui* pSequenceParameterSetVui; // Must be a valid pointer if StdVideoH265SpsFlags:vui_parameters_present_flag is set palette_max_size; - - // extension SPS flags, valid when STD_VIDEO_H265_PROFILE_IDC_SCC_EXTENSIONS is set - uint8_t palette_max_size; - uint8_t delta_palette_max_predictor_size; - uint8_t motion_vector_resolution_control_idc; - uint8_t sps_num_palette_predictor_initializer_minus1; - StdVideoH265PredictorPaletteEntries* pPredictorPaletteEntries; // Must be a valid pointer if sps_palette_predictor_initializer_present_flag is set +typedef struct StdVideoH265SequenceParameterSet { + StdVideoH265ProfileIdc profile_idc; + StdVideoH265Level level_idc; + uint32_t pic_width_in_luma_samples; + uint32_t pic_height_in_luma_samples; + uint8_t sps_video_parameter_set_id; + uint8_t sps_max_sub_layers_minus1; + uint8_t sps_seq_parameter_set_id; + uint8_t chroma_format_idc; + uint8_t bit_depth_luma_minus8; + uint8_t bit_depth_chroma_minus8; + uint8_t log2_max_pic_order_cnt_lsb_minus4; + uint8_t sps_max_dec_pic_buffering_minus1; + uint8_t log2_min_luma_coding_block_size_minus3; + uint8_t log2_diff_max_min_luma_coding_block_size; + uint8_t log2_min_luma_transform_block_size_minus2; + uint8_t log2_diff_max_min_luma_transform_block_size; + uint8_t max_transform_hierarchy_depth_inter; + uint8_t max_transform_hierarchy_depth_intra; + uint8_t num_short_term_ref_pic_sets; + uint8_t num_long_term_ref_pics_sps; + uint8_t pcm_sample_bit_depth_luma_minus1; + uint8_t pcm_sample_bit_depth_chroma_minus1; + uint8_t log2_min_pcm_luma_coding_block_size_minus3; + uint8_t log2_diff_max_min_pcm_luma_coding_block_size; + uint32_t conf_win_left_offset; + uint32_t conf_win_right_offset; + uint32_t conf_win_top_offset; + uint32_t conf_win_bottom_offset; + StdVideoH265DecPicBufMgr* pDecPicBufMgr; + StdVideoH265SpsFlags flags; + StdVideoH265ScalingLists* pScalingLists; + StdVideoH265SequenceParameterSetVui* pSequenceParameterSetVui; + uint8_t palette_max_size; + uint8_t delta_palette_max_predictor_size; + uint8_t motion_vector_resolution_control_idc; + uint8_t sps_num_palette_predictor_initializer_minus1; + StdVideoH265PredictorPaletteEntries* pPredictorPaletteEntries; } StdVideoH265SequenceParameterSet; - typedef struct StdVideoH265PpsFlags { - uint32_t dependent_slice_segments_enabled_flag : 1; - uint32_t output_flag_present_flag : 1; - uint32_t sign_data_hiding_enabled_flag : 1; - uint32_t cabac_init_present_flag : 1; - uint32_t constrained_intra_pred_flag : 1; - uint32_t transform_skip_enabled_flag : 1; - uint32_t cu_qp_delta_enabled_flag : 1; - uint32_t pps_slice_chroma_qp_offsets_present_flag : 1; - uint32_t weighted_pred_flag : 1; - uint32_t weighted_bipred_flag : 1; - uint32_t transquant_bypass_enabled_flag : 1; - uint32_t tiles_enabled_flag : 1; - uint32_t entropy_coding_sync_enabled_flag : 1; - uint32_t uniform_spacing_flag : 1; - uint32_t loop_filter_across_tiles_enabled_flag : 1; - uint32_t pps_loop_filter_across_slices_enabled_flag : 1; - uint32_t deblocking_filter_control_present_flag : 1; - uint32_t deblocking_filter_override_enabled_flag : 1; - uint32_t pps_deblocking_filter_disabled_flag : 1; - uint32_t pps_scaling_list_data_present_flag : 1; - uint32_t lists_modification_present_flag : 1; - uint32_t slice_segment_header_extension_present_flag : 1; - uint32_t pps_extension_present_flag : 1; - - // extension PPS flags, valid when STD_VIDEO_H265_PROFILE_IDC_FORMAT_RANGE_EXTENSIONS is set - uint32_t cross_component_prediction_enabled_flag : 1; - uint32_t chroma_qp_offset_list_enabled_flag : 1; - - // extension PPS flags, valid when STD_VIDEO_H265_PROFILE_IDC_SCC_EXTENSIONS is set - uint32_t pps_curr_pic_ref_enabled_flag : 1; - uint32_t residual_adaptive_colour_transform_enabled_flag : 1; - uint32_t pps_slice_act_qp_offsets_present_flag : 1; - uint32_t pps_palette_predictor_initializer_present_flag : 1; - uint32_t monochrome_palette_flag : 1; - uint32_t pps_range_extension_flag : 1; + uint32_t dependent_slice_segments_enabled_flag : 1; + uint32_t output_flag_present_flag : 1; + uint32_t sign_data_hiding_enabled_flag : 1; + uint32_t cabac_init_present_flag : 1; + uint32_t constrained_intra_pred_flag : 1; + uint32_t transform_skip_enabled_flag : 1; + uint32_t cu_qp_delta_enabled_flag : 1; + uint32_t pps_slice_chroma_qp_offsets_present_flag : 1; + uint32_t weighted_pred_flag : 1; + uint32_t weighted_bipred_flag : 1; + uint32_t transquant_bypass_enabled_flag : 1; + uint32_t tiles_enabled_flag : 1; + uint32_t entropy_coding_sync_enabled_flag : 1; + uint32_t uniform_spacing_flag : 1; + uint32_t loop_filter_across_tiles_enabled_flag : 1; + uint32_t pps_loop_filter_across_slices_enabled_flag : 1; + uint32_t deblocking_filter_control_present_flag : 1; + uint32_t deblocking_filter_override_enabled_flag : 1; + uint32_t pps_deblocking_filter_disabled_flag : 1; + uint32_t pps_scaling_list_data_present_flag : 1; + uint32_t lists_modification_present_flag : 1; + uint32_t slice_segment_header_extension_present_flag : 1; + uint32_t pps_extension_present_flag : 1; + uint32_t cross_component_prediction_enabled_flag : 1; + uint32_t chroma_qp_offset_list_enabled_flag : 1; + uint32_t pps_curr_pic_ref_enabled_flag : 1; + uint32_t residual_adaptive_colour_transform_enabled_flag : 1; + uint32_t pps_slice_act_qp_offsets_present_flag : 1; + uint32_t pps_palette_predictor_initializer_present_flag : 1; + uint32_t monochrome_palette_flag : 1; + uint32_t pps_range_extension_flag : 1; } StdVideoH265PpsFlags; -typedef struct StdVideoH265PictureParameterSet -{ - uint8_t pps_pic_parameter_set_id; - uint8_t pps_seq_parameter_set_id; - uint8_t num_extra_slice_header_bits; - uint8_t num_ref_idx_l0_default_active_minus1; - uint8_t num_ref_idx_l1_default_active_minus1; - int8_t init_qp_minus26; - uint8_t diff_cu_qp_delta_depth; - int8_t pps_cb_qp_offset; - int8_t pps_cr_qp_offset; - uint8_t num_tile_columns_minus1; - uint8_t num_tile_rows_minus1; - uint16_t column_width_minus1[STD_VIDEO_H265_CHROMA_QP_OFFSET_TILE_COLS_LIST_SIZE]; - uint16_t row_height_minus1[STD_VIDEO_H265_CHROMA_QP_OFFSET_TILE_ROWS_LIST_SIZE]; - int8_t pps_beta_offset_div2; - int8_t pps_tc_offset_div2; - uint8_t log2_parallel_merge_level_minus2; - StdVideoH265PpsFlags flags; - StdVideoH265ScalingLists* pScalingLists; // Must be a valid pointer if pps_scaling_list_data_present_flag is set - - // extension PPS, valid when STD_VIDEO_H265_PROFILE_IDC_FORMAT_RANGE_EXTENSIONS is set - uint8_t log2_max_transform_skip_block_size_minus2; - uint8_t diff_cu_chroma_qp_offset_depth; - uint8_t chroma_qp_offset_list_len_minus1; - int8_t cb_qp_offset_list[STD_VIDEO_H265_CHROMA_QP_OFFSET_LIST_SIZE]; - int8_t cr_qp_offset_list[STD_VIDEO_H265_CHROMA_QP_OFFSET_LIST_SIZE]; - uint8_t log2_sao_offset_scale_luma; - uint8_t log2_sao_offset_scale_chroma; - - // extension PPS, valid when STD_VIDEO_H265_PROFILE_IDC_SCC_EXTENSIONS is set - int8_t pps_act_y_qp_offset_plus5; - int8_t pps_act_cb_qp_offset_plus5; - int8_t pps_act_cr_qp_offset_plus5; - uint8_t pps_num_palette_predictor_initializer; - uint8_t luma_bit_depth_entry_minus8; - uint8_t chroma_bit_depth_entry_minus8; - StdVideoH265PredictorPaletteEntries* pPredictorPaletteEntries; // Must be a valid pointer if pps_palette_predictor_initializer_present_flag is set +typedef struct StdVideoH265PictureParameterSet { + uint8_t pps_pic_parameter_set_id; + uint8_t pps_seq_parameter_set_id; + uint8_t num_extra_slice_header_bits; + uint8_t num_ref_idx_l0_default_active_minus1; + uint8_t num_ref_idx_l1_default_active_minus1; + int8_t init_qp_minus26; + uint8_t diff_cu_qp_delta_depth; + int8_t pps_cb_qp_offset; + int8_t pps_cr_qp_offset; + uint8_t num_tile_columns_minus1; + uint8_t num_tile_rows_minus1; + uint16_t column_width_minus1[STD_VIDEO_H265_CHROMA_QP_OFFSET_TILE_COLS_LIST_SIZE]; + uint16_t row_height_minus1[STD_VIDEO_H265_CHROMA_QP_OFFSET_TILE_ROWS_LIST_SIZE]; + int8_t pps_beta_offset_div2; + int8_t pps_tc_offset_div2; + uint8_t log2_parallel_merge_level_minus2; + StdVideoH265PpsFlags flags; + StdVideoH265ScalingLists* pScalingLists; + uint8_t log2_max_transform_skip_block_size_minus2; + uint8_t diff_cu_chroma_qp_offset_depth; + uint8_t chroma_qp_offset_list_len_minus1; + int8_t cb_qp_offset_list[STD_VIDEO_H265_CHROMA_QP_OFFSET_LIST_SIZE]; + int8_t cr_qp_offset_list[STD_VIDEO_H265_CHROMA_QP_OFFSET_LIST_SIZE]; + uint8_t log2_sao_offset_scale_luma; + uint8_t log2_sao_offset_scale_chroma; + int8_t pps_act_y_qp_offset_plus5; + int8_t pps_act_cb_qp_offset_plus5; + int8_t pps_act_cr_qp_offset_plus5; + uint8_t pps_num_palette_predictor_initializer; + uint8_t luma_bit_depth_entry_minus8; + uint8_t chroma_bit_depth_entry_minus8; + StdVideoH265PredictorPaletteEntries* pPredictorPaletteEntries; } StdVideoH265PictureParameterSet; + #ifdef __cplusplus } #endif -#endif // VULKAN_VIDEO_CODEC_H265STD_H_ +#endif diff --git a/external/vk_video/vulkan_video_codec_h265std_decode.h b/external/vk_video/vulkan_video_codec_h265std_decode.h index a1efa055..ff06b110 100644 --- a/external/vk_video/vulkan_video_codec_h265std_decode.h +++ b/external/vk_video/vulkan_video_codec_h265std_decode.h @@ -1,64 +1,60 @@ +#ifndef VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ +#define VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 1 + /* -** Copyright (c) 2019-2021 The Khronos Group Inc. +** Copyright 2015-2021 The Khronos Group Inc. ** ** SPDX-License-Identifier: Apache-2.0 */ -#ifndef VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ -#define VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 1 +/* +** This header is generated from the Khronos Vulkan XML API Registry. +** +*/ + #ifdef __cplusplus extern "C" { #endif -#include "vk_video/vulkan_video_codec_h265std.h" -// ************************************************* -// Video h265 Decode related parameters: -// ************************************************* +#define vulkan_video_codec_h265std_decode 1 #define STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE 8 - typedef struct StdVideoDecodeH265PictureInfoFlags { - uint32_t IrapPicFlag : 1; - uint32_t IdrPicFlag : 1; - uint32_t IsReference : 1; - uint32_t short_term_ref_pic_set_sps_flag : 1; + uint32_t IrapPicFlag : 1; + uint32_t IdrPicFlag : 1; + uint32_t IsReference : 1; + uint32_t short_term_ref_pic_set_sps_flag : 1; } StdVideoDecodeH265PictureInfoFlags; typedef struct StdVideoDecodeH265PictureInfo { - uint8_t vps_video_parameter_set_id; - uint8_t sps_seq_parameter_set_id; - uint8_t pps_pic_parameter_set_id; - uint8_t num_short_term_ref_pic_sets; - int32_t PicOrderCntVal; - uint16_t NumBitsForSTRefPicSetInSlice; // number of bits used in st_ref_pic_set() - //when short_term_ref_pic_set_sps_flag is 0; otherwise set to 0. - uint8_t NumDeltaPocsOfRefRpsIdx; // NumDeltaPocs[ RefRpsIdx ] when short_term_ref_pic_set_sps_flag = 1, otherwise 0 - uint8_t RefPicSetStCurrBefore[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; // slotIndex as used in - // VkVideoReferenceSlotKHR structures representing - //pReferenceSlots in VkVideoDecodeInfoKHR, 0xff for invalid slotIndex - uint8_t RefPicSetStCurrAfter[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; // slotIndex as used in - // VkVideoReferenceSlotKHR structures representing - //pReferenceSlots in VkVideoDecodeInfoKHR, 0xff for invalid slotIndex - uint8_t RefPicSetLtCurr[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; // slotIndex as used in - // VkVideoReferenceSlotKHR structures representing - //pReferenceSlots in VkVideoDecodeInfoKHR, 0xff for invalid slotIndex - StdVideoDecodeH265PictureInfoFlags flags; + uint8_t vps_video_parameter_set_id; + uint8_t sps_seq_parameter_set_id; + uint8_t pps_pic_parameter_set_id; + uint8_t num_short_term_ref_pic_sets; + int32_t PicOrderCntVal; + uint16_t NumBitsForSTRefPicSetInSlice; + uint8_t NumDeltaPocsOfRefRpsIdx; + uint8_t RefPicSetStCurrBefore[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; + uint8_t RefPicSetStCurrAfter[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; + uint8_t RefPicSetLtCurr[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; + StdVideoDecodeH265PictureInfoFlags flags; } StdVideoDecodeH265PictureInfo; typedef struct StdVideoDecodeH265ReferenceInfoFlags { - uint32_t is_long_term : 1; - uint32_t is_non_existing : 1; + uint32_t is_long_term : 1; + uint32_t is_non_existing : 1; } StdVideoDecodeH265ReferenceInfoFlags; typedef struct StdVideoDecodeH265ReferenceInfo { - int32_t PicOrderCntVal; - StdVideoDecodeH265ReferenceInfoFlags flags; + int32_t PicOrderCntVal; + StdVideoDecodeH265ReferenceInfoFlags flags; } StdVideoDecodeH265ReferenceInfo; + #ifdef __cplusplus } #endif -#endif // VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ +#endif diff --git a/external/vk_video/vulkan_video_codec_h265std_encode.h b/external/vk_video/vulkan_video_codec_h265std_encode.h index ffffef20..d867751d 100644 --- a/external/vk_video/vulkan_video_codec_h265std_encode.h +++ b/external/vk_video/vulkan_video_codec_h265std_encode.h @@ -1,122 +1,125 @@ +#ifndef VULKAN_VIDEO_CODEC_H265STD_ENCODE_H_ +#define VULKAN_VIDEO_CODEC_H265STD_ENCODE_H_ 1 + /* -** Copyright (c) 2019-2021 The Khronos Group Inc. +** Copyright 2015-2021 The Khronos Group Inc. ** ** SPDX-License-Identifier: Apache-2.0 */ -#ifndef VULKAN_VIDEO_CODEC_H265STD_ENCODE_H_ -#define VULKAN_VIDEO_CODEC_H265STD_ENCODE_H_ 1 +/* +** This header is generated from the Khronos Vulkan XML API Registry. +** +*/ + #ifdef __cplusplus extern "C" { #endif -#include "vk_video/vulkan_video_codec_h265std.h" -// ************************************************* -// Video h265 Encode related parameters: -// ************************************************* -#define STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE 15 +#define vulkan_video_codec_h265std_encode 1 +#define STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE 15 #define STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE 15 -#define STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM 2 - +#define STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM 2 typedef struct StdVideoEncodeH265SliceHeaderFlags { - uint32_t first_slice_segment_in_pic_flag : 1; - uint32_t no_output_of_prior_pics_flag : 1; - uint32_t dependent_slice_segment_flag : 1; - uint32_t short_term_ref_pic_set_sps_flag : 1; - uint32_t slice_temporal_mvp_enable_flag : 1; - uint32_t slice_sao_luma_flag : 1; - uint32_t slice_sao_chroma_flag : 1; - uint32_t num_ref_idx_active_override_flag : 1; - uint32_t mvd_l1_zero_flag : 1; - uint32_t cabac_init_flag : 1; - uint32_t slice_deblocking_filter_disable_flag : 1; - uint32_t collocated_from_l0_flag : 1; - uint32_t slice_loop_filter_across_slices_enabled_flag : 1; - uint32_t bLastSliceInPic : 1; - uint32_t reservedBits : 18; - uint16_t luma_weight_l0_flag; // bit 0 - num_ref_idx_l0_active_minus1 - uint16_t chroma_weight_l0_flag; // bit 0 - num_ref_idx_l0_active_minus1 - uint16_t luma_weight_l1_flag; // bit 0 - num_ref_idx_l1_active_minus1 - uint16_t chroma_weight_l1_flag; // bit 0 - num_ref_idx_l1_active_minus1 + uint32_t first_slice_segment_in_pic_flag : 1; + uint32_t no_output_of_prior_pics_flag : 1; + uint32_t dependent_slice_segment_flag : 1; + uint32_t short_term_ref_pic_set_sps_flag : 1; + uint32_t slice_temporal_mvp_enable_flag : 1; + uint32_t slice_sao_luma_flag : 1; + uint32_t slice_sao_chroma_flag : 1; + uint32_t num_ref_idx_active_override_flag : 1; + uint32_t mvd_l1_zero_flag : 1; + uint32_t cabac_init_flag : 1; + uint32_t slice_deblocking_filter_disable_flag : 1; + uint32_t collocated_from_l0_flag : 1; + uint32_t slice_loop_filter_across_slices_enabled_flag : 1; + uint32_t bLastSliceInPic : 1; + uint32_t reservedBits : 18; + uint16_t luma_weight_l0_flag; + uint16_t chroma_weight_l0_flag; + uint16_t luma_weight_l1_flag; + uint16_t chroma_weight_l1_flag; } StdVideoEncodeH265SliceHeaderFlags; typedef struct StdVideoEncodeH265SliceHeader { - StdVideoH265SliceType slice_type; - uint8_t slice_pic_parameter_set_id; - uint8_t num_short_term_ref_pic_sets; - uint32_t slice_segment_address; - uint8_t short_term_ref_pic_set_idx; - uint8_t num_long_term_sps; - uint8_t num_long_term_pics; - uint8_t collocated_ref_idx; - uint8_t num_ref_idx_l0_active_minus1; // [0, 14] - uint8_t num_ref_idx_l1_active_minus1; // [0, 14] - uint8_t luma_log2_weight_denom; // [0, 7] - int8_t delta_chroma_log2_weight_denom; - int8_t delta_luma_weight_l0[STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE]; - int8_t luma_offset_l0[STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE]; - int8_t delta_chroma_weight_l0[STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE][STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM]; - int8_t delta_chroma_offset_l0[STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE][STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM]; - int8_t delta_luma_weight_l1[STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE]; - int8_t luma_offset_l1[STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE]; - int8_t delta_chroma_weight_l1[STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE][STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM]; - int8_t delta_chroma_offset_l1[STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE][STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM]; - uint8_t MaxNumMergeCand; - int8_t slice_qp_delta; - int8_t slice_cb_qp_offset; // [-12, 12] - int8_t slice_cr_qp_offset; // [-12, 12] - int8_t slice_beta_offset_div2; // [-6, 6] - int8_t slice_tc_offset_div2; // [-6, 6] - int8_t slice_act_y_qp_offset; - int8_t slice_act_cb_qp_offset; - int8_t slice_act_cr_qp_offset; - StdVideoEncodeH265SliceHeaderFlags flags; + StdVideoH265SliceType slice_type; + uint8_t slice_pic_parameter_set_id; + uint8_t num_short_term_ref_pic_sets; + uint32_t slice_segment_address; + uint8_t short_term_ref_pic_set_idx; + uint8_t num_long_term_sps; + uint8_t num_long_term_pics; + uint8_t collocated_ref_idx; + uint8_t num_ref_idx_l0_active_minus1; + uint8_t num_ref_idx_l1_active_minus1; + uint8_t luma_log2_weight_denom; + int8_t delta_chroma_log2_weight_denom; + int8_t delta_luma_weight_l0[STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE]; + int8_t luma_offset_l0[STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE]; + int8_t delta_chroma_weight_l0[STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE][STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM]; + int8_t delta_chroma_offset_l0[STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE][STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM]; + int8_t delta_luma_weight_l1[STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE]; + int8_t luma_offset_l1[STD_VIDEO_ENCODE_H265_LUMA_LIST_SIZE]; + int8_t delta_chroma_weight_l1[STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE][STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM]; + int8_t delta_chroma_offset_l1[STD_VIDEO_ENCODE_H265_CHROMA_LIST_SIZE][STD_VIDEO_ENCODE_H265_CHROMA_LISTS_NUM]; + uint8_t MaxNumMergeCand; + int8_t slice_qp_delta; + int8_t slice_cb_qp_offset; + int8_t slice_cr_qp_offset; + int8_t slice_beta_offset_div2; + int8_t slice_tc_offset_div2; + int8_t slice_act_y_qp_offset; + int8_t slice_act_cb_qp_offset; + int8_t slice_act_cr_qp_offset; + StdVideoEncodeH265SliceHeaderFlags flags; } StdVideoEncodeH265SliceHeader; typedef struct StdVideoEncodeH265ReferenceModificationFlags { - uint32_t ref_pic_list_modification_flag_l0 : 1; - uint32_t ref_pic_list_modification_flag_l1 : 1; + uint32_t ref_pic_list_modification_flag_l0 : 1; + uint32_t ref_pic_list_modification_flag_l1 : 1; } StdVideoEncodeH265ReferenceModificationFlags; typedef struct StdVideoEncodeH265ReferenceModifications { - StdVideoEncodeH265ReferenceModificationFlags flags; - uint8_t referenceList0ModificationsCount; // num_ref_idx_l0_active_minus1 - uint8_t* pReferenceList0Modifications; // list_entry_l0 - uint8_t referenceList1ModificationsCount; // num_ref_idx_l1_active_minus1 - uint8_t* pReferenceList1Modifications; // list_entry_l1 + StdVideoEncodeH265ReferenceModificationFlags flags; + uint8_t referenceList0ModificationsCount; + uint8_t* pReferenceList0Modifications; + uint8_t referenceList1ModificationsCount; + uint8_t* pReferenceList1Modifications; } StdVideoEncodeH265ReferenceModifications; typedef struct StdVideoEncodeH265PictureInfoFlags { - uint32_t is_reference_flag : 1; - uint32_t IrapPicFlag : 1; - uint32_t long_term_flag : 1; + uint32_t is_reference_flag : 1; + uint32_t IrapPicFlag : 1; + uint32_t long_term_flag : 1; } StdVideoEncodeH265PictureInfoFlags; typedef struct StdVideoEncodeH265PictureInfo { - StdVideoH265PictureType PictureType; - uint8_t sps_video_parameter_set_id; - uint8_t pps_seq_parameter_set_id; - int32_t PicOrderCntVal; - uint8_t TemporalId; - StdVideoEncodeH265PictureInfoFlags flags; + StdVideoH265PictureType PictureType; + uint8_t sps_video_parameter_set_id; + uint8_t pps_seq_parameter_set_id; + int32_t PicOrderCntVal; + uint8_t TemporalId; + StdVideoEncodeH265PictureInfoFlags flags; } StdVideoEncodeH265PictureInfo; typedef struct StdVideoEncodeH265ReferenceInfoFlags { - uint32_t is_long_term : 1; - uint32_t isUsedFlag : 1; + uint32_t is_long_term : 1; + uint32_t isUsedFlag : 1; } StdVideoEncodeH265ReferenceInfoFlags; typedef struct StdVideoEncodeH265ReferenceInfo { - int32_t PicOrderCntVal; - uint8_t TemporalId; - StdVideoEncodeH265ReferenceInfoFlags flags; + int32_t PicOrderCntVal; + uint8_t TemporalId; + StdVideoEncodeH265ReferenceInfoFlags flags; } StdVideoEncodeH265ReferenceInfo; + #ifdef __cplusplus } #endif -#endif // VULKAN_VIDEO_CODEC_H265STD_ENCODE_H_ +#endif diff --git a/external/vk_video/vulkan_video_codecs_common.h b/external/vk_video/vulkan_video_codecs_common.h index 8cc227a6..b7efd160 100644 --- a/external/vk_video/vulkan_video_codecs_common.h +++ b/external/vk_video/vulkan_video_codecs_common.h @@ -1,21 +1,31 @@ +#ifndef VULKAN_VIDEO_CODECS_COMMON_H_ +#define VULKAN_VIDEO_CODECS_COMMON_H_ 1 + /* -** Copyright (c) 2019-2021 The Khronos Group Inc. +** Copyright 2015-2021 The Khronos Group Inc. ** ** SPDX-License-Identifier: Apache-2.0 */ -#ifndef VULKAN_VIDEO_CODEC_COMMON_H_ -#define VULKAN_VIDEO_CODEC_COMMON_H_ 1 +/* +** This header is generated from the Khronos Vulkan XML API Registry. +** +*/ + #ifdef __cplusplus extern "C" { #endif + + +#define vulkan_video_codecs_common 1 #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \ ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch))) + #ifdef __cplusplus } #endif -#endif // VULKAN_VIDEO_CODEC_COMMON_H_ +#endif diff --git a/external/vulkan/vk_platform.h b/external/vulkan/vk_platform.h index 18b913ab..5e1a95d0 100644 --- a/external/vulkan/vk_platform.h +++ b/external/vulkan/vk_platform.h @@ -42,7 +42,7 @@ extern "C" #define VKAPI_CALL __stdcall #define VKAPI_PTR VKAPI_CALL #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 - #error "Vulkan isn't supported for the 'armeabi' NDK ABI" + #error "Vulkan is not supported for the 'armeabi' NDK ABI" #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" // calling convention, i.e. float parameters are passed in registers. This diff --git a/external/vulkan/vulkan_beta.h b/external/vulkan/vulkan_beta.h index d2f34d1c..26dbdb8e 100644 --- a/external/vulkan/vulkan_beta.h +++ b/external/vulkan/vulkan_beta.h @@ -99,6 +99,12 @@ typedef enum VkVideoCodingQualityPresetFlagBitsKHR { VK_VIDEO_CODING_QUALITY_PRESET_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF } VkVideoCodingQualityPresetFlagBitsKHR; typedef VkFlags VkVideoCodingQualityPresetFlagsKHR; +typedef struct VkQueueFamilyQueryResultStatusProperties2KHR { + VkStructureType sType; + void* pNext; + VkBool32 supported; +} VkQueueFamilyQueryResultStatusProperties2KHR; + typedef struct VkVideoQueueFamilyProperties2KHR { VkStructureType sType; void* pNext; @@ -384,7 +390,7 @@ typedef VkFlags VkVideoEncodeFlagsKHR; typedef enum VkVideoEncodeRateControlFlagBitsKHR { VK_VIDEO_ENCODE_RATE_CONTROL_DEFAULT_KHR = 0, - VK_VIDEO_ENCODE_RATE_CONTROL_RESET_BIT_KHR = 0x00000001, + VK_VIDEO_ENCODE_RATE_CONTROL_RESERVED_0_BIT_KHR = 0x00000001, VK_VIDEO_ENCODE_RATE_CONTROL_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF } VkVideoEncodeRateControlFlagBitsKHR; typedef VkFlags VkVideoEncodeRateControlFlagsKHR; @@ -409,18 +415,27 @@ typedef struct VkVideoEncodeInfoKHR { const VkVideoReferenceSlotKHR* pSetupReferenceSlot; uint32_t referenceSlotCount; const VkVideoReferenceSlotKHR* pReferenceSlots; + uint32_t precedingExternallyEncodedBytes; } VkVideoEncodeInfoKHR; +typedef struct VkVideoEncodeRateControlLayerInfoKHR { + VkStructureType sType; + const void* pNext; + uint32_t averageBitrate; + uint32_t maxBitrate; + uint32_t frameRateNumerator; + uint32_t frameRateDenominator; + uint32_t virtualBufferSizeInMs; + uint32_t initialVirtualBufferSizeInMs; +} VkVideoEncodeRateControlLayerInfoKHR; + typedef struct VkVideoEncodeRateControlInfoKHR { - VkStructureType sType; - const void* pNext; - VkVideoEncodeRateControlFlagsKHR flags; - VkVideoEncodeRateControlModeFlagBitsKHR rateControlMode; - uint32_t averageBitrate; - uint16_t peakToAverageBitrateRatio; - uint16_t frameRateNumerator; - uint16_t frameRateDenominator; - uint32_t virtualBufferSizeInMs; + VkStructureType sType; + const void* pNext; + VkVideoEncodeRateControlFlagsKHR flags; + VkVideoEncodeRateControlModeFlagBitsKHR rateControlMode; + uint8_t layerCount; + const VkVideoEncodeRateControlLayerInfoKHR* pLayerConfigs; } VkVideoEncodeRateControlInfoKHR; typedef void (VKAPI_PTR *PFN_vkCmdEncodeVideoKHR)(VkCommandBuffer commandBuffer, const VkVideoEncodeInfoKHR* pEncodeInfo); @@ -435,7 +450,7 @@ VKAPI_ATTR void VKAPI_CALL vkCmdEncodeVideoKHR( #define VK_EXT_video_encode_h264 1 #include "vk_video/vulkan_video_codec_h264std.h" #include "vk_video/vulkan_video_codec_h264std_encode.h" -#define VK_EXT_VIDEO_ENCODE_H264_SPEC_VERSION 2 +#define VK_EXT_VIDEO_ENCODE_H264_SPEC_VERSION 3 #define VK_EXT_VIDEO_ENCODE_H264_EXTENSION_NAME "VK_EXT_video_encode_h264" typedef enum VkVideoEncodeH264CapabilityFlagBitsEXT { @@ -476,6 +491,14 @@ typedef enum VkVideoEncodeH264CreateFlagBitsEXT { VK_VIDEO_ENCODE_H264_CREATE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF } VkVideoEncodeH264CreateFlagBitsEXT; typedef VkFlags VkVideoEncodeH264CreateFlagsEXT; + +typedef enum VkVideoEncodeH264RateControlStructureFlagBitsEXT { + VK_VIDEO_ENCODE_H264_RATE_CONTROL_STRUCTURE_UNKNOWN_EXT = 0, + VK_VIDEO_ENCODE_H264_RATE_CONTROL_STRUCTURE_FLAT_BIT_EXT = 0x00000001, + VK_VIDEO_ENCODE_H264_RATE_CONTROL_STRUCTURE_DYADIC_BIT_EXT = 0x00000002, + VK_VIDEO_ENCODE_H264_RATE_CONTROL_STRUCTURE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +} VkVideoEncodeH264RateControlStructureFlagBitsEXT; +typedef VkFlags VkVideoEncodeH264RateControlStructureFlagsEXT; typedef struct VkVideoEncodeH264CapabilitiesEXT { VkStructureType sType; const void* pNext; @@ -533,9 +556,6 @@ typedef struct VkVideoEncodeH264NaluSliceEXT { const VkVideoEncodeH264DpbSlotInfoEXT* pRefFinalList0Entries; uint8_t refFinalList1EntryCount; const VkVideoEncodeH264DpbSlotInfoEXT* pRefFinalList1Entries; - uint32_t precedingNaluBytes; - uint8_t minQp; - uint8_t maxQp; } VkVideoEncodeH264NaluSliceEXT; typedef struct VkVideoEncodeH264VclFrameInfoEXT { @@ -565,12 +585,48 @@ typedef struct VkVideoEncodeH264ProfileEXT { StdVideoH264ProfileIdc stdProfileIdc; } VkVideoEncodeH264ProfileEXT; +typedef struct VkVideoEncodeH264RateControlInfoEXT { + VkStructureType sType; + const void* pNext; + uint32_t gopFrameCount; + uint32_t idrPeriod; + uint32_t consecutiveBFrameCount; + VkVideoEncodeH264RateControlStructureFlagBitsEXT rateControlStructure; + uint8_t temporalLayerCount; +} VkVideoEncodeH264RateControlInfoEXT; + +typedef struct VkVideoEncodeH264QpEXT { + int32_t qpI; + int32_t qpP; + int32_t qpB; +} VkVideoEncodeH264QpEXT; + +typedef struct VkVideoEncodeH264FrameSizeEXT { + uint32_t frameISize; + uint32_t framePSize; + uint32_t frameBSize; +} VkVideoEncodeH264FrameSizeEXT; + +typedef struct VkVideoEncodeH264RateControlLayerInfoEXT { + VkStructureType sType; + const void* pNext; + uint8_t temporalLayerId; + VkBool32 useInitialRcQp; + VkVideoEncodeH264QpEXT initialRcQp; + VkBool32 useMinQp; + VkVideoEncodeH264QpEXT minQp; + VkBool32 useMaxQp; + VkVideoEncodeH264QpEXT maxQp; + VkBool32 useMaxFrameSize; + VkVideoEncodeH264FrameSizeEXT maxFrameSize; +} VkVideoEncodeH264RateControlLayerInfoEXT; + #define VK_EXT_video_encode_h265 1 #include "vk_video/vulkan_video_codec_h265std.h" #include "vk_video/vulkan_video_codec_h265std_encode.h" -#define VK_EXT_VIDEO_ENCODE_H265_SPEC_VERSION 2 +#define VK_EXT_VIDEO_ENCODE_H265_SPEC_VERSION 3 #define VK_EXT_VIDEO_ENCODE_H265_EXTENSION_NAME "VK_EXT_video_encode_h265" typedef VkFlags VkVideoEncodeH265CapabilityFlagsEXT; @@ -599,6 +655,14 @@ typedef enum VkVideoEncodeH265CtbSizeFlagBitsEXT { VK_VIDEO_ENCODE_H265_CTB_SIZE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF } VkVideoEncodeH265CtbSizeFlagBitsEXT; typedef VkFlags VkVideoEncodeH265CtbSizeFlagsEXT; + +typedef enum VkVideoEncodeH265RateControlStructureFlagBitsEXT { + VK_VIDEO_ENCODE_H265_RATE_CONTROL_STRUCTURE_UNKNOWN_EXT = 0, + VK_VIDEO_ENCODE_H265_RATE_CONTROL_STRUCTURE_FLAT_BIT_EXT = 0x00000001, + VK_VIDEO_ENCODE_H265_RATE_CONTROL_STRUCTURE_DYADIC_BIT_EXT = 0x00000002, + VK_VIDEO_ENCODE_H265_RATE_CONTROL_STRUCTURE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +} VkVideoEncodeH265RateControlStructureFlagBitsEXT; +typedef VkFlags VkVideoEncodeH265RateControlStructureFlagsEXT; typedef struct VkVideoEncodeH265CapabilitiesEXT { VkStructureType sType; const void* pNext; @@ -693,6 +757,42 @@ typedef struct VkVideoEncodeH265ProfileEXT { StdVideoH265ProfileIdc stdProfileIdc; } VkVideoEncodeH265ProfileEXT; +typedef struct VkVideoEncodeH265RateControlInfoEXT { + VkStructureType sType; + const void* pNext; + uint32_t gopFrameCount; + uint32_t idrPeriod; + uint32_t consecutiveBFrameCount; + VkVideoEncodeH265RateControlStructureFlagBitsEXT rateControlStructure; + uint8_t subLayerCount; +} VkVideoEncodeH265RateControlInfoEXT; + +typedef struct VkVideoEncodeH265QpEXT { + int32_t qpI; + int32_t qpP; + int32_t qpB; +} VkVideoEncodeH265QpEXT; + +typedef struct VkVideoEncodeH265FrameSizeEXT { + uint32_t frameISize; + uint32_t framePSize; + uint32_t frameBSize; +} VkVideoEncodeH265FrameSizeEXT; + +typedef struct VkVideoEncodeH265RateControlLayerInfoEXT { + VkStructureType sType; + const void* pNext; + uint8_t temporalId; + VkBool32 useInitialRcQp; + VkVideoEncodeH265QpEXT initialRcQp; + VkBool32 useMinQp; + VkVideoEncodeH265QpEXT minQp; + VkBool32 useMaxQp; + VkVideoEncodeH265QpEXT maxQp; + VkBool32 useMaxFrameSize; + VkVideoEncodeH265FrameSizeEXT maxFrameSize; +} VkVideoEncodeH265RateControlLayerInfoEXT; + #define VK_EXT_video_decode_h264 1 diff --git a/external/vulkan/vulkan_core.h b/external/vulkan/vulkan_core.h index a2f4e771..8bc98d5a 100644 --- a/external/vulkan/vulkan_core.h +++ b/external/vulkan/vulkan_core.h @@ -72,7 +72,7 @@ extern "C" { #define VK_API_VERSION_1_0 VK_MAKE_API_VERSION(0, 1, 0, 0)// Patch version should always be set to 0 // Version of this file -#define VK_HEADER_VERSION 197 +#define VK_HEADER_VERSION 203 // Complete version of this file #define VK_HEADER_VERSION_COMPLETE VK_MAKE_API_VERSION(0, 1, 2, VK_HEADER_VERSION) @@ -418,6 +418,9 @@ typedef enum VkStructureType { #ifdef VK_ENABLE_BETA_EXTENSIONS VK_STRUCTURE_TYPE_VIDEO_FORMAT_PROPERTIES_KHR = 1000023015, #endif +#ifdef VK_ENABLE_BETA_EXTENSIONS + VK_STRUCTURE_TYPE_QUEUE_FAMILY_QUERY_RESULT_STATUS_PROPERTIES_2_KHR = 1000023016, +#endif #ifdef VK_ENABLE_BETA_EXTENSIONS VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR = 1000024000, #endif @@ -459,6 +462,12 @@ typedef enum VkStructureType { #ifdef VK_ENABLE_BETA_EXTENSIONS VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_PROFILE_EXT = 1000038008, #endif +#ifdef VK_ENABLE_BETA_EXTENSIONS + VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_RATE_CONTROL_INFO_EXT = 1000038009, +#endif +#ifdef VK_ENABLE_BETA_EXTENSIONS + VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_RATE_CONTROL_LAYER_INFO_EXT = 1000038010, +#endif #ifdef VK_ENABLE_BETA_EXTENSIONS VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_CAPABILITIES_EXT = 1000039000, #endif @@ -489,6 +498,12 @@ typedef enum VkStructureType { #ifdef VK_ENABLE_BETA_EXTENSIONS VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_REFERENCE_LISTS_EXT = 1000039009, #endif +#ifdef VK_ENABLE_BETA_EXTENSIONS + VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_RATE_CONTROL_INFO_EXT = 1000039010, +#endif +#ifdef VK_ENABLE_BETA_EXTENSIONS + VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_RATE_CONTROL_LAYER_INFO_EXT = 1000039011, +#endif #ifdef VK_ENABLE_BETA_EXTENSIONS VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_CAPABILITIES_EXT = 1000040000, #endif @@ -821,6 +836,9 @@ typedef enum VkStructureType { #endif #ifdef VK_ENABLE_BETA_EXTENSIONS VK_STRUCTURE_TYPE_VIDEO_ENCODE_RATE_CONTROL_INFO_KHR = 1000299001, +#endif +#ifdef VK_ENABLE_BETA_EXTENSIONS + VK_STRUCTURE_TYPE_VIDEO_ENCODE_RATE_CONTROL_LAYER_INFO_KHR = 1000299002, #endif VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DIAGNOSTICS_CONFIG_FEATURES_NV = 1000300000, VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV = 1000300001, @@ -860,6 +878,7 @@ typedef enum VkStructureType { VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2_KHR = 1000337009, VK_STRUCTURE_TYPE_IMAGE_RESOLVE_2_KHR = 1000337010, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT = 1000340000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_ARM = 1000342000, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RGBA10X6_FORMATS_FEATURES_EXT = 1000344000, VK_STRUCTURE_TYPE_DIRECTFB_SURFACE_CREATE_INFO_EXT = 1000346000, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MUTABLE_DESCRIPTOR_TYPE_FEATURES_VALVE = 1000351000, @@ -868,6 +887,8 @@ typedef enum VkStructureType { VK_STRUCTURE_TYPE_VERTEX_INPUT_BINDING_DESCRIPTION_2_EXT = 1000352001, VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT = 1000352002, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT = 1000353000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_CONTROL_FEATURES_EXT = 1000355000, + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_DEPTH_CLIP_CONTROL_CREATE_INFO_EXT = 1000355001, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT = 1000356000, VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3_KHR = 1000360000, VK_STRUCTURE_TYPE_IMPORT_MEMORY_ZIRCON_HANDLE_INFO_FUCHSIA = 1000364000, @@ -897,6 +918,8 @@ typedef enum VkStructureType { VK_STRUCTURE_TYPE_PIPELINE_COLOR_WRITE_CREATE_INFO_EXT = 1000381001, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GLOBAL_PRIORITY_QUERY_FEATURES_EXT = 1000388000, VK_STRUCTURE_TYPE_QUEUE_FAMILY_GLOBAL_PRIORITY_PROPERTIES_EXT = 1000388001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_MIN_LOD_FEATURES_EXT = 1000391000, + VK_STRUCTURE_TYPE_IMAGE_VIEW_MIN_LOD_CREATE_INFO_EXT = 1000391001, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTI_DRAW_FEATURES_EXT = 1000392000, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTI_DRAW_PROPERTIES_EXT = 1000392001, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BORDER_COLOR_SWIZZLE_FEATURES_EXT = 1000411000, @@ -906,6 +929,10 @@ typedef enum VkStructureType { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_4_PROPERTIES_KHR = 1000413001, VK_STRUCTURE_TYPE_DEVICE_BUFFER_MEMORY_REQUIREMENTS_KHR = 1000413002, VK_STRUCTURE_TYPE_DEVICE_IMAGE_MEMORY_REQUIREMENTS_KHR = 1000413003, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_OFFSET_FEATURES_QCOM = 1000425000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_OFFSET_PROPERTIES_QCOM = 1000425001, + VK_STRUCTURE_TYPE_SUBPASS_FRAGMENT_DENSITY_MAP_OFFSET_END_INFO_QCOM = 1000425002, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINEAR_COLOR_ATTACHMENT_FEATURES_NV = 1000430000, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES, VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT, @@ -1863,6 +1890,7 @@ typedef enum VkImageAspectFlagBits { VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT = 0x00000100, VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT = 0x00000200, VK_IMAGE_ASPECT_MEMORY_PLANE_3_BIT_EXT = 0x00000400, + VK_IMAGE_ASPECT_NONE_KHR = 0, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR = VK_IMAGE_ASPECT_PLANE_0_BIT, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR = VK_IMAGE_ASPECT_PLANE_1_BIT, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR = VK_IMAGE_ASPECT_PLANE_2_BIT, @@ -1941,6 +1969,7 @@ typedef enum VkImageCreateFlagBits { VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV = 0x00002000, VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT = 0x00001000, VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT = 0x00004000, + VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_QCOM = 0x00008000, VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR = VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT, VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR = VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT, VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR = VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT, @@ -2214,8 +2243,8 @@ typedef enum VkPipelineCreateFlagBits { VK_PIPELINE_CREATE_DERIVATIVE_BIT = 0x00000004, VK_PIPELINE_CREATE_VIEW_INDEX_FROM_DEVICE_INDEX_BIT = 0x00000008, VK_PIPELINE_CREATE_DISPATCH_BASE_BIT = 0x00000010, - VK_PIPELINE_RASTERIZATION_STATE_CREATE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR = 0x00200000, - VK_PIPELINE_RASTERIZATION_STATE_CREATE_FRAGMENT_DENSITY_MAP_ATTACHMENT_BIT_EXT = 0x00400000, + VK_PIPELINE_CREATE_RENDERING_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR = 0x00200000, + VK_PIPELINE_CREATE_RENDERING_FRAGMENT_DENSITY_MAP_ATTACHMENT_BIT_EXT = 0x00400000, VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR = 0x00004000, VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR = 0x00008000, VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR = 0x00010000, @@ -2232,6 +2261,8 @@ typedef enum VkPipelineCreateFlagBits { VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT = 0x00000200, VK_PIPELINE_CREATE_RAY_TRACING_ALLOW_MOTION_BIT_NV = 0x00100000, VK_PIPELINE_CREATE_DISPATCH_BASE = VK_PIPELINE_CREATE_DISPATCH_BASE_BIT, + VK_PIPELINE_RASTERIZATION_STATE_CREATE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR = VK_PIPELINE_CREATE_RENDERING_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR, + VK_PIPELINE_RASTERIZATION_STATE_CREATE_FRAGMENT_DENSITY_MAP_ATTACHMENT_BIT_EXT = VK_PIPELINE_CREATE_RENDERING_FRAGMENT_DENSITY_MAP_ATTACHMENT_BIT_EXT, VK_PIPELINE_CREATE_VIEW_INDEX_FROM_DEVICE_INDEX_BIT_KHR = VK_PIPELINE_CREATE_VIEW_INDEX_FROM_DEVICE_INDEX_BIT, VK_PIPELINE_CREATE_DISPATCH_BASE_KHR = VK_PIPELINE_CREATE_DISPATCH_BASE, VK_PIPELINE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF @@ -2286,7 +2317,18 @@ typedef VkFlags VkPipelineTessellationStateCreateFlags; typedef VkFlags VkPipelineViewportStateCreateFlags; typedef VkFlags VkPipelineRasterizationStateCreateFlags; typedef VkFlags VkPipelineMultisampleStateCreateFlags; + +typedef enum VkPipelineDepthStencilStateCreateFlagBits { + VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_ARM = 0x00000001, + VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_STENCIL_ACCESS_BIT_ARM = 0x00000002, + VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkPipelineDepthStencilStateCreateFlagBits; typedef VkFlags VkPipelineDepthStencilStateCreateFlags; + +typedef enum VkPipelineColorBlendStateCreateFlagBits { + VK_PIPELINE_COLOR_BLEND_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_BIT_ARM = 0x00000001, + VK_PIPELINE_COLOR_BLEND_STATE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkPipelineColorBlendStateCreateFlagBits; typedef VkFlags VkPipelineColorBlendStateCreateFlags; typedef VkFlags VkPipelineDynamicStateCreateFlags; typedef VkFlags VkPipelineLayoutCreateFlags; @@ -2352,6 +2394,9 @@ typedef enum VkSubpassDescriptionFlagBits { VK_SUBPASS_DESCRIPTION_PER_VIEW_POSITION_X_ONLY_BIT_NVX = 0x00000002, VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM = 0x00000004, VK_SUBPASS_DESCRIPTION_SHADER_RESOLVE_BIT_QCOM = 0x00000008, + VK_SUBPASS_DESCRIPTION_RASTERIZATION_ORDER_ATTACHMENT_COLOR_ACCESS_BIT_ARM = 0x00000010, + VK_SUBPASS_DESCRIPTION_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_ARM = 0x00000020, + VK_SUBPASS_DESCRIPTION_RASTERIZATION_ORDER_ATTACHMENT_STENCIL_ACCESS_BIT_ARM = 0x00000040, VK_SUBPASS_DESCRIPTION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF } VkSubpassDescriptionFlagBits; typedef VkFlags VkSubpassDescriptionFlags; @@ -5352,6 +5397,7 @@ typedef enum VkDriverId { VK_DRIVER_ID_MESA_TURNIP = 18, VK_DRIVER_ID_MESA_V3DV = 19, VK_DRIVER_ID_MESA_PANVK = 20, + VK_DRIVER_ID_SAMSUNG_PROPRIETARY = 21, VK_DRIVER_ID_AMD_PROPRIETARY_KHR = VK_DRIVER_ID_AMD_PROPRIETARY, VK_DRIVER_ID_AMD_OPEN_SOURCE_KHR = VK_DRIVER_ID_AMD_OPEN_SOURCE, VK_DRIVER_ID_MESA_RADV_KHR = VK_DRIVER_ID_MESA_RADV, @@ -8343,12 +8389,12 @@ typedef struct VkCheckpointData2NV { } VkCheckpointData2NV; typedef void (VKAPI_PTR *PFN_vkCmdSetEvent2KHR)(VkCommandBuffer commandBuffer, VkEvent event, const VkDependencyInfoKHR* pDependencyInfo); -typedef void (VKAPI_PTR *PFN_vkCmdResetEvent2KHR)(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2KHR stageMask); +typedef void (VKAPI_PTR *PFN_vkCmdResetEvent2KHR)(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2KHR stageMask); typedef void (VKAPI_PTR *PFN_vkCmdWaitEvents2KHR)(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, const VkDependencyInfoKHR* pDependencyInfos); typedef void (VKAPI_PTR *PFN_vkCmdPipelineBarrier2KHR)(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR* pDependencyInfo); -typedef void (VKAPI_PTR *PFN_vkCmdWriteTimestamp2KHR)(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR stage, VkQueryPool queryPool, uint32_t query); +typedef void (VKAPI_PTR *PFN_vkCmdWriteTimestamp2KHR)(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR stage, VkQueryPool queryPool, uint32_t query); typedef VkResult (VKAPI_PTR *PFN_vkQueueSubmit2KHR)(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR* pSubmits, VkFence fence); -typedef void (VKAPI_PTR *PFN_vkCmdWriteBufferMarker2AMD)(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR stage, VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker); +typedef void (VKAPI_PTR *PFN_vkCmdWriteBufferMarker2AMD)(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR stage, VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker); typedef void (VKAPI_PTR *PFN_vkGetQueueCheckpointData2NV)(VkQueue queue, uint32_t* pCheckpointDataCount, VkCheckpointData2NV* pCheckpointData); #ifndef VK_NO_PROTOTYPES @@ -8631,6 +8677,7 @@ static const VkFormatFeatureFlagBits2KHR VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_ #ifdef VK_ENABLE_BETA_EXTENSIONS static const VkFormatFeatureFlagBits2KHR VK_FORMAT_FEATURE_2_VIDEO_ENCODE_DPB_BIT_KHR = 0x10000000ULL; #endif +static const VkFormatFeatureFlagBits2KHR VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV = 0x4000000000ULL; typedef struct VkFormatProperties3KHR { VkStructureType sType; @@ -8643,7 +8690,7 @@ typedef struct VkFormatProperties3KHR { #define VK_KHR_maintenance4 1 -#define VK_KHR_MAINTENANCE_4_SPEC_VERSION 1 +#define VK_KHR_MAINTENANCE_4_SPEC_VERSION 2 #define VK_KHR_MAINTENANCE_4_EXTENSION_NAME "VK_KHR_maintenance4" typedef struct VkPhysicalDeviceMaintenance4FeaturesKHR { VkStructureType sType; @@ -12716,6 +12763,19 @@ typedef struct VkPhysicalDevice4444FormatsFeaturesEXT { +#define VK_ARM_rasterization_order_attachment_access 1 +#define VK_ARM_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_SPEC_VERSION 1 +#define VK_ARM_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXTENSION_NAME "VK_ARM_rasterization_order_attachment_access" +typedef struct VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesARM { + VkStructureType sType; + const void* pNext; + VkBool32 rasterizationOrderColorAttachmentAccess; + VkBool32 rasterizationOrderDepthAttachmentAccess; + VkBool32 rasterizationOrderStencilAttachmentAccess; +} VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesARM; + + + #define VK_EXT_rgba10x6_formats 1 #define VK_EXT_RGBA10X6_FORMATS_SPEC_VERSION 1 #define VK_EXT_RGBA10X6_FORMATS_EXTENSION_NAME "VK_EXT_rgba10x6_formats" @@ -12823,6 +12883,23 @@ typedef struct VkPhysicalDeviceDrmPropertiesEXT { +#define VK_EXT_depth_clip_control 1 +#define VK_EXT_DEPTH_CLIP_CONTROL_SPEC_VERSION 1 +#define VK_EXT_DEPTH_CLIP_CONTROL_EXTENSION_NAME "VK_EXT_depth_clip_control" +typedef struct VkPhysicalDeviceDepthClipControlFeaturesEXT { + VkStructureType sType; + void* pNext; + VkBool32 depthClipControl; +} VkPhysicalDeviceDepthClipControlFeaturesEXT; + +typedef struct VkPipelineViewportDepthClipControlCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkBool32 negativeOneToOne; +} VkPipelineViewportDepthClipControlCreateInfoEXT; + + + #define VK_EXT_primitive_topology_list_restart 1 #define VK_EXT_PRIMITIVE_TOPOLOGY_LIST_RESTART_SPEC_VERSION 1 #define VK_EXT_PRIMITIVE_TOPOLOGY_LIST_RESTART_EXTENSION_NAME "VK_EXT_primitive_topology_list_restart" @@ -13002,6 +13079,23 @@ typedef struct VkQueueFamilyGlobalPriorityPropertiesEXT { +#define VK_EXT_image_view_min_lod 1 +#define VK_EXT_IMAGE_VIEW_MIN_LOD_SPEC_VERSION 1 +#define VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME "VK_EXT_image_view_min_lod" +typedef struct VkPhysicalDeviceImageViewMinLodFeaturesEXT { + VkStructureType sType; + void* pNext; + VkBool32 minLod; +} VkPhysicalDeviceImageViewMinLodFeaturesEXT; + +typedef struct VkImageViewMinLodCreateInfoEXT { + VkStructureType sType; + const void* pNext; + float minLod; +} VkImageViewMinLodCreateInfoEXT; + + + #define VK_EXT_multi_draw 1 #define VK_EXT_MULTI_DRAW_SPEC_VERSION 1 #define VK_EXT_MULTI_DRAW_EXTENSION_NAME "VK_EXT_multi_draw" @@ -13094,6 +13188,46 @@ VKAPI_ATTR void VKAPI_CALL vkSetDeviceMemoryPriorityEXT( #endif +#define VK_QCOM_fragment_density_map_offset 1 +#define VK_QCOM_FRAGMENT_DENSITY_MAP_OFFSET_SPEC_VERSION 1 +#define VK_QCOM_FRAGMENT_DENSITY_MAP_OFFSET_EXTENSION_NAME "VK_QCOM_fragment_density_map_offset" +typedef struct VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM { + VkStructureType sType; + void* pNext; + VkBool32 fragmentDensityMapOffset; +} VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM; + +typedef struct VkPhysicalDeviceFragmentDensityMapOffsetPropertiesQCOM { + VkStructureType sType; + void* pNext; + VkExtent2D fragmentDensityOffsetGranularity; +} VkPhysicalDeviceFragmentDensityMapOffsetPropertiesQCOM; + +typedef struct VkSubpassFragmentDensityMapOffsetEndInfoQCOM { + VkStructureType sType; + const void* pNext; + uint32_t fragmentDensityOffsetCount; + const VkOffset2D* pFragmentDensityOffsets; +} VkSubpassFragmentDensityMapOffsetEndInfoQCOM; + + + +#define VK_NV_linear_color_attachment 1 +#define VK_NV_LINEAR_COLOR_ATTACHMENT_SPEC_VERSION 1 +#define VK_NV_LINEAR_COLOR_ATTACHMENT_EXTENSION_NAME "VK_NV_linear_color_attachment" +typedef struct VkPhysicalDeviceLinearColorAttachmentFeaturesNV { + VkStructureType sType; + void* pNext; + VkBool32 linearColorAttachment; +} VkPhysicalDeviceLinearColorAttachmentFeaturesNV; + + + +#define VK_GOOGLE_surfaceless_query 1 +#define VK_GOOGLE_SURFACELESS_QUERY_SPEC_VERSION 1 +#define VK_GOOGLE_SURFACELESS_QUERY_EXTENSION_NAME "VK_GOOGLE_surfaceless_query" + + #define VK_KHR_acceleration_structure 1 VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkAccelerationStructureKHR) #define VK_KHR_ACCELERATION_STRUCTURE_SPEC_VERSION 13 From 15124e82328a3907391a24f36d93cce18506f4a1 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Fri, 21 Jan 2022 08:17:07 +0100 Subject: [PATCH 3/9] Code restructuring, cleanup and simplification --- .../vertexattributes/vertexattributes.cpp | 284 ++++++++---------- examples/vertexattributes/vertexattributes.h | 170 +++++------ 2 files changed, 190 insertions(+), 264 deletions(-) diff --git a/examples/vertexattributes/vertexattributes.cpp b/examples/vertexattributes/vertexattributes.cpp index be405b67..7a15db7e 100644 --- a/examples/vertexattributes/vertexattributes.cpp +++ b/examples/vertexattributes/vertexattributes.cpp @@ -1,83 +1,16 @@ /* * Vulkan Example - Passing vertex attributes using interleaved and separate buffers * - * Copyright (C) 2021 by Sascha Willems - www.saschawillems.de + * Copyright (C) 2022 by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ #include "vertexattributes.h" -/* - Vulkan glTF scene class -*/ - -VulkanglTFScene::~VulkanglTFScene() +void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent, std::vector& indexBuffer, std::vector& vertexBuffer) { - // Release all Vulkan resources allocated for the model - vertices.destroy(); - indices.destroy(); - for (Image image : images) { - vkDestroyImageView(vulkanDevice->logicalDevice, image.texture.view, nullptr); - vkDestroyImage(vulkanDevice->logicalDevice, image.texture.image, nullptr); - vkDestroySampler(vulkanDevice->logicalDevice, image.texture.sampler, nullptr); - vkFreeMemory(vulkanDevice->logicalDevice, image.texture.deviceMemory, nullptr); - } -} - -/* - glTF loading functions - - The following functions take a glTF input model loaded via tinyglTF and convert all required data into our own structure -*/ - -void VulkanglTFScene::loadImages(tinygltf::Model& input) -{ - // POI: The textures for the glTF file used in this sample are stored as external ktx files, so we can directly load them from disk without the need for conversion - images.resize(input.images.size()); - for (size_t i = 0; i < input.images.size(); i++) { - tinygltf::Image& glTFImage = input.images[i]; - images[i].texture.loadFromFile(path + "/" + glTFImage.uri, VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, copyQueue); - } -} - -void VulkanglTFScene::loadTextures(tinygltf::Model& input) -{ - textures.resize(input.textures.size()); - for (size_t i = 0; i < input.textures.size(); i++) { - textures[i].imageIndex = input.textures[i].source; - } -} - -void VulkanglTFScene::loadMaterials(tinygltf::Model& input) -{ - materials.resize(input.materials.size()); - for (size_t i = 0; i < input.materials.size(); i++) { - // We only read the most basic properties required for our sample - tinygltf::Material glTFMaterial = input.materials[i]; - // Get the base color factor - if (glTFMaterial.values.find("baseColorFactor") != glTFMaterial.values.end()) { - materials[i].baseColorFactor = glm::make_vec4(glTFMaterial.values["baseColorFactor"].ColorFactor().data()); - } - // Get base color texture index - if (glTFMaterial.values.find("baseColorTexture") != glTFMaterial.values.end()) { - materials[i].baseColorTextureIndex = glTFMaterial.values["baseColorTexture"].TextureIndex(); - } - // Get the normal map texture index - if (glTFMaterial.additionalValues.find("normalTexture") != glTFMaterial.additionalValues.end()) { - materials[i].normalTextureIndex = glTFMaterial.additionalValues["normalTexture"].TextureIndex(); - } - // Get some additional material parameters that are used in this sample - materials[i].alphaMode = glTFMaterial.alphaMode; - materials[i].alphaCutOff = (float)glTFMaterial.alphaCutoff; - materials[i].doubleSided = glTFMaterial.doubleSided; - } -} - -void VulkanglTFScene::loadNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, VulkanglTFScene::Node* parent, std::vector& indexBuffer, std::vector& vertexBuffer) -{ - VulkanglTFScene::Node node{}; - node.name = inputNode.name; + Node node{}; // Get the local node matrix // It's either made up from translation, rotation, scale or a 4x4 matrix @@ -99,7 +32,7 @@ void VulkanglTFScene::loadNode(const tinygltf::Node& inputNode, const tinygltf:: // Load node's children if (inputNode.children.size() > 0) { for (size_t i = 0; i < inputNode.children.size(); i++) { - loadNode(input.nodes[inputNode.children[i]], input, &node, indexBuffer, vertexBuffer); + loadSceneNode(input.nodes[inputNode.children[i]], input, &node, indexBuffer, vertexBuffer); } } @@ -218,54 +151,6 @@ void VulkanglTFScene::loadNode(const tinygltf::Node& inputNode, const tinygltf:: } } -VkDescriptorImageInfo VulkanglTFScene::getTextureDescriptor(const size_t index) -{ - return images[index].texture.descriptor; -} - -/* - glTF rendering functions -*/ - -// Draw a single node including child nodes (if present) -void VulkanglTFScene::drawNode(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout, VulkanglTFScene::Node node, bool separate) -{ - if (!node.visible) { - return; - } - if (node.mesh.primitives.size() > 0) { - // Pass the node's matrix via push constants - // Traverse the node hierarchy to the top-most parent to get the final matrix of the current node - - PushConstBlock pushConstBlock; - - glm::mat4 nodeMatrix = node.matrix; - VulkanglTFScene::Node* currentParent = node.parent; - while (currentParent) { - nodeMatrix = currentParent->matrix * nodeMatrix; - currentParent = currentParent->parent; - } - for (VulkanglTFScene::Primitive& primitive : node.mesh.primitives) { - if (primitive.indexCount > 0) { - VulkanglTFScene::Material& material = materials[primitive.materialIndex]; - pushConstBlock.nodeMatrix = nodeMatrix; - pushConstBlock.alphaMask = (material.alphaMode == "MASK"); - pushConstBlock.alphaMaskCutoff = material.alphaCutOff; - vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(PushConstBlock), &pushConstBlock); - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1, 1, &material.descriptorSet, 0, nullptr); - vkCmdDrawIndexed(commandBuffer, primitive.indexCount, 1, primitive.firstIndex, 0, 0); - } - } - } - for (auto& child : node.children) { - drawNode(commandBuffer, pipelineLayout, child, separate); - } -} - -/* - Vulkan Example class -*/ - VulkanExample::VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { title = "Separate vertex attribute buffers"; @@ -278,10 +163,23 @@ VulkanExample::VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) VulkanExample::~VulkanExample() { + vkDestroyPipeline(device, pipelines.vertexAttributesInterleaved, nullptr); + vkDestroyPipeline(device, pipelines.vertexAttributesSeparate, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.matrices, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.textures, nullptr); + indices.destroy(); shaderData.buffer.destroy(); + vertexAttibuteBuffers.normal.destroy(); + vertexAttibuteBuffers.pos.destroy(); + vertexAttibuteBuffers.tangent.destroy(); + vertexAttibuteBuffers.uv.destroy(); + for (Image image : scene.images) { + vkDestroyImageView(vulkanDevice->logicalDevice, image.texture.view, nullptr); + vkDestroyImage(vulkanDevice->logicalDevice, image.texture.image, nullptr); + vkDestroySampler(vulkanDevice->logicalDevice, image.texture.sampler, nullptr); + vkFreeMemory(vulkanDevice->logicalDevice, image.texture.deviceMemory, nullptr); + } } void VulkanExample::getEnabledFeatures() @@ -325,21 +223,21 @@ void VulkanExample::buildCommandBuffers() vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr); // Use the same index buffer, no matter how vertex attributes are passed - vkCmdBindIndexBuffer(drawCmdBuffers[i], glTFScene.indices.buffer, 0, VK_INDEX_TYPE_UINT32); + vkCmdBindIndexBuffer(drawCmdBuffers[i], indices.buffer, 0, VK_INDEX_TYPE_UINT32); if (vertexAttributeSettings == VertexAttributeSettings::separate) { - // Using separate vertex attribute bindings requires binding all attribute buffers + // Using separate vertex attribute bindings requires binding multiple attribute buffers VkDeviceSize offsets[4] = { 0, 0, 0, 0 }; std::array buffers = { vertexAttibuteBuffers.pos.buffer, vertexAttibuteBuffers.normal.buffer, vertexAttibuteBuffers.uv.buffer, vertexAttibuteBuffers.tangent.buffer }; vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, static_cast(buffers.size()), buffers.data(), offsets); } else { - // Using interleaved attribute bindings only requires one buffer bind + // Using interleaved attribute bindings only requires one buffer to be bound VkDeviceSize offsets[1] = { 0 }; - vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &glTFScene.vertices.buffer, offsets); + vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &interleavedVertexBuffer.buffer, offsets); } // Render all nodes starting at top-level - for (auto& node : glTFScene.nodes) { - glTFScene.drawNode(drawCmdBuffers[i], pipelineLayout, node, vertexAttributeSettings == VertexAttributeSettings::separate); + for (auto& node : nodes) { + drawSceneNode(drawCmdBuffers[i], node); } drawUI(drawCmdBuffers[i]); @@ -363,42 +261,73 @@ void VulkanExample::loadglTFFile(std::string filename) #endif bool fileLoaded = gltfContext.LoadASCIIFromFile(&glTFInput, &error, &warning, filename); - // Pass some Vulkan resources required for setup and rendering to the glTF model loading class - glTFScene.vulkanDevice = vulkanDevice; - glTFScene.copyQueue = queue; - size_t pos = filename.find_last_of('/'); - glTFScene.path = filename.substr(0, pos); - - std::vector indexBuffer; - std::vector vertexBuffer; + std::string path = filename.substr(0, pos); if (!fileLoaded) { vks::tools::exitFatal("Could not open the glTF file.\n\nThe file is part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1); return; } - glTFScene.loadImages(glTFInput); - glTFScene.loadMaterials(glTFInput); - glTFScene.loadTextures(glTFInput); + + // Load images + scene.images.resize(glTFInput.images.size()); + for (size_t i = 0; i < glTFInput.images.size(); i++) { + tinygltf::Image& glTFImage = glTFInput.images[i]; + scene.images[i].texture.loadFromFile(path + "/" + glTFImage.uri, VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); + } + // Load textures + scene.textures.resize(glTFInput.textures.size()); + for (size_t i = 0; i < glTFInput.textures.size(); i++) { + scene.textures[i].imageIndex = glTFInput.textures[i].source; + } + // Load materials + scene.materials.resize(glTFInput.materials.size()); + for (size_t i = 0; i < glTFInput.materials.size(); i++) { + // We only read the most basic properties required for our sample + tinygltf::Material glTFMaterial = glTFInput.materials[i]; + // Get the base color factor + if (glTFMaterial.values.find("baseColorFactor") != glTFMaterial.values.end()) { + scene.materials[i].baseColorFactor = glm::make_vec4(glTFMaterial.values["baseColorFactor"].ColorFactor().data()); + } + // Get base color texture index + if (glTFMaterial.values.find("baseColorTexture") != glTFMaterial.values.end()) { + scene.materials[i].baseColorTextureIndex = glTFMaterial.values["baseColorTexture"].TextureIndex(); + } + // Get the normal map texture index + if (glTFMaterial.additionalValues.find("normalTexture") != glTFMaterial.additionalValues.end()) { + scene.materials[i].normalTextureIndex = glTFMaterial.additionalValues["normalTexture"].TextureIndex(); + } + // Get some additional material parameters that are used in this sample + scene.materials[i].alphaMode = glTFMaterial.alphaMode; + scene.materials[i].alphaCutOff = (float)glTFMaterial.alphaCutoff; + } + // Load nodes const tinygltf::Scene& scene = glTFInput.scenes[0]; for (size_t i = 0; i < scene.nodes.size(); i++) { const tinygltf::Node node = glTFInput.nodes[scene.nodes[i]]; - glTFScene.loadNode(node, glTFInput, nullptr, indexBuffer, vertexBuffer); + loadSceneNode(node, glTFInput, nullptr, indexBuffer, vertexBuffer); } - /* Upload vertex and index buffers */ + uploadVertexData(); +} - /* Anonymous functions to simplify buffer creation */ - /* Create a staging buffer used as a source for copies */ +void VulkanExample::uploadVertexData() +{ + // Upload vertex and index buffers + + // Anonymous functions to simplify buffer creation + + // Create a staging buffer used as a source for copies auto createStagingBuffer = [this](vks::Buffer& buffer, void* data, VkDeviceSize size) { VK_CHECK_RESULT(vulkanDevice->createBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &buffer, size, data)); }; - /* Create a device local buffer used as a target for copies*/ + + // Create a device local buffer used as a target for copies auto createDeviceBuffer = [this](vks::Buffer& buffer, VkDeviceSize size, VkBufferUsageFlags usageFlags = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) { VK_CHECK_RESULT(vulkanDevice->createBuffer(usageFlags | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &buffer, size)); }; - size_t vertexBufferSize = vertexBuffer.size() * sizeof(VulkanglTFScene::Vertex); + size_t vertexBufferSize = vertexBuffer.size() * sizeof(Vertex); size_t indexBufferSize = indexBuffer.size() * sizeof(uint32_t); vks::Buffer vertexStaging, indexStaging; @@ -406,18 +335,18 @@ void VulkanExample::loadglTFFile(std::string filename) createStagingBuffer(indexStaging, indexBuffer.data(), indexBufferSize); createStagingBuffer(vertexStaging, vertexBuffer.data(), vertexBufferSize); - createDeviceBuffer(glTFScene.indices, indexStaging.size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT); - createDeviceBuffer(glTFScene.vertices, vertexStaging.size); + createDeviceBuffer(indices, indexStaging.size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT); + createDeviceBuffer(interleavedVertexBuffer, vertexStaging.size); // Copy data from staging buffers (host) do device local buffer (gpu) VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkBufferCopy copyRegion = {}; copyRegion.size = vertexBufferSize; - vkCmdCopyBuffer(copyCmd, vertexStaging.buffer, glTFScene.vertices.buffer, 1, ©Region); - + vkCmdCopyBuffer(copyCmd, vertexStaging.buffer, interleavedVertexBuffer.buffer, 1, ©Region); + copyRegion.size = indexBufferSize; - vkCmdCopyBuffer(copyCmd, indexStaging.buffer, glTFScene.indices.buffer, 1, ©Region); + vkCmdCopyBuffer(copyCmd, indexStaging.buffer, indices.buffer, 1, ©Region); vulkanDevice->flushCommandBuffer(copyCmd, queue, true); @@ -438,10 +367,10 @@ void VulkanExample::loadglTFFile(std::string filename) */ std::array stagingBuffers; - createStagingBuffer(stagingBuffers[0], glTFScene.vertexAttributes.pos.data(), glTFScene.vertexAttributes.pos.size() * sizeof(glTFScene.vertexAttributes.pos[0])); - createStagingBuffer(stagingBuffers[1], glTFScene.vertexAttributes.normal.data(), glTFScene.vertexAttributes.normal.size() * sizeof(glTFScene.vertexAttributes.normal[0])); - createStagingBuffer(stagingBuffers[2], glTFScene.vertexAttributes.uv.data(), glTFScene.vertexAttributes.uv.size() * sizeof(glTFScene.vertexAttributes.uv[0])); - createStagingBuffer(stagingBuffers[3], glTFScene.vertexAttributes.tangent.data(), glTFScene.vertexAttributes.tangent.size() * sizeof(glTFScene.vertexAttributes.tangent[0])); + createStagingBuffer(stagingBuffers[0], vertexAttributes.pos.data(), vertexAttributes.pos.size() * sizeof(vertexAttributes.pos[0])); + createStagingBuffer(stagingBuffers[1], vertexAttributes.normal.data(), vertexAttributes.normal.size() * sizeof(vertexAttributes.normal[0])); + createStagingBuffer(stagingBuffers[2], vertexAttributes.uv.data(), vertexAttributes.uv.size() * sizeof(vertexAttributes.uv[0])); + createStagingBuffer(stagingBuffers[3], vertexAttributes.tangent.data(), vertexAttributes.tangent.size() * sizeof(vertexAttributes.tangent[0])); createDeviceBuffer(vertexAttibuteBuffers.pos, stagingBuffers[0].size); createDeviceBuffer(vertexAttibuteBuffers.normal, stagingBuffers[1].size); @@ -470,8 +399,11 @@ void VulkanExample::loadglTFFile(std::string filename) The index buffer is always the same, no matter how we pass the vertex attributes */ - // @todo: clear + for (size_t i = 0; i < 4; i++) { + vkDestroyBuffer(device, stagingBuffers[i].buffer, nullptr); + vkFreeMemory(device, stagingBuffers[i].memory, nullptr); + } } void VulkanExample::loadAssets() @@ -485,10 +417,10 @@ void VulkanExample::setupDescriptors() // Two combined image samplers per material as each material uses color and normal maps std::vector poolSizes = { vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1), - vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, static_cast(glTFScene.materials.size()) * 2), + vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, static_cast(scene.materials.size()) * 2), }; // One set for matrices and one per model image/texture - const uint32_t maxSetCount = static_cast(glTFScene.images.size()) + 1; + const uint32_t maxSetCount = static_cast(scene.images.size()) + 1; VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(poolSizes, maxSetCount); VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool)); // Descriptor set layout for passing matrices @@ -525,11 +457,11 @@ void VulkanExample::setupDescriptors() vkUpdateDescriptorSets(device, 1, &writeDescriptorSet, 0, nullptr); // Descriptor sets for the materials - for (auto& material : glTFScene.materials) { + for (auto& material : scene.materials) { const VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.textures, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &material.descriptorSet)); - VkDescriptorImageInfo colorMap = glTFScene.getTextureDescriptor(material.baseColorTextureIndex); - VkDescriptorImageInfo normalMap = glTFScene.getTextureDescriptor(material.normalTextureIndex); + VkDescriptorImageInfo colorMap = scene.images[material.baseColorTextureIndex].texture.descriptor; + VkDescriptorImageInfo normalMap = scene.images[material.normalTextureIndex].texture.descriptor; std::vector writeDescriptorSets = { vks::initializers::writeDescriptorSet(material.descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &colorMap), vks::initializers::writeDescriptorSet(material.descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &normalMap), @@ -554,13 +486,13 @@ void VulkanExample::preparePipelines() // @todo: comment const std::vector vertexInputBindingsInterleaved = { - vks::initializers::vertexInputBindingDescription(0, sizeof(VulkanglTFScene::Vertex), VK_VERTEX_INPUT_RATE_VERTEX), + vks::initializers::vertexInputBindingDescription(0, sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX), }; const std::vector vertexInputAttributesInterleaved = { - vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFScene::Vertex, pos)), - vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFScene::Vertex, normal)), - vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFScene::Vertex, uv)), - vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFScene::Vertex, tangent)), + vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, pos)), + vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, normal)), + vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, uv)), + vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, tangent)), }; // @todo: comment @@ -592,7 +524,6 @@ void VulkanExample::preparePipelines() shaderStages[0] = loadShader(getShadersPath() + "vertexattributes/scene.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); shaderStages[1] = loadShader(getShadersPath() + "vertexattributes/scene.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); - //rasterizationStateCI.cullMode = material.doubleSided ? VK_CULL_MODE_NONE : VK_CULL_MODE_BACK_BIT; vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsInterleaved, vertexInputAttributesInterleaved); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.vertexAttributesInterleaved)); @@ -630,6 +561,33 @@ void VulkanExample::prepare() prepared = true; } +void VulkanExample::drawSceneNode(VkCommandBuffer commandBuffer, Node node) +{ + if (node.mesh.primitives.size() > 0) { + PushConstBlock pushConstBlock; + glm::mat4 nodeMatrix = node.matrix; + Node* currentParent = node.parent; + while (currentParent) { + nodeMatrix = currentParent->matrix * nodeMatrix; + currentParent = currentParent->parent; + } + for (Primitive& primitive : node.mesh.primitives) { + if (primitive.indexCount > 0) { + Material& material = scene.materials[primitive.materialIndex]; + pushConstBlock.nodeMatrix = nodeMatrix; + pushConstBlock.alphaMask = (material.alphaMode == "MASK"); + pushConstBlock.alphaMaskCutoff = material.alphaCutOff; + vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(PushConstBlock), &pushConstBlock); + vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1, 1, &material.descriptorSet, 0, nullptr); + vkCmdDrawIndexed(commandBuffer, primitive.indexCount, 1, primitive.firstIndex, 0, 0); + } + } + } + for (auto& child : node.children) { + drawSceneNode(commandBuffer, child); + } +} + void VulkanExample::render() { renderFrame(); diff --git a/examples/vertexattributes/vertexattributes.h b/examples/vertexattributes/vertexattributes.h index 8d96ac17..e6fde08d 100644 --- a/examples/vertexattributes/vertexattributes.h +++ b/examples/vertexattributes/vertexattributes.h @@ -1,7 +1,7 @@ /* * Vulkan Example - Passing vertex attributes using interleaved and separate buffers * - * Copyright (C) 2021 by Sascha Willems - www.saschawillems.de + * Copyright (C) 2022 by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ @@ -26,117 +26,77 @@ struct PushConstBlock { float alphaMaskCutoff; }; - // Contains everything required to render a basic glTF scene in Vulkan - // This class is heavily simplified (compared to glTF's feature set) but retains the basic glTF structure -class VulkanglTFScene -{ -public: - // The class requires some Vulkan objects so it can create it's own resources - vks::VulkanDevice* vulkanDevice; - VkQueue copyQueue; - - // The vertex layout for the samples' model - struct Vertex { - glm::vec3 pos; - glm::vec3 normal; - glm::vec2 uv; - glm::vec4 tangent; - }; - - // Single vertex buffer for all primitives - vks::Buffer vertices; - - // Used at loading time - struct VertexAttributes { - std::vector uv; - std::vector pos, normal; - std::vector tangent; - } vertexAttributes; - - // Single index buffer for all primitives - vks::Buffer indices; - - // The following structures roughly represent the glTF scene structure - // To keep things simple, they only contain those properties that are required for this sample - struct Node; - - // A primitive contains the data for a single draw call - struct Primitive { - uint32_t firstIndex; - uint32_t indexCount; - int32_t materialIndex; - }; - - // Contains the node's (optional) geometry and can be made up of an arbitrary number of primitives - struct Mesh { - std::vector primitives; - }; - - // A node represents an object in the glTF scene graph - struct Node { - Node* parent; - std::vector children; - Mesh mesh; - glm::mat4 matrix; - std::string name; - bool visible = true; - }; - - // A glTF material stores information in e.g. the texture that is attached to it and colors - struct Material { - glm::vec4 baseColorFactor = glm::vec4(1.0f); - uint32_t baseColorTextureIndex; - uint32_t normalTextureIndex; - std::string alphaMode = "OPAQUE"; - float alphaCutOff; - bool doubleSided = false; - VkDescriptorSet descriptorSet; - }; - - // Contains the texture for a single glTF image - // Images may be reused by texture objects and are as such separated - struct Image { - vks::Texture2D texture; - }; - - // A glTF texture stores a reference to the image and a sampler - // In this sample, we are only interested in the image - struct Texture { - int32_t imageIndex; - }; - - /* - Model data - */ - std::vector images; - std::vector textures; - std::vector materials; - std::vector nodes; - - std::string path; - - ~VulkanglTFScene(); - VkDescriptorImageInfo getTextureDescriptor(const size_t index); - void loadImages(tinygltf::Model& input); - void loadTextures(tinygltf::Model& input); - void loadMaterials(tinygltf::Model& input); - void loadNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, VulkanglTFScene::Node* parent, std::vector& indexBuffer, std::vector& vertexBuffer); - void drawNode(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout, VulkanglTFScene::Node node, bool separate); +struct Material { + glm::vec4 baseColorFactor = glm::vec4(1.0f); + uint32_t baseColorTextureIndex; + uint32_t normalTextureIndex; + std::string alphaMode = "OPAQUE"; + float alphaCutOff; + VkDescriptorSet descriptorSet; }; +struct Image { + vks::Texture2D texture; +}; + +struct Texture { + int32_t imageIndex; +}; + +// Layout for the interleaved vertex attributes +struct Vertex { + glm::vec3 pos; + glm::vec3 normal; + glm::vec2 uv; + glm::vec4 tangent; +}; + +struct Primitive { + uint32_t firstIndex; + uint32_t indexCount; + int32_t materialIndex; +}; +struct Mesh { + std::vector primitives; +}; +struct Node; +struct Node { + Node* parent; + std::vector children; + Mesh mesh; + glm::mat4 matrix; +}; + +// Only used at loading time +struct VertexAttributes { + std::vector uv; + std::vector pos, normal; + std::vector tangent; +} vertexAttributes; + +std::vector nodes; + class VulkanExample : public VulkanExampleBase { public: - VulkanglTFScene glTFScene; - enum VertexAttributeSettings { interleaved, separate }; VertexAttributeSettings vertexAttributeSettings = separate; + std::vector indexBuffer; + std::vector vertexBuffer; + // Buffers for the separate vertex attributes + // @todo: rename struct VertexAttributeBuffers { vks::Buffer pos, normal, uv, tangent; } vertexAttibuteBuffers; + // Single vertex buffer for all primitives + vks::Buffer interleavedVertexBuffer; + + // Index buffer for all primitives of the scene + vks::Buffer indices; + struct ShaderData { vks::Buffer buffer; struct Values { @@ -151,19 +111,25 @@ public: VkPipeline vertexAttributesInterleaved; VkPipeline vertexAttributesSeparate; } pipelines; - VkPipelineLayout pipelineLayout; - VkDescriptorSet descriptorSet; struct DescriptorSetLayouts { VkDescriptorSetLayout matrices; VkDescriptorSetLayout textures; } descriptorSetLayouts; + VkDescriptorSet descriptorSet; + + struct Scene { + std::vector images; + std::vector textures; + std::vector materials; + } scene; VulkanExample(); ~VulkanExample(); virtual void getEnabledFeatures(); void buildCommandBuffers(); + void uploadVertexData(); void loadglTFFile(std::string filename); void loadAssets(); void setupDescriptors(); @@ -171,6 +137,8 @@ public: void prepareUniformBuffers(); void updateUniformBuffers(); void prepare(); + void loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent, std::vector& indexBuffer, std::vector& vertexBuffer); + void drawSceneNode(VkCommandBuffer commandBuffer, Node node); virtual void render(); virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay); }; \ No newline at end of file From 0dc34c3375af8f3da4105faf6da8e7bc0bff7957 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Fri, 21 Jan 2022 09:59:30 +0100 Subject: [PATCH 4/9] Code restructuring --- .../vertexattributes/vertexattributes.cpp | 151 ++++++++---------- examples/vertexattributes/vertexattributes.h | 4 +- 2 files changed, 73 insertions(+), 82 deletions(-) diff --git a/examples/vertexattributes/vertexattributes.cpp b/examples/vertexattributes/vertexattributes.cpp index 7a15db7e..55b820df 100644 --- a/examples/vertexattributes/vertexattributes.cpp +++ b/examples/vertexattributes/vertexattributes.cpp @@ -153,7 +153,7 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt VulkanExample::VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Separate vertex attribute buffers"; + title = "Separate/interleaved vertex attribute buffers"; camera.type = Camera::CameraType::firstperson; camera.flipY = true; camera.setPosition(glm::vec3(0.0f, 1.0f, 0.0f)); @@ -170,10 +170,10 @@ VulkanExample::~VulkanExample() vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.textures, nullptr); indices.destroy(); shaderData.buffer.destroy(); - vertexAttibuteBuffers.normal.destroy(); - vertexAttibuteBuffers.pos.destroy(); - vertexAttibuteBuffers.tangent.destroy(); - vertexAttibuteBuffers.uv.destroy(); + separateVertexBuffers.normal.destroy(); + separateVertexBuffers.pos.destroy(); + separateVertexBuffers.tangent.destroy(); + separateVertexBuffers.uv.destroy(); for (Image image : scene.images) { vkDestroyImageView(vulkanDevice->logicalDevice, image.texture.view, nullptr); vkDestroyImage(vulkanDevice->logicalDevice, image.texture.image, nullptr); @@ -228,7 +228,7 @@ void VulkanExample::buildCommandBuffers() if (vertexAttributeSettings == VertexAttributeSettings::separate) { // Using separate vertex attribute bindings requires binding multiple attribute buffers VkDeviceSize offsets[4] = { 0, 0, 0, 0 }; - std::array buffers = { vertexAttibuteBuffers.pos.buffer, vertexAttibuteBuffers.normal.buffer, vertexAttibuteBuffers.uv.buffer, vertexAttibuteBuffers.tangent.buffer }; + std::array buffers = { separateVertexBuffers.pos.buffer, separateVertexBuffers.normal.buffer, separateVertexBuffers.uv.buffer, separateVertexBuffers.tangent.buffer }; vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, static_cast(buffers.size()), buffers.data(), offsets); } else { // Using interleaved attribute bindings only requires one buffer to be bound @@ -316,94 +316,84 @@ void VulkanExample::uploadVertexData() // Upload vertex and index buffers // Anonymous functions to simplify buffer creation - // Create a staging buffer used as a source for copies auto createStagingBuffer = [this](vks::Buffer& buffer, void* data, VkDeviceSize size) { VK_CHECK_RESULT(vulkanDevice->createBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &buffer, size, data)); - }; - + }; // Create a device local buffer used as a target for copies auto createDeviceBuffer = [this](vks::Buffer& buffer, VkDeviceSize size, VkBufferUsageFlags usageFlags = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) { VK_CHECK_RESULT(vulkanDevice->createBuffer(usageFlags | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &buffer, size)); }; - size_t vertexBufferSize = vertexBuffer.size() * sizeof(Vertex); - size_t indexBufferSize = indexBuffer.size() * sizeof(uint32_t); - - vks::Buffer vertexStaging, indexStaging; - - createStagingBuffer(indexStaging, indexBuffer.data(), indexBufferSize); - createStagingBuffer(vertexStaging, vertexBuffer.data(), vertexBufferSize); - - createDeviceBuffer(indices, indexStaging.size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT); - createDeviceBuffer(interleavedVertexBuffer, vertexStaging.size); - - // Copy data from staging buffers (host) do device local buffer (gpu) - VkCommandBuffer copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); - VkBufferCopy copyRegion = {}; - - copyRegion.size = vertexBufferSize; - vkCmdCopyBuffer(copyCmd, vertexStaging.buffer, interleavedVertexBuffer.buffer, 1, ©Region); - - copyRegion.size = indexBufferSize; - vkCmdCopyBuffer(copyCmd, indexStaging.buffer, indices.buffer, 1, ©Region); - - vulkanDevice->flushCommandBuffer(copyCmd, queue, true); - - // Free staging resources - vkDestroyBuffer(device, vertexStaging.buffer, nullptr); - vkFreeMemory(device, vertexStaging.memory, nullptr); - vkDestroyBuffer(device, indexStaging.buffer, nullptr); - vkFreeMemory(device, indexStaging.memory, nullptr); + VkCommandBuffer copyCmd; + VkBufferCopy copyRegion{}; /* Interleaved vertex attributes We create one single buffer containing the interleaved vertex attributes */ + size_t vertexBufferSize = vertexBuffer.size() * sizeof(Vertex); + vks::Buffer vertexStaging; + createStagingBuffer(vertexStaging, vertexBuffer.data(), vertexBufferSize); + createDeviceBuffer(interleavedVertexBuffer, vertexStaging.size); + + // Copy data from staging buffer (host) do device local buffer (gpu) + copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); + copyRegion.size = vertexBufferSize; + vkCmdCopyBuffer(copyCmd, vertexStaging.buffer, interleavedVertexBuffer.buffer, 1, ©Region); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); + vertexStaging.destroy(); /* Separate vertex attributes - We create a separate buffer for each of the vertex attributes (position, normals, etc.) + We create multiple separate buffers for each of the vertex attributes (position, normals, etc.) */ - std::array stagingBuffers; createStagingBuffer(stagingBuffers[0], vertexAttributes.pos.data(), vertexAttributes.pos.size() * sizeof(vertexAttributes.pos[0])); createStagingBuffer(stagingBuffers[1], vertexAttributes.normal.data(), vertexAttributes.normal.size() * sizeof(vertexAttributes.normal[0])); createStagingBuffer(stagingBuffers[2], vertexAttributes.uv.data(), vertexAttributes.uv.size() * sizeof(vertexAttributes.uv[0])); createStagingBuffer(stagingBuffers[3], vertexAttributes.tangent.data(), vertexAttributes.tangent.size() * sizeof(vertexAttributes.tangent[0])); - createDeviceBuffer(vertexAttibuteBuffers.pos, stagingBuffers[0].size); - createDeviceBuffer(vertexAttibuteBuffers.normal, stagingBuffers[1].size); - createDeviceBuffer(vertexAttibuteBuffers.uv, stagingBuffers[2].size); - createDeviceBuffer(vertexAttibuteBuffers.tangent, stagingBuffers[3].size); + createDeviceBuffer(separateVertexBuffers.pos, stagingBuffers[0].size); + createDeviceBuffer(separateVertexBuffers.normal, stagingBuffers[1].size); + createDeviceBuffer(separateVertexBuffers.uv, stagingBuffers[2].size); + createDeviceBuffer(separateVertexBuffers.tangent, stagingBuffers[3].size); // Stage std::vector attributeBuffers = { - vertexAttibuteBuffers.pos, - vertexAttibuteBuffers.normal, - vertexAttibuteBuffers.uv, - vertexAttibuteBuffers.tangent, + separateVertexBuffers.pos, + separateVertexBuffers.normal, + separateVertexBuffers.uv, + separateVertexBuffers.tangent, }; - // Copy data from staging buffers (host) do device local buffer (gpu) + // Copy data from staging buffer (host) do device local buffer (gpu) copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); - copyRegion = {}; for (size_t i = 0; i < attributeBuffers.size(); i++) { copyRegion.size = attributeBuffers[i].size; vkCmdCopyBuffer(copyCmd, stagingBuffers[i].buffer, attributeBuffers[i].buffer, 1, ©Region); } vulkanDevice->flushCommandBuffer(copyCmd, queue, true); + for (size_t i = 0; i < 4; i++) { + stagingBuffers[i].destroy(); + } + /* Index buffer The index buffer is always the same, no matter how we pass the vertex attributes */ - - // @todo: clear - for (size_t i = 0; i < 4; i++) { - vkDestroyBuffer(device, stagingBuffers[i].buffer, nullptr); - vkFreeMemory(device, stagingBuffers[i].memory, nullptr); - } + size_t indexBufferSize = indexBuffer.size() * sizeof(uint32_t); + vks::Buffer indexStaging; + createStagingBuffer(indexStaging, indexBuffer.data(), indexBufferSize); + createDeviceBuffer(indices, indexStaging.size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT); + // Copy data from staging buffer (host) do device local buffer (gpu) + copyCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); + copyRegion.size = indexBufferSize; + vkCmdCopyBuffer(copyCmd, indexStaging.buffer, indices.buffer, 1, ©Region); + vulkanDevice->flushCommandBuffer(copyCmd, queue, true); + // Free staging resources + indexStaging.destroy(); } void VulkanExample::loadAssets() @@ -484,31 +474,6 @@ void VulkanExample::preparePipelines() VkPipelineVertexInputStateCreateInfo vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(); std::array shaderStages; - // @todo: comment - const std::vector vertexInputBindingsInterleaved = { - vks::initializers::vertexInputBindingDescription(0, sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX), - }; - const std::vector vertexInputAttributesInterleaved = { - vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, pos)), - vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, normal)), - vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, uv)), - vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, tangent)), - }; - - // @todo: comment - const std::vector vertexInputBindingsSeparate = { - vks::initializers::vertexInputBindingDescription(0, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX), - vks::initializers::vertexInputBindingDescription(1, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX), - vks::initializers::vertexInputBindingDescription(2, sizeof(glm::vec2), VK_VERTEX_INPUT_RATE_VERTEX), - vks::initializers::vertexInputBindingDescription(3, sizeof(glm::vec4), VK_VERTEX_INPUT_RATE_VERTEX), - }; - const std::vector vertexInputAttributesSeparate = { - vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), - vks::initializers::vertexInputAttributeDescription(1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0), - vks::initializers::vertexInputAttributeDescription(2, 2, VK_FORMAT_R32G32B32_SFLOAT, 0), - vks::initializers::vertexInputAttributeDescription(3, 3, VK_FORMAT_R32G32B32_SFLOAT, 0), - }; - VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayout, renderPass, 0); pipelineCI.pVertexInputState = &vertexInputStateCI; pipelineCI.pInputAssemblyState = &inputAssemblyStateCI; @@ -524,9 +489,35 @@ void VulkanExample::preparePipelines() shaderStages[0] = loadShader(getShadersPath() + "vertexattributes/scene.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); shaderStages[1] = loadShader(getShadersPath() + "vertexattributes/scene.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + // Interleaved vertex attributes + // One Binding (one buffer) and multiple attributes + const std::vector vertexInputBindingsInterleaved = { + vks::initializers::vertexInputBindingDescription(0, sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX), + }; + const std::vector vertexInputAttributesInterleaved = { + vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, pos)), + vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, normal)), + vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, uv)), + vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, tangent)), + }; + vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsInterleaved, vertexInputAttributesInterleaved); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.vertexAttributesInterleaved)); + // Separate vertex attribute + // Multiple bindings (for each attribute buffer) and multiple attribues + const std::vector vertexInputBindingsSeparate = { + vks::initializers::vertexInputBindingDescription(0, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX), + vks::initializers::vertexInputBindingDescription(1, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX), + vks::initializers::vertexInputBindingDescription(2, sizeof(glm::vec2), VK_VERTEX_INPUT_RATE_VERTEX), + vks::initializers::vertexInputBindingDescription(3, sizeof(glm::vec4), VK_VERTEX_INPUT_RATE_VERTEX), + }; + const std::vector vertexInputAttributesSeparate = { + vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), + vks::initializers::vertexInputAttributeDescription(1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0), + vks::initializers::vertexInputAttributeDescription(2, 2, VK_FORMAT_R32G32B32_SFLOAT, 0), + vks::initializers::vertexInputAttributeDescription(3, 3, VK_FORMAT_R32G32B32_SFLOAT, 0), + }; vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsSeparate, vertexInputAttributesSeparate); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.vertexAttributesSeparate)); } diff --git a/examples/vertexattributes/vertexattributes.h b/examples/vertexattributes/vertexattributes.h index e6fde08d..089ad9f7 100644 --- a/examples/vertexattributes/vertexattributes.h +++ b/examples/vertexattributes/vertexattributes.h @@ -87,9 +87,9 @@ public: // Buffers for the separate vertex attributes // @todo: rename - struct VertexAttributeBuffers { + struct SeparateVertexBuffers { vks::Buffer pos, normal, uv, tangent; - } vertexAttibuteBuffers; + } separateVertexBuffers; // Single vertex buffer for all primitives vks::Buffer interleavedVertexBuffer; From e34634c266d93af2c9f0e31e22280ad9ae5fdb0a Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Fri, 21 Jan 2022 11:42:50 +0100 Subject: [PATCH 5/9] Corrected vertex attribute formats --- examples/vertexattributes/vertexattributes.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/vertexattributes/vertexattributes.cpp b/examples/vertexattributes/vertexattributes.cpp index 55b820df..4046b5d2 100644 --- a/examples/vertexattributes/vertexattributes.cpp +++ b/examples/vertexattributes/vertexattributes.cpp @@ -497,8 +497,8 @@ void VulkanExample::preparePipelines() const std::vector vertexInputAttributesInterleaved = { vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, pos)), vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, normal)), - vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, uv)), - vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, tangent)), + vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32_SFLOAT, offsetof(Vertex, uv)), + vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(Vertex, tangent)), }; vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsInterleaved, vertexInputAttributesInterleaved); @@ -515,8 +515,8 @@ void VulkanExample::preparePipelines() const std::vector vertexInputAttributesSeparate = { vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), vks::initializers::vertexInputAttributeDescription(1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0), - vks::initializers::vertexInputAttributeDescription(2, 2, VK_FORMAT_R32G32B32_SFLOAT, 0), - vks::initializers::vertexInputAttributeDescription(3, 3, VK_FORMAT_R32G32B32_SFLOAT, 0), + vks::initializers::vertexInputAttributeDescription(2, 2, VK_FORMAT_R32G32_SFLOAT, 0), + vks::initializers::vertexInputAttributeDescription(3, 3, VK_FORMAT_R32G32B32A32_SFLOAT, 0), }; vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsSeparate, vertexInputAttributesSeparate); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.vertexAttributesSeparate)); From 6b0bc52a1bda193b2a57868a599127262145f6eb Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Fri, 21 Jan 2022 13:35:06 +0100 Subject: [PATCH 6/9] Code cleanup and readme for vertex attributes sample --- examples/vertexattributes/README.md | 58 +++++++++++++++++- .../vertexattributes/interleavedbuffer.png | Bin 0 -> 9565 bytes examples/vertexattributes/separatebuffers.png | Bin 0 -> 18867 bytes .../vertexattributes/vertexattributes.cpp | 38 ++++++------ 4 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 examples/vertexattributes/interleavedbuffer.png create mode 100644 examples/vertexattributes/separatebuffers.png diff --git a/examples/vertexattributes/README.md b/examples/vertexattributes/README.md index 2900bf26..16969750 100644 --- a/examples/vertexattributes/README.md +++ b/examples/vertexattributes/README.md @@ -2,4 +2,60 @@ ## Synopsis -This sample demonstrates how to pass vertex attributes using interleaved or separate buffers. \ No newline at end of file +This sample demonstrates two different ways of providing vertex data to the GPU using either interleaved or separate buffers for vertex attributes. + +## Shader interface + +The shader interface for passing the vertex attributes is the same, no matter if the data provided is coming from a single interleaved or multiple separate buffers. + +```glsl +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV; +layout (location = 3) in vec4 inTangent; +``` + +## Interleaved vertex attributes + +In an interleaved vertex buffer, the components that make up a single vertex are stored after each other, so the stride of a single vertex is the sum of it's component's sizes. + +![Interleaved buffer layout](interleavedbuffer.png) + +```cpp +// Binding +const std::vector vertexInputBindingsInterleaved = { + { 0, sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX }, +}; + +// Attribute +const std::vector vertexInputAttributesInterleaved = { + { 0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, pos) }, + { 1, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, normal) }, + { 2, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(Vertex, uv) }, + { 3, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(Vertex, tangent) }, +}; +``` + +## Separate vertex attributes + +When using separate buffers, each component is stored in it's own buffer. So e.g. the position buffer only contains vertex positions stored consecutively. + +![Interleaved buffer layout](separatebuffers.png) + +```cpp +// Bindings +const std::vector vertexInputBindingsSeparate = { + { 0, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX }, + { 1, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX }, + { 2, sizeof(glm::vec2), VK_VERTEX_INPUT_RATE_VERTEX }, + { 3, sizeof(glm::vec4), VK_VERTEX_INPUT_RATE_VERTEX }, +}; + +// Attributes +const std::vector vertexInputAttributesSeparate = { + { 0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0 }, + { 1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0 }, + { 2, 2, VK_FORMAT_R32G32_SFLOAT, 0 }, + { 3, 3, VK_FORMAT_R32G32B32A32_SFLOAT, 0 }, +}; +``` \ No newline at end of file diff --git a/examples/vertexattributes/interleavedbuffer.png b/examples/vertexattributes/interleavedbuffer.png new file mode 100644 index 0000000000000000000000000000000000000000..109de3a015ebbe9d710df2a08f105888db62e59b GIT binary patch literal 9565 zcmcI~2{hF2|F2M}>>*^YWJ_5RW2ca%64_!Bl68!2EW=omog~>p2-(KIZVzg#rKLDbE1kFnXU3;OCT!u9`9lviH&w2?;lehN_aDhuK;RwUho(MLWxY&XvW8 zpau$bw zYYivXYd&8;G&VNMf2AN-B>D4jUm!oDgbLz~s-~hNIraN_K+cVOP039{`um~dC8dM$ zoW1IJ`p-0ypA=;O|0z^4$ef(uv**s)tPB^@zp-eGNRMQf(sgund{W!c(4hD5p;Avz zkDk8%9WMBW|6xsb_TA&LwVcYzcg&(@S~|y06SS*;5Bph_G&KaoY;kaKuuL>IG0AOc zNLgN45#ZzFo0luQQBY9uv9?ymEs`iLEm@ZsUtyG=_MB*jf=GxjLIDVVEq|$gTP9~(z zRUM4t`!mBY#g8A;Tf5s4fUK{7&&I~42lfgdwwcoj2jxGVbssJQ-ya(rvo(<#_mtPe zy+-{t48_@+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=Yc+K2NJh=h-9`=@Rp}=sCGo~p86J-Y zvTCDx5^iRqSrzi9G2jim$+nq}Kp|h@OOx=`XW}oQ!FVrr@IXsSEdG^ey%Bcid4crI z!gEgbY;BnqgT8!|Do1@LpVKkGmMjCqU>mcn@@fzq?=%Z%3kR9HgG-(T zF_?ZAG#e(XWJ~4T_}(%(nEObfOfs*?0&2|^uM4#vk5%cXaBpV*wVAPtSixrh{-=DR z4!=G>;e933pxY81xaXGr1nwV&0|;s$ICTeeJ%mbQYxXHZWe>N? z&r_-Io%Vt)2GOjHy(hOrA*1cdW*Y}QLR_&B7dbmI2)W0)PI=o_MYpaJ_K|ACK*~1Hg6up5NR_kT`b-iZW>zUJ!)P^LsHoO=G zqabXFGx~*^M1n>_uNCzLY;m-dcf^1|C0XlK4?0*5{I#4I){;_gzj(FgX{;=12xQBU z;yWWoD3iul%(wU*y&_PW2?8ov*H`J8QD8a>_tUtq5=sDFz-RmTz_fp=U9S;8TSl5c z?{6Xv1+jyY9QxE?{$>Fqk01W3@=DoAz`yB!ww8GQ1KKVF(8ge%DfAcGHj@2-25Z+V zU-YH%czQ*+6+x@&F5HU#Kag!Lw;F4Sy$^u!OZG;--RPDaUKSz?)iBaD-0+n|8a;Td znp}akN$)+Q_7>|wyxBqgr;9+>P8HO=`!{SRAteGYJZ#5{8voA@BZ>bDH4r4I;u$Jrvd*1R8L77 literal 0 HcmV?d00001 diff --git a/examples/vertexattributes/separatebuffers.png b/examples/vertexattributes/separatebuffers.png new file mode 100644 index 0000000000000000000000000000000000000000..abbeec2b70b718c86b6fb4c5c1345409cf439de0 GIT binary patch literal 18867 zcmeIaby(DIyY3B0ioy&?OE@ARBHbNBDWOP9w}eP{gA9VC(jg%#jig9RgQSEY4boi$ z46yIP-}8H(XRWpO+VA_<{$m}-czDb(-@fkqzOK)8o)h*+MgIC#>Z=$S7}pgQ;A$8c zm@(krcYIv%$+Vr^1o#irNljiFqp0`h3I+xPh9X=_-Q8d#?YcABsLPf>Ter8zF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--!xX+8h|-6N#6cl9MUag0SFQE#1IyG#)@vnN&j)E7)y znAR)Xfdk*9bWJU$k0tY zs5vZt4p7|+UfNy7Q+F)y`PTw)q40BR7EfhRV2!u7g<(to0@8a=; zgcF`<2q>}O;kE`xt%V^H--K&d1X+z%EjOnRTdgU~v0B=nqY>lOc!`zc*O%B=Ylx6n{;6hlkP zAH!A<^Andi@{z&{hp+c87_gdD;7Y;{8-SA0lozhI14ke8q?t(t$45S>g{5T%wWU;h zW|~iKLFaqjvRTKJT83-7V}YqWz#>OuvpXp}au1iZTgTh6& indexBuffer, std::vector& vertexBuffer) { Node node{}; - + // Get the local node matrix // It's either made up from translation, rotation, scale or a 4x4 matrix node.matrix = glm::mat4(1.0f); @@ -46,7 +46,7 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt uint32_t firstIndex = static_cast(indexBuffer.size()); uint32_t vertexStart = static_cast(vertexBuffer.size()); uint32_t indexCount = 0; - + // Vertex attributes const float* positionBuffer = nullptr; const float* normalsBuffer = nullptr; @@ -90,7 +90,7 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt vert.normal = glm::normalize(glm::vec3(normalsBuffer ? glm::make_vec3(&normalsBuffer[v * 3]) : glm::vec3(0.0f))); vert.uv = texCoordsBuffer ? glm::make_vec2(&texCoordsBuffer[v * 2]) : glm::vec3(0.0f); vert.tangent = tangentsBuffer ? glm::make_vec4(&tangentsBuffer[v * 4]) : glm::vec4(0.0f); - vertexBuffer.push_back(vert); + vertexBuffer.push_back(vert); // Append separate attributes vertexAttributes.pos.push_back(glm::make_vec3(&positionBuffer[v * 3])); @@ -230,7 +230,8 @@ void VulkanExample::buildCommandBuffers() VkDeviceSize offsets[4] = { 0, 0, 0, 0 }; std::array buffers = { separateVertexBuffers.pos.buffer, separateVertexBuffers.normal.buffer, separateVertexBuffers.uv.buffer, separateVertexBuffers.tangent.buffer }; vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, static_cast(buffers.size()), buffers.data(), offsets); - } else { + } + else { // Using interleaved attribute bindings only requires one buffer to be bound VkDeviceSize offsets[1] = { 0 }; vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &interleavedVertexBuffer.buffer, offsets); @@ -319,7 +320,7 @@ void VulkanExample::uploadVertexData() // Create a staging buffer used as a source for copies auto createStagingBuffer = [this](vks::Buffer& buffer, void* data, VkDeviceSize size) { VK_CHECK_RESULT(vulkanDevice->createBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &buffer, size, data)); - }; + }; // Create a device local buffer used as a target for copies auto createDeviceBuffer = [this](vks::Buffer& buffer, VkDeviceSize size, VkBufferUsageFlags usageFlags = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) { VK_CHECK_RESULT(vulkanDevice->createBuffer(usageFlags | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &buffer, size)); @@ -492,13 +493,13 @@ void VulkanExample::preparePipelines() // Interleaved vertex attributes // One Binding (one buffer) and multiple attributes const std::vector vertexInputBindingsInterleaved = { - vks::initializers::vertexInputBindingDescription(0, sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX), + { 0, sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX }, }; const std::vector vertexInputAttributesInterleaved = { - vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, pos)), - vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, normal)), - vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32_SFLOAT, offsetof(Vertex, uv)), - vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(Vertex, tangent)), + { 0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, pos) }, + { 1, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, normal) }, + { 2, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(Vertex, uv) }, + { 3, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(Vertex, tangent) }, }; vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsInterleaved, vertexInputAttributesInterleaved); @@ -507,17 +508,18 @@ void VulkanExample::preparePipelines() // Separate vertex attribute // Multiple bindings (for each attribute buffer) and multiple attribues const std::vector vertexInputBindingsSeparate = { - vks::initializers::vertexInputBindingDescription(0, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX), - vks::initializers::vertexInputBindingDescription(1, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX), - vks::initializers::vertexInputBindingDescription(2, sizeof(glm::vec2), VK_VERTEX_INPUT_RATE_VERTEX), - vks::initializers::vertexInputBindingDescription(3, sizeof(glm::vec4), VK_VERTEX_INPUT_RATE_VERTEX), + { 0, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX }, + { 1, sizeof(glm::vec3), VK_VERTEX_INPUT_RATE_VERTEX }, + { 2, sizeof(glm::vec2), VK_VERTEX_INPUT_RATE_VERTEX }, + { 3, sizeof(glm::vec4), VK_VERTEX_INPUT_RATE_VERTEX }, }; const std::vector vertexInputAttributesSeparate = { - vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), - vks::initializers::vertexInputAttributeDescription(1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0), - vks::initializers::vertexInputAttributeDescription(2, 2, VK_FORMAT_R32G32_SFLOAT, 0), - vks::initializers::vertexInputAttributeDescription(3, 3, VK_FORMAT_R32G32B32A32_SFLOAT, 0), + { 0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0 }, + { 1, 1, VK_FORMAT_R32G32B32_SFLOAT, 0 }, + { 2, 2, VK_FORMAT_R32G32_SFLOAT, 0 }, + { 3, 3, VK_FORMAT_R32G32B32A32_SFLOAT, 0 }, }; + vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo(vertexInputBindingsSeparate, vertexInputAttributesSeparate); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.vertexAttributesSeparate)); } From aad5a7dd818ec9cbdb4069cbd8593305e069206a Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Fri, 21 Jan 2022 21:07:16 +0100 Subject: [PATCH 7/9] Code cleanup --- .../vertexattributes/vertexattributes.cpp | 23 ++++++++++--------- examples/vertexattributes/vertexattributes.h | 15 ++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/vertexattributes/vertexattributes.cpp b/examples/vertexattributes/vertexattributes.cpp index f382b3a7..1e61712c 100644 --- a/examples/vertexattributes/vertexattributes.cpp +++ b/examples/vertexattributes/vertexattributes.cpp @@ -8,7 +8,7 @@ #include "vertexattributes.h" -void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent, std::vector& indexBuffer, std::vector& vertexBuffer) +void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent) { Node node{}; @@ -32,7 +32,7 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt // Load node's children if (inputNode.children.size() > 0) { for (size_t i = 0; i < inputNode.children.size(); i++) { - loadSceneNode(input.nodes[inputNode.children[i]], input, &node, indexBuffer, vertexBuffer); + loadSceneNode(input.nodes[inputNode.children[i]], input, &node); } } @@ -93,10 +93,10 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt vertexBuffer.push_back(vert); // Append separate attributes - vertexAttributes.pos.push_back(glm::make_vec3(&positionBuffer[v * 3])); - vertexAttributes.normal.push_back(glm::normalize(glm::vec3(normalsBuffer ? glm::make_vec3(&normalsBuffer[v * 3]) : glm::vec3(0.0f)))); - vertexAttributes.tangent.push_back(tangentsBuffer ? glm::make_vec4(&tangentsBuffer[v * 4]) : glm::vec4(0.0f)); - vertexAttributes.uv.push_back(texCoordsBuffer ? glm::make_vec2(&texCoordsBuffer[v * 2]) : glm::vec3(0.0f)); + vertexAttributeBuffers.pos.push_back(glm::make_vec3(&positionBuffer[v * 3])); + vertexAttributeBuffers.normal.push_back(glm::normalize(glm::vec3(normalsBuffer ? glm::make_vec3(&normalsBuffer[v * 3]) : glm::vec3(0.0f)))); + vertexAttributeBuffers.tangent.push_back(tangentsBuffer ? glm::make_vec4(&tangentsBuffer[v * 4]) : glm::vec4(0.0f)); + vertexAttributeBuffers.uv.push_back(texCoordsBuffer ? glm::make_vec2(&texCoordsBuffer[v * 2]) : glm::vec3(0.0f)); } @@ -174,6 +174,7 @@ VulkanExample::~VulkanExample() separateVertexBuffers.pos.destroy(); separateVertexBuffers.tangent.destroy(); separateVertexBuffers.uv.destroy(); + interleavedVertexBuffer.destroy(); for (Image image : scene.images) { vkDestroyImageView(vulkanDevice->logicalDevice, image.texture.view, nullptr); vkDestroyImage(vulkanDevice->logicalDevice, image.texture.image, nullptr); @@ -306,7 +307,7 @@ void VulkanExample::loadglTFFile(std::string filename) const tinygltf::Scene& scene = glTFInput.scenes[0]; for (size_t i = 0; i < scene.nodes.size(); i++) { const tinygltf::Node node = glTFInput.nodes[scene.nodes[i]]; - loadSceneNode(node, glTFInput, nullptr, indexBuffer, vertexBuffer); + loadSceneNode(node, glTFInput, nullptr); } uploadVertexData(); @@ -350,10 +351,10 @@ void VulkanExample::uploadVertexData() We create multiple separate buffers for each of the vertex attributes (position, normals, etc.) */ std::array stagingBuffers; - createStagingBuffer(stagingBuffers[0], vertexAttributes.pos.data(), vertexAttributes.pos.size() * sizeof(vertexAttributes.pos[0])); - createStagingBuffer(stagingBuffers[1], vertexAttributes.normal.data(), vertexAttributes.normal.size() * sizeof(vertexAttributes.normal[0])); - createStagingBuffer(stagingBuffers[2], vertexAttributes.uv.data(), vertexAttributes.uv.size() * sizeof(vertexAttributes.uv[0])); - createStagingBuffer(stagingBuffers[3], vertexAttributes.tangent.data(), vertexAttributes.tangent.size() * sizeof(vertexAttributes.tangent[0])); + createStagingBuffer(stagingBuffers[0], vertexAttributeBuffers.pos.data(), vertexAttributeBuffers.pos.size() * sizeof(vertexAttributeBuffers.pos[0])); + createStagingBuffer(stagingBuffers[1], vertexAttributeBuffers.normal.data(), vertexAttributeBuffers.normal.size() * sizeof(vertexAttributeBuffers.normal[0])); + createStagingBuffer(stagingBuffers[2], vertexAttributeBuffers.uv.data(), vertexAttributeBuffers.uv.size() * sizeof(vertexAttributeBuffers.uv[0])); + createStagingBuffer(stagingBuffers[3], vertexAttributeBuffers.tangent.data(), vertexAttributeBuffers.tangent.size() * sizeof(vertexAttributeBuffers.tangent[0])); createDeviceBuffer(separateVertexBuffers.pos, stagingBuffers[0].size); createDeviceBuffer(separateVertexBuffers.normal, stagingBuffers[1].size); diff --git a/examples/vertexattributes/vertexattributes.h b/examples/vertexattributes/vertexattributes.h index 089ad9f7..af480ab0 100644 --- a/examples/vertexattributes/vertexattributes.h +++ b/examples/vertexattributes/vertexattributes.h @@ -67,13 +67,6 @@ struct Node { glm::mat4 matrix; }; -// Only used at loading time -struct VertexAttributes { - std::vector uv; - std::vector pos, normal; - std::vector tangent; -} vertexAttributes; - std::vector nodes; class VulkanExample : public VulkanExampleBase @@ -82,8 +75,14 @@ public: enum VertexAttributeSettings { interleaved, separate }; VertexAttributeSettings vertexAttributeSettings = separate; + // Used to store indices and vertices from glTF to be uploaded to the GPU std::vector indexBuffer; std::vector vertexBuffer; + struct VertexAttributes { + std::vector uv; + std::vector pos, normal; + std::vector tangent; + } vertexAttributeBuffers; // Buffers for the separate vertex attributes // @todo: rename @@ -137,7 +136,7 @@ public: void prepareUniformBuffers(); void updateUniformBuffers(); void prepare(); - void loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent, std::vector& indexBuffer, std::vector& vertexBuffer); + void loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent); void drawSceneNode(VkCommandBuffer commandBuffer, Node node); virtual void render(); virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay); From 704aeec6b0fbb1dbb41e8c39f62805cd43ef3078 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sat, 22 Jan 2022 10:03:39 +0100 Subject: [PATCH 8/9] Simplified glTF buffer code Added Android build files --- .../examples/vertexattributes/CMakeLists.txt | 35 ++++++++++ .../examples/vertexattributes/build.gradle | 65 +++++++++++++++++++ .../src/main/AndroidManifest.xml | 24 +++++++ .../vulkanSample/VulkanActivity.java | 58 +++++++++++++++++ .../vertexattributes/vertexattributes.cpp | 46 +++++-------- 5 files changed, 200 insertions(+), 28 deletions(-) create mode 100644 android/examples/vertexattributes/CMakeLists.txt create mode 100644 android/examples/vertexattributes/build.gradle create mode 100644 android/examples/vertexattributes/src/main/AndroidManifest.xml create mode 100644 android/examples/vertexattributes/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java diff --git a/android/examples/vertexattributes/CMakeLists.txt b/android/examples/vertexattributes/CMakeLists.txt new file mode 100644 index 00000000..8ddd2e72 --- /dev/null +++ b/android/examples/vertexattributes/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR) + +set(NAME vertexattributes) + +set(SRC_DIR ../../../examples/${NAME}) +set(BASE_DIR ../../../base) +set(EXTERNAL_DIR ../../../external) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DVK_USE_PLATFORM_ANDROID_KHR -DVK_NO_PROTOTYPES") + +file(GLOB EXAMPLE_SRC "${SRC_DIR}/*.cpp") + +add_library(native-lib SHARED ${EXAMPLE_SRC}) + +add_library(native-app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) + +add_subdirectory(../base ${CMAKE_SOURCE_DIR}/../base) + +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate") + +include_directories(${BASE_DIR}) +include_directories(${EXTERNAL_DIR}) +include_directories(${EXTERNAL_DIR}/glm) +include_directories(${EXTERNAL_DIR}/imgui) +include_directories(${EXTERNAL_DIR}/tinygltf) +include_directories(${ANDROID_NDK}/sources/android/native_app_glue) + +target_link_libraries( + native-lib + native-app-glue + libbase + android + log + z +) diff --git a/android/examples/vertexattributes/build.gradle b/android/examples/vertexattributes/build.gradle new file mode 100644 index 00000000..2ca7b87c --- /dev/null +++ b/android/examples/vertexattributes/build.gradle @@ -0,0 +1,65 @@ +apply plugin: 'com.android.application' +apply from: '../gradle/outputfilename.gradle' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "de.saschawillems.vulkanVertexattributes" + minSdkVersion 19 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + ndk { + abiFilters "armeabi-v7a" + } + externalNativeBuild { + cmake { + cppFlags "-std=c++14" + arguments "-DANDROID_STL=c++_shared", '-DANDROID_TOOLCHAIN=clang' + } + } + } + sourceSets { + main.assets.srcDirs = ['assets'] + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + path "CMakeLists.txt" + } + } +} + +task copyTask { + copy { + from '../../common/res/drawable' + into "src/main/res/drawable" + include 'icon.png' + } + + copy { + from '../../../data/shaders/glsl/base' + into 'assets/shaders/glsl/base' + include '*.spv' + } + + copy { + from '../../../data/shaders/glsl/vertexattributes' + into 'assets/shaders/glsl/vertexattributes' + include '*.*' + } + + copy { + from '../../../data/models/sponza' + into 'assets/models/sponza' + include '*.*' + } + +} + +preBuild.dependsOn copyTask \ No newline at end of file diff --git a/android/examples/vertexattributes/src/main/AndroidManifest.xml b/android/examples/vertexattributes/src/main/AndroidManifest.xml new file mode 100644 index 00000000..7345a106 --- /dev/null +++ b/android/examples/vertexattributes/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + diff --git a/android/examples/vertexattributes/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java b/android/examples/vertexattributes/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java new file mode 100644 index 00000000..12e14fc6 --- /dev/null +++ b/android/examples/vertexattributes/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2018 by Sascha Willems - www.saschawillems.de + * + * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + */ +package de.saschawillems.vulkanSample; + +import android.app.AlertDialog; +import android.app.NativeActivity; +import android.content.DialogInterface; +import android.content.pm.ApplicationInfo; +import android.os.Bundle; + +import java.util.concurrent.Semaphore; + +public class VulkanActivity extends NativeActivity { + + static { + // Load native library + System.loadLibrary("native-lib"); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + // Use a semaphore to create a modal dialog + + private final Semaphore semaphore = new Semaphore(0, true); + + public void showAlert(final String message) + { + final VulkanActivity activity = this; + + ApplicationInfo applicationInfo = activity.getApplicationInfo(); + final String applicationName = applicationInfo.nonLocalizedLabel.toString(); + + this.runOnUiThread(new Runnable() { + public void run() { + AlertDialog.Builder builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert); + builder.setTitle(applicationName); + builder.setMessage(message); + builder.setPositiveButton("Close", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + semaphore.release(); + } + }); + builder.setCancelable(false); + AlertDialog dialog = builder.create(); + dialog.show(); + } + }); + try { + semaphore.acquire(); + } + catch (InterruptedException e) { } + } +} diff --git a/examples/vertexattributes/vertexattributes.cpp b/examples/vertexattributes/vertexattributes.cpp index 1e61712c..b10f9991 100644 --- a/examples/vertexattributes/vertexattributes.cpp +++ b/examples/vertexattributes/vertexattributes.cpp @@ -54,34 +54,25 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt const float* tangentsBuffer = nullptr; size_t vertexCount = 0; - // Get buffer data for vertex positions - if (glTFPrimitive.attributes.find("POSITION") != glTFPrimitive.attributes.end()) { - const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("POSITION")->second]; - const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; - positionBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); - vertexCount = accessor.count; - } - // Get buffer data for vertex normals - if (glTFPrimitive.attributes.find("NORMAL") != glTFPrimitive.attributes.end()) { - const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("NORMAL")->second]; - const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; - normalsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); - } - // Get buffer data for vertex texture coordinates - // glTF supports multiple sets, we only load the first one - if (glTFPrimitive.attributes.find("TEXCOORD_0") != glTFPrimitive.attributes.end()) { - const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("TEXCOORD_0")->second]; - const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; - texCoordsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); - } - // POI: This sample uses normal mapping, so we also need to load the tangents from the glTF file - if (glTFPrimitive.attributes.find("TANGENT") != glTFPrimitive.attributes.end()) { - const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("TANGENT")->second]; - const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; - tangentsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); - } + // Anonymous functions to simplify buffer view access + auto getBuffer = [glTFPrimitive, input, &vertexCount](const std::string attributeName, const float* &bufferTarget) { + if (glTFPrimitive.attributes.find(attributeName) != glTFPrimitive.attributes.end()) { + const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find(attributeName)->second]; + const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView]; + bufferTarget = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset])); + if (attributeName == "POSITION") { + vertexCount = accessor.count; + } + } + }; - // Append data to model's vertex buffer + // Get buffer pointers to the vertex attributes used in this sample + getBuffer("POSITION", positionBuffer); + getBuffer("NORMAL", normalsBuffer); + getBuffer("TEXCOORD_0", texCoordsBuffer); + getBuffer("TANGENT", tangentsBuffer); + + // Append attributes to the vertex buffers for (size_t v = 0; v < vertexCount; v++) { // Append interleaved attributes @@ -97,7 +88,6 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt vertexAttributeBuffers.normal.push_back(glm::normalize(glm::vec3(normalsBuffer ? glm::make_vec3(&normalsBuffer[v * 3]) : glm::vec3(0.0f)))); vertexAttributeBuffers.tangent.push_back(tangentsBuffer ? glm::make_vec4(&tangentsBuffer[v * 4]) : glm::vec4(0.0f)); vertexAttributeBuffers.uv.push_back(texCoordsBuffer ? glm::make_vec2(&texCoordsBuffer[v * 2]) : glm::vec3(0.0f)); - } // Indices From 807d11387d4223d88274ebd3349c961e76994817 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sat, 22 Jan 2022 10:09:25 +0100 Subject: [PATCH 9/9] Added vertex attributes sample to the readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index dd9ff82d..cc54e2b0 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,11 @@ Implements a simple CPU based particle system. Particle data is stored in host m Uses the stencil buffer and its compare functionality for rendering a 3D model with dynamic outlines. + +#### [Vertex attributes](examples/vertexattributes/) + +Demonstrates two different ways of passing vertices to the vertex shader using either interleaved or separate vertex attributes. + ### glTF These samples show how implement different features of the [glTF 2.0 3D format](https://www.khronos.org/gltf/) 3D transmission file format in detail.