Commit a3afdc6
Fix parseCommandLineArguments not populating TargetDesc format and profile fields (#8967)
`IGlobalSession::parseCommandLineArguments` was creating `TargetDesc`
objects with correct `compilerOptionEntries` but leaving `format` and
`profile` fields uninitialized (zero). Multiple targets appeared
identical despite having different formats (SPIRV vs DXIL) and profiles
(sm_5_0 vs sm_6_0).
## Changes
- **source/slang/slang-global-session.cpp**: Populate `format` and
`profile` from `TargetRequest` in the target iteration loop:
```cpp
tdesc.format = (SlangCompileTarget)target->getTarget();
tdesc.profile = (SlangProfileID)target->getOptionSet().getProfile().raw;
```
- **tools/slang-unit-test/unit-test-parse-command-line-args.cpp**: Add
test verifying multiple targets with different formats and profiles are
parsed correctly.
## Note
`parseCommandLineArguments` expects arguments **without** the program
name (unlike standard `main(argc, argv)`). Users should pass `argc-1,
argv+1` when adapting from main's arguments.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Multiple targets are not parsed correctly with
slang::IGlobalSession::parseCommandLineArguments</issue_title>
> <issue_description># Issue Description
> When parsing command line arguments via
`slang::IGlobalSession::parseCommandLineArguments`, the
`slang::SessionDesc` object contain the right amount of targets, but the
targets are all the same.
>
> # Reproducer Code
> [Here is a link to a repository that reproduces the
issue.](https://github.com/sporacid/shader-slang-issue)
>
> I've included my `CMakeUserPresets.json` file, you just have to clone
[vcpkg](https://github.com/microsoft/vcpkg) and change the `VCPKG_ROOT`
environment variable.
>
> You can invoke the program with stantard `slangc` command line. I've
used:
>
> ```
> -target spirv -o mesh.spv -profile sm_5_0 -target dxil -o mesh.dxil
-profile sm_6_0 -- mesh.slang
> ```
>
> # Expected Behavior
> I would have expected to have the first target as `SPIR-V` with
`sm_5_0` and the second target as `DXIL` with `sm_6_0`. I would also
have expected the fields of `slang::TargetDesc` to be filled instead of
looking into the compiler option entries. When I execute the program, I
get this output.
>
> ```
> target count: 2
> target: 0
> format: 0
> profile: 0
> target option: 10
> profile option: 196608
> target: 1
> format: 0
> profile: 0
> target option: 10
> profile option: 196608
> ```
>
> # Actual Behavior
> The `slang::TargetDesc::format` and `slang::TargetDesc::profile`
fields are not set to the right values. The format and profile compiler
option entries for both targets are set to `DXIL` and `sm_6_0`.
>
> # Environment
> - Slang Version: 2025.5
> - OS: Windows 11 Version 10.0.26100 Build 26100
> - GPU/Driver version: NVIDIA 576.52
> - Any related environment variables: None
>
> # Additional context
> I'm not compiling the code, simply parsing its syntax to generate C++
bindings for slang types.</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> <comment_new><author>@gtong-nv</author><body>
> Looking at the `Session::parseCommandLineArguments implementation in
source/slang/slang-global-session.cpp (lines 1107-1116)`:
> ```
> for (auto target : tempReq->getLinkage()->targets)
> {
> slang::TargetDesc tdesc;
> SerializedOptionsData& targetOptionData =
outData->options[optionDataIndex];
> optionDataIndex++;
> tempReq->getTargetOptionSet(target).serialize(&targetOptionData);
> tdesc.compilerOptionEntryCount =
(uint32_t)targetOptionData.entries.getCount();
> tdesc.compilerOptionEntries = targetOptionData.entries.getBuffer();
> outData->targets.add(tdesc);
> }
> ```
> The problem: When creating each `TargetDesc`, the code:
> Initializes `tdesc` with default values (format=0, profile=0)
> Only sets the `compilerOptionEntries` field
> Never populates the format and profile fields of the TargetDesc
struct</body></comment_new>
> </comments>
>
</details>
- Fixes #8963
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/shader-slang/slang/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: gtong-nv <[email protected]>
Co-authored-by: Gangzheng Tong <[email protected]>
Co-authored-by: slangbot <[email protected]>
Co-authored-by: slangbot <[email protected]>1 parent f8e97d9 commit a3afdc6
File tree
2 files changed
+151
-0
lines changed- source/slang
- tools/slang-unit-test
2 files changed
+151
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1112 | 1112 | | |
1113 | 1113 | | |
1114 | 1114 | | |
| 1115 | + | |
| 1116 | + | |
1115 | 1117 | | |
1116 | 1118 | | |
1117 | 1119 | | |
| |||
Lines changed: 149 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
0 commit comments