✔ ☕ General Conversation Thread

That is what I thought… would be good to hit a GPU bound shader onto it…

well … if monogame supported compute shaders…

Looks good, Is that water reflecting the environment ?

You should add a fresnel effect to it that would make it a lot better.

1 Like

Yeah, MG really needs to catch up with modern graphics stuff. We have to get rid of MojoShader (that’s the limiting factor here) and probably replace it with glslang (HLSL -> SPIR-V) + SPIRV-Cross (SPIR-V -> GLSL). And possibly also glslang for building GLSL shaders directly (GLSL shaders are compiled by the GPU at runtime so we don’t actually compile; the build step in the content pipeline just does optimization and gets reflection data for EffectParamaters/Sampelers and stuff like that). I’d really like to do this when I’m done with exams.

I now I’ve said before that I’d work on direct GLSL support and I’ve implemented GLSL effect building (with parts of the Effect framework syntax and multiple entry points + techniques in one file) using glsl-optimizer, but that’s still very limiting. The only benefit it has over MojoShader is that you can build effects on Linux/Mac and write in GLSL, but it doesn’t do better in terms of feature support (compute, geometry, GLSL versions…). The Vulkan tools seem like the best way forward.

Well im not sure whats going on tonight but um something is creating garbage in my app and its coming from a class filled entirely with structs.

My little experiment today was to bypass spritebatch and just straight draw to the gpu by refilling a buffer each pass and see how much i can push it,

So 15 k quads or sprites is making mass garbage might be hard to see it in the screen shot.

Anyone know if DrawUserIndexedPrimitives creates garbage ?

Whats the fast most efficient 3d call or way to draw a ton of custom vertices whose positions are changing each frame?

You can just check the memory profiler (.net allocations or something) but as far as I know it doesn’t, but I only draw a few sprites per frame, not thousands.

Oh stupid me i was calling new on the arrays when clearing them even though i already set it up to just reset the indexes.

It’s still making a little garbage though but nothing like before.

I think the cpu eventually bottlenecks me though, on actually building and then sending thru such huge arrays each frame.

Here is the test class if you want to check it out or play around with it.

