MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / into_raw

Method into_raw

crates/cust/src/texture.rs:345–369  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

343
344impl ResourceDescriptor {
345 pub fn into_raw(self) -> CUDA_RESOURCE_DESC {
346 let ty = match self.ty {
347 ResourceType::Array { .. } => CUresourcetype::CU_RESOURCE_TYPE_ARRAY,
348 // ResourceType::Linear { .. } => CUresourcetype::CU_RESOURCE_TYPE_LINEAR,
349 // ResourceType::Pitch2d { .. } => CUresourcetype::CU_RESOURCE_TYPE_PITCH2D,
350 };
351
352 // we can't just use `array.handle`, this will cause the array object to call `Drop` and destroy the
353 // array prematurely, which will yield a status access violation when we try to create the texture object
354 // so we need to essentially leak the array into just a handle.
355 let res = match self.ty {
356 ResourceType::Array { array } => CUDA_RESOURCE_DESC_st__bindgen_ty_1 {
357 array: CUDA_RESOURCE_DESC_st__bindgen_ty_1__bindgen_ty_1 {
358 hArray: array.into_raw(),
359 },
360 },
361 // ResourceType::Linear { format, num_channels, size }
362 };
363
364 CUDA_RESOURCE_DESC {
365 resType: ty,
366 flags: self.flags.bits(),
367 res,
368 }
369 }
370
371 // TODO: evaluate if its possible to cause UB by making a raw descriptor with an invalid array handle.
372 pub(crate) fn from_raw(raw: CUDA_RESOURCE_DESC) -> Self {

Callers 1

newMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected