Skip to content

Commit 602ebc7

Browse files
committed
Add dispatch execution path to runtime smoke
1 parent 5f4759f commit 602ebc7

1 file changed

Lines changed: 211 additions & 1 deletion

File tree

tests/wasm/src/lavapipe_runtime_smoke.c

Lines changed: 211 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ static const uint32_t kSmokeComputeSpirv[] = {
7272
0x0000000bu, 0x0003003eu, 0x0000000eu, 0x0000000cu, 0x000100fdu, 0x00010038u
7373
};
7474

75+
static const uint32_t kDispatchNoopSpirv[] = {
76+
0x07230203u, 0x00010000u, 0x0008000bu, 0x0000000au, 0x00000000u, 0x00020011u, 0x00000001u, 0x0006000bu,
77+
0x00000001u, 0x4c534c47u, 0x6474732eu, 0x3035342eu, 0x00000000u, 0x0003000eu, 0x00000000u, 0x00000001u,
78+
0x0005000fu, 0x00000005u, 0x00000004u, 0x6e69616du, 0x00000000u, 0x00060010u, 0x00000004u, 0x00000011u,
79+
0x00000001u, 0x00000001u, 0x00000001u, 0x00030003u, 0x00000002u, 0x000001c2u, 0x00040005u, 0x00000004u,
80+
0x6e69616du, 0x00000000u, 0x00040047u, 0x00000009u, 0x0000000bu, 0x00000019u, 0x00020013u, 0x00000002u,
81+
0x00030021u, 0x00000003u, 0x00000002u, 0x00040015u, 0x00000006u, 0x00000020u, 0x00000000u, 0x00040017u,
82+
0x00000007u, 0x00000006u, 0x00000003u, 0x0004002bu, 0x00000006u, 0x00000008u, 0x00000001u, 0x0006002cu,
83+
0x00000007u, 0x00000009u, 0x00000008u, 0x00000008u, 0x00000008u, 0x00050036u, 0x00000002u, 0x00000004u,
84+
0x00000000u, 0x00000003u, 0x000200f8u, 0x00000005u, 0x000100fdu, 0x00010038u
85+
};
86+
7587
struct webvulkan_nir_wasm_pattern {
7688
uint32_t ssbo_index;
7789
uint32_t store_offset_bytes;
@@ -432,9 +444,16 @@ EMSCRIPTEN_KEEPALIVE int lavapipe_runtime_smoke(void) {
432444
VkInstance instance = VK_NULL_HANDLE;
433445
VkDevice device = VK_NULL_HANDLE;
434446
VkShaderModule shaderModule = VK_NULL_HANDLE;
447+
VkShaderModule dispatchShaderModule = VK_NULL_HANDLE;
435448
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
436449
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
437450
VkPipeline computePipeline = VK_NULL_HANDLE;
451+
VkPipelineLayout dispatchPipelineLayout = VK_NULL_HANDLE;
452+
VkPipeline dispatchPipeline = VK_NULL_HANDLE;
453+
VkCommandPool commandPool = VK_NULL_HANDLE;
454+
VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
455+
VkFence submitFence = VK_NULL_HANDLE;
456+
VkQueue queue = VK_NULL_HANDLE;
438457
struct webvulkan_nir_wasm_pattern nirWasmPattern;
439458
uint8_t* nirWasmModuleBytes = 0;
440459
size_t nirWasmModuleSize = 0u;
@@ -451,6 +470,18 @@ EMSCRIPTEN_KEEPALIVE int lavapipe_runtime_smoke(void) {
451470
PFN_vkDestroyPipelineLayout pfnDestroyPipelineLayout = 0;
452471
PFN_vkCreateComputePipelines pfnCreateComputePipelines = 0;
453472
PFN_vkDestroyPipeline pfnDestroyPipeline = 0;
473+
PFN_vkGetDeviceQueue pfnGetDeviceQueue = 0;
474+
PFN_vkCreateCommandPool pfnCreateCommandPool = 0;
475+
PFN_vkDestroyCommandPool pfnDestroyCommandPool = 0;
476+
PFN_vkAllocateCommandBuffers pfnAllocateCommandBuffers = 0;
477+
PFN_vkBeginCommandBuffer pfnBeginCommandBuffer = 0;
478+
PFN_vkEndCommandBuffer pfnEndCommandBuffer = 0;
479+
PFN_vkCmdBindPipeline pfnCmdBindPipeline = 0;
480+
PFN_vkCmdDispatch pfnCmdDispatch = 0;
481+
PFN_vkCreateFence pfnCreateFence = 0;
482+
PFN_vkDestroyFence pfnDestroyFence = 0;
483+
PFN_vkQueueSubmit pfnQueueSubmit = 0;
484+
PFN_vkWaitForFences pfnWaitForFences = 0;
454485

455486
memset(&nirWasmPattern, 0, sizeof(nirWasmPattern));
456487

@@ -584,6 +615,30 @@ EMSCRIPTEN_KEEPALIVE int lavapipe_runtime_smoke(void) {
584615
(PFN_vkCreateComputePipelines)vkGetDeviceProcAddr(device, "vkCreateComputePipelines");
585616
pfnDestroyPipeline = vkDestroyPipeline ? vkDestroyPipeline :
586617
(PFN_vkDestroyPipeline)vkGetDeviceProcAddr(device, "vkDestroyPipeline");
618+
pfnGetDeviceQueue = vkGetDeviceQueue ? vkGetDeviceQueue :
619+
(PFN_vkGetDeviceQueue)vkGetDeviceProcAddr(device, "vkGetDeviceQueue");
620+
pfnCreateCommandPool = vkCreateCommandPool ? vkCreateCommandPool :
621+
(PFN_vkCreateCommandPool)vkGetDeviceProcAddr(device, "vkCreateCommandPool");
622+
pfnDestroyCommandPool = vkDestroyCommandPool ? vkDestroyCommandPool :
623+
(PFN_vkDestroyCommandPool)vkGetDeviceProcAddr(device, "vkDestroyCommandPool");
624+
pfnAllocateCommandBuffers = vkAllocateCommandBuffers ? vkAllocateCommandBuffers :
625+
(PFN_vkAllocateCommandBuffers)vkGetDeviceProcAddr(device, "vkAllocateCommandBuffers");
626+
pfnBeginCommandBuffer = vkBeginCommandBuffer ? vkBeginCommandBuffer :
627+
(PFN_vkBeginCommandBuffer)vkGetDeviceProcAddr(device, "vkBeginCommandBuffer");
628+
pfnEndCommandBuffer = vkEndCommandBuffer ? vkEndCommandBuffer :
629+
(PFN_vkEndCommandBuffer)vkGetDeviceProcAddr(device, "vkEndCommandBuffer");
630+
pfnCmdBindPipeline = vkCmdBindPipeline ? vkCmdBindPipeline :
631+
(PFN_vkCmdBindPipeline)vkGetDeviceProcAddr(device, "vkCmdBindPipeline");
632+
pfnCmdDispatch = vkCmdDispatch ? vkCmdDispatch :
633+
(PFN_vkCmdDispatch)vkGetDeviceProcAddr(device, "vkCmdDispatch");
634+
pfnCreateFence = vkCreateFence ? vkCreateFence :
635+
(PFN_vkCreateFence)vkGetDeviceProcAddr(device, "vkCreateFence");
636+
pfnDestroyFence = vkDestroyFence ? vkDestroyFence :
637+
(PFN_vkDestroyFence)vkGetDeviceProcAddr(device, "vkDestroyFence");
638+
pfnQueueSubmit = vkQueueSubmit ? vkQueueSubmit :
639+
(PFN_vkQueueSubmit)vkGetDeviceProcAddr(device, "vkQueueSubmit");
640+
pfnWaitForFences = vkWaitForFences ? vkWaitForFences :
641+
(PFN_vkWaitForFences)vkGetDeviceProcAddr(device, "vkWaitForFences");
587642

588643
if (!pfnDestroyDevice || !pfnCreateShaderModule || !pfnDestroyShaderModule || !pfnCreatePipelineLayout ||
589644
!pfnDestroyPipelineLayout || !pfnCreateComputePipelines || !pfnDestroyPipeline ||
@@ -601,6 +656,25 @@ EMSCRIPTEN_KEEPALIVE int lavapipe_runtime_smoke(void) {
601656
smokeRc = 31;
602657
goto cleanup;
603658
}
659+
if (!pfnGetDeviceQueue || !pfnCreateCommandPool || !pfnDestroyCommandPool || !pfnAllocateCommandBuffers ||
660+
!pfnBeginCommandBuffer || !pfnEndCommandBuffer || !pfnCmdBindPipeline || !pfnCmdDispatch ||
661+
!pfnCreateFence || !pfnDestroyFence || !pfnQueueSubmit || !pfnWaitForFences) {
662+
printf("lavapipe runtime smoke missing dispatch entrypoints\n");
663+
printf(" vkGetDeviceQueue=%s\n", pfnGetDeviceQueue ? "present" : "missing");
664+
printf(" vkCreateCommandPool=%s\n", pfnCreateCommandPool ? "present" : "missing");
665+
printf(" vkDestroyCommandPool=%s\n", pfnDestroyCommandPool ? "present" : "missing");
666+
printf(" vkAllocateCommandBuffers=%s\n", pfnAllocateCommandBuffers ? "present" : "missing");
667+
printf(" vkBeginCommandBuffer=%s\n", pfnBeginCommandBuffer ? "present" : "missing");
668+
printf(" vkEndCommandBuffer=%s\n", pfnEndCommandBuffer ? "present" : "missing");
669+
printf(" vkCmdBindPipeline=%s\n", pfnCmdBindPipeline ? "present" : "missing");
670+
printf(" vkCmdDispatch=%s\n", pfnCmdDispatch ? "present" : "missing");
671+
printf(" vkCreateFence=%s\n", pfnCreateFence ? "present" : "missing");
672+
printf(" vkDestroyFence=%s\n", pfnDestroyFence ? "present" : "missing");
673+
printf(" vkQueueSubmit=%s\n", pfnQueueSubmit ? "present" : "missing");
674+
printf(" vkWaitForFences=%s\n", pfnWaitForFences ? "present" : "missing");
675+
smokeRc = 36;
676+
goto cleanup;
677+
}
604678

605679
VkShaderModuleCreateInfo shaderCreateInfo;
606680
memset(&shaderCreateInfo, 0, sizeof(shaderCreateInfo));
@@ -664,6 +738,127 @@ EMSCRIPTEN_KEEPALIVE int lavapipe_runtime_smoke(void) {
664738
goto cleanup;
665739
}
666740

741+
VkShaderModuleCreateInfo dispatchShaderCreateInfo;
742+
memset(&dispatchShaderCreateInfo, 0, sizeof(dispatchShaderCreateInfo));
743+
dispatchShaderCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
744+
dispatchShaderCreateInfo.codeSize = sizeof(kDispatchNoopSpirv);
745+
dispatchShaderCreateInfo.pCode = kDispatchNoopSpirv;
746+
747+
rc = pfnCreateShaderModule(device, &dispatchShaderCreateInfo, 0, &dispatchShaderModule);
748+
if (rc != VK_SUCCESS || dispatchShaderModule == VK_NULL_HANDLE) {
749+
smokeRc = 58;
750+
goto cleanup;
751+
}
752+
753+
VkPipelineLayoutCreateInfo dispatchPipelineLayoutCreateInfo;
754+
memset(&dispatchPipelineLayoutCreateInfo, 0, sizeof(dispatchPipelineLayoutCreateInfo));
755+
dispatchPipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
756+
dispatchPipelineLayoutCreateInfo.setLayoutCount = 0u;
757+
dispatchPipelineLayoutCreateInfo.pSetLayouts = 0;
758+
759+
rc = pfnCreatePipelineLayout(device, &dispatchPipelineLayoutCreateInfo, 0, &dispatchPipelineLayout);
760+
if (rc != VK_SUCCESS || dispatchPipelineLayout == VK_NULL_HANDLE) {
761+
smokeRc = 59;
762+
goto cleanup;
763+
}
764+
765+
VkPipelineShaderStageCreateInfo dispatchShaderStage;
766+
memset(&dispatchShaderStage, 0, sizeof(dispatchShaderStage));
767+
dispatchShaderStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
768+
dispatchShaderStage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
769+
dispatchShaderStage.module = dispatchShaderModule;
770+
dispatchShaderStage.pName = "main";
771+
772+
VkComputePipelineCreateInfo dispatchPipelineCreateInfo;
773+
memset(&dispatchPipelineCreateInfo, 0, sizeof(dispatchPipelineCreateInfo));
774+
dispatchPipelineCreateInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
775+
dispatchPipelineCreateInfo.stage = dispatchShaderStage;
776+
dispatchPipelineCreateInfo.layout = dispatchPipelineLayout;
777+
778+
rc = pfnCreateComputePipelines(device, VK_NULL_HANDLE, 1u, &dispatchPipelineCreateInfo, 0, &dispatchPipeline);
779+
if (rc != VK_SUCCESS || dispatchPipeline == VK_NULL_HANDLE) {
780+
smokeRc = 60;
781+
goto cleanup;
782+
}
783+
784+
pfnGetDeviceQueue(device, queueFamilyIndex, 0u, &queue);
785+
if (queue == VK_NULL_HANDLE) {
786+
smokeRc = 61;
787+
goto cleanup;
788+
}
789+
790+
VkCommandPoolCreateInfo commandPoolCreateInfo;
791+
memset(&commandPoolCreateInfo, 0, sizeof(commandPoolCreateInfo));
792+
commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
793+
commandPoolCreateInfo.queueFamilyIndex = queueFamilyIndex;
794+
commandPoolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
795+
796+
rc = pfnCreateCommandPool(device, &commandPoolCreateInfo, 0, &commandPool);
797+
if (rc != VK_SUCCESS || commandPool == VK_NULL_HANDLE) {
798+
smokeRc = 62;
799+
goto cleanup;
800+
}
801+
802+
VkCommandBufferAllocateInfo commandBufferAllocateInfo;
803+
memset(&commandBufferAllocateInfo, 0, sizeof(commandBufferAllocateInfo));
804+
commandBufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
805+
commandBufferAllocateInfo.commandPool = commandPool;
806+
commandBufferAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
807+
commandBufferAllocateInfo.commandBufferCount = 1u;
808+
809+
rc = pfnAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer);
810+
if (rc != VK_SUCCESS || commandBuffer == VK_NULL_HANDLE) {
811+
smokeRc = 63;
812+
goto cleanup;
813+
}
814+
815+
VkCommandBufferBeginInfo commandBufferBeginInfo;
816+
memset(&commandBufferBeginInfo, 0, sizeof(commandBufferBeginInfo));
817+
commandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
818+
commandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
819+
820+
rc = pfnBeginCommandBuffer(commandBuffer, &commandBufferBeginInfo);
821+
if (rc != VK_SUCCESS) {
822+
smokeRc = 64;
823+
goto cleanup;
824+
}
825+
826+
pfnCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, dispatchPipeline);
827+
pfnCmdDispatch(commandBuffer, 1u, 1u, 1u);
828+
829+
rc = pfnEndCommandBuffer(commandBuffer);
830+
if (rc != VK_SUCCESS) {
831+
smokeRc = 65;
832+
goto cleanup;
833+
}
834+
835+
VkFenceCreateInfo fenceCreateInfo;
836+
memset(&fenceCreateInfo, 0, sizeof(fenceCreateInfo));
837+
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
838+
rc = pfnCreateFence(device, &fenceCreateInfo, 0, &submitFence);
839+
if (rc != VK_SUCCESS || submitFence == VK_NULL_HANDLE) {
840+
smokeRc = 66;
841+
goto cleanup;
842+
}
843+
844+
VkSubmitInfo submitInfo;
845+
memset(&submitInfo, 0, sizeof(submitInfo));
846+
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
847+
submitInfo.commandBufferCount = 1u;
848+
submitInfo.pCommandBuffers = &commandBuffer;
849+
850+
rc = pfnQueueSubmit(queue, 1u, &submitInfo, submitFence);
851+
if (rc != VK_SUCCESS) {
852+
smokeRc = 67;
853+
goto cleanup;
854+
}
855+
856+
rc = pfnWaitForFences(device, 1u, &submitFence, VK_TRUE, UINT64_MAX);
857+
if (rc != VK_SUCCESS) {
858+
smokeRc = 68;
859+
goto cleanup;
860+
}
861+
667862
nirWasmCompileResult = webvulkan_compile_spirv_nir_to_wasm(
668863
kSmokeComputeSpirv,
669864
sizeof(kSmokeComputeSpirv) / sizeof(kSmokeComputeSpirv[0]),
@@ -709,7 +904,7 @@ EMSCRIPTEN_KEEPALIVE int lavapipe_runtime_smoke(void) {
709904
printf(" vulkan_loader=volk (custom vk_icdGetInstanceProcAddr)\n");
710905
printf(" shader.create_module=ok\n");
711906
printf(" shader.create_compute_pipeline=ok\n");
712-
printf(" shader.dispatch=not_executed (llvmpipe wasm runtime path pending)\n");
907+
printf(" shader.dispatch=ok\n");
713908
printf(" nir_to_wasm.spirv_to_nir=ok\n");
714909
printf(" nir_to_wasm.ssbo_index=%u\n", nirWasmPattern.ssbo_index);
715910
printf(" nir_to_wasm.store_offset=%u\n", nirWasmPattern.store_offset_bytes);
@@ -725,6 +920,21 @@ EMSCRIPTEN_KEEPALIVE int lavapipe_runtime_smoke(void) {
725920
nirWasmModuleBytes = 0;
726921
}
727922
if (device != VK_NULL_HANDLE) {
923+
if (submitFence != VK_NULL_HANDLE && pfnDestroyFence) {
924+
pfnDestroyFence(device, submitFence, 0);
925+
}
926+
if (commandPool != VK_NULL_HANDLE && pfnDestroyCommandPool) {
927+
pfnDestroyCommandPool(device, commandPool, 0);
928+
}
929+
if (dispatchPipeline != VK_NULL_HANDLE && pfnDestroyPipeline) {
930+
pfnDestroyPipeline(device, dispatchPipeline, 0);
931+
}
932+
if (dispatchPipelineLayout != VK_NULL_HANDLE && pfnDestroyPipelineLayout) {
933+
pfnDestroyPipelineLayout(device, dispatchPipelineLayout, 0);
934+
}
935+
if (dispatchShaderModule != VK_NULL_HANDLE && pfnDestroyShaderModule) {
936+
pfnDestroyShaderModule(device, dispatchShaderModule, 0);
937+
}
728938
if (computePipeline != VK_NULL_HANDLE && pfnDestroyPipeline) {
729939
pfnDestroyPipeline(device, computePipeline, 0);
730940
}

0 commit comments

Comments
 (0)