shader: type packed integer vertex inputs by their component type

This commit is contained in:
nmzik committed 2026-10-30 02:59:36 +01:00
1 parent b65dd18224
commit 1703836d06
4 files changed
+13 -38

No files matched your search

@@ -173,7 +173,7 @@ uint32_t EmitVertexParameterComponentU32(EmitterState& state, const InputBinding
state.builder.AddFunction(spv::OpLoad, scalar_type, raw, pointer);
}
if (kind == VertexInputScalarKind::Uint) {
if (kind == Format::ComponentType::Uint) {
return raw;
}
@@ -273,8 +273,6 @@ struct ValueEmitContext {
uint32_t half = 0;
};
enum class VertexInputScalarKind { Float, Sint, Uint };
constexpr uint32_t NoImageComponent = 0xffffffffu;
struct DppTargetLane {
@@ -304,12 +302,11 @@ bool PixelParameterIsFlat(const EmitterState& state, uint32_t attr);
bool PixelParameterIsCustom(const EmitterState& state, uint32_t attr);
VertexInputScalarKind VertexParameterScalarKind(const EmitterState& state, uint32_t location);
Format::ComponentType VertexParameterScalarKind(const EmitterState& state, uint32_t location);
uint32_t VertexParameterComponentCount(const InputBinding& input);
uint32_t VertexParameterScalarType(EmitterState& state, VertexInputScalarKind kind);
uint32_t VertexParameterScalarType(EmitterState& state, Format::ComponentType kind);
uint32_t OutputVariableForExport(const EmitterState& state, const IR::ExportInfo& exp);
uint32_t MrtOutputType(EmitterState& state, uint32_t index);
@@ -402,47 +402,23 @@ uint32_t GlslStd450(EmitterState& state) {
return state.builder.Import("GLSL.std.450");
}
VertexInputScalarKind VertexParameterScalarKind(const EmitterState& state, uint32_t location) {
Format::ComponentType VertexParameterScalarKind(const EmitterState& state, uint32_t location) {
if ((state.program.stage != ShaderType::Vertex && state.program.stage != ShaderType::Local) ||
location >= ShaderVertexInputInfo::RES_MAX ||
location >= static_cast<uint32_t>(state.input_info.vertex->resources_num)) {
return VertexInputScalarKind::Float;
}
switch (state.input_info.vertex->resources[location].Format()) {
case Prospero::BufferFormat::k8UInt:
case Prospero::BufferFormat::k16UInt:
case Prospero::BufferFormat::k8_8UInt:
case Prospero::BufferFormat::k32UInt:
case Prospero::BufferFormat::k16_16UInt:
case Prospero::BufferFormat::k8_8_8_8UInt:
case Prospero::BufferFormat::k32_32UInt:
case Prospero::BufferFormat::k16_16_16_16UInt:
case Prospero::BufferFormat::k32_32_32UInt:
case Prospero::BufferFormat::k32_32_32_32UInt: return VertexInputScalarKind::Uint;
case Prospero::BufferFormat::k8SInt:
case Prospero::BufferFormat::k16SInt:
case Prospero::BufferFormat::k8_8SInt:
case Prospero::BufferFormat::k32SInt:
case Prospero::BufferFormat::k16_16SInt:
case Prospero::BufferFormat::k8_8_8_8SInt:
case Prospero::BufferFormat::k32_32SInt:
case Prospero::BufferFormat::k16_16_16_16SInt:
case Prospero::BufferFormat::k32_32_32SInt:
case Prospero::BufferFormat::k32_32_32_32SInt: return VertexInputScalarKind::Sint;
default: return VertexInputScalarKind::Float;
return Format::ComponentType::Float;
}
return Format::GetFormatComponentType(state.input_info.vertex->resources[location].Format());
}
uint32_t VertexParameterComponentCount(const InputBinding& input) {
return std::clamp(input.component_count, 1u, 4u);
}
uint32_t VertexParameterScalarType(EmitterState& state, VertexInputScalarKind kind) {
uint32_t VertexParameterScalarType(EmitterState& state, Format::ComponentType kind) {
switch (kind) {
case VertexInputScalarKind::Sint: return TypeI32(state);
case VertexInputScalarKind::Uint: return TypeU32(state);
case VertexInputScalarKind::Float:
case Format::ComponentType::Sint: return TypeI32(state);
case Format::ComponentType::Uint: return TypeU32(state);
default: return TypeF32(state);
}
}