PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [D3D10] Multisampling


Coda
2007-05-14, 01:26:31
Mein Problem ist: Es funktioniert einfach nicht. Der RasterizerState hat Multisampling aktiviert und eigentlich sollte die Initialisierung auch passen:

void RenderTarget::Recreate()
{
HRESULT hresult;
RECT rect;
DXGI_SWAP_CHAIN_DESC swap_chain_desc;
ID3D10Texture2D *back_buffer;

SafeRelease(depth_stencil_view);
SafeRelease(render_target_view);
SafeRelease(swap_chain);

GetClientRect(hwnd,&rect);
if((rect.bottom-rect.top)==0 || (rect.right-rect.left)==0) return;

ZeroMemory(&swap_chain_desc,sizeof(swap_chain_desc));
swap_chain_desc.BufferCount = 1;
swap_chain_desc.BufferDesc.Width = rect.right-rect.left;
swap_chain_desc.BufferDesc.Height = rect.bottom-rect.top;
swap_chain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swap_chain_desc.BufferDesc.RefreshRate.Numerator = 60;
swap_chain_desc.BufferDesc.RefreshRate.Denominator = 1;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.OutputWindow = hwnd;
swap_chain_desc.SampleDesc.Count = sample_count;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.Windowed = true;

if((hresult = dxgi_factory->CreateSwapChain(d3d10_device,&swap_chain_desc,&swap_chain)) != S_OK)
throw Exception(L"RenderTarget: CreateSwapChain failed: " + GetD3D10Error(hresult));

if((hresult = swap_chain->GetBuffer(0,__uuidof(ID3D10Texture2D),(LPVOID*)&back_buffer)) != S_OK)
throw Exception(L"RenderTarget: GetBuffer failed: " + GetD3D10Error(hresult));

D3D10_RENDER_TARGET_VIEW_DESC render_target_view_desc;
ZeroMemory(&render_target_view_desc,sizeof(render_target_view_desc));
render_target_view_desc.Format = swap_chain_desc.BufferDesc.Format;
if(sample_count > 1) render_target_view_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
else render_target_view_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;

if((hresult = d3d10_device->CreateRenderTargetView(back_buffer,&render_target_view_desc,&render_target_view)) != S_OK)
throw Exception(L"RenderTarget: CreateRenderTargetView failed: " + GetD3D10Error(hresult));

SafeRelease(back_buffer);

D3D10_TEXTURE2D_DESC depth_texture_desc;
D3D10_DEPTH_STENCIL_VIEW_DESC depth_stencil_view_desc;
ID3D10Texture2D *depth_stencil_texture;

ZeroMemory(&depth_texture_desc,sizeof(depth_texture_desc));
depth_texture_desc.Width = rect.right-rect.left;
depth_texture_desc.Height = rect.bottom-rect.top;
depth_texture_desc.MipLevels = 1;
depth_texture_desc.ArraySize = 1;
depth_texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depth_texture_desc.SampleDesc.Count = sample_count;
depth_texture_desc.SampleDesc.Quality = 0;
depth_texture_desc.Usage = D3D10_USAGE_DEFAULT;
depth_texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
depth_texture_desc.CPUAccessFlags = 0;
depth_texture_desc.MiscFlags = 0;

if((hresult = d3d10_device->CreateTexture2D(&depth_texture_desc,0,&depth_stencil_texture)) != S_OK)
throw Exception(L"RenderTarget: CreateTexture2D failed: " + GetD3D10Error(hresult));

ZeroMemory(&depth_stencil_view_desc,sizeof(depth_stencil_view_desc));
depth_stencil_view_desc.Format = depth_texture_desc.Format;
if(sample_count > 1) depth_stencil_view_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DMS;
else depth_stencil_view_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
depth_stencil_view_desc.Texture2D.MipSlice = 0;

if((hresult = d3d10_device->CreateDepthStencilView(depth_stencil_texture,&depth_stencil_view_desc,&depth_stencil_view)) != S_OK)
throw Exception(L"RenderTarget: CreateDepthStencilView failed: " + GetD3D10Error(hresult));

SafeRelease(depth_stencil_texture);
}


Ich vermute es ist irgend eine Kleinigkeit, aber ich finde nichts. Hat jemand nen Tipp? (sample_count ist auf 4 gesetzt)

