Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate shaders and buffers for nSight #4054

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions luarules/gadgets/cus_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ local function ExecuteDrawPass(drawPass)
local shaderTable = shaders[drawPass][shaderName]

if unitscountforthisshader > 0 then
gl.UseShader(shaderTable.shaderObj)
shaderTable:Activate()
shaderswaps = shaderswaps + 1
for uniformBinID, uniformBin in pairs(data) do

Expand Down Expand Up @@ -1672,7 +1672,7 @@ local function ExecuteDrawPass(drawPass)
end
end

gl.UseShader(0)
shaderTable:Deactivate()
end
end
end
Expand Down
12 changes: 10 additions & 2 deletions luaui/Widgets/Include/LuaShader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,9 @@ function LuaShader:Compile(suppresswarnings)
end
]]--

self.shaderObj = gl.CreateShader(self.shaderParams)
local shaderObj = self.shaderObj
local shaderObj, gl_program_id = gl.CreateShader(self.shaderParams)
self.shaderObj = shaderObj
self.gl_program_id = gl_program_id

local shLog = gl.GetShaderLog() or ""
self.shLog = shLog
Expand All @@ -557,6 +558,11 @@ function LuaShader:Compile(suppresswarnings)
self:ShowWarning(shLog)
end

if gl_program_id and self.shaderName then
local GL_PROGRAM = 0x82E2
gl.ObjectLabel(GL_PROGRAM, gl_program_id, self.shaderName)
end

local uniforms = self.uniforms
for idx, info in ipairs(gl.GetActiveUniforms(shaderObj)) do
local uniName = string.gsub(info.name, "%[0%]", "") -- change array[0] to array
Expand Down Expand Up @@ -613,6 +619,7 @@ LuaShader.Finalize = LuaShader.Delete
function LuaShader:Activate()
if self.shaderObj ~= nil then
self.active = true
gl.PushDebugGroup(self.gl_program_id * 1000, self.shaderName)
return glUseShader(self.shaderObj)
else
local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction"
Expand Down Expand Up @@ -644,6 +651,7 @@ end
function LuaShader:Deactivate()
self.active = false
glUseShader(0)
gl.PopDebugGroup()
end


Expand Down
82 changes: 61 additions & 21 deletions luaui/Widgets/Include/instancevbotable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function makeInstanceVBOTable(layout, maxElements, myName, unitIDattribID)
maxElements,
layout
)



local instanceStep = 0
for i,attribute in pairs(layout) do
instanceStep = instanceStep + attribute.size
Expand All @@ -37,7 +40,6 @@ function makeInstanceVBOTable(layout, maxElements, myName, unitIDattribID)
lastInstanceID = 0,
}


if unitIDattribID ~= nil then
instanceTable.indextoUnitID = {}
instanceTable.unitIDattribID = unitIDattribID
Expand Down Expand Up @@ -164,6 +166,11 @@ function makeInstanceVBOTable(layout, maxElements, myName, unitIDattribID)

newInstanceVBO:Upload(instanceData)

-- I believe that the openGL spec doesnt guarantee that a buffer has an idea before data is uploaded to it, so we will fill it with zeros.
local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, newInstanceVBO:GetID(), myName)


--register self in WG if possible
if WG then
if WG.VBOTableRegistry == nil then
Expand Down Expand Up @@ -391,6 +398,9 @@ function resizeInstanceVBOTable(iT)

iT.instanceVBO:Upload(iT.instanceData,nil,0,1,iT.usedElements * iT.instanceStep)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, iT.instanceVBO:GetID(), iT.myName)

if iT.VAO then -- reattach new if updated :D
iT.VAO:Delete()
iT.VAO = makeVAOandAttach(iT.vertexVBO,iT.instanceVBO, iT.indexVBO)
Expand Down Expand Up @@ -758,7 +768,7 @@ end

--------- HELPERS FOR PRIMITIVES ------------------

function makeCircleVBO(circleSegments, radius)
function makeCircleVBO(circleSegments, radius, name)
-- Makes circle of radius in xy space
-- can be used in both GL.LINES and GL.TRIANGLE_FAN mode
if not radius then radius = 1 end
Expand All @@ -784,10 +794,13 @@ function makeCircleVBO(circleSegments, radius)
VBOLayout
)
circleVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, circleVBO:GetID(), name or "CircleVBO")
return circleVBO, #VBOData/4
end

function makePlaneVBO(xsize, ysize, xresolution, yresolution) -- makes a plane from [-xsize to xsize] with xresolution subdivisions
function makePlaneVBO(xsize, ysize, xresolution, yresolution, name) -- makes a plane from [-xsize to xsize] with xresolution subdivisions
if not xsize then xsize = 1 end
if not ysize then ysize = xsize end
if not xresolution then xresolution = 1 end
Expand Down Expand Up @@ -816,11 +829,14 @@ function makePlaneVBO(xsize, ysize, xresolution, yresolution) -- makes a plane f
)
planeVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, planeVBO:GetID(), name or "PlaneVBO")

--Spring.Echo("PlaneVBOData up:",#VBOData, "Down", #planeVBO:Download())
return planeVBO, #VBOData/2
end

function makePlaneIndexVBO(xresolution, yresolution, cutcircle)
function makePlaneIndexVBO(xresolution, yresolution, cutcircle, name)
xresolution = math.floor(xresolution)
if not yresolution then yresolution = xresolution end
local planeIndexVBO = gl.GetVBO(GL.ELEMENT_ARRAY_BUFFER,false)
Expand Down Expand Up @@ -860,11 +876,14 @@ function makePlaneIndexVBO(xresolution, yresolution, cutcircle)
# IndexVBOData
)
planeIndexVBO:Upload(IndexVBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, planeIndexVBO:GetID(), name or "planeIndexVBO")
--Spring.Echo("PlaneIndexVBO up:",#IndexVBOData, "Down", #planeIndexVBO:Download())
return planeIndexVBO, IndexVBOData
end

function makePointVBO(numPoints, randomFactor)
function makePointVBO(numPoints, randomFactor, name)
-- makes points with xyzw
-- can be used in both GL.LINES and GL.TRIANGLE_FAN mode
numPoints = numPoints or 1
Expand All @@ -890,10 +909,13 @@ function makePointVBO(numPoints, randomFactor)
VBOLayout
)
pointVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, pointVBO:GetID(), name or "pointVBO")
return pointVBO, numPoints
end

function makeRectVBO(minX,minY, maxX, maxY, minU, minV, maxU, maxV)
function makeRectVBO(minX,minY, maxX, maxY, minU, minV, maxU, maxV, name)
if minX == nil then
minX, minY, maxX, maxY, minU, minV, maxU, maxV = 0,0,1,1,0,0,1,1
end
Expand Down Expand Up @@ -921,23 +943,28 @@ function makeRectVBO(minX,minY, maxX, maxY, minU, minV, maxU, maxV)
VBOLayout
)
rectVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, rectVBO:GetID(), name or "rectVBO")
return rectVBO, 6
end

function makeRectIndexVBO()
function makeRectIndexVBO(name)
local rectIndexVBO = gl.GetVBO(GL.ELEMENT_ARRAY_BUFFER,false)
if rectIndexVBO == nil then return nil end

rectIndexVBO:Define(
6
)
rectIndexVBO:Upload({0,1,2,3,4,5})
local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, rectIndexVBO:GetID(), name or "rectIndexVBO")
return rectIndexVBO,6
end



function makeConeVBO(numSegments, height, radius)
function makeConeVBO(numSegments, height, radius, name)
-- make a cone that points up, (y = height), with radius specified
-- returns the VBO object, and the number of elements in it (usually == numvertices)
-- needs GL.TRIANGLES
Expand Down Expand Up @@ -989,12 +1016,16 @@ function makeConeVBO(numSegments, height, radius)

coneVBO:Define(#VBOData/4, {{id = 0, name = "localpos_progress", size = 4}})
coneVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, coneVBO:GetID(), name or "coneVBO")

return coneVBO, #VBOData/4
end



function makeCylinderVBO(numSegments, height, radius, hastop, hasbottom)
function makeCylinderVBO(numSegments, height, radius, hastop, hasbottom, name)
-- make a cylinder that points up, (y = height), with radius specified
-- returns the VBO object, and the number of elements in it (usually == numvertices)
-- needs GL.TRIANGLES
Expand Down Expand Up @@ -1093,12 +1124,16 @@ function makeCylinderVBO(numSegments, height, radius, hastop, hasbottom)

cylinderVBO:Define(#VBOData/4, {{id = 0, name = "localpos_progress", size = 4}})
cylinderVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, cylinderVBO:GetID(), name or "cylinderVBO")

return cylinderVBO, #VBOData/4
end



function makeBoxVBO(minX, minY, minZ, maxX, maxY, maxZ) -- make a box
function makeBoxVBO(minX, minY, minZ, maxX, maxY, maxZ, name) -- make a box
-- needs GL.TRIANGLES
local boxVBO = gl.GetVBO(GL.ARRAY_BUFFER,true)
if boxVBO == nil then return nil end
Expand Down Expand Up @@ -1143,6 +1178,10 @@ function makeBoxVBO(minX, minY, minZ, maxX, maxY, maxZ) -- make a box
}
boxVBO:Define(#VBOData/4, {{id = 0, name = "localpos_progress", size = 4}})
boxVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, boxVBO:GetID(), name or "boxVBO")

return boxVBO, #VBOData/4
end

Expand All @@ -1157,7 +1196,7 @@ end
---@param sectorCount number is the number of orange slices around the belly in XY
---@param stackCount number how many horizontal slices along Z, usually less than sectorcount
---@param radius number how many elmos in radius, default 1
function makeSphereVBO(sectorCount, stackCount, radius) -- http://www.songho.ca/opengl/gl_sphere.html
function makeSphereVBO(sectorCount, stackCount, radius, name) -- http://www.songho.ca/opengl/gl_sphere.html


