Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2018 The Dawn Authors |
Corentin Wallez | a714f5b | 2018-06-18 17:52:55 -0400 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Corentin Wallez | d37523f | 2018-07-24 13:53:51 +0200 | [diff] [blame] | 15 | #include "dawn_native/opengl/QueueGL.h" |
Corentin Wallez | a714f5b | 2018-06-18 17:52:55 -0400 | [diff] [blame] | 16 | |
Corentin Wallez | 47a3341 | 2020-06-02 09:24:39 +0000 | [diff] [blame] | 17 | #include "dawn_native/opengl/BufferGL.h" |
Corentin Wallez | d37523f | 2018-07-24 13:53:51 +0200 | [diff] [blame] | 18 | #include "dawn_native/opengl/CommandBufferGL.h" |
| 19 | #include "dawn_native/opengl/DeviceGL.h" |
Stephen White | 988f3da | 2021-01-25 18:16:48 +0000 | [diff] [blame] | 20 | #include "dawn_native/opengl/TextureGL.h" |
Austin Eng | 73d5bb5 | 2019-10-28 23:15:40 +0000 | [diff] [blame] | 21 | #include "dawn_platform/DawnPlatform.h" |
| 22 | #include "dawn_platform/tracing/TraceEvent.h" |
Corentin Wallez | a714f5b | 2018-06-18 17:52:55 -0400 | [diff] [blame] | 23 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 24 | namespace dawn_native { namespace opengl { |
Corentin Wallez | a714f5b | 2018-06-18 17:52:55 -0400 | [diff] [blame] | 25 | |
| 26 | Queue::Queue(Device* device) : QueueBase(device) { |
| 27 | } |
| 28 | |
Bryan Bernhart | 41f8aa5 | 2019-09-23 21:21:10 +0000 | [diff] [blame] | 29 | MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) { |
Austin Eng | 8b07e43 | 2018-12-01 03:20:19 +0000 | [diff] [blame] | 30 | Device* device = ToBackend(GetDevice()); |
| 31 | |
Austin Eng | 73d5bb5 | 2019-10-28 23:15:40 +0000 | [diff] [blame] | 32 | TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute"); |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 33 | for (uint32_t i = 0; i < commandCount; ++i) { |
Austin Eng | b54c82e | 2020-08-18 18:53:26 +0000 | [diff] [blame] | 34 | DAWN_TRY(ToBackend(commands[i])->Execute()); |
Corentin Wallez | a714f5b | 2018-06-18 17:52:55 -0400 | [diff] [blame] | 35 | } |
Austin Eng | 73d5bb5 | 2019-10-28 23:15:40 +0000 | [diff] [blame] | 36 | TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute"); |
Austin Eng | 8b07e43 | 2018-12-01 03:20:19 +0000 | [diff] [blame] | 37 | |
| 38 | device->SubmitFenceSync(); |
Bryan Bernhart | 41f8aa5 | 2019-09-23 21:21:10 +0000 | [diff] [blame] | 39 | return {}; |
Corentin Wallez | a714f5b | 2018-06-18 17:52:55 -0400 | [diff] [blame] | 40 | } |
| 41 | |
Corentin Wallez | 47a3341 | 2020-06-02 09:24:39 +0000 | [diff] [blame] | 42 | MaybeError Queue::WriteBufferImpl(BufferBase* buffer, |
| 43 | uint64_t bufferOffset, |
| 44 | const void* data, |
| 45 | size_t size) { |
| 46 | const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; |
| 47 | |
Jiawei Shao | dab10ea | 2020-07-09 09:15:22 +0000 | [diff] [blame] | 48 | ToBackend(buffer)->EnsureDataInitializedAsDestination(bufferOffset, size); |
Jiawei Shao | 80f927d | 2020-07-06 08:24:30 +0000 | [diff] [blame] | 49 | |
Corentin Wallez | 47a3341 | 2020-06-02 09:24:39 +0000 | [diff] [blame] | 50 | gl.BindBuffer(GL_ARRAY_BUFFER, ToBackend(buffer)->GetHandle()); |
| 51 | gl.BufferSubData(GL_ARRAY_BUFFER, bufferOffset, size, data); |
| 52 | return {}; |
| 53 | } |
| 54 | |
Corentin Wallez | 8091584 | 2021-03-04 18:13:45 +0000 | [diff] [blame] | 55 | MaybeError Queue::WriteTextureImpl(const ImageCopyTexture& destination, |
Tomek Ponitka | d720785 | 2020-08-20 13:29:39 +0000 | [diff] [blame] | 56 | const void* data, |
| 57 | const TextureDataLayout& dataLayout, |
| 58 | const Extent3D& writeSizePixel) { |
Jiawei Shao | 3d5402c | 2021-06-27 05:38:05 +0000 | [diff] [blame] | 59 | if (destination.aspect == wgpu::TextureAspect::StencilOnly) { |
| 60 | return DAWN_VALIDATION_ERROR("Writes to stencil textures unsupported on OpenGL"); |
| 61 | } |
| 62 | |
Stephen White | b676602 | 2021-04-12 23:03:44 +0000 | [diff] [blame] | 63 | TextureCopy textureCopy; |
| 64 | textureCopy.texture = destination.texture; |
| 65 | textureCopy.mipLevel = destination.mipLevel; |
| 66 | textureCopy.origin = destination.origin; |
| 67 | textureCopy.aspect = |
| 68 | SelectFormatAspects(destination.texture->GetFormat(), destination.aspect); |
Austin Eng | fd783ce | 2021-05-18 21:51:33 +0000 | [diff] [blame] | 69 | |
| 70 | SubresourceRange range = GetSubresourcesAffectedByCopy(textureCopy, writeSizePixel); |
| 71 | if (IsCompleteSubresourceCopiedTo(destination.texture, writeSizePixel, |
| 72 | destination.mipLevel)) { |
| 73 | destination.texture->SetIsSubresourceContentInitialized(true, range); |
| 74 | } else { |
| 75 | ToBackend(destination.texture)->EnsureSubresourceContentInitialized(range); |
| 76 | } |
Stephen White | b676602 | 2021-04-12 23:03:44 +0000 | [diff] [blame] | 77 | DoTexSubImage(ToBackend(GetDevice())->gl, textureCopy, data, dataLayout, writeSizePixel); |
Stephen White | 988f3da | 2021-01-25 18:16:48 +0000 | [diff] [blame] | 78 | return {}; |
Tomek Ponitka | d720785 | 2020-08-20 13:29:39 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 81 | }} // namespace dawn_native::opengl |