OpenGL: Make Device::gl private.

Make Device::gl private, and rename it to mGL. Change all accesses to
use Device::GetGL() accessor.

This is a precursor to adding native EGLContext support to
Dawn.

Bug: dawn:810
Change-Id: I3793d83644a70bafc6bea8b423c1a7c76beb248d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94560
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Stephen White 2022-06-24 14:12:39 +00:00 committed by Dawn LUCI CQ
parent e8d47d5263
commit c174692187
12 changed files with 67 additions and 52 deletions

View File

@ -39,21 +39,22 @@ ResultOrError<Ref<Buffer>> Buffer::CreateInternalBuffer(Device* device,
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor) Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
: BufferBase(device, descriptor) { : BufferBase(device, descriptor) {
const OpenGLFunctions& gl = device->GetGL();
// Allocate at least 4 bytes so clamped accesses are always in bounds. // Allocate at least 4 bytes so clamped accesses are always in bounds.
mAllocatedSize = std::max(GetSize(), uint64_t(4u)); mAllocatedSize = std::max(GetSize(), uint64_t(4u));
device->gl.GenBuffers(1, &mBuffer); gl.GenBuffers(1, &mBuffer);
device->gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer); gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer);
// The buffers with mappedAtCreation == true will be initialized in // The buffers with mappedAtCreation == true will be initialized in
// BufferBase::MapAtCreation(). // BufferBase::MapAtCreation().
if (device->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting) && if (device->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting) &&
!descriptor->mappedAtCreation) { !descriptor->mappedAtCreation) {
std::vector<uint8_t> clearValues(mAllocatedSize, 1u); std::vector<uint8_t> clearValues(mAllocatedSize, 1u);
device->gl.BufferData(GL_ARRAY_BUFFER, mAllocatedSize, clearValues.data(), GL_STATIC_DRAW); gl.BufferData(GL_ARRAY_BUFFER, mAllocatedSize, clearValues.data(), GL_STATIC_DRAW);
} else { } else {
// Buffers start zeroed if you pass nullptr to glBufferData. // Buffers start zeroed if you pass nullptr to glBufferData.
device->gl.BufferData(GL_ARRAY_BUFFER, mAllocatedSize, nullptr, GL_STATIC_DRAW); gl.BufferData(GL_ARRAY_BUFFER, mAllocatedSize, nullptr, GL_STATIC_DRAW);
} }
} }
@ -112,10 +113,11 @@ void Buffer::InitializeToZero() {
const uint64_t size = GetAllocatedSize(); const uint64_t size = GetAllocatedSize();
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
const OpenGLFunctions& gl = device->GetGL();
const std::vector<uint8_t> clearValues(size, 0u); const std::vector<uint8_t> clearValues(size, 0u);
device->gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer); gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer);
device->gl.BufferSubData(GL_ARRAY_BUFFER, 0, size, clearValues.data()); gl.BufferSubData(GL_ARRAY_BUFFER, 0, size, clearValues.data());
device->IncrementLazyClearCountForTesting(); device->IncrementLazyClearCountForTesting();
SetIsDataInitialized(); SetIsDataInitialized();
@ -128,14 +130,14 @@ bool Buffer::IsCPUWritableAtCreation() const {
} }
MaybeError Buffer::MapAtCreationImpl() { MaybeError Buffer::MapAtCreationImpl() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer); gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer);
mMappedData = gl.MapBufferRange(GL_ARRAY_BUFFER, 0, GetSize(), GL_MAP_WRITE_BIT); mMappedData = gl.MapBufferRange(GL_ARRAY_BUFFER, 0, GetSize(), GL_MAP_WRITE_BIT);
return {}; return {};
} }
MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) { MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
// It is an error to map an empty range in OpenGL. We always have at least a 4-byte buffer // It is an error to map an empty range in OpenGL. We always have at least a 4-byte buffer
// so we extend the range to be 4 bytes. // so we extend the range to be 4 bytes.
@ -171,7 +173,7 @@ void* Buffer::GetMappedPointerImpl() {
} }
void Buffer::UnmapImpl() { void Buffer::UnmapImpl() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer); gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer);
gl.UnmapBuffer(GL_ARRAY_BUFFER); gl.UnmapBuffer(GL_ARRAY_BUFFER);
@ -179,8 +181,10 @@ void Buffer::UnmapImpl() {
} }
void Buffer::DestroyImpl() { void Buffer::DestroyImpl() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
BufferBase::DestroyImpl(); BufferBase::DestroyImpl();
ToBackend(GetDevice())->gl.DeleteBuffers(1, &mBuffer); gl.DeleteBuffers(1, &mBuffer);
mBuffer = 0; mBuffer = 0;
} }

