Direct3D Devices

本文详细介绍了Direct3D设备的概念及其在渲染流水线中的作用,涵盖了设备的属性、方法、状态块等内容,并深入解析了Direct3D设备在不同阶段的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.youkuaiyun.com/weili_2007/archive/2007/12/03/1914170.aspx

document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData("text"); if (text && text.length > 300) { text = text + "\r\n\n本文来自优快云博客,转载请标明出处:" + location.href; clipboardData.setData("text", text); } }, 100); } }

这一章讲述了Direct3D的设备对象,它提供了渲染流水线的一个抽象层。流水线的操作是通过设备的属性方法配置的。渲染在设备上的图片是要么2D拷贝操作,要么通过三维场景渲染。

设备的属性和方法控制了整个图形流水线,属性一般是通过Get和Set方法管理。每个设备都有一组它自己的capabilities。设备也是 resource对象的容器,Direct3D通过IDirect3DResource9接口管理资源。图形流水线的很多行为都是通过Render state控制的。应用程序可能需要频繁的设置render states,但是使用state block来保存一组设备属性(包括render state),使应用程序的设置更加方便和容易。

IDirect3DDevice9

IDrect3DDevice9控制流水线的行为,它包含大量的属性和方法。下面我们将探讨它的每个属性和方法。device 对象代表了渲染流水线。我们也可以从流水线里取到图片,提供流水线场景数据,然后将场景渲染到图片上。我们能够把流水线分成几个大的section:顶点 数据Assembly,顶点处理,primitive Assembly以光栅化,像素处理,frame buffer和Video scan out。IDirect3DDevice9的接口如下:

Read-Only Properties
GetAvailableTextureMem可用的纹理内存,单位是KB
GetBackBufferback buffer image surface 接口
GetCreationParameters设备的创建参数
GetDirect3Dcreating IDirect3D9接口
GetDisplayMode视频显示模式
GetFrontBufferDatafront buffer 的拷贝
GetNumberOfSwapChainsNumber of swap chain
GetRasterStatusRaster display status
GetRenderTargetDatasurface data in a render target
GetSwapChainswap chain on the device
Write-only Properties
SetCursorPositioncursor position
SetCursorPropertiescursor image and hot spot
SetDialogBoxModeGDI compatability flag
Properties
GetClipPlaneuser-defined clipping plane
SetClipPlane
GetClipStatusclip status of rendered primitives
SetClipStatus
GetCurrentTexturePalettecurrent texture palette index
SetCurrentTexturePalette
GetDepthStencilSurfaceDepth surface 接口
SetDepthStencilSurface
GetFVFFlexible vertex format
SetFVF
GetGammaRampGamma correction lookup table
SetGammaRamp
GetIndicescurrent index buffer
SetIndices
GetLightlight definition
SetLight
GetLightEnablelight enabled flag
LightEnable
GetMaterialPrimitive material properties
SetMaterial
GetNPatchModeN-Patch tessellation mode
SetNPatchMode
GetPaletteEntriesTexture palette entries
SetPaletteEntries
GetPixelShaderpixel shader program handle
SetPixelShader
GetPixelShaderConstantBBoolean constant registers
SetPixelShaderConstantB
GetPixelShaderConstantFfloating-pont constant registers
SetPixelShaderConstantF
GetPixelShaderConstantIinteger constant registers
SetPixelShaderConstantI
GerRenderStatePipeline control values
SetRenderState
GetRenderTargetTarget surface for rendered pixels
SetRenderTarget
GetSamplerStateTexture sampler control values
SetSamplerState
GetScissorRectScissor test rectangle
SetScissorRect
GetSoftwareVertexProcessingVertex processing control
SetSoftwareVertexProcessing
GetStreamSourcesource vertex data buffers
SetStreamSource
GetStreamSourceFreqstream source sampling frequency
SetStreamSourceFreq
GetTextureTexture resources used by each stage
SetTexture
GetTextureStageStateTexture stage control values
SetTextureStageState
GetTransformtranformation matrix
SetTransform
GetVertexDeclarationVertex component declaration
SetVertexDeclaration
GetVertexShadervertex shader program handle
SetVertexShader
GetVertexShaderConstantBboolean constant registers
SetVertexShaderConstantB
GetVertexShaderConstantFfloating-point constant registers
SetVertexShaderConstantF
GetVertexShaderConstantIInteger constant registers
SetVertexShaderConstantI
GetViewportRendering viewport extent
SetViewport
Methods
BeginSceneMake the start of a scene
BeginStateBlockMake device state for capture
ClearClear the current viewport on the device
ColorFillFills a rectangular area with a color
CreateAdditionalSwapChainCreate an additional swap chain on a windowed device
CreateCubeTextureCreate a cube map texture sources
CreateDepthStencilSurfaceCreate a depth/stencil surface resource
CreateIndexBufferCreate an index buffer resource
CreateOffScreenPlainSurfaceCreate an off-screen surface resource
CreatePixelShaderCreate a pixel shader
CreateQueryCreate a device query
CreateRenderTargetCreate a render target resource
CreateStateBlockCreate a state block
CreateTextureCreate a texture resource
CreateVertexBufferCreate a vertex buffer resource
CreateVertexDeclarationCreate a vertex declaration
CreateVertexShaderCreate a vertex shader
CreateVolumeTextureCreate a volume texture resource
DeletePatchDestroy a cached patch tesselation
DrawIndexedPrimitiveDraw indexed primitives from the current streams.
DrawIndexedPrimitiveUPDraw indexed primitives from user data.
DrawPrimitiveUPDraw primitives from usr data.
DrawRectDataRectangular higher order surface patch
DrawTriPatchTriangular higher order surface patch.
EndSceneMake the end of a scene
EndStateBlockCapture device state changes
EvictManagedResourcesFlush managed resources from the device
MultiplyTransformPost-multiply onto a device transformation matrix
PresentPresents a rendered image for display
ProcessVerticesProcess vertices in software
ResetResets the device's display characteristcs
ShowCursorDisplays or hides the cursor
StretchRectDevice memory blit with stretching
TestCooperativeLevelChecks exclusive ownership of the device
UpdateSurfacesystem to device memory surfaces
UpdateTexturesystem to device memory texture transfer.
ValidateDeviceValidate current device state.

