[glsl] Extract binding information out to separate method.
This CL pulls the code to generate the binding information for Tint out
to a separate method.
Bug: 340582170
Change-Id: I71a547b5890ab0ace02fa0ac8cb23f0d29532353
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/194320
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/dawn/native/opengl/ShaderModuleGL.cpp b/src/dawn/native/opengl/ShaderModuleGL.cpp
index 7893c86..b5dc23a 100644
--- a/src/dawn/native/opengl/ShaderModuleGL.cpp
+++ b/src/dawn/native/opengl/ShaderModuleGL.cpp
@@ -168,42 +168,18 @@
return {};
}
-ResultOrError<GLuint> ShaderModule::CompileShader(
- const OpenGLFunctions& gl,
- const ProgrammableStage& programmableStage,
+std::pair<tint::glsl::writer::Bindings, BindingMap> generateBindingInfo(
SingleShaderStage stage,
- bool usesVertexIndex,
- bool usesInstanceIndex,
- bool usesFragDepth,
- CombinedSamplerInfo* combinedSamplers,
const PipelineLayout* layout,
- bool* needsPlaceholderSampler,
- bool* needsTextureBuiltinUniformBuffer,
- BindingPointToFunctionAndOffset* bindingPointToData) const {
- TRACE_EVENT0(GetDevice()->GetPlatform(), General, "TranslateToGLSL");
-
- const OpenGLVersion& version = ToBackend(GetDevice())->GetGL().GetVersion();
-
- GLSLCompilationRequest req = {};
-
- auto tintProgram = GetTintProgram();
- req.inputProgram = &(tintProgram->program);
-
- tint::inspector::Inspector inspector(*req.inputProgram);
- tint::glsl::writer::Bindings bindings;
-
- // Since (non-Vulkan) GLSL does not support descriptor sets, generate a
- // mapping from the original group/binding pair to a binding-only
- // value. This mapping will be used by Tint to remap all global
- // variables to the 1D space.
- const EntryPointMetadata& entryPointMetaData = GetEntryPoint(programmableStage.entryPoint);
- const BindingInfoArray& moduleBindingInfo = entryPointMetaData.bindings;
-
+ const BindingInfoArray& moduleBindingInfo,
+ GLSLCompilationRequest& req) {
// Because of the way the rest of the backend uses the binding information, we need to pass
// through the original WGSL values in the combined shader map. That means, we need to store
// that data for the external texture, otherwise it ends up getting lost.
BindingMap externalTextureExpansionMap;
+ tint::glsl::writer::Bindings bindings;
+
for (BindGroupIndex group : IterateBitSet(layout->GetBindGroupLayoutsMask())) {
const BindGroupLayout* bgl = ToBackend(layout->GetBindGroupLayout(group));
@@ -280,6 +256,41 @@
}
}
}
+ return {bindings, externalTextureExpansionMap};
+}
+
+ResultOrError<GLuint> ShaderModule::CompileShader(
+ const OpenGLFunctions& gl,
+ const ProgrammableStage& programmableStage,
+ SingleShaderStage stage,
+ bool usesVertexIndex,
+ bool usesInstanceIndex,
+ bool usesFragDepth,
+ CombinedSamplerInfo* combinedSamplers,
+ const PipelineLayout* layout,
+ bool* needsPlaceholderSampler,
+ bool* needsTextureBuiltinUniformBuffer,
+ BindingPointToFunctionAndOffset* bindingPointToData) const {
+ TRACE_EVENT0(GetDevice()->GetPlatform(), General, "TranslateToGLSL");
+
+ const OpenGLVersion& version = ToBackend(GetDevice())->GetGL().GetVersion();
+
+ GLSLCompilationRequest req = {};
+
+ auto tintProgram = GetTintProgram();
+ req.inputProgram = &(tintProgram->program);
+
+ tint::inspector::Inspector inspector(*req.inputProgram);
+
+ // Since (non-Vulkan) GLSL does not support descriptor sets, generate a
+ // mapping from the original group/binding pair to a binding-only
+ // value. This mapping will be used by Tint to remap all global
+ // variables to the 1D space.
+ const EntryPointMetadata& entryPointMetaData = GetEntryPoint(programmableStage.entryPoint);
+ const BindingInfoArray& moduleBindingInfo = entryPointMetaData.bindings;
+
+ auto [bindings, externalTextureExpansionMap] =
+ generateBindingInfo(stage, layout, moduleBindingInfo, req);
// When textures are accessed without a sampler (e.g., textureLoad()),
// GetSamplerTextureUses() will return this sentinel value.