blob: 8c223cf86d2bde16632a700900a3e37c7fda4241 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Kai Ninomiya468dafd2017-06-08 17:25:57 -07002//
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 Wallez30965a72018-07-24 16:42:33 +020015#ifndef DAWNNATIVE_COMMANDBUFFERSTATETRACKER_H
16#define DAWNNATIVE_COMMANDBUFFERSTATETRACKER_H
Kai Ninomiya468dafd2017-06-08 17:25:57 -070017
Corentin Wallezfffe6df2017-07-06 14:41:13 -040018#include "common/Constants.h"
Austin Eng250f2622020-06-20 01:30:32 +000019#include "common/ityp_array.h"
Austin Eng4099f652020-09-17 19:07:00 +000020#include "common/ityp_bitset.h"
Idan Raiterf434fdc2020-06-19 21:39:23 +000021#include "dawn_native/BindingInfo.h"
Corentin Wallezf20f5b92019-02-20 11:46:16 +000022#include "dawn_native/Error.h"
23#include "dawn_native/Forward.h"
Kai Ninomiya468dafd2017-06-08 17:25:57 -070024
Kai Ninomiya468dafd2017-06-08 17:25:57 -070025#include <map>
26#include <set>
27
Corentin Wallez49a65d02018-07-24 16:45:45 +020028namespace dawn_native {
Corentin Wallezaa13be92018-07-10 18:03:22 +020029
Kai Ninomiya468dafd2017-06-08 17:25:57 -070030 class CommandBufferStateTracker {
Corentin Wallezc1400f02017-11-24 13:59:42 -050031 public:
Corentin Wallezc1400f02017-11-24 13:59:42 -050032 // Non-state-modifying validation functions
Corentin Wallez021c9502018-07-16 18:20:09 +020033 MaybeError ValidateCanDispatch();
Jiawei Shaoc789b842018-12-10 05:20:19 +000034 MaybeError ValidateCanDraw();
35 MaybeError ValidateCanDrawIndexed();
Kai Ninomiya468dafd2017-06-08 17:25:57 -070036
Corentin Wallezc1400f02017-11-24 13:59:42 -050037 // State-modifying methods
Corentin Wallez021c9502018-07-16 18:20:09 +020038 void SetComputePipeline(ComputePipelineBase* pipeline);
39 void SetRenderPipeline(RenderPipelineBase* pipeline);
Austin Eng250f2622020-06-20 01:30:32 +000040 void SetBindGroup(BindGroupIndex index, BindGroupBase* bindgroup);
shrekshao232f4d12021-02-23 16:37:29 +000041 void SetIndexBuffer(wgpu::IndexFormat format, uint64_t size);
Austin Eng4099f652020-09-17 19:07:00 +000042 void SetVertexBuffer(VertexBufferSlot slot);
Corentin Wallez1ea205f2018-07-18 18:23:08 +020043
44 static constexpr size_t kNumAspects = 4;
45 using ValidationAspects = std::bitset<kNumAspects>;
Kai Ninomiya468dafd2017-06-08 17:25:57 -070046
shrekshao232f4d12021-02-23 16:37:29 +000047 uint64_t GetIndexBufferSize() {
48 return mIndexBufferSize;
49 }
50 wgpu::IndexFormat GetIndexFormat() {
51 return mIndexFormat;
52 }
Corentin Wallez76732ab2021-05-06 19:20:14 +000053 BindGroupBase* GetBindGroup(BindGroupIndex index) const;
54 PipelineLayoutBase* GetPipelineLayout() const;
shrekshao232f4d12021-02-23 16:37:29 +000055
Corentin Wallezc1400f02017-11-24 13:59:42 -050056 private:
Corentin Wallez1ea205f2018-07-18 18:23:08 +020057 MaybeError ValidateOperation(ValidationAspects requiredAspects);
58 void RecomputeLazyAspects(ValidationAspects aspects);
Yunchao He798cefb2020-05-04 06:05:47 +000059 MaybeError CheckMissingAspects(ValidationAspects aspects);
Kai Ninomiya468dafd2017-06-08 17:25:57 -070060
Corentin Wallezc1400f02017-11-24 13:59:42 -050061 void SetPipelineCommon(PipelineBase* pipeline);
Kai Ninomiya468dafd2017-06-08 17:25:57 -070062
Corentin Wallezc1400f02017-11-24 13:59:42 -050063 ValidationAspects mAspects;
Kai Ninomiya468dafd2017-06-08 17:25:57 -070064
Austin Eng250f2622020-06-20 01:30:32 +000065 ityp::array<BindGroupIndex, BindGroupBase*, kMaxBindGroups> mBindgroups = {};
Austin Eng4099f652020-09-17 19:07:00 +000066 ityp::bitset<VertexBufferSlot, kMaxVertexBuffers> mVertexBufferSlotsUsed;
Brandon Jones8575cb32020-08-27 01:13:35 +000067 bool mIndexBufferSet = false;
68 wgpu::IndexFormat mIndexFormat;
shrekshao232f4d12021-02-23 16:37:29 +000069 uint64_t mIndexBufferSize = 0;
Corentin Wallez1ea205f2018-07-18 18:23:08 +020070
71 PipelineLayoutBase* mLastPipelineLayout = nullptr;
Corentin Wallezc1400f02017-11-24 13:59:42 -050072 RenderPipelineBase* mLastRenderPipeline = nullptr;
Idan Raiterf434fdc2020-06-19 21:39:23 +000073
Corentin Wallez9ed8d512020-08-28 14:26:00 +000074 const RequiredBufferSizes* mMinBufferSizes = nullptr;
Kai Ninomiya468dafd2017-06-08 17:25:57 -070075 };
Corentin Wallezaa13be92018-07-10 18:03:22 +020076
Corentin Wallez49a65d02018-07-24 16:45:45 +020077} // namespace dawn_native
Kai Ninomiya468dafd2017-06-08 17:25:57 -070078
Corentin Wallez30965a72018-07-24 16:42:33 +020079#endif // DAWNNATIVE_COMMANDBUFFERSTATETRACKER_H