Device methods by pipeline section

Vertex Assembly
BeginScene
CreateIndexBuffer
CreateVertexBuffer
DeletePatch
DrawIndexedPrimitive
DrawIndexedPrimitiveUP
DrawPrimitive
DrawPrimitiveUP
DrawRectPatch
DrawTriPatch
EndScene
SetIndices
SetNPatchMode
SetRenderState
SetStreamSource
SetStreamSourceFreq
SetVertexDeclaration
Vertex Processing CreateVertexDeclaration
CreateVertexShader
LightEnable
MultiplyTransform
ProcessVertices
SetClipPlane
SetClipStatus
SetFVF
SetLight
SetMaterial
SetRenderState
SetSoftwareVertexProcessing
SetTransform
SetVertexShader
SetVertexShaderConstantB
SetVertexShaderConstantF
SetVertexShaderConstantI
SetViewPort
Primitive Rasterization SetRenderState
Pixel Processing CreatePixelShader
MultiplyTransform
SetCurrentTexturePalette
SetPaletteEntries
SetPixelShader
SetPixelShaderConstantB
SetPixelShaderConstantF
SetPixelShaderConstantI
SetRenderState
SetSamplerState
SetTexture
SetTextureStageState
SetTransform
Frame Buffer Clear
ColorFill
CreateAdditionalSwapChain
CreateCubeTexture
CreateDepthStencilSurface
CreateOffscreenPlainSurface
CreateRenderTarget
CreateTexture
CreateVolumeTexture
EvictManagedResources
GetAvailableTextureMem
GetBackBuffer
GetFrontBufferData
GetNumberOfSwapChains
GetRenderTargetData
GetSwapChain
Reset
SetDepthStencilSurface
SetDialogBoxMode
SetRenderState
SetRenderTarget
SettScissorRect
SetViewPort
StretchRect
UpdateSurface
UpdateTexture
Video Scan out GetDisplayMode
GetRasterStatus
Present
SetCursorPosition
SetCursorProperties
SetGammaRamp
ShowCursor

Capabilities

一旦创建了设备,某些capabilities允许轻微的变化。 在某个设备上调用GetDeviceCaps可以返回一个真实设备对象的capabilities,但是如果在Direct3D对象上调用 GetDeviceCaps则返回设备通用的一些capabilities。

HRESULT GetDeviceCaps(D3DCAPS9 * value);

typedef struct _D3DCAPS9

