Repository: godotengine/godot
File: drivers/vulkan/rendering_device_vulkan.cpp (C++)

Code before:

String RenderingDeviceVulkan::get_device_vendor_name() const {
	return context->get_device_vendor_name();
}

String RenderingDeviceVulkan::get_device_name() const {
	return context->get_device_name();
}

RenderingDevice::DeviceType RenderingDeviceVulkan::get_device_type() const {
	return context->get_device_type();
}

String RenderingDeviceVulkan::get_device_api_version() const {
	return context->get_device_api_version();
}

String RenderingDeviceVulkan::get_device_pipeline_cache_uuid() const {
	return context->get_device_pipeline_cache_uuid();
}

void RenderingDeviceVulkan::_finalize_command_bufers() {
	if (draw_list) {
		ERR_PRINT("Found open draw list at the end of the frame, this should never happen (further drawing will likely not work).");
	}

	if (compute_list) {
		ERR_PRINT("Found open compute list at the end of the frame, this should never happen (further compute will likely not work).");
	}

	{ // Complete the setup buffer (that needs to be processed before anything else).
		vkEndCommandBuffer(frames[frame].setup_command_buffer);
		vkEndCommandBuffer(frames[frame].draw_command_buffer);
	}
}

void RenderingDeviceVulkan::_begin_frame() {
	// Erase pending resources.
	_free_pending_resources(frame);

	// Create setup command buffer and set as the setup buffer.

	{
		VkCommandBufferBeginInfo cmdbuf_begin;
		cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
		cmdbuf_begin.pNext = nullptr;
		cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
		cmdbuf_begin.pInheritanceInfo = nullptr;

		VkResult err = vkResetCommandBuffer(frames[frame].setup_command_buffer, 0);
		ERR_FAIL_COND_MSG(err, "vkResetCommandBuffer failed with error " + itos(err) + ".");

Review comment (bug):
Unfortunately, just because an implementation supports one sample count, does not mean that they support all valid lesser sample counts (see [here](https://vulkan.gpuinfo.org/displaydevicelimit.php?name=framebufferColorSampleCounts&platform=all)). For example, it is common to support 4 MSAA samples but not 2. If a user requests 2 MSAA samples, but their device only supports 1 or 4, this line will return 2 and will still fail.

Instead I would do something like:
```
if (sample_count_flags & rasterization_sample_count[p_requested_sample_count]) {
    return rasterization_sample_count[p_requested_sample_count];
} else {
    VkSampleCountFlagBits sample_count = rasterization_sample_count[p_requested_sample_count];
    while (sample_count > VK_SAMPLE_COUNT_1_BIT) {
        //check each successively smaller sample count until you hit one sample
    }
}
```

Code after:

void RenderingDeviceVulkan::draw_command_insert_label(String p_label_name, const Color p_color) {
	context->command_insert_label(frames[frame].draw_command_buffer, p_label_name, p_color);
}

void RenderingDeviceVulkan::draw_command_end_label() {
	context->command_end_label(frames[frame].draw_command_buffer);
}

String RenderingDeviceVulkan::get_device_vendor_name() const {
	return context->get_device_vendor_name();
}

String RenderingDeviceVulkan::get_device_name() const {
	return context->get_device_name();
}

RenderingDevice::DeviceType RenderingDeviceVulkan::get_device_type() const {
	return context->get_device_type();
}

String RenderingDeviceVulkan::get_device_api_version() const {
	return context->get_device_api_version();
}

String RenderingDeviceVulkan::get_device_pipeline_cache_uuid() const {
	return context->get_device_pipeline_cache_uuid();
}

void RenderingDeviceVulkan::_finalize_command_bufers() {
	if (draw_list) {
		ERR_PRINT("Found open draw list at the end of the frame, this should never happen (further drawing will likely not work).");
	}

	if (compute_list) {
		ERR_PRINT("Found open compute list at the end of the frame, this should never happen (further compute will likely not work).");
	}

	{ // Complete the setup buffer (that needs to be processed before anything else).
		vkEndCommandBuffer(frames[frame].setup_command_buffer);
		vkEndCommandBuffer(frames[frame].draw_command_buffer);
	}
}

void RenderingDeviceVulkan::_begin_frame() {
	// Erase pending resources.
	_free_pending_resources(frame);

	// Create setup command buffer and set as the setup buffer.

	{