Merge pull request #279 from cdavis5e/vertex-attribute-divisor

Support the VK_EXT_vertex_attribute_divisor extension.
This commit is contained in:
Bill Hollings 2018-09-25 11:59:49 -04:00 committed by GitHub
commit c89d22fc31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 3 deletions

View File

@ -77,7 +77,7 @@ public:
void getFeatures(VkPhysicalDeviceFeatures* features);
/** Populates the specified structure with the features of this device. */
void getFeatures(VkPhysicalDeviceFeatures2KHR* features);
void getFeatures(VkPhysicalDeviceFeatures2* features);
/** Populates the specified structure with the Metal-specific features of this device. */
void getMetalFeatures(MVKPhysicalDeviceMetalFeatures* mtlFeatures);

View File

@ -58,10 +58,25 @@ void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures* features) {
if (features) { *features = _features; }
}
void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures2KHR* features) {
void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures2* features) {
if (features) {
features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
features->features = _features;
auto* next = (VkStructureType*)features->pNext;
while (next) {
switch (*next) {
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: {
auto* divisorFeatures = (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT*)next;
divisorFeatures->vertexAttributeInstanceRateDivisor = true;
divisorFeatures->vertexAttributeInstanceRateZeroDivisor = true;
next = (VkStructureType*)divisorFeatures->pNext;
break;
}
default:
next = (VkStructureType*)((VkPhysicalDeviceFeatures2*)next)->pNext;
break;
}
}
}
}
@ -92,6 +107,12 @@ void MVKPhysicalDevice::getProperties(VkPhysicalDeviceProperties2* properties) {
next = (VkStructureType*)pointClipProps->pNext;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT: {
auto* divisorProps = (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT*)next;
divisorProps->maxVertexAttribDivisor = kMVKUndefinedLargeUInt32;
next = (VkStructureType*)divisorProps->pNext;
break;
}
default:
next = (VkStructureType*)((VkPhysicalDeviceProperties2*)next)->pNext;
break;

View File

@ -278,6 +278,21 @@ void MVKGraphicsPipeline::initMTLRenderPipelineState(const VkGraphicsPipelineCre
// Returns a MTLRenderPipelineDescriptor constructed from this instance, or nil if an error occurs.
MTLRenderPipelineDescriptor* MVKGraphicsPipeline::getMTLRenderPipelineDescriptor(const VkGraphicsPipelineCreateInfo* pCreateInfo) {
// Collect extension structures
VkPipelineVertexInputDivisorStateCreateInfoEXT* pVertexInputDivisorState = nullptr;
VkStructureType* next = (VkStructureType*)pCreateInfo->pNext;
while (next) {
switch (*next) {
case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT:
pVertexInputDivisorState = (VkPipelineVertexInputDivisorStateCreateInfoEXT*)next;
next = (VkStructureType*)pVertexInputDivisorState->pNext;
break;
default:
next = (VkStructureType*)((VkGraphicsPipelineCreateInfo*)next)->pNext;
break;
}
}
SPIRVToMSLConverterContext shaderContext;
initMVKShaderConverterContext(shaderContext, pCreateInfo);
@ -342,6 +357,24 @@ MTLRenderPipelineDescriptor* MVKGraphicsPipeline::getMTLRenderPipelineDescriptor
}
}
// Vertex buffer divisors (step rates)
if (pVertexInputDivisorState) {
vbCnt = pVertexInputDivisorState->vertexBindingDivisorCount;
for (uint32_t i = 0; i < vbCnt; i++) {
const VkVertexInputBindingDivisorDescriptionEXT* pVKVB = &pVertexInputDivisorState->pVertexBindingDivisors[i];
uint32_t vbIdx = _device->getMetalBufferIndexForVertexAttributeBinding(pVKVB->binding);
if (shaderContext.isVertexBufferUsed(vbIdx)) {
MTLVertexBufferLayoutDescriptor* vbDesc = plDesc.vertexDescriptor.layouts[vbIdx];
if (vbDesc.stepFunction == MTLVertexStepFunctionPerInstance) {
if (pVKVB->divisor == 0)
vbDesc.stepFunction = MTLVertexStepFunctionConstant;
else
vbDesc.stepRate = pVKVB->divisor;
}
}
}
}
// Color attachments
if (pCreateInfo->pColorBlendState) {
for (uint32_t caIdx = 0; caIdx < pCreateInfo->pColorBlendState->attachmentCount; caIdx++) {

View File

@ -43,6 +43,7 @@ MVK_EXTENSION(KHR_shader_draw_parameters, KHR_SHADER_DRAW_PARAMETERS)
MVK_EXTENSION(KHR_surface, KHR_SURFACE)
MVK_EXTENSION(KHR_swapchain, KHR_SWAPCHAIN)
MVK_EXTENSION(EXT_shader_viewport_index_layer, EXT_SHADER_VIEWPORT_INDEX_LAYER)
MVK_EXTENSION(EXT_vertex_attribute_divisor, EXT_VERTEX_ATTRIBUTE_DIVISOR)
MVK_EXTENSION(MVK_ios_surface, MVK_IOS_SURFACE)
MVK_EXTENSION(MVK_macos_surface, MVK_MACOS_SURFACE)
MVK_EXTENSION(MVK_moltenvk, MVK_MOLTENVK)