1 // Copyright 2019 The Dawn Authors 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 15 #include "dawn_native/RenderBundle.h" 16 17 #include "common/BitSetIterator.h" 18 #include "dawn_native/Commands.h" 19 #include "dawn_native/Device.h" 20 #include "dawn_native/ObjectType_autogen.h" 21 #include "dawn_native/RenderBundleEncoder.h" 22 23 namespace dawn_native { 24 RenderBundleBase(RenderBundleEncoder * encoder,const RenderBundleDescriptor * descriptor,Ref<AttachmentState> attachmentState,bool depthReadOnly,bool stencilReadOnly,RenderPassResourceUsage resourceUsage,IndirectDrawMetadata indirectDrawMetadata)25 RenderBundleBase::RenderBundleBase(RenderBundleEncoder* encoder, 26 const RenderBundleDescriptor* descriptor, 27 Ref<AttachmentState> attachmentState, 28 bool depthReadOnly, 29 bool stencilReadOnly, 30 RenderPassResourceUsage resourceUsage, 31 IndirectDrawMetadata indirectDrawMetadata) 32 : ApiObjectBase(encoder->GetDevice(), kLabelNotImplemented), 33 mCommands(encoder->AcquireCommands()), 34 mIndirectDrawMetadata(std::move(indirectDrawMetadata)), 35 mAttachmentState(std::move(attachmentState)), 36 mDepthReadOnly(depthReadOnly), 37 mStencilReadOnly(stencilReadOnly), 38 mResourceUsage(std::move(resourceUsage)) { 39 TrackInDevice(); 40 } 41 DestroyImpl()42 void RenderBundleBase::DestroyImpl() { 43 FreeCommands(&mCommands); 44 45 // Remove reference to the attachment state so that we don't have lingering references to 46 // it preventing it from being uncached in the device. 47 mAttachmentState = nullptr; 48 } 49 50 // static MakeError(DeviceBase * device)51 RenderBundleBase* RenderBundleBase::MakeError(DeviceBase* device) { 52 return new RenderBundleBase(device, ObjectBase::kError); 53 } 54 RenderBundleBase(DeviceBase * device,ErrorTag errorTag)55 RenderBundleBase::RenderBundleBase(DeviceBase* device, ErrorTag errorTag) 56 : ApiObjectBase(device, errorTag), mIndirectDrawMetadata(device->GetLimits()) { 57 } 58 GetType() const59 ObjectType RenderBundleBase::GetType() const { 60 return ObjectType::RenderBundle; 61 } 62 GetCommands()63 CommandIterator* RenderBundleBase::GetCommands() { 64 return &mCommands; 65 } 66 GetAttachmentState() const67 const AttachmentState* RenderBundleBase::GetAttachmentState() const { 68 ASSERT(!IsError()); 69 return mAttachmentState.Get(); 70 } 71 IsDepthReadOnly() const72 bool RenderBundleBase::IsDepthReadOnly() const { 73 ASSERT(!IsError()); 74 return mDepthReadOnly; 75 } 76 IsStencilReadOnly() const77 bool RenderBundleBase::IsStencilReadOnly() const { 78 ASSERT(!IsError()); 79 return mStencilReadOnly; 80 } 81 GetResourceUsage() const82 const RenderPassResourceUsage& RenderBundleBase::GetResourceUsage() const { 83 ASSERT(!IsError()); 84 return mResourceUsage; 85 } 86 GetIndirectDrawMetadata()87 const IndirectDrawMetadata& RenderBundleBase::GetIndirectDrawMetadata() { 88 return mIndirectDrawMetadata; 89 } 90 91 } // namespace dawn_native 92