Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Corentin Wallez | 30965a7 | 2018-07-24 16:42:33 +0200 | [diff] [blame] | 15 | #ifndef DAWNNATIVE_OPENGL_PIPELINEGL_H_ |
| 16 | #define DAWNNATIVE_OPENGL_PIPELINEGL_H_ |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 17 | |
Corentin Wallez | d37523f | 2018-07-24 13:53:51 +0200 | [diff] [blame] | 18 | #include "dawn_native/Pipeline.h" |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 19 | |
Corentin Wallez | 28efed1 | 2020-09-09 22:51:37 +0000 | [diff] [blame] | 20 | #include "dawn_native/PerStage.h" |
Corentin Wallez | 8f4046b | 2019-06-17 09:17:29 +0000 | [diff] [blame] | 21 | #include "dawn_native/opengl/opengl_platform.h" |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 22 | |
| 23 | #include <vector> |
| 24 | |
Corentin Wallez | 28efed1 | 2020-09-09 22:51:37 +0000 | [diff] [blame] | 25 | namespace dawn_native { |
| 26 | struct ProgrammableStage; |
| 27 | } // namespace dawn_native |
| 28 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 29 | namespace dawn_native { namespace opengl { |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 30 | |
Corentin Wallez | df69f24 | 2019-06-13 10:22:32 +0000 | [diff] [blame] | 31 | struct OpenGLFunctions; |
Corentin Wallez | 8e335a5 | 2018-08-27 23:12:56 +0200 | [diff] [blame] | 32 | class PipelineLayout; |
Austin Eng | 2395ff5 | 2020-12-02 16:51:19 +0000 | [diff] [blame] | 33 | class Sampler; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 34 | |
Corentin Wallez | b085eec | 2017-07-14 14:04:52 -0400 | [diff] [blame] | 35 | class PipelineGL { |
Corentin Wallez | c7807ab | 2017-11-24 14:16:15 -0500 | [diff] [blame] | 36 | public: |
Corentin Wallez | 8e335a5 | 2018-08-27 23:12:56 +0200 | [diff] [blame] | 37 | PipelineGL(); |
Austin Eng | 2395ff5 | 2020-12-02 16:51:19 +0000 | [diff] [blame] | 38 | ~PipelineGL(); |
Corentin Wallez | 8e335a5 | 2018-08-27 23:12:56 +0200 | [diff] [blame] | 39 | |
Corentin Wallez | ba9f3a8 | 2019-08-21 13:01:23 +0000 | [diff] [blame] | 40 | // For each unit a sampler is bound to we need to know if we should use filtering or not |
| 41 | // because int and uint texture are only complete without filtering. |
| 42 | struct SamplerUnit { |
| 43 | GLuint unit; |
| 44 | bool shouldUseFiltering; |
| 45 | }; |
| 46 | const std::vector<SamplerUnit>& GetTextureUnitsForSampler(GLuint index) const; |
Jiawei Shao | c72ab8c | 2018-10-29 09:07:25 +0000 | [diff] [blame] | 47 | const std::vector<GLuint>& GetTextureUnitsForTextureView(GLuint index) const; |
Corentin Wallez | c7807ab | 2017-11-24 14:16:15 -0500 | [diff] [blame] | 48 | GLuint GetProgramHandle() const; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 49 | |
Corentin Wallez | cac3e7e | 2021-09-29 09:15:02 +0000 | [diff] [blame] | 50 | protected: |
Jiawei Shao | afe9138 | 2021-10-04 12:31:22 +0000 | [diff] [blame] | 51 | void ApplyNow(const OpenGLFunctions& gl); |
Austin Eng | 8e95716 | 2021-08-03 19:07:29 +0000 | [diff] [blame] | 52 | MaybeError InitializeBase(const OpenGLFunctions& gl, |
| 53 | const PipelineLayout* layout, |
| 54 | const PerStage<ProgrammableStage>& stages); |
Jiawei Shao | afe9138 | 2021-10-04 12:31:22 +0000 | [diff] [blame] | 55 | void DeleteProgram(const OpenGLFunctions& gl); |
Austin Eng | 8e95716 | 2021-08-03 19:07:29 +0000 | [diff] [blame] | 56 | |
Corentin Wallez | c7807ab | 2017-11-24 14:16:15 -0500 | [diff] [blame] | 57 | private: |
| 58 | GLuint mProgram; |
Corentin Wallez | ba9f3a8 | 2019-08-21 13:01:23 +0000 | [diff] [blame] | 59 | std::vector<std::vector<SamplerUnit>> mUnitsForSamplers; |
Corentin Wallez | c7807ab | 2017-11-24 14:16:15 -0500 | [diff] [blame] | 60 | std::vector<std::vector<GLuint>> mUnitsForTextures; |
Austin Eng | 2395ff5 | 2020-12-02 16:51:19 +0000 | [diff] [blame] | 61 | std::vector<GLuint> mDummySamplerUnits; |
| 62 | // TODO(enga): This could live on the Device, or elsewhere, but currently it makes Device |
| 63 | // destruction complex as it requires the sampler to be destroyed before the sampler cache. |
| 64 | Ref<Sampler> mDummySampler; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 67 | }} // namespace dawn_native::opengl |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 68 | |
Corentin Wallez | 30965a7 | 2018-07-24 16:42:33 +0200 | [diff] [blame] | 69 | #endif // DAWNNATIVE_OPENGL_PIPELINEGL_H_ |