2019-08-13 22:12:54 +00:00
|
|
|
// Copyright 2019 The Dawn Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "dawn_native/RenderBundleEncoder.h"
|
|
|
|
|
|
|
|
#include "dawn_native/CommandValidation.h"
|
|
|
|
#include "dawn_native/Commands.h"
|
|
|
|
#include "dawn_native/Device.h"
|
2019-08-19 22:49:08 +00:00
|
|
|
#include "dawn_native/Format.h"
|
2019-08-13 22:12:54 +00:00
|
|
|
#include "dawn_native/RenderPipeline.h"
|
|
|
|
#include "dawn_native/ValidationUtils_autogen.h"
|
2019-10-28 23:15:40 +00:00
|
|
|
#include "dawn_platform/DawnPlatform.h"
|
|
|
|
#include "dawn_platform/tracing/TraceEvent.h"
|
2019-08-13 22:12:54 +00:00
|
|
|
|
|
|
|
namespace dawn_native {
|
|
|
|
|
2019-08-19 22:49:08 +00:00
|
|
|
MaybeError ValidateColorAttachmentFormat(const DeviceBase* device,
|
2019-10-23 11:57:41 +00:00
|
|
|
wgpu::TextureFormat textureFormat) {
|
2019-08-19 22:49:08 +00:00
|
|
|
DAWN_TRY(ValidateTextureFormat(textureFormat));
|
|
|
|
const Format* format = nullptr;
|
|
|
|
DAWN_TRY_ASSIGN(format, device->GetInternalFormat(textureFormat));
|
|
|
|
if (!format->IsColor() || !format->isRenderable) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The color attachment texture format is not color renderable");
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeError ValidateDepthStencilAttachmentFormat(const DeviceBase* device,
|
2019-10-23 11:57:41 +00:00
|
|
|
wgpu::TextureFormat textureFormat) {
|
2019-08-19 22:49:08 +00:00
|
|
|
DAWN_TRY(ValidateTextureFormat(textureFormat));
|
|
|
|
const Format* format = nullptr;
|
|
|
|
DAWN_TRY_ASSIGN(format, device->GetInternalFormat(textureFormat));
|
|
|
|
if (!format->HasDepthOrStencil() || !format->isRenderable) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The depth stencil attachment texture format is not a renderable depth/stencil "
|
|
|
|
"format");
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-08-13 22:12:54 +00:00
|
|
|
MaybeError ValidateRenderBundleEncoderDescriptor(
|
|
|
|
const DeviceBase* device,
|
|
|
|
const RenderBundleEncoderDescriptor* descriptor) {
|
|
|
|
if (!IsValidSampleCount(descriptor->sampleCount)) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Sample count is not supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descriptor->colorFormatsCount > kMaxColorAttachments) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Color formats count exceeds maximum");
|
|
|
|
}
|
|
|
|
|
2019-08-27 22:19:16 +00:00
|
|
|
if (descriptor->colorFormatsCount == 0 &&
|
2019-10-23 11:57:41 +00:00
|
|
|
descriptor->depthStencilFormat == wgpu::TextureFormat::Undefined) {
|
2019-08-13 22:12:54 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Should have at least one attachment format");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < descriptor->colorFormatsCount; ++i) {
|
2019-08-19 22:49:08 +00:00
|
|
|
DAWN_TRY(ValidateColorAttachmentFormat(device, descriptor->colorFormats[i]));
|
2019-08-13 22:12:54 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 11:57:41 +00:00
|
|
|
if (descriptor->depthStencilFormat != wgpu::TextureFormat::Undefined) {
|
2019-08-27 22:19:16 +00:00
|
|
|
DAWN_TRY(ValidateDepthStencilAttachmentFormat(device, descriptor->depthStencilFormat));
|
2019-08-13 22:12:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-11-13 17:00:37 +00:00
|
|
|
RenderBundleEncoder::RenderBundleEncoder(DeviceBase* device,
|
|
|
|
const RenderBundleEncoderDescriptor* descriptor)
|
2021-01-27 17:20:16 +00:00
|
|
|
: RenderEncoderBase(device,
|
|
|
|
&mBundleEncodingContext,
|
|
|
|
device->GetOrCreateAttachmentState(descriptor)),
|
|
|
|
mBundleEncodingContext(device, this) {
|
2019-08-13 22:12:54 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 17:00:37 +00:00
|
|
|
RenderBundleEncoder::RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag)
|
2020-04-08 16:04:32 +00:00
|
|
|
: RenderEncoderBase(device, &mBundleEncodingContext, errorTag),
|
|
|
|
mBundleEncodingContext(device, this) {
|
2019-08-13 22:12:54 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 18:36:32 +00:00
|
|
|
// static
|
|
|
|
Ref<RenderBundleEncoder> RenderBundleEncoder::Create(
|
|
|
|
DeviceBase* device,
|
|
|
|
const RenderBundleEncoderDescriptor* descriptor) {
|
|
|
|
return AcquireRef(new RenderBundleEncoder(device, descriptor));
|
|
|
|
}
|
|
|
|
|
2019-08-13 22:12:54 +00:00
|
|
|
// static
|
2019-11-13 17:00:37 +00:00
|
|
|
RenderBundleEncoder* RenderBundleEncoder::MakeError(DeviceBase* device) {
|
|
|
|
return new RenderBundleEncoder(device, ObjectBase::kError);
|
2019-08-13 22:12:54 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 17:00:37 +00:00
|
|
|
CommandIterator RenderBundleEncoder::AcquireCommands() {
|
2020-04-08 16:04:32 +00:00
|
|
|
return mBundleEncodingContext.AcquireCommands();
|
2019-08-13 22:12:54 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 14:02:05 +00:00
|
|
|
RenderBundleBase* RenderBundleEncoder::APIFinish(const RenderBundleDescriptor* descriptor) {
|
2021-01-27 16:03:32 +00:00
|
|
|
RenderBundleBase* result = nullptr;
|
|
|
|
|
|
|
|
if (GetDevice()->ConsumedError(FinishImpl(descriptor), &result)) {
|
|
|
|
return RenderBundleBase::MakeError(GetDevice());
|
|
|
|
}
|
2019-11-21 22:09:41 +00:00
|
|
|
|
2021-01-27 16:03:32 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultOrError<RenderBundleBase*> RenderBundleEncoder::FinishImpl(
|
|
|
|
const RenderBundleDescriptor* descriptor) {
|
2020-04-08 16:04:32 +00:00
|
|
|
// Even if mBundleEncodingContext.Finish() validation fails, calling it will mutate the
|
|
|
|
// internal state of the encoding context. Subsequent calls to encode commands will generate
|
|
|
|
// errors.
|
2021-01-27 16:03:32 +00:00
|
|
|
DAWN_TRY(mBundleEncodingContext.Finish());
|
|
|
|
|
2021-05-05 19:55:23 +00:00
|
|
|
RenderPassResourceUsage usages = mUsageTracker.AcquireResourceUsage();
|
2021-01-27 16:03:32 +00:00
|
|
|
if (IsValidationEnabled()) {
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(this));
|
|
|
|
DAWN_TRY(ValidateProgrammableEncoderEnd());
|
2021-05-05 19:55:23 +00:00
|
|
|
DAWN_TRY(ValidateFinish(usages));
|
2019-08-13 22:12:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 00:15:19 +00:00
|
|
|
return new RenderBundleBase(this, descriptor, AcquireAttachmentState(), std::move(usages),
|
|
|
|
std::move(mIndirectDrawMetadata));
|
2019-08-13 22:12:54 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 19:55:23 +00:00
|
|
|
MaybeError RenderBundleEncoder::ValidateFinish(const RenderPassResourceUsage& usages) const {
|
2019-11-13 17:00:37 +00:00
|
|
|
TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, "RenderBundleEncoder::ValidateFinish");
|
2019-08-13 22:12:54 +00:00
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(this));
|
2021-05-05 15:41:13 +00:00
|
|
|
DAWN_TRY(ValidateSyncScopeResourceUsage(usages));
|
2019-08-13 22:12:54 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dawn_native
|