• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
fs1

Read Shaders from CPU in DirectX 11

9 posts in this topic

I am reading the Constant Buffer to get the World View Projection Matrix through the VSGetConstantBuffers function prior to a DrawIndexed call.

That is working fine.

Can I map all shaders variables into CPU variables? Similar to how the VSGetConstantBuffers works? If so, how?

In addition, is there any API to debug the shader? Like the windows debug API?

Thanks
0

Share this post


Link to post
Share on other sites

Why would you even need to read them back?  In order to get them into the cbuffer, you must have had them somewhere CPU-side to begin with.  Cache and use that copy instead.

0

Share this post


Link to post
Share on other sites
I am doing a sprite model extractor.

I don't have them side to side. That's the point, although I have access to the shader source.
0

Share this post


Link to post
Share on other sites

Tell us more about the process. huh.png

 

So when you say sprite model extractor do you mean like a 2d sprite, rendering to the screen, and then you somehow want to generate a model out of that? (Vertices... Indices...)?

 

And you said you're reading the "Constant Buffer", on the cpu side to get the variables. There I have to fully agree with mhagain, if you've written to them, you must have the data you mapped into them on the cpu side somewhere, maybe try to save them. And if I'm not mistaken, it sounds like (Maybe I'm wrong) you're trying to change some variables inside the constant buffer on the gpu side, see the problem with that is that it's impossible (Please correct me if I'm wrong), and that's the reason why they were named 'constant' buffers.

 

One way that you could get variables from the gpu is somehow writing them to the output, could be a render target, then on the cpu side extract the variables from the render target and process them there. You could even use a structured buffer, send the structure to the Gpu, and then you may edit (write to) this buffer, and you can write to any index of it. (It's usually an array).

 

PS. GPU to CPU operations aren't usually the fastest. smile.png

 

But give us some more info, then we could get closer to the solution.

 

EDIT:

"In addition, is there any API to debug the shader? Like the windows debug API?"

There is, Intel GPA is very good at this (well, it works for me), another option may be to enable the debug flag when creating the shader, then later on in either visual graphics debugger or pix, find the shader object, click on it, then somewhere you'll be able to open it and even sometimes debug it (This is possible with the visual graphics debugger, not sure about pix though).

 

Hope this helps somehow. wink.png

-MIGI0027

Edited by Migi0027
0

Share this post


Link to post
Share on other sites
Migi0027 thanks for your response.

What I am trying to do is a research project to extract sprites (primitives and textures) from a certain DX11 engine.

The problem is that I am trying to do this not knowing the code, so I may have to hook some functions.

I can decompile the shaders and also I have access to the shader constants with the DirectX 11 API (for example the VSGetConstantBuffers function).

My question is how can I map the shader defined variables and structures into my CPU variables/structures (which I will have to mirror somehow)?

One way would be manually re-write the shader definitions in my CPU and then access the shader and assign them. Maybe doing this by the Shader Reflection APIs?

Any tips would be appreciated.

Thanks
0

Share this post


Link to post
Share on other sites

One way would be manually re-writte the shader definitions in my CPU and then access the shader and assign them. I guess another way would be by Shader Reflection?


Yes, those are basically your only options. The DirectX shader reflection interface is kind of cumbersome, but it will get what you need. You won't be able to map the shader objects directly into C++ objects, but you'll at least be able to create a data structure that represents the layout and format the shader's constant buffers. You can use that layout structure to interpret the constant buffer data you have.

Note, however, that shader reflection will only get you the layouts and bindings of constant buffers/resources. You can't get the CONTENT of the constant buffers from shader reflection (though I'm pretty sure you're not trying to do that?)
1

Share this post


Link to post
Share on other sites

Note, however, that shader reflection will only get you the layouts and bindings of constant buffers/resources. You can't get the CONTENT of the constant buffers from shader reflection (though I'm pretty sure you're not trying to do that?)


Thanks Samith for your insights. I will need the Content as well. Can you get its content as well? Let's say with the VSGetConstantBuffers type of functions?
0

Share this post


Link to post
Share on other sites

Please be aware that my knowledge on this is very limited, though it seems to work for me. So if you see anything wrong or complete nonsense, please tell me so I don't send the wrong message to fs1. wacko.png

 

If you already know the layout of the buffer, like:

struct CBUFFER
{
    D3DXMATRIX view, proj, world;
};

Maybe you could create a staging buffer with the same size as the origional one. Then with the staging, do something like this to copy the data:

DeviceContext->CopyResource(staging, buffer);

And remember that this staging buffer has different parameters than the original one, it should include this (the creation flags):

bufferDesc.Usage = D3D11_USAGE_STAGING;
bufferDesc.BindFlags = 0;
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;

So when you've copied the data from the original buffer to the staging, you may begin reading from it:

D3D11_MAPPED_SUBRESOURCE ms;
engine.devcon->Map((ID3D11Buffer*)staging, NULL, D3D11_MAP_READ, NULL, &ms);

CBUFFER cbData;
memcpy(&cbData, ms.pData, sizeof(cbData)); // I think the syntax looks somewhat like this

engine.devcon->Unmap((ID3D11Buffer*)staging, NULL);  

Now you have an instance of the data which you should be able to read from ( the cbData ).

Now this may not work if you don't know the layout/structure of the buffer, in that case I'll have to think a bit more. tongue.png

 

Hope this is useful!

-MIGI0027

1

Share this post


Link to post
Share on other sites

Please be aware that my knowledge on this is very limited, though it seems to work for me. So if you see anything wrong or complete nonsense, please tell me so I don't send the wrong message to fs1. :wacko:

If you already know the layout of the buffer, like:

struct CBUFFER{    D3DXMATRIX view, proj, world;};
Maybe you could create a staging buffer with the same size as the origional one. Then with the staging, do something like this to copy the data:
DeviceContext->CopyResource(staging, buffer);
And remember that this staging buffer has different parameters than the original one, it should include this (the creation flags):
bufferDesc.Usage = D3D11_USAGE_STAGING;bufferDesc.BindFlags = 0;bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
So when you've copied the data from the original buffer to the staging, you may begin reading from it:
D3D11_MAPPED_SUBRESOURCE ms;engine.devcon->Map((ID3D11Buffer*)staging, NULL, D3D11_MAP_READ, NULL, &ms);CBUFFER cbData;memcpy(&cbData, ms.pData, sizeof(cbData)); // I think the syntax looks somewhat like thisengine.devcon->Unmap((ID3D11Buffer*)staging, NULL);
Now you have an instance of the data which you should be able to read from ( the cbData ).
Now this may not work if you don't know the layout/structure of the buffer, in that case I'll have to think a bit more. :P

Hope this is useful!
-MIGI0027
Thanks MIGI0027, I will test this approach, seems like the right path.

EDIT: I guess you can get all structures through reflection and then read the binded buffers.

Thanks
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0