aurora: Work around build_bind_groups race condition

This commit is contained in:
Luke Street 2022-03-07 19:07:14 -05:00
parent 71342ed75e
commit 44a4d667b7
4 changed files with 15 additions and 15 deletions

View File

@ -356,7 +356,8 @@ ShaderInfo populate_pipeline_config(PipelineConfig& config, GX::Primitive primit
// TODO separate shader info from build_shader for async // TODO separate shader info from build_shader for async
{ {
std::lock_guard lk{g_pipelineMutex}; std::lock_guard lk{g_pipelineMutex};
const auto [_, info] = build_shader(config.shaderConfig); auto [_, info] = build_shader(config.shaderConfig);
info.bindGroups = build_bind_groups(info); // TODO this is hack
return info; return info;
} }
} }

View File

@ -91,8 +91,19 @@ struct PipelineConfig {
std::optional<float> dstAlpha; std::optional<float> dstAlpha;
bool depthCompare, depthUpdate, alphaUpdate; bool depthCompare, depthUpdate, alphaUpdate;
}; };
struct GXBindGroupLayouts {
wgpu::BindGroupLayout uniformLayout;
wgpu::BindGroupLayout samplerLayout;
wgpu::BindGroupLayout textureLayout;
};
struct GXBindGroups {
BindGroupRef uniformBindGroup;
BindGroupRef samplerBindGroup;
BindGroupRef textureBindGroup;
};
// Output info from shader generation // Output info from shader generation
struct ShaderInfo { struct ShaderInfo {
GXBindGroups bindGroups;
std::bitset<maxTextures> sampledTextures; std::bitset<maxTextures> sampledTextures;
std::bitset<4> sampledKcolors; std::bitset<4> sampledKcolors;
std::bitset<2> sampledColorChannels; std::bitset<2> sampledColorChannels;
@ -105,20 +116,8 @@ wgpu::RenderPipeline build_pipeline(const PipelineConfig& config, const ShaderIn
ArrayRef<wgpu::VertexBufferLayout> vtxBuffers, wgpu::ShaderModule shader, ArrayRef<wgpu::VertexBufferLayout> vtxBuffers, wgpu::ShaderModule shader,
zstring_view label) noexcept; zstring_view label) noexcept;
std::pair<wgpu::ShaderModule, ShaderInfo> build_shader(const ShaderConfig& config) noexcept; std::pair<wgpu::ShaderModule, ShaderInfo> build_shader(const ShaderConfig& config) noexcept;
// Range build_vertex_buffer(const GXShaderInfo& info) noexcept; // Range build_vertex_buffer(const GXShaderInfo& info) noexcept;
Range build_uniform(const ShaderInfo& info) noexcept; Range build_uniform(const ShaderInfo& info) noexcept;
struct GXBindGroupLayouts {
wgpu::BindGroupLayout uniformLayout;
wgpu::BindGroupLayout samplerLayout;
wgpu::BindGroupLayout textureLayout;
};
struct GXBindGroups {
BindGroupRef uniformBindGroup;
BindGroupRef samplerBindGroup;
BindGroupRef textureBindGroup;
};
GXBindGroupLayouts build_bind_group_layouts(const ShaderInfo& info) noexcept; GXBindGroupLayouts build_bind_group_layouts(const ShaderInfo& info) noexcept;
GXBindGroups build_bind_groups(const ShaderInfo& info) noexcept; GXBindGroups build_bind_groups(const ShaderInfo& info) noexcept;
} // namespace aurora::gfx::gx } // namespace aurora::gfx::gx

View File

@ -513,7 +513,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {{
auto shader = gpu::g_device.CreateShaderModule(&shaderDescriptor); auto shader = gpu::g_device.CreateShaderModule(&shaderDescriptor);
info.uniformSize = align_uniform(info.uniformSize); info.uniformSize = align_uniform(info.uniformSize);
const auto pair = std::make_pair(std::move(shader), info); auto pair = std::make_pair(std::move(shader), info);
g_gxCachedShaders.emplace(hash, pair); g_gxCachedShaders.emplace(hash, pair);
return pair; return pair;

View File

@ -67,7 +67,7 @@ void stream_end() noexcept {
.vertRange = vertRange, .vertRange = vertRange,
.uniformRange = build_uniform(info), .uniformRange = build_uniform(info),
.vertexCount = sStreamState->vertexCount, .vertexCount = sStreamState->vertexCount,
.bindGroups = build_bind_groups(info), .bindGroups = info.bindGroups,
}); });
sStreamState.reset(); sStreamState.reset();