Make rasterization state descriptor optional

Following WebGPU spec change at https://github.com/gpuweb/gpuweb/issues/347,
the rasterizationState from GPURenderPipelineDescriptor should not be
required anymore.

BUG=dawn:22
Change-Id: Ic458396665a7e2fbd942aa7f50138cc96497ff33
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9000
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
diff --git a/dawn.json b/dawn.json
index e46d656..4242abd 100644
--- a/dawn.json
+++ b/dawn.json
@@ -905,7 +905,7 @@
             {"name": "fragment stage", "type": "pipeline stage descriptor", "annotation": "const*"},
             {"name": "vertex input", "type": "vertex input descriptor", "annotation": "const*"},
             {"name": "primitive topology", "type": "primitive topology"},
-            {"name": "rasterization state", "type": "rasterization state descriptor", "annotation": "const*"},
+            {"name": "rasterization state", "type": "rasterization state descriptor", "annotation": "const*", "optional": true},
             {"name": "sample count", "type": "uint32_t", "default": "1"},
             {"name": "depth stencil state", "type": "depth stencil state descriptor", "annotation": "const*", "optional": true},
             {"name": "color state count", "type": "uint32_t"},
diff --git a/generator/templates/dawn_native/api_structs.h b/generator/templates/dawn_native/api_structs.h
index 6de4da6..e4967ee 100644
--- a/generator/templates/dawn_native/api_structs.h
+++ b/generator/templates/dawn_native/api_structs.h
@@ -20,13 +20,25 @@
 
 namespace dawn_native {
 
+{% macro render_cpp_default_value(member) -%}
+    {%- if member.annotation in ["*", "const*", "const*const*"] and member.optional -%}
+        {{" "}}= nullptr
+    {%- elif member.type.category in ["enum", "bitmask"] and member.default_value != None -%}
+        {{" "}}= dawn::{{as_cppType(member.type.name)}}::{{as_cppEnum(Name(member.default_value))}}
+    {%- elif member.type.category == "native" and member.default_value != None -%}
+        {{" "}}= {{member.default_value}}
+    {%- else -%}
+        {{assert(member.default_value == None)}}
+    {%- endif -%}
+{%- endmacro %}
+
     {% for type in by_category["structure"] %}
         struct {{as_cppType(type.name)}} {
             {% if type.extensible %}
                 const void* nextInChain = nullptr;
             {% endif %}
             {% for member in type.members %}
-                {{as_annotated_frontendType(member)}};
+                {{as_annotated_frontendType(member)}} {{render_cpp_default_value(member)}};
             {% endfor %}
         };
 
diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp
index 27973fe..b8b2d2b 100644
--- a/src/dawn_native/RenderPipeline.cpp
+++ b/src/dawn_native/RenderPipeline.cpp
@@ -277,7 +277,10 @@
                                                  descriptor->layout, ShaderStage::Vertex));
         DAWN_TRY(ValidatePipelineStageDescriptor(device, descriptor->fragmentStage,
                                                  descriptor->layout, ShaderStage::Fragment));
-        DAWN_TRY(ValidateRasterizationStateDescriptor(descriptor->rasterizationState));
+
+        if (descriptor->rasterizationState) {
+            DAWN_TRY(ValidateRasterizationStateDescriptor(descriptor->rasterizationState));
+        }
 
         if ((descriptor->vertexStage->module->GetUsedVertexAttributes() & ~attributesSetMask)
                 .any()) {
@@ -347,7 +350,6 @@
           mVertexInput(*descriptor->vertexInput),
           mHasDepthStencilAttachment(descriptor->depthStencilState != nullptr),
           mPrimitiveTopology(descriptor->primitiveTopology),
-          mRasterizationState(*descriptor->rasterizationState),
           mSampleCount(descriptor->sampleCount),
           mSampleMask(descriptor->sampleMask),
           mAlphaToCoverageEnabled(descriptor->alphaToCoverageEnabled),
@@ -376,6 +378,12 @@
             }
         }
 
+        if (descriptor->rasterizationState != nullptr) {
+            mRasterizationState = *descriptor->rasterizationState;
+        } else {
+            mRasterizationState = RasterizationStateDescriptor();
+        }
+
         if (mHasDepthStencilAttachment) {
             mDepthStencilState = *descriptor->depthStencilState;
         } else {