|
3664 | 3664 | <a href="#3663" id="3663">3663</a>
|
3665 | 3665 | <a href="#3664" id="3664">3664</a>
|
3666 | 3666 | <a href="#3665" id="3665">3665</a>
|
| 3667 | +<a href="#3666" id="3666">3666</a> |
| 3668 | +<a href="#3667" id="3667">3667</a> |
| 3669 | +<a href="#3668" id="3668">3668</a> |
| 3670 | +<a href="#3669" id="3669">3669</a> |
| 3671 | +<a href="#3670" id="3670">3670</a> |
| 3672 | +<a href="#3671" id="3671">3671</a> |
| 3673 | +<a href="#3672" id="3672">3672</a> |
3667 | 3674 | </pre></div><pre class="rust"><code><span class="attr">#[cfg(feature = <span class="string">"trace"</span>)]
|
3668 | 3675 | </span><span class="kw">use </span><span class="kw">crate</span>::device::trace;
|
3669 | 3676 | <span class="kw">use crate</span>::{
|
|
3705 | 3712 |
|
3706 | 3713 | <span class="kw">use </span>smallvec::SmallVec;
|
3707 | 3714 | <span class="kw">use </span>thiserror::Error;
|
3708 |
| -<span class="kw">use </span>wgt::{DeviceLostReason, TextureFormat, TextureSampleType, TextureViewDimension}; |
| 3715 | +<span class="kw">use </span>wgt::{ |
| 3716 | + math::align_to, DeviceLostReason, TextureFormat, TextureSampleType, TextureViewDimension, |
| 3717 | +}; |
3709 | 3718 |
|
3710 | 3719 | <span class="kw">use </span>std::{
|
3711 | 3720 | borrow::Cow,
|
|
5295 | 5304 |
|
5296 | 5305 | <span class="doccomment">/// Generate information about late-validated buffer bindings for pipelines.
|
5297 | 5306 | </span><span class="comment">//TODO: should this be combined with `get_introspection_bind_group_layouts` in some way?
|
5298 |
| - </span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>make_late_sized_buffer_groups( |
| 5307 | + </span><span class="kw">fn </span>make_late_sized_buffer_groups( |
5299 | 5308 | shader_binding_sizes: <span class="kw-2">&</span>FastHashMap<naga::ResourceBinding, wgt::BufferSize>,
|
5300 | 5309 | layout: <span class="kw-2">&</span>binding_model::PipelineLayout,
|
5301 | 5310 | ) -> ArrayVec<pipeline::LateSizedBufferGroup, { hal::MAX_BIND_GROUPS }> {
|
|
5547 | 5556 | <span class="prelude-val">Ok</span>(bgl)
|
5548 | 5557 | }
|
5549 | 5558 |
|
5550 |
| - <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>create_buffer_binding<<span class="lifetime">'a</span>>( |
5551 |
| - <span class="self">self</span>: <span class="kw-2">&</span>Arc<<span class="self">Self</span>>, |
| 5559 | + <span class="kw">fn </span>create_buffer_binding<<span class="lifetime">'a</span>>( |
| 5560 | + <span class="kw-2">&</span><span class="self">self</span>, |
5552 | 5561 | bb: <span class="kw-2">&</span><span class="lifetime">'a </span>binding_model::ResolvedBufferBinding,
|
5553 | 5562 | binding: u32,
|
5554 | 5563 | decl: <span class="kw-2">&</span>wgt::BindGroupLayoutEntry,
|
5555 | 5564 | used_buffer_ranges: <span class="kw-2">&mut </span>Vec<BufferInitTrackerAction>,
|
5556 | 5565 | dynamic_binding_info: <span class="kw-2">&mut </span>Vec<binding_model::BindGroupDynamicBindingData>,
|
5557 | 5566 | late_buffer_binding_sizes: <span class="kw-2">&mut </span>FastHashMap<u32, wgt::BufferSize>,
|
5558 | 5567 | used: <span class="kw-2">&mut </span>BindGroupStates,
|
5559 |
| - limits: <span class="kw-2">&</span>wgt::Limits, |
5560 | 5568 | snatch_guard: <span class="kw-2">&</span><span class="lifetime">'a </span>SnatchGuard<<span class="lifetime">'a</span>>,
|
5561 | 5569 | ) -> <span class="prelude-ty">Result</span><hal::BufferBinding<<span class="lifetime">'a</span>, <span class="kw">dyn </span>hal::DynBuffer>, binding_model::CreateBindGroupError>
|
5562 | 5570 | {
|
|
5581 | 5589 | wgt::BufferBindingType::Uniform => (
|
5582 | 5590 | wgt::BufferUsages::UNIFORM,
|
5583 | 5591 | hal::BufferUses::UNIFORM,
|
5584 |
| - limits.max_uniform_buffer_binding_size, |
| 5592 | + <span class="self">self</span>.limits.max_uniform_buffer_binding_size, |
5585 | 5593 | ),
|
5586 | 5594 | wgt::BufferBindingType::Storage { read_only } => (
|
5587 | 5595 | wgt::BufferUsages::STORAGE,
|
|
5590 | 5598 | } <span class="kw">else </span>{
|
5591 | 5599 | hal::BufferUses::STORAGE_READ_WRITE
|
5592 | 5600 | },
|
5593 |
| - limits.max_storage_buffer_binding_size, |
| 5601 | + <span class="self">self</span>.limits.max_storage_buffer_binding_size, |
5594 | 5602 | ),
|
5595 | 5603 | };
|
5596 | 5604 |
|
5597 | 5605 | <span class="kw">let </span>(align, align_limit_name) =
|
5598 |
| - binding_model::buffer_binding_type_alignment(limits, binding_ty); |
| 5606 | + binding_model::buffer_binding_type_alignment(<span class="kw-2">&</span><span class="self">self</span>.limits, binding_ty); |
5599 | 5607 | <span class="kw">if </span>bb.offset % align <span class="kw">as </span>u64 != <span class="number">0 </span>{
|
5600 | 5608 | <span class="kw">return </span><span class="prelude-val">Err</span>(Error::UnalignedBufferOffset(
|
5601 | 5609 | bb.offset,
|
|
5671 | 5679 | late_buffer_binding_sizes.insert(binding, late_size);
|
5672 | 5680 | }
|
5673 | 5681 |
|
5674 |
| - <span class="macro">assert_eq!</span>(bb.offset % wgt::COPY_BUFFER_ALIGNMENT, <span class="number">0</span>); |
| 5682 | + <span class="comment">// This was checked against the device's alignment requirements above, |
| 5683 | + // which should always be a multiple of `COPY_BUFFER_ALIGNMENT`. |
| 5684 | + </span><span class="macro">assert_eq!</span>(bb.offset % wgt::COPY_BUFFER_ALIGNMENT, <span class="number">0</span>); |
| 5685 | + |
| 5686 | + <span class="comment">// `wgpu_hal` only restricts shader access to bound buffer regions with |
| 5687 | + // a certain resolution. For the sake of lazy initialization, round up |
| 5688 | + // the size of the bound range to reflect how much of the buffer is |
| 5689 | + // actually going to be visible to the shader. |
| 5690 | + </span><span class="kw">let </span>bounds_check_alignment = |
| 5691 | + binding_model::buffer_binding_type_bounds_check_alignment(<span class="kw-2">&</span><span class="self">self</span>.alignments, binding_ty); |
| 5692 | + <span class="kw">let </span>visible_size = align_to(bind_size, bounds_check_alignment); |
| 5693 | + |
5675 | 5694 | used_buffer_ranges.extend(buffer.initialization_status.read().create_action(
|
5676 | 5695 | buffer,
|
5677 |
| - bb.offset..bb.offset + bind_size, |
| 5696 | + bb.offset..bb.offset + visible_size, |
5678 | 5697 | MemoryInitKind::NeedsInitializedMemory,
|
5679 | 5698 | ));
|
5680 | 5699 |
|
|
5686 | 5705 | }
|
5687 | 5706 |
|
5688 | 5707 | <span class="kw">fn </span>create_sampler_binding<<span class="lifetime">'a</span>>(
|
5689 |
| - <span class="self">self</span>: <span class="kw-2">&</span>Arc<<span class="self">Self</span>>, |
| 5708 | + <span class="kw-2">&</span><span class="self">self</span>, |
5690 | 5709 | used: <span class="kw-2">&mut </span>BindGroupStates,
|
5691 | 5710 | binding: u32,
|
5692 | 5711 | decl: <span class="kw-2">&</span>wgt::BindGroupLayoutEntry,
|
|
5734 | 5753 | <span class="prelude-val">Ok</span>(sampler.raw())
|
5735 | 5754 | }
|
5736 | 5755 |
|
5737 |
| - <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>create_texture_binding<<span class="lifetime">'a</span>>( |
5738 |
| - <span class="self">self</span>: <span class="kw-2">&</span>Arc<<span class="self">Self</span>>, |
| 5756 | + <span class="kw">fn </span>create_texture_binding<<span class="lifetime">'a</span>>( |
| 5757 | + <span class="kw-2">&</span><span class="self">self</span>, |
5739 | 5758 | binding: u32,
|
5740 | 5759 | decl: <span class="kw-2">&</span>wgt::BindGroupLayoutEntry,
|
5741 | 5760 | view: <span class="kw-2">&</span><span class="lifetime">'a </span>Arc<TextureView>,
|
|
5833 | 5852 | <span class="kw-2">&mut </span>dynamic_binding_info,
|
5834 | 5853 | <span class="kw-2">&mut </span>late_buffer_binding_sizes,
|
5835 | 5854 | <span class="kw-2">&mut </span>used,
|
5836 |
| - <span class="kw-2">&</span><span class="self">self</span>.limits, |
5837 | 5855 | <span class="kw-2">&</span>snatch_guard,
|
5838 | 5856 | )<span class="question-mark">?</span>;
|
5839 | 5857 |
|
|
5855 | 5873 | <span class="kw-2">&mut </span>dynamic_binding_info,
|
5856 | 5874 | <span class="kw-2">&mut </span>late_buffer_binding_sizes,
|
5857 | 5875 | <span class="kw-2">&mut </span>used,
|
5858 |
| - <span class="kw-2">&</span><span class="self">self</span>.limits, |
5859 | 5876 | <span class="kw-2">&</span>snatch_guard,
|
5860 | 5877 | )<span class="question-mark">?</span>;
|
5861 | 5878 | hal_buffers.push(bb);
|
|
5991 | 6008 | <span class="prelude-val">Ok</span>(bind_group)
|
5992 | 6009 | }
|
5993 | 6010 |
|
5994 |
| - <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>check_array_binding( |
| 6011 | + <span class="kw">fn </span>check_array_binding( |
5995 | 6012 | features: wgt::Features,
|
5996 | 6013 | count: <span class="prelude-ty">Option</span><NonZeroU32>,
|
5997 | 6014 | num_bindings: usize,
|
|
6024 | 6041 | <span class="prelude-val">Ok</span>(())
|
6025 | 6042 | }
|
6026 | 6043 |
|
6027 |
| - <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>texture_use_parameters( |
6028 |
| - <span class="self">self</span>: <span class="kw-2">&</span>Arc<<span class="self">Self</span>>, |
| 6044 | + <span class="kw">fn </span>texture_use_parameters( |
| 6045 | + <span class="kw-2">&</span><span class="self">self</span>, |
6029 | 6046 | binding: u32,
|
6030 | 6047 | decl: <span class="kw-2">&</span>wgt::BindGroupLayoutEntry,
|
6031 | 6048 | view: <span class="kw-2">&</span>TextureView,
|
|
7115 | 7132 | <span class="prelude-val">Ok</span>(cache)
|
7116 | 7133 | }
|
7117 | 7134 |
|
7118 |
| - <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>get_texture_format_features( |
7119 |
| - <span class="kw-2">&</span><span class="self">self</span>, |
7120 |
| - format: TextureFormat, |
7121 |
| - ) -> wgt::TextureFormatFeatures { |
| 7135 | + <span class="kw">fn </span>get_texture_format_features(<span class="kw-2">&</span><span class="self">self</span>, format: TextureFormat) -> wgt::TextureFormatFeatures { |
7122 | 7136 | <span class="comment">// Variant of adapter.get_texture_format_features that takes device features into account
|
7123 | 7137 | </span><span class="kw">use </span>wgt::TextureFormatFeatureFlags <span class="kw">as </span>tfsc;
|
7124 | 7138 | <span class="kw">let </span><span class="kw-2">mut </span>format_features = <span class="self">self</span>.adapter.get_texture_format_features(format);
|
|
7132 | 7146 | format_features
|
7133 | 7147 | }
|
7134 | 7148 |
|
7135 |
| - <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>describe_format_features( |
| 7149 | + <span class="kw">fn </span>describe_format_features( |
7136 | 7150 | <span class="kw-2">&</span><span class="self">self</span>,
|
7137 | 7151 | format: TextureFormat,
|
7138 | 7152 | ) -> <span class="prelude-ty">Result</span><wgt::TextureFormatFeatures, MissingFeatures> {
|
|
0 commit comments