Commit f3518b10 authored by Laszlo Agocs's avatar Laszlo Agocs

vk: implement instance step rate

parent 4d35b6d0
......@@ -482,6 +482,8 @@ int main(int argc, char **argv)
<< "VK_LAYER_LUNARG_swapchain"
<< "VK_LAYER_GOOGLE_unique_objects");
#endif
inst.setExtensions(QByteArrayList()
<< "VK_KHR_get_physical_device_properties2");
if (!inst.create()) {
qWarning("Failed to create Vulkan instance, switching to OpenGL");
graphicsApi = OpenGL;
......
......@@ -154,6 +154,9 @@ void Window::customInit()
qDebug("isFeatureSupported(MultisampleTexture): %d", m_r->isFeatureSupported(QRhi::MultisampleTexture));
qDebug("isFeatureSupported(MultisampleRenderBuffer): %d", m_r->isFeatureSupported(QRhi::MultisampleRenderBuffer));
qDebug("isFeatureSupported(DebugMarkers): %d", m_r->isFeatureSupported(QRhi::DebugMarkers));
qDebug("isFeatureSupported(Timestamps): %d", m_r->isFeatureSupported(QRhi::Timestamps));
qDebug("isFeatureSupported(Instancing): %d", m_r->isFeatureSupported(QRhi::Instancing));
qDebug("isFeatureSupported(CustomInstanceStepRate): %d", m_r->isFeatureSupported(QRhi::CustomInstanceStepRate));
qDebug("Min 2D texture width/height: %d", m_r->resourceSizeLimit(QRhi::TextureSizeMin));
qDebug("Max 2D texture width/height: %d", m_r->resourceSizeLimit(QRhi::TextureSizeMax));
}
......
......@@ -1118,7 +1118,9 @@ public:
MultisampleTexture = 1,
MultisampleRenderBuffer,
DebugMarkers,
Timestamps
Timestamps,
Instancing,
CustomInstanceStepRate
};
enum ResourceSizeLimit {
......
......@@ -256,13 +256,17 @@ bool QRhiD3D11::isFeatureSupported(QRhi::Feature feature) const
{
switch (feature) {
case QRhi::MultisampleTexture:
Q_FALLTHROUGH();
return true;
case QRhi::MultisampleRenderBuffer:
return true;
case QRhi::DebugMarkers:
return annotations != nullptr;
case QRhi::Timestamps:
return true;
case QRhi::Instancing:
return true;
case QRhi::CustomInstanceStepRate:
return true;
default:
Q_UNREACHABLE();
return false;
......
......@@ -267,6 +267,10 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
return false;
case QRhi::Timestamps:
return false;
case QRhi::Instancing:
return false;
case QRhi::CustomInstanceStepRate:
return false;
default:
Q_UNREACHABLE();
return false;
......
......@@ -356,13 +356,17 @@ bool QRhiMetal::isFeatureSupported(QRhi::Feature feature) const
{
switch (feature) {
case QRhi::MultisampleTexture:
Q_FALLTHROUGH();
return true;
case QRhi::MultisampleRenderBuffer:
Q_FALLTHROUGH();
return true;
case QRhi::DebugMarkers:
return true;
case QRhi::Timestamps:
return false;
case QRhi::Instancing:
return true;
case QRhi::CustomInstanceStepRate:
return true;
default:
Q_UNREACHABLE();
return false;
......
......@@ -260,12 +260,15 @@ bool QRhiVulkan::create(QRhi::Flags flags)
requestedDevExts.append("VK_KHR_swapchain");
debugMarkersAvailable = false;
if (debugMarkers) {
for (const VkExtensionProperties &ext : devExts) {
if (!strcmp(ext.extensionName, VK_EXT_DEBUG_MARKER_EXTENSION_NAME)) {
requestedDevExts.append(VK_EXT_DEBUG_MARKER_EXTENSION_NAME);
debugMarkersAvailable = true;
break;
vertexAttribDivisorAvailable = false;
for (const VkExtensionProperties &ext : devExts) {
if (!strcmp(ext.extensionName, VK_EXT_DEBUG_MARKER_EXTENSION_NAME)) {
requestedDevExts.append(VK_EXT_DEBUG_MARKER_EXTENSION_NAME);
debugMarkersAvailable = true;
} else if (!strcmp(ext.extensionName, VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME)) {
if (inst->extensions().contains(QByteArrayLiteral("VK_KHR_get_physical_device_properties2"))) {
requestedDevExts.append(VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME);
vertexAttribDivisorAvailable = true;
}
}
}
......@@ -2753,13 +2756,17 @@ bool QRhiVulkan::isFeatureSupported(QRhi::Feature feature) const
{
switch (feature) {
case QRhi::MultisampleTexture:
Q_FALLTHROUGH();
return true;
case QRhi::MultisampleRenderBuffer:
return true;
case QRhi::DebugMarkers:
return debugMarkersAvailable;
case QRhi::Timestamps:
return timestampValidBits != 0;
case QRhi::Instancing:
return true;
case QRhi::CustomInstanceStepRate:
return vertexAttribDivisorAvailable;
default:
Q_UNREACHABLE();
return false;
......@@ -3027,7 +3034,7 @@ void QRhiVulkan::drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
void QRhiVulkan::debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name)
{
if (!debugMarkersAvailable)
if (!debugMarkers || !debugMarkersAvailable)
return;
VkDebugMarkerMarkerInfoEXT marker;
......@@ -3039,7 +3046,7 @@ void QRhiVulkan::debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name)
void QRhiVulkan::debugMarkEnd(QRhiCommandBuffer *cb)
{
if (!debugMarkersAvailable)
if (!debugMarkers || !debugMarkersAvailable)
return;
vkCmdDebugMarkerEnd(QRHI_RES(QVkCommandBuffer, cb)->cb);
......@@ -3047,7 +3054,7 @@ void QRhiVulkan::debugMarkEnd(QRhiCommandBuffer *cb)
void QRhiVulkan::debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg)
{
if (!debugMarkersAvailable)
if (!debugMarkers || !debugMarkersAvailable)
return;
VkDebugMarkerMarkerInfoEXT marker;
......@@ -3059,7 +3066,7 @@ void QRhiVulkan::debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg)
void QRhiVulkan::setObjectName(uint64_t object, VkDebugReportObjectTypeEXT type, const QByteArray &name)
{
if (!debugMarkersAvailable || name.isEmpty())
if (!debugMarkers || !debugMarkersAvailable || name.isEmpty())
return;
VkDebugMarkerObjectNameInfoEXT nameInfo;
......@@ -4233,6 +4240,7 @@ bool QVkGraphicsPipeline::build()
pipelineInfo.pStages = shaderStageCreateInfos.constData();
QVarLengthArray<VkVertexInputBindingDescription, 4> vertexBindings;
QVarLengthArray<VkVertexInputBindingDivisorDescriptionEXT> nonOneStepRates;
for (int i = 0, ie = m_vertexInputLayout.bindings.count(); i != ie; ++i) {
const QRhiVertexInputLayout::Binding &binding(m_vertexInputLayout.bindings[i]);
VkVertexInputBindingDescription bindingInfo = {
......@@ -4244,8 +4252,13 @@ bool QVkGraphicsPipeline::build()
if (binding.classification == QRhiVertexInputLayout::Binding::PerInstance
&& binding.instanceStepRate != 1)
{
// ### could be supported with VK_EXT_vertex_attribute_divisor (Vulkan 1.1)
qWarning("QRhiVulkan: Instance step rates other than 1 not currently supported");
if (rhiD->vertexAttribDivisorAvailable) {
nonOneStepRates.append({ uint32_t(i), uint32_t(binding.instanceStepRate) });
} else {
qWarning("QRhiVulkan: Instance step rates other than 1 not supported without "
"VK_EXT_vertex_attribute_divisor on the device and "
"VK_KHR_get_physical_device_properties2 on the instance");
}
}
vertexBindings.append(bindingInfo);
}
......@@ -4266,6 +4279,14 @@ bool QVkGraphicsPipeline::build()
vertexInputInfo.pVertexBindingDescriptions = vertexBindings.constData();
vertexInputInfo.vertexAttributeDescriptionCount = vertexAttributes.count();
vertexInputInfo.pVertexAttributeDescriptions = vertexAttributes.constData();
VkPipelineVertexInputDivisorStateCreateInfoEXT divisorInfo;
if (!nonOneStepRates.isEmpty()) {
memset(&divisorInfo, 0, sizeof(divisorInfo));
divisorInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT;
divisorInfo.vertexBindingDivisorCount = nonOneStepRates.count();
divisorInfo.pVertexBindingDivisors = nonOneStepRates.constData();
vertexInputInfo.pNext = &divisorInfo;
}
pipelineInfo.pVertexInputState = &vertexInputInfo;
QVarLengthArray<VkDynamicState, 8> dynEnable;
......
......@@ -486,6 +486,7 @@ public:
VkDeviceSize texbufAlign;
bool debugMarkersAvailable = false;
bool vertexAttribDivisorAvailable = false;
PFN_vkCmdDebugMarkerBeginEXT vkCmdDebugMarkerBegin = nullptr;
PFN_vkCmdDebugMarkerEndEXT vkCmdDebugMarkerEnd = nullptr;
PFN_vkCmdDebugMarkerInsertEXT vkCmdDebugMarkerInsert = nullptr;
......
......@@ -19,7 +19,6 @@ more QImage->tex formats
if tex adjust its size (e.g. npot on gl), should QImage get scaled automatically?
d3d, gl, mtl: cache shader sources?
gl: ubuf structs, arrays
vk: support instanceStepRate via VK_EXT_vertex_attribute_divisor
test cubemap face as target
test cubemap face readback
object names for other than buf/rb/tex
......@@ -48,6 +47,7 @@ dxc for d3d as an alternative to fxc?
hlsl -> dxc -> spirv -> spirv-cross hmmm...
+++ done
vk: support instanceStepRate via VK_EXT_vertex_attribute_divisor
resize to 0 width or height fails (vk, d3d)
vk: rendering hangs sometimes when minimize and back on some systems?
allow requesting no-vsync present mode where applicable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment