xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/wgpu/ShaderWgpu.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2024 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ShaderWgpu.cpp:
7 //    Implements the class methods for ShaderWgpu.
8 //
9 
10 #include "libANGLE/renderer/wgpu/ShaderWgpu.h"
11 
12 #include "common/debug.h"
13 #include "libANGLE/Context.h"
14 #include "libANGLE/renderer/ContextImpl.h"
15 #include "libANGLE/trace.h"
16 
17 namespace rx
18 {
19 
20 namespace
21 {
22 class ShaderTranslateTaskWgpu final : public ShaderTranslateTask
23 {
translate(ShHandle compiler,const ShCompileOptions & options,const std::string & source)24     bool translate(ShHandle compiler,
25                    const ShCompileOptions &options,
26                    const std::string &source) override
27     {
28         ANGLE_TRACE_EVENT1("gpu.angle", "ShaderTranslateTaskWgpu::translate", "source", source);
29 
30         const char *srcStrings[] = {source.c_str()};
31         return sh::Compile(compiler, srcStrings, ArraySize(srcStrings), options);
32     }
33 
postTranslate(ShHandle compiler,const gl::CompiledShaderState & compiledState)34     void postTranslate(ShHandle compiler, const gl::CompiledShaderState &compiledState) override {}
35 };
36 }  // namespace
37 
ShaderWgpu(const gl::ShaderState & data)38 ShaderWgpu::ShaderWgpu(const gl::ShaderState &data) : ShaderImpl(data) {}
39 
~ShaderWgpu()40 ShaderWgpu::~ShaderWgpu() {}
41 
compile(const gl::Context * context,ShCompileOptions * options)42 std::shared_ptr<ShaderTranslateTask> ShaderWgpu::compile(const gl::Context *context,
43                                                          ShCompileOptions *options)
44 {
45     const gl::Extensions &extensions = context->getImplementation()->getExtensions();
46     if (extensions.shaderPixelLocalStorageANGLE)
47     {
48         options->pls = context->getImplementation()->getNativePixelLocalStorageOptions();
49     }
50 
51     options->validateAST = true;
52 
53     options->separateCompoundStructDeclarations = true;
54 
55     return std::shared_ptr<ShaderTranslateTask>(new ShaderTranslateTaskWgpu);
56 }
57 
load(const gl::Context * context,gl::BinaryInputStream * stream)58 std::shared_ptr<ShaderTranslateTask> ShaderWgpu::load(const gl::Context *context,
59                                                       gl::BinaryInputStream *stream)
60 {
61     UNREACHABLE();
62     return std::shared_ptr<ShaderTranslateTask>(new ShaderTranslateTask);
63 }
64 
getDebugInfo() const65 std::string ShaderWgpu::getDebugInfo() const
66 {
67     return "";
68 }
69 
70 }  // namespace rx
71