Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [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_COMMANDBUFFERSTATETRACKER_H |
| 16 | #define DAWNNATIVE_COMMANDBUFFERSTATETRACKER_H |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 17 | |
Corentin Wallez | fffe6df | 2017-07-06 14:41:13 -0400 | [diff] [blame] | 18 | #include "common/Constants.h" |
Austin Eng | 250f262 | 2020-06-20 01:30:32 +0000 | [diff] [blame] | 19 | #include "common/ityp_array.h" |
Austin Eng | 4099f65 | 2020-09-17 19:07:00 +0000 | [diff] [blame] | 20 | #include "common/ityp_bitset.h" |
Idan Raiter | f434fdc | 2020-06-19 21:39:23 +0000 | [diff] [blame] | 21 | #include "dawn_native/BindingInfo.h" |
Corentin Wallez | f20f5b9 | 2019-02-20 11:46:16 +0000 | [diff] [blame] | 22 | #include "dawn_native/Error.h" |
| 23 | #include "dawn_native/Forward.h" |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 24 | |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 25 | #include <map> |
| 26 | #include <set> |
| 27 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 28 | namespace dawn_native { |
Corentin Wallez | aa13be9 | 2018-07-10 18:03:22 +0200 | [diff] [blame] | 29 | |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 30 | class CommandBufferStateTracker { |
Corentin Wallez | c1400f0 | 2017-11-24 13:59:42 -0500 | [diff] [blame] | 31 | public: |
Corentin Wallez | c1400f0 | 2017-11-24 13:59:42 -0500 | [diff] [blame] | 32 | // Non-state-modifying validation functions |
Corentin Wallez | 021c950 | 2018-07-16 18:20:09 +0200 | [diff] [blame] | 33 | MaybeError ValidateCanDispatch(); |
Jiawei Shao | c789b84 | 2018-12-10 05:20:19 +0000 | [diff] [blame] | 34 | MaybeError ValidateCanDraw(); |
| 35 | MaybeError ValidateCanDrawIndexed(); |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 36 | |
Corentin Wallez | c1400f0 | 2017-11-24 13:59:42 -0500 | [diff] [blame] | 37 | // State-modifying methods |
Corentin Wallez | 021c950 | 2018-07-16 18:20:09 +0200 | [diff] [blame] | 38 | void SetComputePipeline(ComputePipelineBase* pipeline); |
| 39 | void SetRenderPipeline(RenderPipelineBase* pipeline); |
Austin Eng | 250f262 | 2020-06-20 01:30:32 +0000 | [diff] [blame] | 40 | void SetBindGroup(BindGroupIndex index, BindGroupBase* bindgroup); |
shrekshao | 232f4d1 | 2021-02-23 16:37:29 +0000 | [diff] [blame] | 41 | void SetIndexBuffer(wgpu::IndexFormat format, uint64_t size); |
Austin Eng | 4099f65 | 2020-09-17 19:07:00 +0000 | [diff] [blame] | 42 | void SetVertexBuffer(VertexBufferSlot slot); |
Corentin Wallez | 1ea205f | 2018-07-18 18:23:08 +0200 | [diff] [blame] | 43 | |
| 44 | static constexpr size_t kNumAspects = 4; |
| 45 | using ValidationAspects = std::bitset<kNumAspects>; |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 46 | |
shrekshao | 232f4d1 | 2021-02-23 16:37:29 +0000 | [diff] [blame] | 47 | uint64_t GetIndexBufferSize() { |
| 48 | return mIndexBufferSize; |
| 49 | } |
| 50 | wgpu::IndexFormat GetIndexFormat() { |
| 51 | return mIndexFormat; |
| 52 | } |
Corentin Wallez | 76732ab | 2021-05-06 19:20:14 +0000 | [diff] [blame] | 53 | BindGroupBase* GetBindGroup(BindGroupIndex index) const; |
| 54 | PipelineLayoutBase* GetPipelineLayout() const; |
shrekshao | 232f4d1 | 2021-02-23 16:37:29 +0000 | [diff] [blame] | 55 | |
Corentin Wallez | c1400f0 | 2017-11-24 13:59:42 -0500 | [diff] [blame] | 56 | private: |
Corentin Wallez | 1ea205f | 2018-07-18 18:23:08 +0200 | [diff] [blame] | 57 | MaybeError ValidateOperation(ValidationAspects requiredAspects); |
| 58 | void RecomputeLazyAspects(ValidationAspects aspects); |
Yunchao He | 798cefb | 2020-05-04 06:05:47 +0000 | [diff] [blame] | 59 | MaybeError CheckMissingAspects(ValidationAspects aspects); |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 60 | |
Corentin Wallez | c1400f0 | 2017-11-24 13:59:42 -0500 | [diff] [blame] | 61 | void SetPipelineCommon(PipelineBase* pipeline); |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 62 | |
Corentin Wallez | c1400f0 | 2017-11-24 13:59:42 -0500 | [diff] [blame] | 63 | ValidationAspects mAspects; |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 64 | |
Austin Eng | 250f262 | 2020-06-20 01:30:32 +0000 | [diff] [blame] | 65 | ityp::array<BindGroupIndex, BindGroupBase*, kMaxBindGroups> mBindgroups = {}; |
Austin Eng | 4099f65 | 2020-09-17 19:07:00 +0000 | [diff] [blame] | 66 | ityp::bitset<VertexBufferSlot, kMaxVertexBuffers> mVertexBufferSlotsUsed; |
Brandon Jones | 8575cb3 | 2020-08-27 01:13:35 +0000 | [diff] [blame] | 67 | bool mIndexBufferSet = false; |
| 68 | wgpu::IndexFormat mIndexFormat; |
shrekshao | 232f4d1 | 2021-02-23 16:37:29 +0000 | [diff] [blame] | 69 | uint64_t mIndexBufferSize = 0; |
Corentin Wallez | 1ea205f | 2018-07-18 18:23:08 +0200 | [diff] [blame] | 70 | |
| 71 | PipelineLayoutBase* mLastPipelineLayout = nullptr; |
Corentin Wallez | c1400f0 | 2017-11-24 13:59:42 -0500 | [diff] [blame] | 72 | RenderPipelineBase* mLastRenderPipeline = nullptr; |
Idan Raiter | f434fdc | 2020-06-19 21:39:23 +0000 | [diff] [blame] | 73 | |
Corentin Wallez | 9ed8d51 | 2020-08-28 14:26:00 +0000 | [diff] [blame] | 74 | const RequiredBufferSizes* mMinBufferSizes = nullptr; |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 75 | }; |
Corentin Wallez | aa13be9 | 2018-07-10 18:03:22 +0200 | [diff] [blame] | 76 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 77 | } // namespace dawn_native |
Kai Ninomiya | 468dafd | 2017-06-08 17:25:57 -0700 | [diff] [blame] | 78 | |
Corentin Wallez | 30965a7 | 2018-07-24 16:42:33 +0200 | [diff] [blame] | 79 | #endif // DAWNNATIVE_COMMANDBUFFERSTATETRACKER_H |