22 "ANGLEInputAttachment";
30 const std::vector<ShaderStageIOSlot>& p_inputs,
31 const std::vector<ShaderStageBufferLayout>& layouts) {
32 std::vector<VertexAttribPointer> vertex_attrib_arrays;
33 for (
auto i = 0u; i < p_inputs.size(); i++) {
34 const auto& input = p_inputs[i];
35 const auto& layout = layouts[input.binding];
36 VertexAttribPointer attrib;
37 attrib.index = input.location;
39 if (input.vec_size < 1u || input.vec_size > 4u) {
42 attrib.size = input.vec_size;
44 if (!
type.has_value()) {
47 attrib.type =
type.value();
48 attrib.normalized = GL_FALSE;
49 attrib.offset = input.offset;
50 attrib.stride = layout.stride;
51 vertex_attrib_arrays.emplace_back(attrib);
53 vertex_attrib_arrays_ = std::move(vertex_attrib_arrays);
62 result.push_back(toupper(ch));
69 const std::string& member,
72 result.reserve(struct_name.length() + member.length() + (is_array ? 4 : 1));
74 if (!member.empty()) {
85 const std::string& non_struct_member) {
91 if (!gl.IsProgram(program)) {
94 GLint max_name_size = 0;
95 gl.GetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_size);
97 GLint uniform_count = 0;
98 gl.GetProgramiv(program, GL_ACTIVE_UNIFORMS, &uniform_count);
102 for (GLint i = 0; i < uniform_count; i++) {
103 std::vector<GLchar>
name;
104 name.resize(max_name_size);
105 GLsizei written_count = 0u;
106 GLint uniform_var_size = 0u;
107 GLenum uniform_type = GL_FLOAT;
111 gl.GetActiveUniform(program,
121 if (gl.GetCapabilities()->IsANGLE()) {
130 auto location = gl.GetUniformLocation(program,
name.data());
131 if (location == -1) {
132 VALIDATION_LOG <<
"Could not query the location of an active uniform.";
135 if (written_count <= 0) {
136 VALIDATION_LOG <<
"Uniform name could not be read for active uniform.";
140 name.data(),
static_cast<size_t>(written_count)})] = location;
146 size_t vertex_offset)
const {
147 for (
const auto& array : vertex_attrib_arrays_) {
148 gl.EnableVertexAttribArray(array.index);
149 gl.VertexAttribPointer(array.index,
154 reinterpret_cast<const GLvoid*
>(
static_cast<GLsizei
>(
155 vertex_offset + array.offset))
165 const Bindings& fragment_bindings) {
167 if (!BindUniformBuffer(gl, transients_allocator,
buffer.view)) {
172 if (!BindUniformBuffer(gl, transients_allocator,
buffer.view)) {
177 std::optional<size_t> next_unit_index =
179 if (!next_unit_index.has_value()) {
193 for (
const auto& array : vertex_attrib_arrays_) {
194 gl.DisableVertexAttribArray(array.index);
199GLint BufferBindingsGLES::ComputeTextureLocation(
201 auto location = binding_map_.find(metadata->
name);
202 if (location != binding_map_.end()) {
203 return location->second[0];
205 auto& locations = binding_map_[metadata->
name] = {};
206 auto computed_location =
208 if (computed_location == uniform_locations_.end()) {
209 locations.push_back(-1);
211 locations.push_back(computed_location->second);
216const std::vector<GLint>& BufferBindingsGLES::ComputeUniformLocations(
217 const ShaderMetadata* metadata) {
218 auto location = binding_map_.find(metadata->name);
219 if (location != binding_map_.end()) {
220 return location->second;
225 auto& locations = binding_map_[metadata->name] = {};
226 for (
const auto& member : metadata->members) {
230 locations.push_back(-1);
234 size_t element_count = member.array_elements.value_or(1);
235 const auto member_key =
237 const auto computed_location = uniform_locations_.find(member_key);
238 if (computed_location == uniform_locations_.end()) {
240 locations.push_back(-1);
243 locations.push_back(computed_location->second);
248bool BufferBindingsGLES::BindUniformBuffer(
const ProcTableGLES& gl,
251 const auto* metadata =
buffer.GetMetadata();
252 auto device_buffer =
buffer.resource.buffer;
253 if (!device_buffer) {
258 const uint8_t* buffer_ptr =
259 device_buffer_gles.GetBufferData() +
buffer.resource.range.offset;
261 if (metadata->members.empty()) {
262 VALIDATION_LOG <<
"Uniform buffer had no members. This is currently "
263 "unsupported in the OpenGL ES backend. Use a uniform "
268 const auto& locations = ComputeUniformLocations(metadata);
269 for (
auto i = 0u; i < metadata->members.size(); i++) {
270 const auto& member = metadata->members[i];
271 auto location = locations[i];
277 size_t element_count = member.array_elements.value_or(1);
278 size_t element_stride = member.byte_length / element_count;
280 reinterpret_cast<const GLfloat*
>(buffer_ptr + member.offset);
282 std::vector<uint8_t> array_element_buffer;
283 if (element_count > 1) {
287 array_element_buffer.resize(member.size * element_count);
288 for (
size_t element_i = 0; element_i < element_count; element_i++) {
289 std::memcpy(array_element_buffer.data() + element_i * member.size,
290 reinterpret_cast<const char*
>(buffer_data) +
291 element_i * element_stride,
295 reinterpret_cast<const GLfloat*
>(array_element_buffer.data());
298 switch (member.type) {
300 switch (member.size) {
302 gl.UniformMatrix4fv(location,
308 case sizeof(Vector4):
309 gl.Uniform4fv(location,
314 case sizeof(Vector3):
315 gl.Uniform3fv(location,
321 gl.Uniform2fv(location,
327 gl.Uniform1fv(location,
334 <<
" could not be mapped ShaderType::kFloat for key: "
355 << member.name <<
" : " <<
static_cast<int>(member.type);
362std::optional<size_t> BufferBindingsGLES::BindTextures(
363 const ProcTableGLES& gl,
364 const Bindings& bindings,
366 size_t unit_start_index) {
367 size_t active_index = unit_start_index;
368 for (
const auto& data : bindings.sampled_images) {
370 if (
data.texture.GetMetadata() ==
nullptr) {
375 auto location = ComputeTextureLocation(
data.texture.GetMetadata());
376 if (location == -1) {
383 if (active_index >=
gl.GetCapabilities()->GetMaxTextureUnits(stage)) {
384 VALIDATION_LOG <<
"Texture units specified exceed the capabilities for "
385 "this shader stage.";
388 gl.ActiveTexture(GL_TEXTURE0 + active_index);
393 if (!texture_gles.Bind()) {
402 if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) {
409 gl.Uniform1i(location, active_index);
An object that allocates device memory.
static DeviceBufferGLES & Cast(DeviceBuffer &base)
bool ReadUniformsBindings(const ProcTableGLES &gl, GLuint program)
bool BindVertexAttributes(const ProcTableGLES &gl, size_t vertex_offset) const
bool RegisterVertexStageInput(const ProcTableGLES &gl, const std::vector< ShaderStageIOSlot > &inputs, const std::vector< ShaderStageBufferLayout > &layouts)
bool BindUniformData(const ProcTableGLES &gl, Allocator &transients_allocator, const Bindings &vertex_bindings, const Bindings &fragment_bindings)
bool UnbindVertexAttributes(const ProcTableGLES &gl) const
static const uint8_t buffer[]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
static std::string CreateUniformMemberKey(const std::string &struct_name, const std::string &member, bool is_array)
static constexpr std::string_view kAngleInputAttachmentPrefix
Resource< BufferView > BufferResource
static std::string NormalizeUniformKey(const std::string &key)
constexpr std::optional< GLenum > ToVertexAttribType(ShaderType type)
std::vector< BufferAndUniformSlot > buffers