{

D3DDEVTYPE DeviceType;

UINT AdapterOrdinal;

DWORD Caps;

DWORD Caps2;

DWORD Caps3;

DWORD PresentationIntervals;

DWORD CursorCaps;

DWORD DevCaps;

DWORD PrimitiveMiscCaps;

DWORD RasterCaps;

DWORD ZCmpCaps;

DWORD SrcBlendCaps;

DWORD DestBlendCaps;

DWORD AlphaCmpCaps;

DWORD ShadeCaps;

DWORD TextureCaps;

DWORD TextureFilterCaps;

DWORD CubeTextureFilterCaps;

DWORD VolumeTextureFilterCaps;

DWORD TextureAddressCaps;

DWORD VolumeTextureAddressCaps;

DWORD LineCaps;

DWORD MaxTextureWidth;

DWORD MaxTextureHeight;

DWORD MaxVolumeExtent;

DWORD MaxTextureRepeat;

DWORD MaxTextureAspectRatio;

DWORD MaxAnisotropy;

float MaxVertexW;

float GuardBandLeft;

float GuardBandTop;

float GuardBandRight;

float GuardBandBottom;

float ExtentAdjust;

DWORD StencilCaps;

DWORD FVFCaps;

DWORD TextureOpCaps;

DWORD MaxTextureBlendStages;

DWORD MaxSimultaneousTextures;

DWORD VertexProcessingCaps;

DWORD MaxActiveLights;

DWORD MaxUserClipPlanes;

DWORD MaxVertexBlendMatrices;

DWORD MaxVertexBlendMatrixIndex;

float MaxPointSize;

DWORD MaxPrimitiveCount;

DWORD MaxVertexIndex;

DWORD MaxStreams;

DWORD MaxStreamStride;

DWORD VertexShaderVersion;

DWORD MaxVertexShaderConst;

DWORD PixelShaderVersion;

float PixelShader1XMaxValue;

DWORD DevCaps2;

float MaxNpatchTessellationLevel;

DWORD Reserved5;

UINT MasterAdapterOrdinal;

UINT AdapterOrdinalInGroup;

UINT NumberOfAdaptersInGroup;

UINT DeclTypes;

DWORD NumSimultaneousRTs;

DWORD StretchRectFilterCaps;

D3DVSHADERCAPS2_0 VS20Caps;

D3DPSSHADERCAPS2_0 PS20Caps;

DWORD VertexTextureFilterCaps;

DWORD MaxVShaderInstructionsExecuted;

DWORD MaxPShaderInstructionsExecuted;

DWORD MaxVertexShader30InstructionSlots;

DWORD MaxPixelShader30InstructionsSlots;

}

Device Capabilities By pipleline section

Vertex Assembly Dev Caps:
Draw Prim TL Vertex
Quintic RT Patches
RT Patches
RT Patch Handle Zero
TL Vertex System Memory
TL Vertex Video Memory
Dev Caps 2:
Adaptive Tess N Patch
Adaptive Tess RT Patch
D Map N Patch
Stream Offset
Vertex Elements Can share Stream offset
Decl Types
FVF Caps
Max Primitive Count
Max Streams
Max Stream Stride
Max Vertex Index
Max N Patch Tessellation Level
Vertex Processing Dev Caps:
HW Transform And Light
Pure Device
Max Active Lights
Max User Clip Planes
Max Vertex Blend Matrices
Max Vertex Blend Matrices Index
Max Vertex Shader 30 Instruction Slots
Max Vertex Shader Const
Max V Shader Instruction Executed
Primitive Misc Caps:
Clip Plane Scaled Points
Clip TL Verts
Fog Vertex Clamped
Raster Caps
Fog Range
Fog Vertex
Vertex Processing Caps
Vertex Shader Version
Vertex Texture Filter Caps
VS 20 Caps
Primitive Processing Max User Clip Planes
Primitive Misc Caps:
Clip Plane Scaled Points
Clip TL Verts
Cull CW
Cull CCW
Cull None
Primitive Rasterization Dev Caps:
HW Rasterization
Pure Hardware
Extents Adjust
Guard Band Left
Guard Band Top
Guard Band Right
Guard Band Bottom
Line Caps:
Antialias
Texture
Max Point Size
Max Vertex W
Raster Caps:
Color Perspective
Shade Caps
Texture Caps:
Projected
Pixel Processing Caps 2:
Can Auto Gen Mipmap
Cube Texture Filter Caps
Dev Caps:
Separate Texture Memories
Texture Non Local Vid Mem
Texture System Memory
Texture Video Memory
Max Anisotropy
Max Pixel Shader 30 Instruction Slots
Max P Shader Instructions Executed
Max Simultaneous Textures
Max Texture Aspect Ratio
Max Texture Blend Stages
Max Texture Height
Max Texture Repeat
Max Texture Width
Max Volume Extent
Pixel Shader Version
Pixel Shader 1* max Value
Primitive Misc Caps:
Per Stage Constant
TSS Arg Temp
PS 20 Caps
Raster Caps
Anisotropy
Mipmap LOD Bias
Frame Buffer Alpha Cmp Caps
Caps 3:
Alpha FullScreen Flip or Discard
Copy To System Mem
Copy To Vid Mem
Dest Blend Caps
Line Caps:
Alpha Cmp
Blend
Fog
Z Test
Num Simultaneous RTS
Primitive Misc Caps
Blend Op
Color Write Enable
Independent Write Masks
Mask Z
MRT Independent Bit Depths
MRT Post Pixel Shader Blending
Separate Alpha Blend
Vide Scan out Adapter Ordinal In Group
Caps:
Read Scan line
Caps 2
Can Calibrate Gamma
Full Screen Gamma
Caps 3
Linear To sRGB Presentation
Cursor Caps
Dev Caps
Can Render after Flip
Master Adapter Ordinal
Number of Adapters in Group
Presentation Intervals

