webgpu_test.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GPU_COMMAND_BUFFER_TESTS_WEBGPU_TEST_H_
  5. #define GPU_COMMAND_BUFFER_TESTS_WEBGPU_TEST_H_
  6. #include <dawn/webgpu_cpp.h>
  7. #include <memory>
  8. #include "build/build_config.h"
  9. #include "gpu/command_buffer/client/shared_memory_limits.h"
  10. #include "gpu/command_buffer/common/webgpu_cmd_ids.h"
  11. #include "testing/gtest/include/gtest/gtest.h"
  12. #if BUILDFLAG(IS_MAC)
  13. #include "gpu/ipc/service/gpu_memory_buffer_factory_io_surface.h"
  14. #endif
  15. namespace viz {
  16. class TestGpuServiceHolder;
  17. }
  18. namespace gpu {
  19. class SharedImageInterface;
  20. class WebGPUInProcessContext;
  21. namespace webgpu {
  22. class WebGPUCmdHelper;
  23. class WebGPUDecoder;
  24. class WebGPUImplementation;
  25. } // namespace webgpu
  26. class WebGPUTest : public testing::Test {
  27. public:
  28. struct Options {
  29. Options();
  30. // Shared memory limits
  31. SharedMemoryLimits shared_memory_limits =
  32. SharedMemoryLimits::ForWebGPUContext();
  33. bool force_fallback_adapter = false;
  34. bool enable_unsafe_webgpu = false;
  35. };
  36. protected:
  37. WebGPUTest();
  38. ~WebGPUTest() override;
  39. bool WebGPUSupported() const;
  40. bool WebGPUSharedImageSupported() const;
  41. void SetUp() override;
  42. void TearDown() override;
  43. void Initialize(const Options& options);
  44. webgpu::WebGPUImplementation* webgpu() const;
  45. webgpu::WebGPUCmdHelper* webgpu_cmds() const;
  46. SharedImageInterface* GetSharedImageInterface() const;
  47. webgpu::WebGPUDecoder* GetDecoder() const;
  48. void RunPendingTasks();
  49. void WaitForCompletion(wgpu::Device device);
  50. wgpu::Device GetNewDevice();
  51. viz::TestGpuServiceHolder* GetGpuServiceHolder() {
  52. return gpu_service_holder_.get();
  53. }
  54. wgpu::Instance instance_ = nullptr;
  55. wgpu::Adapter adapter_ = nullptr;
  56. private:
  57. std::unique_ptr<viz::TestGpuServiceHolder> gpu_service_holder_;
  58. std::unique_ptr<WebGPUInProcessContext> context_;
  59. std::unique_ptr<webgpu::WebGPUCmdHelper> cmd_helper_;
  60. #if BUILDFLAG(IS_MAC)
  61. // SharedImages on macOS require a valid image factory.
  62. GpuMemoryBufferFactoryIOSurface image_factory_;
  63. #endif
  64. };
  65. } // namespace gpu
  66. #endif // GPU_COMMAND_BUFFER_TESTS_WEBGPU_TEST_H_