• Content count

  • Joined

  • Last visited

Community Reputation

248 Neutral

About wh1sp3rik

  • Rank
  1. Hello,   I have a question about updaing contant buffer performance. I would like to know how it works when I bind a constant buffer to let's say all shaders. ( it's VS, HS, DS, GS, PS, CS ).   Let's say, I will upload some per frame data and I am curious what steps it will do if I call UpdateSubresource function.   Microsoft says that UpdateSubresource does two copies. First copy goes to temporary storage and it's copied by CPU and second copy goes to non mappable memory and it's copied async by GPU. If I bind contant buffers to more shaders, does it mean, it will copy it multiple times for every shader ?   thank you very much.  
  2. Yeah, I realized it now. Padding ...   Thank you, let's try it.
  3. In this situation, I think it's better to create two textures. One for SRV and one for RTV. After you render into RTV, you can copy RTV to SRV with copyresource. It's should be fast as it's GPU to GPU. Also SRV and RTV should be set to default, so no CPU writing/reading.
  4. Hello,   I have a strange problem with mapping texture for reading. My texture is R32_SINT format. When mapping, I obtained pData, RowPitch and DepthPitch. My texture is 800 x 600 in size. Graphics debugger says, It's 800x600 and its size is 1920000. That's correct. Unfortunately, RowPitch is 3328 ( which is about 128 more then it should be ) and DepthPitch is 1996800 ( and it should be 1920000 ).   Creating texture code ZeroMemory(&textureDesc, sizeof(D3D11_TEXTURE2D_DESC)); textureDesc.BindFlags = 0; textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; textureDesc.Width = width; textureDesc.Height = height; textureDesc.Format = dxformat; textureDesc.Usage = D3D11_USAGE_STAGING; textureDesc.SampleDesc.Quality = 0; textureDesc.SampleDesc.Count = 1; textureDesc.ArraySize = 1; textureDesc.MipLevels = 1; _device->CreateTexture2D(&textureDesc, 0, &resource->_resourceRead); where width = 800, height = 600, dxformat = DXGI_FORMAT_R32_SINT.   Why it happend ? What's going on ?   Thank you very much for answers.
  5. I just got an answer on StackOverflow.   I set up SampleGrabber filter too late. I should set it up before connecting and that was the problem.
  6. Hello,   Trying to figure out, how to get a bitmap from webcam output. The problem is in colours. it seems a webcam output is YUV color space and i am not sure, how to display it right as most other examples are not care about that. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DirectShowLib; using System.Runtime.InteropServices; using System.Drawing.Imaging; namespace WindowsFormsApplication3 { public partial class Form1 : Form { [DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)] public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count); public IGraphBuilder gb; public ICaptureGraphBuilder2 cgb; public IBaseFilter filter; static SampleGrabberCallback cb; VideoInfoHeader header; static Form1 thisform; public class SampleGrabberCallback : ISampleGrabberCB { int ISampleGrabberCB.SampleCB(Double SampleTime, IMediaSample sample) { return 0; } int ISampleGrabberCB.BufferCB( Double SampleTime, IntPtr dataPtr, Int32 BufferLen ) { Bitmap bitmap = new Bitmap(640, 480, 640*3, PixelFormat.Format24bbp, dataPtr); Graphics g = thisform.panel1.CreateGraphics(); g.DrawImageUnscaled(bitmap, 0, 0, 640, 480); return 0; } } public Form1() { InitializeComponent(); thisform = this; DsDevice[] videoInputDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice); object obj = null; Guid iid = typeof(IBaseFilter).GUID; videoInputDevices[1].Mon.BindToObject(null, null, ref iid, out obj); filter = (IBaseFilter)obj; ISampleGrabber grabberFilter = (ISampleGrabber)new SampleGrabber(); IBaseFilter baseGrabber = (IBaseFilter)grabberFilter; ((IAMCameraControl)filter).Set(CameraControlProperty.Exposure, 0, CameraControlFlags.Auto); gb = (IGraphBuilder) new FilterGraph(); cgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); cgb.SetFiltergraph(gb); IEnumPins pins; IPin [] inputPin = { null }; IPin [] outputPin = { null }; filter.EnumPins(out pins); pins.Next(1, outputPin, IntPtr.Zero); baseGrabber.EnumPins(out pins); pins.Next(1, inputPin, IntPtr.Zero); gb.AddFilter(filter, "First Filter"); gb.AddFilter(baseGrabber, "Grabber Filter"); gb.Connect(outputPin[0], inputPin[0]); grabberFilter.SetBufferSamples(true); AMMediaType media = new AMMediaType(); media.majorType = MediaType.Video; media.subType = MediaSubType.RGB24; media.formatType = FormatType.VideoInfo; grabberFilter.SetMediaType(media); grabberFilter.GetConnectedMediaType(media); header = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader)); cb = new SampleGrabberCallback(); grabberFilter.SetCallback(cb, 1); cgb.RenderStream(PinCategory.Preview, MediaType.Video, filter, null, null); ((IVideoWindow)gb).put_Owner(this.panel1.Handle); ((IVideoWindow)gb).put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren); ((IVideoWindow)gb).put_Visible(OABool.True); ((IVideoWindow)gb).SetWindowPosition(0, 0, this.panel1.Width, this.panel1.Height); ((IMediaControl)gb).Run(); } private void OnResize(object sender, EventArgs e) { ((IVideoWindow)gb).SetWindowPosition(0, 0, this.panel1.Width, this.panel1.Height); } } } This is my code, it enumerate video devices ( my default device is number 1, you should use 0, if you have only one device ), SampleGrabber calls callback function and i can get a buffer there.   I tried most formats Format24bbp, Format16bpp565 .. and .. ok, if it's YUV, i should convert it, but i though i can just specify type in mediatype as examples are doing it.   I also attached full source with directshownet library. if someone has a time to check, i will be very happy as i am trying to figure it out whole a day, reading tutorials, samples ...   Thank you very much
  7. Hello,   you are right. Also, there is not R16G16B16_UINT format, it has a reason :) These memory aligments are pain. Thank you, I am on the good way now.
  8. Hello,   I have a little problem :) I would like to write data into buffer with format : {"POSITION", 0, DXGI_FORMAT_R16G16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TPOSITION", 0, DXGI_FORMAT_R16G16_UINT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, {"LODID", 0, DXGI_FORMAT_R16_UINT, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, First stream has 4 bytes, second stream has 6 bytes. So, i created buffers with that sized and i copied USHORT data into buffer.   When rendering, it says D3D11 ERROR: ID3D11DeviceContext::DrawIndexedInstanced: Vertex Buffer Stride (6) at the input vertex slot 1 is not aligned properly. The current Input Layout imposes an alignment of (4) because of the Formats used with this slot. [ EXECUTION ERROR #367: DEVICE_DRAW_VERTEX_STRIDE_UNALIGNED] Shader layout: struct VIn { uint2 position : POSITION0; uint2 instance : TPOSITION; uint lodid : LODID; }; when i use 32bits , it's working fine. I also tried to use uint only and unpack two ushorts ( uints in hlsl ). It's a pity, there are no ushorts in hlsl ;-)   thank you
  9. that's great, i did not know that .. is it working for any resource ?
  10. Pink Horror:   let's say, i have lot of layouts and i thought it's a great idea to be able to access them by index. :-)
  11. Ah, yes, it should have same amount of "items" in array.   Thank you for answer.
  12. Hello,   trying to make an array of struct arrays :) Unfortunately, i am not sure if it's possible .... it should be somehow.   This is how it's usually declared: const D3D11_INPUT_ELEMENT_DESC ILayout0[] = // position only { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, }; const D3D11_INPUT_ELEMENT_DESC ILayout1[] = // normal { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 44, D3D11_INPUT_PER_VERTEX_DATA, 0}, }; but i would like to make a one array from that: const D3D11_INPUT_ELEMENT_DESC LayoutArray[][] = { { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, }, { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 44, D3D11_INPUT_PER_VERTEX_DATA, 0}, }, }; but unfortunately .. error ( second bracket is underlined ) error C2087: 'LayoutArray' : missing subscript error C2078: too many initializers Is this possible to declare it this way somehow ?   About D3D11_INPUT_ELEMENT_DESC struct. It's a DirectX11 struct and it declared typedef struct D3D11_INPUT_ELEMENT_DESC { LPCSTR SemanticName; UINT SemanticIndex; DXGI_FORMAT Format; UINT InputSlot; UINT AlignedByteOffset; D3D11_INPUT_CLASSIFICATION InputSlotClass; UINT InstanceDataStepRate; } D3D11_INPUT_ELEMENT_DESC; Thank you for answers ;-)
  13. Ok, thank you.   So, i will test it then. I just did not want to do blindly something, so it's easier to ask :)
  14. Hello,   I am currently using one compute shader, which calculates everything, i can calculate all deferred lighting with stable cascaded shadow mapping in one pass. I am using UAV texture to save results.   Because UAVs are 5.0 only ( RWTextures, also i heard, they are somehow slow becuase it's doing some checks ... ), i am thinking of using screenquad. My question is, is screenquad faster and better solution ? Perhaps i was just overloaded with expectations that CS is cool and fast :) Also i had a cool feel when i can control thread count :) but pixel shader works same right ? every pixel runs parallel ?   thank you for answers, opinions ;-)
  15. Yep problem solved. RECT realWindowSize = {0, 0, width, height}; AdjustWindowRect(&realWindowSize, WS_OVERLAPPEDWINDOW, FALSE); HWND WindowHandle = CreateWindowEx(NULL, L"CLASSNAME", (LPWSTR) "WINDOWTITLE",WS_OVERLAPPEDWINDOW,300,300,realWindowSize.right-realWindowSize.left,realWindowSize.bottom - realWindowSize.top,NULL,NULL,wc.hInstance,NULL);