Add a toggle to turn off vsync in Dawn
This commit add a toggle to turn off vsync in Dawn. When turn off vsync, choose vulkan present mode VK_PRESENT_MODE_IMMEDIATE_KHR if the mode is available on the system, but if the mode isn't supported, choose default mode VK_PRESENT_MODE_FIFO_KHR. BUG=dawn:237 Change-Id: If400262b67cc8051422745e3bed737431183c0b6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12100 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Yizhou Jiang <yizhou.jiang@intel.com>
This commit is contained in:
parent
b0cdf95213
commit
1093c4de2c
|
@ -57,6 +57,11 @@ namespace dawn_native {
|
||||||
"Clears resource to zero on first usage. This initializes the resource "
|
"Clears resource to zero on first usage. This initializes the resource "
|
||||||
"so that no dirty bits from recycled memory is present in the new resource.",
|
"so that no dirty bits from recycled memory is present in the new resource.",
|
||||||
"https://bugs.chromium.org/p/dawn/issues/detail?id=145"}},
|
"https://bugs.chromium.org/p/dawn/issues/detail?id=145"}},
|
||||||
|
{Toggle::TurnOffVsync,
|
||||||
|
{"turn_off_vsync",
|
||||||
|
"Turn off vsync when rendering. In order to do performance test or run perf tests, "
|
||||||
|
"turn off vsync so that the fps can exeed 60.",
|
||||||
|
"https://bugs.chromium.org/p/dawn/issues/detail?id=237"}},
|
||||||
{Toggle::UseTemporaryBufferInCompressedTextureToTextureCopy,
|
{Toggle::UseTemporaryBufferInCompressedTextureToTextureCopy,
|
||||||
{"use_temporary_buffer_in_texture_to_texture_copy",
|
{"use_temporary_buffer_in_texture_to_texture_copy",
|
||||||
"Split texture-to-texture copy into two copies: copy from source texture into a "
|
"Split texture-to-texture copy into two copies: copy from source texture into a "
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace dawn_native {
|
||||||
NonzeroClearResourcesOnCreationForTesting,
|
NonzeroClearResourcesOnCreationForTesting,
|
||||||
AlwaysResolveIntoZeroLevelAndLayer,
|
AlwaysResolveIntoZeroLevelAndLayer,
|
||||||
LazyClearResourceOnFirstUse,
|
LazyClearResourceOnFirstUse,
|
||||||
|
TurnOffVsync,
|
||||||
UseTemporaryBufferInCompressedTextureToTextureCopy,
|
UseTemporaryBufferInCompressedTextureToTextureCopy,
|
||||||
|
|
||||||
EnumCount,
|
EnumCount,
|
||||||
|
|
|
@ -24,8 +24,30 @@ namespace dawn_native { namespace vulkan {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
bool chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes,
|
||||||
|
bool turnOffVsync,
|
||||||
|
VkPresentModeKHR* presentMode) {
|
||||||
|
if (turnOffVsync) {
|
||||||
|
for (const auto& availablePresentMode : availablePresentModes) {
|
||||||
|
if (availablePresentMode == VK_PRESENT_MODE_IMMEDIATE_KHR) {
|
||||||
|
*presentMode = availablePresentMode;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ChooseSurfaceConfig(const VulkanSurfaceInfo& info,
|
bool ChooseSurfaceConfig(const VulkanSurfaceInfo& info,
|
||||||
NativeSwapChainImpl::ChosenConfig* config) {
|
NativeSwapChainImpl::ChosenConfig* config,
|
||||||
|
bool turnOffVsync) {
|
||||||
|
VkPresentModeKHR presentMode;
|
||||||
|
if (!chooseSwapPresentMode(info.presentModes, turnOffVsync, &presentMode)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// TODO(cwallez@chromium.org): For now this is hardcoded to what works with one NVIDIA
|
// TODO(cwallez@chromium.org): For now this is hardcoded to what works with one NVIDIA
|
||||||
// driver. Need to generalize
|
// driver. Need to generalize
|
||||||
config->nativeFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
config->nativeFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
||||||
|
@ -35,11 +57,11 @@ namespace dawn_native { namespace vulkan {
|
||||||
// TODO(cwallez@chromium.org): This is upside down compared to what we want, at least
|
// TODO(cwallez@chromium.org): This is upside down compared to what we want, at least
|
||||||
// on Linux
|
// on Linux
|
||||||
config->preTransform = info.capabilities.currentTransform;
|
config->preTransform = info.capabilities.currentTransform;
|
||||||
config->presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
config->presentMode = presentMode;
|
||||||
config->compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
config->compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
NativeSwapChainImpl::NativeSwapChainImpl(Device* device, VkSurfaceKHR surface)
|
NativeSwapChainImpl::NativeSwapChainImpl(Device* device, VkSurfaceKHR surface)
|
||||||
|
@ -63,7 +85,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ChooseSurfaceConfig(mInfo, &mConfig)) {
|
if (!ChooseSurfaceConfig(mInfo, &mConfig, mDevice->IsToggleEnabled(Toggle::TurnOffVsync))) {
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,4 +75,20 @@ TEST_F(ToggleValidationTest, OverrideToggleUsage) {
|
||||||
ASSERT_EQ(InvalidToggleExists, false);
|
ASSERT_EQ(InvalidToggleExists, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ToggleValidationTest, TurnOffVsyncWithToggle) {
|
||||||
|
const char* kValidToggleName = "turn_off_vsync";
|
||||||
|
dawn_native::DeviceDescriptor descriptor;
|
||||||
|
descriptor.forceEnabledToggles.push_back(kValidToggleName);
|
||||||
|
|
||||||
|
DawnDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
|
||||||
|
std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
|
||||||
|
bool validToggleExists = false;
|
||||||
|
for (const char* toggle : toggleNames) {
|
||||||
|
if (strcmp(toggle, kValidToggleName) == 0) {
|
||||||
|
validToggleExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ASSERT_EQ(validToggleExists, true);
|
||||||
|
}
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
Loading…
Reference in New Issue