mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Fix] (Diligent/PSO): Build InputLayout for PSO.
This commit is contained in:
@@ -26,6 +26,61 @@ namespace MG_Diligent {
|
||||
bool IsInRenderPass = false;
|
||||
bool initialized = false;
|
||||
|
||||
void BuildInputLayout(GLuint program, VertexArrayState& vaState,
|
||||
std::vector<Diligent::LayoutElement>& inputLayout) {
|
||||
inputLayout.clear();
|
||||
|
||||
auto& programObj = MG_State_T::programState->programs_[program];
|
||||
|
||||
for (const auto& [attribIndex, attrib] : vaState.vaos_[vaState.currentVao_].attribs) {
|
||||
if (!attrib.enabled) continue;
|
||||
|
||||
std::string attribName;
|
||||
for (auto [name, loc] : programObj.attribLocations) {
|
||||
if (loc == attribIndex) {
|
||||
attribName = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MG_State::QueryProgramAttributeLocation(program, attribName.c_str());
|
||||
if (attribIndex == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Diligent::LayoutElement element;
|
||||
element.InputIndex = static_cast<Diligent::Uint32>(attribIndex);
|
||||
element.BufferSlot = 0;
|
||||
element.NumComponents = attrib.size;
|
||||
|
||||
switch (attrib.type) {
|
||||
case GL_BYTE: element.ValueType = Diligent::VT_INT8; break;
|
||||
case GL_UNSIGNED_BYTE: element.ValueType = Diligent::VT_UINT8; break;
|
||||
case GL_SHORT: element.ValueType = Diligent::VT_INT16; break;
|
||||
case GL_UNSIGNED_SHORT: element.ValueType = Diligent::VT_UINT16; break;
|
||||
case GL_INT: element.ValueType = Diligent::VT_INT32; break;
|
||||
case GL_UNSIGNED_INT: element.ValueType = Diligent::VT_UINT32; break;
|
||||
case GL_FLOAT: element.ValueType = Diligent::VT_FLOAT32; break;
|
||||
case GL_HALF_FLOAT: element.ValueType = Diligent::VT_FLOAT16; break;
|
||||
case GL_DOUBLE: element.ValueType = Diligent::VT_FLOAT64; break;
|
||||
default: element.ValueType = Diligent::VT_UNDEFINED; break;
|
||||
}
|
||||
|
||||
element.IsNormalized = attrib.normalized;
|
||||
element.RelativeOffset = static_cast<Diligent::Uint32>(reinterpret_cast<size_t>(attrib.pointer));
|
||||
|
||||
inputLayout.push_back(element);
|
||||
|
||||
MG_Util::Debug::LogD("Built LayoutElement for attrib '%s' (location %d): "
|
||||
"NumComponents=%d, ValueType=%d, IsNormalized=%s, RelativeOffset=%u",
|
||||
attribName.c_str(), attribIndex,
|
||||
element.NumComponents, element.ValueType,
|
||||
element.IsNormalized ? "true" : "false",
|
||||
element.RelativeOffset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PipelineStateManager::ConfigurePSO(
|
||||
Diligent::GraphicsPipelineStateCreateInfo &PSOCreateInfo,
|
||||
GLProgramInfo &programInfo,
|
||||
@@ -101,6 +156,20 @@ namespace MG_Diligent {
|
||||
Diligent::CULL_MODE_BACK : Diligent::CULL_MODE_NONE;
|
||||
rasterizerDesc.FrontCounterClockwise = true;
|
||||
|
||||
if (!programInfo.inputLayout.empty()) {
|
||||
PSOCreateInfo.GraphicsPipeline.InputLayout.LayoutElements = programInfo.inputLayout.data();
|
||||
PSOCreateInfo.GraphicsPipeline.InputLayout.NumElements =
|
||||
static_cast<Diligent::Uint32>(programInfo.inputLayout.size());
|
||||
|
||||
MG_Util::Debug::LogD("Configured InputLayout with %zu elements",
|
||||
programInfo.inputLayout.size());
|
||||
} else {
|
||||
MG_Util::Debug::LogW("No input layout elements for PSO");
|
||||
PSOCreateInfo.GraphicsPipeline.InputLayout.LayoutElements = nullptr;
|
||||
PSOCreateInfo.GraphicsPipeline.InputLayout.NumElements = 0;
|
||||
}
|
||||
|
||||
|
||||
ConfigureResourceLayout(PSOCreateInfo, programInfo);
|
||||
}
|
||||
|
||||
@@ -142,6 +211,8 @@ namespace MG_Diligent {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
MG_Diligent::BuildInputLayout(program, vaState, programInfo.inputLayout);
|
||||
|
||||
Diligent::GraphicsPipelineStateCreateInfo PSOCreateInfo;
|
||||
ConfigurePSO(PSOCreateInfo, programInfo, commonState, vaState, fbInfo);
|
||||
|
||||
|
||||
@@ -244,6 +244,9 @@ namespace MG_Diligent {
|
||||
|
||||
extern PipelineStateManager g_PSOManager;
|
||||
|
||||
void BuildInputLayout(GLuint program, VertexArrayState& vaState,
|
||||
std::vector<Diligent::LayoutElement>& inputLayout);
|
||||
|
||||
extern bool initialized;
|
||||
extern bool IsInRenderPass;
|
||||
}
|
||||
|
||||
@@ -455,14 +455,12 @@ namespace MG_GL::GL {
|
||||
|
||||
if (!pBuffer) {
|
||||
Diligent::BufferDesc BuffDesc;
|
||||
BuffDesc.Name = "Buffer";
|
||||
std::string bufferName = "Dynamic VBO " + std::to_string(buffer);
|
||||
BuffDesc.Name = bufferName.c_str();
|
||||
BuffDesc.Size = bufferObj.data.size();
|
||||
BuffDesc.Usage = Diligent::USAGE_DYNAMIC;
|
||||
BuffDesc.BindFlags = Diligent::BIND_VERTEX_BUFFER;
|
||||
|
||||
if (bufferObj.isDynamic) {
|
||||
BuffDesc.CPUAccessFlags = Diligent::CPU_ACCESS_WRITE;
|
||||
}
|
||||
|
||||
if (pBuffer) {
|
||||
pBuffer->Release();
|
||||
@@ -476,7 +474,7 @@ namespace MG_GL::GL {
|
||||
MG_Diligent::g_pContext->MapBuffer(
|
||||
pBuffer,
|
||||
Diligent::MAP_WRITE,
|
||||
bufferObj.isDynamic ? Diligent::MAP_FLAG_DISCARD : Diligent::MAP_FLAG_NONE,
|
||||
Diligent::MAP_FLAG_DISCARD,
|
||||
pMappedData
|
||||
);
|
||||
|
||||
@@ -499,15 +497,13 @@ namespace MG_GL::GL {
|
||||
|
||||
if (!pBuffer) {
|
||||
Diligent::BufferDesc BuffDesc;
|
||||
BuffDesc.Name = "IndexBuffer";
|
||||
std::string bufferName = "Dynamic IBO " + std::to_string(buffer);
|
||||
BuffDesc.Name = bufferName.c_str();
|
||||
BuffDesc.Size = bufferObj.data.size();
|
||||
BuffDesc.Usage = bufferObj.isDynamic ? Diligent::USAGE_DYNAMIC
|
||||
: Diligent::USAGE_DEFAULT;
|
||||
BuffDesc.BindFlags = Diligent::BIND_INDEX_BUFFER;
|
||||
|
||||
if (bufferObj.isDynamic) {
|
||||
BuffDesc.CPUAccessFlags = Diligent::CPU_ACCESS_WRITE;
|
||||
}
|
||||
|
||||
if (pBuffer) {
|
||||
pBuffer->Release();
|
||||
@@ -551,6 +547,23 @@ namespace MG_GL::GL {
|
||||
}
|
||||
|
||||
if (!vertexBuffers.empty()) {
|
||||
MG_Util::Debug::LogD("Setting Vertex Buffers:");
|
||||
MG_Util::Debug::LogD(" NumBuffers: %u", static_cast<Diligent::Uint32>(vertexBuffers.size()));
|
||||
for (size_t i = 0; i < vertexBuffers.size(); ++i) {
|
||||
MG_Util::Debug::LogD(" Buffer %zu:", i);
|
||||
if (vertexBuffers[i]) {
|
||||
const auto& desc = vertexBuffers[i]->GetDesc();
|
||||
MG_Util::Debug::LogD(" Name: %s", desc.Name ? desc.Name : "N/A");
|
||||
MG_Util::Debug::LogD(" Size: %llu", desc.Size);
|
||||
MG_Util::Debug::LogD(" Usage: %d", desc.Usage);
|
||||
MG_Util::Debug::LogD(" BindFlags: %u", desc.BindFlags);
|
||||
MG_Util::Debug::LogD(" CPUAccessFlags: %u", desc.CPUAccessFlags);
|
||||
} else {
|
||||
MG_Util::Debug::LogD(" <null buffer>");
|
||||
}
|
||||
MG_Util::Debug::LogD(" Offset: %llu", offsets[i]);
|
||||
}
|
||||
|
||||
MG_Diligent::g_pContext->SetVertexBuffers(
|
||||
0,
|
||||
static_cast<Diligent::Uint32>(vertexBuffers.size()),
|
||||
@@ -565,7 +578,7 @@ namespace MG_GL::GL {
|
||||
GLuint buffer = pVAO->elementBuffer;
|
||||
auto it = MG_Diligent::g_BufferMap.find(buffer);
|
||||
if (it != MG_Diligent::g_BufferMap.end() && it->second) {
|
||||
Diligent::Uint64 offset = reinterpret_cast<uintptr_t>(indices);
|
||||
auto offset = reinterpret_cast<uintptr_t>(indices);
|
||||
|
||||
MG_Diligent::g_pContext->SetIndexBuffer(
|
||||
it->second,
|
||||
|
||||
Reference in New Issue
Block a user