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
Separate linear sampler binding type? #1034
Comments
This is unfortunate. Do we have any data on whether 1) is consistent, or even allowed in the various APIs? |
Also there's 4) in the shader round the texel coordinate before doing the texture() call so that not interpolation happens for integer textures. |
Discussed at 2020-09-01 meeting. |
This only works in cases where it's undefined between (filters, doesn't filter), but not where the result or behavior is actually undefined. |
From the WGSL call we determined that it isn't strictly necessary to have separate filtering and non-filtering sampler types in WGSL. We can determine whether a sampler is statically used with any int texture and use that to validate against the BGL during pipeline creation. |
Want to clarify an argument @kainino0x had for not having a separate type in WGSL: generating it from SPIR-V would be difficult. I agree with this argument. The situation with the comparison samplers was difficult, because for each individual sample operation it was clear what kind of image/sampler is required. For linear samplers though, if we see that SPIR-V samples from a floating-point image, we don't know if it's meant to be used with a "linear" sampler or a regular one. So that introduce unnecessary friction. |
@kvark asked how to look up the behaviour for the various native APIs. For Vulkan, the ability to use linear filtering depends on the kind of command (draw, copy), but mainly delegated to a property of the image format. See the tables in "Required format support" https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#features-required-format-support You want to see whether a particular image format (listed by enum) supports the VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT functionality. The pattern I saw was:
It seemed pretty nuanced. |
I'm full aware of the |
Since it's clearly out of spec, then I would assume UB. It seems to me that validation layers would be fully able to complain. |
@dneto0 wait, does that mean that linear sampling of, say |
Yes, that's the way I read those tables too. Yes, this was suprising to me. |
Filed KhronosGroup/Vulkan-Docs#1362 to get some clarification from the Vulkan spec. |
So there is still this problem of some formats with In order to solve that at the API level, we figured (on the call) that we could split the "float" texture component type into "float" and "filtered-float". This would allow the |
TL;DR: undefined behavior in D3D12 I'm not sure I've completely followed the request here. In HLSL it is not valid to try and sample from an integer texture - so Texture2D, for example will fail to compile if you try and sample from it. However, if you bind an integer texture to something expecting a float texture, or if you try and sample from one of the non-sampleable formats, then you get undefined behavior. Details of which formats are sampleable or not can be found here: https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm#19.1.4%20D3D11.3%20Format%20List |
@damyanp the integer textures situation is rather clear. What is not clear is what happens if you linearly sample a float component texture (like R32F) with linear sampling, where the texture format doesn't have this capability. Is it still total UB? |
Yes, UB. |
And not just undefined value? Damn :( |
Fixed by #1223 |
Problem
Linear sampling (or "filtering") can only be done with textures that have
GPUTextureComponentType.float
. The shaders know about the component type of textures, but the shaders don't know if a sampler is filtering or not. So shader translation can't validate this, and outside of the shader, on the API side, we no longer know which textures are used with which samplers.Solutions
GPUBindingType::"filtering-sampler"
(in addition to regular "sampler" and "comparison-sampler") with the corresponding distinction in WGSL. This would mean:-
createShaderModule
can fail if we see that a filtering sampler is used with an incompatible texture-
createBindGroupLayout
can fail if the given sampler doesn't match the binding- no heavy validation at draw time
Details
If we go (3) one concern could be raised about how the translation from other languages, like SPIR-V, would know what type of the sampler to use. To some extent, it fits under the current umbrella of sampler diversity (we have a "comparison" sampler type that SPIR-V doesn't). As proposed in #889, we could generate multiple conflicting bindings for the SPIR-V sampler, and it will all work fine as long as only one of the multiple (regular/comparison/filtering) is used statically for any given entry point.
The text was updated successfully, but these errors were encountered: