Skip to content

Add FP16 and normalized UNORM16 texture coordinates - #48

Closed
nv-mattstack wants to merge 9 commits into
NVIDIA-RTX:mainfrom
nv-mattstack:feature/16bit-texcoords
Closed

nv-mattstack wants to merge 9 commits into
NVIDIA-RTX:mainfrom
nv-mattstack:feature/16bit-texcoords

Conversation

@nv-mattstack

@nv-mattstack nv-mattstack commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Adds optional FP16 and automatically normalized UNORM16 UV storage, reducing each vertex UV pair from 8 to 4 bytes while keeping FP32 as the default. Includes importer configuration, generated UNORM scale/offset metadata, FP32 fallback, skinning, format-aware buffer loaders, and stock raster support. Uses shared HLSL template variants, cached input layouts, shared bindings, UNORM constant reuse, and checked decode-range hints.

Integration: GeometryData grows from 64 to 96 bytes and decode push constants change. Rebuild application shaders with Donut; custom UV readers must support the selected format before enabling 16-bit storage. Shared shader headers require DXC with HLSL 2021; configure with DONUT_WITH_DX11=OFF.

Validation: DX12/Vulkan Release builds, 110 raster cases, and upload/decode/skinning checks passed. All 24 template shader-instruction comparisons match the preceding implementation. Vulkan validation reports zero errors and three existing unused-attribute warnings. Two pre-existing CTest failures remain in string parsing and console formatting.

Keep FP32 as the default and generate UV bounds and decode metadata for UNORM16. Update upload, skinning, raster passes, and shared shader loaders for all three formats.

Add GPU coverage for mixed formats and shared buffers, and document shader interface changes.
@nv-mattstack

Copy link
Copy Markdown
Contributor Author

recheck

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@nv-mattstack

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Comment thread include/donut/engine/GltfImporter.h Outdated
ThreadPool* threadPool,
SceneImportResult& result) const;
SceneImportResult& result,
TexCoordFormat texCoordFormat = TexCoordFormat::Float32) const;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit : don't mix in & out args, keep them grouped

also : isn't the format dictated by the buffer format in GLTF ? if this is an override, then maybe it should be a property of the SceneTypeFactor or the Importer ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will move this to Importer

Comment thread include/donut/render/DepthPass.h Outdated
nvrhi::DeviceHandle m_Device;
nvrhi::InputLayoutHandle m_InputLayout;
nvrhi::InputLayoutHandle m_InputLayoutFloat16;
nvrhi::InputLayoutHandle m_InputLayoutUnorm16;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::variant ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex found a small optimization by using std::array to avoid duplicating layouts for mixed formats

// Derived passes retain their existing shader/binding behavior by default.
// Opt in only when using the stock vertex/input bindings and when no other
// shader stage or custom draw code depends on the input push constants.
virtual bool SupportsInputAssemblerTexCoordSpecialization() const;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no way to avoid this virtual here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving to initialization instead of requiring override from subclass

Comment thread shaders/passes/gbuffer_vs.hlsl Outdated
o_instance = i_instance;
}

