From c25359df47a5663b79c5ff68353b71becd555507 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Sun, 18 Sep 2022 16:32:09 +0200 Subject: [PATCH] LibSoftGPU: Delegate shader creation to new class ShaderCompiler --- Userland/Libraries/LibSoftGPU/CMakeLists.txt | 1 + Userland/Libraries/LibSoftGPU/Device.cpp | 7 +++++-- .../Libraries/LibSoftGPU/ShaderCompiler.cpp | 17 +++++++++++++++ .../Libraries/LibSoftGPU/ShaderCompiler.h | 21 +++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Userland/Libraries/LibSoftGPU/ShaderCompiler.cpp create mode 100644 Userland/Libraries/LibSoftGPU/ShaderCompiler.h diff --git a/Userland/Libraries/LibSoftGPU/CMakeLists.txt b/Userland/Libraries/LibSoftGPU/CMakeLists.txt index 5ff50c066b..e434a1bcf1 100644 --- a/Userland/Libraries/LibSoftGPU/CMakeLists.txt +++ b/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 diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 9d7637d32a..a06f67b1a9 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace SoftGPU { @@ -1642,9 +1643,11 @@ NonnullRefPtr Device::create_image(GPU::PixelFormat const& pixel_for return adopt_ref(*new Image(this, pixel_format, width, height, depth, max_levels)); } -ErrorOr> Device::create_shader(GPU::IR::Shader const&) +ErrorOr> 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) diff --git a/Userland/Libraries/LibSoftGPU/ShaderCompiler.cpp b/Userland/Libraries/LibSoftGPU/ShaderCompiler.cpp new file mode 100644 index 0000000000..4e44aa5bf7 --- /dev/null +++ b/Userland/Libraries/LibSoftGPU/ShaderCompiler.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022, Stephan Unverwerth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace SoftGPU { + +ErrorOr> ShaderCompiler::compile(void const* ownership_token, GPU::IR::Shader const&) +{ + // FIXME: implement the shader compiler + return adopt_ref(*new Shader(ownership_token, {})); +} + +} diff --git a/Userland/Libraries/LibSoftGPU/ShaderCompiler.h b/Userland/Libraries/LibSoftGPU/ShaderCompiler.h new file mode 100644 index 0000000000..3f3fa67b12 --- /dev/null +++ b/Userland/Libraries/LibSoftGPU/ShaderCompiler.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022, Stephan Unverwerth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace SoftGPU { + +class ShaderCompiler final { +public: + ErrorOr> compile(void const* ownership_token, GPU::IR::Shader const&); +}; + +}