Split AttachmentStateDescriptor, in order to match web idl

AttachmentStateDescriptor was removed in web idl. Its format info
for color attachment and depth/stencil attachment were split and
added into BlendStateDescriptor (renamed to ColorStateDescriptor)
and DepthStencilStateDescriptor (became optional) respectively.

This change makes dawn project match the revision in web idl.

BUG=dawn:106, dawn:102

Change-Id: If57b060db7b4b5d1124b4a79a3b92a3880047722
Reviewed-on: https://dawn-review.googlesource.com/c/4561
Commit-Queue: Yunchao He <yunchao.he@intel.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Yunchao He 2019-02-15 02:20:57 +00:00 committed by Commit Bot service account
parent 4dec7371a2
commit 108bcbd5c9
32 changed files with 178 additions and 270 deletions

View File

@ -23,13 +23,6 @@
{"value": 3, "name": "clamp to border color"}
]
},
"attachment descriptor": {
"category": "structure",
"extensible": true,
"members": [
{"name": "format", "type": "texture format"}
]
},
"bind group": {
"category": "object"
},
@ -120,10 +113,11 @@
{"value": 4, "name": "max"}
]
},
"blend state descriptor": {
"color state descriptor": {
"category": "structure",
"extensible": true,
"members": [
{"name": "format", "type": "texture format"},
{"name": "alpha blend", "type": "blend descriptor"},
{"name": "color blend", "type": "blend descriptor"},
{"name": "color write mask", "type": "color write mask"}
@ -507,6 +501,7 @@
"category": "structure",
"extensible": true,
"members": [
{"name": "format", "type": "texture format"},
{"name": "depth write enabled", "type": "bool"},
{"name": "depth compare", "type": "compare function"},
{"name": "stencil front", "type": "stencil state face descriptor"},
@ -659,16 +654,6 @@
{"name": "z", "type": "uint32_t"}
]
},
"attachments state descriptor": {
"category": "structure",
"extensible": true,
"members": [
{"name": "num color attachments", "type": "uint32_t"},
{"name": "color attachments", "type": "attachment descriptor", "annotation": "const*const*", "length": "num color attachments"},
{"name": "has depth stencil attachment", "type": "bool"},
{"name": "depth stencil attachment", "type": "attachment descriptor", "annotation":"const*"}
]
},
"pipeline layout": {
"category": "object"
},
@ -872,11 +857,10 @@
{"name": "input state", "type": "input state"},
{"name": "index format", "type": "index format"},
{"name": "primitive topology", "type": "primitive topology"},
{"name": "attachments state", "type": "attachments state descriptor", "annotation": "const*"},
{"name": "sample count", "type": "uint32_t"},
{"name": "depth stencil state", "type": "depth stencil state descriptor", "annotation": "const*", "optional": true},
{"name": "num blend states", "type": "uint32_t"},
{"name": "blend states", "type": "blend state descriptor", "annotation": "const*", "length": "num blend states"}
{"name": "num color states", "type": "uint32_t"},
{"name": "color states", "type": "color state descriptor", "annotation": "const*", "length": "num color states"}
]
},
"sampler": {

View File

@ -113,9 +113,9 @@ void init() {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cAttachmentsState.hasDepthStencilAttachment = true;
descriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorAttachments[0]->format = GetPreferredSwapChainTextureFormat();
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
pipeline = device.CreateRenderPipeline(&descriptor);

View File

@ -71,32 +71,21 @@ void init() {
fragmentStage.entryPoint = "main";
descriptor.fragmentStage = &fragmentStage;
dawnAttachmentsStateDescriptor attachmentsState;
attachmentsState.nextInChain = nullptr;
attachmentsState.numColorAttachments = 1;
dawnAttachmentDescriptor colorAttachment = {nullptr, swapChainFormat};
dawnAttachmentDescriptor* colorAttachmentPtr[] = {&colorAttachment};
attachmentsState.colorAttachments = colorAttachmentPtr;
attachmentsState.hasDepthStencilAttachment = false;
// Even with hasDepthStencilAttachment = false, depthStencilAttachment must point to valid
// data because we don't have optional substructures yet.
attachmentsState.depthStencilAttachment = &colorAttachment;
descriptor.attachmentsState = &attachmentsState;
descriptor.sampleCount = 1;
descriptor.numBlendStates = 1;
descriptor.numColorStates = 1;
dawnBlendDescriptor blendDescriptor;
blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD;
blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE;
blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE;
dawnBlendStateDescriptor blendStateDescriptor;
blendStateDescriptor.nextInChain = nullptr;
blendStateDescriptor.alphaBlend = blendDescriptor;
blendStateDescriptor.colorBlend = blendDescriptor;
blendStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
descriptor.blendStates = &blendStateDescriptor;
dawnColorStateDescriptor colorStateDescriptor;
colorStateDescriptor.nextInChain = nullptr;
colorStateDescriptor.format = swapChainFormat;
colorStateDescriptor.alphaBlend = blendDescriptor;
colorStateDescriptor.colorBlend = blendDescriptor;
colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
descriptor.colorStates = &colorStateDescriptor;
dawnPipelineLayoutDescriptor pl;
pl.nextInChain = nullptr;
@ -111,21 +100,7 @@ void init() {
descriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32;
descriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
dawnStencilStateFaceDescriptor stencilFace;
stencilFace.compare = DAWN_COMPARE_FUNCTION_ALWAYS;
stencilFace.failOp = DAWN_STENCIL_OPERATION_KEEP;
stencilFace.depthFailOp = DAWN_STENCIL_OPERATION_KEEP;
stencilFace.passOp = DAWN_STENCIL_OPERATION_KEEP;
dawnDepthStencilStateDescriptor depthStencilState;
depthStencilState.nextInChain = nullptr;
depthStencilState.depthWriteEnabled = false;
depthStencilState.depthCompare = DAWN_COMPARE_FUNCTION_ALWAYS;
depthStencilState.stencilBack = stencilFace;
depthStencilState.stencilFront = stencilFace;
depthStencilState.stencilReadMask = 0xff;
depthStencilState.stencilWriteMask = 0xff;
descriptor.depthStencilState = &depthStencilState;
descriptor.depthStencilState = nullptr;
pipeline = dawnDeviceCreateRenderPipeline(device, &descriptor);

View File

@ -156,9 +156,9 @@ void initRender() {
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.inputState = inputState;
descriptor.cAttachmentsState.hasDepthStencilAttachment = true;
descriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorAttachments[0]->format = GetPreferredSwapChainTextureFormat();
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
renderPipeline = device.CreateRenderPipeline(&descriptor);
}

View File

@ -140,9 +140,9 @@ void init() {
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.inputState = inputState;
descriptor.cAttachmentsState.hasDepthStencilAttachment = true;
descriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorAttachments[0]->format = GetPreferredSwapChainTextureFormat();
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
pipeline = device.CreateRenderPipeline(&descriptor);

View File

@ -215,9 +215,9 @@ void init() {
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.inputState = inputState;
descriptor.cAttachmentsState.hasDepthStencilAttachment = true;
descriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorAttachments[0]->format = GetPreferredSwapChainTextureFormat();
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
descriptor.cDepthStencilState.depthWriteEnabled = true;
descriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::Less;
@ -228,9 +228,9 @@ void init() {
pDescriptor.cVertexStage.module = vsModule;
pDescriptor.cFragmentStage.module = fsModule;
pDescriptor.inputState = inputState;
pDescriptor.cAttachmentsState.hasDepthStencilAttachment = true;
pDescriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
pDescriptor.cColorAttachments[0]->format = GetPreferredSwapChainTextureFormat();
pDescriptor.depthStencilState = &pDescriptor.cDepthStencilState;
pDescriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
pDescriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
pDescriptor.cDepthStencilState.stencilFront.passOp = dawn::StencilOperation::Replace;
pDescriptor.cDepthStencilState.stencilBack.passOp = dawn::StencilOperation::Replace;
pDescriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::Less;
@ -242,9 +242,9 @@ void init() {
rfDescriptor.cVertexStage.module = vsModule;
rfDescriptor.cFragmentStage.module = fsReflectionModule;
rfDescriptor.inputState = inputState;
rfDescriptor.cAttachmentsState.hasDepthStencilAttachment = true;
rfDescriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
rfDescriptor.cColorAttachments[0]->format = GetPreferredSwapChainTextureFormat();
rfDescriptor.depthStencilState = &rfDescriptor.cDepthStencilState;
rfDescriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
rfDescriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
rfDescriptor.cDepthStencilState.stencilFront.compare = dawn::CompareFunction::Equal;
rfDescriptor.cDepthStencilState.stencilBack.compare = dawn::CompareFunction::Equal;
rfDescriptor.cDepthStencilState.stencilFront.passOp = dawn::StencilOperation::Replace;

View File

@ -319,9 +319,9 @@ namespace {
descriptor.cFragmentStage.module = oFSModule;
descriptor.inputState = inputState;
descriptor.indexFormat = dawn::IndexFormat::Uint16;
descriptor.cAttachmentsState.hasDepthStencilAttachment = true;
descriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorAttachments[0]->format = GetPreferredSwapChainTextureFormat();
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
descriptor.cDepthStencilState.depthWriteEnabled = true;
descriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::Less;

View File

@ -43,38 +43,7 @@ namespace dawn_native {
return {};
}
MaybeError ValidateAttachmentsStateDescriptor(
const AttachmentsStateDescriptor* descriptor) {
if (descriptor->numColorAttachments > kMaxColorAttachments) {
return DAWN_VALIDATION_ERROR("Color attachments number exceeds maximum");
}
if (descriptor->numColorAttachments == 0 && !descriptor->hasDepthStencilAttachment) {
return DAWN_VALIDATION_ERROR("Should have at least one attachment");
}
if (descriptor->hasDepthStencilAttachment) {
dawn::TextureFormat format = descriptor->depthStencilAttachment->format;
DAWN_TRY(ValidateTextureFormat(format));
if (!IsDepthStencilRenderableTextureFormat(format)) {
return DAWN_VALIDATION_ERROR(
"Depth stencil format must be depth-stencil renderable");
}
}
for (uint32_t i = 0; i < descriptor->numColorAttachments; ++i) {
dawn::TextureFormat format = descriptor->colorAttachments[i]->format;
DAWN_TRY(ValidateTextureFormat(format));
if (!IsColorRenderableTextureFormat(format)) {
return DAWN_VALIDATION_ERROR("Color format must be color renderable");
}
}
return {};
}
MaybeError ValidateBlendStateDescriptor(const BlendStateDescriptor* descriptor) {
MaybeError ValidateColorStateDescriptor(const ColorStateDescriptor* descriptor) {
if (descriptor->nextInChain != nullptr) {
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
}
@ -85,6 +54,13 @@ namespace dawn_native {
DAWN_TRY(ValidateBlendFactor(descriptor->colorBlend.srcFactor));
DAWN_TRY(ValidateBlendFactor(descriptor->colorBlend.dstFactor));
DAWN_TRY(ValidateColorWriteMask(descriptor->colorWriteMask));
dawn::TextureFormat format = descriptor->format;
DAWN_TRY(ValidateTextureFormat(format));
if (!IsColorRenderableTextureFormat(format)) {
return DAWN_VALIDATION_ERROR("Color format must be color renderable");
}
return {};
}
@ -102,6 +78,14 @@ namespace dawn_native {
DAWN_TRY(ValidateStencilOperation(descriptor->stencilBack.failOp));
DAWN_TRY(ValidateStencilOperation(descriptor->stencilBack.depthFailOp));
DAWN_TRY(ValidateStencilOperation(descriptor->stencilBack.passOp));
dawn::TextureFormat format = descriptor->format;
DAWN_TRY(ValidateTextureFormat(format));
if (!IsDepthStencilRenderableTextureFormat(format)) {
return DAWN_VALIDATION_ERROR(
"Depth stencil format must be depth-stencil renderable");
}
return {};
}
@ -119,17 +103,12 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("Input state must not be null");
}
for (uint32_t i = 0; i < descriptor->numBlendStates; ++i) {
DAWN_TRY(ValidateBlendStateDescriptor(&descriptor->blendStates[i]));
}
DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat));
DAWN_TRY(ValidatePrimitiveTopology(descriptor->primitiveTopology));
DAWN_TRY(ValidatePipelineStageDescriptor(device, descriptor->vertexStage,
descriptor->layout, dawn::ShaderStage::Vertex));
DAWN_TRY(ValidatePipelineStageDescriptor(device, descriptor->fragmentStage,
descriptor->layout, dawn::ShaderStage::Fragment));
DAWN_TRY(ValidateAttachmentsStateDescriptor(descriptor->attachmentsState));
if ((descriptor->vertexStage->module->GetUsedVertexAttributes() &
~descriptor->inputState->GetAttributesSetMask())
@ -142,15 +121,21 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("Sample count must be one");
}
if (descriptor->numBlendStates > kMaxColorAttachments) {
return DAWN_VALIDATION_ERROR("Blend states number exceeds maximum");
if (descriptor->numColorStates > kMaxColorAttachments) {
return DAWN_VALIDATION_ERROR("Color States number exceeds maximum");
}
if (descriptor->attachmentsState->numColorAttachments != descriptor->numBlendStates) {
return DAWN_VALIDATION_ERROR("Each color attachment should have blend state");
if (descriptor->numColorStates == 0 && !descriptor->depthStencilState) {
return DAWN_VALIDATION_ERROR("Should have at least one attachment");
}
DAWN_TRY(ValidateDepthStencilStateDescriptor(descriptor->depthStencilState));
for (uint32_t i = 0; i < descriptor->numColorStates; ++i) {
DAWN_TRY(ValidateColorStateDescriptor(&descriptor->colorStates[i]));
}
if (descriptor->depthStencilState) {
DAWN_TRY(ValidateDepthStencilStateDescriptor(descriptor->depthStencilState));
}
return {};
}
@ -166,7 +151,7 @@ namespace dawn_native {
mDepthStencilState->stencilFront.passOp != dawn::StencilOperation::Keep;
}
bool BlendEnabled(const BlendStateDescriptor* mBlendState) {
bool BlendEnabled(const ColorStateDescriptor* mBlendState) {
return mBlendState->alphaBlend.operation != dawn::BlendOperation::Add ||
mBlendState->alphaBlend.srcFactor != dawn::BlendFactor::One ||
mBlendState->alphaBlend.dstFactor != dawn::BlendFactor::Zero ||
@ -182,21 +167,36 @@ namespace dawn_native {
: PipelineBase(device,
descriptor->layout,
dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment),
mDepthStencilState(*descriptor->depthStencilState),
mIndexFormat(descriptor->indexFormat),
mInputState(descriptor->inputState),
mPrimitiveTopology(descriptor->primitiveTopology),
mHasDepthStencilAttachment(descriptor->attachmentsState->hasDepthStencilAttachment) {
mHasDepthStencilAttachment(descriptor->depthStencilState != nullptr) {
if (mHasDepthStencilAttachment) {
mDepthStencilFormat = descriptor->attachmentsState->depthStencilAttachment->format;
mDepthStencilState = *descriptor->depthStencilState;
} else {
// These default values below are useful for backends to fill information.
// The values indicate that depth and stencil test are disabled when backends
// set their own depth stencil states/descriptors according to the values in
// mDepthStencilState.
mDepthStencilState.depthCompare = dawn::CompareFunction::Always;
mDepthStencilState.depthWriteEnabled = false;
mDepthStencilState.stencilBack.compare = dawn::CompareFunction::Always;
mDepthStencilState.stencilBack.failOp = dawn::StencilOperation::Keep;
mDepthStencilState.stencilBack.depthFailOp = dawn::StencilOperation::Keep;
mDepthStencilState.stencilBack.passOp = dawn::StencilOperation::Keep;
mDepthStencilState.stencilFront.compare = dawn::CompareFunction::Always;
mDepthStencilState.stencilFront.failOp = dawn::StencilOperation::Keep;
mDepthStencilState.stencilFront.depthFailOp = dawn::StencilOperation::Keep;
mDepthStencilState.stencilFront.passOp = dawn::StencilOperation::Keep;
mDepthStencilState.stencilReadMask = 0xff;
mDepthStencilState.stencilWriteMask = 0xff;
}
ExtractModuleData(dawn::ShaderStage::Vertex, descriptor->vertexStage->module);
ExtractModuleData(dawn::ShaderStage::Fragment, descriptor->fragmentStage->module);
for (uint32_t i = 0; i < descriptor->attachmentsState->numColorAttachments; ++i) {
for (uint32_t i = 0; i < descriptor->numColorStates; ++i) {
mColorAttachmentsSet.set(i);
mBlendStates[i] = descriptor->blendStates[i];
mColorAttachmentFormats[i] = descriptor->attachmentsState->colorAttachments[i]->format;
mColorStates[i] = descriptor->colorStates[i];
}
// TODO(cwallez@chromium.org): Check against the shader module that the correct color
@ -212,11 +212,11 @@ namespace dawn_native {
return new RenderPipelineBase(device, ObjectBase::kError);
}
const BlendStateDescriptor* RenderPipelineBase::GetBlendStateDescriptor(
const ColorStateDescriptor* RenderPipelineBase::GetColorStateDescriptor(
uint32_t attachmentSlot) {
ASSERT(!IsError());
ASSERT(attachmentSlot < mBlendStates.size());
return &mBlendStates[attachmentSlot];
ASSERT(attachmentSlot < mColorStates.size());
return &mColorStates[attachmentSlot];
}
const DepthStencilStateDescriptor* RenderPipelineBase::GetDepthStencilStateDescriptor() {
@ -251,13 +251,13 @@ namespace dawn_native {
dawn::TextureFormat RenderPipelineBase::GetColorAttachmentFormat(uint32_t attachment) const {
ASSERT(!IsError());
return mColorAttachmentFormats[attachment];
return mColorStates[attachment].format;
}
dawn::TextureFormat RenderPipelineBase::GetDepthStencilFormat() const {
ASSERT(!IsError());
ASSERT(mHasDepthStencilAttachment);
return mDepthStencilFormat;
return mDepthStencilState.format;
}
bool RenderPipelineBase::IsCompatibleWith(const RenderPassDescriptorBase* renderPass) const {
@ -272,7 +272,7 @@ namespace dawn_native {
for (uint32_t i : IterateBitSet(mColorAttachmentsSet)) {
if (renderPass->GetColorAttachment(i).view->GetTexture()->GetFormat() !=
mColorAttachmentFormats[i]) {
mColorStates[i].format) {
return false;
}
}
@ -283,7 +283,7 @@ namespace dawn_native {
if (mHasDepthStencilAttachment &&
(renderPass->GetDepthStencilAttachment().view->GetTexture()->GetFormat() !=
mDepthStencilFormat)) {
mDepthStencilState.format)) {
return false;
}

View File

@ -30,7 +30,7 @@ namespace dawn_native {
MaybeError ValidateRenderPipelineDescriptor(DeviceBase* device,
const RenderPipelineDescriptor* descriptor);
bool StencilTestEnabled(const DepthStencilStateDescriptor* mDepthStencilState);
bool BlendEnabled(const BlendStateDescriptor* mBlendState);
bool BlendEnabled(const ColorStateDescriptor* mBlendState);
class RenderPipelineBase : public PipelineBase {
public:
@ -38,7 +38,7 @@ namespace dawn_native {
static RenderPipelineBase* MakeError(DeviceBase* device);
const BlendStateDescriptor* GetBlendStateDescriptor(uint32_t attachmentSlot);
const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot);
const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor();
dawn::IndexFormat GetIndexFormat() const;
InputStateBase* GetInputState();
@ -60,12 +60,10 @@ namespace dawn_native {
dawn::IndexFormat mIndexFormat;
Ref<InputStateBase> mInputState;
dawn::PrimitiveTopology mPrimitiveTopology;
std::array<BlendStateDescriptor, kMaxColorAttachments> mBlendStates;
std::array<ColorStateDescriptor, kMaxColorAttachments> mColorStates;
std::bitset<kMaxColorAttachments> mColorAttachmentsSet;
std::array<dawn::TextureFormat, kMaxColorAttachments> mColorAttachmentFormats;
bool mHasDepthStencilAttachment = false;
dawn::TextureFormat mDepthStencilFormat;
};
} // namespace dawn_native

View File

@ -127,7 +127,7 @@ namespace dawn_native { namespace d3d12 {
return static_cast<uint8_t>(colorWriteMask);
}
D3D12_RENDER_TARGET_BLEND_DESC ComputeBlendDesc(const BlendStateDescriptor* descriptor) {
D3D12_RENDER_TARGET_BLEND_DESC ComputeBlendDesc(const ColorStateDescriptor* descriptor) {
D3D12_RENDER_TARGET_BLEND_DESC blendDesc;
blendDesc.BlendEnable = BlendEnabled(descriptor);
blendDesc.SrcBlend = D3D12Blend(descriptor->colorBlend.srcFactor);
@ -287,7 +287,7 @@ namespace dawn_native { namespace d3d12 {
for (uint32_t i : IterateBitSet(GetColorAttachmentsMask())) {
descriptorD3D12.RTVFormats[i] = D3D12TextureFormat(GetColorAttachmentFormat(i));
descriptorD3D12.BlendState.RenderTarget[i] =
ComputeBlendDesc(GetBlendStateDescriptor(i));
ComputeBlendDesc(GetColorStateDescriptor(i));
}
descriptorD3D12.NumRenderTargets = static_cast<uint32_t>(GetColorAttachmentsMask().count());

View File

@ -129,7 +129,7 @@ namespace dawn_native { namespace metal {
}
void ComputeBlendDesc(MTLRenderPipelineColorAttachmentDescriptor* attachment,
const BlendStateDescriptor* descriptor) {
const ColorStateDescriptor* descriptor) {
attachment.blendingEnabled = BlendEnabled(descriptor);
attachment.sourceRGBBlendFactor =
MetalBlendFactor(descriptor->colorBlend.srcFactor, false);
@ -237,7 +237,7 @@ namespace dawn_native { namespace metal {
for (uint32_t i : IterateBitSet(GetColorAttachmentsMask())) {
descriptorMTL.colorAttachments[i].pixelFormat =
MetalPixelFormat(GetColorAttachmentFormat(i));
const BlendStateDescriptor* descriptor = GetBlendStateDescriptor(i);
const ColorStateDescriptor* descriptor = GetColorStateDescriptor(i);
ComputeBlendDesc(descriptorMTL.colorAttachments[i], descriptor);
}

View File

@ -90,7 +90,7 @@ namespace dawn_native { namespace opengl {
}
}
void ApplyBlendState(uint32_t attachment, const BlendStateDescriptor* descriptor) {
void ApplyBlendState(uint32_t attachment, const ColorStateDescriptor* descriptor) {
if (BlendEnabled(descriptor)) {
glEnablei(GL_BLEND, attachment);
glBlendEquationSeparatei(attachment, GLBlendMode(descriptor->colorBlend.operation),
@ -196,7 +196,7 @@ namespace dawn_native { namespace opengl {
ApplyDepthStencilState(GetDepthStencilStateDescriptor(), &persistentPipelineState);
for (uint32_t attachmentSlot : IterateBitSet(GetColorAttachmentsMask())) {
ApplyBlendState(attachmentSlot, GetBlendStateDescriptor(attachmentSlot));
ApplyBlendState(attachmentSlot, GetColorStateDescriptor(attachmentSlot));
}
}

View File

@ -112,7 +112,7 @@ namespace dawn_native { namespace vulkan {
}
VkPipelineColorBlendAttachmentState ComputeBlendDesc(
const BlendStateDescriptor* descriptor) {
const ColorStateDescriptor* descriptor) {
VkPipelineColorBlendAttachmentState attachment;
attachment.blendEnable = BlendEnabled(descriptor) ? VK_TRUE : VK_FALSE;
attachment.srcColorBlendFactor = VulkanBlendFactor(descriptor->colorBlend.srcFactor);
@ -286,7 +286,7 @@ namespace dawn_native { namespace vulkan {
// pre-computed in the BlendState
std::array<VkPipelineColorBlendAttachmentState, kMaxColorAttachments> colorBlendAttachments;
for (uint32_t i : IterateBitSet(GetColorAttachmentsMask())) {
const BlendStateDescriptor* descriptor = GetBlendStateDescriptor(i);
const ColorStateDescriptor* descriptor = GetColorStateDescriptor(i);
colorBlendAttachments[i] = ComputeBlendDesc(descriptor);
}
VkPipelineColorBlendStateCreateInfo colorBlend;

View File

@ -130,7 +130,7 @@ TEST_P(BindGroupTests, ReusedUBO) {
textureDescriptor.layout = pipelineLayout;
textureDescriptor.cVertexStage.module = vsModule;
textureDescriptor.cFragmentStage.module = fsModule;
textureDescriptor.cColorAttachments[0]->format = renderPass.colorFormat;
textureDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor);
@ -215,7 +215,7 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
pipelineDescriptor.layout = pipelineLayout;
pipelineDescriptor.cVertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = fsModule;
pipelineDescriptor.cColorAttachments[0]->format = renderPass.colorFormat;
pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&pipelineDescriptor);
@ -337,7 +337,7 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
textureDescriptor.layout = pipelineLayout;
textureDescriptor.cVertexStage.module = vsModule;
textureDescriptor.cFragmentStage.module = fsModule;
textureDescriptor.cColorAttachments[0]->format = renderPass.colorFormat;
textureDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor);
@ -431,7 +431,7 @@ TEST_P(BindGroupTests, DrawTwiceInSamePipelineWithFourBindGroupSets)
pipelineDescriptor.layout = pipelineLayout;
pipelineDescriptor.cVertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = fsModule;
pipelineDescriptor.cColorAttachments[0]->format = renderPass.colorFormat;
pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&pipelineDescriptor);
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();

View File

@ -53,7 +53,7 @@ class BlendStateTest : public DawnTest {
};
// Set up basePipeline and testPipeline. testPipeline has the given blend state on the first attachment. basePipeline has no blending
void SetupSingleSourcePipelines(const dawn::BlendStateDescriptor& blendStateDescriptor) {
void SetupSingleSourcePipelines(const dawn::ColorStateDescriptor& colorStateDescriptor) {
dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
#version 450
layout(set = 0, binding = 0) uniform myBlock {
@ -71,7 +71,7 @@ class BlendStateTest : public DawnTest {
baseDescriptor.layout = pipelineLayout;
baseDescriptor.cVertexStage.module = vsModule;
baseDescriptor.cFragmentStage.module = fsModule;
baseDescriptor.cColorAttachments[0]->format = renderPass.colorFormat;
baseDescriptor.cColorStates[0].format = renderPass.colorFormat;
basePipeline = device.CreateRenderPipeline(&baseDescriptor);
@ -79,8 +79,8 @@ class BlendStateTest : public DawnTest {
testDescriptor.layout = pipelineLayout;
testDescriptor.cVertexStage.module = vsModule;
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorAttachments[0]->format = renderPass.colorFormat;
testDescriptor.cBlendStates[0] = blendStateDescriptor;
testDescriptor.cColorStates[0] = colorStateDescriptor;
testDescriptor.cColorStates[0].format = renderPass.colorFormat;
testPipeline = device.CreateRenderPipeline(&testDescriptor);
}
@ -135,7 +135,7 @@ class BlendStateTest : public DawnTest {
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendStateDescriptor descriptor;
dawn::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
descriptor.colorWriteMask = dawn::ColorWriteMask::All;
@ -159,7 +159,7 @@ class BlendStateTest : public DawnTest {
alphaBlend.srcFactor = alphaSrcFactor;
alphaBlend.dstFactor = alphaDstFactor;
dawn::BlendStateDescriptor descriptor;
dawn::ColorStateDescriptor descriptor;
descriptor.colorBlend = colorBlend;
descriptor.alphaBlend = alphaBlend;
descriptor.colorWriteMask = dawn::ColorWriteMask::All;
@ -278,7 +278,7 @@ TEST_P(BlendStateTest, Basic) {
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero;
dawn::BlendStateDescriptor descriptor;
dawn::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
descriptor.colorWriteMask = dawn::ColorWriteMask::All;
@ -633,7 +633,7 @@ TEST_P(BlendStateTest, ColorWriteMask) {
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendStateDescriptor descriptor;
dawn::ColorStateDescriptor descriptor;
descriptor.colorBlend = blend;
descriptor.alphaBlend = blend;
{
@ -679,7 +679,7 @@ TEST_P(BlendStateTest, ColorWriteMaskBlendingDisabled) {
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero;
dawn::BlendStateDescriptor descriptor;
dawn::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
@ -766,8 +766,7 @@ TEST_P(BlendStateTest, IndependentBlendState) {
baseDescriptor.layout = pipelineLayout;
baseDescriptor.cVertexStage.module = vsModule;
baseDescriptor.cFragmentStage.module = fsModule;
baseDescriptor.cAttachmentsState.numColorAttachments = 4;
baseDescriptor.numBlendStates = 4;
baseDescriptor.numColorStates = 4;
basePipeline = device.CreateRenderPipeline(&baseDescriptor);
@ -775,8 +774,7 @@ TEST_P(BlendStateTest, IndependentBlendState) {
testDescriptor.layout = pipelineLayout;
testDescriptor.cVertexStage.module = vsModule;
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cAttachmentsState.numColorAttachments = 4;
testDescriptor.numBlendStates = 4;
testDescriptor.numColorStates = 4;
// set blend states
dawn::BlendDescriptor blend1;
@ -794,14 +792,14 @@ TEST_P(BlendStateTest, IndependentBlendState) {
blend3.srcFactor = dawn::BlendFactor::One;
blend3.dstFactor = dawn::BlendFactor::One;
testDescriptor.cBlendStates[0].colorBlend = blend1;
testDescriptor.cBlendStates[0].alphaBlend = blend1;
testDescriptor.cColorStates[0].colorBlend = blend1;
testDescriptor.cColorStates[0].alphaBlend = blend1;
testDescriptor.cBlendStates[1].colorBlend = blend2;
testDescriptor.cBlendStates[1].alphaBlend = blend2;
testDescriptor.cColorStates[1].colorBlend = blend2;
testDescriptor.cColorStates[1].alphaBlend = blend2;
testDescriptor.cBlendStates[3].colorBlend = blend3;
testDescriptor.cBlendStates[3].alphaBlend = blend3;
testDescriptor.cColorStates[3].colorBlend = blend3;
testDescriptor.cColorStates[3].alphaBlend = blend3;
testPipeline = device.CreateRenderPipeline(&testDescriptor);
@ -859,7 +857,7 @@ TEST_P(BlendStateTest, DefaultBlendColor) {
baseDescriptor.layout = pipelineLayout;
baseDescriptor.cVertexStage.module = vsModule;
baseDescriptor.cFragmentStage.module = fsModule;
baseDescriptor.cColorAttachments[0]->format = renderPass.colorFormat;
baseDescriptor.cColorStates[0].format = renderPass.colorFormat;
basePipeline = device.CreateRenderPipeline(&baseDescriptor);
@ -867,14 +865,14 @@ TEST_P(BlendStateTest, DefaultBlendColor) {
testDescriptor.layout = pipelineLayout;
testDescriptor.cVertexStage.module = vsModule;
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorAttachments[0]->format = renderPass.colorFormat;
testDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::BlendColor;
blend.dstFactor = dawn::BlendFactor::One;
testDescriptor.cBlendStates[0].colorBlend = blend;
testDescriptor.cBlendStates[0].alphaBlend = blend;
testDescriptor.cColorStates[0].colorBlend = blend;
testDescriptor.cColorStates[0].alphaBlend = blend;
testPipeline = device.CreateRenderPipeline(&testDescriptor);
constexpr dawn::Color kWhite{1.0f, 1.0f, 1.0f, 1.0f};

View File

@ -294,9 +294,9 @@ class DepthStencilStateTest : public DawnTest {
descriptor.layout = pipelineLayout;
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cAttachmentsState.hasDepthStencilAttachment = true;
descriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.depthStencilState = &test.depthStencilState;
descriptor.cDepthStencilState = test.depthStencilState;
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.depthStencilState = &descriptor.cDepthStencilState;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);

View File

@ -64,7 +64,7 @@ class DrawIndexedTest : public DawnTest {
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = dawn::IndexFormat::Uint32;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0]->format = renderPass.colorFormat;
descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);

View File

@ -62,7 +62,7 @@ class DrawTest : public DawnTest {
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = dawn::IndexFormat::Uint32;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0]->format = renderPass.colorFormat;
descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);

View File

@ -69,7 +69,7 @@ class IndexFormatTest : public DawnTest {
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = format;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0]->format = renderPass.colorFormat;
descriptor.cColorStates[0].format = renderPass.colorFormat;
return device.CreateRenderPipeline(&descriptor);
}

View File

@ -125,7 +125,7 @@ class InputStateTest : public DawnTest {
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0]->format = renderPass.colorFormat;
descriptor.cColorStates[0].format = renderPass.colorFormat;
return device.CreateRenderPipeline(&descriptor);
}

View File

@ -203,7 +203,7 @@ class PrimitiveTopologyTest : public DawnTest {
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = primitiveTopology;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0]->format = renderPass.colorFormat;
descriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);

View File

@ -195,8 +195,8 @@ class PushConstantTest: public DawnTest {
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
descriptor.cBlendStates[0].alphaBlend = blend;
descriptor.cBlendStates[0].colorBlend = blend;
descriptor.cColorStates[0].alphaBlend = blend;
descriptor.cColorStates[0].colorBlend = blend;
return device.CreateRenderPipeline(&descriptor);
}

View File

@ -77,7 +77,7 @@ protected:
pipelineDescriptor.layout = pipelineLayout;
pipelineDescriptor.cVertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = fsModule;
pipelineDescriptor.cColorAttachments[0]->format = mRenderPass.colorFormat;
pipelineDescriptor.cColorStates[0].format = mRenderPass.colorFormat;
mPipeline = device.CreateRenderPipeline(&pipelineDescriptor);

View File

@ -40,7 +40,7 @@ class ScissorTest: public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cColorAttachments[0]->format = format;
descriptor.cColorStates[0].format = format;
return device.CreateRenderPipeline(&descriptor);
}

View File

@ -172,7 +172,7 @@ protected:
textureDescriptor.cVertexStage.module = mVSModule;
textureDescriptor.cFragmentStage.module = fsModule;
textureDescriptor.layout = mPipelineLayout;
textureDescriptor.cColorAttachments[0]->format = mRenderPass.colorFormat;
textureDescriptor.cColorStates[0].format = mRenderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor);
@ -516,7 +516,7 @@ class TextureViewRenderingTest : public DawnTest {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.cVertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = oneColorFsModule;
pipelineDescriptor.cColorAttachments[0]->format = kDefaultFormat;
pipelineDescriptor.cColorStates[0].format = kDefaultFormat;
dawn::RenderPipeline oneColorPipeline = device.CreateRenderPipeline(&pipelineDescriptor);

View File

@ -40,7 +40,7 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) {
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList;
descriptor.cColorAttachments[0]->format = renderPass.colorFormat;
descriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);

View File

@ -39,7 +39,7 @@ class InputStateTest : public ValidationTest {
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0]->format = dawn::TextureFormat::R8G8B8A8Unorm;
descriptor.cColorStates[0].format = dawn::TextureFormat::R8G8B8A8Unorm;
if (!success) {
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));

View File

@ -58,26 +58,16 @@ TEST_F(RenderPipelineValidationTest, BlendState) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.numBlendStates = 1;
descriptor.numColorStates = 1;
device.CreateRenderPipeline(&descriptor);
}
{ // Fail because lack of blend states for color attachments
{ // Fail because lack of color states (and depth/stencil state)
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.numBlendStates = 0;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}
{
// Fail because set blend states for empty color attachments
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.numBlendStates = 2;
descriptor.numColorStates = 0;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}

View File

@ -88,16 +88,17 @@ TEST_F(WireArgumentTests, CStringArgument) {
dawnShaderModule apiVsModule = api.GetNewShaderModule();
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule));
// Create the blend state descriptor
// Create the color state descriptor
dawnBlendDescriptor blendDescriptor;
blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD;
blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE;
blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE;
dawnBlendStateDescriptor blendStateDescriptor;
blendStateDescriptor.nextInChain = nullptr;
blendStateDescriptor.alphaBlend = blendDescriptor;
blendStateDescriptor.colorBlend = blendDescriptor;
blendStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
dawnColorStateDescriptor colorStateDescriptor;
colorStateDescriptor.nextInChain = nullptr;
colorStateDescriptor.format = DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
colorStateDescriptor.alphaBlend = blendDescriptor;
colorStateDescriptor.colorBlend = blendDescriptor;
colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
// Create the input state
dawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device);
@ -119,6 +120,7 @@ TEST_F(WireArgumentTests, CStringArgument) {
dawnDepthStencilStateDescriptor depthStencilState;
depthStencilState.nextInChain = nullptr;
depthStencilState.format = DAWN_TEXTURE_FORMAT_D32_FLOAT_S8_UINT;
depthStencilState.depthWriteEnabled = false;
depthStencilState.depthCompare = DAWN_COMPARE_FUNCTION_ALWAYS;
depthStencilState.stencilBack = stencilFace;
@ -151,20 +153,8 @@ TEST_F(WireArgumentTests, CStringArgument) {
fragmentStage.entryPoint = "main";
pipelineDescriptor.fragmentStage = &fragmentStage;
dawnAttachmentsStateDescriptor attachmentsState;
attachmentsState.nextInChain = nullptr;
attachmentsState.numColorAttachments = 1;
dawnAttachmentDescriptor colorAttachment = {nullptr, DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM};
dawnAttachmentDescriptor* colorAttachmentPtr[] = {&colorAttachment};
attachmentsState.colorAttachments = colorAttachmentPtr;
attachmentsState.hasDepthStencilAttachment = false;
// Even with hasDepthStencilAttachment = false, depthStencilAttachment must point to valid
// data because we don't have optional substructures yet.
attachmentsState.depthStencilAttachment = &colorAttachment;
pipelineDescriptor.attachmentsState = &attachmentsState;
pipelineDescriptor.numBlendStates = 1;
pipelineDescriptor.blendStates = &blendStateDescriptor;
pipelineDescriptor.numColorStates = 1;
pipelineDescriptor.colorStates = &colorStateDescriptor;
pipelineDescriptor.sampleCount = 1;
pipelineDescriptor.layout = layout;

View File

@ -73,16 +73,17 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
dawnShaderModule apiVsModule = api.GetNewShaderModule();
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _)).WillOnce(Return(apiVsModule));
// Create the blend state descriptor
// Create the color state descriptor
dawnBlendDescriptor blendDescriptor;
blendDescriptor.operation = DAWN_BLEND_OPERATION_ADD;
blendDescriptor.srcFactor = DAWN_BLEND_FACTOR_ONE;
blendDescriptor.dstFactor = DAWN_BLEND_FACTOR_ONE;
dawnBlendStateDescriptor blendStateDescriptor;
blendStateDescriptor.nextInChain = nullptr;
blendStateDescriptor.alphaBlend = blendDescriptor;
blendStateDescriptor.colorBlend = blendDescriptor;
blendStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
dawnColorStateDescriptor colorStateDescriptor;
colorStateDescriptor.nextInChain = nullptr;
colorStateDescriptor.format = DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
colorStateDescriptor.alphaBlend = blendDescriptor;
colorStateDescriptor.colorBlend = blendDescriptor;
colorStateDescriptor.colorWriteMask = DAWN_COLOR_WRITE_MASK_ALL;
// Create the input state
dawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device);
@ -104,6 +105,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
dawnDepthStencilStateDescriptor depthStencilState;
depthStencilState.nextInChain = nullptr;
depthStencilState.format = DAWN_TEXTURE_FORMAT_D32_FLOAT_S8_UINT;
depthStencilState.depthWriteEnabled = false;
depthStencilState.depthCompare = DAWN_COMPARE_FUNCTION_ALWAYS;
depthStencilState.stencilBack = stencilFace;
@ -136,20 +138,8 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
fragmentStage.entryPoint = "main";
pipelineDescriptor.fragmentStage = &fragmentStage;
dawnAttachmentsStateDescriptor attachmentsState;
attachmentsState.nextInChain = nullptr;
attachmentsState.numColorAttachments = 1;
dawnAttachmentDescriptor colorAttachment = {nullptr, DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM};
dawnAttachmentDescriptor* colorAttachmentPtr[] = {&colorAttachment};
attachmentsState.colorAttachments = colorAttachmentPtr;
attachmentsState.hasDepthStencilAttachment = false;
// Even with hasDepthStencilAttachment = false, depthStencilAttachment must point to valid
// data because we don't have optional substructures yet.
attachmentsState.depthStencilAttachment = &colorAttachment;
pipelineDescriptor.attachmentsState = &attachmentsState;
pipelineDescriptor.numBlendStates = 1;
pipelineDescriptor.blendStates = &blendStateDescriptor;
pipelineDescriptor.numColorStates = 1;
pipelineDescriptor.colorStates = &colorStateDescriptor;
pipelineDescriptor.sampleCount = 1;
pipelineDescriptor.layout = layout;

View File

@ -37,35 +37,22 @@ namespace utils {
cFragmentStage.entryPoint = "main";
}
// Set defaults for the attachment states.
// Set defaults for the color state descriptors.
{
descriptor->attachmentsState = &cAttachmentsState;
cAttachmentsState.numColorAttachments = 1;
cAttachmentsState.colorAttachments = &cColorAttachments[0];
cAttachmentsState.depthStencilAttachment = &cDepthStencilAttachment;
cAttachmentsState.hasDepthStencilAttachment = false;
for (uint32_t i = 0; i < kMaxColorAttachments; ++i) {
colorAttachments[i].format = dawn::TextureFormat::R8G8B8A8Unorm;
cColorAttachments[i] = &colorAttachments[i];
}
}
// Set defaults for the blend state descriptors.
{
descriptor->numBlendStates = 1;
descriptor->blendStates = &cBlendStates[0];
descriptor->numColorStates = 1;
descriptor->colorStates = &cColorStates[0];
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero;
dawn::BlendStateDescriptor blendStateDescriptor;
blendStateDescriptor.alphaBlend = blend;
blendStateDescriptor.colorBlend = blend;
blendStateDescriptor.colorWriteMask = dawn::ColorWriteMask::All;
dawn::ColorStateDescriptor colorStateDescriptor;
colorStateDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
colorStateDescriptor.alphaBlend = blend;
colorStateDescriptor.colorBlend = blend;
colorStateDescriptor.colorWriteMask = dawn::ColorWriteMask::All;
for (uint32_t i = 0; i < kMaxColorAttachments; ++i) {
cBlendStates[i] = blendStateDescriptor;
cColorStates[i] = colorStateDescriptor;
}
}
@ -77,14 +64,14 @@ namespace utils {
stencilFace.depthFailOp = dawn::StencilOperation::Keep;
stencilFace.passOp = dawn::StencilOperation::Keep;
// dawn::DepthStencilStateDescriptor depthStencilState;
cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
cDepthStencilState.depthWriteEnabled = false;
cDepthStencilState.depthCompare = dawn::CompareFunction::Always;
cDepthStencilState.stencilBack = stencilFace;
cDepthStencilState.stencilFront = stencilFace;
cDepthStencilState.stencilReadMask = 0xff;
cDepthStencilState.stencilWriteMask = 0xff;
descriptor->depthStencilState = &cDepthStencilState;
descriptor->depthStencilState = nullptr;
}
descriptor->inputState = device.CreateInputStateBuilder().GetResult();

View File

@ -30,14 +30,10 @@ namespace utils {
dawn::PipelineStageDescriptor cVertexStage;
dawn::PipelineStageDescriptor cFragmentStage;
dawn::AttachmentsStateDescriptor cAttachmentsState;
std::array<dawn::AttachmentDescriptor*, kMaxColorAttachments> cColorAttachments;
dawn::AttachmentDescriptor cDepthStencilAttachment;
std::array<dawn::BlendStateDescriptor, kMaxColorAttachments> cBlendStates;
std::array<dawn::ColorStateDescriptor, kMaxColorAttachments> cColorStates;
dawn::DepthStencilStateDescriptor cDepthStencilState;
private:
dawn::AttachmentDescriptor colorAttachments[kMaxColorAttachments];
};
} // namespace utils