I had this in mind when thinking about particles. But ya i dunno it was just a thought like how many raw sprites can i blit before it takes a toll ? which is about 25,000 at 60fps after that it starts dipping.

    // used
    //using System;
    //using System.Collections.Generic;
    //using Microsoft.Xna.Framework;
    //using Microsoft.Xna.Framework.Graphics;

    //namespace your namespace


    public class LittleGpuSpriteBatcher
    {
        private Vector2 uvLT = new Vector2(0f, 0f);
        private Vector2 uvLB = new Vector2(0f, 1f);
        private Vector2 uvRT = new Vector2(1f, 0f);
        private Vector2 uvRB = new Vector2(1f, 1f);
        public Effect currentEffect;
        public Texture2D currentTexture;
        private int windowWidth = 0;
        private int windowHeight = 0;


        private int quadCapacity = 60;
        private int currentQuads = 0;
        private int ti_pointer = 0;
        private int vi_pointer = 0;
        private int[] triangleIndexList = new int[6];
        private VertexPositionColorTexture[] spriteVertices = new VertexPositionColorTexture[4];

        public int QuadCapacity
        {
            get { return quadCapacity; }
        }
        
        public LittleGpuSpriteBatcher(Rectangle windowClientBounds , int quadCapacity, Effect effectToUse)
        {
            windowWidth = windowClientBounds.Width;
            windowHeight = windowClientBounds.Height;
            this.quadCapacity = quadCapacity;
            triangleIndexList = new int[6 * quadCapacity];
            spriteVertices = new VertexPositionColorTexture[4 * quadCapacity];
            currentEffect = effectToUse;
        }

        public void ClearAll()
        {
            currentQuads = 0;
            vi_pointer = 0;
            ti_pointer = 0;
        }

        public void AddSpriteToBatch(Rectangle destinationRectangle)
        {
            float cw = 2f / windowWidth;
            float ch = 2f / windowHeight;

            float left = destinationRectangle.X * cw - 1f;
            float top = destinationRectangle.Y * ch - 1f;
            float right = destinationRectangle.Right * cw - 1f;
            float bottom = destinationRectangle.Bottom * ch - 1f;

            spriteVertices[vi_pointer + 0] = CreateVPCTstruct(left, -top, 0f, Color.White, uvLT);
            spriteVertices[vi_pointer + 1] = CreateVPCTstruct(left, -bottom, 0f, Color.White, uvLB);
            spriteVertices[vi_pointer + 2] = CreateVPCTstruct(right, -top, 0f, Color.White, uvRT);
            spriteVertices[vi_pointer + 3] = CreateVPCTstruct(right, -bottom, 0f, Color.White, uvRB);

            triangleIndexList[ti_pointer + 0] = 0 + vi_pointer;
            triangleIndexList[ti_pointer + 1] = 1 + vi_pointer;
            triangleIndexList[ti_pointer + 2] = 2 + vi_pointer;
            triangleIndexList[ti_pointer + 3] = 2 + vi_pointer;
            triangleIndexList[ti_pointer + 4] = 1 + vi_pointer;
            triangleIndexList[ti_pointer + 5] = 3 + vi_pointer;

            currentQuads += 1;
            vi_pointer += 4;
            ti_pointer += 6;
        }

        /// <summary>
        /// simplest version
        /// </summary>
        public void DrawAll(GraphicsDevice gd)
        {
            foreach (EffectPass pass in currentEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, spriteVertices, 0, VerticesPerQuad(), triangleIndexList, 0, TriangleDrawCount());
            }
        }

        public void SetCurrentEffect(Effect effectToUse)
        {
            currentEffect = effectToUse;
        }
        public void SetCurrentTexture(Texture2D t)
        {
            currentTexture = t;
            currentEffect.Parameters["Texture"].SetValue(currentTexture);
        }

        public int TotalQuads()
        {
            return currentQuads;
        }
        public int VerticesPerQuad() 
        { 
            return 4; 
        }
        public int TriangleDrawCount() 
        {
            return currentQuads * 2; 
        }

        public void OnResizeUpdateWindowWidthHeight(Rectangle windowClientBounds)
        {
            windowWidth = windowClientBounds.Width;
            windowHeight = windowClientBounds.Height;
        }

        private VertexPositionColorTexture CreateVPCTstruct(float vx, float vy, float vz, Color c, Vector2 uv)
        {
            return new VertexPositionColorTexture(new Vector3(vx, vy, vz), c, uv);
        }
    }

relevant game1 test code

LittleGpuSpriteBatcher lsb;
// gets called from loadcontent
public void LoadAndSetUpDirectBatcher(int numberofquadstomake)
{
    tex2d = Content.Load<Texture2D>("moon");
    BlankEffect = Content.Load<Effect>("BlankGpuEffect");
    BlankEffect.Parameters["Texture"].SetValue(tex2d);

    lsb = new LittleGpuSpriteBatcher(Window.ClientBounds, numberofquadstomake, BlankEffect);
    lsb.SetCurrentTexture(tex2d);
     // dont have to initialize it once constructed
    // UpdateFillDirectBatcherInRealTime();

}
public void UpdateFillDirectBatcherInRealTime()
{
    lsb.ClearAll();
    int quadcapacity = lsb.QuadCapacity;

    Random rng = new Random();
    Random rng2 = new Random();
    for (int i = 0; i < quadcapacity; i++)
    {
        int x = rng.Next(Window.ClientBounds.Width - 60);
        int y = rng2.Next(Window.ClientBounds.Height - 60);
        lsb.AddSpriteToBatch(new Rectangle(x, y, 60, 60));
    }
}
protected override void Update(GameTime gameTime)
{
         UpdateFillDirectBatcherInRealTime();
         base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            GraphicsDevice.RasterizerState = RasterizerState.CullNone;
            
            lsb.DrawAll(GraphicsDevice);

            //spriteBatch.Begin();
            //framerate.Draw(spriteBatch, gameTime);
            //spriteBatch.End();

            base.Draw(gameTime);
        }

The shader is basically as plain as possible.

//_______________________________
// gpu system coordinates effect
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

Texture2D Texture : register(t0);
sampler TextureSampler : register(s0)
{
    Texture = (Texture);
};
struct VertexShaderInput
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
    float2 TexureCoordinate : TEXCOORD0;
};
struct VertexShaderOutput
{
    float4 Position : SV_Position;
    float4 Color : COLOR0;
    float2 TexureCoordinate : TEXCOORD0;
};
struct PixelShaderOutput
{
    float4 Color : COLOR0;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
    output.Position = input.Position;
    output.Color = input.Color;
    output.TexureCoordinate = input.TexureCoordinate;
    return output;
}
PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
{
    PixelShaderOutput output;
    output.Color = tex2D(TextureSampler, input.TexureCoordinate) * input.Color;
    return output;
}
technique BlankTechnique
{
    pass
    {
        VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
        PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
    }
}
1 Like

I think monogame actually transforms the rectangle position in the shader itself afaik, that might save you a bit CPU time

Wasn’t there a road map somewhere?

Can we not drop into C++ and implement it or is it a huge task and battle with swapchains etc.?

And DirectX for Windows of course :slight_smile: I love the DX12 feature where it automatically combines your compatible GPUs, so if you had an internal GPU say an Intel HD Graphics chipset [Modern one on the Core Series of CPUs] and a discrete [Why do they call it that? the things are massive lol] GPU or more [Such as 2 on a desktop + Internal] it would place the workload across all available graphics systems dynamically… which is something I have thought of circa. the VooDoo2/3 days … man, feeling that age… Does Vulkan do something similar? I am not much of an AMD guy any longer so I only slightly follow that line… [NVidia bought my following when they purchased 3Dfx! I was a ATI Rage user before they brought out the GeForce series of cards, never - sort of never - looked back since]

WOWZA, just a benchmark I hope… is that to do with that camera coding you were doing?

So relating to my post before, @kosmonautgames got me back into the Screen Recording thing, I prefer videos though… just easier :slight_smile: you can see an incomplete implementation, just thought it would be nice to put a visual to the code… will likely disappear eventually as I clean out old videos later in the year… Can you see how the .67 pops in at the end?

This is the incrementing thing that I made, I am working on an app that deals with money, more on it soon…

@willmotil I only wish I had time and the experience to look at such code in detail, I could probably make things out but it is the fundamentality that I lack in those things :frowning: though, some code Commenting / Summaries never hurt :slight_smile:

<Boasting>
On a side note I potentially have a huge project landing in my lap this year… only time will tell if it happens… in the mean time I have a week to put together a functioning demonstration to impress and get on board… I cannot say much beyond that at this point and likely not for some time or ever depending on how things pan out… I just needed somewhere to vent out this happiness so I hope you guys do not mind :slight_smile:
</Boasting>

Hmm… so much to do, so little time…

I hope you are all doing well :slight_smile:

Hmmm. I’ve read through the legal stuff and it turns out that Valve, sadly, is very restrictive about ‘publishing’ information about their API in general.
All I’m allowed to do is to post this link here Steamworks SDK (Steamworks Documentation)

See how far you get without logging in.
Another approach is the project Steamworks.NET which is a wrapper for their API.
I think it really provides a good overview.

And I have created a repo on GitHub here: GitHub - UnterrainerInformatik/Nexus: Cross-platform implementation of a communication-hub for use with Steamworks or its own server. Currently this project is just a draft.
That should help getting stuff together, documenting, drafting.
We’ll see where it will get us…
ps: The name and everything else is open for debate of course :smile:

1 Like

Does Vulkan do something similar?

From what i gathered SPIRV is the innovation that is underneath Vulcan an api based on it.
(though the white paper i read didn’t look too complete at the time)
That basically aims to provide direct api to gpu functionality basically the idea is to sidestep the middleman the idea of drivers and create a unified specification for directly sending commands to cards.

WOWZA, just a benchmark I hope… is that to do with that camera coding you were doing?

Well it is a benchmark i suppose but then again it is actually drawing sprites by reassigning positions so for a particles system or text drawing it says a little more.

Also it demonstrates that we could simply allow a user to send in topleft, topright, bottomleft, bottom right positions instead of rectangles then you could draw parellograms and such from quads which im sure could be useful as a feature addition to spritebatch.

Na nothing to do with the camera thing i got it up to 25k on my card before the fps starts to drop below 60fps, In a real app id expect that to be fifthed at least. The random numbers actually can’t keep up with the draws i had to redo that part.

I think monogame actually transforms the rectangle position in the shader itself afaik, that might save you a bit CPU time

humm i didn’t think it did that, So are you saying just skip the calculating part here and put the rectangle itself in a vector4 custom vertex position texture format then do that on the card?

public void AddSpriteToBatch(Rectangle destinationRectangle)
{
    float cw = 2f / windowWidth;
    float ch = 2f / windowHeight;

    float left = destinationRectangle.X * cw - 1f;
    float top = destinationRectangle.Y * ch - 1f;
    float right = destinationRectangle.Right * cw - 1f;
    float bottom = destinationRectangle.Bottom * ch - 1f;

    spriteVertices[vi_pointer + 0] = CreateVPCTstruct(left, -top, 0f, Color.White, uvLT);
    spriteVertices[vi_pointer + 1] = CreateVPCTstruct(left, -bottom, 0f, Color.White, uvLB);
    spriteVertices[vi_pointer + 2] = CreateVPCTstruct(right, -top, 0f, Color.White, uvRT);
    spriteVertices[vi_pointer + 3] = CreateVPCTstruct(right, -bottom, 0f, Color.White, uvRB);

Ill bet the array assignment here then passing it to the gpu at 60 fps is much more costly then the calculations themselves.

Precisely…

Yep, it is publicly visible, thanks!

I do not see any login requirement… is that the .NET project for integrating Steamworks? why is Valve not doing this internally? I know he hates Microsoft but hating devs is just silly… also I should mention that I have no interest in Steam…

What’s that for?

I have been wondering, that DarkSide guy said you can use DirectX in C# in one of his videos, and he is quite clued up with Microsoft so I am thinking, did he mean using things like SharpDX/MonoGame or did he mean directly with C#?

I have thought of a project name for the APIs and will look at buying the domain sometime next week, or perhaps put it on the back burner until I get my ASP.NET studies out of the way to give it a proper website and functionality… I am not aiming to make this an isolated project… it will work for all C#.NET users so it needs its own platform… though again, the core implementation will be for MonoGame usage with the flexibility of ease of implementation into any C#.NET project.

For the Physics I have a good book to get me going, all I have to do it figure out the 3D side of things…

For the networking I will use WCF and its related libraries, I could even look at P2P methods for some aspects…

I do not expect my core coding to be performance based, nor do I expect it to be clean of memory leaks [Though I will try] but once I get something working, I can release it out to the world and let it sail from there…

<ToDream>
I will never understand why Microsoft dropped XNA, it was clearly working… And the debate of C# being slower is nonsense today… so… I can only dream that they will buy MonoGame [Or something] and make it work :slight_smile: [By that I mean bring in more team members and accelerate it along, they have that ability… and will not cost them much and the return I think would be vast…]
</ToDream>

No. Sadly not. It’s not all, just parts of it. No details.

Nope. That’s the Valve-page for their framework for developers building steam-games.
The Steamworks.NET project on the other hand is from a guy who wrote an automated ‘parser’ wrapping the Steamworks C++ code in C# since Valve only provides the networking-client-code in C++.
I don’t know if he hates MS guys, but they don’t want to leak their networking code because it’s an asset to the game-developers out there and it belongs to them.

Most of the game-devs I know have an interest in Steam since it’s the platform they release their game on.
And since they had 8mio users online at the same time for a number of times in the last two years, those guys seem to know how to structure a networking API (which isn’t that easy by the way; Believe me, I know :wink:)
Other than that, me neither.

That’s for collecting documentation and drafting architecture until someone gets started with that project.
I will continue to groom that until someone jumps in or it dies; We’ll see…

Internal politics at mircrosoft back then basically there was a coup de ta and all the old office dinosaurs got back into power they retaliated against all the .net dudes and c# guys to do everything short of firing everyone that was doing anything related to c# .net all. If you look on the ms developer site https://visualstudio.uservoice.com/forums/121579-visual-studio it was the highest voted thing on there for 2 years like 50k votes, to replace xna or give some direct dx access for c# but… here we are MG sharp dx ect… None of these are from microsoft.

“C# is slower then c++” that is the most yanked excuse ever if that were the main reason to do anything we would all be programing strictly in assembly language because its faster then c++ c java and everything but the machine code itself.

1 Like

That is why the project should have an interface so people can communicate between various networking solutions such as the Steam one, I am sure there are others, imagine if GoG made one for its platform? this is flexibility at its best, which is why I said “I have no interest in Steam” though I am not blocking it from the project :slight_smile:, this project is fully for Developers!, Developers!, Developers!, … Developers!, Developers!, Developers!.. [Thumbs up if you know the reference :slight_smile:

[ For those who missed it https://www.youtube.com/watch?v=I14b-C67EXY ]

Sure I do realise the complexity involved… but, if something does not exist, and nobody is doing it, then someone should take up the challenge… so here I am… picking up the gauntlet…

On another note, did you guys see the SpaceX feed… <3 Mars, here we[I] come!

Can you link to it? cannot see it there

I found this however

https://visualstudio.uservoice.com/forums/121579-visual-studio?query=C%23%20DirectX

https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/2214717-bring-back-directx-to-c

Ah… I think we’re already on the same page here. I plan to make an API that you can use consistently, without even knowing what platform your game will do the networking stuff on later on when you release. At least that’s the idea.

1 Like

That’s the idea, by using conditional compilation, the project compile target platform will decide what code should be used… though I will keep this again primarily for UWP… and MonoGame… as this is my target platform… the project can have multiple targets modified by the contributors… keep in mind this sort of project requires a driving force behind it, otherwise it just dies…

My drive is the fact that my game engine requires such a component… as such it will be made… though like I said, I am yet unsure if the code will be made public until I make it modular… and decide on whether my entire engine will be made open source or not… I am yet to decide on this… my engine is built around MonoGame so it relies on MonoGame at its core, though the plan is to make the networking section wholly independent of such a core hence why I think it can be made open to the public… the reason I am considering making the project open source has already been mentioned, I am not a hard core coder at this time…

The dilemma I have is, will I publish my game under my name or set up a new company for it, which is where the complexity comes in with the licencing you see… as I wish to create jobs locally and develop a team to make some games that I have on the backburner so, the engine will sit behind all of those projects hence the dilemma of open sourcing it…

If you see me go silent on the forum it usually means one of two things, I am working neck deep in a project or I am moving houses, which will happen this year around March-April time… have to redecorate and stuff before moving ‘back in’…

Well here is one of them.

https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3725445-xna-5

There were like 3 different ones all high ranked about directx c# gpu support ect ect in different areas all of them had the highest votes.

1 Like

That declined message, is so pitiful…I cannot think what came over them, I mean look at Roslyn, they clearly care for C#, but why drop one of the best things they had going for XBOX? I do not care for Unreal Engine, nor Unity, why do you think I am here? because I Love C# and so too does MonoGame…

There is already talk of people abandoning C++ in droves, I see it everywhere I look, people are moving to higher level languages such as Java, Ruby, PHP, C# and others, Why? because performance is not a key factor any longer… rapid development is…

‘Sigh’ if I ever attend a Microsoft Developer Conference I am going to put the question in a live Q&A and I bet the crowd cheers when it is asked…

Well earlier jjag mentioned vulcan here is the get pumped link for vulcan spir-v

if you scroll down to page 43 you’ll see a nice diagram for how vulcan and spir-v are in principal supposed to work with other languages those such as c# mono ect…

Im guessing the idea here is if spir-v is the middle man it can allow you to optimize things to the gpu instead of the cpu as well as bypass the video driver and instead vulcan will directly access the gpu. One major benefit to this as well is it can give you Debug information just like your vs compiler does.

1 Like