2018-09-21 00:24:37 +00:00
|
|
|
// Copyright 2018 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/RenderPassEncoder.h"
|
|
|
|
|
2019-06-10 20:56:27 +00:00
|
|
|
#include "common/Constants.h"
|
2018-09-21 00:24:37 +00:00
|
|
|
#include "dawn_native/Buffer.h"
|
2019-02-20 11:46:16 +00:00
|
|
|
#include "dawn_native/CommandEncoder.h"
|
2018-09-21 00:24:37 +00:00
|
|
|
#include "dawn_native/Commands.h"
|
2019-02-13 13:09:18 +00:00
|
|
|
#include "dawn_native/Device.h"
|
2018-09-21 00:24:37 +00:00
|
|
|
#include "dawn_native/RenderPipeline.h"
|
|
|
|
|
2019-07-04 15:30:59 +00:00
|
|
|
#include <math.h>
|
2019-07-23 17:04:34 +00:00
|
|
|
#include <cstring>
|
2018-12-03 14:28:04 +00:00
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
namespace dawn_native {
|
|
|
|
|
|
|
|
RenderPassEncoderBase::RenderPassEncoderBase(DeviceBase* device,
|
2019-02-20 11:46:16 +00:00
|
|
|
CommandEncoderBase* topLevelEncoder,
|
2018-09-21 00:24:37 +00:00
|
|
|
CommandAllocator* allocator)
|
2019-07-20 01:34:56 +00:00
|
|
|
: RenderEncoderBase(device, topLevelEncoder, allocator) {
|
2018-09-21 00:24:37 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 01:02:47 +00:00
|
|
|
RenderPassEncoderBase::RenderPassEncoderBase(DeviceBase* device,
|
|
|
|
CommandEncoderBase* topLevelEncoder,
|
|
|
|
ErrorTag errorTag)
|
2019-07-20 01:34:56 +00:00
|
|
|
: RenderEncoderBase(device, topLevelEncoder, errorTag) {
|
2019-03-05 01:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderPassEncoderBase* RenderPassEncoderBase::MakeError(DeviceBase* device,
|
|
|
|
CommandEncoderBase* topLevelEncoder) {
|
|
|
|
return new RenderPassEncoderBase(device, topLevelEncoder, ObjectBase::kError);
|
|
|
|
}
|
|
|
|
|
2019-07-20 01:34:56 +00:00
|
|
|
void RenderPassEncoderBase::EndPass() {
|
2019-02-20 11:46:16 +00:00
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
2018-11-21 11:19:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-20 01:34:56 +00:00
|
|
|
mTopLevelEncoder->PassEnded();
|
|
|
|
mAllocator = nullptr;
|
2018-09-21 00:24:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderPassEncoderBase::SetStencilReference(uint32_t reference) {
|
2019-02-20 11:46:16 +00:00
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
2018-11-21 11:19:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
SetStencilReferenceCmd* cmd =
|
|
|
|
mAllocator->Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
|
|
|
|
cmd->reference = reference;
|
|
|
|
}
|
|
|
|
|
2019-02-05 12:13:10 +00:00
|
|
|
void RenderPassEncoderBase::SetBlendColor(const Color* color) {
|
2019-02-20 11:46:16 +00:00
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
2018-11-21 11:19:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
SetBlendColorCmd* cmd = mAllocator->Allocate<SetBlendColorCmd>(Command::SetBlendColor);
|
2019-02-05 12:13:10 +00:00
|
|
|
cmd->color = *color;
|
2018-09-21 00:24:37 +00:00
|
|
|
}
|
|
|
|
|
2019-07-04 15:30:59 +00:00
|
|
|
void RenderPassEncoderBase::SetViewport(float x,
|
|
|
|
float y,
|
|
|
|
float width,
|
|
|
|
float height,
|
|
|
|
float minDepth,
|
|
|
|
float maxDepth) {
|
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isnan(x) || isnan(y) || isnan(width) || isnan(height) || isnan(minDepth) ||
|
|
|
|
isnan(maxDepth)) {
|
|
|
|
mTopLevelEncoder->HandleError("NaN is not allowed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(yunchao.he@intel.com): there are more restrictions for x, y, width and height in
|
|
|
|
// Vulkan, and height can be a negative value in Vulkan 1.1. Revisit this part later (say,
|
|
|
|
// for WebGPU v1).
|
|
|
|
if (width <= 0 || height <= 0) {
|
|
|
|
mTopLevelEncoder->HandleError("Width and height must be greater than 0.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minDepth < 0 || minDepth > 1 || maxDepth < 0 || maxDepth > 1) {
|
|
|
|
mTopLevelEncoder->HandleError("minDepth and maxDepth must be in [0, 1].");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetViewportCmd* cmd = mAllocator->Allocate<SetViewportCmd>(Command::SetViewport);
|
|
|
|
cmd->x = x;
|
|
|
|
cmd->y = y;
|
|
|
|
cmd->width = width;
|
|
|
|
cmd->height = height;
|
|
|
|
cmd->minDepth = minDepth;
|
|
|
|
cmd->maxDepth = maxDepth;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
void RenderPassEncoderBase::SetScissorRect(uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height) {
|
2019-02-20 11:46:16 +00:00
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
2018-11-21 11:19:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-02 07:42:18 +00:00
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
mTopLevelEncoder->HandleError("Width and height must be greater than 0.");
|
|
|
|
return;
|
|
|
|
}
|
2018-11-21 11:19:36 +00:00
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
SetScissorRectCmd* cmd = mAllocator->Allocate<SetScissorRectCmd>(Command::SetScissorRect);
|
|
|
|
cmd->x = x;
|
|
|
|
cmd->y = y;
|
|
|
|
cmd->width = width;
|
|
|
|
cmd->height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dawn_native
|