Defold Shaders (2021 shader practice / learning edition)

Modified version of the editor script which appears to work with the stand alone legacy version download (tested Mali Offline Compiler Version 6.4 Windows 64-bit).

I think removing the .exe should make it work on other platforms too.

-- Download and install Mali Offline Compiler Version 6.4 from 
-- https://developer.arm.com/tools-and-software/graphics-and-gaming/mali-offline-compiler/downloads

local M = {}

local function ends_with(str, ending)
    return ending == "" or str:sub(-#ending) == ending
end

function M.get_commands()
    return {
        {
            label = "Compile Fragment Shader (Mali-G72)",
            locations = {"Edit", "Assets"},
            query = {selection = {type = "resource", cardinality = "one"}},
            active = function(opts)
                local path = editor.get(opts.selection, "path")
                return ends_with(path, ".fp")
            end,
            run = function(opts)
                local path = editor.get(opts.selection, "path")
                path = path:sub(2)
                return {
                    {action = "shell", command = {"cmd", "/C", "malisc", "--core", "Mali-G72", "--fragment", path}}
                }
            end
        }, {
            label = "Compile Vertex Shader (Mali-G72)",
            locations = {"Edit", "Assets"},
            query = {selection = {type = "resource", cardinality = "one"}},
            active = function(opts)
                local path = editor.get(opts.selection, "path")
                return ends_with(path, ".vp")
            end,
            run = function(opts)
                local path = editor.get(opts.selection, "path")
                path = path:sub(2)
                return {
                    {action = "shell", command = {"cmd", "/C", "malisc", "--core", "Mali-G72", "--vertex", path}}
                }
            end
        }, {
            label = "Compile Fragment Shader (Mali-T600)",
            locations = {"Edit", "Assets"},
            query = {selection = {type = "resource", cardinality = "one"}},
            active = function(opts)
                local path = editor.get(opts.selection, "path")
                return ends_with(path, ".fp")
            end,
            run = function(opts)
                local path = editor.get(opts.selection, "path")
                path = path:sub(2)
                return {
                    {action = "shell", command = {"cmd", "/C", "malisc", "--core", "Mali-T600", "--fragment", path}}
                }
            end
        }, {
            label = "Compile Vertex Shader (Mali-T600)",
            locations = {"Edit", "Assets"},
            query = {selection = {type = "resource", cardinality = "one"}},
            active = function(opts)
                local path = editor.get(opts.selection, "path")
                return ends_with(path, ".vp")
            end,
            run = function(opts)
                local path = editor.get(opts.selection, "path")
                path = path:sub(2)
                return {
                    {action = "shell", command = {"cmd", "/C", "malisc", "--core", "Mali-T600", "--vertex", path}}
                }
            end
        }
    }
end

return M

Now I will need to learn how to use this to optimize shaders.

Arm Mali Offline Compiler v6.4.0
(C) Copyright 2007-2018 Arm, Ltd.
All rights reserved.

No driver specified, using "Mali-Gxx_r11p0-00rel0" as default.

No core revision specified, using "r0p3" as default.


64 work registers used, 2 uniform registers used, spilling not used.

			A	L/S	T
Instructions Emitted:	5	4	1
Shortest Path Cycles:	5	4	1
Longest Path Cycles:	5	4	1

A = Arithmetic, L/S = Load/Store, T = Texture
Note: The cycles counts do not include possible stalls due to cache misses.
Note: Shaders with loops may return "N/A" for cycle counts if the number of cycles cannot be statically determined.

Compilation succeeded.
2 Likes