mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-23 13:55:50 +12:00
tightly pack the pipeline hash
This commit is contained in:
parent
5d5df1931f
commit
559d194cc7
3 changed files with 19 additions and 15 deletions
|
@ -6,19 +6,21 @@ using namespace PICA;
|
|||
|
||||
namespace Metal {
|
||||
|
||||
struct DrawPipelineHash {
|
||||
struct DrawPipelineHash { // 62 bits
|
||||
// Formats
|
||||
ColorFmt colorFmt;
|
||||
DepthFmt depthFmt;
|
||||
ColorFmt colorFmt; // 3 bits
|
||||
DepthFmt depthFmt; // 3 bits
|
||||
|
||||
// Blending
|
||||
bool blendEnabled;
|
||||
u32 blendControl;
|
||||
bool blendEnabled; // 1 bit
|
||||
u32 blendControl; // 32 bits
|
||||
|
||||
// Specialization constants
|
||||
bool lightingEnabled;
|
||||
u8 lightingNumLights;
|
||||
u8 lightingConfig1;
|
||||
// Specialization constants (23 bits)
|
||||
bool lightingEnabled; // 1 bit
|
||||
u8 lightingNumLights; // 3 bits
|
||||
u8 lightingConfig1; // 7 bits
|
||||
// | ref | func | on |
|
||||
u16 alphaControl; // 12 bits (mask: 11111111 0111 0001)
|
||||
};
|
||||
|
||||
// Bind the vertex buffer to binding 30 so that it doesn't occupy the lower indices
|
||||
|
@ -43,8 +45,8 @@ public:
|
|||
}
|
||||
|
||||
MTL::RenderPipelineState* get(DrawPipelineHash hash) {
|
||||
u16 fragmentFunctionHash = ((u8)hash.lightingEnabled << 12) | (hash.lightingNumLights << 8) | hash.lightingConfig1;
|
||||
u64 pipelineHash = ((u64)hash.colorFmt << 52) | ((u64)hash.depthFmt << 49) | ((u64)hash.blendEnabled << 48) | ((u64)hash.blendControl << 16) | fragmentFunctionHash;
|
||||
u32 fragmentFunctionHash = ((u32)hash.lightingEnabled << 22) | ((u32)hash.lightingNumLights << 19) | ((u32)hash.lightingConfig1 << 12) | ((((u32)hash.alphaControl & 0b1111111100000000) >> 8) << 4) | ((((u32)hash.alphaControl & 0b01110000) >> 4) << 1) | ((u32)hash.alphaControl & 0b0001);
|
||||
u64 pipelineHash = ((u64)hash.colorFmt << 59) | ((u64)hash.depthFmt << 56) | ((u64)hash.blendEnabled << 55) | ((u64)hash.blendControl << 23) | fragmentFunctionHash;
|
||||
auto& pipeline = pipelineCache[pipelineHash];
|
||||
if (!pipeline) {
|
||||
auto& fragmentFunction = fragmentFunctionCache[fragmentFunctionHash];
|
||||
|
@ -53,6 +55,7 @@ public:
|
|||
constants->setConstantValue(&hash.lightingEnabled, MTL::DataTypeBool, NS::UInteger(0));
|
||||
constants->setConstantValue(&hash.lightingNumLights, MTL::DataTypeUChar, NS::UInteger(1));
|
||||
constants->setConstantValue(&hash.lightingConfig1, MTL::DataTypeUChar, NS::UInteger(2));
|
||||
constants->setConstantValue(&hash.alphaControl, MTL::DataTypeUShort, NS::UInteger(3));
|
||||
|
||||
NS::Error* error = nullptr;
|
||||
fragmentFunction = library->newFunction(NS::String::string("fragmentDraw", NS::ASCIIStringEncoding), constants, &error);
|
||||
|
@ -116,7 +119,7 @@ public:
|
|||
|
||||
private:
|
||||
std::unordered_map<u64, MTL::RenderPipelineState*> pipelineCache;
|
||||
std::unordered_map<u16, MTL::Function*> fragmentFunctionCache;
|
||||
std::unordered_map<u32, MTL::Function*> fragmentFunctionCache;
|
||||
|
||||
MTL::Device* device;
|
||||
MTL::Library* library;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue