forked from MoonsideGames/Refresh
handle case where shader does not take samplers
parent
a586040123
commit
14993a4f22
|
@ -687,7 +687,13 @@ typedef struct VulkanRenderer
|
||||||
VkDescriptorPool *descriptorPools;
|
VkDescriptorPool *descriptorPools;
|
||||||
uint32_t descriptorPoolCount;
|
uint32_t descriptorPoolCount;
|
||||||
|
|
||||||
VkDescriptorPool UBODescriptorPool;
|
/* initialize baseline descriptor info */
|
||||||
|
VkDescriptorPool defaultDescriptorPool;
|
||||||
|
VkDescriptorSetLayout emptyVertexSamplerLayout;
|
||||||
|
VkDescriptorSetLayout emptyFragmentSamplerLayout;
|
||||||
|
VkDescriptorSet emptyVertexSamplerDescriptorSet;
|
||||||
|
VkDescriptorSet emptyFragmentSamplerDescriptorSet;
|
||||||
|
|
||||||
VkDescriptorSetLayout vertexParamLayout;
|
VkDescriptorSetLayout vertexParamLayout;
|
||||||
VkDescriptorSetLayout fragmentParamLayout;
|
VkDescriptorSetLayout fragmentParamLayout;
|
||||||
VkDescriptorSet vertexUBODescriptorSet;
|
VkDescriptorSet vertexUBODescriptorSet;
|
||||||
|
@ -2894,7 +2900,12 @@ static REFRESH_GraphicsPipeline* VULKAN_CreateGraphicsPipeline(
|
||||||
/* TODO: should we hash these? */
|
/* TODO: should we hash these? */
|
||||||
|
|
||||||
/* Vertex sampler layout */
|
/* Vertex sampler layout */
|
||||||
/* TODO: should we let the user split up images and samplers? */
|
if (pipelineCreateInfo->pipelineLayoutCreateInfo.vertexSamplerBindingCount == 0)
|
||||||
|
{
|
||||||
|
setLayouts[0] = renderer->emptyVertexSamplerLayout;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (i = 0; i < pipelineCreateInfo->pipelineLayoutCreateInfo.vertexSamplerBindingCount; i += 1)
|
for (i = 0; i < pipelineCreateInfo->pipelineLayoutCreateInfo.vertexSamplerBindingCount; i += 1)
|
||||||
{
|
{
|
||||||
vertexSamplerLayoutBindings[i].binding =
|
vertexSamplerLayoutBindings[i].binding =
|
||||||
|
@ -2932,9 +2943,15 @@ static REFRESH_GraphicsPipeline* VULKAN_CreateGraphicsPipeline(
|
||||||
SDL_stack_free(fragmentSamplerLayoutBindings);
|
SDL_stack_free(fragmentSamplerLayoutBindings);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Frag sampler layout */
|
/* Frag sampler layout */
|
||||||
|
if (pipelineCreateInfo->pipelineLayoutCreateInfo.fragmentSamplerBindingCount == 0)
|
||||||
|
{
|
||||||
|
setLayouts[1] = renderer->emptyFragmentSamplerLayout;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (i = 0; i < pipelineCreateInfo->pipelineLayoutCreateInfo.fragmentSamplerBindingCount; i += 1)
|
for (i = 0; i < pipelineCreateInfo->pipelineLayoutCreateInfo.fragmentSamplerBindingCount; i += 1)
|
||||||
{
|
{
|
||||||
fragmentSamplerLayoutBindings[i].binding =
|
fragmentSamplerLayoutBindings[i].binding =
|
||||||
|
@ -2969,6 +2986,7 @@ static REFRESH_GraphicsPipeline* VULKAN_CreateGraphicsPipeline(
|
||||||
SDL_stack_free(fragmentSamplerLayoutBindings);
|
SDL_stack_free(fragmentSamplerLayoutBindings);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setLayouts[2] = renderer->vertexParamLayout;
|
setLayouts[2] = renderer->vertexParamLayout;
|
||||||
setLayouts[3] = renderer->fragmentParamLayout;
|
setLayouts[3] = renderer->fragmentParamLayout;
|
||||||
|
@ -4677,6 +4695,17 @@ static void VULKAN_BindGraphicsPipeline(
|
||||||
VulkanRenderer* renderer = (VulkanRenderer*) driverData;
|
VulkanRenderer* renderer = (VulkanRenderer*) driverData;
|
||||||
VulkanGraphicsPipeline* pipeline = (VulkanGraphicsPipeline*) graphicsPipeline;
|
VulkanGraphicsPipeline* pipeline = (VulkanGraphicsPipeline*) graphicsPipeline;
|
||||||
|
|
||||||
|
/* bind dummy samplers */
|
||||||
|
if (pipeline->vertexSamplerBindingCount == 0)
|
||||||
|
{
|
||||||
|
pipeline->vertexSamplerDescriptorSet = renderer->emptyVertexSamplerDescriptorSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pipeline->fragmentSamplerBindingCount == 0)
|
||||||
|
{
|
||||||
|
pipeline->fragmentSamplerDescriptorSet = renderer->emptyFragmentSamplerDescriptorSet;
|
||||||
|
}
|
||||||
|
|
||||||
RECORD_CMD(renderer->vkCmdBindPipeline(
|
RECORD_CMD(renderer->vkCmdBindPipeline(
|
||||||
renderer->currentCommandBuffer,
|
renderer->currentCommandBuffer,
|
||||||
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
|
@ -5713,12 +5742,16 @@ static REFRESH_Device* VULKAN_CreateDevice(
|
||||||
|
|
||||||
/* Variables: Shader param layouts */
|
/* Variables: Shader param layouts */
|
||||||
VkDescriptorSetLayoutCreateInfo setLayoutCreateInfo;
|
VkDescriptorSetLayoutCreateInfo setLayoutCreateInfo;
|
||||||
|
VkDescriptorSetLayoutBinding emptyVertexSamplerLayoutBinding;
|
||||||
|
VkDescriptorSetLayoutBinding emptyFragmentSamplerLayoutBinding;
|
||||||
VkDescriptorSetLayoutBinding vertexParamLayoutBinding;
|
VkDescriptorSetLayoutBinding vertexParamLayoutBinding;
|
||||||
VkDescriptorSetLayoutBinding fragmentParamLayoutBinding;
|
VkDescriptorSetLayoutBinding fragmentParamLayoutBinding;
|
||||||
|
|
||||||
/* Variables: UBO Creation */
|
/* Variables: UBO Creation */
|
||||||
VkDescriptorPoolCreateInfo uboDescriptorPoolInfo;
|
VkDescriptorPoolCreateInfo defaultDescriptorPoolInfo;
|
||||||
VkDescriptorPoolSize uboPoolSize;
|
VkDescriptorPoolSize poolSizes[2];
|
||||||
|
VkDescriptorSetAllocateInfo emptyVertexSamplerDescriptorAllocateInfo;
|
||||||
|
VkDescriptorSetAllocateInfo emptyFragmentSamplerDescriptorAllocateInfo;
|
||||||
VkDescriptorSetAllocateInfo vertexUBODescriptorAllocateInfo;
|
VkDescriptorSetAllocateInfo vertexUBODescriptorAllocateInfo;
|
||||||
VkDescriptorSetAllocateInfo fragmentUBODescriptorAllocateInfo;
|
VkDescriptorSetAllocateInfo fragmentUBODescriptorAllocateInfo;
|
||||||
|
|
||||||
|
@ -5983,6 +6016,44 @@ static REFRESH_Device* VULKAN_CreateDevice(
|
||||||
|
|
||||||
/* Set up UBO layouts */
|
/* Set up UBO layouts */
|
||||||
|
|
||||||
|
emptyVertexSamplerLayoutBinding.binding = 0;
|
||||||
|
emptyVertexSamplerLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
|
emptyVertexSamplerLayoutBinding.descriptorCount = 0;
|
||||||
|
emptyVertexSamplerLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
|
emptyVertexSamplerLayoutBinding.pImmutableSamplers = NULL;
|
||||||
|
|
||||||
|
setLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||||
|
setLayoutCreateInfo.pNext = NULL;
|
||||||
|
setLayoutCreateInfo.flags = 0;
|
||||||
|
setLayoutCreateInfo.bindingCount = 1;
|
||||||
|
setLayoutCreateInfo.pBindings = &emptyVertexSamplerLayoutBinding;
|
||||||
|
|
||||||
|
vulkanResult = renderer->vkCreateDescriptorSetLayout(
|
||||||
|
renderer->logicalDevice,
|
||||||
|
&setLayoutCreateInfo,
|
||||||
|
NULL,
|
||||||
|
&renderer->emptyVertexSamplerLayout
|
||||||
|
);
|
||||||
|
|
||||||
|
emptyFragmentSamplerLayoutBinding.binding = 0;
|
||||||
|
emptyFragmentSamplerLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
|
emptyFragmentSamplerLayoutBinding.descriptorCount = 0;
|
||||||
|
emptyFragmentSamplerLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
emptyFragmentSamplerLayoutBinding.pImmutableSamplers = NULL;
|
||||||
|
|
||||||
|
setLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||||
|
setLayoutCreateInfo.pNext = NULL;
|
||||||
|
setLayoutCreateInfo.flags = 0;
|
||||||
|
setLayoutCreateInfo.bindingCount = 1;
|
||||||
|
setLayoutCreateInfo.pBindings = &emptyFragmentSamplerLayoutBinding;
|
||||||
|
|
||||||
|
vulkanResult = renderer->vkCreateDescriptorSetLayout(
|
||||||
|
renderer->logicalDevice,
|
||||||
|
&setLayoutCreateInfo,
|
||||||
|
NULL,
|
||||||
|
&renderer->emptyFragmentSamplerLayout
|
||||||
|
);
|
||||||
|
|
||||||
vertexParamLayoutBinding.binding = 0;
|
vertexParamLayoutBinding.binding = 0;
|
||||||
vertexParamLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
vertexParamLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
||||||
vertexParamLayoutBinding.descriptorCount = 1;
|
vertexParamLayoutBinding.descriptorCount = 1;
|
||||||
|
@ -6030,28 +6101,55 @@ static REFRESH_Device* VULKAN_CreateDevice(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* UBO Descriptors */
|
/* Default Descriptors */
|
||||||
|
|
||||||
uboPoolSize.descriptorCount = 2;
|
poolSizes[0].descriptorCount = 2;
|
||||||
uboPoolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
poolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
|
|
||||||
uboDescriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
poolSizes[1].descriptorCount = 2;
|
||||||
uboDescriptorPoolInfo.pNext = NULL;
|
poolSizes[1].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
|
||||||
uboDescriptorPoolInfo.flags = 0;
|
|
||||||
uboDescriptorPoolInfo.maxSets = 2;
|
defaultDescriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
uboDescriptorPoolInfo.poolSizeCount = 1;
|
defaultDescriptorPoolInfo.pNext = NULL;
|
||||||
uboDescriptorPoolInfo.pPoolSizes = &uboPoolSize;
|
defaultDescriptorPoolInfo.flags = 0;
|
||||||
|
defaultDescriptorPoolInfo.maxSets = 4;
|
||||||
|
defaultDescriptorPoolInfo.poolSizeCount = 2;
|
||||||
|
defaultDescriptorPoolInfo.pPoolSizes = poolSizes;
|
||||||
|
|
||||||
renderer->vkCreateDescriptorPool(
|
renderer->vkCreateDescriptorPool(
|
||||||
renderer->logicalDevice,
|
renderer->logicalDevice,
|
||||||
&uboDescriptorPoolInfo,
|
&defaultDescriptorPoolInfo,
|
||||||
NULL,
|
NULL,
|
||||||
&renderer->UBODescriptorPool
|
&renderer->defaultDescriptorPool
|
||||||
|
);
|
||||||
|
|
||||||
|
emptyVertexSamplerDescriptorAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
|
emptyVertexSamplerDescriptorAllocateInfo.pNext = NULL;
|
||||||
|
emptyVertexSamplerDescriptorAllocateInfo.descriptorPool = renderer->defaultDescriptorPool;
|
||||||
|
emptyVertexSamplerDescriptorAllocateInfo.descriptorSetCount = 1;
|
||||||
|
emptyVertexSamplerDescriptorAllocateInfo.pSetLayouts = &renderer->emptyVertexSamplerLayout;
|
||||||
|
|
||||||
|
renderer->vkAllocateDescriptorSets(
|
||||||
|
renderer->logicalDevice,
|
||||||
|
&emptyVertexSamplerDescriptorAllocateInfo,
|
||||||
|
&renderer->emptyVertexSamplerDescriptorSet
|
||||||
|
);
|
||||||
|
|
||||||
|
emptyFragmentSamplerDescriptorAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
|
emptyFragmentSamplerDescriptorAllocateInfo.pNext = NULL;
|
||||||
|
emptyFragmentSamplerDescriptorAllocateInfo.descriptorPool = renderer->defaultDescriptorPool;
|
||||||
|
emptyFragmentSamplerDescriptorAllocateInfo.descriptorSetCount = 1;
|
||||||
|
emptyFragmentSamplerDescriptorAllocateInfo.pSetLayouts = &renderer->emptyFragmentSamplerLayout;
|
||||||
|
|
||||||
|
renderer->vkAllocateDescriptorSets(
|
||||||
|
renderer->logicalDevice,
|
||||||
|
&emptyFragmentSamplerDescriptorAllocateInfo,
|
||||||
|
&renderer->emptyFragmentSamplerDescriptorSet
|
||||||
);
|
);
|
||||||
|
|
||||||
vertexUBODescriptorAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
vertexUBODescriptorAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
vertexUBODescriptorAllocateInfo.pNext = NULL;
|
vertexUBODescriptorAllocateInfo.pNext = NULL;
|
||||||
vertexUBODescriptorAllocateInfo.descriptorPool = renderer->UBODescriptorPool;
|
vertexUBODescriptorAllocateInfo.descriptorPool = renderer->defaultDescriptorPool;
|
||||||
vertexUBODescriptorAllocateInfo.descriptorSetCount = 1;
|
vertexUBODescriptorAllocateInfo.descriptorSetCount = 1;
|
||||||
vertexUBODescriptorAllocateInfo.pSetLayouts = &renderer->vertexParamLayout;
|
vertexUBODescriptorAllocateInfo.pSetLayouts = &renderer->vertexParamLayout;
|
||||||
|
|
||||||
|
@ -6063,7 +6161,7 @@ static REFRESH_Device* VULKAN_CreateDevice(
|
||||||
|
|
||||||
fragmentUBODescriptorAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
fragmentUBODescriptorAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
fragmentUBODescriptorAllocateInfo.pNext = NULL;
|
fragmentUBODescriptorAllocateInfo.pNext = NULL;
|
||||||
fragmentUBODescriptorAllocateInfo.descriptorPool = renderer->UBODescriptorPool;
|
fragmentUBODescriptorAllocateInfo.descriptorPool = renderer->defaultDescriptorPool;
|
||||||
fragmentUBODescriptorAllocateInfo.descriptorSetCount = 1;
|
fragmentUBODescriptorAllocateInfo.descriptorSetCount = 1;
|
||||||
fragmentUBODescriptorAllocateInfo.pSetLayouts = &renderer->fragmentParamLayout;
|
fragmentUBODescriptorAllocateInfo.pSetLayouts = &renderer->fragmentParamLayout;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue