Merge pull request #4766 from ReinUsesLisp/tmml-cube

shader/texture: Implement CUBE texture type for TMML and fix arrays
pull/8/head
bunnei 4 years ago committed by GitHub
commit 4c348f4069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -292,33 +292,36 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) {
break; break;
} }
std::vector<Node> coords; const u64 base_index = is_array ? 1 : 0;
const u64 num_components = [texture_type] {
// TODO: Add coordinates for different samplers once other texture types are implemented. switch (texture_type) {
switch (texture_type) { case TextureType::Texture1D:
case TextureType::Texture1D: return 1;
coords.push_back(GetRegister(instr.gpr8)); case TextureType::Texture2D:
break; return 2;
case TextureType::Texture2D: case TextureType::TextureCube:
coords.push_back(GetRegister(instr.gpr8.Value() + 0)); return 3;
coords.push_back(GetRegister(instr.gpr8.Value() + 1)); default:
break; UNIMPLEMENTED_MSG("Unhandled texture type {}", static_cast<int>(texture_type));
default: return 2;
UNIMPLEMENTED_MSG("Unhandled texture type {}", static_cast<int>(texture_type)); }
}();
// TODO: What's the array component used for?
// Fallback to interpreting as a 2D texture for now std::vector<Node> coords;
coords.push_back(GetRegister(instr.gpr8.Value() + 0)); coords.reserve(num_components);
coords.push_back(GetRegister(instr.gpr8.Value() + 1)); for (u64 component = 0; component < num_components; ++component) {
coords.push_back(GetRegister(instr.gpr8.Value() + base_index + component));
} }
u32 indexer = 0; u32 indexer = 0;
for (u32 element = 0; element < 2; ++element) { for (u32 element = 0; element < 2; ++element) {
if (!instr.tmml.IsComponentEnabled(element)) { if (!instr.tmml.IsComponentEnabled(element)) {
continue; continue;
} }
auto params = coords;
MetaTexture meta{*sampler, {}, {}, {}, {}, {}, {}, {}, {}, element, index_var}; MetaTexture meta{*sampler, {}, {}, {}, {}, {}, {}, {}, {}, element, index_var};
const Node value = Operation(OperationCode::TextureQueryLod, meta, std::move(params)); Node value = Operation(OperationCode::TextureQueryLod, meta, coords);
SetTemporary(bb, indexer++, value); SetTemporary(bb, indexer++, std::move(value));
} }
for (u32 i = 0; i < indexer; ++i) { for (u32 i = 0; i < indexer; ++i) {
SetRegister(bb, instr.gpr0.Value() + i, GetTemporary(i)); SetRegister(bb, instr.gpr0.Value() + i, GetTemporary(i));

Loading…
Cancel
Save