Skip to content

Conversation

@kvark
Copy link
Contributor

@kvark kvark commented Jul 4, 2019

An immutable sampler is one that is a part of the pipeline layout definition, not affected by any bind group binding. The benefits of specifying a sampler as immutable are:

  • on Vulkan, immutable samplers are part of the API, provided in vkCreateDescriptorSetLayout, so the mapping is trivial.
  • on D3D12, immutable samplers can be hard-coded into the root signature that corresponds to GPUPipelineLayout. They are represented by the static sampler concept.
  • on Metal iOS before "MTLFeatureSet_iOS_GPUFamily3_v1" it's impossible to create a sampler with a comparison function, which is often used for shadow map sampling. If it's provided as a part of the pipeline layout, the implementation may hard-code the sampler into the generated MSL shader code, effectively supporting comparison. See Sampler depth comparison before MTLFeatureSet_iOS_GPUFamily3_v1  KhronosGroup/MoltenVK#556 for some real use-case discussion. A as consequence, we may want to document the restriction (for all platforms) that comparison operation is only available on immutable samplers.

If the immutableSampler field of GPUBindGroupLayoutBinding is not nil, and the binding type is "sampler", then this binding is not expected to be provided in GPUBindGroupDescriptor corresponding to the creation of a bind group with this layout.


Preview | Diff

spec/index.bs Outdated
// For "sampler" binding type, if the actual sampler object is provided here,
// it becomes a part of the layout: an "immutable" sampler object, in a sense that
// no bind group binding call can affect it.
GPUSampler immutableSampler;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense for this to be a GPUSamplerDescriptor instead? It doesn't match what Vulkan does but is closer to what D3D12 and Metal do where the sampler descriptor is embedded in the shading language source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean, having a flag there saying that a sampler is immutable? That's not going to be known at pipeline creation time, so I don't see how this would help. Please clarify.

Copy link

@magcius magcius Jul 5, 2019

Choose a reason for hiding this comment

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

I think Kangz means providing the creation descriptor instead of the platform object to the BindGroupLayout. I'm not sure I like that as much, but I see the appeal of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see. Thanks for clarification! I think that would make sense to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change is now in

@kvark kvark force-pushed the immutable-sampler branch from 25a6c42 to c585541 Compare July 5, 2019 13:27
@litherum
Copy link
Contributor

litherum commented Jul 5, 2019

I don’t think “the mapping is trivial” is sufficient to justify an addition to a Web API. We already have a way of supplying samplers to shaders; I’d like to see some performance numbers that justify this addition before we approve it.

Just like indirect draw arguments, sampler comparison functions are present on all hardware we’re targeting for WebGPU. We should just require support for them.

@kvark
Copy link
Contributor Author

kvark commented Jul 5, 2019

@litherum "the mapping is trivial" is not by itself sufficient to justify the addition. I agree. We are weighting many factors here. One of them is how difficult it is to map to the native APIs. We know the answer to this one.

Another factor, as you mentioned, is what does it give us in terms of performance. I haven't done the benchmarks, but I could find this reference from AMD in 2016, see slide 14:

Immutable Samplers can be constructed by SALU instructions instead of SMEM loads. Reduces the amount of latency in the shader. SALU pipe is mostly under-utilized.

I imagine the same reasoning can be applied to Metal, since it supports constexpr samplers in MSL?

Just like indirect draw arguments, sampler comparison functions are present on all hardware we’re targeting for WebGPU. We should just require support for them.

Is there a place where you have those hardware requirements specified? IIRC, indirect arguments on iOS require 9.0, which covers a much wider range of devices than "MTLFeatureSet_iOS_GPUFamily3_v1". For example, iPhone4S can run iOS 9.0, but MTLFeatureSet_iOS_GPUFamily3_v1 is only available in iPhone6S, so there is about 2 generations of a difference here.

@damyanp
Copy link

damyanp commented Jul 12, 2019

I’d like to see some performance numbers that justify this addition before we approve it.

I'm trying to dig up some info on this from the d3d perspective.

@kainino0x kainino0x force-pushed the immutable-sampler branch from c585541 to 327f77a Compare July 12, 2019 21:05
@kainino0x
Copy link
Contributor

Rebased over #365.

@grorg
Copy link
Contributor

grorg commented Jul 15, 2019

This was discussed at the 15 July 2019 teleconference.

@damyanp
Copy link

damyanp commented Jul 15, 2019

I’d like to see some performance numbers that justify this addition before we approve it.

I'm trying to dig up some info on this from the d3d perspective.

Here's what I heard back:

"They are simply a massive convenience. You can define your samplers directly in your shader and not have any external code have to worry about anything."

@kvark
Copy link
Contributor Author

kvark commented Jul 15, 2019

Thanks @damyanp !
I would like to see immutable samplers supported by the API at some point. It looks like the group wants to see hardware requirements or performance benefits for this to happen now. For the former, Apple is fine with iPhone 6S as a baseline, and for the latter - there is no concrete evidence.
Closing then...

@kvark kvark closed this Jul 15, 2019
@devshgraphicsprogramming

Those things (immutable samplers) are a tad faster on Android IIRC

Also easier to implement on an OpenGL backend, OpenGL 4.5 and below has no mutable samplers that you can combine in a shader, the combining happens on the API side.

Full mutable (a shader texture(image,sampler) functionality) is impossible to pull off in OpenGL (except for 4.6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants