Digital Foundry Article Technical Discussion Archive [2015]

Status
Not open for further replies.
That's kinda dumb AI. If they get a path and follow it without constantly evaluating their surroundings and changes in the game state, they aren't really being intelligent. They'd start on a walk and merrily proceed through a stream of bullet crossing their path, getting mowed down because they weren't performing constant evaluations.

No, it's being human. If people were constantly evaluating their surroundings, as you want AI to behave, automobile crashes would almost disappear overnight and nobody would ever fall over anything. But humans spend most of their time in one of two dominant mental states, focussed on something (to varying degrees to the exclusionsof others things) or really thinking about nothing in particular.

If you hear a noise in your kitchen do you proceed their cautiously, evaluating the environment at every step or do you just go into the kitchen? I know which I do.

A smart agent would start on a path but be constantly testing proximity of surroundings, players, threats, ready to change mind at any point. You can either do that per agent, or as an overall game state. Either way you need evaluations more frequently than every time a job has concluded.

I said this in my post above: Now games are multithreaded and there is often a conscious AI decision (take cover, shoot target X, move to position Y, use ability Z, run away etc) then many frames (which could be several seconds) where the AI executes that intention, then the AI starts over unless the AI system has been written in such a way that the AI can make a new decision based on new stimuli.

MGSV suits this AI. However, the question Hesido presented was how is it at all possible that AI can slow down framerate. The answer is by being computationally expensive.

The answer is being computationally expensive and by having the AI in the game loop that also drives rendering. This won't happen if rendering is decoupled from the game world simulation.
 
...the question Hesido presented was how is it at all possible that AI can slow down framerate...

To be clear, I can understand fairly well how AI can slow down frame rate, but I was asking if it's somehow avoidable through different methodologies, with some compromises but without making the AI dumb. As I understand, the game goes from 0 npc in one mode (16ms update) to many npc's in another (33ms update), so if they had their game logic and other systems barely making it under 16ms while utilizing 6cores to the max in parallel execution in the no-NPC multiplayer mode, let's say ~14ms, then yes, 1-2ms of total CPU time and across several cores might not cut it for that kind of AI (esp. if you are leaving the ray casting / path finding to the cpu)

I'm still wondering though, whether they have considered these options:
  • Reserve a core or two for AI (lol, how easy for me to say), then design the game around it (since AI is so important) (of course, decoupled from main loop) and progressively enhance the graphics for no NPC game modes. This is probably the easier option.
  • In online mode, distribute AI across clients in peer to peer fashion.
  • In online mode, have the dedicated server do the AI (power of the cloud :) )
  • Are they using GPU-driven rendering pipelines to lessen the impact on CPU (as described by sebbbi)
  • Get as much help from GPU preferably using async compute (esp. for ray casting) and have the CPU just do the "macro" decisions.
It seems to me that they've designed the game around full multiplayer with no NPC's, and then designed the terror hunt mode on top of it.
 
Last edited:
No, it's being human. If people were constantly evaluating their surroundings, as you want AI to behave, automobile crashes would almost disappear overnight and nobody would ever fall over anything. But humans spend most of their time in one of two dominant mental states, focussed on something (to varying degrees to the exclusionsof others things) or really thinking about nothing in particular.
We're talking about trained soldiers in a war zone! Not Joe Blogs pottering around their home or driving the same old route to work thinking about the upcoming birthday party on the weekend. A soldier wandering around the battlefield thinking about his poetry thesis isn't going to present good AI in a computer game. ;)

The answer is being computationally expensive and by having the AI in the game loop that also drives rendering. This won't happen if rendering is decoupled from the game world simulation.
Only for low demand AI. When AI workload is high, you'll have an impact somewhere. Let's say your super advanced AI requires 1000 ms of CPU time to complete one update/cycle. Let's say rendering takes 15 ms. You have 1 ms free time that you spend on working through this AI on an async thread. It thus takes 1000 frames to compute a cycle of AI, and all your agents have a sixteen second reaction time. Now let's say you spend 15 ms rendering and drop the framerate to 30 fps. You can now spend 16 ms per frame on the AI thread and complete an AI update in ~60 frames. That's two seconds between updates.

