Skip to content

Commit 887bc0c

Browse files
committed
Very quick addition to deprecated.adoc to add shader objects as per F2F request.
1 parent 2b62314 commit 887bc0c

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

chapters/deprecated.adoc

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ The following table lists deprecated items in Vulkan along with their replacemen
8282
|Renamed to `VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT_KHR` to better describe the scope of what resources in the shader are described by the access flag.
8383
|With VK_KHR_synchronization2
8484
|link:https://vulkan.gpuinfo.org/displayextensiondetail.php?extension=VK_KHR_synchronization2[View on GPU Info]
85+
86+
|Pipeline Objects
87+
|`VkPipeline` objects (graphics and compute) used to bind shaders and fixed-function state as a monolithic unit.
88+
|Use Shader Objects via `VK_EXT_shader_object` for a pipeline-free workflow that binds shaders and state directly. See <<pipelines_shader_objects_replacement>> for details.
89+
|With VK_EXT_shader_object
90+
|link:https://vulkan.gpuinfo.org/displayextensiondetail.php?extension=VK_EXT_shader_object[View on GPU Info]
8591
|===
8692

8793
== How to Use This Guide
@@ -1094,3 +1100,108 @@ void RenderFrame(VkCommandBuffer commandBuffer, VkImageView colorImageView, VkCl
10941100
}
10951101
}
10961102
----
1103+
1104+
1105+
[[pipelines_shader_objects_replacement]]
1106+
=== Pipeline Objects
1107+
1108+
Pipeline objects (`VkPipeline` for graphics and compute) are not formally deprecated, but when `VK_EXT_shader_object` is available they are recommended to be replaced by Shader Objects for a more flexible, modular workflow.
1109+
1110+
==== What They Were
1111+
1112+
Pipelines encapsulate shader stages and fixed-function state into a single monolithic object created up front (e.g., via `vkCreateGraphicsPipelines` / `vkCreateComputePipelines`). They are efficient at execution time, but can be expensive to create and inflexible when frequently changing shaders or state.
1113+
1114+
==== Replacement
1115+
1116+
Shader Objects (`VK_EXT_shader_object`) allow you to:
1117+
1118+
* Create shader objects directly from SPIR-V with `vkCreateShadersEXT`.
1119+
* Bind them per-stage at command recording time with `vkCmdBindShadersEXT`.
1120+
* Set most fixed-function state dynamically via existing dynamic state commands.
1121+
1122+
This “pipeline-free” approach reduces pipeline permutation explosion and can simplify hot-reloading and rapid iteration.
1123+
1124+
See also: link:ways_to_provide_spirv.adoc[Shader Objects section of ways to provide spirv].
1125+
1126+
==== Code Example
1127+
1128+
[source,cpp]
1129+
----
1130+
// Traditional: bind a pre-baked pipeline
1131+
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
1132+
1133+
// Shader Objects: create and bind shaders directly
1134+
VkShaderCreateInfoEXT vsCI{ };
1135+
vsCI.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT;
1136+
vsCI.stage = VK_SHADER_STAGE_VERTEX_BIT;
1137+
vsCI.codeType = VK_SHADER_CODE_TYPE_SPIRV_EXT;
1138+
vsCI.pCode = vertSpirv; // const void*
1139+
vsCI.codeSize = vertSpirvSize;
1140+
1141+
VkShaderCreateInfoEXT fsCI{ };
1142+
fsCI.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT;
1143+
fsCI.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
1144+
fsCI.codeType = VK_SHADER_CODE_TYPE_SPIRV_EXT;
1145+
fsCI.pCode = fragSpirv;
1146+
fsCI.codeSize = fragSpirvSize;
1147+
1148+
VkShaderEXT shaders[2]{};
1149+
vkCreateShadersEXT(device, 1, &vsCI, nullptr, &shaders[0]);
1150+
vkCreateShadersEXT(device, 1, &fsCI, nullptr, &shaders[1]);
1151+
1152+
// Bind shaders instead of a pipeline
1153+
vkCmdBindShadersEXT(cmd, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, shaders);
1154+
1155+
// Set dynamic state as needed (examples)
1156+
vkCmdSetViewport(cmd, 0, 1, &viewport);
1157+
vkCmdSetScissor(cmd, 0, 1, &scissor);
1158+
// ... other dynamic states as required
1159+
1160+
// Draw as usual
1161+
vkCmdDraw(cmd, vertexCount, 1, 0, 0);
1162+
----
1163+
1164+
==== Fallback Strategy
1165+
1166+
To support both approaches:
1167+
1168+
1. Detect `VK_EXT_shader_object` support and enable the feature at device creation time.
1169+
2. If unavailable, fall back to pre-baked pipelines.
1170+
1171+
[source,cpp]
1172+
----
1173+
bool hasShaderObject = false;
1174+
1175+
uint32_t extCount = 0;
1176+
vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extCount, nullptr);
1177+
std::vector<VkExtensionProperties> exts(extCount);
1178+
vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extCount, exts.data());
1179+
for (const auto& e : exts) {
1180+
if (strcmp(e.extensionName, VK_EXT_SHADER_OBJECT_EXTENSION_NAME) == 0) {
1181+
hasShaderObject = true;
1182+
break;
1183+
}
1184+
}
1185+
1186+
VkDeviceCreateInfo devCI{ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
1187+
1188+
VkPhysicalDeviceShaderObjectFeaturesEXT shaderObjectFeatures{ };
1189+
shaderObjectFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT;
1190+
shaderObjectFeatures.shaderObject = VK_TRUE;
1191+
1192+
if (hasShaderObject) {
1193+
devCI.pNext = &shaderObjectFeatures; // enable feature
1194+
// also add VK_EXT_shader_object to enabled extension list
1195+
}
1196+
1197+
vkCreateDevice(physicalDevice, &devCI, nullptr, &device);
1198+
1199+
// Later when recording command buffers
1200+
if (hasShaderObject) {
1201+
// Use Shader Objects path (vkCreateShadersEXT / vkCmdBindShadersEXT)
1202+
} else {
1203+
// Use traditional pre-baked pipelines
1204+
}
1205+
----
1206+
1207+
Note: Shader Objects can coexist with pipelines. Applications may choose per-pass which path is more appropriate.

0 commit comments

Comments
 (0)