import dataclasses
import functools
from typing import Any
from gpu_tests import common_browser_args as cba
from gpu_tests import common_typing as ct
from gpu_tests import pixel_test_pages
from gpu_tests.util import host_information
@functools.lru_cache(maxsize=None)
def _GetWebGpuCacheTestBrowserArgs() -> list[str]:
browser_args = [
cba.ENABLE_EXPERIMENTAL_WEB_PLATFORM_FEATURES,
'--enable-features=WebGPUBlobCache',
]
if host_information.IsLinux():
browser_args.append('--enable-features=Vulkan')
return browser_args
@dataclasses.dataclass
class WebGpuCacheTracingTest():
name: str
first_load_page: str
cache_pages: list[str]
browser_args: list[str] = dataclasses.field(
default_factory=_GetWebGpuCacheTestBrowserArgs)
@dataclasses.dataclass
class SimpleTracingTest:
name: str
url: str
browser_args: list[str] = ct.EmptyList()
other_args: dict[str, Any] = ct.EmptyDict()
class TraceTestPages(pixel_test_pages.PixelTestPages):
RENDER_CACHE_PAGES = [
'webgpu-caching.html?testId=render-test',
'webgpu-caching.html?testId=render-test-async',
'webgpu-caching.html?testId=render-test&worker=true',
'webgpu-caching.html?testId=render-test-async&worker=true',
]
COMPUTE_CACHE_PAGES = [
'webgpu-caching.html?testId=compute-test',
'webgpu-caching.html?testId=compute-test-async',
'webgpu-caching.html?testId=compute-test&worker=true',
'webgpu-caching.html?testId=compute-test-async&worker=true',
]
@staticmethod
def WebGpuLoadReloadCachingTests(prefix: str) -> list[WebGpuCacheTracingTest]:
return [
WebGpuCacheTracingTest(
name=f'{prefix}_RenderPipelineMainThread',
first_load_page='webgpu-caching.html?testId=render-test',
cache_pages=TraceTestPages.RENDER_CACHE_PAGES,
),
WebGpuCacheTracingTest(
name=f'{prefix}_RenderPipelineMainThreadAsync',
first_load_page='webgpu-caching.html?testId=render-test-async',
cache_pages=TraceTestPages.RENDER_CACHE_PAGES,
),
WebGpuCacheTracingTest(
name=f'{prefix}_RenderPipelineWorker',
first_load_page=('webgpu-caching.html?'
'testId=render-test&worker=true'),
cache_pages=TraceTestPages.RENDER_CACHE_PAGES),
WebGpuCacheTracingTest(
name=f'{prefix}_RenderPipelineWorkerAsync',
first_load_page=('webgpu-caching.html?'
'testId=render-test-async&worker=true'),
cache_pages=TraceTestPages.RENDER_CACHE_PAGES,
browser_args=_GetWebGpuCacheTestBrowserArgs(),
),
WebGpuCacheTracingTest(
name=f'{prefix}_RenderPipelineCrossOriginCacheHits',
first_load_page=('webgpu-caching.html?'
'testId=render-test&hostname=localhost'),
cache_pages=[
'webgpu-caching.html?testId=render-test&hostname=localhost',
('webgpu-caching.html?'
'testId=render-test-async&hostname=localhost'),
('webgpu-caching.html?'
'testId=render-test&worker=true&hostname=localhost'),
('webgpu-caching.html?'
'testId=render-test-async&worker=true&hostname=localhost'),
],
),
WebGpuCacheTracingTest(
name=f'{prefix}_ComputePipelineMainThread',
first_load_page='webgpu-caching.html?testId=compute-test',
cache_pages=TraceTestPages.COMPUTE_CACHE_PAGES,
),
WebGpuCacheTracingTest(
name=f'{prefix}_ComputePipelineMainThreadAsync',
first_load_page='webgpu-caching.html?testId=compute-test-async',
cache_pages=TraceTestPages.COMPUTE_CACHE_PAGES,
),
WebGpuCacheTracingTest(
name=f'{prefix}_ComputePipelineWorker',
first_load_page=('webgpu-caching.html?'
'testId=compute-test&worker=true'),
cache_pages=TraceTestPages.COMPUTE_CACHE_PAGES,
),
WebGpuCacheTracingTest(
name=f'{prefix}_ComputePipelineWorkerAsync',
first_load_page=('webgpu-caching.html?'
'testId=compute-test-async&worker=true'),
cache_pages=TraceTestPages.COMPUTE_CACHE_PAGES,
),
WebGpuCacheTracingTest(
name=f'{prefix}_ComputePipelineCrossOriginCacheHits',
first_load_page=('webgpu-caching.html?'
'testId=compute-test&hostname=localhost'),
cache_pages=[
'webgpu-caching.html?testId=compute-test&hostname=localhost',
('webgpu-caching.html?'
'testId=compute-test-async&hostname=localhost'),
('webgpu-caching.html?'
'testId=compute-test&worker=true&hostname=localhost'),
('webgpu-caching.html?'
'testId=compute-test-async&worker=true&hostname=localhost'),
],
),
]
@staticmethod
def WebGpuIncognitoCachingTests(prefix: str) -> list[WebGpuCacheTracingTest]:
return [
WebGpuCacheTracingTest(
name=f'{prefix}_RenderPipelineIncognito',
first_load_page='webgpu-caching.html?testId=render-test&runs=2',
cache_pages=TraceTestPages.RENDER_CACHE_PAGES,
browser_args=(_GetWebGpuCacheTestBrowserArgs() + ['--incognito']),
),
WebGpuCacheTracingTest(
name=f'{prefix}_ComputePipelineIncognito',
first_load_page='webgpu-caching.html?testId=compute-test&runs=2',
cache_pages=TraceTestPages.COMPUTE_CACHE_PAGES,
browser_args=(_GetWebGpuCacheTestBrowserArgs() + ['--incognito']),
),
]
@staticmethod
def WebGpuDifferentOriginCachingTests(
prefix: str) -> list[WebGpuCacheTracingTest]:
return [
WebGpuCacheTracingTest(
name=f'{prefix}_RenderPipelineDifferentOrigins',
first_load_page='webgpu-caching.html?testId=render-test',
cache_pages=TraceTestPages.RENDER_CACHE_PAGES,
),
WebGpuCacheTracingTest(
name=f'{prefix}_ComputePipelineDifferentOrigins',
first_load_page='webgpu-caching.html?testId=compute-test',
cache_pages=TraceTestPages.COMPUTE_CACHE_PAGES,
),
]
@staticmethod
def WebGpuCrossOriginCacheMissTests(
prefix: str) -> list[WebGpuCacheTracingTest]:
return [
WebGpuCacheTracingTest(
name=f'{prefix}_RenderPipelineCrossOriginsCacheMisses',
first_load_page=('webgpu-caching.html?'
'testId=render-test&hostname=localhost'),
cache_pages=TraceTestPages.RENDER_CACHE_PAGES,
),
WebGpuCacheTracingTest(
name=f'{prefix}_ComputePipelineCrossOriginsCacheMisses',
first_load_page=('webgpu-caching.html?'
'testId=compute-test&hostname=localhost'),
cache_pages=TraceTestPages.COMPUTE_CACHE_PAGES,
),
]
@staticmethod
def RootSwapChainTests(prefix: str) -> list[SimpleTracingTest]:
return [
SimpleTracingTest(name=f'{prefix}_IsOpaque',
url='wait_for_compositing.html',
other_args={
'has_alpha': False,
}),
]
@staticmethod
def MediaFoundationD3D11VideoCaptureTests(
prefix: str) -> list[SimpleTracingTest]:
return [
SimpleTracingTest(
name=f'{prefix}_MediaFoundationD3D11VideoCapture',
url='media_foundation_d3d11_video_capture.html',
browser_args=[
'--use-fake-ui-for-media-stream',
'--enable-features=MediaFoundationD3D11VideoCapture',
]),
]