Resources

设备与资源对象协同工作来执行场景渲染。 资源对象通常是场景数据的容器。两维和三维的纹理分别使用surface和volume来存放他们的内容。 back buffer,depth/stencil buffer 和设备的render target属性也是使用surfaces来存放数据。

纹理接口的继承层次图

   基类接口包括IDirect3DVolume9和IDirect3DResource9。Volume对象并不是继承 IDirect3DResource9的,所以它并不参与资源管理。剩下的资源都是继承于IDirect3DResource9。另外所有的 Texture对象都是继承于IDirect3DBaseTexture9。

IDirect3DResource9

   IDirect3DResource9是所有资源对象的基本接口,它给可管理的资源提供了资源内存管理功能。它只能管理创建在 D3DPOOL_MANAGED池里面的资源。Managed的资源都有一个整数优先级,数字越大优先级越高。优先级越低的资源就可能先被 discarded。 Non-Managed 资源优先级总是0。在同样的优先级,Direct3D总是优先discard那些最近使用最少的资源。在渲染的时候如果应用程序使用的资源内存超过了显卡 的资源,Direct3D将使用最近使用最多的策略来释放资源。应用程序也可以显示的调用资源管理器来释放资源,EvictManageResource 可以完成这个操作。释放的设备内存不必是连续的,分配一个对象可能会由于设备内存不足而失败,即使资源管理器已经释放了足够的空间。

创建在D3DPOOL_DEFAULT的资源不能进行管理,并且不能被资源管理器释放。应用程序只能手工的分配,拷贝和释放default pool里面的内存。

当纹理加载到设备里面是,你可以先使用GetAvailableTextureMem来查询可用纹理内存空间的估计值,然后根据值来调节纹理的detail。这个是值只是一个粗略的估计值不是一个准确的值。

interface IDirect3DResource9 : IUnknown

{

//read -only properties

HRESULT GetDevice(IDirect3DDevic9 ** value);

D3DRESOURCETYPE GetType();

//read /write properties

DWORD GetPriority();

DWORD SetPriority();

HRESULT GetPrivateData(REFGUID data_guid, void* value, DWORD * size);

HRESULT SetPrivateData(REFGUID data_guid, const void * value, DWORD size, DWORD flags);

//methods

HRESULT FreePrivateData(RFEGUID data_guid);

void PreLoad();

}

GetDevice 方法返回拥有这个资源的设备。资源不能跨设备共享。资源类型可以通过GetType获取。根据这个类型我们就可以知道这个资源IID,然后使用 QueryInterface就可以得到具体的资源接口。GetPrivateDat和SetPrivateData可以将任意的数据快绑定到任何 Direct3D资源上。

Miscellaneous Properties

有几个设备属性与图形流水线没有直接的联系。 GetCreationParameters方法使用D3DDEVICE_CREATION_PARAMETERS结构体返回设备创建的参数。

HRESULT GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS * value);

HRESULT GetDirect3D(IDirect3D** value);

typedef struct _D3DDEVICE_CREATION_PARAMETERS

