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

Method AllocImage

vgpu/image.go:774–853  ·  view source on GitHub ↗

AllocImage allocates the VkImage on the device (must set first), based on the current Format info, and other flags.

()

Source from the content-addressed store, hash-verified

772// AllocImage allocates the VkImage on the device (must set first),
773// based on the current Format info, and other flags.
774func (im *Image) AllocImage() {
775 im.FreeImage()
776 var usage vk.ImageUsageFlagBits
777 // var imgFlags vk.ImageCreateFlags
778 imgType := vk.ImageType2d
779 switch {
780 case im.HasFlag(DepthImage):
781 usage |= vk.ImageUsageDepthStencilAttachmentBit
782 case im.HasFlag(FramebufferImage):
783 usage |= vk.ImageUsageColorAttachmentBit
784 usage |= vk.ImageUsageTransferSrcBit // todo: extra bit to qualify
785 default:
786 usage |= vk.ImageUsageSampledBit // default is sampled texture
787 usage |= vk.ImageUsageTransferDstBit
788 }
789 if im.IsHostActive() && !im.HasFlag(FramebufferImage) {
790 usage |= vk.ImageUsageTransferDstBit
791 }
792 if im.HasFlag(ImageOnHostOnly) {
793 usage |= vk.ImageUsageTransferDstBit
794 }
795
796 if im.Format.Layers == 0 {
797 im.Format.Layers = 1
798 }
799
800 var image vk.Image
801 w, h := im.Format.Size32()
802 imgcfg := &vk.ImageCreateInfo{
803 SType: vk.StructureTypeImageCreateInfo,
804 // Flags: imgFlags,
805 ImageType: imgType,
806 Format: im.Format.Format,
807 Extent: vk.Extent3D{
808 Width: w,
809 Height: h,
810 Depth: 1,
811 },
812 MipLevels: 1,
813 ArrayLayers: uint32(im.Format.Layers),
814 Samples: im.Format.Samples,
815 Tiling: vk.ImageTilingOptimal,
816 Usage: vk.ImageUsageFlags(usage),
817 InitialLayout: vk.ImageLayoutUndefined,
818 SharingMode: vk.SharingModeExclusive,
819 }
820
821 properties := vk.MemoryPropertyDeviceLocalBit
822 if im.HasFlag(ImageOnHostOnly) {
823 properties = vk.MemoryPropertyHostVisibleBit | vk.MemoryPropertyHostCoherentBit
824 imgcfg.Tiling = vk.ImageTilingLinear // essential for grabbing
825 }
826
827 ret := vk.CreateImage(im.Dev, imgcfg, nil, &image)
828 IfPanic(NewError(ret))
829 im.Image = image
830
831 var memReqs vk.MemoryRequirements

Callers 3

SetSizeMethod · 0.95
ConfigGrabMethod · 0.80
AllocTextureMethod · 0.80

Calls 8

FreeImageMethod · 0.95
HasFlagMethod · 0.95
IsHostActiveMethod · 0.95
SetFlagMethod · 0.95
IfPanicFunction · 0.85
NewErrorFunction · 0.85
Size32Method · 0.80

Tested by

no test coverage detected