Skip to content
Snippets Groups Projects
Commit a49578ee authored by Philip Trettner's avatar Philip Trettner
Browse files

working towards first triangle

parent 8f1bddee
No related branches found
No related tags found
No related merge requests found
#pragma once
namespace tg
{
enum class backend
{
vulkan,
lava,
glow
};
}
\ No newline at end of file
#include "assert.hh"
#include <utility>
void tg::assertion_fail() { std::abort(); }
#pragma once
#include <cstdio>
#include "macros.hh"
// expr, msg, args
#define TG_ASSERT(expr, ...) \
do \
{ \
if (!(expr)) \
{ \
fprintf(stderr, "%s", "Assertion `" #expr "' failed."); \
fprintf(stderr, __VA_ARGS__); \
assertion_fail(); \
} \
} while (0) // force ;
namespace tg
{
TG_NO_INLINE void assertion_fail();
} // namespace tg
#pragma once #pragma once
// disable inlining
#ifdef _MSC_VER
#define TG_NO_INLINE __declspec(noinline)
#else
#define TG_NO_INLINE __attribute__((noinline))
#endif
// [[nodiscard]] macro // [[nodiscard]] macro
#define TG_NODISCARD [[nodiscard]] #define TG_NO_DISCARD [[nodiscard]]
// makes SharedXyz types available // makes SharedXyz types available
#define TG_SHARED(klass, type) \ #define TG_SHARED(klass, type) \
...@@ -18,6 +25,13 @@ ...@@ -18,6 +25,13 @@
template <class T1, class T2> \ template <class T1, class T2> \
using Shared##type = std::shared_ptr<type<T1, T2>> // force ; using Shared##type = std::shared_ptr<type<T1, T2>> // force ;
// delete certain ctors/operators for our RAII usage
#define TG_RAII_TYPE(T) \
T(T&&) = default; \
T(T const&) = delete; \
T& operator=(T&&) = delete; \
T& operator=(T const&) = delete // force ;
// unified interface for builders // unified interface for builders
// #define TG_BUILD(type) \ // #define TG_BUILD(type) \
// type##Builder(type##Builder const&) = delete; \ // type##Builder(type##Builder const&) = delete; \
......
...@@ -7,10 +7,17 @@ ...@@ -7,10 +7,17 @@
namespace tg namespace tg
{ {
template <class DataT> template <class DataT>
class Buffer class Buffer : std::enable_shared_from_this<Buffer<DataT>>
{ {
TG_REFERENCE_TYPE(Buffer); TG_REFERENCE_TYPE(Buffer);
public:
SharedBufferView<DataT> view() const
{
// TODO: create default view
return nullptr;
}
public: public:
using data_t = DataT; using data_t = DataT;
......
#pragma once
#include <vector>
#include <tg/typed-graphics-lean.hh>
namespace tg
{
template <class DataT>
class BufferView
{
TG_REFERENCE_TYPE(BufferView);
public:
using data_t = DataT;
BufferView() = default;
};
} // namespace tg
...@@ -22,6 +22,8 @@ public: ...@@ -22,6 +22,8 @@ public:
template <class VertexT, class FragmentT> template <class VertexT, class FragmentT>
struct PrimitivePipelineRecorder struct PrimitivePipelineRecorder
{ {
TG_RAII_TYPE(PrimitivePipelineRecorder);
// TODO: record current vb/ib for rebinding // TODO: record current vb/ib for rebinding
void bindResources() void bindResources()
...@@ -29,19 +31,27 @@ public: ...@@ -29,19 +31,27 @@ public:
// TODO // TODO
} }
void draw(SharedBuffer<VertexT> vertexBuffer) void draw(SharedBuffer<VertexT> const& vertexBuffer) { draw(vertexBuffer->view()); }
void draw(SharedBufferView<VertexT> const& vertexBuffer)
{ {
// TODO // TODO
} }
template <class PushConstants> template <class PushConstants>
void draw(PushConstants const& constants, SharedBuffer<VertexT> vertexBuffer) void draw(PushConstants const& constants, SharedBuffer<VertexT> const& vertexBuffer)
{
draw(constants, vertexBuffer->view());
}
template <class PushConstants>
void draw(PushConstants const& constants, SharedBufferView<VertexT> const& vertexBuffer)
{ {
// TODO // TODO
} }
}; };
struct RenderPassRecorder struct RenderPassRecorder
{ {
TG_RAII_TYPE(RenderPassRecorder);
template <class VertexT, class FragmentT> template <class VertexT, class FragmentT>
PrimitivePipelineRecorder<VertexT, FragmentT> recordPipeline(SharedPrimitivePipeline<VertexT, FragmentT> const& pipeline) PrimitivePipelineRecorder<VertexT, FragmentT> recordPipeline(SharedPrimitivePipeline<VertexT, FragmentT> const& pipeline)
{ {
...@@ -50,11 +60,41 @@ public: ...@@ -50,11 +60,41 @@ public:
}; };
struct Recorder struct Recorder
{ {
TG_RAII_TYPE(Recorder);
Recorder(bool autoSubmit) : mAutoSubmit(autoSubmit)
{
TG_ASSERT(current() == nullptr, "For security reasons, only one CommandBuffer can be recorded at the same time per thread.");
current() = this;
}
~Recorder()
{
TG_ASSERT(current() == this, "Current Recorder corrupted");
current() = nullptr;
if (mAutoSubmit)
{
// TODO
}
}
// TODO // TODO
RenderPassRecorder recordPass(SharedRenderPass const& pass) { return {}; } RenderPassRecorder recordPass(SharedRenderPass const& pass) { return {}; }
RenderPassRecorder recordPass(SharedRenderPass const& pass, ibox2 viewport) { return {}; } RenderPassRecorder recordPass(SharedRenderPass const& pass, ibox2 viewport) { return {}; }
RenderPassRecorder recordPass(SharedRenderPass const& pass, ibox2 viewport, ibox2 scissor) { return {}; } RenderPassRecorder recordPass(SharedRenderPass const& pass, ibox2 viewport, ibox2 scissor) { return {}; }
static bool isRecording() { return current() != nullptr; }
private:
bool mAutoSubmit;
private:
static Recorder*& current()
{
static thread_local Recorder* curr = nullptr;
return curr;
}
}; };
}; };
} // namespace tg } // namespace tg
...@@ -31,10 +31,17 @@ SharedCommandBuffer Device::createCommandBuffer() ...@@ -31,10 +31,17 @@ SharedCommandBuffer Device::createCommandBuffer()
return std::make_shared<CommandBuffer>(); return std::make_shared<CommandBuffer>();
} }
SharedDevice Device::create() Device::Device(backend backend, bool isDebug) : mBackend(backend), mIsDebug(isDebug) {}
SharedDevice Device::create(backend backend)
{ {
// TODO // TODO
return std::make_shared<Device>(); return std::make_shared<Device>(backend, false);
} }
SharedDevice Device::createDebug(backend backend)
{
// TODO
return std::make_shared<Device>(backend, true);
}
} // namespace tg } // namespace tg
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <tg/builder/builder.hh> #include <tg/builder/builder.hh>
#include <tg/backend/backend.hh>
#include "CommandBuffer.hh" #include "CommandBuffer.hh"
#include "pipelines/PrimitivePipeline.hh" #include "pipelines/PrimitivePipeline.hh"
...@@ -21,7 +23,8 @@ class Device : std::enable_shared_from_this<Device> ...@@ -21,7 +23,8 @@ class Device : std::enable_shared_from_this<Device>
TG_REFERENCE_TYPE(Device); TG_REFERENCE_TYPE(Device);
public: public:
Device() = default; bool isDebug() const { return mIsDebug; }
backend getBackend() const { return mBackend; }
// windows // windows
public: public:
...@@ -63,16 +66,24 @@ public: ...@@ -63,16 +66,24 @@ public:
public: public:
SharedCommandBuffer createCommandBuffer(); SharedCommandBuffer createCommandBuffer();
TG_NODISCARD CommandBuffer::Recorder submitGraphicsCommands() TG_NO_DISCARD CommandBuffer::Recorder submitGraphicsCommands()
{ {
// TODO: user one-time submit option // TODO: user one-time submit option
// TODO // TODO
return {}; return {true};
} }
public: public:
static SharedDevice create(); static SharedDevice create(backend backend = backend::vulkan);
static SharedDevice createDebug(backend backend = backend::vulkan);
public:
Device(backend backend, bool isDebug);
private:
backend mBackend;
bool mIsDebug;
}; };
template <class VertexT, class FragmentT> template <class VertexT, class FragmentT>
......
...@@ -5,10 +5,17 @@ ...@@ -5,10 +5,17 @@
namespace tg namespace tg
{ {
template <int D, class DataT> template <int D, class DataT>
class Image class Image : std::enable_shared_from_this<Image<D, DataT>>
{ {
TG_REFERENCE_TYPE(Image); TG_REFERENCE_TYPE(Image);
public:
SharedImageView<D, DataT> view() const
{
// TODO: create default view
return nullptr;
}
public: public:
using data_t = DataT; using data_t = DataT;
......
#pragma once
#include <tg/typed-geometry-lean.hh>
namespace tg
{
template <int D, class DataT>
class ImageView
{
TG_REFERENCE_TYPE(ImageView);
public:
using data_t = DataT;
ImageView() = default;
};
} // namespace tg
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#include <tg/typed-graphics-lean.hh> #include <tg/typed-graphics-lean.hh>
#include "Image.hh"
#include "ImageView.hh"
namespace tg namespace tg
{ {
class Window class Window
...@@ -14,8 +17,17 @@ public: ...@@ -14,8 +17,17 @@ public:
public: public:
struct Frame struct Frame
{ {
TG_RAII_TYPE(Frame);
Frame() {}
template <class FragmentT> template <class FragmentT>
void present(SharedImage2D<FragmentT> const& img) void present(SharedImage2D<FragmentT> const& img)
{
present(img->view());
}
template <class FragmentT>
void present(SharedImageView2D<FragmentT> const& img)
{ {
// TODO // TODO
} }
......
#pragma once #pragma once
#include "Buffer.hh" #include "Buffer.hh"
#include "BufferView.hh"
#include "CommandBuffer.hh" #include "CommandBuffer.hh"
#include "Device.hh" #include "Device.hh"
#include "Framebuffer.hh" #include "Framebuffer.hh"
#include "Image.hh" #include "Image.hh"
#include "ImageView.hh"
#include "Queue.hh" #include "Queue.hh"
#include "RenderPass.hh" #include "RenderPass.hh"
#include "Shader.hh" #include "Shader.hh"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <memory> #include <memory>
#include <tg/common/assert.hh>
#include <tg/common/macros.hh> #include <tg/common/macros.hh>
#include <tg/common/traits.hh> #include <tg/common/traits.hh>
...@@ -19,6 +20,7 @@ TG_SHARED_T2(class, PrimitivePipeline, VertexT, FragmentT); ...@@ -19,6 +20,7 @@ TG_SHARED_T2(class, PrimitivePipeline, VertexT, FragmentT);
TG_SHARED_T1(class, Framebuffer, FragmentT); TG_SHARED_T1(class, Framebuffer, FragmentT);
TG_SHARED_T1(class, Buffer, DataT); TG_SHARED_T1(class, Buffer, DataT);
TG_SHARED_T1(class, BufferView, DataT);
TG_SHARED_T1(class, VertexShader, VertexT); TG_SHARED_T1(class, VertexShader, VertexT);
TG_SHARED(class, TessellationControlShader); TG_SHARED(class, TessellationControlShader);
...@@ -54,4 +56,21 @@ template <class DataT> ...@@ -54,4 +56,21 @@ template <class DataT>
using SharedImage2D = std::shared_ptr<Image2D<DataT>>; using SharedImage2D = std::shared_ptr<Image2D<DataT>>;
template <class DataT> template <class DataT>
using SharedImage3D = std::shared_ptr<Image3D<DataT>>; using SharedImage3D = std::shared_ptr<Image3D<DataT>>;
template <int D, class DataT>
class ImageView;
template <class DataT>
using ImageView1D = ImageView<1, DataT>;
template <class DataT>
using ImageView2D = ImageView<2, DataT>;
template <class DataT>
using ImageView3D = ImageView<3, DataT>;
template <int D, class DataT>
using SharedImageView = std::shared_ptr<ImageView<D, DataT>>;
template <class DataT>
using SharedImageView1D = std::shared_ptr<ImageView1D<DataT>>;
template <class DataT>
using SharedImageView2D = std::shared_ptr<ImageView2D<DataT>>;
template <class DataT>
using SharedImageView3D = std::shared_ptr<ImageView3D<DataT>>;
} // namespace tg } // namespace tg
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment