gl_rasterizer.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include <array>
  6. #include <bitset>
  7. #include <memory>
  8. #include <string>
  9. #include <string_view>
  10. #include <tuple>
  11. #include <utility>
  12. #include <glad/glad.h>
  13. #include "common/assert.h"
  14. #include "common/logging/log.h"
  15. #include "common/math_util.h"
  16. #include "common/microprofile.h"
  17. #include "common/settings.h"
  18. #include "core/memory.h"
  19. #include "video_core/engines/kepler_compute.h"
  20. #include "video_core/engines/maxwell_3d.h"
  21. #include "video_core/memory_manager.h"
  22. #include "video_core/renderer_opengl/gl_device.h"
  23. #include "video_core/renderer_opengl/gl_query_cache.h"
  24. #include "video_core/renderer_opengl/gl_rasterizer.h"
  25. #include "video_core/renderer_opengl/gl_shader_cache.h"
  26. #include "video_core/renderer_opengl/gl_texture_cache.h"
  27. #include "video_core/renderer_opengl/maxwell_to_gl.h"
  28. #include "video_core/renderer_opengl/renderer_opengl.h"
  29. #include "video_core/shader_cache.h"
  30. #include "video_core/texture_cache/texture_cache_base.h"
  31. namespace OpenGL {
  32. using Maxwell = Tegra::Engines::Maxwell3D::Regs;
  33. using GLvec4 = std::array<GLfloat, 4>;
  34. using VideoCore::Surface::PixelFormat;
  35. using VideoCore::Surface::SurfaceTarget;
  36. using VideoCore::Surface::SurfaceType;
  37. MICROPROFILE_DEFINE(OpenGL_Drawing, "OpenGL", "Drawing", MP_RGB(128, 128, 192));
  38. MICROPROFILE_DEFINE(OpenGL_Clears, "OpenGL", "Clears", MP_RGB(128, 128, 192));
  39. MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(128, 128, 192));
  40. MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Management", MP_RGB(100, 255, 100));
  41. namespace {
  42. constexpr size_t NUM_SUPPORTED_VERTEX_ATTRIBUTES = 16;
  43. void oglEnable(GLenum cap, bool state) {
  44. (state ? glEnable : glDisable)(cap);
  45. }
  46. } // Anonymous namespace
  47. RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_,
  48. Core::Memory::Memory& cpu_memory_, const Device& device_,
  49. ScreenInfo& screen_info_, ProgramManager& program_manager_,
  50. StateTracker& state_tracker_)
  51. : RasterizerAccelerated(cpu_memory_), gpu(gpu_), maxwell3d(gpu.Maxwell3D()),
  52. kepler_compute(gpu.KeplerCompute()), gpu_memory(gpu.MemoryManager()), device(device_),
  53. screen_info(screen_info_), program_manager(program_manager_), state_tracker(state_tracker_),
  54. texture_cache_runtime(device, program_manager, state_tracker),
  55. texture_cache(texture_cache_runtime, *this, maxwell3d, kepler_compute, gpu_memory),
  56. buffer_cache_runtime(device),
  57. buffer_cache(*this, maxwell3d, kepler_compute, gpu_memory, cpu_memory_, buffer_cache_runtime),
  58. shader_cache(*this, emu_window_, maxwell3d, kepler_compute, gpu_memory, device, texture_cache,
  59. buffer_cache, program_manager, state_tracker, gpu.ShaderNotify()),
  60. query_cache(*this, maxwell3d, gpu_memory), accelerate_dma(buffer_cache),
  61. fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache) {}
  62. RasterizerOpenGL::~RasterizerOpenGL() = default;
  63. void RasterizerOpenGL::SyncVertexFormats() {
  64. auto& flags = maxwell3d.dirty.flags;
  65. if (!flags[Dirty::VertexFormats]) {
  66. return;
  67. }
  68. flags[Dirty::VertexFormats] = false;
  69. // Use the vertex array as-is, assumes that the data is formatted correctly for OpenGL. Enables
  70. // the first 16 vertex attributes always, as we don't know which ones are actually used until
  71. // shader time. Note, Tegra technically supports 32, but we're capping this to 16 for now to
  72. // avoid OpenGL errors.
  73. // TODO(Subv): Analyze the shader to identify which attributes are actually used and don't
  74. // assume every shader uses them all.
  75. for (std::size_t index = 0; index < NUM_SUPPORTED_VERTEX_ATTRIBUTES; ++index) {
  76. if (!flags[Dirty::VertexFormat0 + index]) {
  77. continue;
  78. }
  79. flags[Dirty::VertexFormat0 + index] = false;
  80. const auto attrib = maxwell3d.regs.vertex_attrib_format[index];
  81. const auto gl_index = static_cast<GLuint>(index);
  82. // Disable constant attributes.
  83. if (attrib.constant) {
  84. glDisableVertexAttribArray(gl_index);
  85. continue;
  86. }
  87. glEnableVertexAttribArray(gl_index);
  88. if (attrib.type == Maxwell::VertexAttribute::Type::SignedInt ||
  89. attrib.type == Maxwell::VertexAttribute::Type::UnsignedInt) {
  90. glVertexAttribIFormat(gl_index, attrib.ComponentCount(),
  91. MaxwellToGL::VertexFormat(attrib), attrib.offset);
  92. } else {
  93. glVertexAttribFormat(gl_index, attrib.ComponentCount(),
  94. MaxwellToGL::VertexFormat(attrib),
  95. attrib.IsNormalized() ? GL_TRUE : GL_FALSE, attrib.offset);
  96. }
  97. glVertexAttribBinding(gl_index, attrib.buffer);
  98. }
  99. }
  100. void RasterizerOpenGL::SyncVertexInstances() {
  101. auto& flags = maxwell3d.dirty.flags;
  102. if (!flags[Dirty::VertexInstances]) {
  103. return;
  104. }
  105. flags[Dirty::VertexInstances] = false;
  106. const auto& regs = maxwell3d.regs;
  107. for (std::size_t index = 0; index < NUM_SUPPORTED_VERTEX_ATTRIBUTES; ++index) {
  108. if (!flags[Dirty::VertexInstance0 + index]) {
  109. continue;
  110. }
  111. flags[Dirty::VertexInstance0 + index] = false;
  112. const auto gl_index = static_cast<GLuint>(index);
  113. const bool instancing_enabled = regs.instanced_arrays.IsInstancingEnabled(gl_index);
  114. const GLuint divisor = instancing_enabled ? regs.vertex_array[index].divisor : 0;
  115. glVertexBindingDivisor(gl_index, divisor);
  116. }
  117. }
  118. void RasterizerOpenGL::LoadDiskResources(u64 title_id, std::stop_token stop_loading,
  119. const VideoCore::DiskResourceLoadCallback& callback) {
  120. shader_cache.LoadDiskResources(title_id, stop_loading, callback);
  121. }
  122. void RasterizerOpenGL::Clear() {
  123. MICROPROFILE_SCOPE(OpenGL_Clears);
  124. if (!maxwell3d.ShouldExecute()) {
  125. return;
  126. }
  127. const auto& regs = maxwell3d.regs;
  128. bool use_color{};
  129. bool use_depth{};
  130. bool use_stencil{};
  131. if (regs.clear_buffers.R || regs.clear_buffers.G || regs.clear_buffers.B ||
  132. regs.clear_buffers.A) {
  133. use_color = true;
  134. const GLuint index = regs.clear_buffers.RT;
  135. state_tracker.NotifyColorMask(index);
  136. glColorMaski(index, regs.clear_buffers.R != 0, regs.clear_buffers.G != 0,
  137. regs.clear_buffers.B != 0, regs.clear_buffers.A != 0);
  138. // TODO(Rodrigo): Determine if clamping is used on clears
  139. SyncFragmentColorClampState();
  140. SyncFramebufferSRGB();
  141. }
  142. if (regs.clear_buffers.Z) {
  143. ASSERT_MSG(regs.zeta_enable != 0, "Tried to clear Z but buffer is not enabled!");
  144. use_depth = true;
  145. state_tracker.NotifyDepthMask();
  146. glDepthMask(GL_TRUE);
  147. }
  148. if (regs.clear_buffers.S) {
  149. ASSERT_MSG(regs.zeta_enable, "Tried to clear stencil but buffer is not enabled!");
  150. use_stencil = true;
  151. }
  152. if (!use_color && !use_depth && !use_stencil) {
  153. // No color surface nor depth/stencil surface are enabled
  154. return;
  155. }
  156. SyncRasterizeEnable();
  157. SyncStencilTestState();
  158. if (regs.clear_flags.scissor) {
  159. SyncScissorTest();
  160. } else {
  161. state_tracker.NotifyScissor0();
  162. glDisablei(GL_SCISSOR_TEST, 0);
  163. }
  164. UNIMPLEMENTED_IF(regs.clear_flags.viewport);
  165. std::scoped_lock lock{texture_cache.mutex};
  166. texture_cache.UpdateRenderTargets(true);
  167. state_tracker.BindFramebuffer(texture_cache.GetFramebuffer()->Handle());
  168. if (use_color) {
  169. glClearBufferfv(GL_COLOR, regs.clear_buffers.RT, regs.clear_color);
  170. }
  171. if (use_depth && use_stencil) {
  172. glClearBufferfi(GL_DEPTH_STENCIL, 0, regs.clear_depth, regs.clear_stencil);
  173. } else if (use_depth) {
  174. glClearBufferfv(GL_DEPTH, 0, &regs.clear_depth);
  175. } else if (use_stencil) {
  176. glClearBufferiv(GL_STENCIL, 0, &regs.clear_stencil);
  177. }
  178. ++num_queued_commands;
  179. }
  180. void RasterizerOpenGL::Draw(bool is_indexed, bool is_instanced) {
  181. MICROPROFILE_SCOPE(OpenGL_Drawing);
  182. query_cache.UpdateCounters();
  183. SyncState();
  184. GraphicsPipeline* const pipeline{shader_cache.CurrentGraphicsPipeline()};
  185. if (!pipeline) {
  186. return;
  187. }
  188. std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex};
  189. pipeline->Configure(is_indexed);
  190. const GLenum primitive_mode = MaxwellToGL::PrimitiveTopology(maxwell3d.regs.draw.topology);
  191. BeginTransformFeedback(pipeline, primitive_mode);
  192. const GLuint base_instance = static_cast<GLuint>(maxwell3d.regs.vb_base_instance);
  193. const GLsizei num_instances =
  194. static_cast<GLsizei>(is_instanced ? maxwell3d.mme_draw.instance_count : 1);
  195. if (is_indexed) {
  196. const GLint base_vertex = static_cast<GLint>(maxwell3d.regs.vb_element_base);
  197. const GLsizei num_vertices = static_cast<GLsizei>(maxwell3d.regs.index_array.count);
  198. const GLvoid* const offset = buffer_cache_runtime.IndexOffset();
  199. const GLenum format = MaxwellToGL::IndexFormat(maxwell3d.regs.index_array.format);
  200. if (num_instances == 1 && base_instance == 0 && base_vertex == 0) {
  201. glDrawElements(primitive_mode, num_vertices, format, offset);
  202. } else if (num_instances == 1 && base_instance == 0) {
  203. glDrawElementsBaseVertex(primitive_mode, num_vertices, format, offset, base_vertex);
  204. } else if (base_vertex == 0 && base_instance == 0) {
  205. glDrawElementsInstanced(primitive_mode, num_vertices, format, offset, num_instances);
  206. } else if (base_vertex == 0) {
  207. glDrawElementsInstancedBaseInstance(primitive_mode, num_vertices, format, offset,
  208. num_instances, base_instance);
  209. } else if (base_instance == 0) {
  210. glDrawElementsInstancedBaseVertex(primitive_mode, num_vertices, format, offset,
  211. num_instances, base_vertex);
  212. } else {
  213. glDrawElementsInstancedBaseVertexBaseInstance(primitive_mode, num_vertices, format,
  214. offset, num_instances, base_vertex,
  215. base_instance);
  216. }
  217. } else {
  218. const GLint base_vertex = static_cast<GLint>(maxwell3d.regs.vertex_buffer.first);
  219. const GLsizei num_vertices = static_cast<GLsizei>(maxwell3d.regs.vertex_buffer.count);
  220. if (num_instances == 1 && base_instance == 0) {
  221. glDrawArrays(primitive_mode, base_vertex, num_vertices);
  222. } else if (base_instance == 0) {
  223. glDrawArraysInstanced(primitive_mode, base_vertex, num_vertices, num_instances);
  224. } else {
  225. glDrawArraysInstancedBaseInstance(primitive_mode, base_vertex, num_vertices,
  226. num_instances, base_instance);
  227. }
  228. }
  229. EndTransformFeedback();
  230. ++num_queued_commands;
  231. has_written_global_memory |= pipeline->WritesGlobalMemory();
  232. gpu.TickWork();
  233. }
  234. void RasterizerOpenGL::DispatchCompute() {
  235. ComputePipeline* const pipeline{shader_cache.CurrentComputePipeline()};
  236. if (!pipeline) {
  237. return;
  238. }
  239. pipeline->Configure();
  240. const auto& qmd{kepler_compute.launch_description};
  241. glDispatchCompute(qmd.grid_dim_x, qmd.grid_dim_y, qmd.grid_dim_z);
  242. ++num_queued_commands;
  243. has_written_global_memory |= pipeline->WritesGlobalMemory();
  244. }
  245. void RasterizerOpenGL::ResetCounter(VideoCore::QueryType type) {
  246. query_cache.ResetCounter(type);
  247. }
  248. void RasterizerOpenGL::Query(GPUVAddr gpu_addr, VideoCore::QueryType type,
  249. std::optional<u64> timestamp) {
  250. query_cache.Query(gpu_addr, type, timestamp);
  251. }
  252. void RasterizerOpenGL::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr,
  253. u32 size) {
  254. std::scoped_lock lock{buffer_cache.mutex};
  255. buffer_cache.BindGraphicsUniformBuffer(stage, index, gpu_addr, size);
  256. }
  257. void RasterizerOpenGL::DisableGraphicsUniformBuffer(size_t stage, u32 index) {
  258. buffer_cache.DisableGraphicsUniformBuffer(stage, index);
  259. }
  260. void RasterizerOpenGL::FlushAll() {}
  261. void RasterizerOpenGL::FlushRegion(VAddr addr, u64 size) {
  262. MICROPROFILE_SCOPE(OpenGL_CacheManagement);
  263. if (addr == 0 || size == 0) {
  264. return;
  265. }
  266. {
  267. std::scoped_lock lock{texture_cache.mutex};
  268. texture_cache.DownloadMemory(addr, size);
  269. }
  270. {
  271. std::scoped_lock lock{buffer_cache.mutex};
  272. buffer_cache.DownloadMemory(addr, size);
  273. }
  274. query_cache.FlushRegion(addr, size);
  275. }
  276. bool RasterizerOpenGL::MustFlushRegion(VAddr addr, u64 size) {
  277. std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex};
  278. if (!Settings::IsGPULevelHigh()) {
  279. return buffer_cache.IsRegionGpuModified(addr, size);
  280. }
  281. return texture_cache.IsRegionGpuModified(addr, size) ||
  282. buffer_cache.IsRegionGpuModified(addr, size);
  283. }
  284. void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) {
  285. MICROPROFILE_SCOPE(OpenGL_CacheManagement);
  286. if (addr == 0 || size == 0) {
  287. return;
  288. }
  289. {
  290. std::scoped_lock lock{texture_cache.mutex};
  291. texture_cache.WriteMemory(addr, size);
  292. }
  293. {
  294. std::scoped_lock lock{buffer_cache.mutex};
  295. buffer_cache.WriteMemory(addr, size);
  296. }
  297. shader_cache.InvalidateRegion(addr, size);
  298. query_cache.InvalidateRegion(addr, size);
  299. }
  300. void RasterizerOpenGL::OnCPUWrite(VAddr addr, u64 size) {
  301. MICROPROFILE_SCOPE(OpenGL_CacheManagement);
  302. if (addr == 0 || size == 0) {
  303. return;
  304. }
  305. shader_cache.OnCPUWrite(addr, size);
  306. {
  307. std::scoped_lock lock{texture_cache.mutex};
  308. texture_cache.WriteMemory(addr, size);
  309. }
  310. {
  311. std::scoped_lock lock{buffer_cache.mutex};
  312. buffer_cache.CachedWriteMemory(addr, size);
  313. }
  314. }
  315. void RasterizerOpenGL::SyncGuestHost() {
  316. MICROPROFILE_SCOPE(OpenGL_CacheManagement);
  317. shader_cache.SyncGuestHost();
  318. {
  319. std::scoped_lock lock{buffer_cache.mutex};
  320. buffer_cache.FlushCachedWrites();
  321. }
  322. }
  323. void RasterizerOpenGL::UnmapMemory(VAddr addr, u64 size) {
  324. {
  325. std::scoped_lock lock{texture_cache.mutex};
  326. texture_cache.UnmapMemory(addr, size);
  327. }
  328. {
  329. std::scoped_lock lock{buffer_cache.mutex};
  330. buffer_cache.WriteMemory(addr, size);
  331. }
  332. shader_cache.OnCPUWrite(addr, size);
  333. }
  334. void RasterizerOpenGL::ModifyGPUMemory(GPUVAddr addr, u64 size) {
  335. {
  336. std::scoped_lock lock{texture_cache.mutex};
  337. texture_cache.UnmapGPUMemory(addr, size);
  338. }
  339. }
  340. void RasterizerOpenGL::SignalSemaphore(GPUVAddr addr, u32 value) {
  341. if (!gpu.IsAsync()) {
  342. gpu_memory.Write<u32>(addr, value);
  343. return;
  344. }
  345. fence_manager.SignalSemaphore(addr, value);
  346. }
  347. void RasterizerOpenGL::SignalSyncPoint(u32 value) {
  348. if (!gpu.IsAsync()) {
  349. gpu.IncrementSyncPoint(value);
  350. return;
  351. }
  352. fence_manager.SignalSyncPoint(value);
  353. }
  354. void RasterizerOpenGL::SignalReference() {
  355. if (!gpu.IsAsync()) {
  356. return;
  357. }
  358. fence_manager.SignalOrdering();
  359. }
  360. void RasterizerOpenGL::ReleaseFences() {
  361. if (!gpu.IsAsync()) {
  362. return;
  363. }
  364. fence_manager.WaitPendingFences();
  365. }
  366. void RasterizerOpenGL::FlushAndInvalidateRegion(VAddr addr, u64 size) {
  367. if (Settings::IsGPULevelExtreme()) {
  368. FlushRegion(addr, size);
  369. }
  370. InvalidateRegion(addr, size);
  371. }
  372. void RasterizerOpenGL::WaitForIdle() {
  373. glMemoryBarrier(GL_ALL_BARRIER_BITS);
  374. SignalReference();
  375. }
  376. void RasterizerOpenGL::FragmentBarrier() {
  377. glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT | GL_TEXTURE_FETCH_BARRIER_BIT);
  378. }
  379. void RasterizerOpenGL::TiledCacheBarrier() {
  380. glTextureBarrier();
  381. }
  382. void RasterizerOpenGL::FlushCommands() {
  383. // Only flush when we have commands queued to OpenGL.
  384. if (num_queued_commands == 0) {
  385. return;
  386. }
  387. num_queued_commands = 0;
  388. // Make sure memory stored from the previous GL command stream is visible
  389. // This is only needed on assembly shaders where we write to GPU memory with raw pointers
  390. if (has_written_global_memory) {
  391. has_written_global_memory = false;
  392. glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
  393. }
  394. glFlush();
  395. }
  396. void RasterizerOpenGL::TickFrame() {
  397. // Ticking a frame means that buffers will be swapped, calling glFlush implicitly.
  398. num_queued_commands = 0;
  399. fence_manager.TickFrame();
  400. {
  401. std::scoped_lock lock{texture_cache.mutex};
  402. texture_cache.TickFrame();
  403. }
  404. {
  405. std::scoped_lock lock{buffer_cache.mutex};
  406. buffer_cache.TickFrame();
  407. }
  408. }
  409. bool RasterizerOpenGL::AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
  410. const Tegra::Engines::Fermi2D::Surface& dst,
  411. const Tegra::Engines::Fermi2D::Config& copy_config) {
  412. MICROPROFILE_SCOPE(OpenGL_Blits);
  413. std::scoped_lock lock{texture_cache.mutex};
  414. texture_cache.BlitImage(dst, src, copy_config);
  415. return true;
  416. }
  417. Tegra::Engines::AccelerateDMAInterface& RasterizerOpenGL::AccessAccelerateDMA() {
  418. return accelerate_dma;
  419. }
  420. bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
  421. VAddr framebuffer_addr, u32 pixel_stride) {
  422. if (framebuffer_addr == 0) {
  423. return false;
  424. }
  425. MICROPROFILE_SCOPE(OpenGL_CacheManagement);
  426. std::scoped_lock lock{texture_cache.mutex};
  427. ImageView* const image_view{texture_cache.TryFindFramebufferImageView(framebuffer_addr)};
  428. if (!image_view) {
  429. return false;
  430. }
  431. // Verify that the cached surface is the same size and format as the requested framebuffer
  432. // ASSERT_MSG(image_view->size.width == config.width, "Framebuffer width is different");
  433. // ASSERT_MSG(image_view->size.height == config.height, "Framebuffer height is different");
  434. screen_info.display_texture = image_view->Handle(Shader::TextureType::Color2D);
  435. screen_info.display_srgb = VideoCore::Surface::IsPixelFormatSRGB(image_view->format);
  436. return true;
  437. }
  438. void RasterizerOpenGL::SyncState() {
  439. SyncViewport();
  440. SyncRasterizeEnable();
  441. SyncPolygonModes();
  442. SyncColorMask();
  443. SyncFragmentColorClampState();
  444. SyncMultiSampleState();
  445. SyncDepthTestState();
  446. SyncDepthClamp();
  447. SyncStencilTestState();
  448. SyncBlendState();
  449. SyncLogicOpState();
  450. SyncCullMode();
  451. SyncPrimitiveRestart();
  452. SyncScissorTest();
  453. SyncPointState();
  454. SyncLineState();
  455. SyncPolygonOffset();
  456. SyncAlphaTest();
  457. SyncFramebufferSRGB();
  458. SyncVertexFormats();
  459. SyncVertexInstances();
  460. }
  461. void RasterizerOpenGL::SyncViewport() {
  462. auto& flags = maxwell3d.dirty.flags;
  463. const auto& regs = maxwell3d.regs;
  464. const bool rescale_viewports = flags[VideoCommon::Dirty::RescaleViewports];
  465. const bool dirty_viewport = flags[Dirty::Viewports] || rescale_viewports;
  466. const bool dirty_clip_control = flags[Dirty::ClipControl];
  467. if (dirty_clip_control || flags[Dirty::FrontFace]) {
  468. flags[Dirty::FrontFace] = false;
  469. GLenum mode = MaxwellToGL::FrontFace(regs.front_face);
  470. if (regs.screen_y_control.triangle_rast_flip != 0 &&
  471. regs.viewport_transform[0].scale_y < 0.0f) {
  472. switch (mode) {
  473. case GL_CW:
  474. mode = GL_CCW;
  475. break;
  476. case GL_CCW:
  477. mode = GL_CW;
  478. break;
  479. }
  480. }
  481. glFrontFace(mode);
  482. }
  483. if (dirty_viewport || flags[Dirty::ClipControl]) {
  484. flags[Dirty::ClipControl] = false;
  485. bool flip_y = false;
  486. if (regs.viewport_transform[0].scale_y < 0.0f) {
  487. flip_y = !flip_y;
  488. }
  489. if (regs.screen_y_control.y_negate != 0) {
  490. flip_y = !flip_y;
  491. }
  492. const bool is_zero_to_one = regs.depth_mode == Maxwell::DepthMode::ZeroToOne;
  493. const GLenum origin = flip_y ? GL_UPPER_LEFT : GL_LOWER_LEFT;
  494. const GLenum depth = is_zero_to_one ? GL_ZERO_TO_ONE : GL_NEGATIVE_ONE_TO_ONE;
  495. state_tracker.ClipControl(origin, depth);
  496. state_tracker.SetYNegate(regs.screen_y_control.y_negate != 0);
  497. }
  498. if (dirty_viewport) {
  499. flags[Dirty::Viewports] = false;
  500. const bool force = flags[Dirty::ViewportTransform] || rescale_viewports;
  501. flags[Dirty::ViewportTransform] = false;
  502. flags[VideoCommon::Dirty::RescaleViewports] = false;
  503. const auto& resolution = Settings::values.resolution_info;
  504. const auto scale_up = [&](u32 value) -> u32 {
  505. if (value == 0) {
  506. return 0U;
  507. }
  508. const u32 converted_value = (value * resolution.up_scale) >> resolution.down_shift;
  509. return std::max<u32>(converted_value, 1U);
  510. };
  511. for (std::size_t i = 0; i < Maxwell::NumViewports; ++i) {
  512. if (!force && !flags[Dirty::Viewport0 + i]) {
  513. continue;
  514. }
  515. flags[Dirty::Viewport0 + i] = false;
  516. const auto& src = regs.viewport_transform[i];
  517. const Common::Rectangle<f32> rect{src.GetRect()};
  518. glViewportIndexedf(static_cast<GLuint>(i), rect.left, rect.bottom,
  519. scale_up(rect.GetWidth()), scale_up(rect.GetHeight()));
  520. const GLdouble reduce_z = regs.depth_mode == Maxwell::DepthMode::MinusOneToOne;
  521. const GLdouble near_depth = src.translate_z - src.scale_z * reduce_z;
  522. const GLdouble far_depth = src.translate_z + src.scale_z;
  523. if (device.HasDepthBufferFloat()) {
  524. glDepthRangeIndexeddNV(static_cast<GLuint>(i), near_depth, far_depth);
  525. } else {
  526. glDepthRangeIndexed(static_cast<GLuint>(i), near_depth, far_depth);
  527. }
  528. if (!GLAD_GL_NV_viewport_swizzle) {
  529. continue;
  530. }
  531. glViewportSwizzleNV(static_cast<GLuint>(i), MaxwellToGL::ViewportSwizzle(src.swizzle.x),
  532. MaxwellToGL::ViewportSwizzle(src.swizzle.y),
  533. MaxwellToGL::ViewportSwizzle(src.swizzle.z),
  534. MaxwellToGL::ViewportSwizzle(src.swizzle.w));
  535. }
  536. }
  537. }
  538. void RasterizerOpenGL::SyncDepthClamp() {
  539. auto& flags = maxwell3d.dirty.flags;
  540. if (!flags[Dirty::DepthClampEnabled]) {
  541. return;
  542. }
  543. flags[Dirty::DepthClampEnabled] = false;
  544. oglEnable(GL_DEPTH_CLAMP, maxwell3d.regs.view_volume_clip_control.depth_clamp_disabled == 0);
  545. }
  546. void RasterizerOpenGL::SyncClipEnabled(u32 clip_mask) {
  547. auto& flags = maxwell3d.dirty.flags;
  548. if (!flags[Dirty::ClipDistances] && !flags[VideoCommon::Dirty::Shaders]) {
  549. return;
  550. }
  551. flags[Dirty::ClipDistances] = false;
  552. clip_mask &= maxwell3d.regs.clip_distance_enabled;
  553. if (clip_mask == last_clip_distance_mask) {
  554. return;
  555. }
  556. last_clip_distance_mask = clip_mask;
  557. for (std::size_t i = 0; i < Maxwell::Regs::NumClipDistances; ++i) {
  558. oglEnable(static_cast<GLenum>(GL_CLIP_DISTANCE0 + i), (clip_mask >> i) & 1);
  559. }
  560. }
  561. void RasterizerOpenGL::SyncClipCoef() {
  562. UNIMPLEMENTED();
  563. }
  564. void RasterizerOpenGL::SyncCullMode() {
  565. auto& flags = maxwell3d.dirty.flags;
  566. const auto& regs = maxwell3d.regs;
  567. if (flags[Dirty::CullTest]) {
  568. flags[Dirty::CullTest] = false;
  569. if (regs.cull_test_enabled) {
  570. glEnable(GL_CULL_FACE);
  571. glCullFace(MaxwellToGL::CullFace(regs.cull_face));
  572. } else {
  573. glDisable(GL_CULL_FACE);
  574. }
  575. }
  576. }
  577. void RasterizerOpenGL::SyncPrimitiveRestart() {
  578. auto& flags = maxwell3d.dirty.flags;
  579. if (!flags[Dirty::PrimitiveRestart]) {
  580. return;
  581. }
  582. flags[Dirty::PrimitiveRestart] = false;
  583. if (maxwell3d.regs.primitive_restart.enabled) {
  584. glEnable(GL_PRIMITIVE_RESTART);
  585. glPrimitiveRestartIndex(maxwell3d.regs.primitive_restart.index);
  586. } else {
  587. glDisable(GL_PRIMITIVE_RESTART);
  588. }
  589. }
  590. void RasterizerOpenGL::SyncDepthTestState() {
  591. auto& flags = maxwell3d.dirty.flags;
  592. const auto& regs = maxwell3d.regs;
  593. if (flags[Dirty::DepthMask]) {
  594. flags[Dirty::DepthMask] = false;
  595. glDepthMask(regs.depth_write_enabled ? GL_TRUE : GL_FALSE);
  596. }
  597. if (flags[Dirty::DepthTest]) {
  598. flags[Dirty::DepthTest] = false;
  599. if (regs.depth_test_enable) {
  600. glEnable(GL_DEPTH_TEST);
  601. glDepthFunc(MaxwellToGL::ComparisonOp(regs.depth_test_func));
  602. } else {
  603. glDisable(GL_DEPTH_TEST);
  604. }
  605. }
  606. }
  607. void RasterizerOpenGL::SyncStencilTestState() {
  608. auto& flags = maxwell3d.dirty.flags;
  609. if (!flags[Dirty::StencilTest]) {
  610. return;
  611. }
  612. flags[Dirty::StencilTest] = false;
  613. const auto& regs = maxwell3d.regs;
  614. oglEnable(GL_STENCIL_TEST, regs.stencil_enable);
  615. glStencilFuncSeparate(GL_FRONT, MaxwellToGL::ComparisonOp(regs.stencil_front_func_func),
  616. regs.stencil_front_func_ref, regs.stencil_front_func_mask);
  617. glStencilOpSeparate(GL_FRONT, MaxwellToGL::StencilOp(regs.stencil_front_op_fail),
  618. MaxwellToGL::StencilOp(regs.stencil_front_op_zfail),
  619. MaxwellToGL::StencilOp(regs.stencil_front_op_zpass));
  620. glStencilMaskSeparate(GL_FRONT, regs.stencil_front_mask);
  621. if (regs.stencil_two_side_enable) {
  622. glStencilFuncSeparate(GL_BACK, MaxwellToGL::ComparisonOp(regs.stencil_back_func_func),
  623. regs.stencil_back_func_ref, regs.stencil_back_func_mask);
  624. glStencilOpSeparate(GL_BACK, MaxwellToGL::StencilOp(regs.stencil_back_op_fail),
  625. MaxwellToGL::StencilOp(regs.stencil_back_op_zfail),
  626. MaxwellToGL::StencilOp(regs.stencil_back_op_zpass));
  627. glStencilMaskSeparate(GL_BACK, regs.stencil_back_mask);
  628. } else {
  629. glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 0xFFFFFFFF);
  630. glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP);
  631. glStencilMaskSeparate(GL_BACK, 0xFFFFFFFF);
  632. }
  633. }
  634. void RasterizerOpenGL::SyncRasterizeEnable() {
  635. auto& flags = maxwell3d.dirty.flags;
  636. if (!flags[Dirty::RasterizeEnable]) {
  637. return;
  638. }
  639. flags[Dirty::RasterizeEnable] = false;
  640. oglEnable(GL_RASTERIZER_DISCARD, maxwell3d.regs.rasterize_enable == 0);
  641. }
  642. void RasterizerOpenGL::SyncPolygonModes() {
  643. auto& flags = maxwell3d.dirty.flags;
  644. if (!flags[Dirty::PolygonModes]) {
  645. return;
  646. }
  647. flags[Dirty::PolygonModes] = false;
  648. const auto& regs = maxwell3d.regs;
  649. if (regs.fill_rectangle) {
  650. if (!GLAD_GL_NV_fill_rectangle) {
  651. LOG_ERROR(Render_OpenGL, "GL_NV_fill_rectangle used and not supported");
  652. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  653. return;
  654. }
  655. flags[Dirty::PolygonModeFront] = true;
  656. flags[Dirty::PolygonModeBack] = true;
  657. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL_RECTANGLE_NV);
  658. return;
  659. }
  660. if (regs.polygon_mode_front == regs.polygon_mode_back) {
  661. flags[Dirty::PolygonModeFront] = false;
  662. flags[Dirty::PolygonModeBack] = false;
  663. glPolygonMode(GL_FRONT_AND_BACK, MaxwellToGL::PolygonMode(regs.polygon_mode_front));
  664. return;
  665. }
  666. if (flags[Dirty::PolygonModeFront]) {
  667. flags[Dirty::PolygonModeFront] = false;
  668. glPolygonMode(GL_FRONT, MaxwellToGL::PolygonMode(regs.polygon_mode_front));
  669. }
  670. if (flags[Dirty::PolygonModeBack]) {
  671. flags[Dirty::PolygonModeBack] = false;
  672. glPolygonMode(GL_BACK, MaxwellToGL::PolygonMode(regs.polygon_mode_back));
  673. }
  674. }
  675. void RasterizerOpenGL::SyncColorMask() {
  676. auto& flags = maxwell3d.dirty.flags;
  677. if (!flags[Dirty::ColorMasks]) {
  678. return;
  679. }
  680. flags[Dirty::ColorMasks] = false;
  681. const bool force = flags[Dirty::ColorMaskCommon];
  682. flags[Dirty::ColorMaskCommon] = false;
  683. const auto& regs = maxwell3d.regs;
  684. if (regs.color_mask_common) {
  685. if (!force && !flags[Dirty::ColorMask0]) {
  686. return;
  687. }
  688. flags[Dirty::ColorMask0] = false;
  689. auto& mask = regs.color_mask[0];
  690. glColorMask(mask.R != 0, mask.B != 0, mask.G != 0, mask.A != 0);
  691. return;
  692. }
  693. // Path without color_mask_common set
  694. for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) {
  695. if (!force && !flags[Dirty::ColorMask0 + i]) {
  696. continue;
  697. }
  698. flags[Dirty::ColorMask0 + i] = false;
  699. const auto& mask = regs.color_mask[i];
  700. glColorMaski(static_cast<GLuint>(i), mask.R != 0, mask.G != 0, mask.B != 0, mask.A != 0);
  701. }
  702. }
  703. void RasterizerOpenGL::SyncMultiSampleState() {
  704. auto& flags = maxwell3d.dirty.flags;
  705. if (!flags[Dirty::MultisampleControl]) {
  706. return;
  707. }
  708. flags[Dirty::MultisampleControl] = false;
  709. const auto& regs = maxwell3d.regs;
  710. oglEnable(GL_SAMPLE_ALPHA_TO_COVERAGE, regs.multisample_control.alpha_to_coverage);
  711. oglEnable(GL_SAMPLE_ALPHA_TO_ONE, regs.multisample_control.alpha_to_one);
  712. }
  713. void RasterizerOpenGL::SyncFragmentColorClampState() {
  714. auto& flags = maxwell3d.dirty.flags;
  715. if (!flags[Dirty::FragmentClampColor]) {
  716. return;
  717. }
  718. flags[Dirty::FragmentClampColor] = false;
  719. glClampColor(GL_CLAMP_FRAGMENT_COLOR, maxwell3d.regs.frag_color_clamp ? GL_TRUE : GL_FALSE);
  720. }
  721. void RasterizerOpenGL::SyncBlendState() {
  722. auto& flags = maxwell3d.dirty.flags;
  723. const auto& regs = maxwell3d.regs;
  724. if (flags[Dirty::BlendColor]) {
  725. flags[Dirty::BlendColor] = false;
  726. glBlendColor(regs.blend_color.r, regs.blend_color.g, regs.blend_color.b,
  727. regs.blend_color.a);
  728. }
  729. // TODO(Rodrigo): Revisit blending, there are several registers we are not reading
  730. if (!flags[Dirty::BlendStates]) {
  731. return;
  732. }
  733. flags[Dirty::BlendStates] = false;
  734. if (!regs.independent_blend_enable) {
  735. if (!regs.blend.enable[0]) {
  736. glDisable(GL_BLEND);
  737. return;
  738. }
  739. glEnable(GL_BLEND);
  740. glBlendFuncSeparate(MaxwellToGL::BlendFunc(regs.blend.factor_source_rgb),
  741. MaxwellToGL::BlendFunc(regs.blend.factor_dest_rgb),
  742. MaxwellToGL::BlendFunc(regs.blend.factor_source_a),
  743. MaxwellToGL::BlendFunc(regs.blend.factor_dest_a));
  744. glBlendEquationSeparate(MaxwellToGL::BlendEquation(regs.blend.equation_rgb),
  745. MaxwellToGL::BlendEquation(regs.blend.equation_a));
  746. return;
  747. }
  748. const bool force = flags[Dirty::BlendIndependentEnabled];
  749. flags[Dirty::BlendIndependentEnabled] = false;
  750. for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) {
  751. if (!force && !flags[Dirty::BlendState0 + i]) {
  752. continue;
  753. }
  754. flags[Dirty::BlendState0 + i] = false;
  755. if (!regs.blend.enable[i]) {
  756. glDisablei(GL_BLEND, static_cast<GLuint>(i));
  757. continue;
  758. }
  759. glEnablei(GL_BLEND, static_cast<GLuint>(i));
  760. const auto& src = regs.independent_blend[i];
  761. glBlendFuncSeparatei(static_cast<GLuint>(i), MaxwellToGL::BlendFunc(src.factor_source_rgb),
  762. MaxwellToGL::BlendFunc(src.factor_dest_rgb),
  763. MaxwellToGL::BlendFunc(src.factor_source_a),
  764. MaxwellToGL::BlendFunc(src.factor_dest_a));
  765. glBlendEquationSeparatei(static_cast<GLuint>(i),
  766. MaxwellToGL::BlendEquation(src.equation_rgb),
  767. MaxwellToGL::BlendEquation(src.equation_a));
  768. }
  769. }
  770. void RasterizerOpenGL::SyncLogicOpState() {
  771. auto& flags = maxwell3d.dirty.flags;
  772. if (!flags[Dirty::LogicOp]) {
  773. return;
  774. }
  775. flags[Dirty::LogicOp] = false;
  776. const auto& regs = maxwell3d.regs;
  777. if (regs.logic_op.enable) {
  778. glEnable(GL_COLOR_LOGIC_OP);
  779. glLogicOp(MaxwellToGL::LogicOp(regs.logic_op.operation));
  780. } else {
  781. glDisable(GL_COLOR_LOGIC_OP);
  782. }
  783. }
  784. void RasterizerOpenGL::SyncScissorTest() {
  785. auto& flags = maxwell3d.dirty.flags;
  786. if (!flags[Dirty::Scissors] && !flags[VideoCommon::Dirty::RescaleScissors]) {
  787. return;
  788. }
  789. flags[Dirty::Scissors] = false;
  790. const bool force = flags[VideoCommon::Dirty::RescaleScissors];
  791. flags[VideoCommon::Dirty::RescaleScissors] = false;
  792. const auto& regs = maxwell3d.regs;
  793. const auto& resolution = Settings::values.resolution_info;
  794. const auto scale_up = [&](u32 value) -> u32 {
  795. if (value == 0) {
  796. return 0U;
  797. }
  798. const u32 converted_value = (value * resolution.up_scale) >> resolution.down_shift;
  799. return std::max<u32>(converted_value, 1U);
  800. };
  801. for (std::size_t index = 0; index < Maxwell::NumViewports; ++index) {
  802. if (!force && !flags[Dirty::Scissor0 + index]) {
  803. continue;
  804. }
  805. flags[Dirty::Scissor0 + index] = false;
  806. const auto& src = regs.scissor_test[index];
  807. if (src.enable) {
  808. glEnablei(GL_SCISSOR_TEST, static_cast<GLuint>(index));
  809. glScissorIndexed(static_cast<GLuint>(index), src.min_x, src.min_y,
  810. scale_up(src.max_x - src.min_x), scale_up(src.max_y - src.min_y));
  811. } else {
  812. glDisablei(GL_SCISSOR_TEST, static_cast<GLuint>(index));
  813. }
  814. }
  815. }
  816. void RasterizerOpenGL::SyncPointState() {
  817. auto& flags = maxwell3d.dirty.flags;
  818. if (!flags[Dirty::PointSize]) {
  819. return;
  820. }
  821. flags[Dirty::PointSize] = false;
  822. oglEnable(GL_POINT_SPRITE, maxwell3d.regs.point_sprite_enable);
  823. oglEnable(GL_PROGRAM_POINT_SIZE, maxwell3d.regs.vp_point_size.enable);
  824. glPointSize(std::max(1.0f, maxwell3d.regs.point_size));
  825. }
  826. void RasterizerOpenGL::SyncLineState() {
  827. auto& flags = maxwell3d.dirty.flags;
  828. if (!flags[Dirty::LineWidth]) {
  829. return;
  830. }
  831. flags[Dirty::LineWidth] = false;
  832. const auto& regs = maxwell3d.regs;
  833. oglEnable(GL_LINE_SMOOTH, regs.line_smooth_enable);
  834. glLineWidth(regs.line_smooth_enable ? regs.line_width_smooth : regs.line_width_aliased);
  835. }
  836. void RasterizerOpenGL::SyncPolygonOffset() {
  837. auto& flags = maxwell3d.dirty.flags;
  838. if (!flags[Dirty::PolygonOffset]) {
  839. return;
  840. }
  841. flags[Dirty::PolygonOffset] = false;
  842. const auto& regs = maxwell3d.regs;
  843. oglEnable(GL_POLYGON_OFFSET_FILL, regs.polygon_offset_fill_enable);
  844. oglEnable(GL_POLYGON_OFFSET_LINE, regs.polygon_offset_line_enable);
  845. oglEnable(GL_POLYGON_OFFSET_POINT, regs.polygon_offset_point_enable);
  846. if (regs.polygon_offset_fill_enable || regs.polygon_offset_line_enable ||
  847. regs.polygon_offset_point_enable) {
  848. // Hardware divides polygon offset units by two
  849. glPolygonOffsetClamp(regs.polygon_offset_factor, regs.polygon_offset_units / 2.0f,
  850. regs.polygon_offset_clamp);
  851. }
  852. }
  853. void RasterizerOpenGL::SyncAlphaTest() {
  854. auto& flags = maxwell3d.dirty.flags;
  855. if (!flags[Dirty::AlphaTest]) {
  856. return;
  857. }
  858. flags[Dirty::AlphaTest] = false;
  859. const auto& regs = maxwell3d.regs;
  860. if (regs.alpha_test_enabled) {
  861. glEnable(GL_ALPHA_TEST);
  862. glAlphaFunc(MaxwellToGL::ComparisonOp(regs.alpha_test_func), regs.alpha_test_ref);
  863. } else {
  864. glDisable(GL_ALPHA_TEST);
  865. }
  866. }
  867. void RasterizerOpenGL::SyncFramebufferSRGB() {
  868. auto& flags = maxwell3d.dirty.flags;
  869. if (!flags[Dirty::FramebufferSRGB]) {
  870. return;
  871. }
  872. flags[Dirty::FramebufferSRGB] = false;
  873. oglEnable(GL_FRAMEBUFFER_SRGB, maxwell3d.regs.framebuffer_srgb);
  874. }
  875. void RasterizerOpenGL::BeginTransformFeedback(GraphicsPipeline* program, GLenum primitive_mode) {
  876. const auto& regs = maxwell3d.regs;
  877. if (regs.tfb_enabled == 0) {
  878. return;
  879. }
  880. program->ConfigureTransformFeedback();
  881. UNIMPLEMENTED_IF(regs.IsShaderConfigEnabled(Maxwell::ShaderProgram::TesselationControl) ||
  882. regs.IsShaderConfigEnabled(Maxwell::ShaderProgram::TesselationEval) ||
  883. regs.IsShaderConfigEnabled(Maxwell::ShaderProgram::Geometry));
  884. UNIMPLEMENTED_IF(primitive_mode != GL_POINTS);
  885. // We may have to call BeginTransformFeedbackNV here since they seem to call different
  886. // implementations on Nvidia's driver (the pointer is different) but we are using
  887. // ARB_transform_feedback3 features with NV_transform_feedback interactions and the ARB
  888. // extension doesn't define BeginTransformFeedback (without NV) interactions. It just works.
  889. glBeginTransformFeedback(GL_POINTS);
  890. }
  891. void RasterizerOpenGL::EndTransformFeedback() {
  892. if (maxwell3d.regs.tfb_enabled != 0) {
  893. glEndTransformFeedback();
  894. }
  895. }
  896. AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_) : buffer_cache{buffer_cache_} {}
  897. bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) {
  898. std::scoped_lock lock{buffer_cache.mutex};
  899. return buffer_cache.DMACopy(src_address, dest_address, amount);
  900. }
  901. bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) {
  902. std::scoped_lock lock{buffer_cache.mutex};
  903. return buffer_cache.DMAClear(src_address, amount, value);
  904. }
  905. } // namespace OpenGL