Update dawn & use external OpenGL context hooks

This commit is contained in:
Luke Street 2022-08-29 17:07:21 -04:00
parent 99bb9e5f83
commit d8e41e4bcc
5 changed files with 40 additions and 13 deletions

2
extern/dawn vendored

@ -1 +1 @@
Subproject commit 64a23ce0ede5f232cc209b69d64164ede6810b65
Subproject commit db82c79db65e502dd226f5cb4e2c03d85f8ffd2d

View File

@ -37,6 +37,22 @@ BackendBinding* CreateVulkanBinding(SDL_Window* window, WGPUDevice device);
BackendBinding::BackendBinding(SDL_Window* window, WGPUDevice device) : m_window(window), m_device(device) {}
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
struct GLUserData {
SDL_Window* window;
SDL_GLContext context;
};
void GLMakeCurrent(void* userData) {
auto* data = static_cast<GLUserData*>(userData);
SDL_GL_MakeCurrent(data->window, data->context);
}
void GLDestroy(void* userData) {
auto* data = static_cast<GLUserData*>(userData);
SDL_GL_DeleteContext(data->context);
delete data;
}
#endif
bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu::BackendType type) {
switch (type) {
#if defined(DAWN_ENABLE_BACKEND_D3D12)
@ -63,10 +79,15 @@ bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);
SDL_GL_CreateContext(window);
auto getProc = reinterpret_cast<void* (*)(const char*)>(SDL_GL_GetProcAddress);
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions;
adapterOptions.getProc = getProc;
SDL_GLContext context = SDL_GL_CreateContext(window);
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions{WGPUBackendType_OpenGL};
adapterOptions.getProc = SDL_GL_GetProcAddress;
adapterOptions.makeCurrent = GLMakeCurrent;
adapterOptions.destroy = GLDestroy;
adapterOptions.userData = new GLUserData{
.window = window,
.context = context,
};
return instance->DiscoverAdapters(&adapterOptions);
}
#endif
@ -76,10 +97,15 @@ bool DiscoverAdapter(dawn::native::Instance* instance, SDL_Window* window, wgpu:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_CreateContext(window);
auto getProc = reinterpret_cast<void* (*)(const char*)>(SDL_GL_GetProcAddress);
dawn::native::opengl::AdapterDiscoveryOptionsES adapterOptions;
adapterOptions.getProc = getProc;
SDL_GLContext context = SDL_GL_CreateContext(window);
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions{WGPUBackendType_OpenGLES};
adapterOptions.getProc = SDL_GL_GetProcAddress;
adapterOptions.makeCurrent = GLMakeCurrent;
adapterOptions.destroy = GLDestroy;
adapterOptions.userData = new GLUserData{
.window = window,
.context = context,
};
return instance->DiscoverAdapters(&adapterOptions);
}
#endif

View File

@ -1311,14 +1311,14 @@ fn textureSamplePaletteI4(tex: texture_2d<f32>, samp: sampler, uv: vec2<f32>, tl
return mix(t0, t1, f.y);
}}
@stage(vertex)
@vertex
fn vs_main({5}
) -> VertexOutput {{
var out: VertexOutput;{9}{6}
return out;
}}
@stage(fragment)
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {{{8}{7}
return prev;
}}

View File

@ -170,7 +170,7 @@ var<private> uvs: array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2(2.0, 0.0),
);
@stage(vertex)
@vertex
fn vs_main(@builtin(vertex_index) vtxIdx: u32) -> VertexOutput {
var out: VertexOutput;
out.pos = vec4<f32>(pos[vtxIdx], 0.0, 1.0);
@ -178,7 +178,7 @@ fn vs_main(@builtin(vertex_index) vtxIdx: u32) -> VertexOutput {
return out;
}
@stage(fragment)
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(efb_texture, efb_sampler, in.uv);
}

View File

@ -157,6 +157,7 @@ bool create_window(AuroraBackend backend) {
#endif
g_window = SDL_CreateWindow(g_config.appName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
if (g_window == nullptr) {
Log.report(LOG_WARNING, FMT_STRING("Failed to create window: {}"), SDL_GetError());
return false;
}
set_window_icon();