Config configures the GPU given the extensions set in InstanceExts, DeviceExts, and ValidationLayers, and the given GPUOpts options. Only the first such opts will be used -- the variable args is used to enable no options to be passed by default.
(name string, opts ...*GPUOpts)
| 198 | // Only the first such opts will be used -- the variable args is used to enable |
| 199 | // no options to be passed by default. |
| 200 | func (gp *GPU) Config(name string, opts ...*GPUOpts) error { |
| 201 | gp.AppName = name |
| 202 | gp.UserOpts = DefaultOpts |
| 203 | if len(opts) > 0 { |
| 204 | if gp.UserOpts == nil { |
| 205 | gp.UserOpts = opts[0] |
| 206 | } else { |
| 207 | gp.UserOpts.CopyFrom(opts[0]) |
| 208 | } |
| 209 | } |
| 210 | if Debug { |
| 211 | gp.AddValidationLayer("VK_LAYER_KHRONOS_validation") |
| 212 | gp.AddInstanceExt("VK_EXT_debug_report") // note _utils is not avail yet |
| 213 | } |
| 214 | |
| 215 | // Select instance extensions |
| 216 | requiredInstanceExts := SafeStrings(gp.InstanceExts) |
| 217 | actualInstanceExts, err := InstanceExts() |
| 218 | IfPanic(err) |
| 219 | instanceExts, missing := CheckExisting(actualInstanceExts, requiredInstanceExts) |
| 220 | if missing > 0 { |
| 221 | log.Println("vgpu: warning: missing", missing, "required instance extensions during Config") |
| 222 | } |
| 223 | if Debug { |
| 224 | log.Printf("vgpu: enabling %d instance extensions", len(instanceExts)) |
| 225 | } |
| 226 | |
| 227 | // Select instance layers |
| 228 | var validationLayers []string |
| 229 | if len(gp.ValidationLayers) > 0 { |
| 230 | requiredValidationLayers := SafeStrings(gp.ValidationLayers) |
| 231 | actualValidationLayers, err := ValidationLayers() |
| 232 | IfPanic(err) |
| 233 | validationLayers, missing = CheckExisting(actualValidationLayers, requiredValidationLayers) |
| 234 | if missing > 0 { |
| 235 | log.Println("vgpu: warning: missing", missing, "required validation layers during Config") |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | // Create instance |
| 240 | var instance vk.Instance |
| 241 | ret := vk.CreateInstance(&vk.InstanceCreateInfo{ |
| 242 | SType: vk.StructureTypeInstanceCreateInfo, |
| 243 | PApplicationInfo: &vk.ApplicationInfo{ |
| 244 | SType: vk.StructureTypeApplicationInfo, |
| 245 | ApiVersion: uint32(gp.APIVersion), |
| 246 | ApplicationVersion: uint32(gp.AppVersion), |
| 247 | PApplicationName: SafeString(gp.AppName), |
| 248 | PEngineName: "vgpu\x00", |
| 249 | }, |
| 250 | EnabledExtensionCount: uint32(len(instanceExts)), |
| 251 | PpEnabledExtensionNames: instanceExts, |
| 252 | EnabledLayerCount: uint32(len(validationLayers)), |
| 253 | PpEnabledLayerNames: validationLayers, |
| 254 | Flags: vk.InstanceCreateFlags(vk.InstanceCreateEnumeratePortabilityBit), |
| 255 | }, nil, &instance) |
| 256 | IfPanic(NewError(ret)) |
| 257 | gp.Instance = instance |
no test coverage detected