Repository navigation
Add FP16 and normalized UNORM16 texture coordinates - #48
nv-mattstack wants to merge 9 commits into
Conversation
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.
|
recheck |
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
| ThreadPool* threadPool, | ||
| SceneImportResult& result) const; | ||
| SceneImportResult& result, | ||
| TexCoordFormat texCoordFormat = TexCoordFormat::Float32) const; |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Will move this to Importer
| nvrhi::DeviceHandle m_Device; | ||
| nvrhi::InputLayoutHandle m_InputLayout; | ||
| nvrhi::InputLayoutHandle m_InputLayoutFloat16; | ||
| nvrhi::InputLayoutHandle m_InputLayoutUnorm16; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
no way to avoid this virtual here ?
There was a problem hiding this comment.
moving to initialization instead of requiring override from subclass
| o_instance = i_instance; | ||
| } | ||
|
|
||
| void input_assembler( |
There was a problem hiding this comment.
we support templates in HLSL : this seems an ideal candidate here
There was a problem hiding this comment.
Does Donut require supporting DX11 with FXC? I dont believe HLSL Templates work in that scenario, its a syntax error
There was a problem hiding this comment.
Update: Manuel said DX11 is being depreciated, so I will go ahead and use templates
| passes/depth_vs | ||
| passes/depth_vs_input_assembler | ||
| passes/depth_vs_input_assembler_float | ||
| passes/depth_vs_buffer_loads |
There was a problem hiding this comment.
shader variants + templates instead of outright more passes ?
There was a problem hiding this comment.
Good idea, I can do shader variants here
| m_UseInputAssembler = params.useInputAssembler; | ||
|
|
||
| m_SpecializeInputAssemblerTexCoords = m_UseInputAssembler | ||
| && params.specializeInputAssemblerTexCoords.value_or(typeid(*this) == typeid(DepthPass)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
| 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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Before this change these were virtual functions so this make break code if other code relies on this behavior.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Same as above virtual function, could be overridden. Just make sure we are aware that this could have a wider blast radius.
| } | ||
|
|
||
| donut::log::warning("[Vulkan: location=0x%zx code=%d, layerPrefix='%s'] %s", location, code, layerPrefix, msg); | ||
| const auto severity = (flags & vk::DebugReportFlagBitsEXT::eError) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
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! |
| 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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
|
migrated this MR to Gitlab, closing |
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:
GeometryDatagrows 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 withDONUT_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.