hello so welcome to the building fleas their applications on a Mac and definitely check out the weather app that Scott hunter just mentioned it's really cool but we have some kind of simpler stuff to get started to talk more about what blazer is and take you through an intro app how to get your feet wet and then we'll move to a more realistic app and make some changes there as well yeah oh and I'm Kendra havens I'm a program manager on dotnet and Visual Studio and I'm Dan Roth I'm a program manager on the asp.net team cool okay so Dan what is blazer is boy so much talk about it and so much excitement so Blazers a modern web framework for building client-side web apps using c-sharp and net instead of JavaScript it's cross-platform it's open source and it's based only on open web standards now we've had ways to build web apps with dotnet for a long time a traditional don''t web app you take your dotnet code and you put it on the server and then the browser sends requests to your server and it responds with dynamically generated HTML or Jason that's pretty typical dotnet web application but if you wanted to do anything that ran in the browser well that meant you had to use some Java scripts like using one of whatever the popular JavaScript framework of the day is and that's cool I mean Java scripts great I mean yeah it's great you kind of have to switch context though and that can kind of slow you down so they can stay in dotnet code that's kind of convenient if you can use the same language the same frameworks the same tools same build system across your entire application that's what blazer is all abouts enabling you to build full stack web apps using Donette and c-sharp that's what we've been working on sweet okay so Blazer you build client-side web apps using just net and c-sharp code it also comes with a component model so you can build reusable web UI components you can package them up as NuGet packages and libraries and share them with your friends it also enables you to use the same code on both sides of the wire if you have some common logic like validation logic or data models that you want to use both on the client and on the server you can do that with Blaser it's full stack web development with net at the same time if you have existing JavaScript code or you want right so we're sharing dotnet code so even like working and like f-sharp or Visual Basic if I have libraries that I want to call from blazer yeah you can do that it's just normal donÃt assemblies that you're calling is your into in your blazer application absolutely and also if you have JavaScript you can still use that as well you can call into existing JavaScript libraries from your blazer code and even call back from the JavaScript code back into net through JavaScript Interop you can use that to also leverage all of the native functionality of the browser okay so if I'm not-like or if I'm slowly migrating my app to blazer alright trying it out in some section I can still use javascript elicit don't have to throw your JavaScript away you can just you reuse it in your existing blazer application how does that work is that possible I know it seems like magic well there's two ways that blazer apps function the first mode we call blazer server the way blazer server works is that we set up a real time connection with the browser we use signal R to do that it's basically a WebSocket connection Brady has a talk on all on signal once we've got that real time connection with the browser we run your blazer UI components on the server any UI events that happen in the browser we send them over to the server dispatch them to your components the components run they render and then blaze are very cleverly figures out just the parts of your UI that have changed and see arises that diff back down to the browser to then be rendered and updated so it's a kind of a thin client model you're you're still running your UI components on the server but you get that rich interactive field that you would expect from like a JavaScript based single page application ok and in server all of my c-sharp is compiling on the server still not at all inside the browser all the compiled compilation happens at Build time but your build code is gonna be running on the server on dotnet core it's not actually going to execute in the browser right but you still get the rich interactivity of being able to handle all the UI events and update the Dom seamlessly without having to do a full browser refresh but I have heard about things you started to do that you know I are not compiling but executing executing that's right in the browser with blazer webassembly your web assembly what we do is we we can download with your app a full dotnet runtime that's implemented in web assembly now web assembly is an open web standard it's basically a bytecode for the web if you can compile your code to web assembly that code can now run in any browser on any platform at near native speeds native as in like browser natives well pretty close to the wire like it's almost like an assembly language that's been standardized for the web so it's pretty fast super fast and it's so we built a dotnet runtime in web assembly that you can bring with your app it's small and compact and then you just download normal dotnet assemblies into the browser and execute them using that runtime the same come you I components the blazer components in this case they're running in the browser itself they do they handle UI events they calculate the diff in process in the browser client side so I see our little slide here says preview that's right so please our web assembly is in previews lays our web assemblies in preview laser server however is ready to go for production I want to use which one here server versus web assembly so Blaser server shipped with dotnet core 300k also shipped with three one LTS LTS is a long-term support release so Blaser server is ready for production use today you can put it in your websites put it out in production it's fully supported with a long-term support life cycle blazer web assemblies still in preview isn't quite done yet but we're working real hard on it we expect to have that finished up in just a few months later this this year how do you pick between the two well there's there's some some trade-offs with blazer server the benefits there is well your your well first of all its production yeah if you can actually use it right now but if your code is also running on a full dotnet core runtime so it's super fast on the server and it treats the client as a basically a thin client it has less demands on what the the browser or the client device needs to do so for example if you want to support older browsers like IE 11 you can do that with the blazer server application because there's no requirement to support web assembly blazer web assembly on the other hand gives you that option of pushing and offloading load from your server onto the client because it's a true client-side application it can support things like offline scenarios that's still in preview so it's not ready for use today but it will open up some really cool scenarios in the future oh my gosh I'm so pumped now regardless of which model you pick though like don't don't get too hung up I'm picking one versus the other because the component model is the same you write your components once and then you can use them in either hosting models so you could start out for example with the blazer server app and if you want to switch the Blazer web assembly in the future that's pretty trivial maybe when it goes to production we can switch our components over if that's what you wanted a oh my gosh I'm so pumped shall we get let's get started ok you say laser I know you can get started by going to blazer dotnet so we have a really simple URL to remember just Blazer dotnet and it'll take you to our main blazer and I guess landing page and we can go to this get started documentation and this will walk you through everything that you need to do to get started with blazer all the stuff you need to install and if you're on a Mac like I see that you are there's a tab there that gives us to do for Mac that has all the steps for getting Visual Studio for Mac set up with blazer so it's already installed dotnet core 3.1 and actually since you're here I won't read this I'll just I'll just launch Visual Studio and you can walk me through since you've already done it you've already installed Visual Studio from that you have dotnet core 3-1 on your machine which comes with Visual Studio for Mac so you're all ready to actually to go with blazer development right now alright so since I got 3.1 installed I already have a blazer server template and if I didn't see that there I could actually just find that in just the regular app templates blazer server under dotnet core that's right oh ok didn't see it's already targeting 3.1 they have a little authentication tab so on the latest preview of Visual Studio for Mac we they now have support for the authentication options for blazer server so you can create blazer server apps that support auth using asp.net core identity cool all right I'll go ahead and initialize one I called it blazer at seven that's a one seven just my favorite number it's nothing to do with the precise number of times we practice nothing at all just lucky it is so this will create you a new blazer server application it's all ready to go a blazer surfer app is just an asp.net core application with a couple of additional things wired up to support blazer server why don't we go ahead and just run it so we can see what the application looks like yeah that sounds good so the visual studio can now build your application get it running you can debug you have full support for blazer development within Visual Studio for Mac once this gets building and actually running we should see a sort of you know standard single page app style style UI and give it a second it's coming slowly will blame blame that on the browser yes you can tap around you have different tabs for different different pages this is all being handled through client-side routing on the home page you have some simple static markup nothing too fancy going on there on the counter page though you have a a button that you can click and as you click the count goes up there's no page refresh happening here the Dom is just getting fluidly updated normally that would require some JavaScript to do but that's all happening using c-sharp and on that neat not to see how that's working yeah and then this is fetch data page is basically a dynamically generated table of weather forecast data so let's take a look at that counter page so that's implemented in this counter dot raiser file and you can see it's pretty simple it's mostly just H standard HTML markup at the top it says that this is a routable component so app page says that we browse to slash counter we should end up here so if you go to the browser you should see in the URL at the counter tab yep slash counter that's where we're at and then you have some normal HTML markup we've got a button that we can click and there's that onclick attribute normally that standard HTML onclick attribute would have some JavaScript in it but here we're using razor syntax a little at sign to say no no I would like to use some c-sharp we've got c-sharp code here go down to that and it's pointing to your c-sharp method increment count that's incrementing the current count field which then gets rear-ended on the page now to show that that really is running c-sharp code whenever every time we click that button set that breakpoint let's see we can hit a breakpoint counter page yeah there you go we're in our C sharp method neat writing client-side web UI using using blazer let's see what else is going on here well the nice thing about these components like all these don't razor files they they get turned into normal dotnet classes as part of the build and now you can reuse them like you if you wanted to have another counter component someplace in your app you can do that by just adding that component wherever you'd like it to be so for example if we wanted to add a counter component to the home page like let's say we wanted two counters one on the counter tab bone on the home page if you go back to the let's go to the index dot razor file that's the home page for the application okay so here it just has markup there's nothing really interesting going on but let's start typing bracket counter angle bracket counter on here so yeah and you can see you get awesome intellisense in Visual Studio for mac and now it's showing up purple that's that's signaling to you that this is a component yeah you know what a blazer component if we rerun the application is purple or brown I think I might be a little bit color dot net purple everyone you learn new things about how you perceive the world yeah okay so I added the counter component and I'm going to go ahead and f5 again and so now when I go to the index yeah it has a completely new component a part of it so I didn't need to like copy in the counter code or anything it's just inheriting that component a reusable chunk of UI you can click on it it works just like the other one did and if you go to the other counter page you see it has a an independent count that's separate from from counter on the home page you can also pass data into components like components can have parameters to define a parameter on the on a component let's let's go to counter and make it configurable you parameterised how much it counts with each click so to do that you just add a property and the property can be made a component parameter by attributed it with the parameter attribute gotcha I have a little tip I want to show in here Visual Studio for Mac does indeed have snippets so if i just type prop and tap Todd OH it automatically loads in my property okay save some typing what st. yeah and let's call it increment amount I think would be good and let's default the value of that property to just one yeah give it give it the parameter attribute to that's that's cool that's what's really gonna make this a parameter for the component that we can pass in so by default it'll be one and now in the increment count method instead of incrementing by one each time doing a standard increment will increment by increment amounts of current count plus command amount perfect you get lovely intellisense for your c-sharp code inside your razor for local variables now go back to the index page and let's use that parameter let's pass in an argument so if we go to index now just add some space after they are and you can see incremental mount shows up wait way you set parameters and blazars just using standard attributes in tax and now the counter on the home page or in commit by 10 whereas the one on the counter tab should just default to the standard increment domenica the one i just kind of chose 10 I hope that's a good number that is a great number 10 times better that was before and we should see okay let's check this yes and now it's incrementing by increments of 10 whereas the counter on the the counter tab should still be doing by 1 because we didn't pass of past any parameter value the houses working like we said this was all based on that magic real time pipe we can actually see that happening if you yeah inspect the in the browser dev tools let's look at the network and if do a do a full reload so we can see all the stuff that's being downloaded holding a shift key or something there we go so you can see that this app's pretty thin it's not downloading very much stuff it's just a little over 400 kilobytes of download and all the magic is really happening in that first request that underscore Blaser WebSocket request yeah you see when you look at the messages you can see there's all these binary messages flying on that WebSocket connection yeah it's updating as you speak if you clear it lets clear them all out and then go click on the button on the sorry there's lots of try the yeah a lot of work yeah then click clear I'll click me thank me but nothing you clever every time you click we send the UI event to the server your counter component gets the message it rear Enders itself and then the Dom updates get sent back to the client that's what's happening here this is how that's how this app is working this is ablaze every base that cool so that's that's counter now I know if you go back to the code real quick on the counter dot razor file some people really like you notice that there was that act code block at the bottom yeah right there so at code that's basically a chunk of code that's going to get added to the generated class for this counter dot razor file it's like a bunch of class members and some people really like that that code lives in the same file because all your UI codes in one place other people would prefer to have that in like a normal C sharp file like in a code behind file which is totally cool you can do that in blazer as well what you can do is add a let's add a c-sharp file to the pages directory let's call it counter crazier dot CS that's sort of this the standard naming convention for a code behind file look good yeah it's good what it automatically put it underneath I put a whole bunch of they got Razer license information I was messing with my header demo later today for the productivity talk a delete that we won't you don't get to see this yet you have to wait till this afternoon I'll talk about how to put header and we don't automatically license like all your c-sharp files I'll get at it no no no that would be bananas right specifically chose that mighty license cool well we have a counter a class now now this matches the name of the class that would be generated from counter dot razor so let's make it a partial class ok grab you grab that code go ahead and grab that that's fine go ahead and copy that out of there and we're gonna move it into here we don't need the constructor so we can just copy over the constructor but make the class a partial class so it'll be combined with the generated class for the component and then you probably need to resolve some namespaces right and I can do that with alt enter so that opens up the little light bulb that I get so I can automatically add using beautiful so I guess all the normal C sharp productivity enhancements and features now are available to you in this I'm getting another little suggestion so this actually might have annoyed some people and I did this originally use a compound assignment it was all part of my plan yeah so vo Cermak gave me the suggestion that I can simplify that it does look better yeah well so this should be the same as what you had before like there's no difference in their code it's just that we've refactored they run it to prove it yeah go ahead and run it to make sure it's still working that's pretty nice like the C sharp so I've got a lot of nice features my gosh all of the little things that's what I work on that's nice t-shirt little things productivity that looks like it was before so she should still have like you know income increment looks good what other c-sharp stuff can you can you do and in yester Mac does it support all the the visual studio it does so right now we actually share the same editor so basically everything that we've added actually latest and like Visual Studio and Windows 16.5 preview 2 I believe is what we're on all of those are actually already piped into Visual Studio for Mac I can demo those later today with Mikaela there's a whole talk on that yeah there's like a shared editor so it's all piped in okay yeah so like like adding an overload like is that is that oh yeah so if I do alt enter um our keyboard shortcut to open the little tooltips I can't override sorry terminologies do something like as you can see all of the component life cycle events in this UI like the on initialize on parameter set these are all standard events in the life cycle of a component so yeah if you wanted to like run some code when this counter component is first and after it's initialized you would override on initialize or on initialize async if you have some async logic I think the fetch data component actually does that so this is this is the component that was generating that dynamic table of weather forecast data and if you look at the bottom all the way at the bottom there's a yeah there so you see uninitialized async there's exam distracted by how cool it was to have a c-sharp for each blue printing out your people we're cool okay continue so yeah there's uninitialized async that's that's when this component gets initialized you see it's using that weather forecasts service to get all the weather forecast data where's that forecast service coming from if you scroll all the way back up to the top there's this @inject directive what @inject is doing is it is a way to do dependency injection into your components you can get services that you've configured here we have a weather forecast service that we're injecting into this particular component and then below it's just normal razor syntax lucky where you were saying it's mostly standard HTML markup but intermingled with C sharp logic statement yeah if statements for each loops like we're just looping over each weather forecast instance to generate the rows in that table that's how that weather forecast table is being generated super cool so we started sort of to get more into realistic scenarios this was just the file new template is the basics they're like a level 2 app that we can use and show us short so I've been working on a recipe app in Glazer to like you know manage the list of recipes and do recipe ratings and those types of things why don't you pull that up yeah that's my repo you give you guys one if you want to download it and see my code like ok got it best for you recipes best for you recipe all right so let's see if I can open this up now usually I've been developing this on window is actually on Visual Studio but it opens great on Visual Studio for Mac builds runs debugs all those things just work as expected once this opens up why don't we just go ahead and run it first just to see what the app is capable of I'm gonna wait till I load my workspace documents perfect and maybe restore my new get packages that's probably always kind of always that restore your new get packages before you build and run its lifestyle choice okay so I'll try to it's saving might have gotten a weird thing well we're yeah we for that we can go ahead and look at the home page of these let's sit let's open on index dot dot razor so we can see a little bit what the when we see the app we'll have an idea of what the code looks like this is the home page for the application and you can see at the top it's mostly just there's a search box and then a little bit of an if else then just to see if the recipes have loaded and once they've loaded it's just generating an unordered list with the list item for each recipe that it loads from a recipe store and again we're using dependency injection to get a recipe store service and to initialize the the list of recipes so that's all that's doing that search box at the top is a custom component for handling the searches once you scroll back up to the top and we can look at that real quick yeah so you can see that on the search box we're passing in normal HTML attributes to like specify a placeholder but we're also able to specify a delegate for when a search has occurred so that we can hook into that and actually then run the query against our store so looks like the app is now up and running yeah so here's that home page that they actually read beautiful nice nice images design is not my forte you can put down recipes you can see details about the recipes some basic functionality you sort of search bar search for chocolate stuff yeah now notice that as you type the search is updating like you're not hitting enter as your house your typing is just looking at the current state of the search query and running a search but it's not doing it on every single keystroke it's like a little visible pause then it waits to see if you're done typing and then it does a search and that's nice because it's throttling all the searches to your database you're not just hammering the database with every single keystroke so it's interesting to see how that's implemented in Blaser if we look at the search box component that's where all that logic is encapsulated so search box that razor there's off now this is that component that just implements the search text box and it's handling all that debouncing logic where every time you search it'll wait a little bit until the even two you're done typing so mostly you can see that this is just an input like Scrolls we'll see the mark up at the top is an input and that's not about timers yeah and it's bringing in the timer's namespace the attributes attributes attribute there what that's doing is allowing you to grab any additional attributes that are passed on the component and sort of splatting them wherever you want them to be that's how that place total holder attribute is getting on to the input and then that app bind is binding the value of the put to the search query text search group property so as you type blazer we'll see that the text has changed and then set that text on to the search query property which I think you have below yeah right there it's actually even specified as a parameter so if you want to pass it in you can do that and we know that it's gonna do that on every single keystroke because after at bind back at the top at the end of the the input all the way the end see that at bind : event that's specifying which event we want to use for the bind like by default we will do it on change here we're saying no no no I want it on every single input every time you type please update the value of the search query uh property and then now let's look at search query cuz there's some of that's where the little bit of cleverness is happening search query when it's set like when the value gets bound it just starts a normal net timer and this is just you know like you saw up above system timers or whatever whoever the name space is it's a normal dotnet timer from the base class library where it will stop the timer if it's already been started and start a new one and if that timer completes then you know there was a pause without any keystrokes hit and that's when it'll actually call back into the the search query changed then call back that was passed in so I thought that debounce parameter there about 300 milliseconds that's that's the the amount of time we want to wait and you can see in an on initialize there's that component life cycle event again that's where we're moving up the timer setting up the defense time frame and wiring up the event handler for when the timer actually completes so all the event handler does is call into your delegate that you passed in and then you get your search results that's the balancing logic and you know 50 some odd lines of code all done in c-sharp no JavaScript required that's great and so should we go back to slides are we short on time I think we want to make one change oh we got five minutes okay let's make a change to this out okay so um if you go back to the yeah let's go back to the app and look at the reload oh right I stopped yeah so the we can click on the recipe that brings you to a recipe details page okay and most of that's just markup and there's even a form where you can do star ratings but there's also these tags and currently if you click on a tag they are links but they don't they don't go Oh like they don't think okay so what we want to do it is it is going to a new URL it's going to slash tag and then the name of the tag that we that you clicked on let's wire that up so that we actually end up on the search page but with the correct list yeah of recipes okay so go back to index dot razor what we want to do is grab that value out of the URI so in order to do that we're gonna add another route so add another app page directive and make a slash tag and then slash now if that's in curly braces cuz this is the value we want to grab out and we'll call the value that we're gonna grab out tag okay now to get that value we're gonna bind it to as a parameter on this component so add a new parameter remember we added a property before to create a parameter do in the code block let's create a new property so property anywhere thank you drink call it tag okay so and then put the parameter attribute on it so now what the Blazer will do is it will take the value from the route and set it on that property so now we can just pass it in to the get recipes yeah it's no it's not specified yet then we probably just will pass empty that will give us all the recipes when the attack is initialized one more thing is up above in the in the search box let's make sure we populate the search box with the tag if there's one there so set the search query parameter a little space in there [Music] sign and tag oh so we're actually getting into the c-sharp property there you go that's all you so now it should populate the tag so go ahead and run it okay let me start it and that should populate the search box with the tag as you click on tags that will filter the search to just that tag whenever you click on a tag like on the page and it should be just that easy okay so click on a recipe let's go down to the tags let's know fruit there's only one food that that works and it populated it you just added a feature to my heart right you're welcome now top back to slides real quick sure so that was getting started as blazer and some blazer in action um we know the number one question on a lot of people might people's minds if we have time for Q&A and stuff as um what is an expert blazer webassembly when wouldn't cute when we get it when will it be out of preview yeah so so this was all blazer server work that we were doing with Visual Studio for Mac Visual Studio for Mac fully supports blaze a server which is great blazer web assembly is still in preview it hasn't shipped yet it is the the focus of the blazer team right now and we are planning to release it in May of this year as a supported release and that will include full support in Visual Studio for Mac the initial release of blaze our web assembly will be based on dotnet course redone in fact we plan to add the template in an update to the dotnet core 3.1 SDK it will be a current release not on LTS release so it's not gonna inherit the LTS status of the rest of dotnet core 3.1 it is the first release of blaze or webassembly we want to give it a little bake time before we bless it as an LTS release to try and make that clear we're going to update the versions of the packages to be 3.2 we've actually already started doing that so the latest previews our version does 3.2 after may blazer web assembly will become part of down to 5 and will then be just part of the normal dotnet update release cycle so you just need to remember to keep clicking YES on that update prompt keep updating and look in May for the the released version of a blazar webassembly got it so in summary we talked a little bit about being productive in blazer on vs or mac blazer server is what we show today it is in production you can go and use it with dotnet core 3.1 and get excited for May 20 2002 a time question in turquoise that's exactly I'm glad I actually start with a statement somebody said I won't Don Ross Visual Studio you know what we have some exciting t-shirts for this event and we'll be giving them out as part of our party so make sure you stick around for until the end of the day so notice but more and we actually have some questions as well so the first one is habeas from a is there any way I can explore on blazer webassembly in Visual Studio Mac that we were just talking about that you can actually open a blazer webassembly app in vs for mac today you'll need to do is the a smith core hosted version of the template the standalone version of the blazer webassembly template isn't working just yet mb/s for mac but it will by the time we ship blazer webassembly in the May time frame you don't have the ability to create laser webassembly apps from vs for Mac just yet but that is coming as well so you can create apps from the command line as long as they're hosted in a nascent core app and run and develop your components and all that the rest of the functionality will be cut will be coming later as we get closer to the may release that's great well there you have it and next one is just close this one down is there performance benefit using blazer server over a blazer webassembly yeah so blazer server runs on a full dotnet core runtime your components are running on the server so you get all the performance benefits of dotnet core which is honestly one of the fastest stacks on the planet it really treats the the client machine also as a thin client so it has very little requirements on the client side of the of the application blazer webassembly runs on an isle interpreter based runtime today so if you have components that are doing really computationally intensive stuff it can drag a little bit when you're running that type of code in the browser so you might want to offload that to like a web api somehow on to your server so you're running on the folder core runtime perfect I think we have time for just one more question so yep question is is there a benefit using blazer over angular react or some other spa oh yeah I mean you see sharp yeah context you get all that syntactic goodness like productivity features in Visual Studio yeah it's a full stack solution for web app development with net and c-sharp I think also there's just a lot of really nice simplicity that comes from the the blazer programming model and tooling like it's really easy to get started file new project and you're up and running in less than five minutes so that can be really nice that said if you if you love angular and react in view and you want to continue to use those for your front-end development you can absolutely still do that and still use net core for your back in api's G RPC services signal our hubs and so forth great well thank you very much for your time it was fantastic to hear about all the Blazer cool myths out there and I'm looking forward to the 2020 build announcements that we're probably gonna have
Wednesday, 23 October 2024
Build Time Reflection with C++ in Year 2023 Pure Virtual C++ 2023
so next up Gabriel dostri is going to tell us about build time reflection with C plus plus in the year 2023 hey Gabby welcome thank you for coming once again have you have you been a talk every year so far I think you have yeah I'm I'm happy to uh to do it you know I'm passionate about it and uh and modules then you know anytime okay well I'll take it away okay so um you've you know as you know I've been talking about modules since uh 2015. and back then I've been busy telling everybody oh modules are great modules are truly an opportunity and uh and and that kind of stuff so today um I wanted to briefly uh tell you some of the awesome things that you can do with modules not just because your code looks better but what you can do with let's say left over of modules not real level but build artifact when you when you build your modules the compiler generates a bunch of satellite files information that it uses to process the rest of um of the program and and that build artifact is not just good for the compiler it can actually be good for you and one of the things you can do with it is to have your own reflection um I know that in the C plus plus Community we have been wanting to have a study reflection for for a while now and uh you know in my private take another couple of years or more before we get it but in between now and then what can you do so here I wanted to tell you you can do a lot of stuff um that don't actually need an upgraded compiler so so a reflection you know when a notion of reflection is just the ability of the program to uh examine query uh introspects and and not just that but also manipulates uh its own States and and structures and and behavior based on the questions that it asks itself and that's quite fairly General and some degree uh abstract but when you look at that definition you have the notion of you know introspection which is just really good query not modifying anything at all and and and indeed introspection is is just that part of uh reflection and some people say oh no you know introspection is not reflection but you know um it's usually is easier to implement uh you know we already have that in C plus plus and yeah of course you have it in other languages but in C plus for example you have um uh runtime tab information when you use tap ID on an expression or a type the compiler uh created data structure uh that it embeds in your program and then at the wrong time you can query the type and a bunch of other stuff um it's it it's something that's quite nice and you know allows um expression or something ideas that's quite easy to do as long as it is well supported when it's not well supported that's where you get a bunch of stuff so the general idea of of reflection introspection there are Notions that can be practiced at any stage of the uh development of of a program whether it is uh during pre-processing stage you know that you can use uh the string signification operator from the macro preprocessor to get the string of of a name right and and you can do concatenation so you can actually it builds more and more stuff and um you know in program you can use straight we've been using trades since uh C plus plus 11 you can query states of the of of a type or an expression an object decal type is one of those uh introspection uh operator same is no except wood and expression Ray is an exception for example so those are properties of a fixation and then of course you have runtime Behavior if you perform a dynamic cast for example that's during program execution and and the the compiler is required to generate data that embed your program in executable and and runtime it carries some operations try to find the right uh type that you cast into and and people will tell you well you know reflection is great but it doesn't it's not free it costs it costs stuff like compiler really has to embed something in your program and that can be a gigabytes so sometimes you will say Yeah in fraction is great but I'm not ready to pay the price for the additional uh you know object size increase that okay at runtime um I'm gonna Hannah cassette uh we have been waiting for uh some notion of static reflection for a very long time and some people are tired we have systems deployed that have their own meta protocol if you know the cute uh GUI system framework for example you know that it has the mooc compiler that nanometer objects compiler that look at your program and then generate supporting infrastructure to make sure that your slot and signals are connected and everything is is working uh properly that's just one one example um so if it has been taking that long to do how hard is it really I it's a type you know just associative value how how can that be the um the truth of the matter is that um if we just look at introspection for example runtime introspection um you know we have runtime RTI for example or any exceptions you can think of them as some kind of continuation uh the where you have program points State program point I want to jump back to uh later and then turn that to data that that you manipulate well what I'm doing here that is is it hinders optimizations right the compiler can't reason saying oh this thing exists there I know the structure and I can come back to it otherwise when I come back to it I can right away uh inline it or or move codes around and so forth so a cost and and furthermore uh you know one of the debates in the C plus plus Community is whether you should ever um enable exceptions or uh rcgi at all you know like type IG because well it you know it makes your program bigger yeah so we know we have uh evidence that a poor implementation of these facilities can actually be detrimental to actual adoption and it takes time and efforts to implement these things properly so it's it's non-trivial uh uh you know investment to make um now when we're talking about reflection so remember in introspection is just ability to query observing without changing the the state but reflection you not only doing query but you also want to modify the behavior of the program or generate new stuff based on what what's the well it's enough magnitude at least much more difficult uh you know in terms of deployment implementations and and so forth and once you have a you know reasonably good um reflection system in place it becomes much harder to evolve the um the language because well some of the construct that you knew when the program was compiled they were turn into Data embedded and if later you embedded in your executable if later somehow you you bring in component that was compile in the future or in the past and they do not agree on on on the protocol while you get into real trouble so once you have reflection in there and features or functionalities that are reflected become much harder to to evolve properly uh so that lead to people to say well we don't really want runtime reflection because you know we know it makes the executor much bigger and and it has much of her stuff well we just want static reflection which just means that during compilation um you know the we noticed that compiler already has those information as it's under this structure we just want to be able to um poke a little bit and then ask the compiler to generate a little bit more code but based on what is known at the time of compilation so the revolution problem is probably more reduced but you still have you know substantial work to do on a compiler so we know compiler writers C plus compiler writers we can fit them in a room and then we have millions of C plus programmers so if you can just get a couple of people suffer for they create a good of everybody else so be it so that that's good and having studying reflection you know mitigate you know many of the drawbacks that I mentioned earlier including performance and and space which is part of why uh the the standards committee and and the community as a whole have been pushing for for this for this notion um here to talk about real-time reflection and and and not static reflection and and some people are rightfully say why the hell is this thing that I'm talking about well it is not a new language feature it is not what it is is just um not making no just being you know very responsible with the resources that we have so the idea is that um as we're building the program you know during build time we we generate build artifacts and we would like to be able to augment the program the final program with uh information that we know during build time so we can generate new codes uh that gets compiled and linked with you know the the rest of the the object file that already exists to create the final program so um it's it's really involves real-time code generation and it moves the the burden from a compiler to the programmer so you know if you're interested in reflection one of questions that you should ask yourself is how much of the work that I'm asking compiler writers to do can I take on myself and how much of that can I get the community like you know help develop and and that is what you know this is about now what can you do based on what is known during build time and so the the way if you want to do build time reflection you you have to structure your your build program built uh in certain way you start with already known uh source code uh it could be you know human altered or you know machine generated and then you compile those things and then you let's say for example you have a module interface source file when you compile it you get what we call builds module interface or BMI uh or if you're using msgc we'll say you have an IFC file well that built uh build artifact contains a lot of the semantics information that compiler knows and it is possible for you as a programmer to go and crack open it and then generate new C plus plus source code that you can now get fit into the pipeline of build pipeline to augmented program and you do this iterate this process as long as you need till you don't need to generate more stuff and then when you when you link everything together uh you get a system that is fairly powerful it doesn't give you everything that static reflection will give you but my hypothesis and conjecture is that it gives you nearly about 90 percent of what we have been waiting for so it's a good thing to invest in um the for this to be successful you have to be mindful that because you're generating codes your build system how to support you know automatically generated code you know most of your systems about that and if somehow uh you're still running your own build definition by hand maybe this is the time to reconsider your your choices and see if something else can help you there okay and and another way of looking at build you know time reflection is let's say some form of grain Computing like you when you imagine you're using all these things and and then something was generated authenticity and you're not leaving it good to waste you you're reusing that information the same information at the compiler had before you two can can have that and with modules it it is there anyway like it's not additional work that we are asking the compiler they compile already did that works so we'll just being very responsible with the resources that that we have um so uh now I want to just illustrate the the idea of um uh build time um you know Reflection by using a very very simple simplified example the idea is not so much that I want to trivialize the problem it is to convey the basic of the idea once you get it I trust you that you'll take taking a run away with it and make it as complicated as you are that I trust you with so I'm just going to use a very very simple example so don't discount the example just think it is just a way of doing something it's a template and you can use it and magnify it to instantiating in other situations so the the example that I want to look at is um imagine that you you have a program uh rewriting program that has bunch of types and somehow you need to do a lot of formatting IO for formatting because you're sending data you're doing distributed computation you're sending data or network or you're saving uh you know data on file and and then bringing it back later imagine you're doing game developments and you want to save some save some characteristics of uh characters in a game or skinning and and so forth well how do you do that kind of IU thing automatically so that you don't spend your time you spend your time so you spend your time actually programming a game as opposed to doing work that is best left to machine so um the example I'm going to give you is using of course modules and what is what I use so um for this to to work properly and and and to scale we can't just go uh through the entire program and then generate IU formatting function for every single type that we find in the source file that just doesn't make any sense even I don't even compile and if it does it would just be waste so we need an ability to annotate in this this Source program hey I need something to be done automatically for this type okay so we need the hints whatever it is if you were designing a new programming language you probably need a keyword or something but remember I'm not here to talk about a new language feature I'm here to tell you what you can do with the existing language when I say existing language I'm mostly thinking about C plus plus 20 C plus plus 23 which should be out very soon and and you already have compilers out there supporting Gustav uh 23. so the ability to selectively tell the the tool the system to generate certain code for something will help reduce code blocks um and do we by doing so we also improve efficiency overall efficiency you know that space is time if your binary is Big it's probably going to hit up a lot of uh um space cache lines and and and so forth so uh take this very simple example imagine um I'm dealing with um uh points on the plane a planner geometry and I have a struct points then the usual thing have a coordinates you know X and Y of course I will go and write my own formatting function but it's boring it's boilerplate we want to increase your productivity we we want you to delegate that boring aspect to a tool just Define your abstractions and we'll take care of the rest that's what reflection is is really good at so in the example that I'm showing here like you said earlier we need the way to annotate so here I'm just using an attribute on on the type definition here the struct point to D have this attribute say uh gdr generates outputs so this is just some kind of you know DSL for me to to to to tell the tool to generate uh IU functions for for this type I don't want to write that function I want the tool to write it for me and what will happen when I do that is something like the following the the tool this you know so that helps me use uh real-time reflection will generate a new module source file it will take the uh the inputs module here the plane the geometry and he loses that name and then as basis and then we'll add reflected that output usually when you have [Music] um uh tools it's good if they they can predictively name things right and then the next thing it does all this is generated source code and say Imports to remember with C plus plus 23 now you just see import student then and then you move and do whatever uh you need to do um and you you can use this thing today like impositude works today uh if you download the uh um the msgc compiler and using your Ms build or using cmake it will take care of all of that and then the next thing it does uh they've told us is generate this function operator less than less than it takes an IR stream and point to D and then you know formats the the coordinates of the points in crystallized way and if you look at the code carefully those places are like green text you'll know that the entirely determined by the structure of the uh the class the destruct that that's here the name member and Absol so it is purely mechanical and this is something that a tool should do for you you do not need to do it the fact that the language the based language does not have this facility built in is yeah it's a shame but it's okay we can get the tools take care of those things that you can have here so like you say this is uh this is just a simple example but imagine you do not want a Authority like this you want let's say in uh Json format so you you know you'll have your tool generate the codes you know using Json library or if you want to have a banner representation on disk or you want to sign over to network now all those things the boilerplate that have structures like yeah templates that can be done automatically for you and the only thing that I so this is source code that's generally the tool and I have to make sure that my build system knows that this source file is going to be generated by the tool so that it schedules it's built properly the other thing that I as a programmer need to do is just to write my main you know program that's using this thing so plain geometry that module is something that I ordered that was input into the tool then the tool will generate automatically for me this or a module playing geometry reflected output that now I can just import an Imports to it again and I can just use um the uh the insertion uh if defaulting operator that was automatically generated based on the structure of of the class that that was defined so this is a a concrete example it is simple I agree but what I'm trying to convey here is not how sophisticated it is but how simple things can be okay and and most of you complicated um situations where you want to have static reflection you can structure the code in a way that you can actually use your system by carefully uh putting you know designing interface that so that you can have this cycle that I mentioned earlier how you orchestrate the build so the summary of course the io stream example is simple but it is a temp again it's a template you can use you can generate Json yaml if you're doing gaming game stuff is where you have a lot of Need for reflection stuff because you have types that you define in your source code but they represent stuff that you want to you know associate property is wave and and anyway that is mechanical so you can actually have a tool do these things for you these functions that are doing yeah the the the the output uh function they are automatically generated so they are always up to date with respect to the uh the type definition that is in your program right so you don't have to worry about it and and also if you happen to change the field or something you do not go you don't need to go and enhance 25 places to try to do you change those things the tool can just automatically generate everything for you and you can deploy this today we do not need to wait for another two three or five years you know decades to to get reflection and occur because this is simple enough that it can be taken care of and we can have your own like if if this doesn't work for you you can have your own generator based on the logic and the needs that you have that's the beauty of it you do not need to go and extend to the compiler you just need the compiler to tell you hey while I was building that module this is what I found is that useful to you and say oh yeah great give that to me I know how to use it okay so um all of that is kind of very high level uh description of how the code is is generated when you're using the msvc compiler and you build a module it generates an IFC file what we call builds module interface in you know standard terminology the msgc format that is the FC format is publicly documented as a matter of fact we want the community to really you know use it extend it and however it is specific a couple of years ago I gave a presentation about how you can actually decompose an IFC file and in another talk that's interesting that for you to see is one given by my colleague uh a camera on the camera and the way he he showed you know a a viewer of an FC fire written entirely in JavaScript so it's not even C plus plus right so when it when we say modules are truly an opportunity your tool doesn't need to be written in C plus right it can begin in language yeah you want as long as you can read a binary file okay um the one thing that I the last thing I wanted you to know before I go out is please start using modules today especially with C plus plus 23 where you don't need to remember which header file you need to include this and that no just say inputs to do boom and furthermore it is much faster the build time is improved because the the the the listed module which built once it's reused many many times so the combat doesn't need to re-pass it all the time it is simpler to use SPCA if you're on PCA today I really invite you to start considering using modules and and if named modules are a bit to still be step for you probably start with header unit but really what a game is is not named modules um there there is to be a a GitHub repo that contains all resource code that can use as inspiration that demonstrate what I just talked about and please call it extend it use it any way you you want and uh and give me feedback well what else would you like to see do you want an SDK how what are you going to do with it let me know um and and finally the IFC spec is is there on GitHub as well it you know it's for the community to develop contributes and and and and give feedback um with that said I'm I'm ready to to take questions thank you so much um so we've got a few questions in chat uh we have one from Antonio who says reflection is a fish hard to sell uh why not show some code you showed some code this was from from about halfway through um what arguments do you have on what there is to gain by using reflection what are the use cases for reflection C plus plus oh okay yeah so um not everybody needs reflection but the first thing I have to admit now clear hey not everybody needs reflection um I in the talk I gave the example of uh formatting that's just you know every time you're doing IU many of these types they have a photo certain pattern and they're very repetitive and you can get that automated um if you're doing gaming uh you have types the characters in your game they they tend to have properties values associated with them and you can have that saved on disk and read back automatically again the way you do that is very very structural and best done by tools if you're doing um this really competition these days we talk a lot about AI well AI is very computer intensive and they work when you're doing it work you're going to the best way to do it is you distribute it work so you have to send data over Network how do you get that done properly and and making sure that yours the data you're sending it starts everything is in sync best use you know a reflection to take care of that for you so it's not so much reflection in itself it's a tool to take care of boilerplate so that I can focus on the most creative aspects you know the joyful part of programming thanks and then we've got uh a few questions from milosh she says um do we believe static reflection would allow us to finally get rid of macros or are we cursed with uh hash if defined I'm just going to Source clang for the rest of time well okay so uh modules take care of you know a good chunk of the Democracy sorry if they have that kind of stuff taken care of by module now when we're talking about um compiler specific characteristics like you know certain features are available only on client or gccms you see uh those who will still be there um but when we're talking about code generation one of the things I I don't like macros but I also have to confess I use macros as a way to generate codes like generate sequence of tokens that are compiled by uh by the compiler well my sincere hope is that we will get a good reflection static reflection system that will take care of that huge sword of Need for um uh code generation then what is left is probably unstructured uh code sometimes you just want to include some text it has no structure to it well you still have to use you know macros for that but having something that plays by the language rules that your ID understand your group system understand is much better than having this you know character string manipulator yeah for sure and um of the the reflection repo uh you're going to pitch that live after the talk right yeah so yes yeah cool um another question is uh more theoretical but do we think it would be smart to have a pre-build step that is going to do this generation so that the IDE knows that these things exist yes I I agree yes yeah yeah it you know that's actually a good point um we talk a lot about what Reflections they great but they also add complications to the uh IB um experience where certain functions that you know now available at compile time or invoke that compile time need to be understood by the ID in order to provide um you know better experience yeah absolutely and then another more General one for everyone and a good introduction to compiler development on that one I'd recommend the book um crafting interpreters it's yes absolutely it's about interpreters but like it's mostly like all applicable to compilers as well you can like read that book and then pick up something a little bit more delving deeper into compilation techniques like uh engineering a compiler or modern compiler development in ml or C or Java whichever one you like for for some of the more compilery things but crafting interpreters is just such a a well-written and structured book that I recommend yeah 100 agree and and if anybody you know you know you should take size advice on it like this is great um and if you do it you'll find out that if you're writing an interpreter um and you want to do let's say IU for example because YouTube reads your you'll find out that you need a way to reflect the facilities in the sea headers on the C plus headers in your interpreter and this is another place where actually reflection help you write simply your interpreter that's fantastic second cat of the day here actually her name is lexical analysis cat so Mexico analysis and uh yeah uh anchor asks what compilers does is the question about GCC oh okay my my apologies they the only reason I didn't mention so I think on the last slide I said that uh use modules today you have cmic build system supports um and and they have built system support for msvc and client it comes in box uh for GCC it's not because you know it's more like the necessary support is not there so I didn't want to leave people on on something but you know you should also be mentioned that GCC also has um in support for modules okay and then there's one more on what compilers does gdr generally work with oh so uh the all the examples are built with msvc so the IFC format right now is very specific to admsvc compiler um you know I use my private you know Network private um build to do that so whatever preview is there as of today will will work um I would like to see the community um coalesce around a common format for a module bureau's module interface whether it is IFC or something else doesn't really matter but being able to have these tools work you know cross-platform cross compilers is is fundamental for for us the C plus probability to realize the uh the promise of you know modules being uh during opportunity yeah and I think that answers the next question as well which is could this work be implemented for other compilers like GCC and clang yeah um so the IFC spec is is is public and if someone feels energetic enough to to get a fork and and and generate uh IFC out of it it will work um you if you do that you do not need to change gcc's own internal representation you do not need to do that that's good it's one of work now what you will need to do is just ability to translate the IFC data structures into gccs or tax internal representation I think if I were to do that that's the way I would do it I will not uh sign up for every student right this is your client you're using obviously no no just ability to read all right that's it and then um still got time so another question is could the IFC spec be put in the C plus standard uh probably not C plus 26 or C plus 29. of course I would love that uh but the reality of thing is that from something like the LC you needed to evolve as quickly as possible the way compilers evolve whereas the the standards tend to be on three or six years raw so um if it could just be some kind of de facto stunner I think that will take care of all the Practical needs that we have and then let it evolve as quickly as it can and I would really love to to to see something like that happen great well we are out of questions and almost exactly on time um we stayed on time for the entire thing kind of thing suspicious you're running this thing quite well yeah it's our fourth year we're getting the hang of it so thank you very much Gabby thank you for everyone who has stuck around and watched all the talks uh these will be put online um on the the visual studio YouTube channel so um please keep your eye out for those going live and uh feel free to share them around if you have enjoyed um so thanks very much and hope to see you all next year
Brad Anderson's Lunch Break s7 e15 Outtakes
- So a lot of corporate leadership coaches ask this question. I'd like to get your feedback on it. - Oh, yeah? - If you had to pick you know, one Golden Girl which one would you be? - Rue McClanahan, she was the sassy one. - Uh huh, that would be you. - That'd be me. - It's lunchtime, and this is Brad Anderson's Lunch Break. Two of my favorite things about Microsoft are the smart people that constantly visit campus and the great fleet of shuttles. Whenever I can I try to take advantage of both of these things and I grab lunch with some of the tech industry's best and brightest. (upbeat peppy music) Okay, so let's have a little fun. You and I can play this game called This or That. - [Nicole] Okay, fantastic. - [Brad] Epic. - I said fantastic. This could go off the rails. - Oh, this is fine. So I'm gonna give you like two topics, and then I'll give you some kind of word or description. You're gonna tell me is it one, two, or both. - Okay. - Okay? So your two terms are transatlantic flights. - Okay. - Or World of Warcraft. Okay, do you know much about World of Warcraft? - A little bit. - [Brad] Alright. - I had to stop playing so that I could finish writing my dissertation, yes. (laughing) - Okay, alright, here we go. You would do something unspeakable in an exchange for an upgrade. - Transatlantic flight. - Okay, I think my boys would say both. You have too much personal baggage to be able to sit comfortably. (laughing) - Um, World of Warcraft. - Walking the floor at a tech conference. - Yes? - Or joining a fight club. People get more aggressive the longer they're there. - [Tim] I guess the fight club. - Yeah, I don't know. That could be both. I've seen people at the tech conference before. - It could be both. Yeah, it could be both. - There ya go, okay. You go back home and brag about how many sessions you were in. - [Tim] That could be both. - Yeah, so a big part of the work that you do is really deepening and broadening the partnerships that Microsoft has. - Right. - And so, you know, there will be a lot of CIOs and senior leaders who will be watching you know, what we're talking about here. How does the work that you do impact their lives and make them better and their organizations better? - [Peggy] I think we've had more of a focus over the last several years on the partnership aspect and kind of moving from this transactional relationship to more of a strategic partnership relationship, and that's opened up a lot of doors for us and our partners. And rather than, you know, approaching it from a transaction we can say, you know, what do our joint customers need? What problems are they trying to solve? And then that helps us look at areas of collaboration that we can do with partners, and I think the opportunities for both sides have increased. - [Brad] Totally. - Yeah, we take a lot of the friction out of it for them so if they have to do something manually that sort of integrates our two products our partner's and our own and we can put them together in a seamless fashion. Um, that's sort of a win for all three of us. - So over the years you've interviewed a ton of like, the tech heavy stars. - Yeah. - Right? - Yes. - Any one of them leave you totally like wow that was amazing? - [Tim] I did interview Steve Ballmer. - Yeah. - Um, so that was quite fun, and his character was not quite what I expected when I first met him. He was uh-- - Lot more low key in an interview? - Yeah, I guess so, yes. Yes, and I liked him actually. I think he was full of life and full of enthusiasm. I really appreciated that. - Yeah, well people know Steve for kind of like the stage presence, but when you're in a small group you know, and you just have this conversation, he really is a great-- - Yeah, and very sharp. - Exactly, just a great guy. I always loved those times I got to spend with Steve like that. We talk a lot about this transition to the cloud and the culture change that it is for our customers. We've had to go through that internally. You know, I've gotten hundreds and hundreds of engineers who have built on prem products for, you know, for some of them for decades. Now some of that skill set is implacable in the cloud, but we've had to fundamentally relearn different aspects of what it means to build cloud services, to operate them, you know, the architecture is different than a client server architecture. So we've had to go through that same cultural transition internally that many customers right now are facing as we're helping them and pushing them to move to the cloud, but we've had to go through it first. - [Jeff] I have started, and I think people would be surprised about this from the SharePoint guy, I start when I'm sitting down with the CIO or I'm on my phone, let me show you how. Look, here's, you know, see all my email, my calendar, but wait, it gets better. Here's OneDrive bring up all my docs. Yeah, that's pretty good. Here's how I share things. You know, let's keep going. Let me show you the new SharePoint app where I can show you my intranet, and I can show you my collab sites and the publishing sites, and search on people and documents and that blows people's mind. They say wow if I could deliver all that just to our users they'd be great. And they say on top of that it is secure. - [Ben] This stuff isn't really a technology barrier. This isn't really a technology change It's a cultural change. It's a huge change. - Massive culture change. - And you know, if we talk about tools or if we talk about technology first without actually addressing the fact that this about people, because we hear every company has their Uber moment coming. It's actually about how do you think about your business in terms of what your customers want and will want into the future and what your people can fundamentally deliver. So it's really about that human element and just spending time kind of thinking about the future and your future. (peppy whimsical music)
Azure App Configuration - Making Centralized Configuration Easy
so my name is Jimmy Campbell I am a developer on Azure app configuration team I'm excited to be here today to talk about our service and also to celebrate net core 3.0 I've been a dotnet core developer since beta 8 and definitely a lot of change since then and I think that a drive configuration is a great tool for a Donette core developer to add to their arsenal whether they're developing modern global cloud applications micro services or maybe just sticking in a DevOps pipeline whatever configuration is all across the stack so a centralized configuration service really makes a lot of sense so what ended up happening was we saw a lot of problems with configuration the way applications are moving today so some examples of some of these problems might be how do I centralized application a centralized configuration when I'm running on an agile function I'm also running on kubernetes I'm running on some VMs that I own and I kind of need to share settings between them or maybe something like I'm running apps in North America and I'm running in them in Europe I need to share settings but I also need them slightly nuanced because the application just needs to behave differently in North America or Europe to more advanced use cases like wherever I'm getting my configuration from how do I dynamically update it during runtime and so configuration is a very fundamental piece and there are some common problems we saw people trying to develop their own solutions that comes with a cost we also saw things like people try to use things that weren't necessarily meant for configuration and then they would eventually get to a point where they got stuck because the solution they were using just wasn't designed for that so it really made sense to make this service a drop configuration which is then in preview now since April I've yes April and we got on this and now it exists so a centralized configuration service for.net core developers specifically we offer things like a configuration provider simple similar to the JSON file provider and dotnet core things we have a STK a configuration client where you can write read settings but I think first of all what I should do is get started saying what is a Drac configuration it's a natural resource what happens when I create it what do I actually get when I start using it and so what kind of do like I getting started right now so I'm going to go into my command line and get started with a draft configuration from the CLI dotnet core has a pretty good CLI and we're all developers here so I think we can kind of enjoy the automation opportunities that come with the CLI so I'll go ahead and get started creating my first Azure app configuration so I'm using the add your CLI now as denoted by a Z and then app config is our command group and I'm going to create an azure app configuration dotnet Contin demo my resource group is going to be Jimmy C a config when I already have configured and I'm going to have a location of central us so what am I getting when I create as your app configuration so it's an azure resource and I'm going to get a place where I can store settings settings in our model are stored as key value pairs so you may have a message which is hello world or something like that just a simple key value and that's really what we stored the foundation we do offer metadata on top of that so you're storing your settings and they're available to you through a web endpoint so if you look on the configure 8 that app configuration instance that I just created my endpoint that has been allocated to me is https dotnet conf demo that AC config die oh so now I have a REST API listening on this endpoint that was allocated just for me where I can start creating settings in a central manner start consuming them and all my applications my dev anything that really speaks the rest API can start writing and reading settings from this app configuration instance and of course the CLI is one of the things that can do this we can go ahead and create our first setting here now that I just booted this up easy app config kv-4 key value set I want to set a key value so the name of my store is dotnet comp demo I have a key online create color pretty typical setting name and a value of blue all right so now we just use the CLI the azure CLI to create a app configuration instance and create our first setting alright this kind of shows some of the automation with the service so you can kind of run these things in a script or whatnot but now we're going to go into the portal and we can show the UI for this thing and we can kind of get the best of both worlds so I'm going to go into the portal here then they refresh the page we're going to see this dotnet comp demo now everything I've done in the CLI can be done through the portal and also the things that I do in the portal can be done through the CLI we look for feature parity across both and so if I wanted to create my app configuration through the portal I could have created it to create a resource and I create settings through configuration Explorer alright so here we see the setting that I created color and then blue simple sea key value pair to represent a setting and then we see some metadata on top of it label last modified content type the one I actually do want to mention before we get too deep here is is label so key value are definitely important because you need those to have a setting but label is something important to our service because it can be used when you're querying settings and it gives you a way to add a new dimension to your configuration for example I may have an application that runs a premium and a standard SKU and I might want the color to be green and standard and I might want it to be red and premium or something like that and so I can kind of model this with label it's not just a metadata it's not just like a tag that when you get it it's actually used in queries so when you query configuration you can say give me all the settings for the standard label or give me all the settings for the premium label so this is kind of what I talked about before where I have nuanced configuration maybe like a West US or North America and Europe stuff like that so label is something important for our service layer so now we have the ability to create settings we know what it kind of means to have an app configuration instance how I can create settings for it I want to go a little bit further into the portal here before we leave it just kind of get the the coverage we see some other things down here and operations such as feature manager feature manager is a value on top of just simple configuration I could probably go into that into another time but we also have some configuration utilities down here we are storing configuration and where a configuration service so it makes sense for us to have utilities like for example I need to restore my configuration to what it was yesterday because it worked yesterday but doesn't work now you can do that through the restore tab so you can select a day of what my what I want my configuration will look like for example on September 11th I didn't have any keys so it's saying hey do you want to delete these keys I can compare settings I can compare across app configuration stores I can compare across labels so like I said I have a premium and a standard app I want to compare these things I can see o of red and green and I can also do import and export import and export is really valuable it's actually my favorite thing because especially when you're bootstrapping app configuration from a dotnet core developer point of view you probably have app settings dot JSON something along those lines and we support the ability to comment from a configuration file import settings we also allow export of settings to a JSON file and this can also be done through the CLI that's that feature parity I talked about all right so that is kind of the background for app configuration the portal CLI interacting with it and now that we know how the settings are represented and how we can kind of get started it makes sense to move into a dotnet core app that's actually utilizing this and so before I do that let me go ahead and use to another app move to another app configuration that I already allocated this one doesn't have any settings yet but I'm gonna show the import I talked about from a configuration file I'm going to import some settings app config web demo Jason I'll actually show that file it's just like appsettings JSON file if you will and I imported it into my configuration store and now you can see I have all these settings here they all start with web demo : that's kind of a prefixing practice I may have multiple apps configuration set stored in my single app configuration and one way to separate them is by namespacing them so all these are from my web demo app and they all start with web demo and now I have these settings here I can start consuming them in a dotnet core application so let's move into an asp.net core 3 application that I have this is a ASP nightcore 3 razor pages application it's doing very little actually the main point to get out of this app is that it's pulling the configuration from app configuration and the way we're doing that is we're binding our configuration to a model called settings and you can see there's kind of a one-to-one mapping here refresh rate languages these these all map to settings here and we're binding them to that model and we're using those properties in our razor view so essentially we have like a one-page app pulling configuration and just using those settings to show what we're seeing on the webpage the very simple way to demo the configuration now the typical practice and dotnet core for configuration is to use a configuration provider dotnet core comes with a few very common ones like JSON file configuration provider environment variable configuration provider command line etc we offer a configuration provider it's the azure app configuration configuration provider and so that is what's going to be showing right now on my program CS on top of the one on top of the environment variable and JSON file providers that come by default and default builder I'm wiring up as your app configuration so it's these lines right here this API add a drop configuration is exposed by the nougat package right here Microsoft Azure app configuration asp net core so i just need to add a reference to this to my asp net core project and that i can go ahead and start using this API okay so I go in I call a - your app configuration and then I need to do a little bit of configuring to actually set up the app to pull the settings from my app configuration instance the most important thing is I need to connect now what I'm doing right here is called connect with managed identity this is a feature that we utilize on Azure platforms that are running applications that support managed identity these identities can be assigned to these agile platforms in this case I'm running an app service so I assigned an identity to my app service and I granted that identity access to my app configuration instance so I can actually go into my app configuration instance and I can look at the role assignments and I say oh I granted access to my app service and so using this flow allows me to short-circuit the other way of connecting that I'm going to get to it allows me to like I can short-circuit connection string basically and I can take advantage of the fact I'm running an app service I'm running on dotnet core up there but if you don't want to do that that's perfectly fine you can just use connect and you pass a connection string the connection string comes from our portal or our CLI you can list it there and then you would just provide it in to bootstrap your app but since I am running this app for the demo in app services I can utilize this way of connecting and one of the great things about this is I don't need any configuration to bootstrap my configuration because as you can see I'm not using a connection string all I'm doing is specifying the end point of my app configuration instance ok moving on to some other options used in this we have a little bit of filtering here this use is just specifying a key filter because I mentioned that I kind of wanted to segment my applications and in this case I have them all name space by web demo : all right and so I'm selecting only those then finally we have this configure refresh and this links back to what I talked about before where we have a notion of wanting to dynamically update configuration during the runtime of our application because some application designs depend on this behavior and so before I go into configure refresh I actually want to talk about where the Refresh is triggered and so I'm going to go into program or startup CS and we see this use Azure app configuration this is the only other place where any a track configuration code is found in the application and what this does is it wires up a middleware inside of your asp net core app that uses requests to actually trigger a refresh of the configuration if you are using our configuration provider previously you may have been aware that we were using a polling model before and now we switch to a middleware model and the reason for this is that when you're polling for configuration especially in a micro service world you end up maybe just using a little bit of unnecessary resources if you're doing that continuously even if the application is dormant with a middleware based approach we can be smart about when we want to refresh our configuration if you have 10 apps maybe not all of them always getting requests your load balancing or something like that only the ones that are getting requests need to really be triggering configuration refreshes when the other ones start getting requests then it makes sense for them to start triggering refresh as well and so that's what this does right here request based refreshes now we can go back to we're actually configuring the Refresh because we know that refreshes are being triggered but what actually hat what does it mean to trigger a refresh and that's what we're configuring right here essentially what we're saying is what do we want to keep up-to-date what's setting so we want to refresh every setting maybe one or two settings that are really important that need to be dynamically updated during the app that's what's configured right here in this case I'm watching a setting called web demo Sentinel and not only am i watching that setting I'm specifying something called refresh all which means when that setting changes when I noticed a change in that setting I want to refresh my entire configuration just like I did when the application started up so I want to go back to app configuration and just get everything again that's what's happening right here and so with that that's the full set up of app configuration in my dotnet core app now I can actually see it in action so I have this application right here it's blank right now because I didn't have any settings before but I uploaded some JSON settings and if i refresh the page you'll actually see that I have some configuration form as wrap configure some settings some data that came from the settings it came from my ad hoc configuration came because I uploaded that JSON file but to kind of give a better view of that we can go in and edit some more things right now I show the values for these let's change the background color to green maybe increase the font size just kind of do what we can to make the changes very apparent I also make better message alright so now what actually happens if i refresh the application now nothing is going to change because we're only watching that sentinel value like I mentioned but as soon as I update the Sentinel value I just need to change it I don't really it doesn't matter what I change it to the application can start picking up the changes to all the settings that I updated so we're going to start seeing the change to the green color hi net comp bigger font so this kind of just shows dynamically updating settings during the runtime of the application so to get started all you really need to do pull in the nuga org the new get package Microsoft Azure the app configuration dice B net core that's if you want to build an asp net core app if you're just building a dotnet core app a screen at core is and involved we also have another package called microsoft of extensions that configuration dialog configuration it uses that common configuration provider namespace that one doesn't pull any ASP nets our core stuff into it so if you're just building a console app or maybe a hosted service makes sense to use that it's still going to give you the ability to do refreshes it just doesn't give you the request based refresh middleware but you can refresh the configuration yourself on demand all right so that's the dotnet core seen but for dotnet core developer just developing applications isn't the whole picture there's also you need to build and you need to be able to release your applications so we've been seeing a lot of mention of Azure DevOps for this these kind of needs and we actually have a DevOps build and release task it is on the DevOps marketplace you can go look for agile app configuration and you can add it and right now to your organization or project to start using it and what this does is it utilizes all the settings we put in our app configuration and injects them as variables into our build into our release so I can actually go ahead and create a new build pipeline to kind of show off using this so create a new build pipeline here delete all the steps just to add in a girafft configuration my subscription my configuration instance name so now with this task every setting that's present here is going to be a available to my build pipeline and if I use it in other builds it's going to be available in those build pipelines so I can share my settings across builds now very easily if I'm centralizing them in my app configuration and I can also put my app settings there and so it kind of makes it easy to manage them in one place and have one interface that you're working with for settings one set of tools one see a lot one form of automation and now to demo this I will add in a PowerShell task right here and I'm just gonna echo a setting from Azure app configuration message I don't have that yet but I can create it message hello DevOps cool and now when I run when I save and run this build I don't want to commit to master but I'll save and run this build and then what we'll see is it's going to pull very quickly pull the settings put them in as build variables and then say hello DevOps and we'll kind of have that and like I said what this allows us is we can easily have one interface for managing our settings for the applications we're building we can share these settings across all these builds all these releases just make sure to bring them in through this one build task and then we can kind of keep with the semantics of how we want to add dimensions to our configuration with label things of that nature and I even want to go a little bit deeper into the DevOps and travel ability without configuration I mean configuration is really all across the stack so applications using configuration DevOps is using it and there's even more room to talk about it here because as your DevOps is very easy to interact with the azure CLI you can spin up very quickly as your CLI and line script to start doing something and so this kind of ties in to a scenario where you may have an application and you can't afford to pull settings at the runtime of your application you can't make a HTP request to pool settings you can't talk to the service possibly as a requirement well if you still want to use as your app configuration it's perfectly reasonable to have those settings pulled at Build time or release time package them in app settings JSON file and deploy them with your application so I can go ahead and show kind of what that might look like right here and also show using the address CLI to talk to app configuration so let's hook up an address CLI tasks let's do a [Music] inline script and we're going to use a functionality you saw import on the portal but now let's do an export on the CLI we're going to do export all the settings in our app configuration to a JSON file so that's what we have in this right here app config Cavey export we're saying to a file we give the file path settings the azure app configuration not Jason it's a JSON file the separate word separator we want to use and it can fixed where it comes from finally let me go ahead and publish these artifacts so that we can see them at the end of the build and it demonstrates as I mentioned you want to pull settings during build you don't want to pull them during the runtime your application you want to kind of have that very consistent or it's just a requirement for when you're running your apps so let me run this build and then so this will take just a second for the addressee allied to login that's probably the longest part of using the address CLI and this build but it will produce the Azure diet can app as your app settings that as your app configuration JSON file and if you were doing this in a real scenario you just put that right next your app settings Jason and then BAM you now have dynamic settings but they came from during build time so that's pretty much all I have right now for Azure app configuration centralized configuration management solution we have utilities for managing your configuration a way to share your configuration across all kinds of different platforms DevOps it doesn't matter where in the stack you are Azure app configuration can help out provide the configuration there and I guess real quick I do just want to show the build artifacts of this did say published build artifacts okay well there was supposed to be adjacent there I may be typed something wrong in the build pipeline but I think the idea is there it basically produces the exact same file is this and it would be present and the build artifacts I mustn't this types of thing but yeah that's pretty much it for me all right this has been a pretty amazing Jimmy like look and I'm gonna tell you this because matheus I think I said if I say it wrong I'm so sorry I thought this presentation was going to be about appsettings Jason as your app configuration is amazing it's cool to have this other place to put that stuff and manage it was about I'm saying so Jason kind of find them and then the other one which was interesting which you answered there at the end but I'd love for you to reiterate what's the best way to do a fallback to offline settings you kind of showed this a little bit in your demo why don't you see what method maybe he's gonna tell me how to say his name I'll say Matthew American nice so how do you do a fallback to offline settings that's a good point so there are multiple different considerations when you're talking about fallback to offline settings there's what I just talked about about putting your settings there during build time and release time so you don't have to make a query during runtime so I just demoed that that's exactly how you do it I don't know I'd like I said I probably miss type something in the build pipeline but there would have been a JSON file there that could have been used as absolutely Jason another aspect would be something that we have in our configuration provider which is called a offline file cache which if you're running on the same VM or something and maybe one time when your app is starting out it doesn't have network connection you can use offline file cache in our configuration provider library and it will pull the last retrieved settings they write them to a file encrypt them and it will pull them in case it doesn't have a network connection so kind of two different practices for offline so probably met the first one but the second one is there as well that's right that's cool cuz I thought maybe you just pull it at Bill but then you also have a cache to fall back on as well yes that's cool is as your app configuration recommended for secrets like connection strings another good question all right so as your app configuration is a completely secure way to store any key value encrypting things I mean there's no worries there authentication authorization all however there is another shirt service named kee volt which is more which is better for management or management of secrets they have things like if you're managing things like certificates Auto renewal of certificates or if you have things like connection string they'll expire your connection string and they have very granular access policies so they are the one like the best place to store a secret so there's nothing wrong per se with storing connection string and app configuration but ultimately for secrets that's exactly what key vault was designed for whereas we were designed for just configuration extensive querying mechanisms things of that nature and one of the things that we're actually gonna be coming out was soon is a way to reference key vault secrets in the dotnet core configuration provider so we'll go through the key ball for you in your app it kind of abstract skeeball but your secrets can still live there and that's cool because Nick had the same sort of question what's the difference between this new app config and key vault so keep all this four secrets app config is for how would you finish that sentence yeah key ball is 100% of that designed for secrets as wrap configuration is done designed for configuration there's nothing limiting you from putting anything you want in app configuration but ultimately the like as we have configuration management utilities key vault is going to have secret management utilities the expiration secret rotation or certificate rotation things like that so those are values that we're not gonna be able to give because that's not what we were designed for that's also does this configuration service integrate directly into Azure function so I don't need to manage that config there okay so two things our dotnet core configuration provider is net standard you can use that in app function and pull it right when your app function starts off the second thing is I exported something to a JSON file in the last presentation you can export it to a app service through the CLI or through the portal and so other app other platforms with an azure we want to integrate with to be able to push our stuff there add your function aks you name it on our roadmap is the ability to do this automatically via sync tasks and to just have your configuration live there still manage it centrally in a configuration amazing last question is there an app configuration nougat package for the.net framework so there is yes there is net the one I just mentioned is net standard so you could use it in the.net framework also we do have a configuration builders and you get package the configuration builders was introduced I believe in four seven and it's kind of a net framework way to do configuration well built into the framework there and we do ship something for that so it's a drop configuration specific dotnet framework configuration builder amazing thank you so much assuming we have some feedback coming in on may I say there Mekas jokes that I was asked to read okay the joke's on dotnet Kampf I I told her that they may not work but she was adamant so maybe we should have a talk with her afterwards
Automated Testing of Shader Code
so without further Ado I will introduce the first Speaker Keith Stockdale who's going to be telling us about automated testing of Shader code welcome Keith Hello nice to be here hello all right take it away all right then okay so this is automated testing of Sher code at rare my name is Kei doil and I'm a senior software engineer at rare and I've given a this a talk on this topic um just at this year's GDC but this is going to have a bit more of a C++ spin on it so a little bit about me first um this is me in case my audio my uh video quality is a bit poor and if you're wondering the accents from Northern Ireland that's where I'm originally from and I've been working at rare uh for the last six and a half years on the engine and rendering teams I quite Bas I basically my whole job is just writing things on the GPU that probably shouldn't be r on the GPU and at my time at rare I have worked on CAF thieves seaf thieves is a game that we launched initially in 2018 it is our first onreal engine game and it is based on a very heavily modified onreal engine 4.10 so quite old and I said we initially launched in 2018 because we have been consistently putting out updates um throughout the years just last week we released a major update and today in fact fact we released for the first time on PS5 which we're all very happy about um so still Lots going on with CF th still very much in development and alongside the development of CF thieves we also have ever wild and ever wild is our upand cominging game at rare and it's a little bit different with CF thieves in that we are trying to stay up to date with the latest and greatest Unreal Engine So currently we're on Unreal Engine 5.2 and we're in the process of of upgrading to 5.3 okay with all that out of the way the problem and the problem that we have at rare is that we are writing more GPU code and this GP code is not your typical GP code that I put pixels it's more general purpose simulation code so just in C of Thieves we have two very prominent GPU part um simulations so the first is our fft water simulation so you can't really have a game called CF THS while having having a very good looking C so that has all been simulated on the GPU and then we also have our GPU particle simulation so anything to do with fire or Sparks fireworks smoke bubbles water spray all of that type of stuff that's all being simulated on the GPU and with all of this general purpose code being executed on the GPU we like to test it and the reason for that is because we as a studio love adoma testing and we love it so much that we have given a number of talks on it this one included um one particular talk was automated testing of gameplay features and see of Thieves by Rob Mella way back in 2019 at GDC this these are some links if you want to go to it if a QR code's easier there's a QR code otherwise some words um but this is the mean slid that I felt was the most prominent thing on his presentation where he's talking about all the benefits that we have reaped from autom testing so we've got things like um redu time to verify bills so we get our content out to players much quicker um lower bug count with comparison to previous rare titles and observably reduced crunch as well so these are all the reasons why we like to do it but Rob here was talking about testing of gameplay features but I'm here to talk about testing of Sher code and if you don't know how to get started with testing Sher code this is a fantastic article by Bart ronsky um it's called how not to test Graphics algorithm and in it he lays out two main ways of testing Graphics algorithms the first is screenshot testing which is what's we've been doing at rare since before I started back in 2015 um and then the second approach is what I'm going to be talking about today which is sheer unit testing so our unit testing framework for sheaters we just called it rare sheeter test and it is a testing framework for hlsl codes and if you don't know what hlsl is it stands for high level shoting Lang language and it is the shading language that all directex applications use as their shading language so if it's a directex app on the PC or if it's an Xbox game chances are the Shader code will be written in hlsl our unit tests are written in hsl 2015 so quite an old version and the main reason for that is because our testing framework is being used for both CF thieves and ever while so 2015 has a common feature set there so we stick to that and it runs on top of an unreal testing framework so this is not a standalone testing framework by all means it is just adding on top of what unreal already gives us um so that we can use all the nice tooling that unreal provides as well as letting us test our Sher code an example of the testing framework that we are building upon is CQ test which stands for code quality test um and because I know in the audience there are probably at most one or two people who actually know what this is um it's an Unreal Engine testing framework like I said and it's available from Unreal Engine 5.3 and on so it's fairly recent um it's quite comparable to Microsoft's unit testing framework and if you haven't seen it before um this is what's a testing Suite might look like with CQ test so you have your test class macro at the top and that defines the actual name of the test suite and then you have any number of test methods within it which are your actual test that run and within your test method method you'll have various assertions basically just making sure all of your code works as you expect it to and then in addition to test methods you also have setup methods called before each so these methods will be called before each test method as well as after each so that'll be called after each test method to do some cleanup now um before I go any further I want to just like make it clear what our coding environment is um Onre engine 5.2 currently so we are upgrading soon but very much still on 5.2 and that means we're in C++ 17 land so unfortunately we don't get the nice C++ 20 just yet um that will be coming with 5.3 so another reason why I'm very excited about 53 and we are using HL C 2015 as I said um now throughout the course of this talk I'll be showing C++ code as well as hlsl code so if you see the C++ symbol at the top right it be C++ code on the screen and if you see the hlsl doggo you will be seeing hlsl code okay then on with actually showing how to write a sh unit test in our testing framework so HL C Dogo at the top right this is hlsl so it starts off with some includes so at the minute it kind of looks like C++ um with it with the includes the first include is the header that all unreal shaders must um include so there's nothing interesting there then we have the actual testing framework I'll be talking a little bit more about that header later on and then we have our system under test header which is in this case the water particle framework and then we have the first clue that this is not in fact C++ this is a Shader so this is an attribute that you tag on to the entry function of a compute Shader to tell it how many threads to run per thread group so this is a very simple it is running a single thread so not very good use of your GPU but we don't really need it to be very fast we just need it to be correct and then we have the entry function and we name the entry function the same name is the test this just makes it easier to connect up the hlsl side to the C++ side and at rare we like to use the given when then naming scheme um for writing tests so in this case we have got giving moving water exists so we construct some water with our known velocity when the particle spawn on the surface so in this case we're passing in water into this spawn function and it returns us a water particle then the velocity is inherited so we assert that the spawn particles velocity is in fact the velocity that we expect it to be and that's quite that's basically it so you've got your standard given when then um that you might see in any other testing framework with any other um language now this is a Sher so we need some C++ code to dispatch the code itself self and we try to make sure this is as minimal boiler plate as possible so we start off with the header of the testing Suite which looks like CQ test test class macro except it has an extra argument and that argument is the path to the actual Sher test themselves and then we have any number of um test methods so again it's just giving the method and giving the name of it so you can search that name and you'll find the C++ code as well as the HL cell code in your code base now our the Shader I just showed is extremely extremely simple it has no external parameters to bind or anything like that there it'll just run with no nothing to provide in the C++ side so all we need to do is call run compute Shater test with the dispatch configuration so if you're familiar with direct xit all this will be equivalent to calling dispatch 111 right so it's um dispatching a single thread group on your GPU so it's a single thread group and that single thread group will be running a single thread so not very fast not very not making use of your GPU in any way your perform but that's fine because we are the main thing we're consider we're concerned about here is testing our code on the actual Hardware that it would be running on during your game now at this point I want to talk about the goals of the framework and initially I was going to talk about all of them but um just for the sake of time I'm only going to talk about two the first is we want our test to be fully automated avilable so I mentioned that we have screenshot testing for CF thieves and we've had that for ages um but the problem with it is it's not fully on amable we do require our test team to verify um screenshots from time to time to make sure everything is still right however that's not ideal we'd rather them just get a green tick for happiness and red tick for sadness um so to demonstrate that this is actually something we can do now um we have this feature in CF thieves which is our calm water system and what it will do is as you get closer to an island it will smooth out the fft water simulation um so in the distance there you can see it's all very choppy then as as you get closer it Smooths out quite considerably and we have a full test Suite just for this feature and the nice thing about building on top of our testing framework in unreal is that we get all the nice unreal um test running capabilities as well and Reporting so we can just open this up in our session front end like anything else um hit run on all of them so there's 29 tests and they run lightning quick so there are 29 tests here and they're running at in about 0.3 seconds so about 10 milliseconds a test and that is lightning quick especially if you consider how slow screenshot test can take um so yep fully automatable we're happy with this and then right to goal number five error driven development and what I mean by this is if you get an error as a developer in the while rating the test in the framework that error should tell you how to proceed so it tells you what you did wrong and how to fix it now to explain to give a demonstration of that um we have a slightly more complex sheeter test here um so instead of just passing in the dispatch configuration we are passing in a setup function and that within that setup function you can set some parameters on the actual Shader itself I I'll go into more detail on this later on the talk but suffice to say developer writes this it looks right um but you'll get a compilation there and it's not a massive big Litany of template errors it's actually a single line which says expected a single parameter of f sheer test context reference so it is very very common very easy to just miss out an ampersound right how often have we seen like performance regressions because we accidentally um forgot theant in a sorting functor right um so we we do as much static reflection at API boundaries of functions that are templated as much static reflection as the language currently allows us we're not quite at the land of static reflection proper yet but I'm very hopeful for C++ 26 to get us there um so yeah as much as we can and then we static a search and give nice error messages now you'll notice here that I'm not able to actually format the message I'm not able to say what they did wrong I can just tell them what they need to change something to or to make sure that the parameter is a reference rather than just passing by value and that's because we don't really have user generated static assert mesages right it's currently not possible these have to be string literals you can't do stood format or anything like that with them um at least it's not possible for us um depending on what your development environment is it might be possible for you right now um because it got accepted into C++ 26 very happy about that we'll get there soon maybe possibly um and it's mented in K 17 at a minute and I think it'll be making its way to gcc1 14 um still no word on msvc yet which is the compiler that we use um but some people might be able to use it and I'm very excited for them um these are the links to the discussion art basically seeing the progression of it and also a link to the paper um it's all of the points that quarantine brought up in his paper are basically all the things that I want so yeah rational solid there um definitely worth a read now binding extra sheeter resources in the previous example I talked about binding extra parameters um and we do a lot of static reflection whenever we're binding extra sheeter resources um and to give more of an example of what that actually means is if we have this test Shater here called test with extra parameters very imaginative name and we have these parameters themselves so we've got a biess buffer and we've got an inst float so if you've got a non-static global variable in HL cell code that is a sheeter binding so that is an object that you can bind to on the C++ side to pass in information to be used within your Shater and here we're just asserting on them essentially so to be able to do this you need to a littleit of extra work on the C++ side and the nice thing about unreal is it provides some nice macros for us to do that so if you've written any rendering code in onreal engine you'll have seen this macro here so begin Sher parameter struct we give it a name and then we just pass in all of the parameters that we are going to be using so in this case it's our bodess buffer our uent and our float and we end it off with an end Shader parameter struct however this is wrong and we'll get a nice compilation error here out of this it will first say the test Shater that this test uses has a parameter struct which does not contain the Bas Shater parameters it might shock it might not Shock you to believe that um the test framework itself requires extra parameters be bind because whenever we are running a Sears what that's doing is logging some information to a buffer behind the scenes and then we read back that on the GPU on the CPU um so it needs its own parameters and whenever we just use this begin shter parameter struct for ours we're not including the ones that are required for the test so how do we get around that well thankfully the error message continues says to fix this please use begin CQ test sheeter parameter struct so it's telling you that the thing you need to change so change begin sh parameter struct to begin CQ test sh parameter struct and that will fix things for you and then it continues and says the line below this one is the test that uses this inal theator so we're telling the developer that it is the sh it is the um test that is signified in the next line of the error message that is the problem so we're telling people where the issue is what they did wrong and how to fix it so this is what I strive for in this framework just to make it as easy as possible for people to write tests without having to go diving into the documentation of somewhere else um so all of this is predicated all the static reflection is predicated on being able to detect invalid expressions and in C++ 20 this is quite trivial um you just use Concepts so you have a concept here I've just called it C has sheeter test parameter strict and we have our requires Clause here and within our requires Clause we will Define some constraints and essentially if you pass in a t uh to this concept and these constraints hold so they are valid constraints with this type T then the concept will evalue to true and everybody is happy so you could just static aert on this because the evaluation of a concept is a Boolean expression and if everything is fine turns true everything's good if it returns false then the whole concept framework gives compiler writers the opportunity to provide good helpful um compilation errors however I did say that we don't have the luxury of C++ 20 just yet um so what people typically do in this situation is lean back on void T um but there's another way that I want to talk about today which is what I would call emulating C++ Concepts so it's trying its best to make it look like it if you squint hard enough so we start off with a non-templated struct called C Shader test parameter struct so it's the same name and then we have a templated requires function declaration and in this we're just passing in a type T just like with our concept so if you start squinting it's starting to look almost there and the return type of this requires Clause is a decal type and the deal type will evaluate to this expression so it's our constraints so yeah if you squint hard enough you will see that this is somewhat concept e like um one of the difference here is that we're using the comma operator rather than having semicolons and the reason we're using the Comm operator here is because we're sort of abusing it a bit um the result of the Comm operator is the left um upper hand and the right upper hand and then it Returns the right upper hand but if any one of these Expressions is ill formed then the whole expression is ill formed therefore the type that's returned by The Deco type expression is ill formed so the whole requires function is thrown out it is ill formed it does not exist SP kicks in and then to make use of this in a static assert you don't obviously get the automatic um conversion to an operate to the operator bull like you do with Concepts we instead pass this concept in to t- models which is the driver of this feature and you can see here this is our lovely error message whenever you get this um now I'm going to go through the actual implementation of this because I haven't actually seen it anywhere else although then again I haven't really dived into too many um temp meta programming libraries but I thought it was pretty neat so I'll talk about it so it starts off like any other uh templated meta function it's a a template struct called t- models and it has a function here which will return a reference to a character array of of two elements so two characters if the concepts requires function is well formed with the arguments passed into it so if everything's well formed everything passes then this function will exist if it doesn't resolve if it's if it's if the requires Clause is ill formed then this function will be created instead and the difference here is that it returns a a reference to an array of one character so there's a size difference here and you can probably see where I'm going with this the output of this expression is then um B asserting that if you get if the result of resolve is of size two if it's of size two everything's well formed everything is good and it goes even further you can do a little bit of I'm not going to call subsumption because subsumption is very complicated and it's um it's got It's got well- defined rules so I'll say inheriting so you can inherit concept using the refines Clause um and that's about it really and I just want to talk a little bit about a future goal I have with this framework before I end um and that is hlsl 2021 I mentioned the start that we are stuck on 2015 for now but I really want us to get to 2021 and the main reason for that is we get templates and I love me some templates but the main reason why templates is a great thing is because it allows us to program to an interface rather than to types and if you've written any amount of aom um testing in the in the past you'll know that dependency injection is your best friend right um and with templates we get static polymorphism which is nice way of getting dependency injection somewhat into the language and it allows us to write much more expressive code and um it is easier to write and share hlsl libraries and but the problem is it's a breaking change to go from 2018 to 2021 so um I'm going to fight that battle but I'm not I'm not sure how I'm not um that sure how far I'll get with that one um but if you do want to see what a testing framework in hsl 2021 looks like look no further than mine so I have uh an open an open source project on GitHub any go and see it um and it's running Sher tests on GitHub actions and all of that fun stuff so it's got a full CI and everything going running Shater code tests um and the nice thing about it is it is well the the main goal of it is just to experiment and see what a testing framework can look like in this language and I'm heavily basing everything off catch 2 and by that means by and by that I mean I just I'm just taking every feature that I can for me catch to I really like the the framework and I want to see how how far you can get to it in shoters um but yeah that's basically it um so I just want to leave you with an a nice thing I like to say Shater code is code please test it and that's about it so if there is any questions or if there's even time for questions I can answer them hey yeah thanks very much it was really interesting uh we have a few questions and a few minutes for them uh the first question is from V OA says asks um Can this code be used with GSL glsl yes glsl theyan I see no reason not to it's just I haven't used glsl since University days I'm I'm sorry I've been a rare too long another question from Leslie Li is how does how do assertions work on the GPU um so assertions so I I go a lot more in depth into this into in my GDC talk but effectively at the bottom of an assertion if an assertion fails it'll write some data to a buffer um with some sort of information on it so um the type of data that failed the data itself and what kind of assert that fails and then we read that back on the CPU and then assert on that data um using the underlying testing framework that we're building upon um so yeah it's just it's all it's all big lie around a readback buffer essentially cool um question from bsdb is screenshot testing still a thing why not just grab the state of the rendering pipeline just before all the pixels are colored uh that would be huge screenshot testing is still very much a thing and it's something that we rely on quite a lot at rare especially on CF thieves it has been extremely beneficial throughout the development of CF thieves um for us like it has shown up so much stuff um for us and has caught a lot of things before getting to release so may I can speak for us at least it is very much a thing for us I don't know about other Studios cool and one from D candy um can this be extended to glsl which you also already answered but also spear V open GL or Vulcan yeah that is something I want to I sort of want to try it because yeah you can't you can compile uh HL C down to spear V and then run it in Vulcan and that' be something really cool I have a I have a pipe dream of getting that to run on my Raspberry Pi 5 like I think that'd be really cool to get that to run just like on a like on my own Rosary Pi server um something I want to try that sounds cool and uh a talk sorry a question from Peter nmo for me is uh speaking of catch 2 in the future will there be more support for testing Frameworks in Visual Studio yes we're still very much working on uh other test T in Frameworks um for the test Explorer in in visual studio and uh crossplatform testing uh remote unit testing all that kind of stuff so yeah keep your eyes out for more in that space uh and then I think we've got time for one last question from Michael voling who asks have you all had issues with developers forgetting to register tests that's my biggest fear with manually registered tests uh these are not manually registered as soon as so as soon as you write that uh macro test class it's that's it in it's a it's a static registration on yeah so that that can't happen you can you can opt out so like you can say this test should not run on server for example and if it's a client only thing um but it's Auto registered yeah great all right well thank you so much for joining us Keith and uh hopefully see you around see you
Building Bots Part 1
it's about time we did a toolbox episode on BOTS hi welcome to visual studio toolbox I'm your host Robert green and jo...
-
hey everyone welcome to Microsoft Connect my name is Nina Zakharchenko I'm a senior cloud developer advocate at Microsoft ...
-
It's lunchtime, and this is Brad Anderson's lunch break. Here in Redmond we're visited by some of the smartest peo...
-
[MUSIC]