| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <array> |
| 7 |
#include <span> |
| 8 |
#include <string> |
| 9 |
|
| 10 |
#include "Common/CommonTypes.h" |
| 11 |
#include "Common/Matrix.h" |
| 12 |
#include "VideoCommon/ConstantManager.h" |
| 13 |
#include "VideoCommon/NativeVertexFormat.h" |
| 14 |
|
| 15 |
class PointerWrap; |
| 16 |
struct PortableVertexDeclaration; |
| 17 |
class XFStateManager; |
| 18 |
|
| 19 |
|
| 20 |
class alignas(16) VertexShaderManager |
| 21 |
{ |
| 22 |
public: |
| 23 |
void Init(); |
| 24 |
void DoState(PointerWrap& p); |
| 25 |
|
| 26 |
|
| 27 |
void SetProjectionMatrix(XFStateManager& xf_state_manager); |
| 28 |
void SetConstants(std::span<const std::string> textures, XFStateManager& xf_state_manager); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
void TransformToClipSpace(const float* data, float* out, u32 mtxIdx); |
| 35 |
|
| 36 |
static bool UseVertexDepthRange(); |
| 37 |
|
| 38 |
VertexShaderConstants constants{}; |
| 39 |
bool dirty = false; |
| 40 |
|
| 41 |
static DOLPHIN_FORCE_INLINE void UpdateValue(bool* dirty, u32* old_value, u32 new_value) |
| 42 |
{ |
| 43 |
if (*old_value == new_value) |
| 44 |
return; |
| 45 |
*old_value = new_value; |
| 46 |
*dirty = true; |
| 47 |
} |
| 48 |
|
| 49 |
static DOLPHIN_FORCE_INLINE void UpdateOffset(bool* dirty, bool include_components, |
| 50 |
u32* old_value, const AttributeFormat& attribute) |
| 51 |
{ |
| 52 |
if (!attribute.enable) |
| 53 |
return; |
| 54 |
u32 new_value = attribute.offset / 4; |
| 55 |
if (include_components) |
| 56 |
new_value |= attribute.components << 16; |
| 57 |
UpdateValue(dirty, old_value, new_value); |
| 58 |
} |
| 59 |
|
| 60 |
template <size_t N> |
| 61 |
static DOLPHIN_FORCE_INLINE void UpdateOffsets(bool* dirty, bool include_components, |
| 62 |
std::array<u32, N>* old_value, |
| 63 |
const std::array<AttributeFormat, N>& attribute) |
| 64 |
{ |
| 65 |
for (size_t i = 0; i < N; i++) |
| 66 |
UpdateOffset(dirty, include_components, &(*old_value)[i], attribute[i]); |
| 67 |
} |
| 68 |
|
| 69 |
DOLPHIN_FORCE_INLINE void SetVertexFormat(u32 components, const PortableVertexDeclaration& format) |
| 70 |
{ |
| 71 |
UpdateValue(&dirty, &constants.components, components); |
| 72 |
UpdateValue(&dirty, &constants.vertex_stride, format.stride / 4); |
| 73 |
UpdateOffset(&dirty, true, &constants.vertex_offset_position, format.position); |
| 74 |
UpdateOffset(&dirty, false, &constants.vertex_offset_posmtx, format.posmtx); |
| 75 |
UpdateOffsets(&dirty, true, &constants.vertex_offset_texcoords, format.texcoords); |
| 76 |
UpdateOffsets(&dirty, false, &constants.vertex_offset_colors, format.colors); |
| 77 |
UpdateOffsets(&dirty, false, &constants.vertex_offset_normals, format.normals); |
| 78 |
} |
| 79 |
|
| 80 |
private: |
| 81 |
alignas(16) std::array<float, 16> m_projection_matrix; |
| 82 |
|
| 83 |
|
| 84 |
bool m_projection_graphics_mod_change = false; |
| 85 |
|
| 86 |
Common::Matrix44 LoadProjectionMatrix(); |
| 87 |
}; |