Pārlūkot izejas kodu

LibSoftGPU: Delegate shader creation to new class ShaderCompiler

Stephan Unverwerth 2 gadi atpakaļ
vecāks
revīzija
c25359df47

+ 1 - 0
Userland/Libraries/LibSoftGPU/CMakeLists.txt

@@ -3,6 +3,7 @@ set(SOURCES
     Device.cpp
     Image.cpp
     PixelConverter.cpp
+    ShaderCompiler.cpp
     ShaderProcessor.cpp
     Sampler.cpp
     Shader.cpp

+ 5 - 2
Userland/Libraries/LibSoftGPU/Device.cpp

@@ -23,6 +23,7 @@
 #include <LibSoftGPU/PixelQuad.h>
 #include <LibSoftGPU/SIMD.h>
 #include <LibSoftGPU/Shader.h>
+#include <LibSoftGPU/ShaderCompiler.h>
 #include <math.h>
 
 namespace SoftGPU {
@@ -1642,9 +1643,11 @@ NonnullRefPtr<GPU::Image> Device::create_image(GPU::PixelFormat const& pixel_for
     return adopt_ref(*new Image(this, pixel_format, width, height, depth, max_levels));
 }
 
-ErrorOr<NonnullRefPtr<GPU::Shader>> Device::create_shader(GPU::IR::Shader const&)
+ErrorOr<NonnullRefPtr<GPU::Shader>> Device::create_shader(GPU::IR::Shader const& intermediate_representation)
 {
-    return adopt_ref(*new Shader(this, {}));
+    ShaderCompiler compiler;
+    auto shader = TRY(compiler.compile(this, intermediate_representation));
+    return shader;
 }
 
 void Device::set_sampler_config(unsigned sampler, GPU::SamplerConfig const& config)

+ 17 - 0
Userland/Libraries/LibSoftGPU/ShaderCompiler.cpp

@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibSoftGPU/ShaderCompiler.h>
+
+namespace SoftGPU {
+
+ErrorOr<NonnullRefPtr<Shader>> ShaderCompiler::compile(void const* ownership_token, GPU::IR::Shader const&)
+{
+    // FIXME: implement the shader compiler
+    return adopt_ref(*new Shader(ownership_token, {}));
+}
+
+}

+ 21 - 0
Userland/Libraries/LibSoftGPU/ShaderCompiler.h

@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Error.h>
+#include <AK/NonnullRefPtr.h>
+#include <LibGPU/IR.h>
+#include <LibSoftGPU/Shader.h>
+
+namespace SoftGPU {
+
+class ShaderCompiler final {
+public:
+    ErrorOr<NonnullRefPtr<Shader>> compile(void const* ownership_token, GPU::IR::Shader const&);
+};
+
+}