{

UINT AdapterOrdinal;

D3DDEVTYPE DeviceType;

HWND hFocusWindow;

DWORD BehaviorFlags;
}D3DDEVICE_CREATION_PARAMETERS;

创建设备的IDirect3D实例可以通过GetDirect3D获取。

设备查询

设备查询就是从设备的驱动层获取信息。主要用途是渲染统计和设备的时间通知。只要设备查询对象和设备对象存在,你就可以向设备查询最新的信息。可以通过CreateQuery创建查询对象,D3DQUERYTPE是查询信息的类别。

typedef enum _D3DQUERYTYPE

{

D3DQUERYTYPE_BANDWIDTHTIMINGS = 17,

D3DQUERYTYPE_CACHEUTILIZATION = 18,

D3DQUERYTYPE_EVENT = 8,

D3DQUERYTYPE_INTERFACETIMINGS = 14,

D3DQUERYTYPE_OCCLUSION = 9,

D3DQUERYTYPE_PIPELINETIMINGS = 13,

D3DQUERYTYPE_PIXELTIMINGS = 16,

D3DQUERYTYPE_RESOURCEMANAGER = 5,

D3DQUERYTYPE_TIMESTAMP = 10,

D3DQUERYTYPE_TIMESTAMPFDISJOINT = 11,

D3DQUERYTYPE_TIMESTAMPFREQ = 12,

D3DQUERYTYPE_VCACHE = 4,

D3DQUERYTYPE_VERTEXSTATS = 6,

D3DQUERYTYPE_VERTEXTIMING = 15

} D3DQUERYTYPE;

HRESULT CreateQuery(D3DQUREYTYPE kind, IDirect3DQuery9 ** result);

interface IDirect3DQuery9 : IUnknown

{

//read-only properties

HRESULT GetDevice(IDirect3DDevice9 ** value);

D3DQUERYTYPE GetType();

HRESULT GetData(void * data, DWORD size,DWORD flags);

DWORD GetDataSize();

//methods

HRESULT ISSUE(DWORD flags);

}

一 个查询对象通常有三种状态:signaled, building, 或者issued。Issue 方法用于将一个状态转换标记为有信号。当设备驱动返回了查询信息时,它也可以改变一个查询对象的状态。查询信息将通过渲染命令流发送给设备。Issue的 flags参数将用于标识查询的开始和结束。

#define D3DISSUE_END (1<<0)

#define D3DISSUE_BEGIN (1<<1)

在 查询开始和结束之间,查询对象可以汇报被发布的primitive的情况。顶点cache,资源管理统计和事件查询都有一个隐式的开始,应用程序 issue查询对象结束。隐式查询开始如下表。统计查询自从present调用后收集的数据,然而时间和顶点cache查询返回自设备创建后的数据。对于 occlusion, disjoint timestamp和timing 查询,应用程序只能显示的指定查询开始和结束。

Query Type Beginning
Vertex CacheCreateDevice
Resource Manager StatisticsPresent
Vertex StatisticsPresent
Event CreateDevice

为了取得查询的结果,GetDataSize和GetData方法可以获得查询信息的拷贝。每种查询结果都对应一个数据结构。如下表,

Query Type Data Type
Bandwidth TimingsD3DDEVINFO_D3D9BANDWIDTHTIMINGS
Cache UtilizationD3DDEVINFO_D3D9CACHEUTILIZATION
EventBOOL
Interface TimingsD3DDEVINFO_D3D9INTERFACETIMINGS
OcclusionDWORD
Pipeline TimingsD3DDEVINFO_D3D9INTERFACETIMINGS
Pixel Shader TimingsD3DDEVINFO_D3D9STAGETIMINGS
Resource Manager StatisticsD3DDEVINFO_RESOURCEMANAGER
TimestampUINT64
Timestamp DisjointBOOL
Timestamp FrequencyUINT64
Vertex CacheD3DDEVINFO_CACHE
Vertex Shader TimingsD3DDEVINFO_D3D9STAGETIMING
Vertex StatisticsD3DDEVINFO_D3DVERTEXSTATS

GetData的flags参数可以让你同步刷新设备的命令队列。

事件查询可以用来当命令流里的某个特定点被驱动处理的时候通知应用程序,Occlusion查询返回传递到depth测试的像素数目。如果值为0,标识这组primitive全部被obscured。应用程序使用这个信息来cull occlueded物体。

