From 8938850441f46d1a5db5e606e6d327ee8b3e0709 Mon Sep 17 00:00:00 2001 From: Ilya Perapechka Date: Mon, 19 Aug 2024 23:29:51 +0300 Subject: [PATCH 1/3] feat: BSComputeShader and some improvements for BSImagespaceSahder. --- include/RE/B/BSComputeShader.h | 30 ++++++++++++++++ include/RE/B/BSImagespaceShader.h | 43 ++++++++++++++++++----- include/RE/B/BSImagespaceShaderBlur3.h | 4 ++- include/RE/B/BSReloadShaderI.h | 4 ++- include/RE/B/BSShader.h | 48 +++++++++++++++++++------- include/RE/Skyrim.h | 1 + 6 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 include/RE/B/BSComputeShader.h diff --git a/include/RE/B/BSComputeShader.h b/include/RE/B/BSComputeShader.h new file mode 100644 index 000000000..343de25e4 --- /dev/null +++ b/include/RE/B/BSComputeShader.h @@ -0,0 +1,30 @@ +#pragma once + +#include "RE/B/BSReloadShaderI.h" +#include "RE/B/BSShader.h" +#include "RE/N/NiRefObject.h" + +namespace RE +{ + class BSComputeShader : public NiRefObject, public BSReloadShaderI + { + public: + inline static constexpr auto RTTI = RTTI_BSComputeShader; + inline static constexpr auto VTABLE = VTABLE_BSComputeShader; + + ~BSComputeShader() override; // 00 + + // override (BSReloadShaderI) + void ReloadShaders(void* stream) override; // 00 + + // add + virtual void Dispatch(uint32_t techniqueId, uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ); // 02 + + const char* name; // 18 + BSTHashMap shadersMap; // 20 + + private: + KEEP_FOR_RE() + }; + static_assert(sizeof(BSComputeShader) == 0x50); +} diff --git a/include/RE/B/BSImagespaceShader.h b/include/RE/B/BSImagespaceShader.h index 7d588261f..163f6c607 100644 --- a/include/RE/B/BSImagespaceShader.h +++ b/include/RE/B/BSImagespaceShader.h @@ -15,6 +15,13 @@ namespace RE inline static constexpr auto RTTI = RTTI_BSImagespaceShader; inline static constexpr auto VTABLE = VTABLE_BSImagespaceShader; + struct ShaderMacro + { + const char* name; // 00 + const char* definition; // 08 + }; + static_assert(sizeof(ShaderMacro) == 0x10); + ~BSImagespaceShader() override; // 00 // override (BSShader) @@ -25,23 +32,43 @@ namespace RE bool RestoreRenderStates(ImageSpaceEffectParam* a_param) override; // 09 // add - virtual void Unk_0A(void); // 0A - { return; } - virtual void Unk_0B(void); // 0B - { return; } - virtual void Unk_0C(void); // 0C - virtual void Unk_0D(void); // 0D - virtual void Unk_0E(void); // 0E + virtual void PreRender(); // 0A - { return; } + virtual void PostRender(); // 0B - { return; } + virtual void DispatchComputeShader(uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ); // 0C + virtual void GetShaderMacros(ShaderMacro* macros); // 0D + virtual void LoadShaders(); // 0E + + static BSImagespaceShader* Create() + { + auto isShader = malloc(); + std::memset(reinterpret_cast(isShader), 0, sizeof(BSImagespaceShader)); + if (isShader) { + isShader->Ctor(); + } + return isShader; + } // members - BSFixedString name; // 120 - BSFixedString originalShaderName; // 128 + const char* name; // 120 + const char* originalShaderName; // 128 std::uint64_t unk130; // 130 BSTArray vsConstantNames; // 138 BSTArray psConstantNames; // 150 BSTArray samplerNames; // 158 - BSTArray unk180; // 180 + BSTArray uavNames; // 180 BSComputeShader* computeShader; // 198 bool unk1A0; // 1A0 bool isComputeShader; // 1A1 + + private: + BSImagespaceShader* Ctor() + { + using func_t = decltype(&BSImagespaceShader::Ctor); + static REL::Relocation func{ RELOCATION_ID(100943, 107725) }; + BSImagespaceShader* isShader = func(this); + stl::emplace_vtable(isShader); + return isShader; + } }; static_assert(sizeof(BSImagespaceShader) == 0x1A8); } diff --git a/include/RE/B/BSImagespaceShaderBlur3.h b/include/RE/B/BSImagespaceShaderBlur3.h index 0be03a0ed..815686977 100644 --- a/include/RE/B/BSImagespaceShaderBlur3.h +++ b/include/RE/B/BSImagespaceShaderBlur3.h @@ -13,7 +13,9 @@ namespace RE ~BSImagespaceShaderBlur3() override; // 00 // override (BSImagespaceShader) - void Unk_0D(void) override; // 0D + void GetShaderMacros(ShaderMacro* macros) override; // 0D + private: + KEEP_FOR_RE() }; static_assert(sizeof(BSImagespaceShaderBlur3) == 0x1A8); } diff --git a/include/RE/B/BSReloadShaderI.h b/include/RE/B/BSReloadShaderI.h index f595992a1..ba8d2d43b 100644 --- a/include/RE/B/BSReloadShaderI.h +++ b/include/RE/B/BSReloadShaderI.h @@ -10,7 +10,9 @@ namespace RE inline static constexpr auto RTTI = RTTI_BSReloadShaderI; inline static constexpr auto VTABLE = VTABLE_BSReloadShaderI; - virtual void Unk_00(void) = 0; // 00 + virtual void ReloadShaders(void* stream) = 0; // 00 + private: + KEEP_FOR_RE() }; static_assert(sizeof(BSReloadShaderI) == 0x8); } diff --git a/include/RE/B/BSShader.h b/include/RE/B/BSShader.h index 8fc10845c..434f0a8ce 100644 --- a/include/RE/B/BSShader.h +++ b/include/RE/B/BSShader.h @@ -29,10 +29,10 @@ namespace RE { public: // members - std::uint32_t id; // 00 - ID3D11PixelShader* shader; // 08 - ConstantGroup constantBuffers[3]; // 10 - std::int8_t constantTable[64]; // 58 + std::uint32_t id; // 00 + REX::W32::ID3D11PixelShader* shader = nullptr; // 08 + ConstantGroup constantBuffers[3]; // 10 + std::array constantTable; // 58 }; static_assert(sizeof(PixelShader) == 0x80); @@ -40,16 +40,40 @@ namespace RE { public: // members - std::uint32_t id; // 00 - ID3D11VertexShader* shader; // 08 - std::uint32_t byteCodeSize; // 10 - ConstantGroup constantBuffers[3]; // 18 - std::uint64_t shaderDesc; // 48 - std::int8_t constantTable[20]; // 50 - std::uint32_t pad64; // 64 - std::uint8_t rawBytecode[0]; // 68 + std::uint32_t id; // 00 + REX::W32::ID3D11VertexShader* shader = nullptr; // 08 + std::uint32_t byteCodeSize; // 10 + ConstantGroup constantBuffers[3]; // 18 + std::uint64_t shaderDesc; // 48 + std::array constantTable; // 50 + std::uint32_t pad64; // 64 + std::uint8_t rawBytecode[0]; // 68 }; static_assert(sizeof(VertexShader) == 0x68); + + class ComputeShader + { + public: + // members + uint64_t unk00; // 00 + uint64_t unk08; // 08 + uint64_t unk10; // 10 + uint32_t unk18; // 18 + uint64_t unk20; // 20 + uint64_t unk28; // 28 + uint64_t unk30; // 30 + uint32_t unk38; // 38 + uint64_t unk40; // 40 + uint64_t unk48; // 38 + uint64_t unk50; // 50 + uint32_t unk58; // 58 + REX::W32::ID3D11ComputeShader* shader; // 60 + uint32_t id; // 68 + uint32_t byteCodeSize; // 6C + std::array constantTable; // 70 + uint8_t rawBytecode[0]; // 90 + }; + static_assert(sizeof(ComputeShader) == 0x90); } namespace BSShaderTechniqueIDMap diff --git a/include/RE/Skyrim.h b/include/RE/Skyrim.h index b48409262..e273b4aee 100644 --- a/include/RE/Skyrim.h +++ b/include/RE/Skyrim.h @@ -217,6 +217,7 @@ #include "RE/B/BSBitField.h" #include "RE/B/BSBloodSplatterShaderProperty.h" #include "RE/B/BSBound.h" +#include "RE/B/BSComputeShader.h" #include "RE/B/BSContainer.h" #include "RE/B/BSCullingProcess.h" #include "RE/B/BSDirectInputManager.h" From 606987af5d6403ce248966fe9024273eed0c89b9 Mon Sep 17 00:00:00 2001 From: Jonahex Date: Mon, 19 Aug 2024 20:30:37 +0000 Subject: [PATCH 2/3] maintenance --- cmake/sourcelist.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/sourcelist.cmake b/cmake/sourcelist.cmake index 3e730c988..2e0c837d3 100644 --- a/cmake/sourcelist.cmake +++ b/cmake/sourcelist.cmake @@ -214,6 +214,7 @@ set(SOURCES include/RE/B/BSBitField.h include/RE/B/BSBloodSplatterShaderProperty.h include/RE/B/BSBound.h + include/RE/B/BSComputeShader.h include/RE/B/BSContainer.h include/RE/B/BSCoreTypes.h include/RE/B/BSCullingProcess.h From b19131697b9ffaa6e9c12f0b9df00349d50323e8 Mon Sep 17 00:00:00 2001 From: FlayaN Date: Tue, 20 Aug 2024 00:24:20 +0200 Subject: [PATCH 3/3] fix: build and follow sse naming standard --- include/RE/B/BSComputeShader.h | 8 ++-- include/RE/B/BSImagespaceShader.h | 11 +++-- include/RE/B/BSImagespaceShaderBlur3.h | 4 +- include/RE/B/BSReloadShaderI.h | 4 +- include/RE/B/BSShader.h | 63 +++++++++++++------------- 5 files changed, 43 insertions(+), 47 deletions(-) diff --git a/include/RE/B/BSComputeShader.h b/include/RE/B/BSComputeShader.h index 343de25e4..3c62afbde 100644 --- a/include/RE/B/BSComputeShader.h +++ b/include/RE/B/BSComputeShader.h @@ -15,16 +15,14 @@ namespace RE ~BSComputeShader() override; // 00 // override (BSReloadShaderI) - void ReloadShaders(void* stream) override; // 00 + void ReloadShaders(void* a_stream) override; // 00 // add - virtual void Dispatch(uint32_t techniqueId, uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ); // 02 + virtual void Dispatch(uint32_t a_techniqueId, uint32_t a_threadGroupCountX, uint32_t a_threadGroupCountY, uint32_t a_threadGroupCountZ); // 02 + // members const char* name; // 18 BSTHashMap shadersMap; // 20 - - private: - KEEP_FOR_RE() }; static_assert(sizeof(BSComputeShader) == 0x50); } diff --git a/include/RE/B/BSImagespaceShader.h b/include/RE/B/BSImagespaceShader.h index 163f6c607..005a9dc81 100644 --- a/include/RE/B/BSImagespaceShader.h +++ b/include/RE/B/BSImagespaceShader.h @@ -17,6 +17,7 @@ namespace RE struct ShaderMacro { + // members const char* name; // 00 const char* definition; // 08 }; @@ -32,11 +33,11 @@ namespace RE bool RestoreRenderStates(ImageSpaceEffectParam* a_param) override; // 09 // add - virtual void PreRender(); // 0A - { return; } - virtual void PostRender(); // 0B - { return; } - virtual void DispatchComputeShader(uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ); // 0C - virtual void GetShaderMacros(ShaderMacro* macros); // 0D - virtual void LoadShaders(); // 0E + virtual void PreRender(); // 0A - { return; } + virtual void PostRender(); // 0B - { return; } + virtual void DispatchComputeShader(uint32_t a_threadGroupCountX, uint32_t a_threadGroupCountY, uint32_t a_threadGroupCountZ); // 0C + virtual void GetShaderMacros(ShaderMacro* a_macros); // 0D + virtual void LoadShaders(); // 0E static BSImagespaceShader* Create() { diff --git a/include/RE/B/BSImagespaceShaderBlur3.h b/include/RE/B/BSImagespaceShaderBlur3.h index 815686977..9ccf290ab 100644 --- a/include/RE/B/BSImagespaceShaderBlur3.h +++ b/include/RE/B/BSImagespaceShaderBlur3.h @@ -13,9 +13,7 @@ namespace RE ~BSImagespaceShaderBlur3() override; // 00 // override (BSImagespaceShader) - void GetShaderMacros(ShaderMacro* macros) override; // 0D - private: - KEEP_FOR_RE() + void GetShaderMacros(ShaderMacro* a_macros) override; // 0D }; static_assert(sizeof(BSImagespaceShaderBlur3) == 0x1A8); } diff --git a/include/RE/B/BSReloadShaderI.h b/include/RE/B/BSReloadShaderI.h index ba8d2d43b..41b8a5e92 100644 --- a/include/RE/B/BSReloadShaderI.h +++ b/include/RE/B/BSReloadShaderI.h @@ -10,9 +10,7 @@ namespace RE inline static constexpr auto RTTI = RTTI_BSReloadShaderI; inline static constexpr auto VTABLE = VTABLE_BSReloadShaderI; - virtual void ReloadShaders(void* stream) = 0; // 00 - private: - KEEP_FOR_RE() + virtual void ReloadShaders(void* a_stream) = 0; // 00 }; static_assert(sizeof(BSReloadShaderI) == 0x8); } diff --git a/include/RE/B/BSShader.h b/include/RE/B/BSShader.h index 434f0a8ce..da9dfaae4 100644 --- a/include/RE/B/BSShader.h +++ b/include/RE/B/BSShader.h @@ -13,6 +13,7 @@ namespace RE struct ID3D11Buffer; struct ID3D11PixelShader; struct ID3D11VertexShader; + struct ID3D11ComputeShader; namespace BSGraphics { @@ -29,10 +30,10 @@ namespace RE { public: // members - std::uint32_t id; // 00 - REX::W32::ID3D11PixelShader* shader = nullptr; // 08 - ConstantGroup constantBuffers[3]; // 10 - std::array constantTable; // 58 + std::uint32_t id; // 00 + ID3D11PixelShader* shader; // 08 + ConstantGroup constantBuffers[3]; // 10 + std::array constantTable; // 58 }; static_assert(sizeof(PixelShader) == 0x80); @@ -40,14 +41,14 @@ namespace RE { public: // members - std::uint32_t id; // 00 - REX::W32::ID3D11VertexShader* shader = nullptr; // 08 - std::uint32_t byteCodeSize; // 10 - ConstantGroup constantBuffers[3]; // 18 - std::uint64_t shaderDesc; // 48 - std::array constantTable; // 50 - std::uint32_t pad64; // 64 - std::uint8_t rawBytecode[0]; // 68 + std::uint32_t id; // 00 + ID3D11VertexShader* shader; // 08 + std::uint32_t byteCodeSize; // 10 + ConstantGroup constantBuffers[3]; // 18 + std::uint64_t shaderDesc; // 48 + std::array constantTable; // 50 + std::uint32_t pad64; // 64 + std::uint8_t rawBytecode[0]; // 68 }; static_assert(sizeof(VertexShader) == 0x68); @@ -55,23 +56,23 @@ namespace RE { public: // members - uint64_t unk00; // 00 - uint64_t unk08; // 08 - uint64_t unk10; // 10 - uint32_t unk18; // 18 - uint64_t unk20; // 20 - uint64_t unk28; // 28 - uint64_t unk30; // 30 - uint32_t unk38; // 38 - uint64_t unk40; // 40 - uint64_t unk48; // 38 - uint64_t unk50; // 50 - uint32_t unk58; // 58 - REX::W32::ID3D11ComputeShader* shader; // 60 - uint32_t id; // 68 - uint32_t byteCodeSize; // 6C - std::array constantTable; // 70 - uint8_t rawBytecode[0]; // 90 + uint64_t unk00; // 00 + uint64_t unk08; // 08 + uint64_t unk10; // 10 + uint32_t unk18; // 18 + uint64_t unk20; // 20 + uint64_t unk28; // 28 + uint64_t unk30; // 30 + uint32_t unk38; // 38 + uint64_t unk40; // 40 + uint64_t unk48; // 38 + uint64_t unk50; // 50 + uint32_t unk58; // 58 + ID3D11ComputeShader* shader; // 60 + uint32_t id; // 68 + uint32_t byteCodeSize; // 6C + std::array constantTable; // 70 + uint8_t rawBytecode[0]; // 90 }; static_assert(sizeof(ComputeShader) == 0x90); } @@ -124,11 +125,11 @@ namespace RE virtual void GetTechniqueName(std::uint32_t a_techniqueID, char* a_buffer, std::uint32_t a_bufferSize); // 08 virtual void ReloadShaders(bool a_clear); // 09 - RE::BSRenderPass* MakeRenderPass(BSShaderProperty* property, BSGeometry* geometry, uint32_t technique, uint8_t numLights, BSLight** lights) + RE::BSRenderPass* MakeRenderPass(BSShaderProperty* a_property, BSGeometry* a_geometry, uint32_t a_technique, uint8_t a_numLights, BSLight** a_lights) { using func_t = decltype(&BSShader::MakeRenderPass); static REL::Relocation func{ RELOCATION_ID(100717, 107497) }; - return func(this, property, geometry, technique, numLights, lights); + return func(this, a_property, a_geometry, a_technique, a_numLights, a_lights); } // members