void WrappedOpenGL::glLinkProgram(GLuint program) { m_Real.glLinkProgram(program); if(m_State >= WRITING) { GLResourceRecord *record = GetResourceManager()->GetResourceRecord(ProgramRes(GetCtx(), program)); RDCASSERT(record); { SCOPED_SERIALISE_CONTEXT(LINKPROGRAM); Serialise_glLinkProgram(program); record->AddChunk(scope.Get()); } } else { ResourceId progid = GetResourceManager()->GetID(ProgramRes(GetCtx(), program)); ProgramData &progDetails = m_Programs[progid]; progDetails.linked = true; for(size_t s = 0; s < 6; s++) { for(size_t sh = 0; sh < progDetails.shaders.size(); sh++) { if(m_Shaders[progDetails.shaders[sh]].type == ShaderEnum(s)) progDetails.stageShaders[s] = progDetails.shaders[sh]; } } } }
bool WrappedOpenGL::Serialise_glLinkProgram(GLuint program) { SERIALISE_ELEMENT(ResourceId, id, GetResourceManager()->GetID(ProgramRes(GetCtx(), program))); if(m_State == READING) { ResourceId progid = GetResourceManager()->GetLiveID(id); ProgramData &progDetails = m_Programs[progid]; progDetails.linked = true; for(size_t s = 0; s < 6; s++) { for(size_t sh = 0; sh < progDetails.shaders.size(); sh++) { if(m_Shaders[progDetails.shaders[sh]].type == ShaderEnum(s)) progDetails.stageShaders[s] = progDetails.shaders[sh]; } } m_Real.glLinkProgram(GetResourceManager()->GetLiveResource(id).name); } return true; }
bool WrappedOpenGL::Serialise_glUseProgramStages(GLuint pipeline, GLbitfield stages, GLuint program) { SERIALISE_ELEMENT(ResourceId, pipe, GetResourceManager()->GetID(ProgramPipeRes(GetCtx(), pipeline))); SERIALISE_ELEMENT(uint32_t, Stages, stages); SERIALISE_ELEMENT(ResourceId, prog, (program ? GetResourceManager()->GetID(ProgramRes(GetCtx(), program)) : ResourceId())); if(m_State < WRITING) { if(prog != ResourceId()) { ResourceId livePipeId = GetResourceManager()->GetLiveID(pipe); ResourceId liveProgId = GetResourceManager()->GetLiveID(prog); PipelineData &pipeDetails = m_Pipelines[livePipeId]; ProgramData &progDetails = m_Programs[liveProgId]; for(size_t s=0; s < 6; s++) { if(Stages & ShaderBit(s)) { for(size_t sh=0; sh < progDetails.shaders.size(); sh++) { if(m_Shaders[ progDetails.shaders[sh] ].type == ShaderEnum(s)) { pipeDetails.stagePrograms[s] = liveProgId; pipeDetails.stageShaders[s] = progDetails.shaders[sh]; break; } } } } m_Real.glUseProgramStages(GetResourceManager()->GetLiveResource(pipe).name, Stages, GetResourceManager()->GetLiveResource(prog).name); } else { ResourceId livePipeId = GetResourceManager()->GetLiveID(pipe); PipelineData &pipeDetails = m_Pipelines[livePipeId]; for(size_t s=0; s < 6; s++) { if(Stages & ShaderBit(s)) { pipeDetails.stagePrograms[s] = ResourceId(); pipeDetails.stageShaders[s] = ResourceId(); } } m_Real.glUseProgramStages(GetResourceManager()->GetLiveResource(pipe).name, Stages, 0); } } return true; }
void WrappedOpenGL::glUseProgramStages(GLuint pipeline, GLbitfield stages, GLuint program) { m_Real.glUseProgramStages(pipeline, stages, program); if(m_State > WRITING) { SCOPED_SERIALISE_CONTEXT(USE_PROGRAMSTAGES); Serialise_glUseProgramStages(pipeline, stages, program); GLResourceRecord *record = GetResourceManager()->GetResourceRecord(ProgramPipeRes(GetCtx(), pipeline)); RDCASSERT(record); Chunk *chunk = scope.Get(); if(m_State == WRITING_CAPFRAME) { m_ContextRecord->AddChunk(chunk); } else { // USE_PROGRAMSTAGES is one of the few kinds of chunk that are // recorded to pipeline records, so we can probably find previous // uses (if it's been constantly rebound instead of once at init // time) that can be popped as redundant. // We do have to be careful though to make sure we only remove // redundant calls, not other different USE_PROGRAMSTAGES calls! struct FilterChunkClass { FilterChunkClass(uint32_t s) : stages(s) {} uint32_t stages; // this is kind of a hack, but it would be really awkward // to make a general solution just for this one case, and // we also can't really afford to drop it entirely. // we search for the marker serialised above, skip over the // pipeline id (as it will be the same in all chunks in this // record), and check if the Stages bitfield afterwards is // the same - if so we remove that chunk as replaced by // this one bool operator()(Chunk *c) const { if(c->GetChunkType() != USE_PROGRAMSTAGES) return false; byte *b = c->GetData(); byte *end = b + c->GetLength(); // 'fast' path, rather than searching byte-by-byte from // the start to be safe, check the exact difference it should // always be first. if(*(uint64_t *)(b + 6) == marker_glUseProgramStages_hack) b += 6; while(b + sizeof(uint64_t) < end) { uint64_t *marker = (uint64_t *)b; if(*marker == marker_glUseProgramStages_hack) { // increment to point to pipeline id marker++; // increment to point to stages field marker++; // now compare uint32_t *chunkStages = (uint32_t *)marker; if(*chunkStages == stages) return true; return false; } b++; } RDCERR( "Didn't find marker value! This should not happen, check " "Serialise_glUseProgramStages serialisation"); return false; } }; record->FilterChunks(FilterChunkClass(stages)); record->AddChunk(chunk); } if(program) { GLResourceRecord *progrecord = GetResourceManager()->GetResourceRecord(ProgramRes(GetCtx(), program)); RDCASSERT(progrecord); record->AddParent(progrecord); } } else { if(program) { ResourceId pipeID = GetResourceManager()->GetID(ProgramPipeRes(GetCtx(), pipeline)); ResourceId progID = GetResourceManager()->GetID(ProgramRes(GetCtx(), program)); PipelineData &pipeDetails = m_Pipelines[pipeID]; ProgramData &progDetails = m_Programs[progID]; for(size_t s = 0; s < 6; s++) { if(stages & ShaderBit(s)) { for(size_t sh = 0; sh < progDetails.shaders.size(); sh++) { if(m_Shaders[progDetails.shaders[sh]].type == ShaderEnum(s)) { pipeDetails.stagePrograms[s] = progID; pipeDetails.stageShaders[s] = progDetails.shaders[sh]; break; } } } } } else { ResourceId pipeID = GetResourceManager()->GetID(ProgramPipeRes(GetCtx(), pipeline)); PipelineData &pipeDetails = m_Pipelines[pipeID]; for(size_t s = 0; s < 6; s++) { if(stages & ShaderBit(s)) { pipeDetails.stagePrograms[s] = ResourceId(); pipeDetails.stageShaders[s] = ResourceId(); } } } } }