summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/webgl/webgl2_compute_rendering_context_base.h
blob: f085dabfafbf6fb5d91d1634a0d9578807575284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL2_COMPUTE_RENDERING_CONTEXT_BASE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL2_COMPUTE_RENDERING_CONTEXT_BASE_H_

#include "third_party/blink/renderer/modules/webgl/webgl2_rendering_context_base.h"
#include "third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h"

namespace blink {

class WebGLProgram;
class WebGLTexture;

class WebGL2ComputeRenderingContextBase : public WebGL2RenderingContextBase {
 public:
  void DestroyContext() override;

  /* Launch one or more compute work groups */
  void dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ);
  void dispatchComputeIndirect(int64_t offset);

  /* Draw indirect */
  void drawArraysIndirect(GLenum mode, int64_t offset);
  void drawElementsIndirect(GLenum mode, GLenum type, int64_t offset);

  /* Program interface query */
  ScriptValue getProgramInterfaceParameter(ScriptState*,
                                           WebGLProgram*,
                                           GLenum program_interface,
                                           GLenum pname);
  GLuint getProgramResourceIndex(WebGLProgram*,
                                 GLenum program_interface,
                                 const String& name);
  String getProgramResourceName(WebGLProgram*,
                                GLenum program_interface,
                                GLuint index);
  base::Optional<HeapVector<ScriptValue>> getProgramResource(
      ScriptState*,
      WebGLProgram*,
      GLenum program_interface,
      GLuint index,
      const Vector<GLenum>& props);
  ScriptValue getProgramResourceLocation(ScriptState*,
                                         WebGLProgram*,
                                         GLenum program_interface,
                                         const String& name);

  /* Bind a level of a texture to an image unit */
  void bindImageTexture(GLuint unit,
                        WebGLTexture* texture,
                        GLint level,
                        GLboolean layered,
                        GLint layer,
                        GLenum access,
                        GLenum format);

  /* Memory access synchronization */
  void memoryBarrier(GLbitfield barriers);
  void memoryBarrierByRegion(GLbitfield barriers);

  /* WebGLRenderingContextBase overrides */
  void InitializeNewContext() override;
  ScriptValue getParameter(ScriptState*, GLenum pname) override;

  /* WebGL2RenderingContextBase overrides */
  ScriptValue getIndexedParameter(ScriptState*,
                                  GLenum target,
                                  GLuint index) override;

  void Trace(Visitor*) const override;

 protected:
  WebGL2ComputeRenderingContextBase(
      CanvasRenderingContextHost*,
      std::unique_ptr<WebGraphicsContext3DProvider>,
      bool using_gpu_compositing,
      const CanvasContextCreationAttributesCore& requested_attributes);

  virtual bool ValidateProgramInterface(const char* function_name,
                                        GLenum program_interface);
  virtual bool ValidateProgramResourceIndex(const char* function_name,
                                            WebGLProgram*,
                                            GLenum program_interface,
                                            GLuint index);
  virtual bool ValidateAndExtendProgramResourceProperties(
      const char* function_name,
      GLenum program_interface,
      const Vector<GLenum>& props,
      Vector<GLenum>& extended_props);

  ScriptValue WrapLocation(ScriptState*,
                           GLint location,
                           WebGLProgram* program,
                           GLenum program_interface);

  /* WebGLRenderingContextBase overrides */
  bool ValidateShaderType(const char* function_name,
                          GLenum shader_type) override;
  bool ValidateBufferTarget(const char* function_name, GLenum target) override;
  WebGLBuffer* ValidateBufferDataTarget(const char* function_name,
                                        GLenum target) override;
  bool ValidateAndUpdateBufferBindTarget(const char* function_name,
                                         GLenum target,
                                         WebGLBuffer*) override;
  void RemoveBoundBuffer(WebGLBuffer*) override;

  /* WebGL2RenderingContextBase overrides */
  bool ValidateBufferTargetCompatibility(const char* function_name,
                                         GLenum target,
                                         WebGLBuffer*) override;
  bool ValidateBufferBaseTarget(const char* function_name,
                                GLenum target) override;
  bool ValidateAndUpdateBufferBindBaseTarget(const char* function_name,
                                             GLenum target,
                                             GLuint index,
                                             WebGLBuffer*) override;

  Member<WebGLBuffer> bound_dispatch_indirect_buffer_;
  Member<WebGLBuffer> bound_draw_indirect_buffer_;
  Member<WebGLBuffer> bound_atomic_counter_buffer_;
  Member<WebGLBuffer> bound_shader_storage_buffer_;

  HeapVector<Member<WebGLBuffer>> bound_indexed_atomic_counter_buffers_;
  HeapVector<Member<WebGLBuffer>> bound_indexed_shader_storage_buffers_;
};

}  // namespace blink

#endif