CPU power is finite. AI represents a demand on that finite resource. If you can't fit the AI in between other workloads, those other workloads will suffer, or the AI will. It's no different to physics - the CPU can fit a certain asynchronous computation workload between rendering tasks, but when you crank up the computations, the workload slows down the rendering. Either that or physics starts working in slow motion as the computations can't be computed in time on the allocated CPU time budget.
 
I'm still wondering though, whether they have considered these options:
I'm pretty sure there's a thread on AI discussing alternative avenues.
It seems to me that they've designed the game around full multiplayer with no NPC's, and then designed the terror hunt mode on top of it.
Probably makes good business sense if the game is chiefly an online shooter. Terror Hunt mode shouldn't be the basis of the engine design unless that's the key selling point that'll generate the most money.
 
We're talking about trained soldiers in a war zone! Not Joe Blogs pottering around their home or driving the same old route to work thinking about the upcoming birthday party on the weekend. A soldier wandering around the battlefield thinking about his poetry thesis isn't going to present good AI in a computer game. ;)

And you know what soldiers do more than anything else? Wait. Clean their weapons, check their kit, walk, talk and patrol. Actions repeated almost mindlessly. Real war isn't like Rambo.

Play MGS V, many of the soldiers are bored and/or complacent because they are far from any front line or in a large compound that nobody would want to attack. Surprise in the face of boredom of complacency is how you win. If all of the soldiers were on high alert all the time, the game would a) be unrealistic and b) be pretty dull as you'd spend most of your time crawling around in 3 meter bursts when a spotter isn't looking exactly in your direction.

Only for low demand AI. When AI workload is high, you'll have an impact somewhere. Let's say your super advanced AI requires 1000 ms of CPU time to complete one update/cycle. Let's say rendering takes 15 ms. You have 1 ms free time that you spend on working through this AI on an async thread. It thus takes 1000 frames to compute a cycle of AI, and all your agents have a sixteen second reaction time. Now let's say you spend 15 ms rendering and drop the framerate to 30 fps. You can now spend 16 ms per frame on the AI thread and complete an AI update in ~60 frames. That's two seconds between updates.

Well that's a different issue to AI slowing framerate, not having CPU time to do the AI you want to do is no different to any other programming problem, you find another way to achieve the desired effect in less cycles. There are a lot of books on very efficient ways to implement convincing AI and most of these are using algorithms decades old from decision making programs.
 
I should have read the extract from the book Game Engine Architecture [Gamasutra] in a little more detail:

One particularly tricky aspect of converting synchronous, unbatched code to use an asynchronous, batched approach is determining when during the game loop (a) to kick off the request and (b) to wait for and utilize the results. In doing this, it is oft en helpful to ask ourselves the following questions:
  • How early can we kick off this request? The earlier we make the request, the more likely it is to be done when we actually need the results -- and this maximizes CPU utilization by helping to ensure that the main thread is never idle waiting for an asynchronous request to complete. So for any given request, we should determine the earliest point during the frame at which we have enough information to kick it off , and kick it there.
  • How long can we wait before we need the results of this request? Perhaps we can wait until later in the update loop to do the second half of an operation. Perhaps we can tolerate a one-frame lag and use last frame's results to update the object's state this frame. (Some subsystems like AI can tolerate even longer lag times because they update only every few seconds.) In many circumstances, code that uses the results of a request can in fact be deferred until later in the frame, given a little thought, some code re-factoring, and possibly some additional caching of intermediate data.
Who is the author of this? Jason Gregory. Who the hell is Jason Gregory? He's lead programmer at Naughty Dog. The Naughty Dogs have spoken.. uh.. barked.:yep2: Read the whole extract. Then buy the book if you're have not read it. Because like I said above. It's gooooood.
 
And you know what soldiers do more than anything else? Wait. Clean their weapons, check their kit, walk, talk and patrol. Actions repeated almost mindlessly. Real war isn't like Rambo.
Further qualification - we're talking a computer game about war. ;) Real war isn't like COD, but the AI for COD (or any other war based game) doesn't want to match the real world - it'd be too tedious and no-one would play it. Every agent in the game, human or artificial, is constantly evaluating their surroundings and the game state. They're looking for meaningful objectives, and to stay alive, and to get an easy kill, and to find a strong position to defend, etc. Only the most noobish of noobs and most dumb of artificial intelligence is going to be standing around chatting about the latest celebrity gossip and who they hope wins Come Dancing. Everyone else is constantly in motion, avoiding head-shots and trying to surprise folk, or bunkered down in an annoying sniper spot being a damned nuisance. Those guys do have reduced AI. A simple ray test for visibility, and then a shot with a random error factor to approximate human skill.

Edit - I'll add that basic AI needn't be too demanding, but a common complaint of AI is it's too dumb, and the interest in online player is against real intelligence. If you want to crank up the intelligence of your bots so they can play smart and offer a decent high-level human analogue, you need to spend processing cycles on it.
 
Call of Duty has very little actual AI, most of the enemy behaviour is scripted. Call of Duty is whack-a-mole with guns. That's why I used MGS V as an example. You can 'play' with the enemy to see how the AI reacts in different ways.
 
And it all also runs on last gen consoles, so not likely to be CPU bottlenecked. :p
 
And it all also runs on last gen consoles, so not likely to be CPU bottlenecked. :p

Right, and you can easily have 40-50 enemy AI all alert and reacting in different ways. One of the earliest missions has you extracting Miller who is held captive in an enemy occupied village. If you lose stealth the whole village goes ape shit (its a military term :yep2:). The game doesn't slow down, nor should it. AI is one of the world systems that should be decoupled from rendering along with physics, environmental systems (weather, clouds, wind). None of these need to be running synchronous to the renderer either.
 
Last edited by a moderator:
Lol. Leaving the "hobbyist" mode of game development. ^^^

Sounds like a good read though. Like I said earlier every game will profile AI differently. Without knowing what Ubisoft is attempting to do with its engine and where the bottlenecks sit it's hard to know what's really causing the issue.

I do agree with "how long can you wait" for a response. The answer I guess is "it depends" on the game or the enemy. Some games need instant reaction like a lot of top down or side scrollers. But games that try to simulate real life behaviour can slow down a bit.
 
In D3D11 and corresponding hardware AF is a per-sampler setting. It does have a significant cost that increases as you go up if you just do it naively, but since it's per-sampler it can be targeted to where it needs it most. Most textures do not need AF at all. For the ones that do maybe only the normal map or diffuse map needs it. For most textures it's really hard to notice values above 4x even on long glancing views.

If you just naively set all your textures to 16xAF you're going to have terrible performance. If you set a large amount of the scene to 4x or even 2x you're still often bumping into unacceptable performance deltas. When we talk about games that have "patched in AF" chances are that you're talking about a handful of materials changed to have a slightly higher setting. And when you're talking about "no performance penalty" you're talking about something you don't have the tools to measure appropriately in the consumer world.

This is really simple. Why don't games have AF? Because it's expensive to do it naively and only a handful of textures benefit from it, so the smartest thing to do is default it to off and raise it by hand as needed. See a blurry texture? An artist hasn't checked the "use AF" box on it. The end.

I really hope everyone reads this post, and the idea that AF is somehow 'free' goes away.
 
I really hope everyone reads this post, and the idea that AF is somehow 'free' goes away.
Likely won't happen :( as long as people turn on the feature and do not notice correlated fps drop then they will always feel that it is free.
 
Call of Duty has very little actual AI, most of the enemy behaviour is scripted. Call of Duty is whack-a-mole with guns. That's why I used MGS V as an example. You can 'play' with the enemy to see how the AI reacts in different ways.
COD as in battlefield scenario. Why do think COD has whack-a-mole AI? Perhaps because they couldn't afford the CPU cycles to get human like AI in a 60fps time budget.

If you want to prove to me decent AI is possible at 60 fps without impacting framerate, don't quote a game that has AI agents twiddling their thumbs and walking patrol routes hoping a Men's Magazine is going to mysteriously appear. ;) That's not representative of the AI agent's requirements in a fast shooter action game with destructible environments who need to play like human players and make choices and react as quickly as a human player.
 
If you want to prove to me decent AI is possible at 60 fps without impacting framerate, don't quote a game that has AI agents twiddling their thumbs and walking patrol routes hoping a Men's Magazine is going to mysteriously appear. ;)
Why don't you play the game. Just drive up into an enemy village, compound or occupied prison and see how many enemy AI are reading magazines.
 
Here is more from Jason Gregory on the AI in The Last of Us - taken from an interview with digital tends:

“Both Ellie and the enemy AI has been completely revamped for this game [compared to Uncharted]. We’re still using some of the lower-level systems — the animation systems are obviously leveraged from prior technology — but all of the enemy perception, the way that they analyze the play space, how they decide where they are going to go, is brand new technology.”

“Basically every AI character has a set of behaviors that are for when they are being aggressive, and another set of behaviors for when they are trying to hide from you, take cover, flank you, and so on. And they make those judgments based on their perception of what you have shown to them. So it’s a bit like a poker game. If you reveal your hand, if you brandish a gun at them, they’re like ‘holy crap, this guy has a gun!’ and they start running. If you sneak around they may not know that you have a gun until you take that first shot.”

“It’s all based on their perception, and they’ll switch behavioral modes based on what’s going on. When they’re in attack mode, they’ll band together, they work as a team and they’ll be more aggressive. When you’re in the position of power, when the balance of power shifts, they’ll try to take cover more, they’ll try to flank you, they’ll try to sneak up behind you.”
I'm done on AI now but I really could write pages and pages on it! :yes:
 
Uncharted 4 also a leap ahead of TLOU (first demo very impressive AI wise), i am very interested to see what they are using in that one.
 
This is getting silly now. You're citing MGSV as evidence that agents in a game don't need to be constantly evaluating the combat zone. You then relate AI agents in an action computer game to normal people going about their every day business. Neither is the slightest bit representative of what an AI agent has to do in a close-quarters, urban, one shot kill combat game where clearly the enemy AI has to be as aware and responsive as a human player in that computer game. Even if Joe Gamer drives his car not thinking about anything in particular and having accidents, and even if Joe Gamer was to spend most of a war patrolling and cleaning his weapon and gazing at a well-worn photo of his sweetheart, when that human being is in a combat situation like R6 (assuming they aren't in a blind panic and are suitably trained), they'll be 100% focussed on staying alive and killing the enemy, constantly processing cues, orders, and looking for opportunities. That's something smart AI will need to replicate. There's no point holding up any other games, whether Paradroid or MGSV or COD or Bass Fishing, as proof this can be achieved at 60 fps with long AI intervals running on a low priority thread if they aren't accomplishing the goal of realistic human player behaviour. If you want to use MGSV as an example of how 60 fps and smart AI is possible, show a comparable situation of 20 AI agents in an internal urban environment and not behaving like typical game cannon-fodder. From what I've seen of vids, MGSV agents are typical morons, merrily standing in plain view of getting shot and not reacting much like a reasonable player in fear of a one-shot kill. eg. Standing behind a wall of sandbags, they get shot. Snake ducks behind the sandbags on the other side. The enemy agents continue standing there - they don't shoot over the top, don't run for cover, don't try to run around the wall, don't do anything except stand there ready to be shot. If you're only aiming for that sort of simple AI, fitting it into a higher framerate game is easier. If you want smarter AI, you need to spend processing cycles on it, and that's how a 60 fps can be bogged down to 30 fps when including AI.
 
I don't think PCI-E has any impact on AF. AF is limited by the performance of the GPU core and that isn't limited by PCI-E bandwidth.
I suppose what I'm getting at is that there has to be some sort of bottleneck specific to PC setups that hides the performance cost for various titles.

Oh well.
 
Status
Not open for further replies.
Back
Top