[DawnLPM] Fuzz CreateShaderModule wgsl code

Provide raw bytes to CreateShaderModule from protobuf. This will behave like dawn_wire_server_fuzzer's implicit wgsl fuzzer (just fuzzing with raw bytes).

Keep the existing pre-defined shader to help guide the fuzzer when fuzzing for object-lifetime bugs.

Change-Id: I05cf804d131247636da68b4d005ee2f262c031a3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/137080
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Brendon Tiszka <tiszka@chromium.org>
diff --git a/src/dawn/fuzzers/lpmfuzz/DawnLPMSerializerCustom.cpp b/src/dawn/fuzzers/lpmfuzz/DawnLPMSerializerCustom.cpp
index 6eab8c4..d982f87 100644
--- a/src/dawn/fuzzers/lpmfuzz/DawnLPMSerializerCustom.cpp
+++ b/src/dawn/fuzzers/lpmfuzz/DawnLPMSerializerCustom.cpp
@@ -48,18 +48,21 @@
             WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
             wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
 
-            // Hardcoded shader for now, eventually we should write an LPM grammar for WGSL
-            wgsl_desc.code =
-                "@group(0) @binding(0)\n"
-                "var<storage, read_write> output: array<f32>;\n"
-                "@compute @workgroup_size(64)\n"
-                "fn main( \n"
-                "    @builtin(global_invocation_id) global_id : vec3<u32>,\n"
-                "    @builtin(local_invocation_id) local_id : vec3<u32>,\n"
-                ") { \n"
-                "output[global_id.x] = \n"
-                "    f32(global_id.x) * 1000. + f32(local_id.x);\n"
-                "}";
+            if (command.devicecreateshadermodule().has_code()) {
+                wgsl_desc.code = command.devicecreateshadermodule().code().c_str();
+            } else {
+                wgsl_desc.code =
+                    "@group(0) @binding(0)\n"
+                    "var<storage, read_write> output: array<f32>;\n"
+                    "@compute @workgroup_size(64)\n"
+                    "fn main( \n"
+                    "    @builtin(global_invocation_id) global_id : vec3<u32>,\n"
+                    "    @builtin(local_invocation_id) local_id : vec3<u32>,\n"
+                    ") { \n"
+                    "output[global_id.x] = \n"
+                    "    f32(global_id.x) * 1000. + f32(local_id.x);\n"
+                    "}";
+            }
             cmd_descriptor.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgsl_desc);
 
             cmd.descriptor = &cmd_descriptor;
diff --git a/src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.proto b/src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.proto
index f9f2946..5b392b6 100644
--- a/src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.proto
+++ b/src/dawn/fuzzers/lpmfuzz/dawn_custom_lpm.proto
@@ -20,6 +20,7 @@
 // Custom commands
 message DeviceCreateShaderModule {
     required uint32 self = 1;
+    optional bytes code = 2;
 }
 
 message DestroyObject {