diff --git a/PKRenderer/src/Core/Application.cpp b/PKRenderer/src/Core/Application.cpp index cfd660a1..bb6df2e1 100644 --- a/PKRenderer/src/Core/Application.cpp +++ b/PKRenderer/src/Core/Application.cpp @@ -25,6 +25,8 @@ namespace PK::Core { using namespace Utilities; using namespace Rendering; + using namespace Rendering::Structs; + using namespace Rendering::Objects; using namespace Services; Application* Application::s_Instance = nullptr; @@ -139,7 +141,7 @@ namespace PK::Core Application::~Application() { - GetService()->Release(); + GetService()->Release(); GetService()->Unload(); m_services->Clear(); m_window = nullptr; @@ -148,7 +150,7 @@ namespace PK::Core void Application::Run() { - auto sequencer = GetService(); + auto sequencer = GetService(); while (m_window->IsAlive() && m_Running) { diff --git a/PKRenderer/src/Core/Application.h b/PKRenderer/src/Core/Application.h index 2a2a3078..3aba3721 100644 --- a/PKRenderer/src/Core/Application.h +++ b/PKRenderer/src/Core/Application.h @@ -9,17 +9,13 @@ int main(int argc, char** argv); namespace PK::Core { - using namespace Utilities; - using namespace Rendering; - using namespace Services; - struct ApplicationArguments { int count; char** args; }; - class Application : public NoCopy + class Application : public Utilities::NoCopy { public: Application(ApplicationArguments arguments, const std::string& name = "Application"); @@ -40,9 +36,9 @@ namespace PK::Core static Application* s_Instance; bool m_Running = true; - Scope m_graphicsDriver; - Scope m_window; - Scope m_services; + Utilities::Scope m_graphicsDriver; + Utilities::Scope m_window; + Utilities::Scope m_services; friend int ::main(int argc, char** argv); }; diff --git a/PKRenderer/src/Core/ApplicationConfig.cpp b/PKRenderer/src/Core/ApplicationConfig.cpp index 4f8b4aa0..ceabc295 100644 --- a/PKRenderer/src/Core/ApplicationConfig.cpp +++ b/PKRenderer/src/Core/ApplicationConfig.cpp @@ -91,5 +91,5 @@ namespace PK::Core bool AssetImporters::IsValidExtension(const std::filesystem::path& extension) { return extension.compare(".cfg") == 0; } template<> - Ref AssetImporters::Create() { return CreateRef(); } + Utilities::Ref AssetImporters::Create() { return Utilities::CreateRef(); } } \ No newline at end of file diff --git a/PKRenderer/src/Core/ApplicationConfig.h b/PKRenderer/src/Core/ApplicationConfig.h index 30d36918..677347ef 100644 --- a/PKRenderer/src/Core/ApplicationConfig.h +++ b/PKRenderer/src/Core/ApplicationConfig.h @@ -4,89 +4,86 @@ namespace PK::Core { - using namespace Services; - using namespace YAML; - - struct ApplicationConfig : YamlValueList, public Asset, public IAssetImportSimple + struct ApplicationConfig : YAML::YamlValueList, public Core::Services::Asset, public Core::Services::IAssetImportSimple { - BoxedValue EnableConsole = BoxedValue("EnableConsole", true); - BoxedValue EnableVsync = BoxedValue("EnableVsync", true); - BoxedValue EnableGizmos = BoxedValue("EnableGizmos", false); - BoxedValue EnableLightingDebug = BoxedValue("EnableLightingDebug", false); - BoxedValue EnableCursor = BoxedValue("EnableCursor", true); - BoxedValue EnableFrameRateLog = BoxedValue("EnableFrameRateLog", true); - BoxedValue InitialWidth = BoxedValue("InitialWidth", 1024); - BoxedValue InitialHeight = BoxedValue("InitialHeight", 512); + YAML::BoxedValue EnableConsole = YAML::BoxedValue("EnableConsole", true); + YAML::BoxedValue EnableVsync = YAML::BoxedValue("EnableVsync", true); + YAML::BoxedValue EnableGizmos = YAML::BoxedValue("EnableGizmos", false); + YAML::BoxedValue EnableLightingDebug = YAML::BoxedValue("EnableLightingDebug", false); + YAML::BoxedValue EnableCursor = YAML::BoxedValue("EnableCursor", true); + YAML::BoxedValue EnableFrameRateLog = YAML::BoxedValue("EnableFrameRateLog", true); + YAML::BoxedValue InitialWidth = YAML::BoxedValue("InitialWidth", 1024); + YAML::BoxedValue InitialHeight = YAML::BoxedValue("InitialHeight", 512); - BoxedValue RandomSeed = BoxedValue("RandomSeed", 512); + YAML::BoxedValue RandomSeed = YAML::BoxedValue("RandomSeed", 512); - BoxedValue CameraStartPosition = BoxedValue("CameraStartPosition", PK_FLOAT3_ZERO); - BoxedValue CameraStartRotation = BoxedValue("CameraStartRotation", PK_FLOAT3_ZERO); - BoxedValue CameraSpeed = BoxedValue("CameraSpeed", 5.0f); - BoxedValue CameraLookSensitivity = BoxedValue("CameraLookSensitivity", 1.0f); - BoxedValue CameraMoveSmoothing = BoxedValue("CameraMoveSmoothing", 0.0f); - BoxedValue CameraLookSmoothing = BoxedValue("CameraLookSmoothing", 0.0f); - BoxedValue CameraFov = BoxedValue("CameraFov", 75.0f); - BoxedValue CameraZNear = BoxedValue("CameraZNear", 0.1f); - BoxedValue CameraZFar = BoxedValue("CameraZFar", 200.0f); - BoxedValue CascadeLinearity = BoxedValue("CascadeLinearity", 0.5f); + YAML::BoxedValue CameraStartPosition = YAML::BoxedValue("CameraStartPosition", Math::PK_FLOAT3_ZERO); + YAML::BoxedValue CameraStartRotation = YAML::BoxedValue("CameraStartRotation", Math::PK_FLOAT3_ZERO); + YAML::BoxedValue CameraSpeed = YAML::BoxedValue("CameraSpeed", 5.0f); + YAML::BoxedValue CameraLookSensitivity = YAML::BoxedValue("CameraLookSensitivity", 1.0f); + YAML::BoxedValue CameraMoveSmoothing = YAML::BoxedValue("CameraMoveSmoothing", 0.0f); + YAML::BoxedValue CameraLookSmoothing = YAML::BoxedValue("CameraLookSmoothing", 0.0f); + YAML::BoxedValue CameraFov = YAML::BoxedValue("CameraFov", 75.0f); + YAML::BoxedValue CameraZNear = YAML::BoxedValue("CameraZNear", 0.1f); + YAML::BoxedValue CameraZFar = YAML::BoxedValue("CameraZFar", 200.0f); + YAML::BoxedValue CascadeLinearity = YAML::BoxedValue("CascadeLinearity", 0.5f); - BoxedValue TimeScale = BoxedValue("TimeScale", 1.0f); + YAML::BoxedValue TimeScale = YAML::BoxedValue("TimeScale", 1.0f); - BoxedValue LightCount = BoxedValue("LightCount", 0u); - BoxedValue ShadowmapTileSize = BoxedValue("ShadowmapTileSize", 512); - BoxedValue ShadowmapTileCount = BoxedValue("ShadowmapTileCount", 32); + YAML::BoxedValue LightCount = YAML::BoxedValue("LightCount", 0u); + YAML::BoxedValue ShadowmapTileSize = YAML::BoxedValue("ShadowmapTileSize", 512); + YAML::BoxedValue ShadowmapTileCount = YAML::BoxedValue("ShadowmapTileCount", 32); - BoxedValue CameraFocalLength = BoxedValue("CameraFocalLength", 0.05f); - BoxedValue CameraFNumber = BoxedValue("CameraFNumber", 1.40f); - BoxedValue CameraFilmHeight = BoxedValue("CameraFilmHeight", 0.024f); - BoxedValue CameraFocusSpeed = BoxedValue("CameraFocusSpeed", 5.0f); - BoxedValue AutoExposureLuminanceMin = BoxedValue("AutoExposureLuminanceMin", 1.0f); - BoxedValue AutoExposureLuminanceRange = BoxedValue("AutoExposureLuminanceRange", 1.0f); - BoxedValue AutoExposureSpeed = BoxedValue("AutoExposureSpeed", 1.0f); - BoxedValue TonemapExposure = BoxedValue("TonemapExposure", 1.0f); - BoxedValue VignetteIntensity = BoxedValue("VignetteIntensity", 15.0f); - BoxedValue VignettePower = BoxedValue("VignettePower", 0.25f); - BoxedValue FilmGrainIntensity = BoxedValue("FilmGrainIntensity", 0.25f); - BoxedValue FilmGrainLuminance = BoxedValue("FilmGrainLuminance", 0.25f); - BoxedValue CC_Contribution = BoxedValue("CC_Contribution", 1.0f); - BoxedValue CC_TemperatureShift = BoxedValue("CC_TemperatureShift", 0.0f); - BoxedValue CC_Tint = BoxedValue("CC_Tint", 0.0f); - BoxedValue CC_Hue = BoxedValue("CC_Hue", 0.0f); - BoxedValue CC_Saturation = BoxedValue("CC_Saturation", 1.0f); - BoxedValue CC_Vibrance = BoxedValue("CC_Vibrance", 0.0f); - BoxedValue CC_Value = BoxedValue("CC_Value", 1.0f); - BoxedValue CC_Contrast = BoxedValue("CC_Contrast", 1.0f); - BoxedValue CC_Gain = BoxedValue("CC_Gain", 1.0f); - BoxedValue CC_Gamma = BoxedValue("CC_Gamma", 1.0f); - BoxedValue CC_Shadows = BoxedValue("CC_Shadows", 0x000000FF); - BoxedValue CC_Midtones = BoxedValue("CC_Midtones", 0x7F7F7FFF); - BoxedValue CC_Highlights = BoxedValue("CC_Highlights", 0xFFFFFFFF); - BoxedValue CC_ChannelMixerRed = BoxedValue("CC_ChannelMixerRed", 0xFF0000FF); - BoxedValue CC_ChannelMixerGreen = BoxedValue("CC_ChannelMixerGreen", 0x00FF00FF); - BoxedValue CC_ChannelMixerBlue = BoxedValue("CC_ChannelMixerBlue", 0x0000FFFF); - BoxedValue BloomIntensity = BoxedValue("BloomIntensity", 0.0f); - BoxedValue BloomLensDirtIntensity = BoxedValue("BloomLensDirtIntensity", 0.0f); - BoxedValue FileBloomDirt = BoxedValue("FileBloomDirt", "T_Bloom_LensDirt"); + YAML::BoxedValue CameraFocalLength = YAML::BoxedValue("CameraFocalLength", 0.05f); + YAML::BoxedValue CameraFNumber = YAML::BoxedValue("CameraFNumber", 1.40f); + YAML::BoxedValue CameraFilmHeight = YAML::BoxedValue("CameraFilmHeight", 0.024f); + YAML::BoxedValue CameraFocusSpeed = YAML::BoxedValue("CameraFocusSpeed", 5.0f); + YAML::BoxedValue AutoExposureLuminanceMin = YAML::BoxedValue("AutoExposureLuminanceMin", 1.0f); + YAML::BoxedValue AutoExposureLuminanceRange = YAML::BoxedValue("AutoExposureLuminanceRange", 1.0f); + YAML::BoxedValue AutoExposureSpeed = YAML::BoxedValue("AutoExposureSpeed", 1.0f); + YAML::BoxedValue TonemapExposure = YAML::BoxedValue("TonemapExposure", 1.0f); + YAML::BoxedValue VignetteIntensity = YAML::BoxedValue("VignetteIntensity", 15.0f); + YAML::BoxedValue VignettePower = YAML::BoxedValue("VignettePower", 0.25f); + YAML::BoxedValue FilmGrainIntensity = YAML::BoxedValue("FilmGrainIntensity", 0.25f); + YAML::BoxedValue FilmGrainLuminance = YAML::BoxedValue("FilmGrainLuminance", 0.25f); + YAML::BoxedValue CC_Contribution = YAML::BoxedValue("CC_Contribution", 1.0f); + YAML::BoxedValue CC_TemperatureShift = YAML::BoxedValue("CC_TemperatureShift", 0.0f); + YAML::BoxedValue CC_Tint = YAML::BoxedValue("CC_Tint", 0.0f); + YAML::BoxedValue CC_Hue = YAML::BoxedValue("CC_Hue", 0.0f); + YAML::BoxedValue CC_Saturation = YAML::BoxedValue("CC_Saturation", 1.0f); + YAML::BoxedValue CC_Vibrance = YAML::BoxedValue("CC_Vibrance", 0.0f); + YAML::BoxedValue CC_Value = YAML::BoxedValue("CC_Value", 1.0f); + YAML::BoxedValue CC_Contrast = YAML::BoxedValue("CC_Contrast", 1.0f); + YAML::BoxedValue CC_Gain = YAML::BoxedValue("CC_Gain", 1.0f); + YAML::BoxedValue CC_Gamma = YAML::BoxedValue("CC_Gamma", 1.0f); + YAML::BoxedValue CC_Shadows = YAML::BoxedValue("CC_Shadows", 0x000000FF); + YAML::BoxedValue CC_Midtones = YAML::BoxedValue("CC_Midtones", 0x7F7F7FFF); + YAML::BoxedValue CC_Highlights = YAML::BoxedValue("CC_Highlights", 0xFFFFFFFF); + YAML::BoxedValue CC_ChannelMixerRed = YAML::BoxedValue("CC_ChannelMixerRed", 0xFF0000FF); + YAML::BoxedValue CC_ChannelMixerGreen = YAML::BoxedValue("CC_ChannelMixerGreen", 0x00FF00FF); + YAML::BoxedValue CC_ChannelMixerBlue = YAML::BoxedValue("CC_ChannelMixerBlue", 0x0000FFFF); + YAML::BoxedValue BloomIntensity = YAML::BoxedValue("BloomIntensity", 0.0f); + YAML::BoxedValue BloomLensDirtIntensity = YAML::BoxedValue("BloomLensDirtIntensity", 0.0f); + YAML::BoxedValue FileBloomDirt = YAML::BoxedValue("FileBloomDirt", "T_Bloom_LensDirt"); - BoxedValue AmbientOcclusionIntensity = BoxedValue("AmbientOcclusionIntensity", 1.0f); - BoxedValue AmbientOcclusionRadius = BoxedValue("AmbientOcclusionRadius", 1.0f); - BoxedValue AmbientOcclusionDownsample = BoxedValue("AmbientOcclusionDownsample", true); + YAML::BoxedValue AmbientOcclusionIntensity = YAML::BoxedValue("AmbientOcclusionIntensity", 1.0f); + YAML::BoxedValue AmbientOcclusionRadius = YAML::BoxedValue("AmbientOcclusionRadius", 1.0f); + YAML::BoxedValue AmbientOcclusionDownsample = YAML::BoxedValue("AmbientOcclusionDownsample", true); - BoxedValue VolumeConstantFog = BoxedValue("VolumeConstantFog", 0.0f); - BoxedValue VolumeHeightFogExponent = BoxedValue("VolumeHeightFogExponent", 0.0f); - BoxedValue VolumeHeightFogOffset = BoxedValue("VolumeHeightFogOffset", 0.0f); - BoxedValue VolumeHeightFogAmount = BoxedValue("VolumeHeightFogAmount", 0.0f); - BoxedValue VolumeDensity = BoxedValue("VolumeDensity", 0.0f); - BoxedValue VolumeIntensity = BoxedValue("VolumeIntensity", 0.0f); - BoxedValue VolumeAnisotropy = BoxedValue("VolumeAnisotropy", 0.0f); - BoxedValue VolumeNoiseFogAmount = BoxedValue("VolumeNoiseFogAmount", 0.0f); - BoxedValue VolumeNoiseFogScale = BoxedValue("VolumeNoiseFogScale", 0.0f); - BoxedValue VolumeWindSpeed = BoxedValue("VolumeWindSpeed", 0.0f); - BoxedValue VolumeWindDirection = BoxedValue("VolumeWindDirection", PK_FLOAT3_FORWARD); + YAML::BoxedValue VolumeConstantFog = YAML::BoxedValue("VolumeConstantFog", 0.0f); + YAML::BoxedValue VolumeHeightFogExponent = YAML::BoxedValue("VolumeHeightFogExponent", 0.0f); + YAML::BoxedValue VolumeHeightFogOffset = YAML::BoxedValue("VolumeHeightFogOffset", 0.0f); + YAML::BoxedValue VolumeHeightFogAmount = YAML::BoxedValue("VolumeHeightFogAmount", 0.0f); + YAML::BoxedValue VolumeDensity = YAML::BoxedValue("VolumeDensity", 0.0f); + YAML::BoxedValue VolumeIntensity = YAML::BoxedValue("VolumeIntensity", 0.0f); + YAML::BoxedValue VolumeAnisotropy = YAML::BoxedValue("VolumeAnisotropy", 0.0f); + YAML::BoxedValue VolumeNoiseFogAmount = YAML::BoxedValue("VolumeNoiseFogAmount", 0.0f); + YAML::BoxedValue VolumeNoiseFogScale = YAML::BoxedValue("VolumeNoiseFogScale", 0.0f); + YAML::BoxedValue VolumeWindSpeed = YAML::BoxedValue("VolumeWindSpeed", 0.0f); + YAML::BoxedValue VolumeWindDirection = YAML::BoxedValue("VolumeWindDirection", Math::PK_FLOAT3_FORWARD); - BoxedValue FileBackgroundTexture = BoxedValue("FileBackgroundTexture", "T_OEM_Mountains"); - BoxedValue BackgroundExposure = BoxedValue("BackgroundExposure", 1.0f); + YAML::BoxedValue FileBackgroundTexture = YAML::BoxedValue("FileBackgroundTexture", "T_OEM_Mountains"); + YAML::BoxedValue BackgroundExposure = YAML::BoxedValue("BackgroundExposure", 1.0f); ApplicationConfig(); diff --git a/PKRenderer/src/Core/CommandConfig.cpp b/PKRenderer/src/Core/CommandConfig.cpp index 12308e70..862915a5 100644 --- a/PKRenderer/src/Core/CommandConfig.cpp +++ b/PKRenderer/src/Core/CommandConfig.cpp @@ -11,8 +11,8 @@ namespace PK::Core } template<> - bool AssetImporters::IsValidExtension(const std::filesystem::path& extension) { return extension.compare(".keycfg") == 0; } + bool Services::AssetImporters::IsValidExtension(const std::filesystem::path& extension) { return extension.compare(".keycfg") == 0; } template<> - Ref AssetImporters::Create() { return CreateRef(); } + Utilities::Ref Services::AssetImporters::Create() { return Utilities::CreateRef(); } } \ No newline at end of file diff --git a/PKRenderer/src/Core/CommandConfig.h b/PKRenderer/src/Core/CommandConfig.h index 5aaa0569..d85280b6 100644 --- a/PKRenderer/src/Core/CommandConfig.h +++ b/PKRenderer/src/Core/CommandConfig.h @@ -4,11 +4,9 @@ namespace PK::Core { - using namespace YAML; - - struct CommandConfig : YamlValueList, public Asset, public IAssetImportSimple + struct CommandConfig : YAML::YamlValueList, public Core::Services::Asset, public Core::Services::IAssetImportSimple { - BoxedValue Commands = BoxedValue("Commands", ConsoleCommandBindList()); + YAML::BoxedValue Commands = YAML::BoxedValue("Commands", ConsoleCommandBindList()); CommandConfig(); void Import(const char* filepath, void* pParams) override final; }; diff --git a/PKRenderer/src/Core/ConsoleCommandBinding.h b/PKRenderer/src/Core/ConsoleCommandBinding.h index 5d03cf54..4cd33eed 100644 --- a/PKRenderer/src/Core/ConsoleCommandBinding.h +++ b/PKRenderer/src/Core/ConsoleCommandBinding.h @@ -4,8 +4,6 @@ namespace PK::Core { - using namespace Services; - struct ConsoleCommandToken { const std::string& argument; @@ -14,7 +12,7 @@ namespace PK::Core struct ConsoleCommandBinding { - KeyCode keycode = KeyCode::MOUSE1; + Services::KeyCode keycode = Services::KeyCode::MOUSE1; std::string command; }; diff --git a/PKRenderer/src/Core/Services/AssetDatabase.h b/PKRenderer/src/Core/Services/AssetDatabase.h index 5aea61b4..3d7ee139 100644 --- a/PKRenderer/src/Core/Services/AssetDatabase.h +++ b/PKRenderer/src/Core/Services/AssetDatabase.h @@ -9,11 +9,9 @@ namespace PK::Core::Services { - using namespace PK::Utilities; - typedef uint32_t AssetID; - class Asset : public NoCopy + class Asset : public Utilities::NoCopy { friend class AssetDatabase; @@ -32,7 +30,7 @@ namespace PK::Core::Services // @TODO decouple these from the actual asset classes template - class IAssetImport : public NoCopy + class IAssetImport : public Utilities::NoCopy { friend class AssetDatabase; virtual void Import(const char* filepath, TParams* pParams) = 0; @@ -59,7 +57,7 @@ namespace PK::Core::Services bool IsValidExtension(const std::filesystem::path& extension); template - [[nodiscard]] Ref Create(); + [[nodiscard]] Utilities::Ref Create(); }; class AssetDatabase : public IService @@ -101,7 +99,7 @@ namespace PK::Core::Services auto& collection = m_assets[std::type_index(typeid(T))]; auto iter = collection.find(assetId); - Ref asset = nullptr; + Utilities::Ref asset = nullptr; if (iter != collection.end()) { @@ -134,7 +132,7 @@ namespace PK::Core::Services PK_THROW_ASSERT(collection.count(assetId) < 1, "Procedural asset (%s) already exists", name.c_str()); - auto asset = CreateRef(std::forward(args)...); + auto asset = Utilities::CreateRef(std::forward(args)...); collection[assetId] = asset; std::static_pointer_cast(asset)->m_assetId = assetId; @@ -142,7 +140,7 @@ namespace PK::Core::Services } template - [[nodiscard]] T* RegisterProcedural(std::string name, Ref asset) + [[nodiscard]] T* RegisterProcedural(std::string name, Utilities::Ref asset) { static_assert(std::is_base_of::value, "Template argument type does not derive from Asset!"); @@ -326,7 +324,7 @@ namespace PK::Core::Services } private: - std::unordered_map>> m_assets; + std::unordered_map>> m_assets; Sequencer* m_sequencer; }; } \ No newline at end of file diff --git a/PKRenderer/src/Core/Services/Input.cpp b/PKRenderer/src/Core/Services/Input.cpp index 4ac03743..96fbc7d9 100644 --- a/PKRenderer/src/Core/Services/Input.cpp +++ b/PKRenderer/src/Core/Services/Input.cpp @@ -48,7 +48,7 @@ namespace PK::Core::Services return action == GLFW_PRESS || action == GLFW_REPEAT; } - float2 Input::GetAxis2D(KeyCode front, KeyCode back, KeyCode right, KeyCode left) + Math::float2 Input::GetAxis2D(KeyCode front, KeyCode back, KeyCode right, KeyCode left) { return { @@ -57,7 +57,7 @@ namespace PK::Core::Services }; } - float3 Input::GetAxis3D(KeyCode up, KeyCode down, KeyCode front, KeyCode back, KeyCode right, KeyCode left) + Math::float3 Input::GetAxis3D(KeyCode up, KeyCode down, KeyCode front, KeyCode back, KeyCode right, KeyCode left) { return { diff --git a/PKRenderer/src/Core/Services/Input.h b/PKRenderer/src/Core/Services/Input.h index 2b32082e..be9bedd7 100644 --- a/PKRenderer/src/Core/Services/Input.h +++ b/PKRenderer/src/Core/Services/Input.h @@ -7,8 +7,6 @@ namespace PK::Core::Services { - using namespace Math; - // @TODO Refactor this to be decoupled from glfw enum class KeyCode { @@ -151,12 +149,12 @@ namespace PK::Core::Services bool GetKeyUp(KeyCode key); bool GetKey(KeyCode key); - float2 GetAxis2D(KeyCode front, KeyCode back, KeyCode right, KeyCode left); - float3 GetAxis3D(KeyCode up, KeyCode down, KeyCode front, KeyCode back, KeyCode right, KeyCode left); - inline float2 GetMouseDelta() const { return m_mouseDelta; } - inline float2 GetMousePosition() const { return m_mousePosition; } - inline float2 GetMouseNormalizedPosition() const { return m_mousePositionNormalized; } - inline float2 GetMouseScroll() const { return m_mouseScroll; } + Math::float2 GetAxis2D(KeyCode front, KeyCode back, KeyCode right, KeyCode left); + Math::float3 GetAxis3D(KeyCode up, KeyCode down, KeyCode front, KeyCode back, KeyCode right, KeyCode left); + inline Math::float2 GetMouseDelta() const { return m_mouseDelta; } + inline Math::float2 GetMousePosition() const { return m_mousePosition; } + inline Math::float2 GetMouseNormalizedPosition() const { return m_mousePositionNormalized; } + inline Math::float2 GetMouseScroll() const { return m_mouseScroll; } inline float GetMouseDeltaX() const { return m_mouseDelta.x; } inline float GetMouseDeltaY() const { return m_mouseDelta.y; } inline float GetMouseX() const { return m_mousePosition.x; } @@ -179,11 +177,11 @@ namespace PK::Core::Services Sequencer* m_sequencer; int16_t m_inputActionsCurrent[(int)KeyCode::COUNT]{}; int16_t m_inputActionsPrevious[(int)KeyCode::COUNT]{}; - float2 m_mousePositionNormalized = PK_FLOAT2_ZERO; - float2 m_mousePosition = PK_FLOAT2_ZERO; - float2 m_mousePrev = PK_FLOAT2_ZERO; - float2 m_mouseDelta = PK_FLOAT2_ZERO; - float2 m_mouseScrollRaw = PK_FLOAT2_ZERO; - float2 m_mouseScroll = PK_FLOAT2_ZERO; + Math::float2 m_mousePositionNormalized = Math::PK_FLOAT2_ZERO; + Math::float2 m_mousePosition = Math::PK_FLOAT2_ZERO; + Math::float2 m_mousePrev = Math::PK_FLOAT2_ZERO; + Math::float2 m_mouseDelta = Math::PK_FLOAT2_ZERO; + Math::float2 m_mouseScrollRaw = Math::PK_FLOAT2_ZERO; + Math::float2 m_mouseScroll = Math::PK_FLOAT2_ZERO; }; } \ No newline at end of file diff --git a/PKRenderer/src/Core/Services/Log.h b/PKRenderer/src/Core/Services/Log.h index 041f98ab..c62ff0af 100644 --- a/PKRenderer/src/Core/Services/Log.h +++ b/PKRenderer/src/Core/Services/Log.h @@ -5,8 +5,6 @@ namespace PK::Core::Services::Debug { - using namespace PK::Utilities; - constexpr unsigned short ComposeConsoleColor(unsigned short fore, unsigned short back) { return ((unsigned)back << 4) | (unsigned)fore; @@ -47,7 +45,7 @@ namespace PK::Core::Services::Debug PK_LOG_LVL_ALL_FLAGS = 0xFF, } PKLogSeverityFlags; - class Logger : public IService, public ISingleton + class Logger : public IService, public PK::Utilities::ISingleton { public: Logger(uint32_t filterFlags) : m_filterFlags(filterFlags) {} diff --git a/PKRenderer/src/Core/Services/ServiceRegister.h b/PKRenderer/src/Core/Services/ServiceRegister.h index cb77cb02..b1b034e3 100644 --- a/PKRenderer/src/Core/Services/ServiceRegister.h +++ b/PKRenderer/src/Core/Services/ServiceRegister.h @@ -6,9 +6,7 @@ namespace PK::Core::Services { - using namespace Utilities; - - class ServiceRegister : public NoCopy + class ServiceRegister : public PK::Utilities::NoCopy { public: template @@ -22,13 +20,13 @@ namespace PK::Core::Services auto idx = std::type_index(typeid(T)); PK_THROW_ASSERT(m_services.count(idx) == 0, "Service of type (%s) is already registered", typeid(T).name()); auto service = new T(std::forward(args)...); - m_services[idx] = Scope(service); + m_services[idx] = PK::Utilities::Scope(service); return service; } inline void Clear() { m_services.clear(); } private: - std::unordered_map> m_services; + std::unordered_map> m_services; }; } \ No newline at end of file diff --git a/PKRenderer/src/Core/Window.cpp b/PKRenderer/src/Core/Window.cpp index 7a69472b..822d16a8 100644 --- a/PKRenderer/src/Core/Window.cpp +++ b/PKRenderer/src/Core/Window.cpp @@ -6,10 +6,11 @@ namespace PK::Core { - using namespace PK::Rendering; - using namespace PK::Rendering::Structs; - using namespace PK::Rendering::VulkanRHI; - using namespace PK::Rendering::VulkanRHI::Systems; + using namespace Utilities; + using namespace Rendering; + using namespace Rendering::Structs; + using namespace Rendering::VulkanRHI; + using namespace Rendering::VulkanRHI::Systems; Scope Window::Create(const WindowProperties& properties) { diff --git a/PKRenderer/src/Core/Window.h b/PKRenderer/src/Core/Window.h index 8bb4f741..d44b01b0 100644 --- a/PKRenderer/src/Core/Window.h +++ b/PKRenderer/src/Core/Window.h @@ -7,9 +7,6 @@ namespace PK::Core { - using namespace Utilities; - using namespace Math; - struct WindowProperties { std::string title; @@ -24,14 +21,14 @@ namespace PK::Core } }; - class Window : public NoCopy, public NativeInterface + class Window : public Utilities::NoCopy, public Utilities::NativeInterface { public: - static Scope Create(const WindowProperties& properties); + static Utilities::Scope Create(const WindowProperties& properties); virtual ~Window() = default; - virtual uint3 GetResolution() const = 0; - virtual uint4 GetRect() const = 0; + virtual Math::uint3 GetResolution() const = 0; + virtual Math::uint4 GetRect() const = 0; virtual float GetAspectRatio() const = 0; virtual bool IsAlive() const = 0; virtual bool IsMinimized() const = 0; diff --git a/PKRenderer/src/Core/YamlSerializers.h b/PKRenderer/src/Core/YamlSerializers.h index 391c62ec..5142615d 100644 --- a/PKRenderer/src/Core/YamlSerializers.h +++ b/PKRenderer/src/Core/YamlSerializers.h @@ -107,15 +107,15 @@ namespace YAML static bool decode(const Node& node, Texture*& rhs) { auto path = node.as(); - rhs = Application::GetService()->Load(path); + rhs = PK::Core::Application::GetService()->Load(path); return true; } }; template<> - struct convert + struct convert { - static Node encode(const ConsoleCommandBinding& rhs) + static Node encode(const PK::Core::ConsoleCommandBinding& rhs) { Node node; @@ -125,7 +125,7 @@ namespace YAML return node; } - static bool decode(const Node& node, ConsoleCommandBinding& rhs) + static bool decode(const Node& node, PK::Core::ConsoleCommandBinding& rhs) { if (!node.IsSequence() || node.size() != 2) { @@ -139,9 +139,9 @@ namespace YAML }; template<> - struct convert + struct convert { - static Node encode(const ConsoleCommandBindList& rhs) + static Node encode(const PK::Core::ConsoleCommandBindList& rhs) { Node node; for (auto& arg : rhs) @@ -153,11 +153,11 @@ namespace YAML return node; } - static bool decode(const Node& node, ConsoleCommandBindList& rhs) + static bool decode(const Node& node, PK::Core::ConsoleCommandBindList& rhs) { for (auto i = 0; i < node.size(); ++i) { - rhs.push_back(node[i].as()); + rhs.push_back(node[i].as()); } return true; diff --git a/PKRenderer/src/ECS/Contextual/Builders/Builders.cpp b/PKRenderer/src/ECS/Contextual/Builders/Builders.cpp index 90766a64..d52720de 100644 --- a/PKRenderer/src/ECS/Contextual/Builders/Builders.cpp +++ b/PKRenderer/src/ECS/Contextual/Builders/Builders.cpp @@ -8,8 +8,12 @@ namespace PK::ECS::Builders { - using namespace PK::Rendering; - using namespace PK::Core::Services; + using namespace Utilities; + using namespace Core::Services; + using namespace Math; + using namespace Rendering; + using namespace Rendering::Objects; + using namespace Rendering::Structs; using namespace EntityViews; using namespace Implementers; diff --git a/PKRenderer/src/ECS/Contextual/Builders/Builders.h b/PKRenderer/src/ECS/Contextual/Builders/Builders.h index 0478e6d8..86117f9a 100644 --- a/PKRenderer/src/ECS/Contextual/Builders/Builders.h +++ b/PKRenderer/src/ECS/Contextual/Builders/Builders.h @@ -11,24 +11,21 @@ namespace PK::ECS::Builders { - using namespace PK::Math; - using namespace PK::Rendering::Objects; - using namespace PK::Core::Services; - using namespace EntityViews; - template void BuildTransformView(EntityDatabase* entityDb, T* implementer, const EGID& egid, - const float3& position, - const float3& rotation, - const float3& scale, - const BoundingBox& localBounds) + const Math::float3& position, + const Math::float3& rotation, + const Math::float3& scale, + const Math::BoundingBox& localBounds) { - auto view = entityDb->ReserveEntityView(implementer, egid, &TransformView::bounds, &TransformView::transform); + auto view = entityDb->ReserveEntityView(implementer, egid, + &EntityViews::TransformView::bounds, + &EntityViews::TransformView::transform); implementer->localAABB = localBounds; implementer->position = position; - implementer->rotation = glm::quat(rotation * PK_FLOAT_DEG2RAD); + implementer->rotation = glm::quat(rotation * Math::PK_FLOAT_DEG2RAD); implementer->scale = scale; } @@ -36,9 +33,11 @@ namespace PK::ECS::Builders void BuildBaseRenderableView(EntityDatabase* entityDb, T* implementer, const EGID& egid, - RenderableFlags flags) + Rendering::Structs::RenderableFlags flags) { - auto view = entityDb->ReserveEntityView(implementer, egid, &BaseRenderableView::renderable, &BaseRenderableView::bounds); + auto view = entityDb->ReserveEntityView(implementer, egid, + &EntityViews::BaseRenderableView::renderable, + &EntityViews::BaseRenderableView::bounds); implementer->flags = flags; } @@ -46,10 +45,13 @@ namespace PK::ECS::Builders void BuildMeshRenderableView(EntityDatabase* entityDb, T* implementer, const EGID& egid, - Mesh* mesh, - const std::initializer_list& materials) + Rendering::Objects::Mesh* mesh, + const std::initializer_list& materials) { - auto view = entityDb->ReserveEntityView(implementer, egid, &MeshRenderableView::materials, &MeshRenderableView::mesh, &MeshRenderableView::transform); + auto view = entityDb->ReserveEntityView(implementer, egid, + &EntityViews::MeshRenderableView::materials, + &EntityViews::MeshRenderableView::mesh, + &EntityViews::MeshRenderableView::transform); implementer->materials = materials; implementer->sharedMesh = mesh; } @@ -58,18 +60,18 @@ namespace PK::ECS::Builders void BuildLightRenderableView(EntityDatabase* entityDb, T* implementer, const EGID& egid, - LightType type, - Cookie cookie, - const color& color, + Rendering::Structs::LightType type, + Rendering::Structs::Cookie cookie, + const Math::color& color, float radius, float angle) { auto view = entityDb->ReserveEntityView(implementer, egid, - &LightRenderableView::transform, - &LightRenderableView::bounds, - &LightRenderableView::light, - &LightRenderableView::lightFrameInfo, - &LightRenderableView::renderable); + &EntityViews::LightRenderableView::transform, + &EntityViews::LightRenderableView::bounds, + &EntityViews::LightRenderableView::light, + &EntityViews::LightRenderableView::lightFrameInfo, + &EntityViews::LightRenderableView::renderable); implementer->color = color; implementer->radius = radius; implementer->angle = angle; @@ -81,38 +83,38 @@ namespace PK::ECS::Builders void BuildLightRenderableViews(EntityDatabase* entityDb, T* implementer, const EGID& egid, - LightType type, - Cookie cookie, - const color& color, + Rendering::Structs::LightType type, + Rendering::Structs::Cookie cookie, + const Math::color& color, float angle, float radius, bool castShadows) { const auto intensityThreshold = 0.2f; auto lightColor = glm::exp(color); - auto gammaColor = glm::pow(float3(lightColor.rgb), float3(1.0f / 2.2f)); + auto gammaColor = glm::pow(Math::float3(lightColor.rgb), Math::float3(1.0f / 2.2f)); auto intensity = glm::compMax(gammaColor); auto autoRadius = radius < 0.0f ? intensity / intensityThreshold : radius; - auto flags = RenderableFlags::Light; + auto flags = Rendering::Structs::RenderableFlags::Light; if (castShadows) { - flags = flags | RenderableFlags::CastShadows; + flags = flags | Rendering::Structs::RenderableFlags::CastShadows; } switch (type) { - case LightType::Directional: - implementer->localAABB = BoundingBox::CenterExtents(PK_FLOAT3_ZERO, PK_FLOAT3_ONE); + case Rendering::Structs::LightType::Directional: + implementer->localAABB = Math::BoundingBox::CenterExtents(Math::PK_FLOAT3_ZERO, Math::PK_FLOAT3_ONE); break; - case LightType::Point: - implementer->localAABB = BoundingBox::CenterExtents(PK_FLOAT3_ZERO, PK_FLOAT3_ONE * autoRadius); - flags = flags | RenderableFlags::Cullable; + case Rendering::Structs::LightType::Point: + implementer->localAABB = Math::BoundingBox::CenterExtents(Math::PK_FLOAT3_ZERO, Math::PK_FLOAT3_ONE * autoRadius); + flags = flags | Rendering::Structs::RenderableFlags::Cullable; break; - case LightType::Spot: - auto a = autoRadius * glm::tan(angle * 0.5f * PK_FLOAT_DEG2RAD); - implementer->localAABB = BoundingBox::CenterExtents({ 0.0f, 0.0f, autoRadius * 0.5f }, { a, a, autoRadius * 0.5f }); - flags = flags | RenderableFlags::Cullable; + case Rendering::Structs::LightType::Spot: + auto a = autoRadius * glm::tan(angle * 0.5f * Math::PK_FLOAT_DEG2RAD); + implementer->localAABB = Math::BoundingBox::CenterExtents({ 0.0f, 0.0f, autoRadius * 0.5f }, { a, a, autoRadius * 0.5f }); + flags = flags | Rendering::Structs::RenderableFlags::Cullable; break; } @@ -120,39 +122,39 @@ namespace PK::ECS::Builders BuildLightRenderableView(entityDb, implementer, egid, type, cookie, lightColor, autoRadius, angle); } - EGID BuildMeshRenderableEntity(EntityDatabase* entityDb, - Mesh* mesh, - const std::initializer_list& materials, - const float3& position, - const float3& rotation, + EGID BuildMeshRenderableEntity(EntityDatabase* entityDb, + Rendering::Objects::Mesh* mesh, + const std::initializer_list& materials, + const Math::float3& position, + const Math::float3& rotation, float size = 1.0f, - RenderableFlags flags = RenderableFlags::DefaultMesh); + Rendering::Structs::RenderableFlags flags = Rendering::Structs::RenderableFlags::DefaultMesh); EGID BuildMeshRenderableEntity(EntityDatabase* entityDb, - VirtualMesh* mesh, - const std::initializer_list& materials, - const float3& position, - const float3& rotation, + Rendering::Objects::VirtualMesh* mesh, + const std::initializer_list& materials, + const Math::float3& position, + const Math::float3& rotation, float size = 1.0f, - RenderableFlags flags = RenderableFlags::DefaultMesh); + Rendering::Structs::RenderableFlags flags = Rendering::Structs::RenderableFlags::DefaultMesh); EGID BuildLightRenderableEntity(EntityDatabase* entityDb, - AssetDatabase* assetDatabase, - const float3& position, - const float3& rotation, - LightType type, - Cookie cookie, - const color& color, + Core::Services::AssetDatabase* assetDatabase, + const Math::float3& position, + const Math::float3& rotation, + Rendering::Structs::LightType type, + Rendering::Structs::Cookie cookie, + const Math::color& color, float angle, float radius, bool castShadows); EGID BuildLightSphereRenderableEntity(EntityDatabase* entityDb, - AssetDatabase* assetDatabase, - const float3& position, - LightType type, - Cookie cookie, - const color& color, + Core::Services::AssetDatabase* assetDatabase, + const Math::float3& position, + Rendering::Structs::LightType type, + Rendering::Structs::Cookie cookie, + const Math::color& color, bool castShadows); } \ No newline at end of file diff --git a/PKRenderer/src/ECS/Contextual/Components/Bounds.h b/PKRenderer/src/ECS/Contextual/Components/Bounds.h index 655f5478..eaa61c36 100644 --- a/PKRenderer/src/ECS/Contextual/Components/Bounds.h +++ b/PKRenderer/src/ECS/Contextual/Components/Bounds.h @@ -3,12 +3,10 @@ namespace PK::ECS::Components { - using namespace PK::Math; - struct Bounds { - BoundingBox localAABB; - BoundingBox worldAABB; + PK::Math::BoundingBox localAABB; + PK::Math::BoundingBox worldAABB; virtual ~Bounds() = default; }; } \ No newline at end of file diff --git a/PKRenderer/src/ECS/Contextual/Components/Light.h b/PKRenderer/src/ECS/Contextual/Components/Light.h index 6bdef1e4..6831dc5e 100644 --- a/PKRenderer/src/ECS/Contextual/Components/Light.h +++ b/PKRenderer/src/ECS/Contextual/Components/Light.h @@ -4,17 +4,14 @@ namespace PK::ECS::Components { - using namespace PK::Math; - using namespace PK::Rendering::Structs; - struct Light { - color color = PK_COLOR_WHITE; + PK::Math::color color = PK::Math::PK_COLOR_WHITE; float radius = 1.0f; float angle = 45.0f; float shadowBlur = 0.1f; - Cookie cookie = Cookie::Circle0; - LightType type = LightType::Point; + PK::Rendering::Structs::Cookie cookie = PK::Rendering::Structs::Cookie::Circle0; + PK::Rendering::Structs::LightType type = PK::Rendering::Structs::LightType::Point; virtual ~Light() = default; }; diff --git a/PKRenderer/src/ECS/Contextual/Components/Materials.h b/PKRenderer/src/ECS/Contextual/Components/Materials.h index 8a5230c3..2f4ff4a5 100644 --- a/PKRenderer/src/ECS/Contextual/Components/Materials.h +++ b/PKRenderer/src/ECS/Contextual/Components/Materials.h @@ -3,11 +3,9 @@ namespace PK::ECS::Components { - using namespace PK::Rendering::Objects; - struct Materials { - std::vector materials; + std::vector materials; virtual ~Materials() = default; }; } \ No newline at end of file diff --git a/PKRenderer/src/ECS/Contextual/Components/MeshReference.h b/PKRenderer/src/ECS/Contextual/Components/MeshReference.h index ce2e1b55..5b1dc06c 100644 --- a/PKRenderer/src/ECS/Contextual/Components/MeshReference.h +++ b/PKRenderer/src/ECS/Contextual/Components/MeshReference.h @@ -3,11 +3,9 @@ namespace PK::ECS::Components { - using namespace PK::Rendering::Objects; - struct MeshReference { - Mesh* sharedMesh = nullptr; + PK::Rendering::Objects::Mesh* sharedMesh = nullptr; virtual ~MeshReference() = default; }; } \ No newline at end of file diff --git a/PKRenderer/src/ECS/Contextual/Components/Renderable.h b/PKRenderer/src/ECS/Contextual/Components/Renderable.h index 1326caab..27bf6414 100644 --- a/PKRenderer/src/ECS/Contextual/Components/Renderable.h +++ b/PKRenderer/src/ECS/Contextual/Components/Renderable.h @@ -3,11 +3,9 @@ namespace PK::ECS::Components { - using namespace PK::Rendering::Structs; - struct Renderable { - RenderableFlags flags = RenderableFlags::Mesh; + PK::Rendering::Structs::RenderableFlags flags = PK::Rendering::Structs::RenderableFlags::Mesh; virtual ~Renderable() = default; }; } \ No newline at end of file diff --git a/PKRenderer/src/ECS/Contextual/Components/Transform.h b/PKRenderer/src/ECS/Contextual/Components/Transform.h index 0d63fbb2..cdb4b976 100644 --- a/PKRenderer/src/ECS/Contextual/Components/Transform.h +++ b/PKRenderer/src/ECS/Contextual/Components/Transform.h @@ -3,19 +3,16 @@ namespace PK::ECS::Components { - using namespace PK::Math; - struct Transform { - float3 position = PK_FLOAT3_ZERO; - quaternion rotation = PK_QUATERNION_IDENTITY; - float3 scale = PK_FLOAT3_ONE; - - float4x4 localToWorld = PK_FLOAT4X4_IDENTITY; - float4x4 worldToLocal = PK_FLOAT4X4_IDENTITY; + Math::float3 position = Math::PK_FLOAT3_ZERO; + Math::quaternion rotation = Math::PK_QUATERNION_IDENTITY; + Math::float3 scale = Math::PK_FLOAT3_ONE; + Math::float4x4 localToWorld = Math::PK_FLOAT4X4_IDENTITY; + Math::float4x4 worldToLocal = Math::PK_FLOAT4X4_IDENTITY; - inline float4x4 GetLocalToWorld() const { return Functions::GetMatrixTRS(position, rotation, scale); } - inline float4x4 GetWorldToLocal() const { return Functions::GetMatrixInvTRS(position, rotation, scale); } + inline Math::float4x4 GetLocalToWorld() const { return Math::Functions::GetMatrixTRS(position, rotation, scale); } + inline Math::float4x4 GetWorldToLocal() const { return Math::Functions::GetMatrixInvTRS(position, rotation, scale); } virtual ~Transform() = default; }; diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineCommandInput.cpp b/PKRenderer/src/ECS/Contextual/Engines/EngineCommandInput.cpp index ca11f32a..b9d6a15c 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineCommandInput.cpp +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineCommandInput.cpp @@ -9,7 +9,11 @@ namespace PK::ECS::Engines { - using namespace PK::Math; + using namespace Math; + using namespace Core; + using namespace Core::Services; + using namespace Rendering::Objects; + using namespace Rendering::Structs; const std::unordered_map EngineCommandInput::ArgumentMap = { diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineCommandInput.h b/PKRenderer/src/ECS/Contextual/Engines/EngineCommandInput.h index 15b2bc42..e0e5dd7c 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineCommandInput.h +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineCommandInput.h @@ -10,9 +10,6 @@ namespace PK::ECS::Engines { - using namespace PK::Utilities; - using namespace PK::Rendering::Objects; - enum class CommandArgument : char { Query, @@ -38,13 +35,18 @@ namespace PK::ECS::Engines { }; - class EngineCommandInput : public IService, public IStep + class EngineCommandInput : public Core::Services::IService, public Core::Services::IStep { public: const static std::unordered_map ArgumentMap; - EngineCommandInput(AssetDatabase* assetDatabase, Sequencer* sequencer, Time* time, EntityDatabase* entityDb, CommandConfig* commandBindings); - void Step(Input* input) override final; + EngineCommandInput(Core::Services::AssetDatabase* assetDatabase, + Core::Services::Sequencer* sequencer, + Core::Services::Time* time, + EntityDatabase* entityDb, + Core::CommandConfig* commandBindings); + + void Step(Core::Services::Input* input) override final; private: void ApplicationExit(const ConsoleCommand& arguments); @@ -67,10 +69,10 @@ namespace PK::ECS::Engines void ProcessCommand(const std::string& command); std::map, std::function> m_commands; - CommandConfig* m_commandBindings = nullptr; + Core::CommandConfig* m_commandBindings = nullptr; EntityDatabase* m_entityDb = nullptr; - AssetDatabase* m_assetDatabase = nullptr; - Sequencer* m_sequencer = nullptr; - Time* m_time = nullptr; + Core::Services::AssetDatabase* m_assetDatabase = nullptr; + Core::Services::Sequencer* m_sequencer = nullptr; + Core::Services::Time* m_time = nullptr; }; } \ No newline at end of file diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineCull.cpp b/PKRenderer/src/ECS/Contextual/Engines/EngineCull.cpp index c327c3ed..f4f720d8 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineCull.cpp +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineCull.cpp @@ -5,7 +5,10 @@ namespace PK::ECS::Engines { - using namespace PK::ECS::EntityViews; + using namespace ECS::EntityViews; + using namespace ECS::Tokens; + using namespace Rendering::Structs; + using namespace Math; EngineCull::EngineCull(EntityDatabase* entityDb) : m_entityDb(entityDb) { diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineCull.h b/PKRenderer/src/ECS/Contextual/Engines/EngineCull.h index 9f0f7c03..f4d24b20 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineCull.h +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineCull.h @@ -6,21 +6,16 @@ namespace PK::ECS::Engines { - using namespace PK::ECS::Tokens; - using namespace PK::Math; - using namespace PK::Rendering::Structs; - using namespace PK::Core::Services; - - class EngineCull : public IService, - public IStep, - public IStep, - public IStep + class EngineCull : public Core::Services::IService, + public Core::Services::IStep, + public Core::Services::IStep, + public Core::Services::IStep { public: EngineCull(EntityDatabase* entityDb); - void Step(TokenCullFrustum* token) override final; - void Step(TokenCullCubeFaces* token) override final; - void Step(TokenCullCascades* token) override final; + void Step(Tokens::TokenCullFrustum* token) override final; + void Step(Tokens::TokenCullCubeFaces* token) override final; + void Step(Tokens::TokenCullCascades* token) override final; private: EntityDatabase* m_entityDb = nullptr; diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineDebug.cpp b/PKRenderer/src/ECS/Contextual/Engines/EngineDebug.cpp index 73511ce4..3ace4765 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineDebug.cpp +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineDebug.cpp @@ -9,9 +9,12 @@ namespace PK::ECS::Engines { - using namespace PK::Rendering::Objects; - using namespace PK::Rendering::Structs; + using namespace PK::Utilities; using namespace PK::Math; + using namespace PK::Core; + using namespace PK::Core::Services; + using namespace PK::Rendering::Structs; + using namespace PK::Rendering::Objects; EngineDebug::EngineDebug(AssetDatabase* assetDatabase, EntityDatabase* entityDb, const ApplicationConfig* config) { diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineDebug.h b/PKRenderer/src/ECS/Contextual/Engines/EngineDebug.h index 7873d879..ef2ca1cb 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineDebug.h +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineDebug.h @@ -5,18 +5,15 @@ namespace PK::ECS::Engines { - using namespace PK::Utilities; - using namespace PK::Rendering::Objects; - - class EngineDebug : public IService, public ISimpleStep + class EngineDebug : public Core::Services::IService, public Core::Services::ISimpleStep { public: - EngineDebug(AssetDatabase* assetDatabase, EntityDatabase* entityDb, const ApplicationConfig* config); + EngineDebug(Core::Services::AssetDatabase* assetDatabase, EntityDatabase* entityDb, const Core::ApplicationConfig* config); void Step(int condition) override; private: EntityDatabase* m_entityDb; - AssetDatabase* m_assetDatabase; - Ref m_virtualBaseMesh = nullptr; + Core::Services::AssetDatabase* m_assetDatabase; + Utilities::Ref m_virtualBaseMesh = nullptr; }; } \ No newline at end of file diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineEditorCamera.cpp b/PKRenderer/src/ECS/Contextual/Engines/EngineEditorCamera.cpp index 4e50d9e9..7a702ff5 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineEditorCamera.cpp +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineEditorCamera.cpp @@ -8,7 +8,9 @@ namespace PK::ECS::Engines { - using namespace PK::Math; + using namespace Math; + using namespace Core; + using namespace Core::Services; EngineEditorCamera::EngineEditorCamera(Sequencer* sequencer, Time* time, const ApplicationConfig* config) { diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineEditorCamera.h b/PKRenderer/src/ECS/Contextual/Engines/EngineEditorCamera.h index 774c069a..5a44ffe3 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineEditorCamera.h +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineEditorCamera.h @@ -8,26 +8,24 @@ namespace PK::ECS::Engines { - using namespace PK::Math; - using namespace PK::Core; - using namespace PK::Core::Services; - - class EngineEditorCamera : public IService, public IStep, public IStep + class EngineEditorCamera : public Core::Services::IService, + public Core::Services::IStep, + public Core::Services::IStep { public: - EngineEditorCamera(Sequencer* sequencer, Time* time, const ApplicationConfig* config); - void Step(Input* input) override final; - void Step(ConsoleCommandToken* token) override final; + EngineEditorCamera(Core::Services::Sequencer* sequencer, Core::Services::Time* time, const Core::ApplicationConfig* config); + void Step(Core::Services::Input* input) override final; + void Step(Core::ConsoleCommandToken* token) override final; private: - Sequencer* m_sequencer = nullptr; - Time* m_time = nullptr; - const ApplicationConfig* m_config = nullptr; - float3 m_position = PK_FLOAT3_ZERO; - float3 m_eulerAngles = PK_FLOAT3_ZERO; - quaternion m_rotation = PK_QUATERNION_IDENTITY; - float3 m_smoothPosition = PK_FLOAT3_ZERO; - quaternion m_smoothRotation = PK_QUATERNION_IDENTITY; + Core::Services::Sequencer* m_sequencer = nullptr; + Core::Services::Time* m_time = nullptr; + const Core::ApplicationConfig* m_config = nullptr; + Math::float3 m_position = Math::PK_FLOAT3_ZERO; + Math::float3 m_eulerAngles = Math::PK_FLOAT3_ZERO; + Math::quaternion m_rotation = Math::PK_QUATERNION_IDENTITY; + Math::float3 m_smoothPosition = Math::PK_FLOAT3_ZERO; + Math::quaternion m_smoothRotation = Math::PK_QUATERNION_IDENTITY; float m_fieldOfView = 60.0f; float m_zNear = 0.1f; float m_zFar = 250.0f; diff --git a/PKRenderer/src/ECS/Contextual/Engines/EnginePKAssetBuilder.cpp b/PKRenderer/src/ECS/Contextual/Engines/EnginePKAssetBuilder.cpp index 0a46938d..2dd78ed3 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EnginePKAssetBuilder.cpp +++ b/PKRenderer/src/ECS/Contextual/Engines/EnginePKAssetBuilder.cpp @@ -4,6 +4,8 @@ namespace PK::ECS::Engines { + using namespace Core; + EnginePKAssetBuilder::EnginePKAssetBuilder(const ApplicationArguments& arguments) : m_executablePath(L"") { if (arguments.count < 4) diff --git a/PKRenderer/src/ECS/Contextual/Engines/EnginePKAssetBuilder.h b/PKRenderer/src/ECS/Contextual/Engines/EnginePKAssetBuilder.h index a1c76793..665b486f 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EnginePKAssetBuilder.h +++ b/PKRenderer/src/ECS/Contextual/Engines/EnginePKAssetBuilder.h @@ -6,16 +6,11 @@ namespace PK::ECS::Engines { - using namespace PK::Math; - using namespace PK::Rendering::Structs; - using namespace PK::Core; - using namespace PK::Core::Services; - - class EnginePKAssetBuilder : public IService, public IStep + class EnginePKAssetBuilder : public Core::Services::IService, public Core::Services::IStep { public: - EnginePKAssetBuilder(const ApplicationArguments& arguments); - void Step(ConsoleCommandToken* token) override final; + EnginePKAssetBuilder(const Core::ApplicationArguments& arguments); + void Step(Core::ConsoleCommandToken* token) override final; private: std::wstring m_executablePath; diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineScreenshot.cpp b/PKRenderer/src/ECS/Contextual/Engines/EngineScreenshot.cpp index fe47da0e..bce7cb91 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineScreenshot.cpp +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineScreenshot.cpp @@ -4,7 +4,12 @@ namespace PK::ECS::Engines { - using namespace PK::Rendering; + using namespace Math; + using namespace Core; + using namespace Core::Services; + using namespace Rendering; + using namespace Rendering::Structs; + using namespace Rendering::Objects; // Source: https://elcharolin.wordpress.com/2018/11/28/read-and-write-bmp-files-in-c-c/ static void WriteImage(const char* fileName, byte* pixels, uint width, uint height) diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineScreenshot.h b/PKRenderer/src/ECS/Contextual/Engines/EngineScreenshot.h index 9380ce6a..2dab0c58 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineScreenshot.h +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineScreenshot.h @@ -9,23 +9,22 @@ namespace PK::ECS::Engines { - using namespace PK::Utilities; - using namespace PK::Rendering::Objects; - - class EngineScreenshot : public IService, public IStep, public IStep + class EngineScreenshot : public Core::Services::IService, + public Core::Services::IStep, + public Core::Services::IStep { public: EngineScreenshot(); - void Step(Window* window) override final; - void Step(ConsoleCommandToken* token) override final; + void Step(Core::Window* window) override final; + void Step(Core::ConsoleCommandToken* token) override final; private: - ExecutionGate m_copyGate; - MemoryBlock m_accumulatedPixels; - Ref m_copyBuffer; + Rendering::Structs::ExecutionGate m_copyGate; + Utilities::MemoryBlock m_accumulatedPixels; + Utilities::Ref m_copyBuffer; uint32_t m_captureCounter = 0u; uint32_t m_captureFrameCount = 0u; - uint2 m_captureResolution = PK_UINT2_ZERO; - uint2 m_currentResolution = PK_UINT2_ZERO; + Math::uint2 m_captureResolution = Math::PK_UINT2_ZERO; + Math::uint2 m_currentResolution = Math::PK_UINT2_ZERO; }; } \ No newline at end of file diff --git a/PKRenderer/src/ECS/Contextual/Engines/EngineUpdateTransforms.h b/PKRenderer/src/ECS/Contextual/Engines/EngineUpdateTransforms.h index 6357e634..0812dc55 100644 --- a/PKRenderer/src/ECS/Contextual/Engines/EngineUpdateTransforms.h +++ b/PKRenderer/src/ECS/Contextual/Engines/EngineUpdateTransforms.h @@ -5,7 +5,7 @@ namespace PK::ECS::Engines { - class EngineUpdateTransforms : public IService, public ISimpleStep + class EngineUpdateTransforms : public Core::Services::IService, public Core::Services::ISimpleStep { public: EngineUpdateTransforms(EntityDatabase* entityDb); diff --git a/PKRenderer/src/ECS/Contextual/Tokens/CullingTokens.cpp b/PKRenderer/src/ECS/Contextual/Tokens/CullingTokens.cpp index 43d56bc2..3c2ebb77 100644 --- a/PKRenderer/src/ECS/Contextual/Tokens/CullingTokens.cpp +++ b/PKRenderer/src/ECS/Contextual/Tokens/CullingTokens.cpp @@ -4,7 +4,7 @@ namespace PK::ECS::Tokens { - void VisibilityList::Add(uint entityId, ushort depth, ushort clipId) + void VisibilityList::Add(uint32_t entityId, uint16_t depth, uint16_t clipId) { results.Validate(count + 1u); results[count++] = { entityId, depth, clipId }; diff --git a/PKRenderer/src/ECS/Contextual/Tokens/CullingTokens.h b/PKRenderer/src/ECS/Contextual/Tokens/CullingTokens.h index 06474e7a..b923f2ac 100644 --- a/PKRenderer/src/ECS/Contextual/Tokens/CullingTokens.h +++ b/PKRenderer/src/ECS/Contextual/Tokens/CullingTokens.h @@ -5,23 +5,19 @@ namespace PK::ECS::Tokens { - using namespace PK::Utilities; - using namespace PK::Math; - using namespace PK::Rendering::Structs; - struct VisibleItem { - uint entityId; - ushort depth; - ushort clipId; + uint32_t entityId; + uint16_t depth; + uint16_t clipId; }; struct VisibilityList { - MemoryBlock results; + Utilities::MemoryBlock results; size_t count; VisibilityList(size_t count) : results(512){} - void Add(uint entityId, ushort depth, ushort clipId); + void Add(uint32_t entityId, uint16_t depth, uint16_t clipId); inline void Clear() { count = 0ull; } inline const VisibleItem& operator [] (size_t index) const { return results[index]; } }; @@ -29,24 +25,24 @@ namespace PK::ECS::Tokens struct TokenCullBase { VisibilityList* results; - RenderableFlags mask; + Rendering::Structs::RenderableFlags mask; float depthRange; }; struct TokenCullFrustum : public TokenCullBase { - FrustumPlanes planes; + Math::FrustumPlanes planes; }; struct TokenCullCubeFaces : public TokenCullBase { - BoundingBox aabb; + Math::BoundingBox aabb; }; struct TokenCullCascades : public TokenCullBase { - FrustumPlanes* cascades; - uint count; + Math::FrustumPlanes* cascades; + uint32_t count; }; struct CullTokens diff --git a/PKRenderer/src/ECS/Contextual/Tokens/ViewProjectionToken.h b/PKRenderer/src/ECS/Contextual/Tokens/ViewProjectionToken.h index 391b4ff8..93c67f66 100644 --- a/PKRenderer/src/ECS/Contextual/Tokens/ViewProjectionToken.h +++ b/PKRenderer/src/ECS/Contextual/Tokens/ViewProjectionToken.h @@ -3,11 +3,9 @@ namespace PK::ECS::Tokens { - using namespace PK::Math; - struct ViewProjectionUpdateToken { - float4x4 view; - float4x4 projection; + Math::float4x4 view; + Math::float4x4 projection; }; } \ No newline at end of file diff --git a/PKRenderer/src/ECS/EntityDatabase.h b/PKRenderer/src/ECS/EntityDatabase.h index cb5589a9..e0fd3de4 100644 --- a/PKRenderer/src/ECS/EntityDatabase.h +++ b/PKRenderer/src/ECS/EntityDatabase.h @@ -7,10 +7,6 @@ namespace PK::ECS { - using namespace PK::Utilities; - using namespace PK::Core; - using namespace PK::Core::Services; - enum class ENTITY_GROUPS { INVALID = 0, @@ -66,7 +62,7 @@ namespace PK::ECS struct ImplementerContainer { size_t count = 0; - std::vector> buckets; + std::vector> buckets; }; struct EntityViewsCollection @@ -87,7 +83,7 @@ namespace PK::ECS }; - class EntityDatabase : public IService + class EntityDatabase : public Core::Services::IService { public: constexpr int ReserveEntityId() { return ++m_idCounter; } @@ -111,7 +107,7 @@ namespace PK::ECS auto newBucket = new ImplementerBucket(); newBucket->data = new T[elementsPerBucket]; newBucket->destructor = [](void* v) { delete[] reinterpret_cast(v); }; - container.buckets.push_back(Scope(newBucket)); + container.buckets.push_back(Utilities::Scope(newBucket)); } return reinterpret_cast(container.buckets.at(bucketIndex).get()->data) + subIndex; @@ -142,7 +138,7 @@ namespace PK::ECS } template - const BufferView Query(const uint32_t group) + const Utilities::BufferView Query(const uint32_t group) { static_assert(std::is_base_of::value, "Template argument type does not derive from IEntityView!"); PK_THROW_ASSERT(group, "Trying to acquire resources for an invalid egid!"); diff --git a/PKRenderer/src/Rendering/Batcher.cpp b/PKRenderer/src/Rendering/Batcher.cpp index 27daeb9a..b5c0cd83 100644 --- a/PKRenderer/src/Rendering/Batcher.cpp +++ b/PKRenderer/src/Rendering/Batcher.cpp @@ -8,11 +8,17 @@ #include "Utilities/VectorUtilities.h" #include "Math/FunctionsIntersect.h" -using namespace PK::Rendering; -using namespace PK::ECS::EntityViews; - namespace PK::Rendering { + using namespace Core; + using namespace Core::Services; + using namespace Rendering; + using namespace Rendering::Structs; + using namespace Rendering::Objects; + using namespace Math; + using namespace ECS; + using namespace ECS::EntityViews; + uint16_t MaterialGroup::Add(Material* material) { if (stride == 0ull) diff --git a/PKRenderer/src/Rendering/Batcher.h b/PKRenderer/src/Rendering/Batcher.h index 5f16df39..8573be6e 100644 --- a/PKRenderer/src/Rendering/Batcher.h +++ b/PKRenderer/src/Rendering/Batcher.h @@ -14,24 +14,21 @@ namespace PK::Rendering { - using namespace PK::Rendering::Objects; - using namespace PK::ECS; - struct DrawCall { - const Mesh* mesh = nullptr; - const Shader* shader = nullptr; - IndexRange indices{}; + const Objects::Mesh* mesh = nullptr; + const Objects::Shader* shader = nullptr; + Structs::IndexRange indices{}; }; struct MaterialGroup { - IndexedSet materials; + Utilities::IndexedSet materials; size_t firstIndex = 0ull; size_t stride = 0ull; MaterialGroup() : materials(32){} - uint16_t Add(Material* material); + uint16_t Add(Objects::Material* material); inline void Clear() { firstIndex = 0ull; materials.Clear(); } constexpr size_t GetSize() const { return materials.GetCount() * stride; } constexpr size_t GetOffset() const { return firstIndex * stride; } @@ -60,31 +57,31 @@ namespace PK::Rendering } }; - class Batcher : public PK::Core::NoCopy + class Batcher : public Utilities::NoCopy { public: Batcher(); void BeginCollectDrawCalls(); void EndCollectDrawCalls(); constexpr uint32_t BeginNewGroup() { return m_groupIndex++; } - void SubmitDraw(Components::Transform* transform, Shader* shader, Material* material, Mesh* mesh, uint32_t submesh, uint32_t clipIndex); - void Render(CommandBuffer* cmd, uint32_t group, FixedFunctionShaderAttributes* overrideAttributes = nullptr, uint32_t requireKeyword = 0u); + void SubmitDraw(ECS::Components::Transform* transform, Objects::Shader* shader, Objects::Material* material, Objects::Mesh* mesh, uint32_t submesh, uint32_t clipIndex); + void Render(Objects::CommandBuffer* cmd, uint32_t group, Structs::FixedFunctionShaderAttributes* overrideAttributes = nullptr, uint32_t requireKeyword = 0u); private: - Ref m_matrices; - Ref m_indices; - Ref m_properties; - Ref m_indirectArguments; - BindSet m_textures2D; + Utilities::Ref m_matrices; + Utilities::Ref m_indices; + Utilities::Ref m_properties; + Utilities::Ref m_indirectArguments; + Objects::BindSet m_textures2D; std::vector m_drawCalls; - std::vector m_passGroups; + std::vector m_passGroups; std::vector m_drawInfos; - FixedList m_materials; - IndexedSet m_meshes; - IndexedSet m_shaders; - IndexedSet m_transforms; + Utilities::FixedList m_materials; + Utilities::IndexedSet m_meshes; + Utilities::IndexedSet m_shaders; + Utilities::IndexedSet m_transforms; uint16_t m_groupIndex = 0u; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/GraphicsAPI.cpp b/PKRenderer/src/Rendering/GraphicsAPI.cpp index ef5b6f0c..2294abe8 100644 --- a/PKRenderer/src/Rendering/GraphicsAPI.cpp +++ b/PKRenderer/src/Rendering/GraphicsAPI.cpp @@ -6,9 +6,10 @@ namespace PK::Rendering { + using namespace Rendering::Objects; using namespace Structs; using namespace VulkanRHI; - using namespace PK::Utilities; + using namespace Utilities; static GraphicsDriver* s_currentDriver; diff --git a/PKRenderer/src/Rendering/GraphicsAPI.h b/PKRenderer/src/Rendering/GraphicsAPI.h index f0a9df2d..8b195dbc 100644 --- a/PKRenderer/src/Rendering/GraphicsAPI.h +++ b/PKRenderer/src/Rendering/GraphicsAPI.h @@ -6,10 +6,6 @@ namespace PK::Rendering { - using namespace Structs; - using namespace Utilities; - using namespace PK::Rendering::Objects; - // @TODO investigate if this is can be fulfilled by a possible dx12 implementation? struct DriverMemoryInfo { @@ -26,17 +22,17 @@ namespace PK::Rendering size_t unusedRangeSizeMax; }; - struct GraphicsDriver : public PK::Core::NoCopy + struct GraphicsDriver : public PK::Utilities::NoCopy { virtual ~GraphicsDriver() = default; - virtual APIType GetAPI() const = 0; - virtual CommandBuffer* GetPrimaryCommandBuffer() = 0; + virtual Structs::APIType GetAPI() const = 0; + virtual Objects::CommandBuffer* GetPrimaryCommandBuffer() = 0; virtual void WaitForIdle() const = 0; virtual DriverMemoryInfo GetMemoryInfo() const = 0; - virtual size_t GetBufferOffsetAlignment(BufferUsage usage) const = 0; + virtual size_t GetBufferOffsetAlignment(Structs::BufferUsage usage) const = 0; virtual void GC() = 0; - static Scope Create(const std::string& workingDirectory, APIType api); + static Utilities::Scope Create(const std::string& workingDirectory, Structs::APIType api); }; namespace GraphicsAPI @@ -50,13 +46,13 @@ namespace PK::Rendering return static_cast(GetActiveDriver()); } - APIType GetActiveAPI(); + Structs::APIType GetActiveAPI(); // Add support for secondary commandbuffers - CommandBuffer* GetCommandBuffer(); + Objects::CommandBuffer* GetCommandBuffer(); DriverMemoryInfo GetMemoryInfo(); - size_t GetBufferOffsetAlignment(BufferUsage usage); + size_t GetBufferOffsetAlignment(Structs::BufferUsage usage); void GC(); } diff --git a/PKRenderer/src/Rendering/HashCache.h b/PKRenderer/src/Rendering/HashCache.h index d0634a38..2f41d8e0 100644 --- a/PKRenderer/src/Rendering/HashCache.h +++ b/PKRenderer/src/Rendering/HashCache.h @@ -5,12 +5,10 @@ namespace PK::Rendering { - using namespace PK::Core::Services; - using namespace PK::Utilities; - - struct HashCache : public IService, public ISingleton + struct HashCache : public Core::Services::IService, + public Utilities::ISingleton { - #define DECLARE_HASH(name) uint32_t name = StringHashID::StringToID(#name); \ + #define DECLARE_HASH(name) uint32_t name = Core::Services::StringHashID::StringToID(#name); \ DECLARE_HASH(_MainTex) DECLARE_HASH(_SourceTex) @@ -140,11 +138,11 @@ namespace PK::Rendering #undef DEFINE_HASH_CACHE - uint32_t pk_Instancing_Transforms = StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_TRANSFORMS); - uint32_t pk_Instancing_Indices = StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_INDICES); - uint32_t pk_Instancing_Properties = StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_PROPERTIES); - uint32_t pk_Instancing_Textures2D = StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_TEXTURES2D); - uint32_t pk_Instancing_Textures3D = StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_TEXTURES3D); - uint32_t pk_Instancing_TexturesCube = StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_TEXTURESCUBE); + uint32_t pk_Instancing_Transforms = Core::Services::StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_TRANSFORMS); + uint32_t pk_Instancing_Indices = Core::Services::StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_INDICES); + uint32_t pk_Instancing_Properties = Core::Services::StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_PROPERTIES); + uint32_t pk_Instancing_Textures2D = Core::Services::StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_TEXTURES2D); + uint32_t pk_Instancing_Textures3D = Core::Services::StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_TEXTURES3D); + uint32_t pk_Instancing_TexturesCube = Core::Services::StringHashID::StringToID(PK::Assets::Shader::PK_SHADER_INSTANCING_TEXTURESCUBE); }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/MeshUtilitity.cpp b/PKRenderer/src/Rendering/MeshUtilitity.cpp index 03f28cae..090b062c 100644 --- a/PKRenderer/src/Rendering/MeshUtilitity.cpp +++ b/PKRenderer/src/Rendering/MeshUtilitity.cpp @@ -6,6 +6,9 @@ namespace PK::Rendering::MeshUtility { using namespace Utilities; + using namespace Math; + using namespace Objects; + using namespace Structs; namespace MikktsInterface0 { @@ -164,7 +167,7 @@ namespace PK::Rendering::MeshUtility } } - void CalculateNormals(const float3* vertices, const uint* indices, float3* normals, uint vcount, uint icount, float sign) + void CalculateNormals(const float3* vertices, const uint32_t* indices, float3* normals, uint32_t vcount, uint32_t icount, float sign) { for (uint i = 0, j = 0; i < icount; i += 3) { @@ -190,7 +193,7 @@ namespace PK::Rendering::MeshUtility } - void CalculateTangents(const float3* vertices, const float3* normals, const float2* texcoords, const uint* indices, float4* tangents, uint vcount, uint icount) + void CalculateTangents(const float3* vertices, const float3* normals, const float2* texcoords, const uint32_t* indices, float4* tangents, uint32_t vcount, uint32_t icount) { MikktsInterface0::PKMeshData data; data.vertices = reinterpret_cast(vertices); @@ -217,7 +220,7 @@ namespace PK::Rendering::MeshUtility PK_THROW_ASSERT(genTangSpaceDefault(&context), "Failed to calculate tangents"); } - void CalculateTangents(void* vertices, uint stride, uint vertexOffset, uint normalOffset, uint tangentOffset, uint texcoordOffset, const uint* indices, uint vcount, uint icount) + void CalculateTangents(void* vertices, uint32_t stride, uint32_t vertexOffset, uint32_t normalOffset, uint32_t tangentOffset, uint32_t texcoordOffset, const uint32_t* indices, uint32_t vcount, uint32_t icount) { MikktsInterface1::PKMeshData data; data.vertices = reinterpret_cast(vertices); diff --git a/PKRenderer/src/Rendering/MeshUtility.h b/PKRenderer/src/Rendering/MeshUtility.h index 3006cd45..3ea63403 100644 --- a/PKRenderer/src/Rendering/MeshUtility.h +++ b/PKRenderer/src/Rendering/MeshUtility.h @@ -5,15 +5,11 @@ namespace PK::Rendering::MeshUtility { - using namespace Utilities; - using namespace PK::Math; - using namespace PK::Rendering::Objects; - - void CalculateNormals(const float3* vertices, const uint* indices, float3* normals, uint vcount, uint icount, float sign = 1.0f); - void CalculateTangents(const float3* vertices, const float3* normals, const float2* texcoords, const uint* indices, float4* tangents, uint vcount, uint icount); - void CalculateTangents(void* vertices, uint stride, uint vertexOffset, uint normalOffset, uint tangentOffset, uint texcoordOffset, const uint* indices, uint vcount, uint icount); - Ref GetBox(const float3& offset, const float3& extents); - Ref GetQuad(const float2& min, const float2& max); - Ref GetPlane(Ref baseMesh, const float2& center, const float2& extents, uint2 resolution); - Ref GetSphere(Ref baseMesh, const float3& offset, const float radius); + void CalculateNormals(const Math::float3* vertices, const uint32_t* indices, Math::float3* normals, uint32_t vcount, uint32_t icount, float sign = 1.0f); + void CalculateTangents(const Math::float3* vertices, const Math::float3* normals, const Math::float2* texcoords, const uint32_t indices, Math::float4* tangents, uint32_t vcount, uint32_t icount); + void CalculateTangents(void* vertices, uint32_t stride, uint32_t vertexOffset, uint32_t normalOffset, uint32_t tangentOffset, uint32_t texcoordOffset, const uint32_t* indices, uint32_t vcount, uint32_t icount); + Utilities::Ref GetBox(const Math::float3& offset, const Math::float3& extents); + Utilities::Ref GetQuad(const Math::float2& min, const Math::float2& max); + Utilities::Ref GetPlane(Utilities::Ref baseMesh, const Math::float2& center, const Math::float2& extents, Math::uint2 resolution); + Utilities::Ref GetSphere(Utilities::Ref baseMesh, const Math::float3& offset, const float radius); } diff --git a/PKRenderer/src/Rendering/Objects/BindArray.h b/PKRenderer/src/Rendering/Objects/BindArray.h index a79a2363..f975daa1 100644 --- a/PKRenderer/src/Rendering/Objects/BindArray.h +++ b/PKRenderer/src/Rendering/Objects/BindArray.h @@ -5,13 +5,11 @@ namespace PK::Rendering::Objects { - using namespace PK::Utilities; - template - class BindArray : public NoCopy, public NativeInterface> + class BindArray : public Utilities::NoCopy, public Utilities::NativeInterface> { public: - static Ref> Create(size_t capacity); + static Utilities::Ref> Create(size_t capacity); virtual int32_t Add(T* value, void* bindInfo) = 0; virtual int32_t Add(T* value) = 0; virtual int32_t Add(const T* value) = 0; diff --git a/PKRenderer/src/Rendering/Objects/BindSet.h b/PKRenderer/src/Rendering/Objects/BindSet.h index 77461650..175f8bc7 100644 --- a/PKRenderer/src/Rendering/Objects/BindSet.h +++ b/PKRenderer/src/Rendering/Objects/BindSet.h @@ -4,11 +4,8 @@ namespace PK::Rendering::Objects { - using namespace PK::Core; - using namespace PK::Utilities; - template - class BindSet : public NoCopy + class BindSet : public Utilities::NoCopy { public: BindSet(uint32_t capacity) : m_array(BindArray::Create(capacity)), m_indices(capacity) {} @@ -42,7 +39,7 @@ namespace PK::Rendering::Objects operator const BindArray* () { return m_array.get(); } private: - Ref> m_array; - IndexedSet m_indices; + Utilities::Ref> m_array; + Utilities::IndexedSet m_indices; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/Buffer.cpp b/PKRenderer/src/Rendering/Objects/Buffer.cpp index 88882eca..53368b02 100644 --- a/PKRenderer/src/Rendering/Objects/Buffer.cpp +++ b/PKRenderer/src/Rendering/Objects/Buffer.cpp @@ -5,7 +5,8 @@ namespace PK::Rendering::Objects { - using namespace PK::Rendering::VulkanRHI::Objects; + using namespace Utilities; + using namespace VulkanRHI::Objects; Ref Buffer::Create(const BufferLayout& layout, const void* data, size_t count, BufferUsage usage) { diff --git a/PKRenderer/src/Rendering/Objects/Buffer.h b/PKRenderer/src/Rendering/Objects/Buffer.h index 5c462e04..152a1758 100644 --- a/PKRenderer/src/Rendering/Objects/Buffer.h +++ b/PKRenderer/src/Rendering/Objects/Buffer.h @@ -8,39 +8,35 @@ namespace PK::Rendering::Objects { - using namespace PK::Core; - using namespace PK::Utilities; - using namespace PK::Rendering::Structs; - - class Buffer : public NoCopy, public NativeInterface + class Buffer : public Utilities::NoCopy, public Utilities::NativeInterface { public: - static Ref Create(const BufferLayout& layout, const void* data, size_t count, BufferUsage usage); + static Utilities::Ref Create(const Structs::BufferLayout& layout, const void* data, size_t count, Structs::BufferUsage usage); - inline static Ref CreateVertex(const BufferLayout& layout, + inline static Utilities::Ref CreateVertex(const Structs::BufferLayout& layout, const void* data, size_t count, - BufferUsage extraFlags = BufferUsage::None) + Structs::BufferUsage extraFlags = Structs::BufferUsage::None) { - return Create(layout, data, count, BufferUsage::DefaultVertex | extraFlags); + return Create(layout, data, count, Structs::BufferUsage::DefaultVertex | extraFlags); } - inline static Ref CreateIndex(ElementType type, + inline static Utilities::Ref CreateIndex(Structs::ElementType type, const void* data, size_t count, - BufferUsage extraFlags = BufferUsage::None) + Structs::BufferUsage extraFlags = Structs::BufferUsage::None) { - return Create(BufferLayout({{ type, "INDEX" }}), data, count, BufferUsage::DefaultIndex | extraFlags); + return Create(Structs::BufferLayout({{ type, "INDEX" }}), data, count, Structs::BufferUsage::DefaultIndex | extraFlags); } - inline static Ref CreateConstant(const BufferLayout& layout, BufferUsage extraFlags = BufferUsage::None) + inline static Utilities::Ref CreateConstant(const Structs::BufferLayout& layout, Structs::BufferUsage extraFlags = Structs::BufferUsage::None) { - return Create(layout, nullptr, 1, BufferUsage::DefaultConstant | extraFlags); + return Create(layout, nullptr, 1, Structs::BufferUsage::DefaultConstant | extraFlags); } - inline static Ref CreateStorage(const BufferLayout& layout, size_t count, BufferUsage extraFlags = BufferUsage::None) + inline static Utilities::Ref CreateStorage(const Structs::BufferLayout& layout, size_t count, Structs::BufferUsage extraFlags = Structs::BufferUsage::None) { - return Create(layout, nullptr, count, BufferUsage::DefaultStorage | extraFlags); + return Create(layout, nullptr, count, Structs::BufferUsage::DefaultStorage | extraFlags); } virtual ~Buffer() = default; @@ -54,13 +50,13 @@ namespace PK::Rendering::Objects virtual void EndRead() = 0; template - BufferView BeginWrite() + Utilities::BufferView BeginWrite() { return { reinterpret_cast(BeginWrite(0, GetCapacity())), GetCapacity() / sizeof(T) }; } template - BufferView BeginWrite(size_t offset, size_t count) + Utilities::BufferView BeginWrite(size_t offset, size_t count) { auto tsize = sizeof(T); auto mapSize = tsize * count + tsize * offset; @@ -72,13 +68,13 @@ namespace PK::Rendering::Objects } template - ConstBufferView BeginRead() + Utilities::ConstBufferView BeginRead() { return { reinterpret_cast(BeginRead(0, GetCapacity())), GetCapacity() / sizeof(T) }; } template - ConstBufferView BeginRead(size_t offset, size_t count) + Utilities::ConstBufferView BeginRead(size_t offset, size_t count) { auto tsize = sizeof(T); auto mapSize = tsize * count + tsize * offset; @@ -89,24 +85,24 @@ namespace PK::Rendering::Objects return { reinterpret_cast(BeginRead(offset * tsize, count * tsize)), count }; } - virtual void MakeRangeResident(const IndexRange& range) = 0; - virtual void MakeRangeNonResident(const IndexRange& range) = 0; + virtual void MakeRangeResident(const Structs::IndexRange& range) = 0; + virtual void MakeRangeNonResident(const Structs::IndexRange& range) = 0; virtual bool Validate(size_t count) = 0; virtual size_t GetCapacity() const = 0; constexpr size_t GetCount() const { return m_count; } - constexpr bool IsSparse() const { return (m_usage & BufferUsage::Sparse) != 0; } - constexpr const BufferUsage GetUsage() const { return m_usage; } - constexpr const BufferLayout& GetLayout() const { return m_layout; } - constexpr IndexRange GetFullRange() const { return { 0ull, m_count }; } + constexpr bool IsSparse() const { return (m_usage & Structs::BufferUsage::Sparse) != 0; } + constexpr const Structs::BufferUsage GetUsage() const { return m_usage; } + constexpr const Structs::BufferLayout& GetLayout() const { return m_layout; } + constexpr Structs::IndexRange GetFullRange() const { return { 0ull, m_count }; } protected: - Buffer(const BufferLayout& layout, size_t count, BufferUsage usage) : m_usage(usage), m_layout(layout), m_count(count) {} + Buffer(const Structs::BufferLayout& layout, size_t count, Structs::BufferUsage usage) : m_usage(usage), m_layout(layout), m_count(count) {} - BufferLayout m_layout{}; - BufferUsage m_usage = BufferUsage::None; - InputRate m_inputRate = InputRate::PerVertex; + Structs::BufferLayout m_layout{}; + Structs::BufferUsage m_usage = Structs::BufferUsage::None; + Structs::InputRate m_inputRate = Structs::InputRate::PerVertex; size_t m_count = 0; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/CommandBuffer.cpp b/PKRenderer/src/Rendering/Objects/CommandBuffer.cpp index 2fe65c31..b1509e3c 100644 --- a/PKRenderer/src/Rendering/Objects/CommandBuffer.cpp +++ b/PKRenderer/src/Rendering/Objects/CommandBuffer.cpp @@ -3,6 +3,11 @@ namespace PK::Rendering::Objects { + using namespace PK::Math; + using namespace PK::Core::Services; + using namespace PK::Rendering::Objects; + using namespace PK::Rendering::Structs; + void CommandBuffer::SetViewPort(const uint4& rect) { SetViewPorts(&rect, 1); @@ -134,12 +139,12 @@ namespace PK::Rendering::Objects pVBuffers[i] = vbuffers[i].get(); } - SetVertexBuffers(pVBuffers, (uint)vbuffers.size()); + SetVertexBuffers(pVBuffers, (uint32_t)vbuffers.size()); SetIndexBuffer(mesh->GetIndexBuffer(), 0); } - void CommandBuffer::DrawMesh(const Mesh* mesh, int submesh, uint32_t instanceCount, uint32_t firstInstance) + void CommandBuffer::DrawMesh(const Mesh* mesh, int32_t submesh, uint32_t instanceCount, uint32_t firstInstance) { SetMesh(mesh); @@ -165,17 +170,17 @@ namespace PK::Rendering::Objects DrawIndexed(sm.indexCount, instanceCount, sm.firstIndex, sm.firstVertex, firstInstance); } - void CommandBuffer::DrawMesh(const Mesh* mesh, int submesh) + void CommandBuffer::DrawMesh(const Mesh* mesh, int32_t submesh) { DrawMesh(mesh, submesh, 1u, 0u); } - void CommandBuffer::DrawMesh(const Mesh* mesh, int submesh, const Shader* shader, int variantIndex) + void CommandBuffer::DrawMesh(const Mesh* mesh, int32_t submesh, const Shader* shader, int32_t variantIndex) { DrawMesh(mesh, submesh, shader, 1u, 0u, variantIndex); } - void CommandBuffer::DrawMesh(const Mesh* mesh, int submesh, const Shader* shader, uint32_t instanceCount, uint32_t firstInstance, int variantIndex) + void CommandBuffer::DrawMesh(const Mesh* mesh, int32_t submesh, const Shader* shader, uint32_t instanceCount, uint32_t firstInstance, int32_t variantIndex) { SetShader(shader, variantIndex); DrawMesh(mesh, submesh, instanceCount, firstInstance); @@ -187,13 +192,13 @@ namespace PK::Rendering::Objects DrawIndexedIndirect(indirectArguments, offset, drawCount, stride); } - void CommandBuffer::Blit(const Shader* shader, int variantIndex) + void CommandBuffer::Blit(const Shader* shader, int32_t variantIndex) { SetShader(shader, variantIndex); Draw(3,1,0,0); } - void CommandBuffer::Blit(const Shader* shader, uint32_t instanceCount, uint32_t firstInstance, int variantIndex) + void CommandBuffer::Blit(const Shader* shader, uint32_t instanceCount, uint32_t firstInstance, int32_t variantIndex) { SetShader(shader, variantIndex); Draw(3, instanceCount, 0u, firstInstance); @@ -205,7 +210,7 @@ namespace PK::Rendering::Objects Dispatch(groupCount); } - void CommandBuffer::Dispatch(const Shader* shader, uint variantIndex, uint3 groupCount) + void CommandBuffer::Dispatch(const Shader* shader, uint32_t variantIndex, uint3 groupCount) { SetShader(shader, variantIndex); Dispatch(groupCount); diff --git a/PKRenderer/src/Rendering/Objects/CommandBuffer.h b/PKRenderer/src/Rendering/Objects/CommandBuffer.h index b8ce7591..02dd4f0d 100644 --- a/PKRenderer/src/Rendering/Objects/CommandBuffer.h +++ b/PKRenderer/src/Rendering/Objects/CommandBuffer.h @@ -10,80 +10,80 @@ namespace PK::Rendering::Objects { - typedef std::initializer_list RenderTargetRanges; + typedef std::initializer_list RenderTargetRanges; struct CommandBuffer : public PK::Utilities::NoCopy { - virtual ExecutionGate GetOnCompleteGate() const = 0; - virtual void SetRenderTarget(const uint3& resolution) = 0; - virtual void SetRenderTarget(Texture** renderTarget, Texture** resolveTargets, const TextureViewRange* ranges, uint32_t count) = 0; - virtual void ClearColor(const color& color, uint32_t index) = 0; + virtual Structs::ExecutionGate GetOnCompleteGate() const = 0; + virtual void SetRenderTarget(const Math::uint3& resolution) = 0; + virtual void SetRenderTarget(Texture** renderTarget, Texture** resolveTargets, const Structs::TextureViewRange* ranges, uint32_t count) = 0; + virtual void ClearColor(const Math::color& color, uint32_t index) = 0; virtual void ClearDepth(float depth, uint32_t stencil) = 0; virtual void DiscardColor(uint32_t index) = 0; virtual void DiscardDepth() = 0; - virtual void SetViewPorts(const uint4* rects, uint32_t count) = 0; - virtual void SetScissors(const uint4* rects, uint32_t count) = 0; + virtual void SetViewPorts(const Math::uint4* rects, uint32_t count) = 0; + virtual void SetScissors(const Math::uint4* rects, uint32_t count) = 0; - virtual void SetBlending(const BlendParameters& blend) = 0; - virtual void SetRasterization(const RasterizationParameters& rasterization) = 0; - virtual void SetDepthStencil(const DepthStencilParameters& depthStencil) = 0; - virtual void SetMultisampling(const MultisamplingParameters& multisampling) = 0; + virtual void SetBlending(const Structs::BlendParameters& blend) = 0; + virtual void SetRasterization(const Structs::RasterizationParameters& rasterization) = 0; + virtual void SetDepthStencil(const Structs::DepthStencilParameters& depthStencil) = 0; + virtual void SetMultisampling(const Structs::MultisamplingParameters& multisampling) = 0; - virtual void SetShader(const Shader* shader, int variantIndex = -1) = 0; - virtual void SetVertexBuffers(const Buffer** buffers, uint count) = 0; + virtual void SetShader(const Shader* shader, int32_t variantIndex = -1) = 0; + virtual void SetVertexBuffers(const Buffer** buffers, uint32_t count) = 0; virtual void SetIndexBuffer(const Buffer* buffer, size_t offset) = 0; - virtual void SetBuffer(uint32_t nameHashId, Buffer* buffer, const IndexRange& range) = 0; - virtual void SetTexture(uint32_t nameHashId, Texture* texture, const TextureViewRange& range) = 0; + virtual void SetBuffer(uint32_t nameHashId, Buffer* buffer, const Structs::IndexRange& range) = 0; + virtual void SetTexture(uint32_t nameHashId, Texture* texture, const Structs::TextureViewRange& range) = 0; virtual void SetBufferArray(uint32_t nameHashId, BindArray* bufferArray) = 0; virtual void SetTextureArray(uint32_t nameHashId, BindArray* textureArray) = 0; - virtual void SetImage(uint32_t nameHashId, Texture* texture, const TextureViewRange& range) = 0; + virtual void SetImage(uint32_t nameHashId, Texture* texture, const Structs::TextureViewRange& range) = 0; virtual void SetConstant(uint32_t nameHashId, const void* data, uint32_t size) = 0; virtual void SetKeyword(uint32_t nameHashId, bool value) = 0; virtual void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) = 0; virtual void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) = 0; virtual void DrawIndexedIndirect(const Buffer* indirectArguments, size_t offset, uint32_t drawCount, uint32_t stride) = 0; - virtual void Dispatch(uint3 groupCount) = 0; + virtual void Dispatch(Math::uint3 groupCount) = 0; // @TODO Nasty dependency. Rethink this one! - virtual void Blit(Texture* src, Window* dst, FilterMode filter) = 0; - virtual void Blit(Window* src, Buffer* dst) = 0; - virtual void Blit(Texture* src, Texture* dst, uint32_t srcLevel, uint32_t dstLevel, uint32_t srcLayer, uint32_t dstLayer, FilterMode filter) = 0; + virtual void Blit(Texture* src, Core::Window* dst, Structs::FilterMode filter) = 0; + virtual void Blit(Core::Window* src, Buffer* dst) = 0; + virtual void Blit(Texture* src, Texture* dst, uint32_t srcLevel, uint32_t dstLevel, uint32_t srcLayer, uint32_t dstLayer, Structs::FilterMode filter) = 0; virtual void Clear(Buffer* dst, size_t offset, size_t size, uint32_t value) = 0; - virtual void Clear(Texture* dst, const TextureViewRange& range, const uint4& value) = 0; + virtual void Clear(Texture* dst, const Structs::TextureViewRange& range, const Math::uint4& value) = 0; - virtual void Barrier(const Texture* texture, const TextureViewRange& range, const Buffer* buffer, MemoryAccessFlags srcFlags, MemoryAccessFlags dstFlags) = 0; + virtual void Barrier(const Texture* texture, const Structs::TextureViewRange& range, const Buffer* buffer, Structs::MemoryAccessFlags srcFlags, Structs::MemoryAccessFlags dstFlags) = 0; - void SetViewPort(const uint4& rect); - void SetScissor(const uint4& rect); + void SetViewPort(const Math::uint4& rect); + void SetScissor(const Math::uint4& rect); - void SetFixedStateAttributes(FixedFunctionShaderAttributes* attribs); + void SetFixedStateAttributes(Structs::FixedFunctionShaderAttributes* attribs); void SetRenderTarget(RenderTexture* renderTarget, const uint32_t* targets, uint32_t targetCount, bool bindDepth, bool updateViewPort); void SetRenderTarget(RenderTexture* renderTarget, std::initializer_list targets, bool bindDepth, bool updateViewPort); void SetRenderTarget(RenderTexture* renderTarget, bool updateViewPort); void SetRenderTarget(Texture* renderTarget); - void SetRenderTarget(Texture* renderTarget, const TextureViewRange& range); - void SetRenderTarget(Texture* renderTarget, ushort level, ushort layer); + void SetRenderTarget(Texture* renderTarget, const Structs::TextureViewRange& range); + void SetRenderTarget(Texture* renderTarget, Math::ushort level, Math::ushort layer); void SetRenderTarget(Texture* renderTarget, const RenderTargetRanges& ranges); void SetMesh(const Mesh* mesh); void SetBuffer(uint32_t nameHashId, Buffer* buffer); void SetBuffer(const char* name, Buffer* buffer); - void SetBuffer(const char* name, Buffer* buffer, const IndexRange& range); + void SetBuffer(const char* name, Buffer* buffer, const Structs::IndexRange& range); void SetTexture(uint32_t nameHashId, Texture* texture); - void SetTexture(uint32_t nameHashId, Texture* texture, ushort level, ushort layer); + void SetTexture(uint32_t nameHashId, Texture* texture, Math::ushort level, Math::ushort layer); void SetTexture(const char* name, Texture* texture); - void SetTexture(const char* name, Texture* texture, ushort level, ushort layer); - void SetTexture(const char* name, Texture* texture, const TextureViewRange& range); + void SetTexture(const char* name, Texture* texture, Math::ushort level, Math::ushort layer); + void SetTexture(const char* name, Texture* texture, const Structs::TextureViewRange& range); void SetImage(uint32_t nameHashId, Texture* texture); - void SetImage(uint32_t nameHashId, Texture* texture, ushort level, ushort layer); + void SetImage(uint32_t nameHashId, Texture* texture, Math::ushort level, Math::ushort layer); void SetImage(const char* name, Texture* texture); - void SetImage(const char* name, Texture* texture, ushort level, ushort layer); - void SetImage(const char* name, Texture* texture, const TextureViewRange& range); + void SetImage(const char* name, Texture* texture, Math::ushort level, Math::ushort layer); + void SetImage(const char* name, Texture* texture, const Structs::TextureViewRange& range); void SetBufferArray(const char* name, BindArray* bufferArray); void SetTextureArray(const char* name, BindArray* textureArray); @@ -97,20 +97,20 @@ namespace PK::Rendering::Objects template void SetConstant(const char* name, const T& value) { SetConstant(name, &value, (uint32_t)sizeof(T)); } - void DrawMesh(const Mesh* mesh, int submesh); - void DrawMesh(const Mesh* mesh, int submesh, uint32_t instanceCount, uint32_t firstInstance); - void DrawMesh(const Mesh* mesh, int submesh, const Shader* shader, int variantIndex = -1); - void DrawMesh(const Mesh* mesh, int submesh, const Shader* shader, uint32_t instanceCount, uint32_t firstInstance, int variantIndex = -1); + void DrawMesh(const Mesh* mesh, int32_t submesh); + void DrawMesh(const Mesh* mesh, int32_t submesh, uint32_t instanceCount, uint32_t firstInstance); + void DrawMesh(const Mesh* mesh, int32_t submesh, const Shader* shader, int32_t variantIndex = -1); + void DrawMesh(const Mesh* mesh, int32_t submesh, const Shader* shader, uint32_t instanceCount, uint32_t firstInstance, int32_t variantIndex = -1); void DrawMeshIndirect(const Mesh* mesh, const Buffer* indirectArguments, size_t offset, uint32_t drawCount, uint32_t stride); - void Blit(const Shader* shader, int variantIndex = -1); - void Blit(const Shader* shader, uint32_t instanceCount, uint32_t firstInstance, int variantIndex = -1); - void Dispatch(const Shader* shader, uint3 groupCount); - void Dispatch(const Shader* shader, uint variantIndex, uint3 groupCount); + void Blit(const Shader* shader, int32_t variantIndex = -1); + void Blit(const Shader* shader, uint32_t instanceCount, uint32_t firstInstance, int32_t variantIndex = -1); + void Dispatch(const Shader* shader, Math::uint3 groupCount); + void Dispatch(const Shader* shader, uint32_t variantIndex, Math::uint3 groupCount); - void Barrier(const Texture* texture, MemoryAccessFlags srcFlags, MemoryAccessFlags dstFlags); - void Barrier(const Texture* texture, const TextureViewRange& range, MemoryAccessFlags srcFlags, MemoryAccessFlags dstFlags); - void Barrier(const Texture* texture, ushort level, ushort layer, MemoryAccessFlags srcFlags, MemoryAccessFlags dstFlags); - void Barrier(const Buffer* buffer, MemoryAccessFlags srcFlags, MemoryAccessFlags dstFlags); - void Barrier(MemoryAccessFlags srcFlags, MemoryAccessFlags dstFlags); + void Barrier(const Texture* texture, Structs::MemoryAccessFlags srcFlags, Structs::MemoryAccessFlags dstFlags); + void Barrier(const Texture* texture, const Structs::TextureViewRange& range, Structs::MemoryAccessFlags srcFlags, Structs::MemoryAccessFlags dstFlags); + void Barrier(const Texture* texture, Math::ushort level, Math::ushort layer, Structs::MemoryAccessFlags srcFlags, Structs::MemoryAccessFlags dstFlags); + void Barrier(const Buffer* buffer, Structs::MemoryAccessFlags srcFlags, Structs::MemoryAccessFlags dstFlags); + void Barrier(Structs::MemoryAccessFlags srcFlags, Structs::MemoryAccessFlags dstFlags); }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/ConstantBuffer.cpp b/PKRenderer/src/Rendering/Objects/ConstantBuffer.cpp index 09f12fa9..585d2aaf 100644 --- a/PKRenderer/src/Rendering/Objects/ConstantBuffer.cpp +++ b/PKRenderer/src/Rendering/Objects/ConstantBuffer.cpp @@ -3,6 +3,8 @@ namespace PK::Rendering::Objects { + using namespace Structs; + ConstantBuffer::ConstantBuffer(const BufferLayout& layout) : ShaderPropertyBlock(nullptr, 0ull), m_graphicsBuffer(Buffer::CreateConstant(layout, BufferUsage::PersistentStage)) diff --git a/PKRenderer/src/Rendering/Objects/ConstantBuffer.h b/PKRenderer/src/Rendering/Objects/ConstantBuffer.h index f1dea16a..7c4d7d34 100644 --- a/PKRenderer/src/Rendering/Objects/ConstantBuffer.h +++ b/PKRenderer/src/Rendering/Objects/ConstantBuffer.h @@ -4,12 +4,10 @@ namespace PK::Rendering::Objects { - using namespace PK::Utilities; - class ConstantBuffer : public ShaderPropertyBlock { public: - ConstantBuffer(const BufferLayout& layout); + ConstantBuffer(const Structs::BufferLayout& layout); inline void FlushBuffer() { m_graphicsBuffer->EndWrite(); } const Buffer* GetBuffer() const { return m_graphicsBuffer.get(); } @@ -19,6 +17,6 @@ namespace PK::Rendering::Objects operator const Buffer* () { return m_graphicsBuffer.get(); } private: - Ref m_graphicsBuffer; + Utilities::Ref m_graphicsBuffer; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/Material.cpp b/PKRenderer/src/Rendering/Objects/Material.cpp index 3abc0743..0317480d 100644 --- a/PKRenderer/src/Rendering/Objects/Material.cpp +++ b/PKRenderer/src/Rendering/Objects/Material.cpp @@ -4,8 +4,12 @@ #include using namespace PK::Core; +using namespace PK::Core::Services; +using namespace PK::Math; using namespace PK::Utilities; using namespace PK::Rendering::Objects; +using namespace PK::Rendering::Structs; +using namespace PK::Rendering::Structs; namespace YAML { diff --git a/PKRenderer/src/Rendering/Objects/Material.h b/PKRenderer/src/Rendering/Objects/Material.h index bb031d91..6547271b 100644 --- a/PKRenderer/src/Rendering/Objects/Material.h +++ b/PKRenderer/src/Rendering/Objects/Material.h @@ -7,16 +7,13 @@ namespace PK::Rendering::Objects { - using namespace PK::Utilities; - using namespace PK::Rendering::Structs; - - class Material : public Asset, public IAssetImportSimple, public ShaderPropertyBlock + class Material : public Core::Services::Asset, public Core::Services::IAssetImportSimple, public ShaderPropertyBlock { // @TODO refactor this to be derived from a config or generate at runtime?. constexpr static const char* DEFAULT_PATH_TEXTURE_BLACK = "res/textures/default/T_Black.ktx2"; constexpr static const char* DEFAULT_PATH_TEXTURE_WHITE = "res/textures/default/T_White.ktx2"; - friend Ref AssetImporters::Create(); + friend Utilities::Ref Core::Services::AssetImporters::Create(); public: Material() : ShaderPropertyBlock(1024) {} diff --git a/PKRenderer/src/Rendering/Objects/Mesh.cpp b/PKRenderer/src/Rendering/Objects/Mesh.cpp index 5f114c04..5400f9aa 100644 --- a/PKRenderer/src/Rendering/Objects/Mesh.cpp +++ b/PKRenderer/src/Rendering/Objects/Mesh.cpp @@ -4,10 +4,12 @@ #include "Math/FunctionsMisc.h" #include +using namespace PK::Math; using namespace PK::Core; using namespace PK::Utilities; using namespace PK::Rendering; using namespace PK::Rendering::Objects; +using namespace PK::Rendering::Structs; namespace PK::Rendering::Objects { @@ -226,10 +228,10 @@ namespace PK::Rendering::Objects } template<> -bool AssetImporters::IsValidExtension(const std::filesystem::path& extension) { return extension.compare(".ktx2") == 0; } +bool PK::Core::Services::AssetImporters::IsValidExtension(const std::filesystem::path& extension) { return extension.compare(".ktx2") == 0; } template<> -Ref AssetImporters::Create() +Ref PK::Core::Services::AssetImporters::Create() { return CreateRef(); } diff --git a/PKRenderer/src/Rendering/Objects/Mesh.h b/PKRenderer/src/Rendering/Objects/Mesh.h index 2eaf7478..01781727 100644 --- a/PKRenderer/src/Rendering/Objects/Mesh.h +++ b/PKRenderer/src/Rendering/Objects/Mesh.h @@ -5,15 +5,13 @@ namespace PK::Rendering::Objects { - using namespace PK::Core::Services; - struct SubMesh { uint32_t firstVertex = 0u; uint32_t vertexCount = 0u; uint32_t firstIndex = 0u; uint32_t indexCount = 0u; - BoundingBox bounds = BoundingBox::GetMinBounds(); + Math::BoundingBox bounds = Math::BoundingBox::GetMinBounds(); constexpr bool operator < (const SubMesh& other) { @@ -29,22 +27,22 @@ namespace PK::Rendering::Objects { void* pVertices; void* pIndices; - BufferLayout vertexLayout; + Structs::BufferLayout vertexLayout; SubMesh* pSubmeshes; - ElementType indexType; + Structs::ElementType indexType; uint32_t vertexCount; uint32_t indexCount; uint32_t submeshCount; }; - class Mesh : public Asset, public IAssetImportSimple + class Mesh : public Core::Services::Asset, public Core::Services::IAssetImportSimple { - friend Ref AssetImporters::Create(); + friend Utilities::Ref Core::Services::AssetImporters::Create(); public: Mesh(); - Mesh(const Ref& vertexBuffer, const Ref& indexBuffer); - Mesh(const Ref& vertexBuffer, const Ref& indexBuffer, const BoundingBox& bounds); + Mesh(const Utilities::Ref& vertexBuffer, const Utilities::Ref& indexBuffer); + Mesh(const Utilities::Ref& vertexBuffer, const Utilities::Ref& indexBuffer, const Math::BoundingBox& bounds); void Import(const char* filepath, void* pParams) override final; @@ -57,24 +55,24 @@ namespace PK::Rendering::Objects void DeallocateSubmeshRange(const SubMesh& allocationRange, uint32_t* submeshIndices, uint32_t submeshCount); - void AddVertexBuffer(const Ref& vertexBuffer); - void SetIndexBuffer(const Ref& indexBuffer) { m_indexBuffer = indexBuffer; } + void AddVertexBuffer(const Utilities::Ref& vertexBuffer); + void SetIndexBuffer(const Utilities::Ref& indexBuffer) { m_indexBuffer = indexBuffer; } void SetSubMeshes(const SubMesh* submeshes, size_t submeshCount); inline void SetSubMeshes(const std::initializer_list& submeshes) { SetSubMeshes(submeshes.begin(), submeshes.end() - submeshes.begin()); } inline void SetSubMeshes(const std::vector& submeshes) { SetSubMeshes(submeshes.data(), submeshes.size()); } - constexpr const std::vector>& GetVertexBuffers() const { return m_vertexBuffers; } - const BufferLayout& GetDefaultLayout() const { return m_vertexBuffers.at(0)->GetLayout(); } + constexpr const std::vector>& GetVertexBuffers() const { return m_vertexBuffers; } + const Structs::BufferLayout& GetDefaultLayout() const { return m_vertexBuffers.at(0)->GetLayout(); } const Buffer* GetVertexBuffer() const { return m_vertexBuffers.at(0).get(); } - const Buffer* GetVertexBuffer(uint index) const { return m_vertexBuffers.at(index).get(); } + const Buffer* GetVertexBuffer(uint32_t index) const { return m_vertexBuffers.at(index).get(); } const Buffer* GetIndexBuffer() const { return m_indexBuffer.get(); } const SubMesh& GetSubmesh(int submesh) const; - inline const uint GetSubmeshCount() const { return glm::max(1u, (uint32_t)m_submeshes.size() - (uint32_t)m_freeSubmeshIndices.size()); } + inline const uint32_t GetSubmeshCount() const { return glm::max(1u, (uint32_t)m_submeshes.size() - (uint32_t)m_freeSubmeshIndices.size()); } constexpr const SubMesh& GetFullRange() const { return m_fullRange; } private: - std::vector> m_vertexBuffers; - Ref m_indexBuffer; + std::vector> m_vertexBuffers; + Utilities::Ref m_indexBuffer; SubMesh m_fullRange{}; std::vector m_submeshes; diff --git a/PKRenderer/src/Rendering/Objects/RenderTexture.cpp b/PKRenderer/src/Rendering/Objects/RenderTexture.cpp index 6442747a..9cb2e654 100644 --- a/PKRenderer/src/Rendering/Objects/RenderTexture.cpp +++ b/PKRenderer/src/Rendering/Objects/RenderTexture.cpp @@ -3,6 +3,9 @@ namespace PK::Rendering::Objects { + using namespace Structs; + using namespace Math; + RenderTexture::RenderTexture(const RenderTextureDescriptor& descriptor) : m_descriptor(descriptor) { m_colorAttachmentCount = 0u; diff --git a/PKRenderer/src/Rendering/Objects/RenderTexture.h b/PKRenderer/src/Rendering/Objects/RenderTexture.h index dbf58140..8b37e0a2 100644 --- a/PKRenderer/src/Rendering/Objects/RenderTexture.h +++ b/PKRenderer/src/Rendering/Objects/RenderTexture.h @@ -4,26 +4,23 @@ namespace PK::Rendering::Objects { - using namespace PK::Core; - using namespace Structs; - - class RenderTexture : public NoCopy + class RenderTexture : public Utilities::NoCopy { public: - RenderTexture(const RenderTextureDescriptor& descriptor); + RenderTexture(const Structs::RenderTextureDescriptor& descriptor); - void Validate(uint3 resolution); + void Validate(Math::uint3 resolution); - constexpr uint GetColorCount() const { return m_colorAttachmentCount; } - inline Texture* GetColor(uint index) const { return index >= m_colorAttachmentCount ? nullptr : m_colorAttachments[index].get(); } + constexpr uint32_t GetColorCount() const { return m_colorAttachmentCount; } + inline Texture* GetColor(uint32_t index) const { return index >= m_colorAttachmentCount ? nullptr : m_colorAttachments[index].get(); } inline Texture* GetDepth() const { return m_depthAttachment == nullptr ? nullptr : m_depthAttachment.get(); } - constexpr const uint4 GetRect() const { return { 0, 0, m_descriptor.resolution.x, m_descriptor.resolution.y }; } - constexpr const uint3 GetResolution() const { return m_descriptor.resolution; } + constexpr const Math::uint4 GetRect() const { return { 0, 0, m_descriptor.resolution.x, m_descriptor.resolution.y }; } + constexpr const Math::uint3 GetResolution() const { return m_descriptor.resolution; } private: - RenderTextureDescriptor m_descriptor; - Ref m_colorAttachments[PK_MAX_RENDER_TARGETS]{}; - Ref m_depthAttachment = nullptr; - uint m_colorAttachmentCount = 0u; + Structs::RenderTextureDescriptor m_descriptor; + Utilities::Ref m_colorAttachments[Structs::PK_MAX_RENDER_TARGETS]{}; + Utilities::Ref m_depthAttachment = nullptr; + uint32_t m_colorAttachmentCount = 0u; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/Shader.cpp b/PKRenderer/src/Rendering/Objects/Shader.cpp index b0f145de..87be9125 100644 --- a/PKRenderer/src/Rendering/Objects/Shader.cpp +++ b/PKRenderer/src/Rendering/Objects/Shader.cpp @@ -6,9 +6,11 @@ #include using namespace PK::Core; +using namespace PK::Core::Services; using namespace PK::Utilities; using namespace PK::Rendering; using namespace PK::Rendering::Objects; +using namespace PK::Rendering::Structs; using namespace PK::Rendering::VulkanRHI::Objects; namespace PK::Rendering::Objects diff --git a/PKRenderer/src/Rendering/Objects/Shader.h b/PKRenderer/src/Rendering/Objects/Shader.h index dee798cf..bf84a7f1 100644 --- a/PKRenderer/src/Rendering/Objects/Shader.h +++ b/PKRenderer/src/Rendering/Objects/Shader.h @@ -7,10 +7,7 @@ namespace PK::Rendering::Objects { - using namespace PK::Core; - using namespace PK::Rendering::Structs; - - class ShaderVariantMap : public NoCopy + class ShaderVariantMap : public Utilities::NoCopy { public: constexpr static const int MAX_DIRECTIVES = 16; @@ -29,12 +26,12 @@ namespace PK::Rendering::Objects { const ShaderVariantMap* map; uint32_t keywords[MAX_DIRECTIVES]{}; - void SetKeywordsFrom(const PropertyBlock& block); + void SetKeywordsFrom(const Utilities::PropertyBlock& block); inline uint32_t GetIndex() const { return map->GetIndex(keywords, map->directivecount); } }; }; - class ShaderVariant : public NoCopy, public NativeInterface + class ShaderVariant : public Utilities::NoCopy, public Utilities::NativeInterface { friend class Shader; @@ -42,29 +39,29 @@ namespace PK::Rendering::Objects virtual ~ShaderVariant() = default; virtual void Dispose() = 0; - constexpr const BufferLayout& GetVertexLayout() const { return m_vertexLayout; } - constexpr const ConstantBufferLayout& GetConstantLayout() const { return m_constantLayout; } - constexpr const ResourceLayout& GetResourceLayout(uint32_t set) const { return m_resourceLayouts[set]; } - constexpr const ShaderType GetType() const { return m_type; } + constexpr const Structs::BufferLayout& GetVertexLayout() const { return m_vertexLayout; } + constexpr const Structs::ConstantBufferLayout& GetConstantLayout() const { return m_constantLayout; } + constexpr const Structs::ResourceLayout& GetResourceLayout(uint32_t set) const { return m_resourceLayouts[set]; } + constexpr const Structs::ShaderType GetType() const { return m_type; } constexpr const uint32_t GetStageFlags() const { return m_stageFlags; } void ListProperties(); protected: - BufferLayout m_vertexLayout; - ConstantBufferLayout m_constantLayout; - ResourceLayout m_resourceLayouts[PK_MAX_DESCRIPTOR_SETS]; - ShaderType m_type = ShaderType::Graphics; + Structs::BufferLayout m_vertexLayout; + Structs::ConstantBufferLayout m_constantLayout; + Structs::ResourceLayout m_resourceLayouts[Structs::PK_MAX_DESCRIPTOR_SETS]; + Structs::ShaderType m_type = Structs::ShaderType::Graphics; uint32_t m_stageFlags = 0u; }; - class Shader : public Asset, public IAssetImportSimple + class Shader : public Core::Services::Asset, public Core::Services::IAssetImportSimple { - friend Ref AssetImporters::Create(); + friend Utilities::Ref Core::Services::AssetImporters::Create(); public: - constexpr ShaderType GetType() const { return m_variants.at(0)->GetType(); } - inline const FixedFunctionShaderAttributes& GetFixedFunctionAttributes() const { return m_attributes; } + constexpr Structs::ShaderType GetType() const { return m_variants.at(0)->GetType(); } + inline const Structs::FixedFunctionShaderAttributes& GetFixedFunctionAttributes() const { return m_attributes; } inline uint32_t GetVariantIndex(const uint32_t* keywords, uint32_t count) const { return m_variantMap.GetIndex(keywords, count); } inline uint32_t GetVariantIndex(uint32_t keyword) const { return m_variantMap.GetIndex(&keyword, 1); } inline uint32_t GetVariantIndex(const std::initializer_list& keywords) const { return GetVariantIndex(keywords.begin(), (uint32_t)(keywords.end() - keywords.begin())); } @@ -74,7 +71,7 @@ namespace PK::Rendering::Objects inline bool SupportsKeyword(const uint32_t hashId) const { return m_variantMap.SupportsKeyword(hashId); } inline bool SupportsKeywords(const uint32_t* hashIds, const uint32_t count) const { return m_variantMap.SupportsKeywords(hashIds, count); } inline bool SupportsMaterials() const { return m_materialPropertyLayout.size() > 0; } - inline const BufferLayout& GetMaterialPropertyLayout() const { return m_materialPropertyLayout; } + inline const Structs::BufferLayout& GetMaterialPropertyLayout() const { return m_materialPropertyLayout; } void ListVariants(); void ListProperties(uint32_t variantIndex); @@ -82,9 +79,9 @@ namespace PK::Rendering::Objects void Import(const char* filepath, void* pParams) override final; protected: - std::vector> m_variants; + std::vector> m_variants; ShaderVariantMap m_variantMap; - FixedFunctionShaderAttributes m_attributes; - BufferLayout m_materialPropertyLayout; + Structs::FixedFunctionShaderAttributes m_attributes; + Structs::BufferLayout m_materialPropertyLayout; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/ShaderPropertyBlock.h b/PKRenderer/src/Rendering/Objects/ShaderPropertyBlock.h index 69cb1240..815f6b7a 100644 --- a/PKRenderer/src/Rendering/Objects/ShaderPropertyBlock.h +++ b/PKRenderer/src/Rendering/Objects/ShaderPropertyBlock.h @@ -4,14 +4,11 @@ namespace PK::Rendering::Objects { - using namespace PK::Utilities; - using namespace PK::Rendering::Structs; - - class ShaderPropertyBlock : public PropertyBlock + class ShaderPropertyBlock : public Utilities::PropertyBlock { public: - ShaderPropertyBlock(uint64_t capacity) : PropertyBlock(capacity) {} - ShaderPropertyBlock(void* foreignBuffer, uint64_t capacity) : PropertyBlock(foreignBuffer, capacity) {} - void ReserveLayout(const BufferLayout& layout); + ShaderPropertyBlock(uint64_t capacity) : Utilities::PropertyBlock(capacity) {} + ShaderPropertyBlock(void* foreignBuffer, uint64_t capacity) : Utilities::PropertyBlock(foreignBuffer, capacity) {} + void ReserveLayout(const Structs::BufferLayout& layout); }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/Texture.cpp b/PKRenderer/src/Rendering/Objects/Texture.cpp index cc3effa2..9b820de3 100644 --- a/PKRenderer/src/Rendering/Objects/Texture.cpp +++ b/PKRenderer/src/Rendering/Objects/Texture.cpp @@ -4,6 +4,7 @@ #include "Rendering/GraphicsAPI.h" using namespace PK::Core; +using namespace PK::Core::Services; using namespace PK::Utilities; using namespace PK::Rendering; using namespace PK::Rendering::Objects; diff --git a/PKRenderer/src/Rendering/Objects/Texture.h b/PKRenderer/src/Rendering/Objects/Texture.h index b19b0376..28231b02 100644 --- a/PKRenderer/src/Rendering/Objects/Texture.h +++ b/PKRenderer/src/Rendering/Objects/Texture.h @@ -5,33 +5,28 @@ namespace PK::Rendering::Objects { - using namespace PK::Utilities; - using namespace PK::Core; - using namespace PK::Core::Services; - using namespace PK::Rendering::Structs; - - class Texture : public Asset, public IAssetImportSimple, public NativeInterface + class Texture : public Core::Services::Asset, public Core::Services::IAssetImportSimple, public Utilities::NativeInterface { - friend Ref AssetImporters::Create(); + friend Utilities::Ref Core::Services::AssetImporters::Create(); public: - static Ref Create(const TextureDescriptor& descriptor); + static Utilities::Ref Create(const Structs::TextureDescriptor& descriptor); virtual ~Texture() = default; virtual void SetData(const void* data, size_t size, uint32_t level, uint32_t layer) const = 0; - virtual void SetSampler(const SamplerDescriptor& sampler) = 0; + virtual void SetSampler(const Structs::SamplerDescriptor& sampler) = 0; virtual void Import(const char* filepath, void* pParams) = 0; - virtual bool Validate(const uint3& resolution) = 0; + virtual bool Validate(const Math::uint3& resolution) = 0; virtual bool Validate(const uint32_t levels, const uint32_t layers) = 0; - virtual bool Validate(const TextureDescriptor& descriptor) = 0; + virtual bool Validate(const Structs::TextureDescriptor& descriptor) = 0; - constexpr const SamplerDescriptor& GetSamplerDescriptor() const { return m_descriptor.sampler; } - constexpr const uint4 GetRect() const { return { 0, 0, m_descriptor.resolution.x, m_descriptor.resolution.y }; } - constexpr const uint3 GetResolution() const { return m_descriptor.resolution; } - constexpr const uint GetLevels() const { return m_descriptor.levels; } - constexpr const uint GetLayers() const { return m_descriptor.layers; } + constexpr const Structs::SamplerDescriptor& GetSamplerDescriptor() const { return m_descriptor.sampler; } + constexpr const Math::uint4 GetRect() const { return { 0, 0, m_descriptor.resolution.x, m_descriptor.resolution.y }; } + constexpr const Math::uint3 GetResolution() const { return m_descriptor.resolution; } + constexpr const uint32_t GetLevels() const { return m_descriptor.levels; } + constexpr const uint32_t GetLayers() const { return m_descriptor.layers; } protected: - TextureDescriptor m_descriptor; + Structs::TextureDescriptor m_descriptor; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/VirtualMesh.cpp b/PKRenderer/src/Rendering/Objects/VirtualMesh.cpp index 5bf2a9cd..c1269b87 100644 --- a/PKRenderer/src/Rendering/Objects/VirtualMesh.cpp +++ b/PKRenderer/src/Rendering/Objects/VirtualMesh.cpp @@ -4,14 +4,14 @@ #include "Math/FunctionsMisc.h" #include "Math/FunctionsIntersect.h" -using namespace PK::Core; -using namespace PK::Utilities; -using namespace PK::Rendering; -using namespace PK::Rendering::Objects; - namespace PK::Rendering::Objects { - VirtualMesh::VirtualMesh() + using namespace Core; + using namespace Math; + using namespace Utilities; + using namespace Structs; + + VirtualMesh::VirtualMesh() { } @@ -93,7 +93,7 @@ namespace PK::Rendering::Objects } template<> -Ref AssetImporters::Create() +PK::Utilities::Ref PK::Core::Services::AssetImporters::Create() { - return CreateRef(); + return PK::Utilities::CreateRef(); } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Objects/VirtualMesh.h b/PKRenderer/src/Rendering/Objects/VirtualMesh.h index d3ec435d..2df21c6c 100644 --- a/PKRenderer/src/Rendering/Objects/VirtualMesh.h +++ b/PKRenderer/src/Rendering/Objects/VirtualMesh.h @@ -3,25 +3,23 @@ namespace PK::Rendering::Objects { - using namespace PK::Core::Services; - - class VirtualMesh : public Asset, public IAssetImport> + class VirtualMesh : public Core::Services::Asset, public Core::Services::IAssetImport> { - friend Ref AssetImporters::Create(); + friend Utilities::Ref Core::Services::AssetImporters::Create(); public: VirtualMesh(); - VirtualMesh(const SubmeshRangeAllocationInfo& data, Ref mesh); + VirtualMesh(const SubmeshRangeAllocationInfo& data, Utilities::Ref mesh); ~VirtualMesh(); - void Import(const char* filepath, Ref* pParams) override final; + void Import(const char* filepath, Utilities::Ref* pParams) override final; inline Mesh* GetBaseMesh() const { return m_mesh.get(); } uint32_t GetSubmeshIndex(uint32_t submesh) const; uint32_t GetBaseSubmeshIndex() const { return m_submeshIndices.at(0); } - inline const uint GetSubmeshCount() const { return glm::max(1, (int)m_submeshIndices.size()); } + inline const uint32_t GetSubmeshCount() const { return glm::max(1, (int)m_submeshIndices.size()); } private: - Ref m_mesh = nullptr; + Utilities::Ref m_mesh = nullptr; SubMesh m_fullRange{}; std::vector m_submeshIndices; }; diff --git a/PKRenderer/src/Rendering/Passes/PassBloom.cpp b/PKRenderer/src/Rendering/Passes/PassBloom.cpp index 9efae51b..70343c5e 100644 --- a/PKRenderer/src/Rendering/Passes/PassBloom.cpp +++ b/PKRenderer/src/Rendering/Passes/PassBloom.cpp @@ -5,7 +5,12 @@ namespace PK::Rendering::Passes { - PassBloom::PassBloom(AssetDatabase* assetDatabase, uint initialWidth, uint initialHeight) + using namespace Core::Services; + using namespace Math; + using namespace Objects; + using namespace Structs; + + PassBloom::PassBloom(AssetDatabase* assetDatabase, uint32_t initialWidth, uint32_t initialHeight) { TextureDescriptor descriptor{}; descriptor.samplerType = SamplerType::Sampler2D; diff --git a/PKRenderer/src/Rendering/Passes/PassBloom.h b/PKRenderer/src/Rendering/Passes/PassBloom.h index bcaaf34d..4b503c90 100644 --- a/PKRenderer/src/Rendering/Passes/PassBloom.h +++ b/PKRenderer/src/Rendering/Passes/PassBloom.h @@ -5,22 +5,18 @@ namespace PK::Rendering::Passes { - using namespace PK::Core; - using namespace PK::Utilities; - using namespace PK::Rendering::Objects; - - class PassBloom : public NoCopy + class PassBloom : public Utilities::NoCopy { public: - PassBloom(AssetDatabase* assetDatabase, uint initialWidth, uint initialHeight); - void Execute(RenderTexture* source, MemoryAccessFlags lastAccess); + PassBloom(Core::Services::AssetDatabase* assetDatabase, uint32_t initialWidth, uint32_t initialHeight); + void Execute(Objects::RenderTexture* source, Structs::MemoryAccessFlags lastAccess); - Texture* GetTexture() { return m_bloomTexture.get(); } + Objects::Texture* GetTexture() { return m_bloomTexture.get(); } private: - Shader* m_computeBloom = nullptr; - Ref m_bloomTexture; - uint m_passPrefilter = 0; - uint m_passDiskblur = 0; + Objects::Shader* m_computeBloom = nullptr; + Utilities::Ref m_bloomTexture; + uint32_t m_passPrefilter = 0; + uint32_t m_passDiskblur = 0; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Passes/PassDepthOfField.cpp b/PKRenderer/src/Rendering/Passes/PassDepthOfField.cpp index 7b5b04ae..763f3802 100644 --- a/PKRenderer/src/Rendering/Passes/PassDepthOfField.cpp +++ b/PKRenderer/src/Rendering/Passes/PassDepthOfField.cpp @@ -5,6 +5,11 @@ namespace PK::Rendering::Passes { + using namespace Core; + using namespace Core::Services; + using namespace Rendering::Objects; + using namespace Rendering::Structs; + PassDepthOfField::PassDepthOfField(AssetDatabase* assetDatabase, const ApplicationConfig* config) { m_shaderBlur = assetDatabase->Find("VS_DepthOfFieldBlur"); diff --git a/PKRenderer/src/Rendering/Passes/PassDepthOfField.h b/PKRenderer/src/Rendering/Passes/PassDepthOfField.h index d3076df9..a5033cc3 100644 --- a/PKRenderer/src/Rendering/Passes/PassDepthOfField.h +++ b/PKRenderer/src/Rendering/Passes/PassDepthOfField.h @@ -7,10 +7,7 @@ namespace PK::Rendering::Passes { - using namespace PK::Core; - using namespace PK::Rendering::Objects; - - class PassDepthOfField : public PK::Core::NoCopy + class PassDepthOfField : public PK::Utilities::NoCopy { struct Constants { @@ -22,19 +19,18 @@ namespace PK::Rendering::Passes }; public: - PassDepthOfField(AssetDatabase* assetDatabase, const ApplicationConfig* config); - void Execute(RenderTexture* destination, MemoryAccessFlags lastAccess); - void OnUpdateParameters(const ApplicationConfig* config); + PassDepthOfField(Core::Services::AssetDatabase* assetDatabase, const Core::ApplicationConfig* config); + void Execute(Objects::RenderTexture* destination, Structs::MemoryAccessFlags lastAccess); + void OnUpdateParameters(const Core::ApplicationConfig* config); private: - Shader* m_shaderBlur = nullptr; - Shader* m_shaderComposite = nullptr; - Shader* m_computeAutoFocus = nullptr; - Ref m_renderTarget; - Ref m_autoFocusParams; - uint m_passPrefilter = 0u; - uint m_passDiskblur = 0u; - + Objects::Shader* m_shaderBlur = nullptr; + Objects::Shader* m_shaderComposite = nullptr; + Objects::Shader* m_computeAutoFocus = nullptr; + Utilities::Ref m_renderTarget; + Utilities::Ref m_autoFocusParams; + uint32_t m_passPrefilter = 0u; + uint32_t m_passDiskblur = 0u; Constants m_constants{}; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Passes/PassGeometry.cpp b/PKRenderer/src/Rendering/Passes/PassGeometry.cpp index 1490fb42..4bae44e4 100644 --- a/PKRenderer/src/Rendering/Passes/PassGeometry.cpp +++ b/PKRenderer/src/Rendering/Passes/PassGeometry.cpp @@ -6,8 +6,14 @@ namespace PK::Rendering::Passes { - using namespace PK::ECS::Tokens; - using namespace PK::ECS::EntityViews; + using namespace Core; + using namespace Core::Services; + using namespace Math; + using namespace ECS; + using namespace ECS::Tokens; + using namespace ECS::EntityViews; + using namespace Objects; + using namespace Structs; PassGeometry::PassGeometry(EntityDatabase* entityDb, Sequencer* sequencer, Batcher* batcher) : m_entityDb(entityDb), m_sequencer(sequencer), m_batcher(batcher) { diff --git a/PKRenderer/src/Rendering/Passes/PassGeometry.h b/PKRenderer/src/Rendering/Passes/PassGeometry.h index b0aa6b09..b19d076c 100644 --- a/PKRenderer/src/Rendering/Passes/PassGeometry.h +++ b/PKRenderer/src/Rendering/Passes/PassGeometry.h @@ -9,23 +9,19 @@ namespace PK::Rendering::Passes { - using namespace PK::Core; - using namespace PK::ECS::Tokens; - using namespace PK::Rendering::Objects; - - class PassGeometry : public PK::Core::NoCopy + class PassGeometry : public PK::Utilities::NoCopy { public: - PassGeometry(EntityDatabase* entityDb, Sequencer* sequencer, Batcher* batcher); - void Cull(void* engineRoot, VisibilityList* visibilityList, const float4x4& viewProjection, float depthRange); - void RenderForward(CommandBuffer* cmd); - void RenderGBuffer(CommandBuffer* cmd); + PassGeometry(ECS::EntityDatabase* entityDb, Core::Services::Sequencer* sequencer, Batcher* batcher); + void Cull(void* engineRoot, ECS::Tokens::VisibilityList* visibilityList, const Math::float4x4& viewProjection, float depthRange); + void RenderForward(Objects::CommandBuffer* cmd); + void RenderGBuffer(Objects::CommandBuffer* cmd); constexpr uint32_t GetPassGroup() const { return m_passGroup; } private: - EntityDatabase* m_entityDb = nullptr; - Sequencer* m_sequencer = nullptr; + ECS::EntityDatabase* m_entityDb = nullptr; + Core::Services::Sequencer* m_sequencer = nullptr; Batcher* m_batcher = nullptr; uint32_t m_passGroup = 0u; - FixedFunctionShaderAttributes m_gbufferAttribs{}; + Structs::FixedFunctionShaderAttributes m_gbufferAttribs{}; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Passes/PassHistogram.cpp b/PKRenderer/src/Rendering/Passes/PassHistogram.cpp index ab7c470b..72f8a444 100644 --- a/PKRenderer/src/Rendering/Passes/PassHistogram.cpp +++ b/PKRenderer/src/Rendering/Passes/PassHistogram.cpp @@ -5,8 +5,11 @@ namespace PK::Rendering::Passes { - using namespace PK::Core; - using namespace PK::Rendering::Objects; + using namespace Core; + using namespace Core::Services; + using namespace Math; + using namespace Objects; + using namespace Structs; PassHistogram::PassHistogram(AssetDatabase* assetDatabase) { diff --git a/PKRenderer/src/Rendering/Passes/PassHistogram.h b/PKRenderer/src/Rendering/Passes/PassHistogram.h index 8313e0d7..ba6cba84 100644 --- a/PKRenderer/src/Rendering/Passes/PassHistogram.h +++ b/PKRenderer/src/Rendering/Passes/PassHistogram.h @@ -6,20 +6,16 @@ namespace PK::Rendering::Passes { - using namespace PK::Utilities; - using namespace PK::Rendering::Objects; - - class PassHistogram : public NoCopy + class PassHistogram : public Utilities::NoCopy { public: - PassHistogram(AssetDatabase* assetDatabase); - void Execute(Texture* target, MemoryAccessFlags nextAccess); + PassHistogram(Core::Services::AssetDatabase* assetDatabase); + void Execute(Objects::Texture* target, Structs::MemoryAccessFlags nextAccess); private: - Shader* m_computeHistogram = nullptr; - Ref m_histogram; - - uint m_passHistogramBins = 0u; - uint m_passHistogramAvg = 0u; + Objects::Shader* m_computeHistogram = nullptr; + Utilities::Ref m_histogram; + uint32_t m_passHistogramBins = 0u; + uint32_t m_passHistogramAvg = 0u; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Passes/PassLights.cpp b/PKRenderer/src/Rendering/Passes/PassLights.cpp index 76bdd131..67f0e5fb 100644 --- a/PKRenderer/src/Rendering/Passes/PassLights.cpp +++ b/PKRenderer/src/Rendering/Passes/PassLights.cpp @@ -7,12 +7,17 @@ #include "Rendering/HashCache.h" using namespace PK::Core; +using namespace PK::Core::Services; +using namespace PK::Math; +using namespace PK::Utilities; +using namespace PK::ECS; using namespace PK::ECS::Tokens; using namespace PK::ECS::EntityViews; using namespace PK::Rendering::Objects; +using namespace PK::Rendering::Structs; template<> -struct PK::Utilities::Vector::Comparer +struct Vector::Comparer { int operator()(LightRenderableView*& a, LightRenderableView*& b) { diff --git a/PKRenderer/src/Rendering/Passes/PassLights.h b/PKRenderer/src/Rendering/Passes/PassLights.h index 11fef83e..ce9e526f 100644 --- a/PKRenderer/src/Rendering/Passes/PassLights.h +++ b/PKRenderer/src/Rendering/Passes/PassLights.h @@ -10,63 +10,60 @@ namespace PK::Rendering::Passes { - using namespace PK::Core; - using namespace PK::ECS::Tokens; - using namespace PK::ECS::EntityViews; - using namespace PK::Rendering::Objects; - typedef struct ShadowCascades { float planes[5]; } ShadowCascades; struct ShadowmapLightTypeData { - Ref SceneRenderTarget = nullptr; + Utilities::Ref SceneRenderTarget = nullptr; uint32_t BlurPass0 = 0u; uint32_t BlurPass1 = 0u; uint32_t TileCount = 0u; uint32_t LayerStride = 0u; }; - class PassLights : public PK::Core::NoCopy + class PassLights : public Utilities::NoCopy { public: - const uint MaxLightsPerTile = 64; - const uint GridSizeX = 16; - const uint GridSizeY = 9; - const uint GridSizeZ = 24; - const uint ClusterCount = GridSizeX * GridSizeY * GridSizeZ; + const uint32_t MaxLightsPerTile = 64; + const uint32_t GridSizeX = 16; + const uint32_t GridSizeY = 9; + const uint32_t GridSizeZ = 24; + const uint32_t ClusterCount = GridSizeX * GridSizeY * GridSizeZ; const float DepthGroupSize = 32.0f; - PassLights(AssetDatabase* assetDatabase, EntityDatabase* entityDb, Sequencer* sequencer, Batcher* batcher, const ApplicationConfig* config); - void Cull(void* engineRoot, VisibilityList* visibilityList, const float4x4& viewProjection, float znear, float zfar); - void Render(CommandBuffer* cmd); + PassLights(Core::Services::AssetDatabase* assetDatabase, + ECS::EntityDatabase* entityDb, + Core::Services::Sequencer* sequencer, + Batcher* batcher, + const Core::ApplicationConfig* config); + void Cull(void* engineRoot, ECS::Tokens::VisibilityList* visibilityList, const Math::float4x4& viewProjection, float znear, float zfar); + void Render(Objects::CommandBuffer* cmd); ShadowCascades GetCascadeZSplits(float znear, float zfar) const; private: - void BuildShadowmapBatches(void* engineRoot, CullTokens* tokens, LightRenderableView* view, const float4x4& inverseViewProjection); + void BuildShadowmapBatches(void* engineRoot, ECS::Tokens::CullTokens* tokens, ECS::EntityViews::LightRenderableView* view, const Math::float4x4& inverseViewProjection); - EntityDatabase* m_entityDb = nullptr; - Sequencer* m_sequencer = nullptr; + ECS::EntityDatabase* m_entityDb = nullptr; + Core::Services::Sequencer* m_sequencer = nullptr; Batcher* m_batcher = nullptr; - Shader* m_computeLightAssignment = nullptr; - Shader* m_shadowmapBlur = nullptr; + Objects::Shader* m_computeLightAssignment = nullptr; + Objects::Shader* m_shadowmapBlur = nullptr; float m_cascadeLinearity; - uint m_shadowmapCubeFaceSize; - uint m_shadowmapTileSize; - uint m_shadowmapTileCount; - + uint32_t m_shadowmapCubeFaceSize; + uint32_t m_shadowmapTileSize; + uint32_t m_shadowmapTileCount; uint32_t m_shadowmapCount; uint32_t m_projectionCount; uint32_t m_lightCount; ShadowCascades m_cascadeSplits; - ShadowmapLightTypeData m_shadowmapTypeData[(int)LightType::TypeCount]; - - MemoryBlock m_lights; - Ref m_lightsBuffer; - Ref m_lightMatricesBuffer; - Ref m_lightDirectionsBuffer; - Ref m_globalLightsList; - Ref m_globalLightIndex; - Ref m_lightTiles; - Ref m_shadowmaps; + ShadowmapLightTypeData m_shadowmapTypeData[(int)Structs::LightType::TypeCount]; + Utilities::MemoryBlock m_lights; + Utilities::Ref m_lightsBuffer; + Utilities::Ref m_lightMatricesBuffer; + Utilities::Ref m_lightDirectionsBuffer; + Utilities::Ref m_globalLightsList; + Utilities::Ref m_globalLightIndex; + Utilities::Ref m_lightTiles; + Utilities::Ref m_shadowmaps; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Passes/PassPostEffects.cpp b/PKRenderer/src/Rendering/Passes/PassPostEffects.cpp index 7ff7c241..d4237bd6 100644 --- a/PKRenderer/src/Rendering/Passes/PassPostEffects.cpp +++ b/PKRenderer/src/Rendering/Passes/PassPostEffects.cpp @@ -6,6 +6,13 @@ namespace PK::Rendering::Passes { + using namespace Core; + using namespace Core::Services; + using namespace Math; + using namespace Utilities; + using namespace Structs; + using namespace Objects; + PassPostEffects::PassPostEffects(AssetDatabase* assetDatabase, const ApplicationConfig* config) : m_bloom(assetDatabase, config->InitialWidth, config->InitialHeight), m_histogram(assetDatabase), diff --git a/PKRenderer/src/Rendering/Passes/PassPostEffects.h b/PKRenderer/src/Rendering/Passes/PassPostEffects.h index 8d4195f9..b5233eca 100644 --- a/PKRenderer/src/Rendering/Passes/PassPostEffects.h +++ b/PKRenderer/src/Rendering/Passes/PassPostEffects.h @@ -9,25 +9,22 @@ namespace PK::Rendering::Passes { - using namespace PK::Core; - using namespace PK::Rendering::Objects; - - class PassPostEffects : public PK::Core::NoCopy + class PassPostEffects : public PK::Utilities::NoCopy { public: - PassPostEffects(AssetDatabase* assetDatabase, const ApplicationConfig* config); - void Render(CommandBuffer* cmd, RenderTexture* destination, MemoryAccessFlags lastAccess); - void OnUpdateParameters(const ApplicationConfig* config); + PassPostEffects(Core::Services::AssetDatabase* assetDatabase, const Core::ApplicationConfig* config); + void Render(Objects::CommandBuffer* cmd, Objects::RenderTexture* destination, Structs::MemoryAccessFlags lastAccess); + void OnUpdateParameters(const Core::ApplicationConfig* config); private: PassBloom m_bloom; PassHistogram m_histogram; PassDepthOfField m_depthOfField; - Shader* m_computeComposite = nullptr; - Shader* m_computeFilmGrain = nullptr; - Texture* m_bloomLensDirtTexture; - Ref m_filmGrainTexture; - Ref m_paramatersBuffer; + Objects::Shader* m_computeComposite = nullptr; + Objects::Shader* m_computeFilmGrain = nullptr; + Objects::Texture* m_bloomLensDirtTexture; + Utilities::Ref m_filmGrainTexture; + Utilities::Ref m_paramatersBuffer; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Passes/PassSceneGI.cpp b/PKRenderer/src/Rendering/Passes/PassSceneGI.cpp index d874f77d..0938c852 100644 --- a/PKRenderer/src/Rendering/Passes/PassSceneGI.cpp +++ b/PKRenderer/src/Rendering/Passes/PassSceneGI.cpp @@ -4,6 +4,13 @@ namespace PK::Rendering::Passes { + using namespace Core; + using namespace Core::Services; + using namespace Math; + using namespace Utilities; + using namespace Structs; + using namespace Objects; + PassSceneGI::PassSceneGI(AssetDatabase* assetDatabase, const ApplicationConfig* config) { m_computeFade = assetDatabase->Find("CS_SceneGI_Fade"); diff --git a/PKRenderer/src/Rendering/Passes/PassSceneGI.h b/PKRenderer/src/Rendering/Passes/PassSceneGI.h index f59c0949..9ceb19eb 100644 --- a/PKRenderer/src/Rendering/Passes/PassSceneGI.h +++ b/PKRenderer/src/Rendering/Passes/PassSceneGI.h @@ -8,27 +8,23 @@ namespace PK::Rendering::Passes { - using namespace PK::Core; - using namespace PK::ECS::Tokens; - using namespace PK::Rendering::Objects; - - class PassSceneGI : public PK::Core::NoCopy + class PassSceneGI : public PK::Utilities::NoCopy { public: - PassSceneGI(AssetDatabase* assetDatabase, const ApplicationConfig* config); - void PreRender(CommandBuffer* cmd, const uint3& resolution); - void RenderVoxels(CommandBuffer* cmd, Batcher* batcher, uint32_t batchGroup); - void RenderGI(CommandBuffer* cmd); + PassSceneGI(Core::Services::AssetDatabase* assetDatabase, const Core::ApplicationConfig* config); + void PreRender(Objects::CommandBuffer* cmd, const Math::uint3& resolution); + void RenderVoxels(Objects::CommandBuffer* cmd, Batcher* batcher, uint32_t batchGroup); + void RenderGI(Objects::CommandBuffer* cmd); private: - FixedFunctionShaderAttributes m_voxelizeAttribs{}; - Shader* m_computeFade = nullptr; - Shader* m_computeMipmap = nullptr; - Shader* m_computeBakeGI = nullptr; - Ref m_parameters; - Ref m_voxels; - Ref m_screenSpaceGI; - uint m_checkerboardIndex = 0u; - int m_rasterAxis = 0; + Structs::FixedFunctionShaderAttributes m_voxelizeAttribs{}; + Objects::Shader* m_computeFade = nullptr; + Objects::Shader* m_computeMipmap = nullptr; + Objects::Shader* m_computeBakeGI = nullptr; + Utilities::Ref m_parameters; + Utilities::Ref m_voxels; + Utilities::Ref m_screenSpaceGI; + uint32_t m_checkerboardIndex = 0u; + int32_t m_rasterAxis = 0; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Passes/PassVolumeFog.cpp b/PKRenderer/src/Rendering/Passes/PassVolumeFog.cpp index eac79484..f5abd107 100644 --- a/PKRenderer/src/Rendering/Passes/PassVolumeFog.cpp +++ b/PKRenderer/src/Rendering/Passes/PassVolumeFog.cpp @@ -4,6 +4,13 @@ namespace PK::Rendering::Passes { + using namespace Math; + using namespace Core; + using namespace Core::Services; + using namespace Utilities; + using namespace Structs; + using namespace Objects; + constexpr static const uint3 InjectThreadCount = { 16u, 2u, 16u }; constexpr static const uint3 ScatterThreadCount = { 32u,2u,1u }; constexpr static const uint3 VolumeResolution = { 160u, 90u, 128u }; diff --git a/PKRenderer/src/Rendering/Passes/PassVolumeFog.h b/PKRenderer/src/Rendering/Passes/PassVolumeFog.h index f4137fc9..d4b6156c 100644 --- a/PKRenderer/src/Rendering/Passes/PassVolumeFog.h +++ b/PKRenderer/src/Rendering/Passes/PassVolumeFog.h @@ -7,24 +7,21 @@ namespace PK::Rendering::Passes { - using namespace PK::Core; - using namespace PK::Rendering::Objects; - - class PassVolumeFog : public PK::Core::NoCopy + class PassVolumeFog : public PK::Utilities::NoCopy { public: - PassVolumeFog(AssetDatabase* assetDatabase, const ApplicationConfig* config); - void Render(CommandBuffer* cmd, RenderTexture* destination, const uint3& resolution); - void OnUpdateParameters(const ApplicationConfig* config); + PassVolumeFog(Core::Services::AssetDatabase* assetDatabase, const Core::ApplicationConfig* config); + void Render(Objects::CommandBuffer* cmd, Objects::RenderTexture* destination, const Math::uint3& resolution); + void OnUpdateParameters(const Core::ApplicationConfig* config); private: - Ref m_volumeResources; - Ref m_depthTiles; - Ref m_volumeInject; - Ref m_volumeScatter; - Shader* m_computeInject = nullptr; - Shader* m_computeScatter = nullptr; - Shader* m_computeDepthTiles = nullptr; - Shader* m_shaderComposite = nullptr; + Utilities::Ref m_volumeResources; + Utilities::Ref m_depthTiles; + Utilities::Ref m_volumeInject; + Utilities::Ref m_volumeScatter; + Objects::Shader* m_computeInject = nullptr; + Objects::Shader* m_computeScatter = nullptr; + Objects::Shader* m_computeDepthTiles = nullptr; + Objects::Shader* m_shaderComposite = nullptr; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/RenderPipeline.cpp b/PKRenderer/src/Rendering/RenderPipeline.cpp index d6ffa42f..1fc86b74 100644 --- a/PKRenderer/src/Rendering/RenderPipeline.cpp +++ b/PKRenderer/src/Rendering/RenderPipeline.cpp @@ -6,7 +6,13 @@ namespace PK::Rendering { - using namespace PK::Rendering::Objects; + using namespace Utilities; + using namespace Core; + using namespace Core::Services; + using namespace Math; + using namespace ECS; + using namespace Objects; + using namespace Structs; struct ModelMatrices { diff --git a/PKRenderer/src/Rendering/RenderPipeline.h b/PKRenderer/src/Rendering/RenderPipeline.h index 0dbf66f4..ad6dad8f 100644 --- a/PKRenderer/src/Rendering/RenderPipeline.h +++ b/PKRenderer/src/Rendering/RenderPipeline.h @@ -15,24 +15,24 @@ namespace PK::Rendering { - using namespace PK::Core; - using namespace PK::Core::Services; - using namespace PK::Rendering::Objects; - - class RenderPipeline : public IService, - public IStep, - public IStep, - public IConditionalStep, - public IStep> + class RenderPipeline : public Core::Services::IService, + public Core::Services::IStep, + public Core::Services::IStep, + public Core::Services::IConditionalStep, + public Core::Services::IStep> { public: - RenderPipeline(AssetDatabase* assetDatabase, EntityDatabase* entityDb, Sequencer* sequencer, const ApplicationConfig* config); + RenderPipeline(Core::Services::AssetDatabase* assetDatabase, + ECS::EntityDatabase* entityDb, + Core::Services::Sequencer* sequencer, + const Core::ApplicationConfig* config); + ~RenderPipeline(); void Step(PK::ECS::Tokens::ViewProjectionUpdateToken* token) override final; void Step(PK::ECS::Tokens::TimeToken* token) override final; - void Step(Window* window, int condition) override final; - void Step(AssetImportToken* token) override final; + void Step(Core::Window* window, int condition) override final; + void Step(Core::Services::AssetImportToken* token) override final; private: Passes::PassPostEffects m_passPostEffects; @@ -42,12 +42,12 @@ namespace PK::Rendering Passes::PassVolumeFog m_passVolumeFog; Batcher m_batcher; - Ref m_constantsPerFrame; - Ref m_RenderTarget; - Shader* m_OEMBackgroundShader; + Utilities::Ref m_constantsPerFrame; + Utilities::Ref m_RenderTarget; + Objects::Shader* m_OEMBackgroundShader; ECS::Tokens::VisibilityList m_visibilityList; - float4x4 m_viewProjectionMatrix; + Math::float4x4 m_viewProjectionMatrix; float m_znear; float m_zfar; }; diff --git a/PKRenderer/src/Rendering/Structs/Descriptors.h b/PKRenderer/src/Rendering/Structs/Descriptors.h index 06c81b83..9fc18d50 100644 --- a/PKRenderer/src/Rendering/Structs/Descriptors.h +++ b/PKRenderer/src/Rendering/Structs/Descriptors.h @@ -4,8 +4,6 @@ namespace PK::Rendering::Structs { - using namespace PK::Math; - struct SamplerDescriptor { FilterMode filter = FilterMode::Point; @@ -35,7 +33,7 @@ namespace PK::Rendering::Structs TextureFormat format = TextureFormat::RGBA8; SamplerType samplerType = SamplerType::Sampler2D; TextureUsage usage = TextureUsage::Default; - uint3 resolution = PK_UINT3_ONE; + Math::uint3 resolution = Math::PK_UINT3_ONE; uint8_t levels = 1; uint8_t samples = 1; uint16_t layers = 1; @@ -48,7 +46,7 @@ namespace PK::Rendering::Structs TextureFormat depthFormat = TextureFormat::Depth24_Stencil8; SamplerType samplerType = SamplerType::Sampler2D; TextureUsage usage = TextureUsage::Default; - uint3 resolution = PK_UINT3_ONE; + Math::uint3 resolution = Math::PK_UINT3_ONE; uint8_t levels = 1; uint8_t samples = 1; uint16_t layers = 1; @@ -57,18 +55,18 @@ namespace PK::Rendering::Structs struct TextureViewRange { - ushort level = 0u; - ushort layer = 0u; - ushort levels = 0u; - ushort layers = 0u; + uint16_t level = 0u; + uint16_t layer = 0u; + uint16_t levels = 0u; + uint16_t layers = 0u; TextureViewRange() {} - TextureViewRange(ushort level, ushort layer, ushort levels, ushort layers) : level(level), layer(layer), levels(levels), layers(layers) {} + TextureViewRange(uint16_t level, uint16_t layer, uint16_t levels, uint16_t layers) : level(level), layer(layer), levels(levels), layers(layers) {} }; struct MultisamplingParameters { - uint rasterizationSamples = 1; + uint32_t rasterizationSamples = 1; bool sampleShadingEnable = false; bool alphaToCoverageEnable = false; bool alphaToOneEnable = false; diff --git a/PKRenderer/src/Rendering/Structs/Layout.cpp b/PKRenderer/src/Rendering/Structs/Layout.cpp index f779f134..3396feb4 100644 --- a/PKRenderer/src/Rendering/Structs/Layout.cpp +++ b/PKRenderer/src/Rendering/Structs/Layout.cpp @@ -20,7 +20,7 @@ namespace PK::Rendering::Structs element->Offset = m_stride; m_stride += element->Size(); - m_alignedStride = alignment * (uint)glm::ceil(m_alignedStride / (float)alignment); + m_alignedStride = alignment * (uint32_t)glm::ceil(m_alignedStride / (float)alignment); element->AlignedOffset = m_alignedStride; m_alignedStride += element->Size(); @@ -34,8 +34,8 @@ namespace PK::Rendering::Structs } // As per std140 a structure has a base alignment equal to the largest base alignment of any of its members, rounded up to a multiple of 16. - maxAlignment = 16 * (uint)glm::ceil(maxAlignment / 16.0f); - m_paddedStride = maxAlignment * (uint)glm::ceil(m_alignedStride / (float)maxAlignment); + maxAlignment = 16 * (uint32_t)glm::ceil(maxAlignment / 16.0f); + m_paddedStride = maxAlignment * (uint32_t)glm::ceil(m_alignedStride / (float)maxAlignment); } const BufferElement* BufferLayout::TryGetElement(uint32_t nameHashId, uint32_t* index) const diff --git a/PKRenderer/src/Rendering/Structs/Layout.h b/PKRenderer/src/Rendering/Structs/Layout.h index 782b79eb..2aa16e5b 100644 --- a/PKRenderer/src/Rendering/Structs/Layout.h +++ b/PKRenderer/src/Rendering/Structs/Layout.h @@ -6,10 +6,6 @@ namespace PK::Rendering::Structs { - using namespace PK::Math; - using namespace PK::Utilities; - using namespace PK::Core::Services; - struct ConstantVariable { uint32_t NameHashId = 0; @@ -20,7 +16,7 @@ namespace PK::Rendering::Structs ConstantVariable() = default; ConstantVariable(const std::string & name, uint16_t size, uint16_t offset, uint32_t stageFlags) : - NameHashId(StringHashID::StringToID(name)), + NameHashId(Core::Services::StringHashID::StringToID(name)), Size(size), Offset(offset), StageFlags(stageFlags) @@ -59,7 +55,7 @@ namespace PK::Rendering::Structs ResourceElement() = default; ResourceElement(ResourceType type, const std::string& name, uint16_t count) : - NameHashId(StringHashID::StringToID(name)), + NameHashId(Core::Services::StringHashID::StringToID(name)), Type(type), Count(count) { @@ -96,15 +92,14 @@ namespace PK::Rendering::Structs byte Count = 1; byte Location = 0; - ushort Offset = 0; - ushort AlignedOffset = 0; - - ushort Size() const { return ElementConvert::Size(Type) * Count; } + uint16_t Offset = 0; + uint16_t AlignedOffset = 0; + uint16_t Size() const { return ElementConvert::Size(Type) * Count; } BufferElement() = default; BufferElement(ElementType type, const std::string& name, byte count = 1, byte location = 0) : - NameHashId(StringHashID::StringToID(name)), + NameHashId(Core::Services::StringHashID::StringToID(name)), Type(type), Count(count), Offset(0), @@ -160,10 +155,10 @@ namespace PK::Rendering::Structs CalculateOffsetsAndStride(); } - inline uint GetStride(BufferUsage usage) const { return (usage & BufferUsage::AlignedTypes) != 0 ? m_alignedStride : m_stride; } - constexpr inline uint GetStride() const { return m_stride; } - constexpr inline uint GetAlignedStride() const { return m_alignedStride; } - constexpr inline uint GetPaddedStride() const { return m_paddedStride; } + inline uint32_t GetStride(BufferUsage usage) const { return (usage & BufferUsage::AlignedTypes) != 0 ? m_alignedStride : m_stride; } + constexpr inline uint32_t GetStride() const { return m_stride; } + constexpr inline uint32_t GetAlignedStride() const { return m_alignedStride; } + constexpr inline uint32_t GetPaddedStride() const { return m_paddedStride; } const BufferElement* TryGetElement(uint32_t nameHashId, uint32_t* index) const; @@ -171,8 +166,8 @@ namespace PK::Rendering::Structs void CalculateOffsetsAndStride(); std::map m_elementMap; - uint m_stride = 0; - uint m_alignedStride = 0; - uint m_paddedStride = 0; + uint32_t m_stride = 0; + uint32_t m_alignedStride = 0; + uint32_t m_paddedStride = 0; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/Structs/StructsCommon.h b/PKRenderer/src/Rendering/Structs/StructsCommon.h index 4eb7190c..b1e54e66 100644 --- a/PKRenderer/src/Rendering/Structs/StructsCommon.h +++ b/PKRenderer/src/Rendering/Structs/StructsCommon.h @@ -3,35 +3,33 @@ namespace PK::Rendering::Structs { - using namespace PK::Math; - struct PK_Draw { - uint material; - uint transfrom; - uint mesh; - uint clipInfo; + Math::uint material; + Math::uint transfrom; + Math::uint mesh; + Math::uint clipInfo; }; struct PK_Light { - float4 position; - float4 color; - uint4 indices; + Math::float4 position; + Math::float4 color; + Math::uint4 indices; }; struct Vertex_Simple { - float3 position; - float2 texcoord; + Math::float3 position; + Math::float2 texcoord; }; struct Vertex_Full { - float3 position; - float3 normal; - float4 tangent; - float2 texcoord; + Math::float3 position; + Math::float3 normal; + Math::float4 tangent; + Math::float2 texcoord; }; struct IndexRange diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBindArray.h b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBindArray.h index 70886efa..cc51cc64 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBindArray.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBindArray.h @@ -7,23 +7,20 @@ namespace PK::Rendering::VulkanRHI::Objects { - using namespace PK::Core; - using namespace PK::Rendering::Objects; - - class VulkanBindArray : public BindArray, - public BindArray + class VulkanBindArray : public Rendering::Objects::BindArray, + public Rendering::Objects::BindArray { public: VulkanBindArray(size_t capacity); ~VulkanBindArray(); const VulkanBindHandle* const* GetHandles(uint32_t* version, uint32_t* count) const; - int32_t Add(Texture* value, void* bindInfo) override final; - int32_t Add(Texture* value) override final; - int32_t Add(const Texture* value) override final; - int32_t Add(Buffer* value, void* bindInfo) override final; - int32_t Add(Buffer* value) override final; - int32_t Add(const Buffer* value) override final; + int32_t Add(Rendering::Objects::Texture* value, void* bindInfo) override final; + int32_t Add(Rendering::Objects::Texture* value) override final; + int32_t Add(const Rendering::Objects::Texture* value) override final; + int32_t Add(Rendering::Objects::Buffer* value, void* bindInfo) override final; + int32_t Add(Rendering::Objects::Buffer* value) override final; + int32_t Add(const Rendering::Objects::Buffer* value) override final; void Clear() override final { m_count = 0; } diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBuffer.cpp b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBuffer.cpp index 80351ee6..a73c5c6d 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBuffer.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBuffer.cpp @@ -5,6 +5,8 @@ namespace PK::Rendering::VulkanRHI::Objects { + using namespace Systems; + VulkanBuffer::VulkanBuffer(const BufferLayout& layout, const void* data, size_t count, BufferUsage usage) : Buffer(layout, count, usage), m_driver(GraphicsAPI::GetActiveDriver()) diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBuffer.h b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBuffer.h index e351c8df..038ef3ae 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBuffer.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanBuffer.h @@ -7,14 +7,10 @@ namespace PK::Rendering::VulkanRHI::Objects { - using namespace PK::Rendering::Objects; - using namespace PK::Utilities; - using namespace Systems; - class VulkanBuffer : public Buffer { public: - VulkanBuffer(const BufferLayout& layout, const void* data, size_t count, BufferUsage usage); + VulkanBuffer(const Structs::BufferLayout& layout, const void* data, size_t count, Structs::BufferUsage usage); ~VulkanBuffer(); void SetData(const void* data, size_t offset, size_t size) override final; @@ -26,24 +22,24 @@ namespace PK::Rendering::VulkanRHI::Objects size_t GetCapacity() const override final { return m_rawBuffer->capacity; } const VulkanRawBuffer* GetRaw() const { return m_rawBuffer; } - const VulkanBindHandle* GetBindHandle(const IndexRange& range); + const VulkanBindHandle* GetBindHandle(const Structs::IndexRange& range); inline const VulkanBindHandle* GetBindHandle() const { // Default range is always the first one return m_bindHandles.GetValueAt(0); } - void MakeRangeResident(const IndexRange& range) override final; - void MakeRangeNonResident(const IndexRange& range) override final; + void MakeRangeResident(const Structs::IndexRange& range) override final; + void MakeRangeNonResident(const Structs::IndexRange& range) override final; bool Validate(size_t count) override final; private: struct RangeHash { - size_t operator()(const IndexRange& k) const noexcept + size_t operator()(const Structs::IndexRange& k) const noexcept { - return HashHelpers::FNV1AHash(&k, sizeof(IndexRange)); + return Utilities::HashHelpers::FNV1AHash(&k, sizeof(Structs::IndexRange)); } }; @@ -52,8 +48,8 @@ namespace PK::Rendering::VulkanRHI::Objects const VulkanDriver* m_driver = nullptr; VulkanRawBuffer* m_rawBuffer = nullptr; - VulkanStagingBuffer* m_mappedBuffer = nullptr; + Systems::VulkanStagingBuffer* m_mappedBuffer = nullptr; VulkanSparsePageTable* m_pageTable = nullptr; - PointerMap m_bindHandles; + Utilities::PointerMap m_bindHandles; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanCommandBuffer.cpp b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanCommandBuffer.cpp index e9f158bd..391d7097 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanCommandBuffer.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanCommandBuffer.cpp @@ -8,6 +8,9 @@ namespace PK::Rendering::VulkanRHI::Objects { + using namespace Utilities; + using namespace Core; + void VulkanCommandBuffer::SetRenderTarget(const uint3& resolution) { VulkanRenderTarget dummy(VK_NULL_HANDLE, @@ -61,7 +64,7 @@ namespace PK::Rendering::VulkanRHI::Objects } - void VulkanCommandBuffer::SetShader(const Shader* shader, int variantIndex) + void VulkanCommandBuffer::SetShader(const Shader* shader, int32_t variantIndex) { if (variantIndex == -1) { @@ -84,7 +87,7 @@ namespace PK::Rendering::VulkanRHI::Objects renderState->SetShader(pVariant); } - void VulkanCommandBuffer::SetVertexBuffers(const Buffer** buffers, uint count) + void VulkanCommandBuffer::SetVertexBuffers(const Buffer** buffers, uint32_t count) { auto pHandles = PK_STACK_ALLOC(const VulkanBindHandle*, count); diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanCommandBuffer.h b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanCommandBuffer.h index ff12c346..3a89676d 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanCommandBuffer.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanCommandBuffer.h @@ -8,9 +8,10 @@ namespace PK::Rendering::VulkanRHI::Objects { - using namespace PK::Rendering::VulkanRHI; + // Forgive me for this + using namespace PK::Math; using namespace PK::Rendering::Objects; - using namespace PK::Utilities; + using namespace PK::Rendering::Structs; struct VulkanCommandBuffer : public CommandBuffer { @@ -19,8 +20,8 @@ namespace PK::Rendering::VulkanRHI::Objects VkCommandBuffer commandBuffer = VK_NULL_HANDLE; VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; uint64_t invocationIndex = 0; - VulkanRenderState* renderState = nullptr; - Ref fence = nullptr; + Objects::VulkanRenderState* renderState = nullptr; + PK::Utilities::Ref fence = nullptr; bool isInActiveRenderPass = false; inline bool IsActive() const { return commandBuffer != VK_NULL_HANDLE; } @@ -57,8 +58,8 @@ namespace PK::Rendering::VulkanRHI::Objects void DrawIndexedIndirect(const Buffer* indirectArguments, size_t offset, uint32_t drawCount, uint32_t stride) override final; void Dispatch(uint3 groupCount) override final; - void Blit(Texture* src, Window* dst, FilterMode filter) override final; - void Blit(Window* src, Buffer* dst) override final; + void Blit(Texture* src, Core::Window* dst, FilterMode filter) override final; + void Blit(Core::Window* src, Buffer* dst) override final; void Blit(Texture* src, Texture* dst, uint32_t srcLevel, uint32_t dstLevel, uint32_t srcLayer, uint32_t dstLayer, FilterMode filter) override final; void Blit(const VulkanRenderTarget& src, const VulkanRenderTarget& dst, uint32_t srcLevel, uint32_t dstLevel, uint32_t srcLayer, uint32_t dstLayer, FilterMode filter, bool flipVertical = false); diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanRenderState.cpp b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanRenderState.cpp index fedb855f..109e1b11 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanRenderState.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanRenderState.cpp @@ -9,6 +9,10 @@ namespace PK::Rendering::VulkanRHI::Objects { + using namespace Utilities; + using namespace Systems; + using namespace Core::Services; + void VulkanRenderState::Reset() { memset(m_descriptorSetKeys, 0, sizeof(m_descriptorSetKeys)); diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanRenderState.h b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanRenderState.h index 7a3601bd..f8f59d81 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanRenderState.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanRenderState.h @@ -10,8 +10,6 @@ namespace PK::Rendering::VulkanRHI::Objects { - using namespace PK::Rendering::VulkanRHI::Systems; - enum PKRenderStateDirtyFlags { PK_RENDER_STATE_DIRTY_RENDERTARGET = 1 << 0, @@ -32,31 +30,31 @@ namespace PK::Rendering::VulkanRHI::Objects struct VulkanSystemContext { - VulkanDescriptorCache* descriptorCache; - VulkanPipelineCache* pipelineCache; - VulkanSamplerCache* samplerCache; - VulkanFrameBufferCache* frameBufferCache; - VulkanStagingBufferCache* stagingBufferCache; - VulkanDisposer* disposer; + Systems::VulkanDescriptorCache* descriptorCache; + Systems::VulkanPipelineCache* pipelineCache; + Systems::VulkanSamplerCache* samplerCache; + Systems::VulkanFrameBufferCache* frameBufferCache; + Systems::VulkanStagingBufferCache* stagingBufferCache; + Systems::VulkanDisposer* disposer; }; struct VulkanVertexBufferBundle { - VkBuffer buffers[PK_MAX_VERTEX_ATTRIBUTES]{}; - VkDeviceSize offsets[PK_MAX_VERTEX_ATTRIBUTES]{}; // Not used atm. + VkBuffer buffers[Structs::PK_MAX_VERTEX_ATTRIBUTES]{}; + VkDeviceSize offsets[Structs::PK_MAX_VERTEX_ATTRIBUTES]{}; // Not used atm. uint32_t count = 0u; }; struct VulkanDescriptorSetBundle { - VkDescriptorSet sets[PK_MAX_DESCRIPTOR_SETS]{}; + VkDescriptorSet sets[Structs::PK_MAX_DESCRIPTOR_SETS]{}; VkPipelineLayout layout; VkPipelineBindPoint bindPoint; uint32_t firstSet = 0u; uint32_t count = 0u; }; - class VulkanRenderState : NoCopy + class VulkanRenderState : PK::Utilities::NoCopy { public: VulkanRenderState(const VulkanSystemContext& systems) : @@ -71,40 +69,40 @@ namespace PK::Rendering::VulkanRHI::Objects void Reset(); void SetRenderTarget(const VulkanRenderTarget* renderTargets, const VulkanRenderTarget* resolves, uint32_t count); - void ClearColor(const color& color, uint32_t index); + void ClearColor(const Math::color& color, uint32_t index); void ClearDepth(float depth, uint32_t stencil); void DiscardColor(uint32_t index); void DiscardDepth(); - bool SetViewports(const uint4* rects, uint32_t& count, VkViewport** outViewports); - bool SetScissors(const uint4* rects, uint32_t& count, VkRect2D** outScissors); + bool SetViewports(const Math::uint4* rects, uint32_t& count, VkViewport** outViewports); + bool SetScissors(const Math::uint4* rects, uint32_t& count, VkRect2D** outScissors); - void SetShader(const VulkanShader* shader); - void SetBlending(const BlendParameters& blend); - void SetRasterization(const RasterizationParameters& rasterization); - void SetDepthStencil(const DepthStencilParameters& depthStencil); - void SetMultisampling(const MultisamplingParameters& multisampling); + void SetShader(const Objects::VulkanShader* shader); + void SetBlending(const Structs::BlendParameters& blend); + void SetRasterization(const Structs::RasterizationParameters& rasterization); + void SetDepthStencil(const Structs::DepthStencilParameters& depthStencil); + void SetMultisampling(const Structs::MultisamplingParameters& multisampling); void SetVertexBuffers(const VulkanBindHandle** handles, uint32_t count); void SetIndexBuffer(const VulkanBindHandle* handle, VkIndexType indexType); template - void SetResource(uint32_t nameHashId, const T* value, uint count = 1) { m_resourceState.Set(nameHashId, value, count); } + void SetResource(uint32_t nameHashId, const T* value, uint32_t count = 1) { m_resourceState.Set(nameHashId, value, count); } template void SetResource(uint32_t nameHashId, const T& value) { m_resourceState.Set(nameHashId, value); } VkRenderPassBeginInfo GetRenderPassInfo() const; VulkanVertexBufferBundle GetVertexBufferBundle() const; - VulkanDescriptorSetBundle GetDescriptorSetBundle(const ExecutionGate& gate, uint32_t dirtyFlags); + VulkanDescriptorSetBundle GetDescriptorSetBundle(const Structs::ExecutionGate& gate, uint32_t dirtyFlags); const VulkanBindHandle* GetIndexBuffer(VkIndexType* outIndexType) const; void ValidateRenderTarget(); void ValidateVertexBuffers(); - void ValidateDescriptorSets(const ExecutionGate& gate); - PKRenderStateDirtyFlags ValidatePipeline(const ExecutionGate& gate); + void ValidateDescriptorSets(const Structs::ExecutionGate& gate); + PKRenderStateDirtyFlags ValidatePipeline(const Structs::ExecutionGate& gate); - constexpr const PropertyBlock& GetResourceState() const { return m_resourceState; } - constexpr const ConstantBufferLayout& GetPipelinePushConstantLayout() const { return m_pipelineKey.shader->GetConstantLayout(); } + constexpr const PK::Utilities::PropertyBlock& GetResourceState() const { return m_resourceState; } + constexpr const Structs::ConstantBufferLayout& GetPipelinePushConstantLayout() const { return m_pipelineKey.shader->GetConstantLayout(); } constexpr VkPipelineLayout GetPipelineLayout() const { return m_pipelineKey.shader->GetPipelineLayout()->layout; } constexpr VkPipeline GetPipeline() const { return m_pipeline->pipeline; } constexpr bool HasPipeline() const { return m_pipeline != nullptr; } @@ -112,32 +110,32 @@ namespace PK::Rendering::VulkanRHI::Objects inline VkPipelineBindPoint GetPipelineBindPoint() const { return EnumConvert::GetPipelineBindPoint(m_pipelineKey.shader->GetType()); } private: - PropertyBlock m_resourceState = PropertyBlock(16384); - VulkanDescriptorCache* m_descriptorCache = nullptr; - VulkanPipelineCache* m_pipelineCache = nullptr; - VulkanSamplerCache* m_samplerCache = nullptr; - VulkanFrameBufferCache* m_frameBufferCache = nullptr; - VulkanStagingBufferCache* m_stagingBufferCache = nullptr; - VulkanDisposer* m_disposer = nullptr; + PK::Utilities::PropertyBlock m_resourceState = PK::Utilities::PropertyBlock(16384); + Systems::VulkanDescriptorCache* m_descriptorCache = nullptr; + Systems::VulkanPipelineCache* m_pipelineCache = nullptr; + Systems::VulkanSamplerCache* m_samplerCache = nullptr; + Systems::VulkanFrameBufferCache* m_frameBufferCache = nullptr; + Systems::VulkanStagingBufferCache* m_stagingBufferCache = nullptr; + Systems::VulkanDisposer* m_disposer = nullptr; - DescriptorSetKey m_descriptorSetKeys[PK_MAX_DESCRIPTOR_SETS]{}; - PipelineKey m_pipelineKey{}; - FrameBufferKey m_frameBufferKey[2]{}; - RenderPassKey m_renderPassKey[2]{}; + Systems::DescriptorSetKey m_descriptorSetKeys[Structs::PK_MAX_DESCRIPTOR_SETS]{}; + Systems::PipelineKey m_pipelineKey{}; + Systems::FrameBufferKey m_frameBufferKey[2]{}; + Systems::RenderPassKey m_renderPassKey[2]{}; - const VulkanBindHandle* m_vertexBuffers[PK_MAX_VERTEX_ATTRIBUTES]{}; + const VulkanBindHandle* m_vertexBuffers[Structs::PK_MAX_VERTEX_ATTRIBUTES]{}; const VulkanBindHandle* m_indexBuffer = nullptr; VkIndexType m_indexType = VK_INDEX_TYPE_UINT16; - VkViewport m_viewports[PK_MAX_VIEWPORTS]{}; - VkRect2D m_scissors[PK_MAX_VIEWPORTS]{}; - VkClearValue m_clearValues[PK_MAX_RENDER_TARGETS + 1]{}; + VkViewport m_viewports[Structs::PK_MAX_VIEWPORTS]{}; + VkRect2D m_scissors[Structs::PK_MAX_VIEWPORTS]{}; + VkClearValue m_clearValues[Structs::PK_MAX_RENDER_TARGETS + 1]{}; uint32_t m_clearValueCount = 0u; uint32_t m_dirtyFlags; const VulkanRenderPass* m_renderPass = nullptr; const VulkanPipeline* m_pipeline = nullptr; - const VulkanDescriptorSet* m_descriptorSets[PK_MAX_DESCRIPTOR_SETS]; + const VulkanDescriptorSet* m_descriptorSets[Structs::PK_MAX_DESCRIPTOR_SETS]; const VulkanFrameBuffer* m_frameBuffer = nullptr; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanShader.cpp b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanShader.cpp index a12b7122..57b6c747 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanShader.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanShader.cpp @@ -7,8 +7,9 @@ namespace PK::Rendering::VulkanRHI::Objects { - using namespace PK::Rendering::VulkanRHI::Utilities; - using namespace PK::Rendering::Structs; + using namespace VulkanRHI::Utilities; + using namespace Structs; + using namespace Systems; VulkanShader::VulkanShader(void* base, PK::Assets::Shader::PKShaderVariant* variant) : m_device(GraphicsAPI::GetActiveDriver()->device) { diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanShader.h b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanShader.h index 2676d95c..e5bbf0e3 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanShader.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanShader.h @@ -6,9 +6,6 @@ namespace PK::Rendering::VulkanRHI::Objects { - using namespace PK::Utilities; - using namespace PK::Rendering::Structs; - class VulkanShader : public PK::Rendering::Objects::ShaderVariant, public IVulkanDisposable { public: @@ -25,8 +22,8 @@ namespace PK::Rendering::VulkanRHI::Objects private: const VkDevice m_device; uint32_t m_descriptorSetCount; - VulkanShaderModule* m_modules[(int)ShaderStage::MaxCount]; - VulkanDescriptorSetLayout* m_descriptorSetLayouts[PK_MAX_DESCRIPTOR_SETS]{}; + VulkanShaderModule* m_modules[(int)Structs::ShaderStage::MaxCount]; + VulkanDescriptorSetLayout* m_descriptorSetLayouts[Structs::PK_MAX_DESCRIPTOR_SETS]{}; VulkanPipelineLayout* m_pipelineLayout; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanSparsePageTable.h b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanSparsePageTable.h index 08d42edb..8610e199 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanSparsePageTable.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanSparsePageTable.h @@ -6,8 +6,6 @@ namespace PK::Rendering::VulkanRHI::Objects { - using namespace PK::Utilities; - class VulkanSparsePageTable : public IVulkanDisposable { struct Page @@ -26,8 +24,8 @@ namespace PK::Rendering::VulkanRHI::Objects VulkanSparsePageTable(const VulkanDriver* driver, const VkBuffer buffer, VmaMemoryUsage memoryUsage); ~VulkanSparsePageTable(); - void AllocateRange(const IndexRange& range); - void FreeRange(const IndexRange& range); + void AllocateRange(const Structs::IndexRange& range); + void FreeRange(const Structs::IndexRange& range); private: bool CheckRange(size_t* start, size_t* end); @@ -38,6 +36,6 @@ namespace PK::Rendering::VulkanRHI::Objects VmaAllocationCreateInfo m_pageCreateInfo{}; VkMemoryRequirements m_memoryRequirements{}; std::map m_activePages; - FixedPool m_pages; + Utilities::FixedPool m_pages; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanTexture.cpp b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanTexture.cpp index 89503fd8..2dcfe8d3 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanTexture.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanTexture.cpp @@ -5,6 +5,10 @@ namespace PK::Rendering::VulkanRHI::Objects { + using namespace PK::Utilities; + using namespace Systems; + using namespace Objects; + VulkanTexture::VulkanTexture() : m_driver(GraphicsAPI::GetActiveDriver()) { } diff --git a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanTexture.h b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanTexture.h index 2edcfe50..24efd964 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanTexture.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Objects/VulkanTexture.h @@ -5,10 +5,7 @@ namespace PK::Rendering::VulkanRHI::Objects { - using namespace Systems; - using namespace PK::Rendering::Objects; - - class VulkanTexture : public Texture + class VulkanTexture : public Rendering::Objects::Texture { public: VulkanTexture(); @@ -16,28 +13,31 @@ namespace PK::Rendering::VulkanRHI::Objects ~VulkanTexture(); void SetData(const void* data, size_t size, uint32_t level, uint32_t layer) const override final; - void SetSampler(const SamplerDescriptor& sampler) override final; + void SetSampler(const Structs::SamplerDescriptor& sampler) override final; void Import(const char* filepath, void* pParams) override final; - bool Validate(const uint3& resolution) override final; + bool Validate(const Math::uint3& resolution) override final; bool Validate(const uint32_t levels, const uint32_t layers) override final; - bool Validate(const TextureDescriptor& descriptor) override final; - void Rebuild(const TextureDescriptor& descriptor); + bool Validate(const Structs::TextureDescriptor& descriptor) override final; + void Rebuild(const Structs::TextureDescriptor& descriptor); - TextureViewRange NormalizeViewRange(const TextureViewRange& range) const; + Structs::TextureViewRange NormalizeViewRange(const Structs::TextureViewRange& range) const; inline VkImageLayout GetImageLayout() const { return EnumConvert::GetImageLayout(m_descriptor.usage); } inline VkImageAspectFlags GetAspectFlags() const { return m_rawImage->aspect; } inline VkFormat GetNativeFormat() const { return m_rawImage->format; } inline const VulkanRawImage* GetRaw() const { return m_rawImage; } VulkanRenderTarget GetRenderTarget() const; - VulkanRenderTarget GetRenderTarget(const TextureViewRange& range); + VulkanRenderTarget GetRenderTarget(const Structs::TextureViewRange& range); inline const VulkanBindHandle* GetBindHandle() const { return &GetView(m_defaultViewRange)->bindHandle; } - inline const VulkanBindHandle* GetBindHandle(const TextureViewRange& range, bool sampled) { return &GetView(range, sampled ? TextureBindMode::SampledTexture : TextureBindMode::Image)->bindHandle; } + inline const VulkanBindHandle* GetBindHandle(const Structs::TextureViewRange& range, bool sampled) + { + return &GetView(range, sampled ? Structs::TextureBindMode::SampledTexture : Structs::TextureBindMode::Image)->bindHandle; + } private: struct alignas(8) ViewKey { - TextureViewRange range{}; - TextureBindMode bindMode = TextureBindMode::SampledTexture; + Structs::TextureViewRange range{}; + Structs::TextureBindMode bindMode = Structs::TextureBindMode::SampledTexture; inline constexpr bool operator < (const ViewKey& other) const noexcept { @@ -76,20 +76,20 @@ namespace PK::Rendering::VulkanRHI::Objects VulkanImageView* view = nullptr; }; - inline const ViewValue* GetView(const TextureViewRange& range, TextureBindMode mode = TextureBindMode::SampledTexture) const + inline const ViewValue* GetView(const Structs::TextureViewRange& range, Structs::TextureBindMode mode = Structs::TextureBindMode::SampledTexture) const { return m_imageViews.at({ range, mode }).get(); } - const ViewValue* GetView(const TextureViewRange& range, TextureBindMode mode = TextureBindMode::SampledTexture); + const ViewValue* GetView(const Structs::TextureViewRange& range, Structs::TextureBindMode mode = Structs::TextureBindMode::SampledTexture); void Dispose(); const VulkanDriver* m_driver = nullptr; VulkanRawImage* m_rawImage = nullptr; - std::map> m_imageViews; + std::map> m_imageViews; VkComponentMapping m_swizzle{}; - TextureViewRange m_defaultViewRange{}; + Structs::TextureViewRange m_defaultViewRange{}; VkImageViewType m_viewType = VK_IMAGE_VIEW_TYPE_MAX_ENUM; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanCommandBufferPool.cpp b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanCommandBufferPool.cpp index f105612e..50171ac0 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanCommandBufferPool.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanCommandBufferPool.cpp @@ -6,6 +6,7 @@ namespace PK::Rendering::VulkanRHI::Systems { using namespace Objects; + using namespace PK::Utilities; VulkanCommandBufferPool::VulkanCommandBufferPool(const VkDevice device, const VulkanSystemContext& systems, uint32_t queueFamilyIndex) : m_device(device), m_primaryRenderState(systems) { diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanCommandBufferPool.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanCommandBufferPool.h index cda06be5..d9671cc8 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanCommandBufferPool.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanCommandBufferPool.h @@ -6,16 +6,13 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Utilities; - using namespace Objects; - - class VulkanCommandBufferPool + class VulkanCommandBufferPool : public PK::Utilities::NoCopy { public: - VulkanCommandBufferPool(const VkDevice device, const VulkanSystemContext& systems, uint32_t queueFamilyIndex); + VulkanCommandBufferPool(const VkDevice device, const Objects::VulkanSystemContext& systems, uint32_t queueFamilyIndex); ~VulkanCommandBufferPool(); - VulkanCommandBuffer* GetCurrent(); + Objects::VulkanCommandBuffer* GetCurrent(); VkSemaphore QueueDependency(const VkSemaphore** previousDependency); void SubmitCurrent(VkPipelineStageFlags waitFlag, const VulkanSemaphore* waitSignal); void PruneStaleBuffers(); @@ -28,12 +25,12 @@ namespace PK::Rendering::VulkanRHI::Systems const VkDevice m_device; VkQueue m_queue; VkCommandPool m_pool; - VulkanRenderState m_primaryRenderState; - VulkanCommandBuffer m_commandBuffers[MAX_PRIMARY_COMMANDBUFFERS] = {}; + Objects::VulkanRenderState m_primaryRenderState; + Objects::VulkanCommandBuffer m_commandBuffers[MAX_PRIMARY_COMMANDBUFFERS] = {}; VulkanSemaphore* m_renderingFinishedSignals[MAX_PRIMARY_COMMANDBUFFERS] = {}; VulkanSemaphore* m_dependencySignals[MAX_DEPENDENCIES] = {}; - VulkanCommandBuffer* m_current = nullptr; + Objects::VulkanCommandBuffer* m_current = nullptr; VulkanSemaphore* m_renderingFinishedSignal = {}; VulkanSemaphore* m_currentDependencySignal = {}; uint32_t m_dependencySignalIndex = 0u; diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDescriptorCache.cpp b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDescriptorCache.cpp index 02dc8b09..d89019da 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDescriptorCache.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDescriptorCache.cpp @@ -5,6 +5,8 @@ namespace PK::Rendering::VulkanRHI::Systems { + using namespace Structs; + static uint32_t GetArraySize(const DescriptorSetKey& key) { uint32_t variableSize = 0u; diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDescriptorCache.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDescriptorCache.h index aa1e893c..b93a8e6b 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDescriptorCache.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDescriptorCache.h @@ -7,8 +7,6 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Utilities; - struct alignas(8) DescriptorBinding { union @@ -17,7 +15,7 @@ namespace PK::Rendering::VulkanRHI::Systems const VulkanBindHandle* const* handles; }; - ResourceType type; + Structs::ResourceType type; bool isArray; uint16_t count; uint64_t version; @@ -26,7 +24,7 @@ namespace PK::Rendering::VulkanRHI::Systems struct DescriptorSetKey { VkShaderStageFlagBits stageFlags; - DescriptorBinding bindings[PK_MAX_DESCRIPTORS_PER_SET]; + DescriptorBinding bindings[Structs::PK_MAX_DESCRIPTORS_PER_SET]; inline bool operator == (const DescriptorSetKey& other) const noexcept { @@ -38,19 +36,19 @@ namespace PK::Rendering::VulkanRHI::Systems { std::size_t operator()(const DescriptorSetKey& k) const noexcept { - constexpr ulong seed = 18446744073709551557; - return HashHelpers::MurmurHash(&k, sizeof(DescriptorSetKey), seed); + constexpr uint64_t seed = 18446744073709551557; + return PK::Utilities::HashHelpers::MurmurHash(&k, sizeof(DescriptorSetKey), seed); } }; - class VulkanDescriptorCache : public NoCopy + class VulkanDescriptorCache : public PK::Utilities::NoCopy { private: struct ExtinctPool { VulkanDescriptorPool* pool; - mutable ExecutionGate executionGate; + mutable Structs::ExecutionGate executionGate; std::vector extinctSetIndices; }; @@ -60,13 +58,13 @@ namespace PK::Rendering::VulkanRHI::Systems const VulkanDescriptorSet* GetDescriptorSet(const VulkanDescriptorSetLayout* layout, const DescriptorSetKey& key, - const ExecutionGate& gate); + const Structs::ExecutionGate& gate); void Prune(); private: - void GrowPool(const ExecutionGate& executionGate); - void GetDescriptorSets(VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets, const ExecutionGate& gate, bool throwOnFail); + void GrowPool(const Structs::ExecutionGate& executionGate); + void GetDescriptorSets(VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets, const Structs::ExecutionGate& gate, bool throwOnFail); const std::map m_poolSizes; const VkDevice m_device; @@ -76,8 +74,8 @@ namespace PK::Rendering::VulkanRHI::Systems uint64_t m_currentPruneTick = 0ull; VulkanDescriptorPool* m_currentPool = nullptr; - FixedPool m_setsPool; - PointerMap m_sets; + PK::Utilities::FixedPool m_setsPool; + PK::Utilities::PointerMap m_sets; std::vector m_extinctPools; std::vector m_writeImages; std::vector m_writeBuffers; diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDisposer.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDisposer.h index b0fb84e0..4576282f 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDisposer.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanDisposer.h @@ -4,24 +4,22 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Utilities; - - class VulkanDisposer : public NoCopy + class VulkanDisposer : public PK::Utilities::NoCopy { struct DisposeHandle { - Scope disposable = nullptr; - ExecutionGate gate{}; + PK::Utilities::Scope disposable = nullptr; + Structs::ExecutionGate gate{}; }; public: VulkanDisposer() {} template - void Dispose(T* disposable, const ExecutionGate& releaseGate) + void Dispose(T* disposable, const Structs::ExecutionGate& releaseGate) { static_assert(std::is_base_of::value, "Template argument type does not derive from IService!"); - m_disposables.push_back({ Scope(disposable), releaseGate }); + m_disposables.push_back({ PK::Utilities::Scope(disposable), releaseGate }); } void Prune(); diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanFrameBufferCache.cpp b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanFrameBufferCache.cpp index 8883d13d..1c3f762f 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanFrameBufferCache.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanFrameBufferCache.cpp @@ -3,7 +3,9 @@ #include "Rendering/VulkanRHI/Utilities/VulkanUtilities.h" namespace PK::Rendering::VulkanRHI::Systems -{ +{ + using namespace Structs; + VulkanFrameBufferCache::VulkanFrameBufferCache(VkDevice device, uint64_t pruneDelay) : m_device(device), m_pruneDelay(pruneDelay) {} VulkanFrameBufferCache::~VulkanFrameBufferCache() diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanFrameBufferCache.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanFrameBufferCache.h index a5bb2d1e..16c35bd3 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanFrameBufferCache.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanFrameBufferCache.h @@ -6,13 +6,10 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Utilities; - using namespace PK::Math; - struct alignas(8) FrameBufferKey { - VkImageView color[PK_MAX_RENDER_TARGETS]; - VkImageView resolve[PK_MAX_RENDER_TARGETS]; + VkImageView color[Structs::PK_MAX_RENDER_TARGETS]; + VkImageView resolve[Structs::PK_MAX_RENDER_TARGETS]; VkImageView depth; VkRenderPass renderPass; VkExtent2D extent; @@ -28,14 +25,14 @@ namespace PK::Rendering::VulkanRHI::Systems { VkImageLayout layout; VkFormat format; - LoadOp loadop; - StoreOp storeop; + Structs::LoadOp loadop; + Structs::StoreOp storeop; bool resolve; }; struct alignas(8) RenderPassKey { - AttachmentKey colors[PK_MAX_RENDER_TARGETS]; + AttachmentKey colors[Structs::PK_MAX_RENDER_TARGETS]; AttachmentKey depth; uint32_t samples = 1; @@ -52,8 +49,8 @@ namespace PK::Rendering::VulkanRHI::Systems { std::size_t operator()(const FrameBufferKey& k) const noexcept { - constexpr ulong seed = 18446744073709551557; - return HashHelpers::MurmurHash(reinterpret_cast(&k), sizeof(FrameBufferKey), seed); + constexpr uint64_t seed = 18446744073709551557; + return PK::Utilities::HashHelpers::MurmurHash(reinterpret_cast(&k), sizeof(FrameBufferKey), seed); } }; @@ -61,12 +58,12 @@ namespace PK::Rendering::VulkanRHI::Systems { std::size_t operator()(const RenderPassKey& k) const noexcept { - constexpr ulong seed = 18446744073709551557; - return HashHelpers::MurmurHash(reinterpret_cast(&k), sizeof(RenderPassKey), seed); + constexpr uint64_t seed = 18446744073709551557; + return PK::Utilities::HashHelpers::MurmurHash(reinterpret_cast(&k), sizeof(RenderPassKey), seed); } }; - class VulkanFrameBufferCache : public NoCopy + class VulkanFrameBufferCache : public PK::Utilities::NoCopy { public: VulkanFrameBufferCache(VkDevice device, uint64_t pruneDelay); diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanLayoutCache.cpp b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanLayoutCache.cpp index fd25c5a4..5c7fb5d9 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanLayoutCache.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanLayoutCache.cpp @@ -3,6 +3,9 @@ namespace PK::Rendering::VulkanRHI::Systems { + using namespace Structs; + using namespace Utilities; + VulkanDescriptorSetLayout* VulkanLayoutCache::GetSetLayout(const DescriptorSetLayoutKey& key) { auto iterator = m_setlayouts.find(key); diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanLayoutCache.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanLayoutCache.h index 91a129ec..2d0049db 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanLayoutCache.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanLayoutCache.h @@ -7,13 +7,10 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Math; - using namespace PK::Utilities; - struct DescriptorSetLayoutKey { - uint16_t counts[PK_MAX_DESCRIPTORS_PER_SET]{}; - VkDescriptorType types[PK_MAX_DESCRIPTORS_PER_SET]{}; + uint16_t counts[Structs::PK_MAX_DESCRIPTORS_PER_SET]{}; + VkDescriptorType types[Structs::PK_MAX_DESCRIPTORS_PER_SET]{}; VkShaderStageFlags stageFlags = 0u; inline bool operator < (const DescriptorSetLayoutKey& r) const noexcept @@ -24,8 +21,8 @@ namespace PK::Rendering::VulkanRHI::Systems struct PipelineLayoutKey { - VkDescriptorSetLayout setlayouts[PK_MAX_DESCRIPTOR_SETS]{}; - VkPushConstantRange pushConstants[(int)ShaderStage::MaxCount]{}; + VkDescriptorSetLayout setlayouts[Structs::PK_MAX_DESCRIPTOR_SETS]{}; + VkPushConstantRange pushConstants[(int)Structs::ShaderStage::MaxCount]{}; inline bool operator < (const PipelineLayoutKey& r) const noexcept { @@ -33,7 +30,7 @@ namespace PK::Rendering::VulkanRHI::Systems } }; - class VulkanLayoutCache : public NoCopy + class VulkanLayoutCache : public PK::Utilities::NoCopy { public: VulkanLayoutCache(VkDevice device) : m_device(device) {} @@ -43,7 +40,7 @@ namespace PK::Rendering::VulkanRHI::Systems private: VkDevice m_device; - std::map> m_setlayouts; - std::map> m_pipelineLayouts; + std::map> m_setlayouts; + std::map> m_pipelineLayouts; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanPipelineCache.cpp b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanPipelineCache.cpp index e6ba38f7..25092d7c 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanPipelineCache.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanPipelineCache.cpp @@ -7,6 +7,8 @@ namespace PK::Rendering::VulkanRHI::Systems { using namespace PK::Utilities; + using namespace Structs; + using namespace Objects; VulkanPipelineCache::VulkanPipelineCache(VkDevice device, const std::string& workingDirectory, uint64_t pruneDelay) : m_device(device), diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanPipelineCache.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanPipelineCache.h index 76185e42..9819a3c7 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanPipelineCache.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanPipelineCache.h @@ -6,19 +6,15 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Math; - using namespace PK::Utilities; - using namespace Objects; - struct PipelineKey { - IDHandle shader; - FixedFunctionState fixedFunctionState{}; + PK::Utilities::IDHandle shader; + Structs::FixedFunctionState fixedFunctionState{}; VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; VkBool32 primitiveRestart = VK_FALSE; VkRenderPass renderPass = VK_NULL_HANDLE; - VkVertexInputAttributeDescription vertexAttributes[PK_MAX_VERTEX_ATTRIBUTES]{}; - VkVertexInputBindingDescription vertexBuffers[PK_MAX_VERTEX_ATTRIBUTES]{}; + VkVertexInputAttributeDescription vertexAttributes[Structs::PK_MAX_VERTEX_ATTRIBUTES]{}; + VkVertexInputBindingDescription vertexBuffers[Structs::PK_MAX_VERTEX_ATTRIBUTES]{}; inline bool operator == (const PipelineKey& r) const noexcept { @@ -30,12 +26,12 @@ namespace PK::Rendering::VulkanRHI::Systems { std::size_t operator()(const PipelineKey& k) const noexcept { - constexpr ulong seed = 18446744073709551557; - return HashHelpers::MurmurHash(reinterpret_cast(&k), sizeof(PipelineKey), seed); + constexpr uint64_t seed = 18446744073709551557; + return PK::Utilities::HashHelpers::MurmurHash(reinterpret_cast(&k), sizeof(PipelineKey), seed); } }; - class VulkanPipelineCache : public NoCopy + class VulkanPipelineCache : public PK::Utilities::NoCopy { private: @@ -53,7 +49,7 @@ namespace PK::Rendering::VulkanRHI::Systems const VulkanPipeline* GetPipeline(const PipelineKey& key); const VulkanPipeline* GetGraphicsPipeline(const PipelineKey& key); - const VulkanPipeline* GetComputePipeline(const IDHandle& shader); + const VulkanPipeline* GetComputePipeline(const PK::Utilities::IDHandle& shader); void Prune(); private: @@ -61,7 +57,7 @@ namespace PK::Rendering::VulkanRHI::Systems VkPipelineCache m_pipelineCache = VK_NULL_HANDLE; std::string m_workingDirectory; std::unordered_map m_graphicsPipelines; - std::unordered_map, PipelineValue, IDHandle::Hash> m_computePipelines; + std::unordered_map, PipelineValue, PK::Utilities::IDHandle::Hash> m_computePipelines; uint64_t m_currentPruneTick = 0; uint64_t m_pruneDelay = 0; }; diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSamplerCache.cpp b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSamplerCache.cpp index f8244137..0a6eb6f0 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSamplerCache.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSamplerCache.cpp @@ -3,6 +3,8 @@ namespace PK::Rendering::VulkanRHI::Systems { + using namespace Structs; + VulkanSamplerCache::~VulkanSamplerCache() { for (auto& kv : m_samplers) diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSamplerCache.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSamplerCache.h index b8448884..7ca115ed 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSamplerCache.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSamplerCache.h @@ -5,19 +5,16 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Utilities; - using namespace Structs; - - class VulkanSamplerCache : NoCopy + class VulkanSamplerCache : PK::Utilities::NoCopy { public: VulkanSamplerCache(VkDevice device) : m_device(device) {} ~VulkanSamplerCache(); - VkSampler GetSampler(const SamplerDescriptor& descriptor); + VkSampler GetSampler(const Structs::SamplerDescriptor& descriptor); private: const VkDevice m_device; - std::map m_samplers; + std::map m_samplers; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanStagingBufferCache.cpp b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanStagingBufferCache.cpp index 1a236e74..617f4041 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanStagingBufferCache.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanStagingBufferCache.cpp @@ -5,6 +5,7 @@ using namespace PK::Utilities; using namespace PK::Rendering::VulkanRHI::Systems; +using namespace PK::Rendering::Structs; template<> struct Vector::Comparer diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanStagingBufferCache.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanStagingBufferCache.h index 3244114d..78e51811 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanStagingBufferCache.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanStagingBufferCache.h @@ -6,18 +6,16 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Utilities; - struct VulkanStagingBuffer : public VulkanRawBuffer { VulkanStagingBuffer(VkDevice device, VmaAllocator allocator, const VulkanBufferCreateInfo& createInfo) : VulkanRawBuffer(device, allocator, createInfo) {} - mutable ExecutionGate executionGate; + mutable Rendering::Structs::ExecutionGate executionGate; mutable VkDeviceSize destinationOffset = 0ull; mutable VkDeviceSize desitnationRange = 0ull; uint64_t pruneTick = 0ull; }; - class VulkanStagingBufferCache : public NoCopy + class VulkanStagingBufferCache : public PK::Utilities::NoCopy { public: VulkanStagingBufferCache(VkDevice device, VmaAllocator allocator, uint64_t pruneDelay) : @@ -38,7 +36,7 @@ namespace PK::Rendering::VulkanRHI::Systems const VkDevice m_device; std::vector m_freeBuffers; std::vector m_activeBuffers; - FixedPool m_bufferPool; + PK::Utilities::FixedPool m_bufferPool; uint64_t m_currentPruneTick = 0ull; uint64_t m_pruneDelay = 0ull; diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSwapchain.cpp b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSwapchain.cpp index 7390b6fc..bed859fd 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSwapchain.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSwapchain.cpp @@ -5,6 +5,8 @@ namespace PK::Rendering::VulkanRHI::Systems { + using namespace PK::Utilities; + static bool SwapchainErrorAssert(VkResult result, bool& outofdate, bool& submoptimal) { if (result == VK_ERROR_OUT_OF_DATE_KHR && !outofdate) diff --git a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSwapchain.h b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSwapchain.h index 5fee338f..133752c8 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSwapchain.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Systems/VulkanSwapchain.h @@ -6,8 +6,6 @@ namespace PK::Rendering::VulkanRHI::Systems { - using namespace PK::Utilities; - struct SwapchainCreateInfo { VkExtent2D desiredExtent; @@ -18,7 +16,7 @@ namespace PK::Rendering::VulkanRHI::Systems uint32_t maxFramesInFlight; }; - class VulkanSwapchain : public NoCopy + class VulkanSwapchain : public Utilities::NoCopy { public: VulkanSwapchain(const VkPhysicalDevice physicalDevice, @@ -37,7 +35,7 @@ namespace PK::Rendering::VulkanRHI::Systems void Present(VulkanSemaphore* waitSignal); void OnWindowResize(int w, int h); - const std::vector>& GetImageViews() const { return m_imageViews; } + const std::vector>& GetImageViews() const { return m_imageViews; } VulkanImageView* GetImageView() const { return m_imageViews.at(m_imageIndex).get(); } const VulkanRenderTarget GetRenderTarget() const { @@ -54,11 +52,11 @@ namespace PK::Rendering::VulkanRHI::Systems ); } constexpr VkExtent2D GetExtent() const { return m_extent; } - constexpr uint3 GetResolution() const { return { m_extent.width, m_extent.height, 1 }; } + constexpr Math::uint3 GetResolution() const { return { m_extent.width, m_extent.height, 1 }; } constexpr float GetAspectRatio() const { return (float)m_extent.width / (float)m_extent.height; } - constexpr uint4 GetRect() const { return { 0, 0, m_extent.width, m_extent.height }; } + constexpr Math::uint4 GetRect() const { return { 0, 0, m_extent.width, m_extent.height }; } constexpr VkFormat GetNativeFormat() const { return m_format; } - TextureFormat GetFormat() const { return EnumConvert::GetTextureFormat(m_format); } + Structs::TextureFormat GetFormat() const { return EnumConvert::GetTextureFormat(m_format); } private: const VkPhysicalDevice m_physicalDevice; @@ -71,8 +69,8 @@ namespace PK::Rendering::VulkanRHI::Systems VkQueue m_presentQueue = VK_NULL_HANDLE; VkSwapchainKHR m_swapchain = VK_NULL_HANDLE; std::vector m_images; - std::vector> m_imageViews; - std::vector> m_imageAvailableSignals; + std::vector> m_imageViews; + std::vector> m_imageAvailableSignals; VkFormat m_format; VkExtent2D m_extent; uint32_t m_maxFramesInFlight; diff --git a/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanEnumConversion.cpp b/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanEnumConversion.cpp index aa4f98e9..b914afa2 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanEnumConversion.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanEnumConversion.cpp @@ -4,6 +4,8 @@ namespace PK::Rendering::VulkanRHI::EnumConvert { + using namespace Rendering::Structs; + VkFormat GetFormat(ElementType format) { switch (format) diff --git a/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanEnumConversion.h b/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanEnumConversion.h index ab0fbd2f..a5710465 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanEnumConversion.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanEnumConversion.h @@ -4,36 +4,34 @@ namespace PK::Rendering::VulkanRHI::EnumConvert { - using namespace PK::Rendering::Structs; - - VkFormat GetFormat(ElementType format); - ElementType GetElementType(VkFormat format); - VkFormat GetFormat(TextureFormat format); - VkIndexType GetIndexType(ElementType format); - TextureFormat GetTextureFormat(VkFormat format); + VkFormat GetFormat(Rendering::Structs::ElementType format); + Rendering::Structs::ElementType GetElementType(VkFormat format); + VkFormat GetFormat(Rendering::Structs::TextureFormat format); + VkIndexType GetIndexType(Rendering::Structs::ElementType format); + Rendering::Structs::TextureFormat GetTextureFormat(VkFormat format); bool IsDepthFormat(VkFormat format); VkComponentMapping GetSwizzle(VkFormat format); - VkImageViewType GetViewType(SamplerType samplerType); - VkImageLayout GetImageLayout(TextureUsage usage, bool useOptimized = false); - VkAttachmentLoadOp GetLoadOp(LoadOp loadOp); - VkAttachmentStoreOp GetStoreOp(StoreOp storeOp); - VkCompareOp GetCompareOp(Comparison comparison); - VkBorderColor GetBorderColor(BorderColor color); - VkSamplerAddressMode GetSamplerAddressMode(WrapMode wrap); - VkFilter GetFilterMode(FilterMode filter); - VkDescriptorType GetDescriptorType(ResourceType type); - ResourceType GetResourceType(VkDescriptorType type, uint32_t count); - VkShaderStageFlagBits GetShaderStage(ShaderStage stage); - VkPipelineBindPoint GetPipelineBindPoint(ShaderType type); + VkImageViewType GetViewType(Rendering::Structs::SamplerType samplerType); + VkImageLayout GetImageLayout(Rendering::Structs::TextureUsage usage, bool useOptimized = false); + VkAttachmentLoadOp GetLoadOp(Rendering::Structs::LoadOp loadOp); + VkAttachmentStoreOp GetStoreOp(Rendering::Structs::StoreOp storeOp); + VkCompareOp GetCompareOp(Rendering::Structs::Comparison comparison); + VkBorderColor GetBorderColor(Rendering::Structs::BorderColor color); + VkSamplerAddressMode GetSamplerAddressMode(Rendering::Structs::WrapMode wrap); + VkFilter GetFilterMode(Rendering::Structs::FilterMode filter); + VkDescriptorType GetDescriptorType(Rendering::Structs::ResourceType type); + Rendering::Structs::ResourceType GetResourceType(VkDescriptorType type, uint32_t count); + VkShaderStageFlagBits GetShaderStage(Rendering::Structs::ShaderStage stage); + VkPipelineBindPoint GetPipelineBindPoint(Rendering::Structs::ShaderType type); VkSampleCountFlagBits GetSampleCountFlags(uint32_t samples); - VkVertexInputRate GetInputRate(InputRate inputRate); + VkVertexInputRate GetInputRate(Rendering::Structs::InputRate inputRate); VkShaderStageFlagBits GetShaderStageFlags(uint32_t pkStageFlags); - VkPolygonMode GetPolygonMode(PolygonMode mode); - VkBlendOp GetBlendOp(BlendOp op); - VkBlendFactor GetBlendFactor(BlendFactor factor, VkBlendFactor fallback); - VkCullModeFlagBits GetCullMode(CullMode op); - VkFrontFace GetFrontFace(FrontFace face); - VkPipelineStageFlagBits GetPipelineStageFlags(MemoryAccessFlags flags); - VkAccessFlagBits GetAccessFlags(MemoryAccessFlags flags); + VkPolygonMode GetPolygonMode(Rendering::Structs::PolygonMode mode); + VkBlendOp GetBlendOp(Rendering::Structs::BlendOp op); + VkBlendFactor GetBlendFactor(Rendering::Structs::BlendFactor factor, VkBlendFactor fallback); + VkCullModeFlagBits GetCullMode(Rendering::Structs::CullMode op); + VkFrontFace GetFrontFace(Rendering::Structs::FrontFace face); + VkPipelineStageFlagBits GetPipelineStageFlags(Rendering::Structs::MemoryAccessFlags flags); + VkAccessFlagBits GetAccessFlags(Rendering::Structs::MemoryAccessFlags flags); } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanStructs.cpp b/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanStructs.cpp index 2f2d1127..c320f30f 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanStructs.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanStructs.cpp @@ -4,6 +4,8 @@ namespace PK::Rendering::VulkanRHI { + using namespace Structs; + VulkanBufferCreateInfo::VulkanBufferCreateInfo(BufferUsage usage, size_t size) { buffer.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; diff --git a/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanStructs.h b/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanStructs.h index 48f6e393..3e39d074 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanStructs.h +++ b/PKRenderer/src/Rendering/VulkanRHI/Utilities/VulkanStructs.h @@ -9,9 +9,6 @@ namespace PK::Rendering::VulkanRHI { - using namespace PK::Rendering::Structs; - using namespace PK::Utilities; - constexpr const static uint32_t PK_QUEUE_FAMILY_COUNT = 3; constexpr const static uint32_t PK_INVALID_QUEUE_FAMILY = 0xFFFFFFFF; @@ -51,7 +48,7 @@ namespace PK::Rendering::VulkanRHI struct VulkanBufferCreateInfo { VulkanBufferCreateInfo() {}; - VulkanBufferCreateInfo(BufferUsage usage, size_t size); + VulkanBufferCreateInfo(Structs::BufferUsage usage, size_t size); VkBufferCreateInfo buffer { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; VmaAllocationCreateInfo allocation {}; @@ -60,7 +57,7 @@ namespace PK::Rendering::VulkanRHI struct VulkanImageCreateInfo { VulkanImageCreateInfo() {}; - VulkanImageCreateInfo(const TextureDescriptor& descriptor); + VulkanImageCreateInfo(const Structs::TextureDescriptor& descriptor); VkImageCreateInfo image = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO }; VmaAllocationCreateInfo allocation = {}; @@ -85,12 +82,12 @@ namespace PK::Rendering::VulkanRHI VkAccessFlags dstAccessMask = 0; }; - struct IVulkanDisposable : public IDObject + struct IVulkanDisposable : public PK::Utilities::IDObject { virtual ~IVulkanDisposable() = 0 {}; }; - struct VulkanFence : public NoCopy + struct VulkanFence : public PK::Utilities::NoCopy { VulkanFence(VkDevice device, bool signaled = false); ~VulkanFence(); @@ -99,7 +96,7 @@ namespace PK::Rendering::VulkanRHI VkFence vulkanFence; }; - struct VulkanSemaphore : public NoCopy + struct VulkanSemaphore : public PK::Utilities::NoCopy { VulkanSemaphore(VkDevice device); ~VulkanSemaphore(); @@ -116,7 +113,7 @@ namespace PK::Rendering::VulkanRHI VkImageView view; }; - struct VulkanFrameBuffer : public NoCopy + struct VulkanFrameBuffer : public PK::Utilities::NoCopy { VulkanFrameBuffer(VkDevice device, const VkFramebufferCreateInfo& createInfo); ~VulkanFrameBuffer(); @@ -125,7 +122,7 @@ namespace PK::Rendering::VulkanRHI VkFramebuffer frameBuffer; }; - struct VulkanRenderPass : public NoCopy + struct VulkanRenderPass : public PK::Utilities::NoCopy { VulkanRenderPass(VkDevice device, const VkRenderPassCreateInfo& createInfo); ~VulkanRenderPass(); @@ -180,7 +177,7 @@ namespace PK::Rendering::VulkanRHI VkPipelineShaderStageCreateInfo stageInfo; }; - struct VulkanPipeline : public NoCopy + struct VulkanPipeline : public PK::Utilities::NoCopy { VulkanPipeline(VkDevice device, VkPipelineCache pipelineCache, const VkGraphicsPipelineCreateInfo& createInfo); VulkanPipeline(VkDevice device, VkPipelineCache pipelineCache, const VkComputePipelineCreateInfo& createInfo); @@ -190,7 +187,7 @@ namespace PK::Rendering::VulkanRHI VkPipeline pipeline; }; - struct VulkanPipelineLayout : public NoCopy + struct VulkanPipelineLayout : public PK::Utilities::NoCopy { VulkanPipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo& createInfo); ~VulkanPipelineLayout(); @@ -199,7 +196,7 @@ namespace PK::Rendering::VulkanRHI VkPipelineLayout layout; }; - struct VulkanDescriptorSetLayout : public NoCopy + struct VulkanDescriptorSetLayout : public PK::Utilities::NoCopy { VulkanDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo& createInfo, VkShaderStageFlagBits stageFlags); ~VulkanDescriptorSetLayout(); @@ -209,7 +206,7 @@ namespace PK::Rendering::VulkanRHI VkShaderStageFlagBits stageFlags; }; - struct VulkanDescriptorPool : public NoCopy + struct VulkanDescriptorPool : public PK::Utilities::NoCopy { VulkanDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo& createInfo); ~VulkanDescriptorPool(); @@ -224,19 +221,19 @@ namespace PK::Rendering::VulkanRHI { VkDescriptorSet set; uint64_t pruneTick; - mutable ExecutionGate executionGate; + mutable Rendering::Structs::ExecutionGate executionGate; }; - struct VulkanSampler : public NoCopy + struct VulkanSampler : public PK::Utilities::NoCopy { - VulkanSampler(VkDevice device, const SamplerDescriptor& descriptor); + VulkanSampler(VkDevice device, const Rendering::Structs::SamplerDescriptor& descriptor); ~VulkanSampler(); const VkDevice device; VkSampler sampler; }; - struct VulkanBindHandle : IDObject + struct VulkanBindHandle : PK::Utilities::IDObject { union { @@ -247,7 +244,7 @@ namespace PK::Rendering::VulkanRHI union { VkSampler sampler = VK_NULL_HANDLE; - const BufferLayout* bufferLayout; + const Rendering::Structs::BufferLayout* bufferLayout; }; union @@ -260,7 +257,7 @@ namespace PK::Rendering::VulkanRHI VkDeviceSize bufferOffset = 0ull; }; - struct VulkanRenderTarget : public NoCopy + struct VulkanRenderTarget : public PK::Utilities::NoCopy { VulkanRenderTarget(VkImageView view, VkImage image, diff --git a/PKRenderer/src/Rendering/VulkanRHI/VulkanDriver.cpp b/PKRenderer/src/Rendering/VulkanRHI/VulkanDriver.cpp index 119a8970..8c000b42 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/VulkanDriver.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/VulkanDriver.cpp @@ -6,6 +6,10 @@ namespace PK::Rendering::VulkanRHI { + using namespace PK::Utilities; + using namespace Systems; + using namespace Objects; + VulkanDriver::VulkanDriver(const VulkanContextProperties& properties) : properties(properties) { glfwInit(); diff --git a/PKRenderer/src/Rendering/VulkanRHI/VulkanDriver.h b/PKRenderer/src/Rendering/VulkanRHI/VulkanDriver.h index 7a2880b3..76177eda 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/VulkanDriver.h +++ b/PKRenderer/src/Rendering/VulkanRHI/VulkanDriver.h @@ -14,10 +14,6 @@ namespace PK::Rendering::VulkanRHI { - using namespace PK::Utilities; - using namespace PK::Rendering::GraphicsAPI; - using namespace Systems; - struct VulkanContextProperties { std::string appName; @@ -49,14 +45,13 @@ namespace PK::Rendering::VulkanRHI VulkanDriver(const VulkanContextProperties& properties); ~VulkanDriver(); - APIType GetAPI() const override final { return APIType::Vulkan; } - - CommandBuffer* GetPrimaryCommandBuffer() override final { return commandBufferPool->GetCurrent(); } + Rendering::Structs::APIType GetAPI() const override final { return Rendering::Structs::APIType::Vulkan; } + Rendering::Objects::CommandBuffer* GetPrimaryCommandBuffer() override final { return commandBufferPool->GetCurrent(); } void WaitForIdle() const override final { vkDeviceWaitIdle(device); } DriverMemoryInfo GetMemoryInfo() const override final; - size_t GetBufferOffsetAlignment(BufferUsage usage) const override final; + size_t GetBufferOffsetAlignment(Structs::BufferUsage usage) const override final; void GC() override final; @@ -74,13 +69,13 @@ namespace PK::Rendering::VulkanRHI VulkanContextProperties properties; VkPhysicalDeviceProperties physicalDeviceProperties; - Scope frameBufferCache; - Scope commandBufferPool; - Scope stagingBufferCache; - Scope descriptorCache; - Scope pipelineCache; - Scope samplerCache; - Scope layoutCache; - Scope disposer; + PK::Utilities::Scope frameBufferCache; + PK::Utilities::Scope commandBufferPool; + PK::Utilities::Scope stagingBufferCache; + PK::Utilities::Scope descriptorCache; + PK::Utilities::Scope pipelineCache; + PK::Utilities::Scope samplerCache; + PK::Utilities::Scope layoutCache; + PK::Utilities::Scope disposer; }; } \ No newline at end of file diff --git a/PKRenderer/src/Rendering/VulkanRHI/VulkanWindow.cpp b/PKRenderer/src/Rendering/VulkanRHI/VulkanWindow.cpp index 786d04ab..8e6333ea 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/VulkanWindow.cpp +++ b/PKRenderer/src/Rendering/VulkanRHI/VulkanWindow.cpp @@ -5,6 +5,11 @@ namespace PK::Rendering::VulkanRHI { + using namespace PK::Utilities; + using namespace Systems; + using namespace Objects; + using namespace Structs; + static VulkanWindow* GetWindowPtr(GLFWwindow* window) { return (VulkanWindow*)glfwGetWindowUserPointer(window); diff --git a/PKRenderer/src/Rendering/VulkanRHI/VulkanWindow.h b/PKRenderer/src/Rendering/VulkanRHI/VulkanWindow.h index 0ad19673..5e606705 100644 --- a/PKRenderer/src/Rendering/VulkanRHI/VulkanWindow.h +++ b/PKRenderer/src/Rendering/VulkanRHI/VulkanWindow.h @@ -8,8 +8,6 @@ namespace PK::Rendering::VulkanRHI { - using namespace Systems; - class VulkanWindow : public PK::Core::Window { public: @@ -18,7 +16,7 @@ namespace PK::Rendering::VulkanRHI VulkanWindow(VulkanDriver* driver, const PK::Core::WindowProperties& properties); ~VulkanWindow(); - uint3 GetResolution() const override { return m_swapchain->GetResolution(); } + Math::uint3 GetResolution() const override { return m_swapchain->GetResolution(); } float GetAspectRatio() const override { return m_swapchain->GetAspectRatio(); } bool IsAlive() const override { return m_alive; } bool IsMinimized() const override { return m_minimized; } @@ -31,7 +29,7 @@ namespace PK::Rendering::VulkanRHI inline void PollEvents() const override final { glfwPollEvents(); } void* GetNativeWindow() const override final { return m_window; } - uint4 GetRect() const override final { return m_swapchain->GetRect(); } + Math::uint4 GetRect() const override final { return m_swapchain->GetRect(); } constexpr VkExtent2D GetExtent() const { return m_swapchain->GetExtent(); } constexpr VkFormat GetNativeFormat() const { return m_swapchain->GetNativeFormat(); } const VulkanRenderTarget GetRenderTarget() const { return m_swapchain->GetRenderTarget(); } @@ -40,7 +38,7 @@ namespace PK::Rendering::VulkanRHI const VulkanDriver* m_driver; VkSurfaceKHR m_surface; GLFWwindow* m_window; - Scope m_swapchain; + PK::Utilities::Scope m_swapchain; VulkanSemaphore* m_imageAvailableSignal; bool m_vsync = true; diff --git a/PKRenderer/src/Utilities/PropertyBlock.h b/PKRenderer/src/Utilities/PropertyBlock.h index 2664a9c3..561d6523 100644 --- a/PKRenderer/src/Utilities/PropertyBlock.h +++ b/PKRenderer/src/Utilities/PropertyBlock.h @@ -4,7 +4,7 @@ namespace PK::Utilities { - class PropertyBlock : public NoCopy + class PropertyBlock : public Utilities::NoCopy { protected: struct PropertyInfo