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
[wgsl] Textures #573
Comments
Looking at various shading languages: MSL
HLSL
I'm not sure what the GLSL
WGSLGiven the above I'd propose something like the following for WGSL.
|
I think you forgot SPIR-V and the "shadow samplers" in GLSL |
GLSL Shadow
Does this map to the
|
For the SPIR-V side, there is a single
|
Adding this relevant note which surprised me when working with depth sampling. In Vulkan, "Validation Rules within a Module"
|
Does that mean depth sampling doesn't work in Vulkan, or it doesn't care what you say and lets you do it no matter what you set? |
From what I understand, depth sampling does work and it simply ignores the Depth operand. The spec is very unclear about whether or not the image passed to Metal's documentation is also not clear about this. In HLSL it is valid to comparison-sample a color texture.
Experimentally, neither Metal nor Vulkan's validation layers complain if you depth-sample a color texture, though there's inconsistent behavior depending on the texture format / driver. Sometimes it follows the HLSL semantics and does the depth-comparison with the first component, sometimes it simply returns the value of the first component, and sometimes it returns something else. |
Thank you for investigation @dj2 and @austinEng ! MSAA
I don't think we need the
It would be highly inconvenient for the users if we require it. More often than not, the decision on MSAA quality is made at run-time, and not everybody wants to unroll the MSAA iteration loops and generate separate shaders per sample count. Depth comparisonLet's not try to do depth comparison on color values. That's not terribly useful, hard to guarantee, and complicates the grammar/shader language. It looks like Metal requires us to specify if the texture is only used for depth comparison sampling... |
Not yet, was waiting to see if someone could point me to how the MSL |
In HLSL you have a regular
|
So, then the intersection of those 3 APIs seems to be: WGSL
Unless I missed something? |
WebGPU currently supports 1d textures, cube textures, and 3d textures. It looks like all 3 APIs support those. |
On Vulkan depth textures. My understanding is that it's all controlled from the API side, and only certain image formats are compatible with being attached as a depth texture. See documentation related to VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT. |
As for the proposal, we need to make clear what the Depending on what operations are being performed on an image, Vulkan sometimes requires the shader to declare the image format. E.g. if doing image atomics. That will affect the declaration, I think. I'll need to look further. |
Discussed at the 2020-06-09 meeting. |
I see in MSL spec that depth textures provide both |
Thinking of samplers and comparison samplers, ignoring depth and stencil for now. Declare Texture
%1 = OpTypeImage %type <1|2|3> 0 0 <0|1 for ms> 1 Unknown Declare Sampler
%14 = OpTypeSampler
OpTypeSampler Fetch texel from texture
%32 = OpImageFetch %v4float %31 %29 Lod %int_2 Sample from a texture
%24 = OpImageSampleImplicitLod %v4float %19 %23
Comparison sample from a texture
I believe the only grammar changes needed are the ability to declare the textures and samplers. The calls look like method calls, so we'd just need to validate that the method called on the texture is correct during validation. |
@dj2 thank you for writing this down!
I don't think you can talk about comparison samplers without considering depth textures. IIRC, the limitations of the API force us to only use one with another. Using a comparison sampler with a regular texture is not portable to MSL, for example.
Why does it get a
Can we please restrict the overloading semantics of functions to only be within "generics"? Basically, it makes sense to have functions polymorphic of some types, but I don't think we need to extend this to calling the same function with different set of parameters. It introduces ambiguity, confusion, and doesn't really get us much over the explicit variant:
This should be Also, cube arrays would require vec4 coordinates.
MSL doesn't allow regular textures to do Other questions
|
I think that's taken into account with the methods taking either a sampler or a comparison sampler?
As far as I can tell, with SPIR-V you need to have the sampler as it is part of the
GLSL appears to be similar in that you end up doing
Works for me.
There appears to be a bit of missing text here, I'm guessing you mean should be
Oh, missed that when reading through the MSL code. So, then we do need to add the: Depth textures
%1 = OpTypeImage %type <1|2|3> 0 0 <0|1 for ms> 1 Unknown %53 = OpTypeImage %float <2|Cube> 1 0 <1|0 for ms> Unknown
Yes.
If MSL doesn't allow it, then I don't think we can do it unless there is some way to work around it in MSL.
Haven't gotten there yet, do you have a GLSL example where this is done? |
|
Change from method call syntaxes to functions:
|
Discussed at the 2020-06-24 WebGPU Virtual F2F. |
Relevant: #532 (comment) |
@dj2 a few corrections are needed
|
There's a lot going on here, but I wanted to answer one thing:
Yes, I believe so. In Vulkan SPIR-V an image type is either sampled (Sampled=1) or not-sampled (Sampled=2) (a storage image or storage texel buffer). To read a texel from a Sample=d=1 image, use OpImageFetch; to read a texel from a Sampled=2 image, use OpImageRead. |
This CL starts to add textures into the WGSL spec. Issue #573
Sounds like these are probably issues with the Vulkan and Metal validation layers, and we should ideally report them upstream. |
I've started a document that lists each of the texture functions by texture type for MSL and HLSL (SPIR-V TODO). |
Closing. Textures were added to WGSL with a bunch of functions. The only thing left seems to be the texture gather builtins, but I think it should be in a separate issue given how much was specced already. |
The design for textures needs to be added to the spec. Need to determine a good syntax for textures in the language.
The text was updated successfully, but these errors were encountered: