blob: 977f8bf9b8ae84feb7c2542ecaf6f9eb4787c5bb [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2018 The Dawn Authors
Corentin Walleza714f5b2018-06-18 17:52:55 -04002//
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 Wallezd37523f2018-07-24 13:53:51 +020015#include "dawn_native/opengl/QueueGL.h"
Corentin Walleza714f5b2018-06-18 17:52:55 -040016
Corentin Wallez47a33412020-06-02 09:24:39 +000017#include "dawn_native/opengl/BufferGL.h"
Corentin Wallezd37523f2018-07-24 13:53:51 +020018#include "dawn_native/opengl/CommandBufferGL.h"
19#include "dawn_native/opengl/DeviceGL.h"
Stephen White988f3da2021-01-25 18:16:48 +000020#include "dawn_native/opengl/TextureGL.h"
Austin Eng73d5bb52019-10-28 23:15:40 +000021#include "dawn_platform/DawnPlatform.h"
22#include "dawn_platform/tracing/TraceEvent.h"
Corentin Walleza714f5b2018-06-18 17:52:55 -040023
Corentin Wallez49a65d02018-07-24 16:45:45 +020024namespace dawn_native { namespace opengl {
Corentin Walleza714f5b2018-06-18 17:52:55 -040025
26 Queue::Queue(Device* device) : QueueBase(device) {
27 }
28
Bryan Bernhart41f8aa52019-09-23 21:21:10 +000029 MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
Austin Eng8b07e432018-12-01 03:20:19 +000030 Device* device = ToBackend(GetDevice());
31
Austin Eng73d5bb52019-10-28 23:15:40 +000032 TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute");
Jiawei Shao20301662019-02-21 00:45:19 +000033 for (uint32_t i = 0; i < commandCount; ++i) {
Austin Engb54c82e2020-08-18 18:53:26 +000034 DAWN_TRY(ToBackend(commands[i])->Execute());
Corentin Walleza714f5b2018-06-18 17:52:55 -040035 }
Austin Eng73d5bb52019-10-28 23:15:40 +000036 TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute");
Austin Eng8b07e432018-12-01 03:20:19 +000037
38 device->SubmitFenceSync();
Bryan Bernhart41f8aa52019-09-23 21:21:10 +000039 return {};
Corentin Walleza714f5b2018-06-18 17:52:55 -040040 }
41
Corentin Wallez47a33412020-06-02 09:24:39 +000042 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 Shaodab10ea2020-07-09 09:15:22 +000048 ToBackend(buffer)->EnsureDataInitializedAsDestination(bufferOffset, size);
Jiawei Shao80f927d2020-07-06 08:24:30 +000049
Corentin Wallez47a33412020-06-02 09:24:39 +000050 gl.BindBuffer(GL_ARRAY_BUFFER, ToBackend(buffer)->GetHandle());
51 gl.BufferSubData(GL_ARRAY_BUFFER, bufferOffset, size, data);
52 return {};
53 }
54
Corentin Wallez80915842021-03-04 18:13:45 +000055 MaybeError Queue::WriteTextureImpl(const ImageCopyTexture& destination,
Tomek Ponitkad7207852020-08-20 13:29:39 +000056 const void* data,
57 const TextureDataLayout& dataLayout,
58 const Extent3D& writeSizePixel) {
Jiawei Shao3d5402c2021-06-27 05:38:05 +000059 if (destination.aspect == wgpu::TextureAspect::StencilOnly) {
60 return DAWN_VALIDATION_ERROR("Writes to stencil textures unsupported on OpenGL");
61 }
62
Stephen Whiteb6766022021-04-12 23:03:44 +000063 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 Engfd783ce2021-05-18 21:51:33 +000069
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 Whiteb6766022021-04-12 23:03:44 +000077 DoTexSubImage(ToBackend(GetDevice())->gl, textureCopy, data, dataLayout, writeSizePixel);
Stephen White988f3da2021-01-25 18:16:48 +000078 return {};
Tomek Ponitkad7207852020-08-20 13:29:39 +000079 }
80
Corentin Wallez49a65d02018-07-24 16:45:45 +020081}} // namespace dawn_native::opengl