顶点统计和资源管理查询只在debug时支持,retail runtime不支持这两个查询。

  • 资源管理统计查询

资源管理统计查询返回一个D3DDEVINFO_RESOURCEMANAGER结构体,它包含了一个D3DRESOURCESTATS结构体数组,每个资源类型对应一个D3DRESOURCESTATS。D3DRTYPECOUNT定义了资源类型数目。

#define D3DRTYPECOUNT (D3DRTYPE_INDEXBUFFER + 1)

typedef struct _D3DDEVINFO_RESOURCEMANAGER

{

D3DRESOURCESTATS stats[D3DRTYPECOUNT];

} D3DDEVINFO_RESOURCEMANAGER;

D3DRESOURCESTAS不仅包括自从上次调用Present后的统计数据外,还包含自从设备Reset后保存的统计数据。每个资源的统计数据暗示 着D3DPOOL_MANAGED池里的资源的performance。 其他池里面的资源不在这个这个统计数组里面。

typedef struct _D3DRESOURCESTATS

{

// Data collected since last Present()

BOOL bThrashing;

DWORD ApproxBytesDownloaded;

DWORD NumEvicts;

DWORD NumVidCreates;

DWORD LastPri;

DWORD NumUsed;

DWORD NumUsedVidMem;

// Persistent data

DWORD Workingset;

DWORD WorkingSetBytes;

DWORD TotalManaged;

DWORD TotalBytes;

} D3DRESOURCESTATS;

Persistent数据设备内存working set和一些汇总数据。Working set成员是video内存资源对象的数目。WorkingSetBytes是working set的大小。TotalManaged 成员是可管理资源对象的数目,TotalBytes是他们总的大小。

bThrashing成员设置是否资源管理器thrashing。当资源管理器不断的把资源流化到video内存,thrashing 就发生了。例如,假定场景里面有很多物体,每个都使用纹理集合中的一个纹理。如果物体按照纹理排序顺序绘制,极有可能是必需的纹理将会装载到设备内存里 面。如果物体绘制的顺序不根据纹理顺序,资源管理器将会花很多时间在working set的不同纹理之间来回thrashing。

ApproxBytesDownloaded ,NumEvicts和NumVidCreates成员描述了自从上次调用Present后资源管理器的资源消耗行为。LastPri给出了上一次从设备 内存里面回收的资源对象的优先级。NumUsed和NumUsedInVidMem分别表示已经设置到设备的资源对象的数目和已经present到设备内 存上资源对象的数目。

  • 顶点统计查询

设备也能统计自上次调用Present以来的顶点处理,如三角形的数目以及clipping后增加的三角形数目。

typedef struct _D3DDEVINFO_D3DVERTEXSTATS

{

DWORD NumRenderedTriangles;

DWORD NumberExtraClippingTriangles;

}D3DDEVINFO_D3DVERTEXSTATS;

  • 顶点cache查询

顶点cache查询返回设备上顶点cache的大小等信息。顶点cache是一块临近GPU的内存cache,它避免访问一些最近使用的顶点内存。这个查询返回的是D3DDEVINFO_VCACHE结构体。

typdef struct _D3DDEVINFO_VCACHE

{

DWORD Pattern //必须是四字符代码CACH

DWORD OptMethod; //当它的值是0的时候,应用程序必须使用尽可能长的三角形步长来最大化顶点cache。 如果值是1表示应用程序将使用CacheSize大小的顶点Cache来优化。

DWORD CacheSize;

DWORD MagicNumber;// 当OptMethod 是的时候,它决定了重启三角形步长的时间。
} D3DDEVINFO_VCACHE, *LPD3DDEVINFO_VCACHE;

  • PIX 相关查询

PIX是DirectX应用程序的性能测量工具。余下的查询类型返回性能测量的数据。一个驱动可能不支持所有查询。如果值是0,它将忽略测量的结果。cache利用查询,返回texel和顶点cache的命中率。

typedef struct _D3DDEVINFO_D3D9CACHEUTILIZATION

{

float TextureCacheHitRate;

float PostTransformVertexCacheHitRate;

}D3DDEVINFO_D3D9CACHEUTILIZATION;

所有的时间查询返回都是流水线各个部分的查询时间消耗情况。这个测量反应查询开始和结束之间的百分比。

typedef struct _D3DDEVINFO_D3D9BANDWIDTHTIMINGS

