From d0ddcf87acd09ce4738d2811b8313d0525dc433f Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Sun, 15 Oct 2017 20:16:36 +0100 Subject: [PATCH] big refactor in shader - application interop --- WickedEngine/ConstantBufferMapping.h | 24 -------- WickedEngine/ResourceMapping.h | 49 --------------- WickedEngine/SamplerMapping.h | 12 ---- WickedEngine/ShaderInterop.h | 92 ++++++++++++++++++++++++++++ WickedEngine/globals.hlsli | 3 - WickedEngine/lightCullingCS.hlsl | 2 +- WickedEngine/lightingHF.hlsli | 34 ++-------- WickedEngine/objectHF.hlsli | 2 +- WickedEngine/objectPS_voxelizer.hlsl | 4 +- WickedEngine/wiEmittedParticle.h | 8 +-- WickedEngine/wiFont.h | 2 +- WickedEngine/wiHairParticle.h | 10 +-- WickedEngine/wiImage.h | 14 +---- WickedEngine/wiLensFlare.h | 8 +-- WickedEngine/wiLoader.cpp | 2 +- WickedEngine/wiLoader.h | 42 +++++-------- WickedEngine/wiRenderer.cpp | 36 +++++------ WickedEngine/wiRenderer.h | 89 ++++----------------------- WickedEngine/wiVersion.cpp | 2 +- 19 files changed, 157 insertions(+), 278 deletions(-) diff --git a/WickedEngine/ConstantBufferMapping.h b/WickedEngine/ConstantBufferMapping.h index fe89bbb89..cde75e1e0 100644 --- a/WickedEngine/ConstantBufferMapping.h +++ b/WickedEngine/ConstantBufferMapping.h @@ -33,28 +33,4 @@ -/////////////////////////// -// Helpers: -/////////////////////////// - -// CPP: -///////// - -#define CONSTANTBUFFER_BINDSLOT __ConstantBuffer_BindSlot__ -// Add this to a struct to match that with a bind slot: -#define CB_SETBINDSLOT(slot) static const int CONSTANTBUFFER_BINDSLOT = (slot); -// Get bindslot from a struct which is matched with a bind slot: -#define CB_GETBINDSLOT(structname) structname::CONSTANTBUFFER_BINDSLOT - - - -// Shader: -////////// - -// Automatically binds constantbuffers on the shader side: -// Needs macro expansion -#define CBUFFER_X(name, slot) cbuffer name : register(b ## slot) -#define CBUFFER(name, slot) CBUFFER_X(name, slot) - - #endif // _CONSTANTBUFFER_MAPPING_H_ diff --git a/WickedEngine/ResourceMapping.h b/WickedEngine/ResourceMapping.h index 510f6369e..f0ac4e3a1 100644 --- a/WickedEngine/ResourceMapping.h +++ b/WickedEngine/ResourceMapping.h @@ -75,53 +75,4 @@ #define SKINNINGSLOT_OUT_VERTEX_PRE 2 - -/////////////////////////// -// Helpers: -/////////////////////////// - -// CPP: -///////// - -#define STRUCTUREDBUFFER_BINDSLOT __StructuredBuffer_BindSlot__ -// Add this to a struct to match that with a bind slot: -#define STRUCTUREDBUFFER_SETBINDSLOT(slot) static const int STRUCTUREDBUFFER_BINDSLOT = (slot); -// Get bindslot from a struct which is matched with a bind slot: -#define STRUCTUREDBUFFER_GETBINDSLOT(structname) structname::STRUCTUREDBUFFER_BINDSLOT - - - -// Shader: -////////// - -// Automatically binds resources on the shader side: - -#define RAWBUFFER(name,slot) ByteAddressBuffer name : register(t ## slot) -#define RWRAWBUFFER(name,slot) RWByteAddressBuffer name : register(u ## slot) - -#define TYPEDBUFFER(name, type, slot) Buffer< type > name : register(t ## slot) -#define RWTYPEDBUFFER(name, type, slot) RWBuffer< type > name : register(u ## slot) - -#define STRUCTUREDBUFFER(name, type, slot) StructuredBuffer< type > name : register(t ## slot) -#define RWSTRUCTUREDBUFFER(name, type, slot) RWStructuredBuffer< type > name : register(u ## slot) -#define ROVSTRUCTUREDBUFFER(name, type, slot) RasterizerOrderedStructuredBuffer< type > name : register(u ## slot) - - -#define TEXTURE1D(name, type, slot) Texture1D< type > name : register(t ## slot); -#define TEXTURE1DARRAY(name, type, slot) Texture1DArray< type > name : register(t ## slot); -#define RWTEXTURE1D(name, type, slot) RWTexture1D< type > name : register(u ## slot); - -#define TEXTURE2D(name, type, slot) Texture2D< type > name : register(t ## slot); -#define TEXTURE2DMS(name, type, slot) Texture2DMS< type > name : register(t ## slot); -#define TEXTURE2DARRAY(name, type, slot) Texture2DArray< type > name : register(t ## slot); -#define RWTEXTURE2D(name, type, slot) RWTexture2D< type > name : register(u ## slot); -#define ROVTEXTURE2D(name, type, slot) RasterizerOrderedTexture2D< type > name : register(u ## slot); - -#define TEXTURECUBE(name, type, slot) TextureCube< type > name : register(t ## slot); -#define TEXTURECUBEARRAY(name, type, slot) TextureCubeArray< type > name : register(t ## slot); - -#define TEXTURE3D(name, type, slot) Texture3D< type > name : register(t ## slot); -#define RWTEXTURE3D(name, type, slot) RWTexture3D< type > name : register(u ## slot); -#define ROVTEXTURE3D(name, type, slot) RasterizerOrderedTexture3D< type > name : register(u ## slot); - #endif // _RESOURCEBUFFER_MAPPING_H_ diff --git a/WickedEngine/SamplerMapping.h b/WickedEngine/SamplerMapping.h index ab86ff5c2..99032a534 100644 --- a/WickedEngine/SamplerMapping.h +++ b/WickedEngine/SamplerMapping.h @@ -30,16 +30,4 @@ #define SSLOT_COUNT (SSLOT_COUNT_PERSISTENT + SSLOT_COUNT_ONDEMAND) -/////////////////////////// -// Helpers: -/////////////////////////// - -// Shader: -////////// - -// Automatically binds samplers on the shader side: -// Needs macro expansion -#define SAMPLERSTATE(name, slot) SamplerState name : register(s ## slot); -#define SAMPLERCOMPARISONSTATE(name, slot) SamplerComparisonState name : register(s ## slot); - #endif // _SAMPLER_MAPPING_H_ diff --git a/WickedEngine/ShaderInterop.h b/WickedEngine/ShaderInterop.h index b92525d14..fecd99b3d 100644 --- a/WickedEngine/ShaderInterop.h +++ b/WickedEngine/ShaderInterop.h @@ -1,6 +1,98 @@ #ifndef _WICKEDENGINE_SHADERINTEROP_H_ #define _WICKEDENGINE_SHADERINTEROP_H_ +#include "ConstantBufferMapping.h" +#include "SamplerMapping.h" +#include "ResourceMapping.h" + + +#ifdef __cplusplus + +// Application-side types: + +#define matrix XMMATRIX +#define float4x4 XMFLOAT4X4 +#define float2 XMFLOAT2 +#define float3 XMFLOAT3 +#define float4 XMFLOAT4 +#define uint uint32_t +#define uint2 XMUINT2 +#define uint3 XMUINT3 +#define uint4 XMUINT4 + +#define CB_GETBINDSLOT(name) __CBUFFERBINDSLOT__##name##__ +#define CBUFFER(name, slot) static const int CB_GETBINDSLOT(name) = slot; struct alignas(16) name + +#else + +// Shader - side types: + +#define CBUFFER(name, slot) cbuffer name : register(b ## slot) + +#define RAWBUFFER(name,slot) ByteAddressBuffer name : register(t ## slot) +#define RWRAWBUFFER(name,slot) RWByteAddressBuffer name : register(u ## slot) + +#define TYPEDBUFFER(name, type, slot) Buffer< type > name : register(t ## slot) +#define RWTYPEDBUFFER(name, type, slot) RWBuffer< type > name : register(u ## slot) + +#define STRUCTUREDBUFFER(name, type, slot) StructuredBuffer< type > name : register(t ## slot) +#define RWSTRUCTUREDBUFFER(name, type, slot) RWStructuredBuffer< type > name : register(u ## slot) +#define ROVSTRUCTUREDBUFFER(name, type, slot) RasterizerOrderedStructuredBuffer< type > name : register(u ## slot) + + +#define TEXTURE1D(name, type, slot) Texture1D< type > name : register(t ## slot); +#define TEXTURE1DARRAY(name, type, slot) Texture1DArray< type > name : register(t ## slot); +#define RWTEXTURE1D(name, type, slot) RWTexture1D< type > name : register(u ## slot); + +#define TEXTURE2D(name, type, slot) Texture2D< type > name : register(t ## slot); +#define TEXTURE2DMS(name, type, slot) Texture2DMS< type > name : register(t ## slot); +#define TEXTURE2DARRAY(name, type, slot) Texture2DArray< type > name : register(t ## slot); +#define RWTEXTURE2D(name, type, slot) RWTexture2D< type > name : register(u ## slot); +#define ROVTEXTURE2D(name, type, slot) RasterizerOrderedTexture2D< type > name : register(u ## slot); + +#define TEXTURECUBE(name, type, slot) TextureCube< type > name : register(t ## slot); +#define TEXTURECUBEARRAY(name, type, slot) TextureCubeArray< type > name : register(t ## slot); + +#define TEXTURE3D(name, type, slot) Texture3D< type > name : register(t ## slot); +#define RWTEXTURE3D(name, type, slot) RWTexture3D< type > name : register(u ## slot); +#define ROVTEXTURE3D(name, type, slot) RasterizerOrderedTexture3D< type > name : register(u ## slot); + + +#define SAMPLERSTATE(name, slot) SamplerState name : register(s ## slot); +#define SAMPLERCOMPARISONSTATE(name, slot) SamplerComparisonState name : register(s ## slot); + +#endif // __cplusplus + + + +struct LightArrayType +{ + float3 positionVS; // View Space! + float range; + // -- + float4 color; + // -- + float3 positionWS; + float energy; + // -- + float3 directionVS; + float shadowKernel; + // -- + float3 directionWS; + uint type; + // -- + float shadowBias; + int shadowMap_index; + float coneAngle; + float coneAngleCos; + // -- + float4 texMulAdd; + // -- + matrix shadowMatrix[3]; +}; + + + // Tiled rendering params: #define TILED_CULLING_BLOCKSIZE 16 #define MAX_LIGHTS 1024 diff --git a/WickedEngine/globals.hlsli b/WickedEngine/globals.hlsli index 63a7d9c30..f4d50c3eb 100644 --- a/WickedEngine/globals.hlsli +++ b/WickedEngine/globals.hlsli @@ -1,9 +1,6 @@ #ifndef _SHADER_GLOBALS_ #define _SHADER_GLOBALS_ #include "ShaderInterop.h" -#include "ConstantBufferMapping.h" -#include "SamplerMapping.h" -#include "ResourceMapping.h" TEXTURE2D(texture_depth, float, TEXSLOT_DEPTH) TEXTURE2D(texture_lineardepth, float, TEXSLOT_LINEARDEPTH) diff --git a/WickedEngine/lightCullingCS.hlsl b/WickedEngine/lightCullingCS.hlsl index 2e6368c3e..b165c263c 100644 --- a/WickedEngine/lightCullingCS.hlsl +++ b/WickedEngine/lightCullingCS.hlsl @@ -356,7 +356,7 @@ void main(ComputeShaderInput IN) // frustum AABB in world space transformed into the space of the probe/decal OBB: AABB b = GroupAABB_WS; - b.transform(light.shadowMat[0]); // shadowMat[0] : decal inverse box matrix! + b.transform(light.shadowMatrix[0]); // shadowMatrix[0] : decal inverse box matrix! if (IntersectAABB(a, b)) { diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli index 47ce7b2d8..f748e87b9 100644 --- a/WickedEngine/lightingHF.hlsli +++ b/WickedEngine/lightingHF.hlsli @@ -4,32 +4,6 @@ #include "brdf.hlsli" #include "voxelConeTracingHF.hlsli" -struct LightArrayType -{ - float3 positionVS; // View Space! - float range; - // -- - float4 color; - // -- - float3 positionWS; - float energy; - // -- - float3 directionVS; - float shadowKernel; - // -- - float3 directionWS; - uint type; - // -- - float shadowBias; - int shadowMap_index; - float coneAngle; - float coneAngleCos; - // -- - float4 texMulAdd; - // -- - float4x4 shadowMat[3]; -}; - TEXTURE2D(LightGrid, uint2, TEXSLOT_LIGHTGRID); STRUCTUREDBUFFER(LightIndexList, uint, SBSLOT_LIGHTINDEXLIST); STRUCTUREDBUFFER(LightArray, LightArrayType, SBSLOT_LIGHTARRAY); @@ -90,9 +64,9 @@ inline LightingResult DirectionalLight(in LightArrayType light, in float3 N, in { // calculate shadow map texcoords: float4 ShPos[3]; - ShPos[0] = mul(float4(P, 1), light.shadowMat[0]); - ShPos[1] = mul(float4(P, 1), light.shadowMat[1]); - ShPos[2] = mul(float4(P, 1), light.shadowMat[2]); + ShPos[0] = mul(float4(P, 1), light.shadowMatrix[0]); + ShPos[1] = mul(float4(P, 1), light.shadowMatrix[1]); + ShPos[2] = mul(float4(P, 1), light.shadowMatrix[2]); ShPos[0].xyz /= ShPos[0].w; ShPos[1].xyz /= ShPos[1].w; ShPos[2].xyz /= ShPos[2].w; @@ -212,7 +186,7 @@ inline LightingResult SpotLight(in LightArrayType light, in float3 N, in float3 [branch] if (light.shadowMap_index >= 0) { - float4 ShPos = mul(float4(P, 1), light.shadowMat[0]); + float4 ShPos = mul(float4(P, 1), light.shadowMatrix[0]); ShPos.xyz /= ShPos.w; float2 ShTex = ShPos.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f); [branch] diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index 7ef3f236f..32b098918 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -189,7 +189,7 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P { LightArrayType decal = LightArray[LightIndexList[startOffset + iterator]]; - float4x4 decalProjection = decal.shadowMat[0]; + float4x4 decalProjection = decal.shadowMatrix[0]; float3 clipSpace = mul(float4(P, 1), decalProjection).xyz; float3 uvw = clipSpace.xyz*float3(0.5f, -0.5f, 0.5f) + 0.5f; [branch] diff --git a/WickedEngine/objectPS_voxelizer.hlsl b/WickedEngine/objectPS_voxelizer.hlsl index ae655f420..1934f713b 100644 --- a/WickedEngine/objectPS_voxelizer.hlsl +++ b/WickedEngine/objectPS_voxelizer.hlsl @@ -41,7 +41,7 @@ void main(float4 pos : SV_POSITION, float3 N : NORMAL, float2 tex : TEXCOORD, fl [branch] if (light.shadowMap_index >= 0) { - float4 ShPos = mul(float4(P, 1), light.shadowMat[0]); + float4 ShPos = mul(float4(P, 1), light.shadowMatrix[0]); ShPos.xyz /= ShPos.w; float3 ShTex = ShPos.xyz*float3(1, -1, 1) / 2.0f + 0.5f; @@ -103,7 +103,7 @@ void main(float4 pos : SV_POSITION, float3 N : NORMAL, float2 tex : TEXCOORD, fl [branch] if (light.shadowMap_index >= 0) { - float4 ShPos = mul(float4(P, 1), light.shadowMat[0]); + float4 ShPos = mul(float4(P, 1), light.shadowMatrix[0]); ShPos.xyz /= ShPos.w; float2 ShTex = ShPos.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f); [branch] diff --git a/WickedEngine/wiEmittedParticle.h b/WickedEngine/wiEmittedParticle.h index aad0df391..326172b68 100644 --- a/WickedEngine/wiEmittedParticle.h +++ b/WickedEngine/wiEmittedParticle.h @@ -1,6 +1,6 @@ #pragma once #include "wiParticle.h" -#include "ConstantBufferMapping.h" +#include "ShaderInterop.h" #include "wiIntersectables.h" #include @@ -45,15 +45,11 @@ private: }; std::deque points; - GFX_STRUCT ConstantBuffer + CBUFFER(ConstantBuffer, CBSLOT_OTHER_EMITTEDPARTICLE) { XMFLOAT2 mAdd; float mMotionBlurAmount; float padding; - - CB_SETBINDSLOT(CBSLOT_OTHER_EMITTEDPARTICLE) - - ALIGN_16 }; wiGraphicsTypes::GPUBuffer *vertexBuffer; static wiGraphicsTypes::VertexLayout *vertexLayout; diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index b02ac2827..3e1757880 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -1,7 +1,7 @@ #pragma once #include "CommonInclude.h" #include "wiGraphicsAPI.h" -#include "ConstantBufferMapping.h" +#include "ShaderInterop.h" #include "wiColor.h" diff --git a/WickedEngine/wiHairParticle.h b/WickedEngine/wiHairParticle.h index c767faf7f..3e3d25966 100644 --- a/WickedEngine/wiHairParticle.h +++ b/WickedEngine/wiHairParticle.h @@ -19,7 +19,7 @@ public: UINT tangent; }; private: - GFX_STRUCT ConstantBuffer + CBUFFER(ConstantBuffer, CBSLOT_OTHER_HAIRPARTICLE) { XMMATRIX mWorld; XMFLOAT3 color; float __pad0; @@ -27,19 +27,13 @@ private: float LOD1; float LOD2; float __pad1; - - CB_SETBINDSLOT(CBSLOT_OTHER_HAIRPARTICLE) - - ALIGN_16 }; - GFX_STRUCT BitonicSortConstantBuffer + CBUFFER(BitonicSortConstantBuffer, 0) { UINT iLevel; UINT iLevelMask; UINT iWidth; UINT iHeight; - - ALIGN_16 }; static wiGraphicsTypes::VertexLayout *il; static wiGraphicsTypes::VertexShader *vs; diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index 7dd7d85da..a55918cb0 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -1,7 +1,7 @@ #pragma once #include "CommonInclude.h" #include "wiGraphicsAPI.h" -#include "ConstantBufferMapping.h" +#include "ShaderInterop.h" class wiImageEffects; enum BLENDMODE; @@ -11,7 +11,7 @@ class wiImage private: //static mutex MUTEX; protected: - GFX_STRUCT ImageCB + CBUFFER(ImageCB, CBSLOT_IMAGE_IMAGE) { XMMATRIX mTransform; XMFLOAT4 mTexMulAdd; @@ -28,19 +28,11 @@ protected: float pad0; float pad1; float pad2; - - CB_SETBINDSLOT(CBSLOT_IMAGE_IMAGE) - - ALIGN_16 }; - GFX_STRUCT PostProcessCB + CBUFFER(PostProcessCB, CBSLOT_IMAGE_POSTPROCESS) { float params0[4]; float params1[4]; - - CB_SETBINDSLOT(CBSLOT_IMAGE_POSTPROCESS) - - ALIGN_16 }; static wiGraphicsTypes::BlendState *blendState, *blendStateAdd, *blendStateNoBlend, *blendStateAvg, *blendStateDisable; diff --git a/WickedEngine/wiLensFlare.h b/WickedEngine/wiLensFlare.h index 22f3cfb12..eb757db04 100644 --- a/WickedEngine/wiLensFlare.h +++ b/WickedEngine/wiLensFlare.h @@ -2,7 +2,7 @@ #define LENSFLARE #include "CommonInclude.h" #include "wiGraphicsAPI.h" -#include "ConstantBufferMapping.h" +#include "ShaderInterop.h" class wiLensFlare { @@ -16,14 +16,10 @@ private: static wiGraphicsTypes::DepthStencilState *depthStencilState; static wiGraphicsTypes::BlendState *blendState; - GFX_STRUCT ConstantBuffer + CBUFFER(ConstantBuffer, CBSLOT_OTHER_LENSFLARE) { XMVECTOR mSunPos; XMFLOAT4 mScreen; - - CB_SETBINDSLOT(CBSLOT_OTHER_LENSFLARE) - - ALIGN_16 }; public: diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 31c03f56a..9146560bc 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -1595,7 +1595,7 @@ void Material::CreateImpostorMaterialCB() } } -void Material::MaterialCB::Create(const Material& mat) +void MaterialCB::Create(const Material& mat) { baseColor = XMFLOAT4(mat.baseColor.x, mat.baseColor.y, mat.baseColor.z, mat.alpha); texMulAdd = mat.texMulAdd; diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index 6900d3643..38e38839f 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -8,8 +8,6 @@ #include "wiFrustum.h" #include "wiTransform.h" #include "wiIntersectables.h" -#include "ConstantBufferMapping.h" -#include "ResourceMapping.h" #include "ShaderInterop.h" #include @@ -82,6 +80,23 @@ GFX_STRUCT InstancePrev ALIGN_16 }; +CBUFFER(MaterialCB, CBSLOT_RENDERER_MATERIAL) +{ + XMFLOAT4 baseColor; // + alpha (.w) + XMFLOAT4 texMulAdd; + float roughness; + float reflectance; + float metalness; + float emissive; + float refractionIndex; + float subsurfaceScattering; + float normalMapStrength; + float parallaxOcclusionMapping; + + MaterialCB() {}; + MaterialCB(const Material& mat) { Create(mat); }; + void Create(const Material& mat); +}; struct Material { std::string name; @@ -104,27 +119,6 @@ struct Material std::string specularMapName; wiGraphicsTypes::Texture2D* specularMap; - GFX_STRUCT MaterialCB - { - XMFLOAT4 baseColor; // + alpha (.w) - XMFLOAT4 texMulAdd; - float roughness; - float reflectance; - float metalness; - float emissive; - float refractionIndex; - float subsurfaceScattering; - float normalMapStrength; - float parallaxOcclusionMapping; - - CB_SETBINDSLOT(CBSLOT_RENDERER_MATERIAL) - - MaterialCB() {}; - MaterialCB(const Material& mat) { Create(mat); }; - void Create(const Material& mat); - - ALIGN_16 - }; MaterialCB gpuData; wiGraphicsTypes::GPUBuffer constantBuffer; static wiGraphicsTypes::GPUBuffer* constantBuffer_Impostor; @@ -729,8 +723,6 @@ public: pose2 = XMFLOAT4A(matIn._13, matIn._23, matIn._33, matIn._43); } - STRUCTUREDBUFFER_SETBINDSLOT(SKINNINGSLOT_IN_BONEBUFFER) - ALIGN_16 }; std::vector boneData; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index ec7620f44..63fde2fc6 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -1,5 +1,4 @@ #include "wiRenderer.h" -#include "ShaderInterop.h" #include "wiFrameRate.h" #include "wiHairParticle.h" #include "wiEmittedParticle.h" @@ -20,7 +19,6 @@ #include "wiEnums.h" #include "wiRandom.h" #include "wiFont.h" -#include "ResourceMapping.h" #include "wiGraphicsDevice_DX11.h" #include "wiTranslator.h" #include "wiRectPacker.h" @@ -1430,8 +1428,8 @@ void wiRenderer::BindPersistentState(GRAPHICSTHREAD threadID) GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); - GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTARRAY], STRUCTUREDBUFFER_GETBINDSLOT(LightArrayType), threadID); - GetDevice()->BindResourceCS(resourceBuffers[RBTYPE_LIGHTARRAY], STRUCTUREDBUFFER_GETBINDSLOT(LightArrayType), threadID); + GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTARRAY], SBSLOT_LIGHTARRAY, threadID); + GetDevice()->BindResourceCS(resourceBuffers[RBTYPE_LIGHTARRAY], SBSLOT_LIGHTARRAY, threadID); } Transform* wiRenderer::getTransformByName(const std::string& get) @@ -1839,13 +1837,13 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) for (Model* model : GetScene().models) { // Update material constant buffers: - Material::MaterialCB materialGPUData; + MaterialCB materialGPUData; for (auto& it : model->materials) { Material* material = it.second; materialGPUData.Create(*material); // These will probably not change every time so only issue a GPU memory update if it is necessary: - if (memcmp(&material->gpuData, &materialGPUData, sizeof(Material::MaterialCB)) != 0) + if (memcmp(&material->gpuData, &materialGPUData, sizeof(MaterialCB)) != 0) { material->gpuData = materialGPUData; GetDevice()->UpdateBuffer(&material->constantBuffer, &materialGPUData, threadID); @@ -1883,7 +1881,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) armature->boneData[k].Create(armature->boneCollection[k]->boneRelativity); } GetDevice()->UpdateBuffer(&armature->boneBuffer, armature->boneData.data(), threadID, (int)(sizeof(Armature::ShaderBoneType) * armature->boneCollection.size())); - GetDevice()->BindResourceCS(&armature->boneBuffer, STRUCTUREDBUFFER_GETBINDSLOT(Armature::ShaderBoneType), threadID); + GetDevice()->BindResourceCS(&armature->boneBuffer, SKINNINGSLOT_IN_BONEBUFFER, threadID); // Do the skinning const GPUResource* vbs[] = { @@ -1969,10 +1967,10 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) continue; } - lightArray[lightCounter].posWS = l->translation; - XMStoreFloat3(&lightArray[lightCounter].posVS, XMVector3TransformCoord(XMLoadFloat3(&lightArray[lightCounter].posWS), viewMatrix)); - lightArray[lightCounter].distance = l->enerDis.y; - lightArray[lightCounter].col = l->color; + lightArray[lightCounter].positionWS = l->translation; + XMStoreFloat3(&lightArray[lightCounter].positionVS, XMVector3TransformCoord(XMLoadFloat3(&lightArray[lightCounter].positionWS), viewMatrix)); + lightArray[lightCounter].range = l->enerDis.y; + lightArray[lightCounter].color = l->color; lightArray[lightCounter].energy = l->enerDis.x; lightArray[lightCounter].type = l->GetType(); lightArray[lightCounter].shadowBias = l->shadowBias; @@ -2014,7 +2012,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) XMMATRIX lightMat = XMLoadFloat4x4(&l->world); XMStoreFloat3(&lightArray[lightCounter].directionWS, XMVector3TransformNormal(XMVectorSet(-1, 0, 0, 0), lightMat)); // left dir XMStoreFloat3(&lightArray[lightCounter].directionVS, XMVector3TransformNormal(XMVectorSet(0, 1, 0, 0), lightMat)); // up dir - XMStoreFloat3(&lightArray[lightCounter].posVS, XMVector3TransformNormal(XMVectorSet(0, 0, -1, 0), lightMat)); // front dir + XMStoreFloat3(&lightArray[lightCounter].positionVS, XMVector3TransformNormal(XMVectorSet(0, 0, -1, 0), lightMat)); // front dir lightArray[lightCounter].texMulAdd = XMFLOAT4(l->radius, l->width, l->height, 0); } break; @@ -2030,12 +2028,12 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) lightCounter--; break; } - lightArray[lightCounter].posWS = decal->translation; - XMStoreFloat3(&lightArray[lightCounter].posVS, XMVector3TransformCoord(XMLoadFloat3(&decal->translation), viewMatrix)); - lightArray[lightCounter].distance = max(decal->scale.x, max(decal->scale.y, decal->scale.z)) * 2; + lightArray[lightCounter].positionWS = decal->translation; + XMStoreFloat3(&lightArray[lightCounter].positionVS, XMVector3TransformCoord(XMLoadFloat3(&decal->translation), viewMatrix)); + lightArray[lightCounter].range = max(decal->scale.x, max(decal->scale.y, decal->scale.z)) * 2; lightArray[lightCounter].shadowMatrix[0] = XMMatrixTranspose(XMMatrixInverse(nullptr, XMLoadFloat4x4(&decal->world))); lightArray[lightCounter].texMulAdd = decal->atlasMulAdd; - lightArray[lightCounter].col = XMFLOAT4(decal->color.x, decal->color.y, decal->color.z, decal->GetOpacity()); + lightArray[lightCounter].color = XMFLOAT4(decal->color.x, decal->color.y, decal->color.z, decal->GetOpacity()); lightArray[lightCounter].energy = decal->emissive; lightArray[lightCounter].type = 100; @@ -3967,7 +3965,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle { // Bind the static impostor params once: impostorRenderSetup = true; - device->BindConstantBufferPS(Material::constantBuffer_Impostor, CB_GETBINDSLOT(Material::MaterialCB), threadID); + device->BindConstantBufferPS(Material::constantBuffer_Impostor, CB_GETBINDSLOT(MaterialCB), threadID); device->BindPrimitiveTopology(TRIANGLELIST, threadID); device->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_FRONT], threadID); device->BindVertexLayout(vertexLayouts[realVL], threadID); @@ -4314,7 +4312,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle boundVBType_Prev = boundVBType; device->BindIndexBuffer(&subset.indexBuffer, subset.GetIndexFormat(), threadID); - device->BindConstantBufferPS(&material->constantBuffer, CB_GETBINDSLOT(Material::MaterialCB), threadID); + device->BindConstantBufferPS(&material->constantBuffer, CB_GETBINDSLOT(MaterialCB), threadID); UINT realStencilRef = material->GetStencilRef(); // todo: better @@ -6161,7 +6159,7 @@ void wiRenderer::CreateImpostor(Mesh* mesh) { GetDevice()->BindIndexBuffer(&subset.indexBuffer, subset.GetIndexFormat(), threadID); - GetDevice()->BindConstantBufferPS(&subset.material->constantBuffer, CB_GETBINDSLOT(Material::MaterialCB), threadID); + GetDevice()->BindConstantBufferPS(&subset.material->constantBuffer, CB_GETBINDSLOT(MaterialCB), threadID); GetDevice()->BindResourcePS(subset.material->GetBaseColorMap(), TEXSLOT_ONDEMAND0, threadID); GetDevice()->BindResourcePS(subset.material->GetNormalMap(), TEXSLOT_ONDEMAND1, threadID); diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 3c02ebefd..2fd43bc11 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -1,10 +1,8 @@ #pragma once #include "CommonInclude.h" +#include "ShaderInterop.h" #include "wiEnums.h" #include "wiGraphicsAPI.h" -#include "SamplerMapping.h" -#include "ConstantBufferMapping.h" -#include "ResourceMapping.h" #include "wiSPTree.h" #include "wiWindowRegistration.h" @@ -90,7 +88,7 @@ public: // Constant Buffers: // Persistent buffers: - GFX_STRUCT WorldCB + CBUFFER(WorldCB, CBSLOT_RENDERER_WORLD) { XMFLOAT2 mScreenWidthHeight; XMFLOAT2 mInternalResolution; @@ -106,12 +104,8 @@ public: float mVoxelRadianceDataFalloff; XMFLOAT3 mVoxelRadianceDataCenter; BOOL mAdvancedRefractions; - - CB_SETBINDSLOT(CBSLOT_RENDERER_WORLD) - - ALIGN_16 }; - GFX_STRUCT FrameCB + CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME) { float mTime; float mTimePrev; @@ -143,118 +137,57 @@ public: XMFLOAT3 mUp; float mZFarP; XMFLOAT4 mFrustumPlanesWS[6]; - - CB_SETBINDSLOT(CBSLOT_RENDERER_FRAME) - - ALIGN_16 }; - GFX_STRUCT CameraCB + CBUFFER(CameraCB, CBSLOT_RENDERER_CAMERA) { XMMATRIX mVP; XMMATRIX mView; XMMATRIX mProj; XMFLOAT3 mCamPos; float pad0; - - CB_SETBINDSLOT(CBSLOT_RENDERER_CAMERA) - - ALIGN_16 }; - GFX_STRUCT MiscCB + CBUFFER(MiscCB, CBSLOT_RENDERER_MISC) { XMMATRIX mTransform; XMFLOAT4 mColor; - - CB_SETBINDSLOT(CBSLOT_RENDERER_MISC) - - ALIGN_16 }; // On demand buffers: - GFX_STRUCT VolumeLightCB + CBUFFER(VolumeLightCB, CBSLOT_RENDERER_VOLUMELIGHT) { XMMATRIX world; XMFLOAT4 col; XMFLOAT4 enerdis; - - CB_SETBINDSLOT(CBSLOT_RENDERER_VOLUMELIGHT) - - ALIGN_16 }; - GFX_STRUCT DecalCB + CBUFFER(DecalCB, CBSLOT_RENDERER_DECAL) { XMMATRIX mDecalVP; int hasTexNor; XMFLOAT3 eye; float opacity; XMFLOAT3 front; - - CB_SETBINDSLOT(CBSLOT_RENDERER_DECAL) - - ALIGN_16 }; - GFX_STRUCT CubeMapRenderCB + CBUFFER(CubeMapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER) { XMMATRIX mViewProjection[6]; - - CB_SETBINDSLOT(CBSLOT_RENDERER_CUBEMAPRENDER) - - ALIGN_16 }; - GFX_STRUCT APICB + CBUFFER(APICB, CBSLOT_API) { XMFLOAT4 clipPlane; float alphaRef; float pad[3]; APICB(const XMFLOAT4& clipPlane = XMFLOAT4(0, 0, 0, 0), float alphaRef = 0.75f) :clipPlane(clipPlane), alphaRef(alphaRef) {} - - CB_SETBINDSLOT(CBSLOT_API) - - ALIGN_16 }; - GFX_STRUCT TessellationCB + CBUFFER(TessellationCB, CBSLOT_RENDERER_TESSELLATION) { XMFLOAT4 tessellationFactors; - - CB_SETBINDSLOT(CBSLOT_RENDERER_TESSELLATION) - - ALIGN_16 }; - GFX_STRUCT DispatchParamsCB + CBUFFER(DispatchParamsCB, CBSLOT_RENDERER_DISPATCHPARAMS) { UINT numThreadGroups[3]; UINT value0; UINT numThreads[3]; UINT value1; - - CB_SETBINDSLOT(CBSLOT_RENDERER_DISPATCHPARAMS) - - ALIGN_16 - }; - - // Resource Buffers: - - GFX_STRUCT LightArrayType - { - XMFLOAT3 posVS; - float distance; - XMFLOAT4 col; - XMFLOAT3 posWS; - float energy; - XMFLOAT3 directionVS; - float shadowKernel; - XMFLOAT3 directionWS; - UINT type; - float shadowBias; - int shadowMap_index; - float coneAngle; - float coneAngleCos; - XMFLOAT4 texMulAdd; - XMMATRIX shadowMatrix[3]; - - STRUCTUREDBUFFER_SETBINDSLOT(SBSLOT_LIGHTARRAY) - - ALIGN_16 }; protected: diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 985628954..b8ccf21fd 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 13; // minor bug fixes, alterations, refactors, updates - const int revision = 30; + const int revision = 31; long GetVersion()