-
Notifications
You must be signed in to change notification settings - Fork 28
[Offload] Add support for Mipmapped Textures #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86a7a45
[Offload] Add support for Mipmapped Textures
s-perron 9f57ce8
Change the calculate lod test to a pixel shader.
s-perron c83831b
Merge branch 'main' into miplevels
s-perron 43064d5
Add validation for the buffer sizes.
s-perron 26e53c4
Add const to read-only variable.
s-perron a564f3c
Fix xfail for the latest clang commits.
s-perron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Mipmapped Textures | ||
|
|
||
| The test suite supports textures with multiple mipmap levels. This allows | ||
| verifying that the compiler correctly generates code for | ||
| `CalculateLevelOfDetail`, `SampleGrad` (explicit gradients), and direct access | ||
| via `mips[level][coords]`. | ||
|
|
||
| ## Defining Mip Levels | ||
|
|
||
| To define a texture with multiple mips, specify the `MipLevels` field in | ||
| `OutputProps`. | ||
|
|
||
| **Example:** | ||
| ```yaml | ||
| Buffers: | ||
| - Name: Tex | ||
| Format: Float32 | ||
| Channels: 4 | ||
| OutputProps: | ||
| Width: 4 | ||
| Height: 4 | ||
| Depth: 1 | ||
| MipLevels: 3 # Defines Mip 0 (4x4), Mip 1 (2x2), and Mip 2 (1x1) | ||
| ``` | ||
|
|
||
| ## Dimension Calculation | ||
|
|
||
| The dimensions of each mip level are calculated automatically based on the base | ||
| `Width`, `Height`, and `Depth` provided in `OutputProps`. Following standard | ||
| graphics API conventions (Vulkan, DirectX, Metal), each subsequent mip level is | ||
| half the size of the previous level, rounded down, with a minimum of 1. | ||
|
|
||
| For Mip Level $N$: | ||
| * $\text{Width}_N = \max(1, \lfloor \text{Width}_0 / 2^N \rfloor)$ | ||
| * $\text{Height}_N = \max(1, \lfloor \text{Height}_0 / 2^N \rfloor)$ | ||
| * $\text{Depth}_N = \max(1, \lfloor \text{Depth}_0 / 2^N \rfloor)$ | ||
|
|
||
| ## Data Layout | ||
|
|
||
| The `Data` array in the YAML must contain the texel data for **all mip levels | ||
| sequentially**, packed tightly without padding. | ||
|
|
||
| For a 4x4 texture with 3 mip levels, the `Data` array structure is: | ||
|
|
||
| 1. **Mip 0 (4x4 = 16 texels):** Indices 0 - 15. | ||
| 2. **Mip 1 (2x2 = 4 texels):** Indices 16 - 19. | ||
| 3. **Mip 2 (1x1 = 1 texel):** Index 20. | ||
|
|
||
| **Total Size:** 21 texels. | ||
|
|
||
| ### Example YAML | ||
|
|
||
| ```yaml | ||
| - Name: Tex | ||
| Format: Float32 | ||
| Channels: 4 # RGBA | ||
| OutputProps: { Width: 4, Height: 4, Depth: 1, MipLevels: 3 } | ||
| Data: [ | ||
| # --- Mip 0 (4x4) --- | ||
| 1,0,0,1, 1,0,0,1, 1,0,0,1, 1,0,0,1, # Row 0 (Red) | ||
| 1,0,0,1, 1,0,0,1, 1,0,0,1, 1,0,0,1, # Row 1 | ||
| 1,0,0,1, 1,0,0,1, 1,0,0,1, 1,0,0,1, # Row 2 | ||
| 1,0,0,1, 1,0,0,1, 1,0,0,1, 1,0,0,1, # Row 3 | ||
|
|
||
| # --- Mip 1 (2x2) --- | ||
| 0,1,0,1, 0,1,0,1, # Row 0 (Green) | ||
| 0,1,0,1, 0,1,0,1, # Row 1 | ||
|
|
||
| # --- Mip 2 (1x1) --- | ||
| 0,0,1,1 # Single Pixel (Blue) | ||
| ] | ||
| ``` | ||
|
|
||
| ## Usage in Tests | ||
|
|
||
| This structure allows you to verify explicit mip selection in shaders: | ||
|
|
||
| ```hlsl | ||
| // Should return Green (Mip 1) | ||
| float4 val = Tex.mips[1][int2(0,0)]; | ||
|
|
||
| // Should return Blue (Mip 2) | ||
| float4 val2 = Tex.Load(int3(0,0,2)); | ||
| ``` | ||
|
|
||
| ## Implementation Notes | ||
|
|
||
| ### Mipmap Filtering | ||
|
|
||
| Currently, the test suite hardcodes the mipmap sampling mode to **Nearest** | ||
| (`VK_SAMPLER_MIPMAP_MODE_NEAREST` in Vulkan). This ensures deterministic results | ||
| for tests that verify specific mip level selection without requiring linear | ||
| interpolation between levels. Linear mip filtering is not configurable via YAML. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.