{

float MaxBandwidthUtilized;

float FrontEndUploadMemoryUtilizedPercent;

float VertexRateUtilizedPercent;

float TriangleSetupRateUtilizedPercent;

float FillRateUtilizedPercent;

}D3DDEVINFO_D3D9BANDWIDTHTIMINGS;

typedef struct _D3DDEVINFO_D3D9INTERFACETIMINGS

{

float WaitingForGPUToUseApplicationResourceTimePercent;

float WaitingForGPUToAcceptMoreCommandsTimePercent;

float WaitingForGPUToStayWithinLatencyTimePercent;

float WaitingForGPUExclusiveResourceTimePercent;

float WaitingForGPUOtherTimePercent;

} D3DDEVINFO_D3D9INTERFACETIMINGS;

typedef struct _D3DDEVINFO_D3D9PIPELINETIMINGS

{

float VertexProcessingTimePercent;

float PixelProcessingTimePercent;

float OtherGPUProcessingTimePercent;

float GPUIdleTimePercent;

} D3DDEVINFO_D3D9PIPELINETIMINGS;

顶点shader timing和pixel shader timing查询都返回了D3DDEVINFO_D3D9STAGETIMINGS结构体里面的信息。

typdef struct _D3DDEVINFO_D3D9STAGETIMINGS

{

float MemoryProcessingPercent;

float ComputationProcessingPercent;
}D3DDEVINFO_D3D9STAGETIMINGS;

设备状态

设备对象的属性控制渲染流水线的行为,它的方法给流水线供应数据。设备的渲染,采样器,纹理阶段的状态属性控制了很多流水线行为,总结如下表:

Vertex Assembly RS Patch Edge StyleRS Adaptive Tess X, Y,Z,W
RS Position DegreeRS Enable Adaptive Tessellation
RS Normal DegreeRS Max Tessellation Level
RS Color VertexRS Min Tessellation Level
RS Point SizeSS D Map offset
Vertex Processing RS Tween FactorRS Clipping
RS Vertex BlendRS Indexed Vertex Blend Enable
TSS Tex Coord IndexRS Ambient Material Source
RS FOG Vertex ModeRS Diffuse Material Source
RS Range Fog EnableRS Specular Material Source
RS AmbientRS Emissive Material Source
RS Local ViewerRS Lighting
RS Specular EnableRS Normailze Normals
RS Shade ModeTSS Texture Transform Flags
RS Cull Mode RS Clip Plane Enable
Pixel Processing SS Border Color
RS Fill ModeSS Mag Filter
RS Last PixelSS Min Filter
SS Mip Filter
RS Specular EnableSS Mip Map LOD Bias
RS Texture FactorSS Max Mip level
RS Wrap 0——15SS Max Anisotrophy
SS Address U, V, WTSS Color Arg 0-2
TSS Color OpTSS Constant
TSS Alpha Arg 0-2RS Fog Table Mode
TSS Alpha OpRS Fog Density
TSS Result ArgRS Fog End
TSS Bump Env Mat 00-11RS Fog Start
TSS Bump Env L ScaleRS Fog Color
TSS Bump Env L OffsetRS Fog Enable
RS Depth BiasRS Slope Scale Depth Bias
SS sRGB TextureRS Antialiased Line Enable
Frame Buffer RS Alpha RefRS Alpha Test Enable
RS Alpha FuncRS Z Enable
RS Z Func
RS Stencil EnableRS Stencil Func
RS Stencil FailRS Stencil Z Fail
RS Stencil PassRS Alpha Blend Enable
RS Src BlendRS Dest Blend
RS Blend OpRS Dither Enable
RS Color Write EnableRS Stencil Write Mask
RS Z Write EnableRS Multi Sample Antialias
RS Multi Sample MaskRS Scissor Test Enable
RS Src Blend AlphaRS Separate Alpha Blend Enable
RS Dest Blend AlphaRS Blend Op Alpha
RS Blend FactorRS CCW Stencil Fail
RS CCW Stencil Z FailRS CCW Stencil Pass
RS sRGB Write EnableRS CCW Stencil Func
SS Element IndexRS Color Write Enable 1-3
RS Two Sided Stencil Mode

注意:RS,SS和TSS 分别表示render, sampler和texture stage states。

Render state, sampler state和纹理阶段state都是32位的数量,并且携带一个名字和值。名字取值于D3DRENDERSTATETYPE, D3DSAMPLERSTATETYPE和D3DTEXTURESTAGESTATETYPE 枚举值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值