Skip to content

Commit

Permalink
gh-45: remove dx11 style context and introduce explicit gfx cmd list …
Browse files Browse the repository at this point in the history
…objects
  • Loading branch information
EgorOrachyov committed Jul 21, 2024
1 parent b886f8b commit f940fc6
Show file tree
Hide file tree
Showing 61 changed files with 1,394 additions and 2,982 deletions.
2 changes: 1 addition & 1 deletion engine/plugins/runtime/asset/texture_asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "texture_asset_loader.hpp"

#include "asset/texture_import_data.hpp"
#include "gfx/gfx_ctx.hpp"
#include "gfx/gfx_cmd_list.hpp"
#include "gfx/gfx_driver.hpp"
#include "grc/image.hpp"
#include "grc/texture.hpp"
Expand Down
2 changes: 1 addition & 1 deletion engine/runtime/core/pool_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace wmoge {
return m_i != other.m_i;
}
IterType& operator*() {
return (IterType*) m_nodes[m_i / NODE_CAPACITY]->items[m_i % NODE_CAPACITY].mem;
return *((IterType*) m_nodes[m_i / NODE_CAPACITY]->items[m_i % NODE_CAPACITY].mem);
}
void operator++() {
m_i += 1;
Expand Down
3 changes: 1 addition & 2 deletions engine/runtime/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@
#include "gameplay/game_token_manager.hpp"

#include "gfx/gfx_buffers.hpp"
#include "gfx/gfx_ctx.hpp"
#include "gfx/gfx_cmd_list.hpp"
#include "gfx/gfx_defs.hpp"
#include "gfx/gfx_desc_set.hpp"
#include "gfx/gfx_driver.hpp"
#include "gfx/gfx_dynamic_buffers.hpp"
#include "gfx/gfx_pipeline.hpp"
#include "gfx/gfx_render_pass.hpp"
#include "gfx/gfx_resource.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,15 @@
#include "math/vec.hpp"
#include "platform/window.hpp"

#include <array>
#include <functional>
#include <string>
#include <thread>

namespace wmoge {

/**
* @class GfxCtx
* @brief Gfx context interface
*
* Context exposes gfx an environment and API for resources manipulation and rendering.
*/
class GfxCtx {
* @class GfxCmdList
* @brief List to record gfx commands for execution on device
*/
class GfxCmdList : public GfxResource {
public:
virtual ~GfxCtx() = default;

virtual void update_desc_set(const Ref<GfxDescSet>& set, const GfxDescSetResources& resources) = 0;
~GfxCmdList() override = default;

virtual void update_vert_buffer(const Ref<GfxVertBuffer>& buffer, int offset, int range, const Ref<Data>& data) = 0;
virtual void update_index_buffer(const Ref<GfxIndexBuffer>& buffer, int offset, int range, const Ref<Data>& data) = 0;
Expand All @@ -84,14 +75,9 @@ namespace wmoge {
virtual void barrier_image(const Ref<GfxTexture>& texture, GfxTexBarrierType barrier_type) = 0;
virtual void barrier_buffer(const Ref<GfxStorageBuffer>& buffer) = 0;

virtual void begin_render_pass(const GfxRenderPassDesc& pass_desc, const Strid& name = Strid()) = 0;
virtual void bind_target(const Ref<Window>& window) = 0;
virtual void bind_color_target(const Ref<GfxTexture>& texture, int target, int mip, int slice) = 0;
virtual void bind_depth_target(const Ref<GfxTexture>& texture, int mip, int slice) = 0;
virtual void begin_render_pass(const GfxRenderPassBeginInfo& pass_desc) = 0;
virtual void peek_render_pass(GfxRenderPassRef& rp) = 0;
virtual void viewport(const Rect2i& viewport) = 0;
virtual void clear(int target, const Vec4f& color) = 0;
virtual void clear(float depth, int stencil) = 0;
virtual void extract_render_pass(GfxRenderPassRef& rp) = 0;
virtual void bind_pso(const Ref<GfxPsoGraphics>& pipeline) = 0;
virtual void bind_pso(const Ref<GfxPsoCompute>& pipeline) = 0;
virtual void bind_vert_buffer(const Ref<GfxVertBuffer>& buffer, int index, int offset = 0) = 0;
Expand All @@ -103,36 +89,12 @@ namespace wmoge {
virtual void dispatch(Vec3i group_count) = 0;
virtual void end_render_pass() = 0;

virtual void execute(const std::function<void()>& functor) = 0;
virtual void shutdown() = 0;

virtual void begin_frame() = 0;
virtual void end_frame() = 0;

virtual void begin_label(const Strid& label) = 0;
virtual void end_label() = 0;

[[nodiscard]] virtual const Mat4x4f& clip_matrix() const = 0;
[[nodiscard]] virtual GfxCtxType ctx_type() const = 0;

static Vec3i group_size(int x, int y, int local_size);
};

/**
* @class GfxDebugLabel
* @brief Scope for debug laber
*/
struct GfxDebugLabel {
GfxDebugLabel(GfxCtx* ctx, const Strid& label) : ctx(ctx) { ctx->begin_label(label); }
~GfxDebugLabel() { ctx->end_label(); }
GfxCtx* ctx;
virtual GfxQueueType get_queue_type() const = 0;
};

#ifndef WMOGE_RELEASE
#define WG_GFX_LABEL(ctx, label) \
GfxDebugLabel __label_guard(ctx, label);
#else
#define WG_GFX_LABEL(ctx, label)
#endif
using GfxCmdListRef = Ref<GfxCmdList>;

}// namespace wmoge
}// namespace wmoge
36 changes: 0 additions & 36 deletions engine/runtime/gfx/gfx_ctx.cpp

This file was deleted.

39 changes: 16 additions & 23 deletions engine/runtime/gfx/gfx_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,12 @@ namespace wmoge {
static constexpr int NUM_PLATFORMS = int(GfxShaderPlatform::Max);
};

/** @brief Type of gfx context behaviour */
enum class GfxCtxType : int {
Immediate,
Deferred,
Async
};

/** @brief Status of the shader */
enum class GfxShaderStatus : int {
Compiling,
Compiled,
Failed
};

/** @brief Status of the gfx pipeline */
enum class GfxPipelineStatus : int {
Default,
Creating,
Created,
Failed
/** @brief Type of gfx queues for submission */
enum class GfxQueueType : int {
Graphics = 0,
Compute,
Copy,
None
};

/** @brief Type of elements in index buffer */
Expand Down Expand Up @@ -169,9 +155,10 @@ namespace wmoge {

/** @brief Texture manual barrier type */
enum class GfxTexBarrierType : int {
RenderTarget,
Sampling,
Storage
RenderTarget,// For drawing into texture
Sampling, // For sampling from shader in read-only mode
Storage, // For read-write in compute shader
Presentation // For presentation to the screen
};

/** @brief Texture type */
Expand Down Expand Up @@ -596,4 +583,10 @@ namespace wmoge {
int uniform_block_offset_alignment = -1;
};

struct GfxUtils {
static Vec3i group_size(int x, int y, int local_size) {
return Vec3i(int(Math::div_up(x, local_size)), int(Math::div_up(y, local_size)), 1);
}
};

}// namespace wmoge
Loading

0 comments on commit f940fc6

Please sign in to comment.