local sphereVBO = gl.GetVBO(GL.ARRAY_BUFFER,true)
Expand Down Expand Up @@ -1219,6 +1258,10 @@ function makeSphereVBO(sectorCount, stackCount, radius) -- http://www.songho.ca/
end
sphereVBO:Define(#VBOData/9, vertVBOLayout)
sphereVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, sphereVBO:GetID(), name or "sphereVBO")

local numVerts = #VBOData/9

local sphereIndexVBO = gl.GetVBO(GL.ELEMENT_ARRAY_BUFFER,false)
Expand Down Expand Up @@ -1263,12 +1306,15 @@ function makeSphereVBO(sectorCount, stackCount, radius) -- http://www.songho.ca/

sphereIndexVBO:Define(#VBOData)
sphereIndexVBO:Upload(VBOData)

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, sphereIndexVBO:GetID(), name or "sphereIndexVBO")

return sphereVBO, numVerts, sphereIndexVBO, #VBOData
end


function MakeTexRectVAO(minX,minY, maxX, maxY, minU, minV, maxU, maxV)
function MakeTexRectVAO(minX,minY, maxX, maxY, minU, minV, maxU, maxV, name)
-- Draw with myGL4TexRectVAO:DrawArrays(GL.TRIANGLES)
minX,minY,maxX,maxY,minU,minV,maxU,maxV = minX or -1,minY or -1,maxX or 1, maxY or 1, minU or 0, minV or 0, maxU or 1, maxV or 1

Expand All @@ -1290,15 +1336,9 @@ function MakeTexRectVAO(minX,minY, maxX, maxY, minU, minV, maxU, maxV)
minX,minY, minU, minV, --bl
})

--[[rectVBO:Upload( {
minX,minY,z,w, minU, minV,0,0, --bl
minX,maxY,z,w, minU, maxV,0,0, --br
maxX,maxY,z,w, maxU, maxV,0,0,--tr
maxX,maxY,z,w,maxU, maxV,0,0, --tr
maxX,minY,z,w, maxU, minV,0,0, --br
minX,minY,z,w, minU, minV,0,0, --bl
})
]]--

local GL_BUFFER = 0x82E0
gl.ObjectLabel(GL_BUFFER, rectVBO:GetID(), name or "rectVBO")

myGL4TexRectVAO = gl.GetVAO()
if myGL4TexRectVAO == nil then return nil end
Expand Down
8 changes: 5 additions & 3 deletions luaui/Widgets/gfx_ssao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ local function InitGL()
uniformFloat = {},
silent = true, -- suppress compilation messages
shaderConfig = shaderConfig,
shaderName = widgetName..": G-buffer Fuse",
shaderName = widgetName.." G-buffer Fuse",
}

gbuffFuseShader = LuaShader.CheckShaderUpdates(gbuffFuseShaderCache)
Expand All @@ -472,7 +472,7 @@ local function InitGL()
},
silent = true, -- suppress compilation messages
shaderConfig = shaderConfig,
shaderName = widgetName..": SSAO",
shaderName = widgetName.." SSAO",
}

ssaoShader = LuaShader.CheckShaderUpdates(ssaoShaderCache)
Expand Down Expand Up @@ -501,7 +501,7 @@ local function InitGL()
},
silent = true, -- suppress compilation messages
shaderConfig = shaderConfig,
shaderName = widgetName..": gaussianBlur",
shaderName = widgetName.." gaussianBlur",
}

gaussianBlurShader = LuaShader.CheckShaderUpdates(gaussianBlurShaderCache)
Expand Down Expand Up @@ -758,8 +758,10 @@ function widget:DrawWorld()
drawFrame = df
end
if shaderConfig.ENABLE == 0 then return end
gl.PushDebugGroup(9999, "SSAO")
DoDrawSSAO(false)

gl.PopDebugGroup()
if delayedUpdateSun and os.clock() > delayedUpdateSun then
Spring.SendCommands("luarules updatesun")
delayedUpdateSun = nil
Expand Down
5 changes: 4 additions & 1 deletion luaui/Widgets/gui_sensor_ranges_los.lua
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ end

function widget:DrawWorld()
--if spec and fullview then return end

local GL_DEBUG_SOURCE_APPLICATION = 0x824A
gl.PushDebugGroup(1000, "Sensor Ranges LOS")
if Spring.IsGUIHidden() or (WG['topbar'] and WG['topbar'].showingQuit()) then return end
if circleInstanceVBO.usedElements == 0 then return end
if opacity < 0.01 then return end
Expand Down Expand Up @@ -319,6 +320,8 @@ function widget:DrawWorld()
--glColor(1.0, 1.0, 1.0, 1.0) --reset like a nice boi
glLineWidth(1.0)
gl.Clear(GL.STENCIL_BUFFER_BIT)

gl.PopDebugGroup()

end

Expand Down