From 4ba8637d018fec6d6e3a90d7fa47d11c085f6b4a Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 11 May 2021 21:38:09 +0200 Subject: [PATCH] generator: pSampleMask setter should write NULL if slice is empty (#432) As per [1] no explicit length field is available for `pSampleMask`, this is based on `ceil(rasterizationSamples/32)` instead. It is valid to not set an array for `pSampleMask` (under normal circumestances this is signaled by setting the length to zero, and the array pointer is ignored) but this has to happen by setting the pointer to `NULL`. [1]: https://github.com/MaikKlein/ash/issues/256 --- ash/src/vk/definitions.rs | 11 ++++++++++- generator/src/lib.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ash/src/vk/definitions.rs b/ash/src/vk/definitions.rs index 2987558..4fb1406 100644 --- a/ash/src/vk/definitions.rs +++ b/ash/src/vk/definitions.rs @@ -5672,8 +5672,17 @@ impl<'a> PipelineMultisampleStateCreateInfoBuilder<'a> { self.inner.min_sample_shading = min_sample_shading; self } + #[doc = r" Sets `p_sample_mask` to `null` if the slice is empty. The mask will"] + #[doc = r" be treated as if it has all bits set to `1`."] + #[doc = r""] + #[doc = r" See "] + #[doc = r" for more details."] pub fn sample_mask(mut self, sample_mask: &'a [SampleMask]) -> Self { - self.inner.p_sample_mask = sample_mask.as_ptr() as *const SampleMask; + self.inner.p_sample_mask = if sample_mask.is_empty() { + std::ptr::null() + } else { + sample_mask.as_ptr() as *const SampleMask + }; self } pub fn alpha_to_coverage_enable(mut self, alpha_to_coverage_enable: bool) -> Self { diff --git a/generator/src/lib.rs b/generator/src/lib.rs index 77fe6cd..5583129 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -1788,8 +1788,17 @@ pub fn derive_setters( if name == "pSampleMask" { return Some(quote!{ + /// Sets `p_sample_mask` to `null` if the slice is empty. The mask will + /// be treated as if it has all bits set to `1`. + /// + /// See + /// for more details. pub fn sample_mask(mut self, sample_mask: &'a [SampleMask]) -> Self { - self.inner.p_sample_mask = sample_mask.as_ptr() as *const SampleMask; + self.inner.p_sample_mask = if sample_mask.is_empty() { + std::ptr::null() + } else { + sample_mask.as_ptr() as *const SampleMask + }; self } });