View File

@ -448,7 +448,7 @@ CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescrip
: CommandBufferBase(encoder, descriptor) {} : CommandBufferBase(encoder, descriptor) {}
MaybeError CommandBuffer::Execute() { MaybeError CommandBuffer::Execute() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
auto LazyClearSyncScope = [](const SyncScopeResourceUsage& scope) { auto LazyClearSyncScope = [](const SyncScopeResourceUsage& scope) {
for (size_t i = 0; i < scope.textures.size(); i++) { for (size_t i = 0; i < scope.textures.size(); i++) {
@ -767,7 +767,7 @@ MaybeError CommandBuffer::Execute() {
} }
MaybeError CommandBuffer::ExecuteComputePass() { MaybeError CommandBuffer::ExecuteComputePass() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
ComputePipeline* lastPipeline = nullptr; ComputePipeline* lastPipeline = nullptr;
BindGroupTracker bindGroupTracker = {}; BindGroupTracker bindGroupTracker = {};
@ -844,7 +844,7 @@ MaybeError CommandBuffer::ExecuteComputePass() {
} }
MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass) { MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
GLuint fbo = 0; GLuint fbo = 0;
// Create the framebuffer used for this render pass and calls the correct glDrawBuffers // Create the framebuffer used for this render pass and calls the correct glDrawBuffers

View File

@ -29,16 +29,17 @@ ComputePipeline::~ComputePipeline() = default;
void ComputePipeline::DestroyImpl() { void ComputePipeline::DestroyImpl() {
ComputePipelineBase::DestroyImpl(); ComputePipelineBase::DestroyImpl();
DeleteProgram(ToBackend(GetDevice())->gl); DeleteProgram(ToBackend(GetDevice())->GetGL());
} }
MaybeError ComputePipeline::Initialize() { MaybeError ComputePipeline::Initialize() {
DAWN_TRY(InitializeBase(ToBackend(GetDevice())->gl, ToBackend(GetLayout()), GetAllStages())); DAWN_TRY(
InitializeBase(ToBackend(GetDevice())->GetGL(), ToBackend(GetLayout()), GetAllStages()));
return {}; return {};
} }
void ComputePipeline::ApplyNow() { void ComputePipeline::ApplyNow() {
PipelineGL::ApplyNow(ToBackend(GetDevice())->gl); PipelineGL::ApplyNow(ToBackend(GetDevice())->GetGL());
} }
} // namespace dawn::native::opengl } // namespace dawn::native::opengl

View File

@ -46,7 +46,7 @@ ResultOrError<Ref<Device>> Device::Create(AdapterBase* adapter,
Device::Device(AdapterBase* adapter, Device::Device(AdapterBase* adapter,
const DeviceDescriptor* descriptor, const DeviceDescriptor* descriptor,
const OpenGLFunctions& functions) const OpenGLFunctions& functions)
: DeviceBase(adapter, descriptor), gl(functions) {} : DeviceBase(adapter, descriptor), mGL(functions) {}
Device::~Device() { Device::~Device() {
Destroy(); Destroy();
@ -60,6 +60,7 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
} }
void Device::InitTogglesFromDriver() { void Device::InitTogglesFromDriver() {
const OpenGLFunctions& gl = GetGL();
bool supportsBaseVertex = gl.IsAtLeastGLES(3, 2) || gl.IsAtLeastGL(3, 2); bool supportsBaseVertex = gl.IsAtLeastGLES(3, 2) || gl.IsAtLeastGL(3, 2);
bool supportsBaseInstance = gl.IsAtLeastGLES(3, 2) || gl.IsAtLeastGL(4, 2); bool supportsBaseInstance = gl.IsAtLeastGLES(3, 2) || gl.IsAtLeastGL(4, 2);
@ -124,6 +125,7 @@ const GLFormat& Device::GetGLFormat(const Format& format) {
} }
GLenum Device::GetBGRAInternalFormat() const { GLenum Device::GetBGRAInternalFormat() const {
const OpenGLFunctions& gl = GetGL();
if (gl.IsGLExtensionSupported("GL_EXT_texture_format_BGRA8888") || if (gl.IsGLExtensionSupported("GL_EXT_texture_format_BGRA8888") ||
gl.IsGLExtensionSupported("GL_APPLE_texture_format_BGRA8888")) { gl.IsGLExtensionSupported("GL_APPLE_texture_format_BGRA8888")) {
return GL_BGRA8_EXT; return GL_BGRA8_EXT;
@ -195,6 +197,7 @@ ResultOrError<Ref<TextureViewBase>> Device::CreateTextureViewImpl(
} }
void Device::SubmitFenceSync() { void Device::SubmitFenceSync() {
const OpenGLFunctions& gl = GetGL();
GLsync sync = gl.FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); GLsync sync = gl.FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
IncrementLastSubmittedCommandSerial(); IncrementLastSubmittedCommandSerial();
mFencesInFlight.emplace(sync, GetLastSubmittedCommandSerial()); mFencesInFlight.emplace(sync, GetLastSubmittedCommandSerial());
@ -224,6 +227,7 @@ MaybeError Device::ValidateEGLImageCanBeWrapped(const TextureDescriptor* descrip
} }
TextureBase* Device::CreateTextureWrappingEGLImage(const ExternalImageDescriptor* descriptor, TextureBase* Device::CreateTextureWrappingEGLImage(const ExternalImageDescriptor* descriptor,
::EGLImage image) { ::EGLImage image) {
const OpenGLFunctions& gl = GetGL();
const TextureDescriptor* textureDescriptor = FromAPI(descriptor->cTextureDescriptor); const TextureDescriptor* textureDescriptor = FromAPI(descriptor->cTextureDescriptor);
if (ConsumedError(ValidateTextureDescriptor(this, textureDescriptor))) { if (ConsumedError(ValidateTextureDescriptor(this, textureDescriptor))) {
@ -264,6 +268,7 @@ MaybeError Device::TickImpl() {
ResultOrError<ExecutionSerial> Device::CheckAndUpdateCompletedSerials() { ResultOrError<ExecutionSerial> Device::CheckAndUpdateCompletedSerials() {
ExecutionSerial fenceSerial{0}; ExecutionSerial fenceSerial{0};
const OpenGLFunctions& gl = GetGL();
while (!mFencesInFlight.empty()) { while (!mFencesInFlight.empty()) {
auto [sync, tentativeSerial] = mFencesInFlight.front(); auto [sync, tentativeSerial] = mFencesInFlight.front();
@ -314,6 +319,7 @@ void Device::DestroyImpl() {
} }
MaybeError Device::WaitForIdleForDestruction() { MaybeError Device::WaitForIdleForDestruction() {
const OpenGLFunctions& gl = GetGL();
gl.Finish(); gl.Finish();
DAWN_TRY(CheckPassedSerials()); DAWN_TRY(CheckPassedSerials());
ASSERT(mFencesInFlight.empty()); ASSERT(mFencesInFlight.empty());
@ -333,4 +339,8 @@ float Device::GetTimestampPeriodInNS() const {
return 1.0f; return 1.0f;
} }
const OpenGLFunctions& Device::GetGL() const {
return mGL;
}
} // namespace dawn::native::opengl } // namespace dawn::native::opengl

View File

@ -46,8 +46,8 @@ class Device final : public DeviceBase {
MaybeError Initialize(const DeviceDescriptor* descriptor); MaybeError Initialize(const DeviceDescriptor* descriptor);
// Contains all the OpenGL entry points, glDoFoo is called via device->gl.DoFoo. // Contains all the OpenGL entry points, glDoFoo is called via gl.DoFoo.
const OpenGLFunctions gl; const OpenGLFunctions& GetGL() const;
const GLFormat& GetGLFormat(const Format& format); const GLFormat& GetGLFormat(const Format& format);
@ -121,6 +121,8 @@ class Device final : public DeviceBase {
void DestroyImpl() override; void DestroyImpl() override;
MaybeError WaitForIdleForDestruction() override; MaybeError WaitForIdleForDestruction() override;
const OpenGLFunctions mGL;
std::queue<std::pair<GLsync, ExecutionSerial>> mFencesInFlight; std::queue<std::pair<GLsync, ExecutionSerial>> mFencesInFlight;
GLFormatTable mFormatTable; GLFormatTable mFormatTable;

View File

@ -24,13 +24,13 @@ NativeSwapChainImpl::NativeSwapChainImpl(Device* device,
: mPresentCallback(present), mPresentUserdata(presentUserdata), mDevice(device) {} : mPresentCallback(present), mPresentUserdata(presentUserdata), mDevice(device) {}
NativeSwapChainImpl::~NativeSwapChainImpl() { NativeSwapChainImpl::~NativeSwapChainImpl() {
const OpenGLFunctions& gl = mDevice->gl; const OpenGLFunctions& gl = mDevice->GetGL();
gl.DeleteTextures(1, &mBackTexture); gl.DeleteTextures(1, &mBackTexture);
gl.DeleteFramebuffers(1, &mBackFBO); gl.DeleteFramebuffers(1, &mBackFBO);
} }
void NativeSwapChainImpl::Init(DawnWSIContextGL* /*context*/) { void NativeSwapChainImpl::Init(DawnWSIContextGL* /*context*/) {
const OpenGLFunctions& gl = mDevice->gl; const OpenGLFunctions& gl = mDevice->GetGL();
gl.GenTextures(1, &mBackTexture); gl.GenTextures(1, &mBackTexture);
gl.BindTexture(GL_TEXTURE_2D, mBackTexture); gl.BindTexture(GL_TEXTURE_2D, mBackTexture);
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
@ -53,7 +53,7 @@ DawnSwapChainError NativeSwapChainImpl::Configure(WGPUTextureFormat format,
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
const OpenGLFunctions& gl = mDevice->gl; const OpenGLFunctions& gl = mDevice->GetGL();
gl.BindTexture(GL_TEXTURE_2D, mBackTexture); gl.BindTexture(GL_TEXTURE_2D, mBackTexture);
// Reallocate the texture // Reallocate the texture
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
@ -67,7 +67,7 @@ DawnSwapChainError NativeSwapChainImpl::GetNextTexture(DawnSwapChainNextTexture*
} }
DawnSwapChainError NativeSwapChainImpl::Present() { DawnSwapChainError NativeSwapChainImpl::Present() {
const OpenGLFunctions& gl = mDevice->gl; const OpenGLFunctions& gl = mDevice->GetGL();
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO); gl.BindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO);
gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
gl.Scissor(0, 0, mWidth, mHeight); gl.Scissor(0, 0, mWidth, mHeight);

View File

@ -42,7 +42,7 @@ MaybeError Queue::WriteBufferImpl(BufferBase* buffer,
uint64_t bufferOffset, uint64_t bufferOffset,
const void* data, const void* data,
size_t size) { size_t size) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
ToBackend(buffer)->EnsureDataInitializedAsDestination(bufferOffset, size); ToBackend(buffer)->EnsureDataInitializedAsDestination(bufferOffset, size);
@ -70,7 +70,7 @@ MaybeError Queue::WriteTextureImpl(const ImageCopyTexture& destination,
} else { } else {
ToBackend(destination.texture)->EnsureSubresourceContentInitialized(range); ToBackend(destination.texture)->EnsureSubresourceContentInitialized(range);
} }
DoTexSubImage(ToBackend(GetDevice())->gl, textureCopy, data, dataLayout, writeSizePixel); DoTexSubImage(ToBackend(GetDevice())->GetGL(), textureCopy, data, dataLayout, writeSizePixel);
ToBackend(destination.texture)->Touch(); ToBackend(destination.texture)->Touch();
return {}; return {};
} }

View File

@ -226,7 +226,8 @@ RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* d
mGlPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {} mGlPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {}
MaybeError RenderPipeline::Initialize() { MaybeError RenderPipeline::Initialize() {
DAWN_TRY(InitializeBase(ToBackend(GetDevice())->gl, ToBackend(GetLayout()), GetAllStages())); DAWN_TRY(
InitializeBase(ToBackend(GetDevice())->GetGL(), ToBackend(GetLayout()), GetAllStages()));
CreateVAOForVertexState(); CreateVAOForVertexState();
return {}; return {};
} }
@ -235,7 +236,7 @@ RenderPipeline::~RenderPipeline() = default;
void RenderPipeline::DestroyImpl() { void RenderPipeline::DestroyImpl() {
RenderPipelineBase::DestroyImpl(); RenderPipelineBase::DestroyImpl();
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
gl.DeleteVertexArrays(1, &mVertexArrayObject); gl.DeleteVertexArrays(1, &mVertexArrayObject);
gl.BindVertexArray(0); gl.BindVertexArray(0);
DeleteProgram(gl); DeleteProgram(gl);
@ -252,7 +253,7 @@ RenderPipeline::GetAttributesUsingVertexBuffer(VertexBufferSlot slot) const {
} }
void RenderPipeline::CreateVAOForVertexState() { void RenderPipeline::CreateVAOForVertexState() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
gl.GenVertexArrays(1, &mVertexArrayObject); gl.GenVertexArrays(1, &mVertexArrayObject);
gl.BindVertexArray(mVertexArrayObject); gl.BindVertexArray(mVertexArrayObject);
@ -284,7 +285,7 @@ void RenderPipeline::CreateVAOForVertexState() {
} }
void RenderPipeline::ApplyNow(PersistentPipelineState& persistentPipelineState) { void RenderPipeline::ApplyNow(PersistentPipelineState& persistentPipelineState) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
PipelineGL::ApplyNow(gl); PipelineGL::ApplyNow(gl);
ASSERT(mVertexArrayObject); ASSERT(mVertexArrayObject);

View File

@ -67,7 +67,7 @@ GLenum WrapMode(wgpu::AddressMode mode) {
Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor) Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) { : SamplerBase(device, descriptor) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
gl.GenSamplers(1, &mFilteringHandle); gl.GenSamplers(1, &mFilteringHandle);
SetupGLSampler(mFilteringHandle, descriptor, false); SetupGLSampler(mFilteringHandle, descriptor, false);
@ -80,7 +80,7 @@ Sampler::~Sampler() = default;
void Sampler::DestroyImpl() { void Sampler::DestroyImpl() {
SamplerBase::DestroyImpl(); SamplerBase::DestroyImpl();
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
gl.DeleteSamplers(1, &mFilteringHandle); gl.DeleteSamplers(1, &mFilteringHandle);
gl.DeleteSamplers(1, &mNonFilteringHandle); gl.DeleteSamplers(1, &mNonFilteringHandle);
} }
@ -89,7 +89,7 @@ void Sampler::SetupGLSampler(GLuint sampler,
const SamplerDescriptor* descriptor, const SamplerDescriptor* descriptor,
bool forceNearest) { bool forceNearest) {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
const OpenGLFunctions& gl = device->gl; const OpenGLFunctions& gl = device->GetGL();
if (forceNearest) { if (forceNearest) {
gl.SamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl.SamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

View File

@ -95,7 +95,7 @@ ResultOrError<std::string> ShaderModule::TranslateToGLSL(const char* entryPointN
tint::Program program; tint::Program program;
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs, DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs,
nullptr, nullptr)); nullptr, nullptr));
const OpenGLVersion& version = ToBackend(GetDevice())->gl.GetVersion(); const OpenGLVersion& version = ToBackend(GetDevice())->GetGL().GetVersion();
tint::writer::glsl::Options tintOptions; tint::writer::glsl::Options tintOptions;
using Version = tint::writer::glsl::Version; using Version = tint::writer::glsl::Version;

View File

@ -83,12 +83,6 @@ GLenum TargetForTextureViewDimension(wgpu::TextureViewDimension dimension,
UNREACHABLE(); UNREACHABLE();
} }
GLuint GenTexture(const OpenGLFunctions& gl) {
GLuint handle = 0;
gl.GenTextures(1, &handle);
return handle;
}
bool RequiresCreatingNewTextureView(const TextureBase* texture, bool RequiresCreatingNewTextureView(const TextureBase* texture,
const TextureViewDescriptor* textureViewDescriptor) { const TextureViewDescriptor* textureViewDescriptor) {
constexpr wgpu::TextureUsage kShaderUsageNeedsView = constexpr wgpu::TextureUsage kShaderUsageNeedsView =
@ -179,9 +173,10 @@ void AllocateTexture(const OpenGLFunctions& gl,
// Texture // Texture
Texture::Texture(Device* device, const TextureDescriptor* descriptor) Texture::Texture(Device* device, const TextureDescriptor* descriptor)
: Texture(device, descriptor, GenTexture(device->gl), TextureState::OwnedInternal) { : Texture(device, descriptor, 0, TextureState::OwnedInternal) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = device->GetGL();
gl.GenTextures(1, &mHandle);
uint32_t levels = GetNumMipLevels(); uint32_t levels = GetNumMipLevels();
const GLFormat& glFormat = GetGLFormat(); const GLFormat& glFormat = GetGLFormat();
@ -221,7 +216,8 @@ Texture::~Texture() {}
void Texture::DestroyImpl() { void Texture::DestroyImpl() {
TextureBase::DestroyImpl(); TextureBase::DestroyImpl();
if (GetTextureState() == TextureState::OwnedInternal) { if (GetTextureState() == TextureState::OwnedInternal) {
ToBackend(GetDevice())->gl.DeleteTextures(1, &mHandle); const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
gl.DeleteTextures(1, &mHandle);
mHandle = 0; mHandle = 0;
} }
} }
@ -246,7 +242,7 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range,
} }
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
const OpenGLFunctions& gl = device->gl; const OpenGLFunctions& gl = device->GetGL();
uint8_t clearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0 : 1; uint8_t clearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0 : 1;
float fClearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0.f : 1.f; float fClearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0.f : 1.f;
@ -534,7 +530,7 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range,
} }
textureCopy.origin.z = layer; textureCopy.origin.z = layer;
DoTexSubImage(ToBackend(GetDevice())->gl, textureCopy, 0, dataLayout, mipSize); DoTexSubImage(gl, textureCopy, 0, dataLayout, mipSize);
} }
} }
gl.BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); gl.BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
@ -571,9 +567,9 @@ TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* desc
if (!RequiresCreatingNewTextureView(texture, descriptor)) { if (!RequiresCreatingNewTextureView(texture, descriptor)) {
mHandle = ToBackend(texture)->GetHandle(); mHandle = ToBackend(texture)->GetHandle();
} else { } else {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
if (gl.IsAtLeastGL(4, 3)) { if (gl.IsAtLeastGL(4, 3)) {
mHandle = GenTexture(gl); gl.GenTextures(1, &mHandle);
const Texture* textureGL = ToBackend(texture); const Texture* textureGL = ToBackend(texture);
gl.TextureView(mHandle, mTarget, textureGL->GetHandle(), GetInternalFormat(), gl.TextureView(mHandle, mTarget, textureGL->GetHandle(), GetInternalFormat(),
descriptor->baseMipLevel, descriptor->mipLevelCount, descriptor->baseMipLevel, descriptor->mipLevelCount,
@ -592,7 +588,8 @@ TextureView::~TextureView() {}
void TextureView::DestroyImpl() { void TextureView::DestroyImpl() {
TextureViewBase::DestroyImpl(); TextureViewBase::DestroyImpl();
if (mOwnsHandle) { if (mOwnsHandle) {
ToBackend(GetDevice())->gl.DeleteTextures(1, &mHandle); const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
gl.DeleteTextures(1, &mHandle);
} }
} }
@ -606,7 +603,7 @@ GLenum TextureView::GetGLTarget() const {
} }
void TextureView::BindToFramebuffer(GLenum target, GLenum attachment) { void TextureView::BindToFramebuffer(GLenum target, GLenum attachment) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
// Use the base texture where possible to minimize the amount of copying required on GLES. // Use the base texture where possible to minimize the amount of copying required on GLES.
bool useOwnView = GetFormat().format != GetTexture()->GetFormat().format && bool useOwnView = GetFormat().format != GetTexture()->GetFormat().format &&
@ -648,7 +645,7 @@ void TextureView::CopyIfNeeded() {
} }
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
const OpenGLFunctions& gl = device->gl; const OpenGLFunctions& gl = device->GetGL();
uint32_t srcLevel = GetBaseMipLevel(); uint32_t srcLevel = GetBaseMipLevel();
uint32_t numLevels = GetLevelCount(); uint32_t numLevels = GetLevelCount();
@ -657,7 +654,7 @@ void TextureView::CopyIfNeeded() {
Extent3D size{width, height, GetLayerCount()}; Extent3D size{width, height, GetLayerCount()};
if (mHandle == 0) { if (mHandle == 0) {
mHandle = GenTexture(gl); gl.GenTextures(1, &mHandle);
gl.BindTexture(mTarget, mHandle); gl.BindTexture(mTarget, mHandle);
AllocateTexture(gl, mTarget, texture->GetSampleCount(), numLevels, GetInternalFormat(), AllocateTexture(gl, mTarget, texture->GetSampleCount(), numLevels, GetInternalFormat(),
size); size);

View File

@ -128,7 +128,7 @@ class EGLImageTestBase : public DawnTest {
size_t size) { size_t size) {
dawn::native::opengl::Device* openglDevice = dawn::native::opengl::Device* openglDevice =
dawn::native::opengl::ToBackend(dawn::native::FromAPI(device.Get())); dawn::native::opengl::ToBackend(dawn::native::FromAPI(device.Get()));
const dawn::native::opengl::OpenGLFunctions& gl = openglDevice->gl; const dawn::native::opengl::OpenGLFunctions& gl = openglDevice->GetGL();
GLuint tex; GLuint tex;
gl.GenTextures(1, &tex); gl.GenTextures(1, &tex);
gl.BindTexture(GL_TEXTURE_2D, tex); gl.BindTexture(GL_TEXTURE_2D, tex);
@ -300,7 +300,7 @@ class EGLImageUsageTests : public EGLImageTestBase {
size_t dataSize) { size_t dataSize) {
dawn::native::opengl::Device* openglDevice = dawn::native::opengl::Device* openglDevice =
dawn::native::opengl::ToBackend(dawn::native::FromAPI(device.Get())); dawn::native::opengl::ToBackend(dawn::native::FromAPI(device.Get()));
const dawn::native::opengl::OpenGLFunctions& gl = openglDevice->gl; const dawn::native::opengl::OpenGLFunctions& gl = openglDevice->GetGL();
// Get a texture view for the eglImage // Get a texture view for the eglImage
wgpu::TextureDescriptor textureDescriptor; wgpu::TextureDescriptor textureDescriptor;