Skip to content

Commit

Permalink
WIP switching to texture/sampler arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
PazerOP committed Jun 2, 2019
1 parent 09ac6ed commit fbdad88
Show file tree
Hide file tree
Showing 21 changed files with 759 additions and 740 deletions.
2 changes: 1 addition & 1 deletion sdk2013
34 changes: 33 additions & 1 deletion shaderapivulkan/include/TF2Vulkan/AlignedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ namespace TF2Vulkan{ namespace Shaders
};
template<typename T, size_t alignment> struct alignas(alignment) vector_storage<T, 3, alignment>
{
constexpr vector_storage() : x{}, y{}, z{}
{
// vec3s must be aligned to 16 bytes, but we can't use alignas because
// then MSVC makes the whole thing take 16 bytes rather than 12. We
// still need to be able to pack [float3, float1] into 16 bytes.
assert(uintptr_t(this) % (sizeof(T) * 4) == 0);
}
constexpr vector_storage(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {}

T x;
T y;
T z;
Expand All @@ -79,7 +88,7 @@ namespace TF2Vulkan{ namespace Shaders
using BaseType = detail::vector_storage<T, size, alignment>;

template<typename TArg, typename... TInit>
static constexpr BaseType InitBaseType(const TArg& arg1, const TInit&... args)
static constexpr BaseType InitBaseType(const TArg& arg1, const TInit& ... args)
{
constexpr bool BROADCAST = sizeof...(TInit) == 0 && size > 1;
constexpr bool DIRECT_INIT = (size - 1) == sizeof...(TInit);
Expand Down Expand Up @@ -467,6 +476,29 @@ inline auto operator-(const TLhs& lhs, const TF2Vulkan::Shaders::vector<TRhs, el
return retVal;
}

#ifndef __INTELLISENSE__
template<typename T>
inline auto operator<=>(const T& lhs, const TF2Vulkan::Shaders::vector<T, 1> & rhs)
{
return lhs <=> rhs.x;
}
template<typename T>
inline auto operator<=>(const TF2Vulkan::Shaders::vector<T, 1>& lhs, const T& rhs)
{
return lhs.x <=> rhs;
}
#endif
template<typename T>
inline auto operator!=(const T& lhs, const TF2Vulkan::Shaders::vector<T, 1> & rhs)
{
return lhs != rhs.x;
}
template<typename T>
inline auto operator!=(const TF2Vulkan::Shaders::vector<T, 1> & lhs, const T& rhs)
{
return lhs.x != rhs;
}

namespace TF2Vulkan{ namespace Shaders{ namespace detail
{
template<typename TLhs, typename TRhs, size_t elements, typename TFunc>
Expand Down
3 changes: 3 additions & 0 deletions shaderapivulkan/include/TF2Vulkan/ISpecConstLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace TF2Vulkan
{
Bool,
Int,
UInt,
Float,
};

Expand All @@ -22,6 +23,8 @@ namespace TF2Vulkan
return SpecConstType::Bool;
else if constexpr (std::is_same_v<T, Shaders::int1>)
return SpecConstType::Int;
else if constexpr (std::is_same_v<T, Shaders::uint1>)
return SpecConstType::UInt;
else if constexpr (std::is_same_v<T, Shaders::float1>)
return SpecConstType::Float;
else
Expand Down
41 changes: 41 additions & 0 deletions shaderapivulkan/include/TF2Vulkan/ShaderTextureBinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include "AlignedTypes.h"
#include "TF2Vulkan/Util/InPlaceVector.h"

namespace TF2Vulkan
{
static constexpr size_t MAX_SHADER_TEXTURE_BINDINGS = 32;
class ShaderTextureBinder final
{
public:
void AddBinding(ITexture* tex, uint32_t& locationSpecConst)
{
assert(tex);

for (uint32_t i = 0; i < m_Bindings.size(); i++)
{
auto& existing = m_Bindings[i];
if (existing.m_Texture == tex)
{
locationSpecConst = i;
return;
}
}

auto& newBinding = m_Bindings.emplace_back();
newBinding.m_Texture = tex;
locationSpecConst = m_Bindings.size() - 1;
}

auto begin() const { return m_Bindings.begin(); }
auto end() const { return m_Bindings.end(); }

private:
struct Binding
{
ITexture* m_Texture = nullptr;
};
Util::InPlaceVector<Binding, MAX_SHADER_TEXTURE_BINDINGS> m_Bindings;
};
}
2 changes: 2 additions & 0 deletions shaderapivulkan/shaderapivulkan.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<ClInclude Include="include\TF2Vulkan\IShaderShadowNext.h" />
<ClInclude Include="include\TF2Vulkan\ISpecConstLayout.h" />
<ClInclude Include="include\TF2Vulkan\IBufferPool.h" />
<ClInclude Include="include\TF2Vulkan\ShaderTextureBinder.h" />
<ClInclude Include="include\TF2Vulkan\TextureSubrect.h" />
<ClInclude Include="src\interface\IMaterialInternal.h" />
<ClInclude Include="src\interface\internal\IDebugTextureInfoInternal.h" />
Expand All @@ -112,6 +113,7 @@
<ClInclude Include="src\interface\internal\IStateManagerDynamic.h" />
<ClInclude Include="src\interface\internal\IBufferPoolInternal.h" />
<ClInclude Include="src\interface\internal\IVBAllocTrackerInternal.h" />
<ClInclude Include="src\interface\ITextureInternal.h" />
<ClInclude Include="src\TF2Vulkan\BufferPool.h" />
<ClInclude Include="src\TF2Vulkan\Exceptions.h" />
<ClInclude Include="src\TF2Vulkan\FormatConverter.h" />
Expand Down
11 changes: 11 additions & 0 deletions shaderapivulkan/src/interface/ITextureInternal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <materialsystem/itexture.h>

class ITextureInternal : public ITexture
{
private:
virtual void EXPAND_CONCAT(DummyFunc, __COUNTER__)() const final { NOT_IMPLEMENTED_FUNC(); }
public:
virtual ShaderAPITextureHandle_t GetTextureHandle(int frame, int something = 0) = 0;
};
12 changes: 6 additions & 6 deletions stdshader_vulkan/src/shaders/BaseShaderNext.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,24 @@ namespace TF2Vulkan{ namespace Shaders
bool IsRegistered() { return m_Instance.GetNumParams(); }
};

template<typename T, typename TParams = ShaderParams<>, ShaderFlags_t FLAGS = ShaderFlags_t(0)>
class ShaderNext : public TParams, public BaseShaderNext
template<typename T, typename TComponents = ShaderComponents<>, ShaderFlags_t FLAGS = ShaderFlags_t(0)>
class ShaderNext : public TComponents, public BaseShaderNext
{
protected:
static_assert(is_shader_params_v<TParams>);
static_assert(is_shader_components_v<TComponents>);

using BaseClass = BaseShaderNext;
using Params = TParams;
using Components = TComponents;

public:
ShaderNext() : BaseShaderNext(TParams::ParamsBase(), TParams::ParamsCount)
ShaderNext() : BaseShaderNext(TComponents::ParamsBase(), TComponents::PARAMS_COUNT)
{
}

void InitShaderParams(IMaterialVar** ppParams, const char* pMaterialName) override
{
BaseClass::InitShaderParams(ppParams, pMaterialName);
TParams::InitParamGroups(ppParams);
TComponents::InitParamGroups(ppParams);
}

using InstanceRegister = DefaultInstanceRegister<T>;
Expand Down
23 changes: 11 additions & 12 deletions stdshader_vulkan/src/shaders/HLSL/makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# DirectXShaderCompiler
# SHADER_COMPILER:=dxc.exe
# COMPILER_ARGS:=-spirv -E main -WX -fspv-debug=line -fspv-reflect -No -fvk-s-shift 100 0 -fvk-t-shift 200 0
# COMPILER_ARGS_VERT:=-T vs_6_0 -fvk-invert-y
# COMPILER_ARGS_FRAG:=-T ps_6_0
# COMPILER_ARGS_TARGET:=-Fo

SHADER_COMPILER:=dxc_git.exe
COMPILER_ARGS:=-spirv -E main -WX -fspv-debug=line -fspv-reflect -No -fvk-s-shift 100 0 -fvk-t-shift 200 0
COMPILER_ARGS_VERT:=-T vs_6_0 -fvk-invert-y
COMPILER_ARGS_FRAG:=-T ps_6_0
COMPILER_ARGS_TARGET:=-Fo

# glslc
# SHADER_COMPILER:=glslc.exe
Expand All @@ -14,11 +13,11 @@
# COMPILER_ARGS_TARGET:= -o

# glslangValidator
SHADER_COMPILER:=glslangValidator.exe
COMPILER_ARGS:= -fhlsl_functionality1 --shift-sampler-binding 100 --shift-texture-binding 200 --invert-y -V -e main
COMPILER_ARGS_VERT:=
COMPILER_ARGS_FRAG:=
COMPILER_ARGS_TARGET:= -o
# SHADER_COMPILER:=glslangValidator.exe
# COMPILER_ARGS:= -fhlsl_functionality1 --shift-sampler-binding 100 --shift-texture-binding 200 --invert-y -V -e main
# COMPILER_ARGS_VERT:=
# COMPILER_ARGS_FRAG:=
# COMPILER_ARGS_TARGET:= -o

SPIRV_VAL:=spirv-val.exe
SPIRV_DIS:=spirv-dis.exe
Expand Down Expand Up @@ -50,4 +49,4 @@ $(TARGET_DIR)%.spirv_dis : $(TARGET_DIR)%.spirv
$(SPIRV_DIS) -o $@ $<

$(TARGET_DIR)%.spirv_val : $(TARGET_DIR)%.spirv
$(SPIRV_VAL) $< && touch $@
$(SPIRV_VAL) $< && touch $@
4 changes: 2 additions & 2 deletions stdshader_vulkan/src/shaders/LightmappedGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ inline namespace SHADER_NAME
{
};

using Params = ShaderParams<>;// /*CustomParamGroup, */DetailParams, SelfillumParams, BumpmapParams, SeamlessScaleParams>;
using Components = ShaderComponents<>;// /*CustomParamGroup, */DetailParams, SelfillumParams, BumpmapParams, SeamlessScaleParams>;

class Shader final : public ShaderNext<Shader, Params>
class Shader final : public ShaderNext<Shader>
{
public:
const char* GetName() const override { return V_STRINGIFY(SHADER_NAME); }
Expand Down
Loading

0 comments on commit fbdad88

Please sign in to comment.