Skip to content

Commit

Permalink
Added more YUV helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
corporateshark committed Jul 2, 2024
1 parent 8e6f0ce commit 1b69d7b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
38 changes: 36 additions & 2 deletions lvk/vulkan/VulkanUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,16 @@ VkSpecializationInfo lvk::getPipelineShaderStageSpecializationInfo(lvk::Speciali
};
}

VkBindImageMemoryInfo lvk::getBindImageMemoryInfo(const VkBindImagePlaneMemoryInfo* next, VkImage image, VkDeviceMemory memory) {
return VkBindImageMemoryInfo{
.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO,
.pNext = next,
.image = image,
.memory = memory,
.memoryOffset = 0,
};
}

VkPipelineShaderStageCreateInfo lvk::getPipelineShaderStageCreateInfo(VkShaderStageFlagBits stage,
VkShaderModule shaderModule,
const char* entryPoint,
Expand Down Expand Up @@ -753,14 +763,38 @@ VkResult lvk::allocateMemory(VkPhysicalDevice physDev,
return vkAllocateMemory(device, &ai, nullptr, outMemory);
}

VkDescriptorSetLayoutBinding lvk::getDSLBinding(uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount) {
VkResult lvk::allocateMemory2(VkPhysicalDevice physDev,
VkDevice device,
const VkMemoryRequirements2* memRequirements,
VkMemoryPropertyFlags props,
VkDeviceMemory* outMemory) {
assert(memRequirements);

const VkMemoryAllocateFlagsInfo memoryAllocateFlagsInfo = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO,
.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR,
};
const VkMemoryAllocateInfo ai = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = &memoryAllocateFlagsInfo,
.allocationSize = memRequirements->memoryRequirements.size,
.memoryTypeIndex = findMemoryType(physDev, memRequirements->memoryRequirements.memoryTypeBits, props),
};

return vkAllocateMemory(device, &ai, NULL, outMemory);
}

VkDescriptorSetLayoutBinding lvk::getDSLBinding(uint32_t binding,
VkDescriptorType descriptorType,
uint32_t descriptorCount,
const VkSampler* immutableSamplers) {
return VkDescriptorSetLayoutBinding{
.binding = binding,
.descriptorType = descriptorType,
.descriptorCount = descriptorCount,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT |
VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT,
.pImmutableSamplers = nullptr,
.pImmutableSamplers = immutableSamplers,
};
}

Expand Down
12 changes: 11 additions & 1 deletion lvk/vulkan/VulkanUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ VkResult allocateMemory(VkPhysicalDevice physDev,
const VkMemoryRequirements* memRequirements,
VkMemoryPropertyFlags props,
VkDeviceMemory* outMemory);
VkResult allocateMemory2(VkPhysicalDevice physDev,
VkDevice device,
const VkMemoryRequirements2* memRequirements,
VkMemoryPropertyFlags props,
VkDeviceMemory* outMemory);

glslang_resource_t getGlslangResource(const VkPhysicalDeviceLimits& limits);
Result compileShader(VkShaderStageFlagBits stage,
Expand All @@ -78,12 +83,17 @@ Result compileShader(VkShaderStageFlagBits stage,
const glslang_resource_t* glslLangResource = nullptr);

VkSamplerCreateInfo samplerStateDescToVkSamplerCreateInfo(const lvk::SamplerStateDesc& desc, const VkPhysicalDeviceLimits& limits);
VkDescriptorSetLayoutBinding getDSLBinding(uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount);
VkDescriptorSetLayoutBinding getDSLBinding(uint32_t binding,
VkDescriptorType descriptorType,
uint32_t descriptorCount,
const VkSampler* immutableSamplers = nullptr);
VkSpecializationInfo getPipelineShaderStageSpecializationInfo(lvk::SpecializationConstantDesc desc, VkSpecializationMapEntry* outEntries);
VkPipelineShaderStageCreateInfo getPipelineShaderStageCreateInfo(VkShaderStageFlagBits stage,
VkShaderModule shaderModule,
const char* entryPoint,
const VkSpecializationInfo* specializationInfo);
VkBindImageMemoryInfo getBindImageMemoryInfo(const VkBindImagePlaneMemoryInfo* next, VkImage image, VkDeviceMemory memory);

void imageMemoryBarrier(VkCommandBuffer buffer,
VkImage image,
VkAccessFlags srcAccessMask,
Expand Down

0 comments on commit 1b69d7b

Please sign in to comment.