www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [GSoC 2026] DCompute Vulkan Backend

reply Quang Ha <ha.phamquang.dev gmail.com> writes:
Hi everyone,

I am making this thread to share my weekly updates for the 
**DCompute Vulkan Backend** project.

Here are the 3 main parts of my project (Mentored by Nicholas 
Wilson):

* **LDC Compiler:** Connect D's data types with Vulkan's memory 
rules by adding a wrapper kernel. I will also fix pointer sizes 
to make correct SPIR-V files.
* **Testing:** Check the compiled `.spv` files with Vulkan tools 
to make sure the memory works right.
* **DCompute Runtime:** Build the host-side system to start the 
Vulkan device and run the code.

I will post my progress, problems, and questions as replies to 
this thread every week. This helps keep everything in one place.

I am excited to share my work with you all!

GitHub: 
[https://github.com/gnavdev28](https://github.com/gnavdev28)
May 09
parent reply Quang Ha <ha.phamquang.dev gmail.com> writes:
Hi everyone, here is my progress update for **Week 1** of the 
DCompute Vulkan Backend project.


   * Squashed [Nicholas's 
PR](https://github.com/ldc-developers/ldc/pull/4958) to 
thoroughly analyze the required implementation details in 
`targetVulkan.cpp` and `dcomputecodegenerator.cpp`.

   * Investigated the `TODO` in `dcomputecodegenerator.cpp` and 
implemented support for parsing the `vulkan-{version}` target 
value by adapting the existing OpenCL (OCL) and CUDA logic.

   * Updated `cl_options.cpp` to include Vulkan in the 
`--mdcompute-targets` flag's description.

   * Addressed the hardcoded 64-bit pointer assignment in 
`targetVulkan.cpp` to fix the layout issue for different pointer 
sizes.

   * Refactored relevant files by updating the LLVM version macro 
checks from `LLVM_LDC_VER >= 2100` to `LLVM_VERSION_MAJOR >= 23`.


   * **The .spv file output problem:** I used the 
`--mdcompute-targets` flag to make a `.spv` file, but it was in 
COFF format, not real SPIR-V. It was very strange. When I added a 
logging line just to print things out, it made correct SPIR-V 
code. After that, I built the newest LLVM 23 (on May 24), and it 
went back to COFF format. Nicholas and I didn't understand why. 
Finally, I fixed it. I copied the "HACK" part from 
`DComputeTarget::emit` to `DComputeTarget::writeModule`. Now it 
works normally.

   * **Build error:** I got a linker error when building. But it 
was easy to fix. I just changed the paths in the `CMakeLists.txt` 
file.

   * **The TODO part:** There is a `TODO` for `spirv.Layout` in 
`targetVulkan.cpp`. It is very difficult to understand. So, I 
haven't touched it yet. I need more time to study it.


   * **Look into spirv.Layout:** I will spend time studying the 
`TODO` about `spirv.Layout` in `targetVulkan.cpp` because I 
didn't finish it this week.

   * **Write more tests:** I will write some more test files to 
make sure the compiler always makes the correct `.spv` files.

   * **Update my PR:** I will wait for Nicholas to finish 
reviewing my PR. Then, I will update the code and fix any issues 
he points out.


* Commits/PRs: https://github.com/ldc-developers/ldc/pull/5132
* My Personal Blog: Will update soon!

Feel free to leave any feedback or suggestions!
May 24
parent reply Quang Ha <ha.phamquang.dev gmail.com> writes:


Hi everyone, here is my progress update for **Week 2** of the 
DCompute Vulkan Backend project.


    * **Updated `target.cpp`:** I added `gABI = abi; gIR = _ir; 
gTargetMachine = targetMachine;` to `writeModule` to help the 
compiler write the correct file format.

    * **Added missing tags:** I added ` CompileFor.deviceOnly` to 
`test_vulkan.d` so it can emit the module. I also added the 
` kernel()` tag to the test functions so the compiler knows the 
entry point.

    * **Fixed 3 big crashes in `targetVulkan.cpp`:** This was my 
most important work this week. I updated the LLVM intrinsic calls:
       * Deleted `i1false` from the `handlefrombinding` call to 
fix the bad signature.
       * Added `i32zero->getType()` and changed `i32one` to 
`i32zero` to fix the `getpointer` invalid index.
       * Wrote a `CreateStructGEP` loop to get each `fieldTy` and 
load them one by one. This replaced the old `CreateAlignedLoad` 
for the big struct and fixed the element type error.
    * **Checked `isWritable`:** I used `spirv-dis` to check the 
`TargetExtType`. I saw `OpMemberDecorate %_struct_20 0 
NonWritable`. I am researching if the number should be `0` or `1`.


    * **The COFF file problem:** At first, my compiler made a COFF 
file, not a `.spv` file. Sometimes it was right, sometimes wrong. 
It was very strange until I updated `writeModule`.
    * **Missing Kernel and "not set" spam:** The `.spv` file did 
not have `OpEntryPoint` and `_kernel`. Also, when I put a log 
inside `addKernelMetadata`, my screen was full of `"-> 
dcomputetarget: not set"`. I found out I just missed the 
` CompileFor.deviceOnly` and ` kernel()` tags.
    * **The Compiler Crashes:** Right after the file emitted, the 
compiler crashed 3 times in a row! First, it had a bad signature. 
Second, it had an invalid index. Third, LLVM did not let me load 
a big struct at the same time. I had to debug and fix all of them 
in `targetVulkan.cpp`.


    * **Update my PR:** I will wait for Nicholas to check my pull 
request and I will update my code.
    * **Find `isWritable` answer:** I will find the final answer 
for the `isWritable` number (0 or 1).
    * **Write more tests:** I will write more test files to make 
sure everything works perfectly.


* Commits/PRs: https://github.com/ldc-developers/ldc/pull/5132
* My Personal Blog: Updating soon!
Jun 01
parent reply Quang Ha <ha.phamquang.dev gmail.com> writes:


Hi everyone, this is my update for Week 3. This week, I did not 
write a lot of new code for the compiler. Instead, I focused on 
testing to make sure everything works correctly in real life!


    * **Added a new test file:** I wrote another test file for the 
compiler to generate the `.spv` file.
    * **Cloned a test project:** I cloned a repository called 
`vulkan_minimal_compute` from GitHub.
    * **Tested the Vulkan API:** I changed some code in the 
`vulkan_minimal_compute` project. I want to use it to run my 
generated `.spv` file. This helps me check if the Vulkan API can 
read and use my file correctly.


    * **Understanding the real environment:** It takes time to 
read and understand the `vulkan_minimal_compute` repo. Setting up 
a real Vulkan environment to test the `.spv` file is a bit slow 
and requires a lot of checking.


    * **Finish the API test:** I will finish modifying the 
`vulkan_minimal_compute` project and fully test my `.spv` file.
    * **Fix bugs (if any):** If the Vulkan API finds any problems 
with my `.spv` file, I will go back to the compiler and fix them.
    * **Wait for PR review:** I am still waiting for Nicholas to 
review my pull request so I can update my code.


* Commits/PRs: https://github.com/ldc-developers/ldc/pull/5132
* My Personal Blog: https://gnavdev28.github.io (nothing special 
yet :D)
Jun 09
parent reply Quang Ha <ha.phamquang.dev gmail.com> writes:


Hi everyone, this is my new update. I took a short break from the 
project because I had to study for my university final exams. 
Now, I am back to work!


* **Fixed the Linker Error:** First, I updated my LDC and LLVM to 
the newest versions. But then, I got a very bad linker error and 
could not build the compiler. Finally, I found a trick! I added a 
new entry in CMake: `CMAKE_MSVC_RUNTIME_LIBRARY` with the value 
`MultiThreaded`. This fixed the build.
* **Continued ABI Testing (from Week 3):** I went back to my 
unfinished work from Week 3. I used the `vulkan_minimal_compute` 
project to do ABI testing and check if my `.spv` file works with 
the Vulkan API.
* **Found an LLVM Bug!:** This is the most interesting part of 
the week. While I was doing the ABI testing, I found a bug. But 
it was not my bug, it was a bug inside LLVM! So now, I am also 
trying to fix this LLVM bug.


* **Getting back on track:** Taking a break for exams made me 
forget some small details. It took me a little time to remember 
how the ABI testing works from Week 3.
* **Fixing LLVM:** Finding a bug in my own code is normal, but 
finding a bug inside LLVM is a big surprise. The LLVM codebase is 
very huge, so fixing it is a big challenge for me.


* I will focus on fixing the LLVM bug I found.
* I will finish the ABI testing with the `vulkan_minimal_compute` 
project.
* I will clean up my code and wait for my mentor to review my 
pull request.


* Commits/PRs: https://github.com/ldc-developers/ldc/pull/5132
* My Personal Blog: https://gnavdev28.github.io
Jul 08
parent reply FinalEvilution <FinalEvilution gmail.com> writes:
On Thursday, 9 July 2026 at 00:39:55 UTC, Quang Ha wrote:

 * **Found an LLVM Bug!:** This is the most interesting part of 
 the week. While I was doing the ABI testing, I found a bug. But 
 it was not my bug, it was a bug inside LLVM! So now, I am also 
 trying to fix this LLVM bug.
Interesting. What's the bug? If you don't mind me asking.
Jul 08
parent reply Quang Ha <ha.phamquang.dev gmail.com> writes:
 Interesting. What's the bug? If you don't mind me asking.
First of all, I want to sincerely apologize to FinalEvilution and everyone for the long silence. I have been deep in the debugging trenches for a while, but I am finally back with the ultimate update! To answer FinalEvilution's question: *"Interesting. What's the bug? If you don't mind me asking."* — The short answer is that the LLVM SPIR-V Backend was creating an invalid instruction when compiling shaders for Vulkan. You can find the full technical details of how I fixed this in the LLVM section below! Now, onto the best news: the project is successfully done! I am just waiting for the final reviews and merges to officially wrap up GSoC. After this, my next big stop is DConf 2026! * **Fixed Bugs in LLVM SPIR-V Backend:** * When compiling shaders for Vulkan, LLVM created an invalid instruction (`OpBitcast` on pointers). I fixed it by using `OpAccessChain` instead. * Added support for `PhysicalStorageBuffer` in Vulkan so pointer addresses work correctly. * Made the code clean and generic so any language can use it, not just D. * Added a new test file in LLVM (`physical-storage-buffer-load-store.ll`) and opened a pull request to LLVM. * **Fixed LDC ABI Issues:** * Fixed how D passes pointers to Vulkan compute shaders so the GPU can read the buffer directly. * Updated the target detector in LDC to recognize `spirv`, `spirv32`, and `spirv64`. * **Tested on Real GPU:** * Tested with our C++ Vulkan test program. * Both the minimal test (`67.36f`) and Vector Addition (A + B = C) ran successfully and gave the correct output! * **Understanding LLVM Codebase:** LLVM is very large, so finding where the bug happened took a lot of time and debugging. * **Clean Code:** My mentor, Nicholas Wilson, helped me review the code to make sure it follows all LLVM coding rules. * Follow the LLVM pull request and reply to reviewers. * Fix the CI issue in the LDC repository. * Get ready for my upcoming online talk: "Vulkan Compute Support in DCompute and LDC" at DConf 2026 this September! * Write more compute test cases in D for Vulkan. * **LDC PR:** https://github.com/ldc-developers/ldc/pull/5132 * **LLVM PR:** https://github.com/llvm/llvm-project/pull/216919 * **My Personal Blog:** https://gnavdev28.github.io
Aug 21
next sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
Very nice, I'm sure having to fix a bug in LLVM wasn't in your plan for 
SAoC!
Aug 21
next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 22/08/2026 9:25 AM, Richard (Rikki) Andrew Cattermole wrote:
 Very nice, I'm sure having to fix a bug in LLVM wasn't in your plan for 
 SAoC!
Err GSoC not SAoC oops.
Aug 21
prev sibling parent Quang Ha <ha.phamquang.dev gmail.com> writes:
On Friday, 21 August 2026 at 21:25:46 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 Very nice, I'm sure having to fix a bug in LLVM wasn't in your 
 plan for SAoC!
yes, it is ^^, I just spent a few days writing a resume and proposal to apply for SAoC too!
Aug 27
prev sibling parent reply FinalEvilution <FinalEvilution gmail.com> writes:
On Friday, 21 August 2026 at 16:37:45 UTC, Quang Ha wrote:


 First of all, I want to sincerely apologize to FinalEvilution 
 and everyone for the long silence. I have been deep in the 
 debugging trenches for a while, but I am finally back with the 
 ultimate update!
Don't worry about it. I figured you were busy and i didn't take any offense, and I'm sure everyone else feels the same.
 To answer FinalEvilution's question: *"Interesting. What's the 
 bug? If you don't mind me asking."* — The short answer is that 
 the LLVM SPIR-V Backend was creating an invalid instruction 
 when compiling shaders for Vulkan. You can find the full 
 technical details of how I fixed this in the LLVM section below!
Even the experts over at LLVM get it wrong sometimes. I have my own (unrelated) LLVM bug i need to create an issue for. I tried building your LLVM pr but it failed with. ``` llvm-project/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp:945:40: error: ‘SrcTy’ was not declared in this scope; did you mean ‘STy’? 945 | if (auto *STy = dyn_cast<StructType>(SrcTy)) { | ^~~~~ | STy ``` Is there perhaps a commit that hasn't been pushed to the repo yet? Ps. You left a little vietnamese in llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp:233 I also took a look at the ldc pr and i was able to build it and one of the test kernels as well. I don't have a vulkan test environment setup yet, but i have a cuda project i would like to port to D and i think that it could be a good exercise. The only issue i was able to find were that a build without vulkan support (LLVM 22) prints ``` Error: LDC was not built with Vulkan DCompute support. Error: Unrecognised or invalid DCompute targets: the format is ocl-xy0 for OpenCl x.y and cuda-xy0 for CUDA CC x.y, and vulkan-xy0 for Vulkan. Valid version strings for OpenCl are ocl-{100, 110, 120, 200, 210, 220}. Valid version strings for Vulkan are vulkan-{VULKAN_VALID_VER_INIT}. ```
 Now, onto the best news: the project is successfully done! I am 
 just waiting for the final reviews and merges to officially 
 wrap up GSoC. After this, my next big stop is DConf 2026!
Congratulations on your success! Figuring out both LLVM and SPIR-V is no small feat!

 * Follow the LLVM pull request and reply to reviewers.
 * Fix the CI issue in the LDC repository.
 * Get ready for my upcoming online talk: "Vulkan Compute 
 Support in DCompute and LDC" at DConf 2026 this September!
 * Write more compute test cases in D for Vulkan.
Looking forward to the talk!
Aug 23
parent reply Quang Ha <ha.phamquang.dev gmail.com> writes:
 Looking forward to the talk!
Thank you so much for your interest! I just spent a few days writing my resume and proposal to apply for SAoC, and I hope the organization will continue to trust me. I wonder if you've still encountered the issues you mentioned over the past few days? Please let me know!
Aug 27
parent FinalEvilution <FinalEvilution gmail.com> writes:
On Friday, 28 August 2026 at 02:45:24 UTC, Quang Ha wrote:
 Looking forward to the talk!
Thank you so much for your interest! I just spent a few days writing my resume and proposal to apply for SAoC, and I hope the organization will continue to trust me. I wonder if you've still encountered the issues you mentioned over the past few days? Please let me know!
Good luck with your application! There have been no new commits or force pushes to ether pr since i did my tests, and therefore the issues are still there. If you want or need any help testing things get in touch. I'm not much of a programmer but i can compile things :)
Aug 27