shader: parse vertex metadata once when a shader is mapped

This commit is contained in:
nmzik committed 2026-10-24 05:44:46 +02:00
1 parent dbc7b8b2ff
commit 8291cfeb04
6 files changed
+44 -44

No files matched your search

+13 -14
View File
@@ -5,10 +5,10 @@
namespace Libs::Graphics {
bool ShaderReadVertexMetadata(const ShaderMappedData& data, uint32_t max_user_sgprs,
ShaderVertexMetadata& metadata, std::string* error) {
const char* ShaderReadVertexMetadata(const ShaderMappedData& data, uint32_t max_user_sgprs,
ShaderVertexMetadata& metadata) {
if (data.user_data == nullptr) {
return ShaderError::Fail(error, "missing AGC user-data header");
return "missing AGC user-data header";
}
ShaderUserData user_data {};
@@ -17,8 +17,7 @@ bool ShaderReadVertexMetadata(const ShaderMappedData& data, uint32_t max_user_sg
constexpr uint32_t DirectResourceCount =
static_cast<uint32_t>(AgcDirectResourceType::Last) + 1u;
if (user_data.direct_resource_count > DirectResourceCount) {
return ShaderError::Fail(error,
"AGC direct-resource count exceeds the known resource domain");
return "AGC direct-resource count exceeds the known resource domain";
}
std::array<uint16_t, DirectResourceCount> direct_offsets {};
@@ -26,7 +25,7 @@ bool ShaderReadVertexMetadata(const ShaderMappedData& data, uint32_t max_user_sg
static_cast<uint64_t>(user_data.direct_resource_count) * sizeof(uint16_t);
if (direct_size != 0) {
if (user_data.direct_resource_offset == nullptr) {
return ShaderError::Fail(error, "missing AGC direct-resource offsets");
return "missing AGC direct-resource offsets";
}
std::memcpy(direct_offsets.data(), user_data.direct_resource_offset, direct_size);
}
@@ -47,33 +46,33 @@ bool ShaderReadVertexMetadata(const ShaderMappedData& data, uint32_t max_user_sg
}
if (next.vertex_attrib_reg >= 0 && next.vertex_buffer_reg < 0) {
return ShaderError::Fail(error, "vertex attribute table requires a vertex buffer table");
return "vertex attribute table requires a vertex buffer table";
}
if (next.vertex_buffer_reg < 0) {
metadata = next;
return true;
return nullptr;
}
if (static_cast<uint32_t>(next.vertex_buffer_reg) + 1u >= max_user_sgprs) {
return ShaderError::Fail(error, "vertex table pointer exceeds the user-SGPR domain");
return "vertex table pointer exceeds the user-SGPR domain";
}
if (next.vertex_attrib_reg < 0) {
metadata = next;
return true;
return nullptr;
}
if (static_cast<uint32_t>(next.vertex_attrib_reg) + 1u >= max_user_sgprs) {
return ShaderError::Fail(error, "vertex table pointer exceeds the user-SGPR domain");
return "vertex table pointer exceeds the user-SGPR domain";
}
if (data.num_input_semantics == 0 ||
data.num_input_semantics > ShaderVertexInputInfo::RES_MAX) {
return ShaderError::Fail(error, "vertex semantic count is outside the supported domain");
return "vertex semantic count is outside the supported domain";
}
if (data.input_semantics == nullptr) {
return ShaderError::Fail(error, "missing vertex input semantics");
return "missing vertex input semantics";
}
next.input_semantics = {data.input_semantics, data.num_input_semantics};
metadata = next;
return true;
return nullptr;
}
} // namespace Libs::Graphics