Skip to content

Re-works how LDS regions are defined and how their total size is computed#70

Merged
pm4rtx merged 1 commit intomicrosoft:developmentfrom
pm4rtx:lds-region-rework
Feb 18, 2026
Merged

Re-works how LDS regions are defined and how their total size is computed#70
pm4rtx merged 1 commit intomicrosoft:developmentfrom
pm4rtx:lds-region-rework

Conversation

@pm4rtx
Copy link
Collaborator

@pm4rtx pm4rtx commented Feb 17, 2026

This PR tries to improve how LDS regions are defined in the code shared between HLSL and C/C++. Previously the size of LDS region was computed twice: in .hlsl shader file when declaring single groupshared variable and in .h file within the body of the corresponding function. The latter was necessary to represent LDS by a local array in C/C++ side. Things would have been easier if HLSL had supported declaring groupshared variable within a function, but it doesn't support that. So the first approach existed for some time to somehow address what HLSL can't do, but this approach was prone to errors when sizes of groupshared memory became out of sync. To address this, this PR starts defining partition (groups) of LDS variables by respective macro lists (usually, right in front of functions that use them) that are expanded twice: outside of the function to compute the total size of required LDS region, and the second time within function body to compute offsets relative to the start of LDS (on HLSL side), and to define local variables replacing global LDS memory (on C/C++ side). This approach requires to define all macro/constants that affect LDS size before including zstdgpu_shaders.h where LDS partition macro are defined.

…uted to use for HLSL groupshared definition.
@pm4rtx pm4rtx self-assigned this Feb 17, 2026
@coopp
Copy link
Collaborator

coopp commented Feb 17, 2026

Nice!. This looks good to me.

@pm4rtx pm4rtx merged commit 3775165 into microsoft:development Feb 18, 2026
1 check passed
@pm4rtx pm4rtx deleted the lds-region-rework branch February 18, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants