MCPcopy Create free account
hub / github.com/cogentcore/core / DevGoImage

Method DevGoImage

vgpu/image.go:428–451  ·  view source on GitHub ↗

DevGoImage returns an image.RGBA standard Go image version of the HostOnly Device memory representation, directly pointing to the source memory. This will be valid only as long as that memory is valid, and modifications will directly write into the source memory. You MUST call UnmapDev once done us

()

Source from the content-addressed store, hash-verified

426// Only works if ImageOnHostOnly and Format is default
427// vk.FormatR8g8b8a8Srgb.
428func (im *Image) DevGoImage() (*image.RGBA, error) {
429 if !im.HasFlag(ImageOnHostOnly) || im.Mem == vk.NullDeviceMemory {
430 return nil, fmt.Errorf("vgpu.Image DevGoImage: Image not available because device Image is not HostOnly, or Mem is nil: %s", im.Name)
431 }
432 if !im.Format.IsStdRGBA() && !im.Format.IsRGBAUnorm() {
433 return nil, fmt.Errorf("vgpu.Image DevGoImage: Device image is not standard RGBA format: %s", im.Format.String())
434 }
435 ptr := MapMemoryAll(im.Dev, im.Mem)
436 subrec := vk.ImageSubresource{}
437 subrec.AspectMask = vk.ImageAspectFlags(vk.ImageAspectColorBit)
438 subrec.ArrayLayer = 0
439 sublay := vk.SubresourceLayout{}
440 vk.GetImageSubresourceLayout(im.Dev, im.Image, &subrec, &sublay)
441 sublay.Deref()
442 offset := int(sublay.Offset)
443 size := int(sublay.Size) // im.Format.LayerByteSize()
444 pix := (*[ByteCopyMemoryLimit]byte)(ptr)[offset : size+offset]
445
446 rgba := &image.RGBA{}
447 rgba.Pix = pix
448 rgba.Stride = int(sublay.RowPitch) // im.Format.Stride()
449 rgba.Rect = image.Rect(0, 0, im.Format.Size.X, im.Format.Size.Y)
450 return rgba, nil
451}
452
453// DevGoImageCopy sets the given image.RGBA standard Go image to
454// a copy of the HostOnly Device memory representation,

Callers 2

mainFunction · 0.80
ImageMethod · 0.80

Calls 6

HasFlagMethod · 0.95
MapMemoryAllFunction · 0.85
IsStdRGBAMethod · 0.80
IsRGBAUnormMethod · 0.80
ErrorfMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected