Skip to content

Fix sRGB filtering in GenerateMips - #449

Merged
Chuck Walbourn (walbourn) merged 1 commit into
microsoft:mainfrom
nv3ifu:fix-srgb-mip-generation
Nov 7, 2026
Merged

Chuck Walbourn (walbourn) merged 1 commit into
microsoft:mainfrom
nv3ifu:fix-srgb-mip-generation

Conversation

@nv3ifu

Copy link
Copy Markdown
Contributor

Hi, I try to fix #142.

My approach uses a typeless intermediate texture with an sRGB SRV and a UNORM UAV. The sRGB SRV decodes each texel before filtering, so filtering takes place in linear space. The compute shader then encodes the filtered RGB values back to sRGB before writing through the UNORM UAV. Alpha retains the existing linear behavior.

Local tests passed on RTX 5080 and WARP, covering different colors, texture sizes, and multiple mip levels. The repository’s clang-format check also passed.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@walbourn

Copy link
Copy Markdown
Collaborator

Thanks for your contribution. I need to get some additional hardware to validate this on different platforms, but I'll pick it up when I can.

@nv3ifu

Copy link
Copy Markdown
Contributor Author

Got it. Thanks for the review!

@walbourn

Copy link
Copy Markdown
Collaborator

I see that this converts the input sRGB to linear for the filtering, but where does it convert the result back to sRGB?

@nv3ifu

Copy link
Copy Markdown
Contributor Author

In the sRGB entry point in Src/Shaders/GenerateMips.hlsl
image

@walbourn

Copy link
Copy Markdown
Collaborator

OK, sorry. I see that you are converting the linear result to sRGB there. I'm trying to see where you convert the sRGB input to linear for the filtering...

@walbourn

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
No pipelines were found matching this branch/path.

@nv3ifu

Copy link
Copy Markdown
Contributor Author

The SRV is configured as DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, so SrcMip.SampleLevel(Sampler, uv, SrcMipIndex) automatically decodes RGB to linear in hardware?

@walbourn

Copy link
Copy Markdown
Collaborator

Awesome. Thanks! I'll try it out...

@walbourn

Copy link
Copy Markdown
Collaborator

@walbourn

Copy link
Copy Markdown
Collaborator

Note the MinGW failures are a known issue. I'll be fixing the headers problem via vcpkg next week.

@walbourn
Chuck Walbourn (walbourn) merged commit f3555e3 into microsoft:main Nov 7, 2026
213 of 245 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenerateMips on sRGB Textures averaging in gamma space?

2 participants