pick physical device
This commit is contained in:
parent
1a2c31ab41
commit
f48c8cd2cc
1 changed files with 38 additions and 2 deletions
40
main.cpp
40
main.cpp
|
|
@ -35,7 +35,7 @@ private:
|
|||
|
||||
void initVulkan() {
|
||||
createInstance();
|
||||
// pickPhysicalDevice();
|
||||
pickPhysicalDevice();
|
||||
}
|
||||
|
||||
void mainLoop() {
|
||||
|
|
@ -104,9 +104,45 @@ private:
|
|||
return true;
|
||||
}
|
||||
|
||||
void pickPhysicalDevice() {
|
||||
uint32_t deviceCount = 0;
|
||||
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
|
||||
|
||||
if (deviceCount == 0) {
|
||||
throw std::runtime_error("no gpu with vulkan support");
|
||||
}
|
||||
|
||||
std::vector<VkPhysicalDevice> devices(deviceCount);
|
||||
vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());
|
||||
|
||||
for (const auto& device : devices) {
|
||||
if (isDeviceSuitable(device)) {
|
||||
physicalDevice = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!physicalDevice) throw std::runtime_error("no suitable gpu");
|
||||
}
|
||||
|
||||
static bool isDeviceSuitable(VkPhysicalDevice device) {
|
||||
VkPhysicalDeviceProperties properties;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
|
||||
vkGetPhysicalDeviceProperties(device, &properties);
|
||||
vkGetPhysicalDeviceFeatures(device, &features);
|
||||
|
||||
// if (properties.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) return false;
|
||||
if (!features.geometryShader) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
GLFWwindow* window = nullptr;
|
||||
VkInstance instance {};
|
||||
|
||||
VkInstance instance = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
int main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue