diff options
| author | NeoBrainX <NeoBrainX@gmail.com> | 2013-06-22 21:24:21 +0200 |
|---|---|---|
| committer | NeoBrainX <NeoBrainX@gmail.com> | 2013-06-22 21:47:22 +0200 |
| commit | bdc28106eed06af0d9c0da4c8ee9672a59a7bf7e (patch) | |
| tree | 0df1ad6e9d9cadb8d9e25a0f688bde47829821ef /Source/Core/VideoCommon | |
| parent | 16ada5fa3d0d21171c00060d08433f3a53d2a55c (diff) | |
Optimize shader uid checks by checking the number of uid values which are actually used.
Diffstat (limited to 'Source/Core/VideoCommon')
| -rw-r--r-- | Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 5 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/PixelShaderGen.h | 55 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/ShaderGenCommon.h | 4 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/VertexShaderGen.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Src/VertexShaderGen.h | 3 |
5 files changed, 42 insertions, 27 deletions
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index dce8bfbe96..dd284ced7d 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -535,6 +535,11 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api for (unsigned int i = 0; i < numStages; i++) WriteStage<T>(out, uid_data, i, ApiType, RegisterStates); // build the equation for this stage +#define MY_STRUCT_OFFSET(str,elem) ((u32)((u64)&(str).elem-(u64)&(str))) + bool enable_pl = g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting; + uid_data.num_values = (enable_pl) ? sizeof(uid_data)/sizeof(32) : MY_STRUCT_OFFSET(uid_data,stagehash[numStages])/sizeof(u32); + + if (numStages) { // The results of the last texenv stage are put onto the screen, diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 01b0ad3489..210dd9dd32 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -61,6 +61,9 @@ struct pixel_shader_uid_data { // TODO: Optimize field order for easy access! + u32 num_values; // TODO: Shouldn't be a u32 + u32 NumValues() const { return num_values; } // TODO: Can be optimized :) + u32 components; u32 dstAlphaMode : 2; u32 Pretest : 2; @@ -96,6 +99,23 @@ struct pixel_shader_uid_data else if (index == 3) { tevindref_bi4 = texmap; } } + u32 alpha_test_comp0 : 3; + u32 alpha_test_comp1 : 3; + u32 alpha_test_logic : 2; + + u32 alpha_test_use_zcomploc_hack : 1; + + u32 fog_proj : 1; + u32 fog_fsel : 3; + u32 fog_RangeBaseEnabled : 1; + + u32 ztex_op : 2; + + u32 fast_depth_calc : 1; + u32 per_pixel_depth : 1; + + u32 xfregs_numTexGen_numTexGens : 4; + struct { u32 cc : 24; u32 ac : 24; @@ -106,41 +126,24 @@ struct pixel_shader_uid_data u32 tevorders_colorchan : 3; u32 pad1 : 6; + // TODO: Clean up the swapXY mess u32 hasindstage : 1; u32 tevind : 21; - u32 tevksel_swap1a : 2; // TODO: Doesn't fit here.. - u32 tevksel_swap2a : 2; // TODO: Doesn't fit here.. - u32 tevksel_swap1b : 2; // TODO: Doesn't fit here.. - u32 tevksel_swap2b : 2; // TODO: Doesn't fit here.. + u32 tevksel_swap1a : 2; + u32 tevksel_swap2a : 2; + u32 tevksel_swap1b : 2; + u32 tevksel_swap2b : 2; u32 pad2 : 2; - u32 tevksel_swap1c : 2; // TODO: Doesn't fit here.. - u32 tevksel_swap2c : 2; // TODO: Doesn't fit here.. - u32 tevksel_swap1d : 2; // TODO: Doesn't fit here.. - u32 tevksel_swap2d : 2; // TODO: Doesn't fit here.. + u32 tevksel_swap1c : 2; + u32 tevksel_swap2c : 2; + u32 tevksel_swap1d : 2; + u32 tevksel_swap2d : 2; u32 tevksel_kc : 5; u32 tevksel_ka : 5; u32 pad3 : 14; } stagehash[16]; - - u32 alpha_test_comp0 : 3; - u32 alpha_test_comp1 : 3; - u32 alpha_test_logic : 2; - - u32 alpha_test_use_zcomploc_hack : 1; - - u32 fog_proj : 1; - u32 fog_fsel : 3; - u32 fog_RangeBaseEnabled : 1; - - u32 ztex_op : 2; - - u32 fast_depth_calc : 1; - u32 per_pixel_depth : 1; - - u32 xfregs_numTexGen_numTexGens : 4; - // TODO: I think we're fine without an enablePixelLighting field, should probably double check, though.. LightingUidData lighting; }; diff --git a/Source/Core/VideoCommon/Src/ShaderGenCommon.h b/Source/Core/VideoCommon/Src/ShaderGenCommon.h index b8820e2e98..53f2405f8a 100644 --- a/Source/Core/VideoCommon/Src/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/Src/ShaderGenCommon.h @@ -100,7 +100,7 @@ public: bool operator < (const ShaderUid& obj) const { // TODO: Store last frame used and order by that? makes much more sense anyway... - for (unsigned int i = 0; i < sizeof(uid_data) / sizeof(u32); ++i) + for (unsigned int i = 0; i < data.NumValues(); ++i) { if (this->values[i] < obj.values[i]) return true; @@ -212,6 +212,8 @@ struct LightingUidData u32 diffusefunc : 8; // 4x2 bits u32 attnfunc : 8; // 4x2 bits u32 light_mask : 32; // 4x8 bits + + u32 NumValues() const { return sizeof(LightingUidData) / sizeof(u32); } }; #pragma pack() diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 3edb51c505..8c157dc030 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -74,6 +74,8 @@ static void GenerateVertexShader(T& out, u32 components, API_TYPE api_type) vertex_shader_uid_data& uid_data = (&out.template GetUidData<vertex_shader_uid_data>() != NULL) ? out.template GetUidData<vertex_shader_uid_data>() : dummy_data; + uid_data.num_values = sizeof(uid_data)/sizeof(u32); + out.SetBuffer(text); #ifndef ANDROID locale_t locale; diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index eb7236678a..3f3087783d 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -67,6 +67,9 @@ const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 }, struct vertex_shader_uid_data { + u32 num_values; // TODO: Shouldn't be a u32 + + u32 NumValues() const { return num_values; } u32 components; u32 numColorChans : 2; u32 numTexGens : 4; |