Demirug
2007-05-14, 07:48:58
Auf den ersten Blick würde ich sagen du bist über das Problem gestolpert über das ich gerade gestern etwas geschrieben habe: http://gpu-fun.spaces.live.com/blog/cns!FB5EEACE075E1350!242.entry

Coda
2007-05-14, 13:23:09
Das komische ist dann aber, dass MS das in den SDK-Samples selber so macht (also die Textur danach freigibt).

Also ich hab's jetzt mal so umgebaut:
void RenderTarget::Recreate()
{
HRESULT hresult;
RECT rect;
DXGI_SWAP_CHAIN_DESC swap_chain_desc;

SafeRelease(depth_stencil_texture);
SafeRelease(depth_stencil_view);
SafeRelease(render_target_view);
SafeRelease(back_buffer);
SafeRelease(swap_chain);

GetClientRect(hwnd,&rect);
if((rect.bottom-rect.top)==0 || (rect.right-rect.left)==0) return;

ZeroMemory(&swap_chain_desc,sizeof(swap_chain_desc));
swap_chain_desc.BufferCount = 1;
swap_chain_desc.BufferDesc.Width = rect.right-rect.left;
swap_chain_desc.BufferDesc.Height = rect.bottom-rect.top;
swap_chain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swap_chain_desc.BufferDesc.RefreshRate.Numerator = 60;
swap_chain_desc.BufferDesc.RefreshRate.Denominator = 1;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.OutputWindow = hwnd;
swap_chain_desc.SampleDesc.Count = sample_count;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.Windowed = true;

if((hresult = dxgi_factory->CreateSwapChain(d3d10_device,&swap_chain_desc,&swap_chain)) != S_OK)
throw Exception(L"RenderTarget: CreateSwapChain failed: " + GetD3D10Error(hresult));

if((hresult = swap_chain->GetBuffer(0,__uuidof(ID3D10Texture2D),(LPVOID*)&back_buffer)) != S_OK)
throw Exception(L"RenderTarget: GetBuffer failed: " + GetD3D10Error(hresult));

D3D10_RENDER_TARGET_VIEW_DESC render_target_view_desc;
ZeroMemory(&render_target_view_desc,sizeof(render_target_view_desc));
render_target_view_desc.Format = swap_chain_desc.BufferDesc.Format;
if(sample_count > 1) render_target_view_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
else render_target_view_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;

if((hresult = d3d10_device->CreateRenderTargetView(back_buffer,&render_target_view_desc,&render_target_view)) != S_OK)
throw Exception(L"RenderTarget: CreateRenderTargetView failed: " + GetD3D10Error(hresult));

D3D10_TEXTURE2D_DESC depth_texture_desc;
D3D10_DEPTH_STENCIL_VIEW_DESC depth_stencil_view_desc;

ZeroMemory(&depth_texture_desc,sizeof(depth_texture_desc));
depth_texture_desc.Width = rect.right-rect.left;
depth_texture_desc.Height = rect.bottom-rect.top;
depth_texture_desc.MipLevels = 1;
depth_texture_desc.ArraySize = 1;
depth_texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depth_texture_desc.SampleDesc.Count = sample_count;
depth_texture_desc.SampleDesc.Quality = 0;
depth_texture_desc.Usage = D3D10_USAGE_DEFAULT;
depth_texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
depth_texture_desc.CPUAccessFlags = 0;
depth_texture_desc.MiscFlags = 0;

if((hresult = d3d10_device->CreateTexture2D(&depth_texture_desc,0,&depth_stencil_texture)) != S_OK)
throw Exception(L"RenderTarget: CreateTexture2D failed: " + GetD3D10Error(hresult));

ZeroMemory(&depth_stencil_view_desc,sizeof(depth_stencil_view_desc));
depth_stencil_view_desc.Format = depth_texture_desc.Format;
if(sample_count > 1) depth_stencil_view_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DMS;
else depth_stencil_view_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
depth_stencil_view_desc.Texture2D.MipSlice = 0;

if((hresult = d3d10_device->CreateDepthStencilView(depth_stencil_texture,&depth_stencil_view_desc,&depth_stencil_view)) != S_OK)
throw Exception(L"RenderTarget: CreateDepthStencilView failed: " + GetD3D10Error(hresult));
}



Immer noch der selbe Fehler :(

Coda
2007-05-14, 17:51:37
Kann es sein, dass ich im Fenstermodus nur in einen Offscreen-Buffer mit Multisampling rendern kann und nicht in eine Swapchain?