void input_assembler(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we support templates in HLSL : this seems an ideal candidate here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Donut require supporting DX11 with FXC? I dont believe HLSL Templates work in that scenario, its a syntax error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: Manuel said DX11 is being depreciated, so I will go ahead and use templates

Comment thread shaders/CMakeLists.txt
passes/depth_vs
passes/depth_vs_input_assembler
passes/depth_vs_input_assembler_float
passes/depth_vs_buffer_loads

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shader variants + templates instead of outright more passes ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I can do shader variants here

Comment thread src/render/DepthPass.cpp Outdated
m_UseInputAssembler = params.useInputAssembler;

m_SpecializeInputAssemblerTexCoords = m_UseInputAssembler
&& params.specializeInputAssemblerTexCoords.value_or(typeid(*this) == typeid(DepthPass));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of today there are zero uses of typeid I would like to keep it that way. typeid is generally a bad idea. I would prefer the pass has flags that indicates what it is, than relying it being a specific class.

@manuelkNVDA manuelkNVDA Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only case where *this != DepthPass is if a child overrides Init(), in which case the burden to resolve this config boolean is theirs

the larger question is whether m_SpecializeInputAssemblerTexCoords is a property of DepthPass or if it should owned by IGeometryPass ; also : all this stuff is known at compile time, so i really would want to see a compile time (template specialization) design pattern rather than virtual overrides (see my other comment)

Comment thread src/engine/Scene.cpp Outdated
if (scale == 0.f)
return 0;
const double normalized = (double(value) - double(offset)) / double(scale);
return uint16_t(std::floor(std::clamp(normalized, 0.0, 1.0) * 65535.0 + 0.5));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the floor for brevity. I would consider if doing the entire expression in double is strictly required. Curious why you thought to promote to double.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Floor is removed now. Astra called out that there was a small rounding issue when an encoding would round up incorrectly so I had it upgrade it to double to avoid that. Small accuracy detail


nvrhi::BindingLayoutHandle ForwardShadingPass::CreateInputBindingLayout()
{
if (m_UseInputAssembler)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change these were virtual functions so this make break code if other code relies on this behavior.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this should all be a compile-time resolution ; the parent IGeometryClass can own a template initialization function that expects the children to define some constants to specialize the input assembler generattion

  • this design pattern centralizes all the logic in one place
  • any child class that does not define the proper specialization constants will immediately generate compile errors
  • no run-time machinery overhead needed


nvrhi::BindingLayoutHandle GBufferFillPass::CreateInputBindingLayout()
{
if (m_UseInputAssembler)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above virtual function, could be overridden. Just make sure we are aware that this could have a wider blast radius.

Comment thread src/app/vulkan/DeviceManager_VK.cpp Outdated
}

donut::log::warning("[Vulkan: location=0x%zx code=%d, layerPrefix='%s'] %s", location, code, layerPrefix, msg);
const auto severity = (flags & vk::DebugReportFlagBitsEXT::eError)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is likely controversial. I understand your point of view, I really agree too. @manuelkNVDA ? I def don't want it bottled up in this PR. I would want it in a separate PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why it's controversial : it's just "flavoring" the log output based on Vk's own severity, so it can be filtered ? seems like a nice addition to me

the DX12 device manager just plugs the default log callback with no formatting or anything IIRC

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill move this a smaller, separate branch and MR

Share geometry input handling through Stock and Custom policies, enforce input-hook contracts, and add focused compile and raster coverage.

Default DX11 off with an explicit renderer configuration error, simplify UNORM16 packing, and remove the Vulkan logging severity change from this feature branch.
@nv-mattstack

Copy link
Copy Markdown
Contributor Author

Hey @manuelkNVDA, thank you for your note last week. I agree that the whole custom shader framework was overbuilt and unnecessary. This new version returns to the ordinary pass classes and small shared helpers. Shader specialization still happens at compile time with templates and shader variation. Please let me know if you have more notes, thanks!

Comment thread CMakeLists.txt
option(DONUT_WITH_NVRHI "Enable NVRHI and related projects" ON)

cmake_dependent_option(DONUT_WITH_DX11 "Enable the DX11 version of Donut" ON "WIN32" OFF)
cmake_dependent_option(DONUT_WITH_DX11 "Enable the DX11 version of Donut" OFF "WIN32" OFF)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to decide if we want to soft break or hard break DX11 this is a hard break.

float4 worldPos = float4(o_vtx.pos, 1.0);
o_position = mul(worldPos, g_ForwardView.view.matWorldToClip);

o_vtx.texCoord = DecodeTexCoord<DECODE_TEXCOORD != 0>(o_vtx.texCoord, g_Push.texCoordFormat, g_Push.texCoordScaleBias);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it is already tied to DECODE_TEXCOORD is there any reason to not just use that? This is fine if we kill DX11. But if we keep it, we need something that works on DX1.


protected:
nvrhi::DeviceHandle m_Device;
nvrhi::InputLayoutHandle m_InputLayout;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could break downstream code if it relies on this member. I think this is the right change long term just making sure we don't break downstream code.

@nv-mattstack

Copy link
Copy Markdown
Contributor Author

migrated this MR to Gitlab, closing

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants