Jump to content

  • Log In with Google      Sign In   
  • Create Account


wh1sp3rik

Member Since 03 Nov 2009
Offline Last Active Mar 31 2014 08:35 AM
-----

Topics I've Started

UpdateSubresource & Constant Buffer Perfomance

07 March 2014 - 10:13 AM

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.

 


Map texture for reading problem

16 February 2014 - 02:23 PM

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.


[DXSHOW] Get webcam bitmap

25 December 2013 - 03:49 PM

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 ... smile.png

 

Thank you very much


Writing to R16G16_UINT

14 October 2013 - 05:36 AM

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


Constant struct arrays

11 September 2013 - 07:42 AM

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 ;-)


PARTNERS